From 12b6f610b0f1b4157c04f0db264f1f1d0634709b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 27 Dec 2023 12:09:11 -0300 Subject: Several tweaks in the garbage collector - back with step size in collectgarbage("step") - adjustments in defaults for some GC parameters - adjustments in 'luaO_codeparam' --- lapi.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index dcdc1cd3..9ff1b851 100644 --- a/lapi.c +++ b/lapi.c @@ -416,10 +416,11 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { luaC_checkGC(L); o = index2value(L, idx); /* previous call may reallocate the stack */ } - if (len != NULL) - *len = tsslen(tsvalue(o)); lua_unlock(L); - return getstr(tsvalue(o)); + if (len != NULL) + return getlstr(tsvalue(o), *len); + else + return getstr(tsvalue(o)); } @@ -1174,11 +1175,16 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { } case LUA_GCSTEP: { lu_byte oldstp = g->gcstp; + l_obj n = va_arg(argp, int); + int work = 0; /* true if GC did some work */ g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ - luaC_step(L); /* run one basic step */ - g->gcstp = oldstp; /* restore previous state */ - if (g->gcstate == GCSpause) /* end of cycle? */ + if (n <= 0) + n = g->GCdebt; /* force to run one basic step */ + luaE_setdebt(g, g->GCdebt - n); + luaC_condGC(L, (void)0, work = 1); + if (work && g->gcstate == GCSpause) /* end of cycle? */ res = 1; /* signal it */ + g->gcstp = oldstp; /* restore previous state */ break; } case LUA_GCISRUNNING: { -- cgit v1.2.3-55-g6feb