Skip to content

Commit

Permalink
35a2fed2d1e0b95a1bfab364707e469863517085
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Feb 7, 2024
1 parent 1cb0bf2 commit 5b32200
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
18 changes: 3 additions & 15 deletions src/lapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
va_list argp;
int res = 0;
global_State *g = G(L);
if (g->gcstp & GCSTPGC) /* internal stop? */
if (g->gcstp & (GCSTPGC | GCSTPCLS)) /* internal stop? */
return -1; /* all options are invalid when stopped */
lua_lock(L);
va_start(argp, what);
Expand All @@ -1294,7 +1294,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
}
case LUA_GCRESTART: {
luaE_setdebt(g, 0);
g->gcstp = 0; /* (bit GCSTPGC must be zero here) */
g->gcstp = 0; /* (other bits must be zero here) */
break;
}
case LUA_GCCOLLECT: {
Expand All @@ -1314,7 +1314,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
int todo = va_arg(argp, int); /* work to be done */
int didsomething = 0;
lu_byte oldstp = g->gcstp;
g->gcstp = 0; /* allow GC to run (bit GCSTPGC must be zero here) */
g->gcstp = 0; /* allow GC to run (other bits must be zero here) */
if (todo == 0)
todo = 1 << g->gcstepsize; /* standard step size */
while (todo >= g->GCdebt) { /* enough to run a step? */
Expand All @@ -1333,18 +1333,6 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
res = 1; /* signal it */
break;
}
case LUA_GCSETPAUSE: {
unsigned int data = va_arg(argp, unsigned int);
res = applygcparam(g, gcpause, 100);
setgcparam(g, gcpause, data);
break;
}
case LUA_GCSETSTEPMUL: {
unsigned int data = va_arg(argp, unsigned int);
res = applygcparam(g, gcstepmul, 100);
setgcparam(g, gcstepmul, data);
break;
}
case LUA_GCISRUNNING: {
res = gcrunning(g);
break;
Expand Down
14 changes: 2 additions & 12 deletions src/lbaselib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,9 @@ static int pushmode (lua_State *L, int oldmode) {

static int luaB_collectgarbage (lua_State *L) {
static const char *const opts[] = {"stop", "restart", "collect",
"count", "step", "setpause", "setstepmul",
"isrunning", "generational", "incremental", NULL};
"count", "step", "isrunning", "generational", "incremental", NULL};
static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC };
int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
switch (o) {
case LUA_GCCOUNT: {
Expand All @@ -269,14 +267,6 @@ static int luaB_collectgarbage (lua_State *L) {
lua_pushboolean(L, res);
return 1;
}
case LUA_GCSETPAUSE:
case LUA_GCSETSTEPMUL: {
int p = (int)luaL_optinteger(L, 2, 0);
int previous = lua_gc(L, o, p);
checkvalres(previous);
lua_pushinteger(L, previous);
return 1;
}
case LUA_GCISRUNNING: {
int res = lua_gc(L, o);
checkvalres(res);
Expand Down
8 changes: 3 additions & 5 deletions src/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,9 @@ PLUTO_API void (pluto_warning) (lua_State *L, const char *msg);
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
#define LUA_GCISRUNNING 9
#define LUA_GCGEN 10
#define LUA_GCINC 11
#define LUA_GCISRUNNING 6
#define LUA_GCGEN 7
#define LUA_GCINC 8

LUA_API int (lua_gc) (lua_State *L, int what, ...);

Expand Down
9 changes: 2 additions & 7 deletions testes/gc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,18 @@ end

-- test weird parameters to 'collectgarbage'
do
-- save original parameters
local a = collectgarbage("setpause", 200)
local b = collectgarbage("setstepmul", 200)
local t = {0, 2, 10, 90, 500, 5000, 30000, 0x7ffffffe}
for i = 1, #t do
local p = t[i]
for j = 1, #t do
local m = t[j]
collectgarbage("setpause", p)
collectgarbage("setstepmul", m)
collectgarbage("incremental", p, m)
collectgarbage("step", 0)
collectgarbage("step", 10000)
end
end
-- restore original parameters
collectgarbage("setpause", a)
collectgarbage("setstepmul", b)
collectgarbage("incremental", 200, 300)
collectgarbage()
end

Expand Down

0 comments on commit 5b32200

Please sign in to comment.