From 1cce3e6842fd76099b1973dabd8504566610f068 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 14 Feb 2014 14:43:14 -0200 Subject: change in the way 'collectgarbage("step", size)' interprets 'size' (mimicking the way the GC itself behaves when Lua allocates 'size' Kbytes) --- lapi.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index d5765cc9..cb38ffba 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.194 2014/02/13 12:11:34 roberto Exp roberto $ +** $Id: lapi.c,v 2.195 2014/02/13 17:25:20 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -1070,12 +1070,20 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { break; } case LUA_GCSTEP: { - lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE; - if (g->gcrunning) - debt += g->GCdebt; /* include current debt */ - luaE_setdebt(g, debt); - luaC_forcestep(L); - if (g->gcstate == GCSpause) /* end of cycle? */ + l_mem debt = 1; /* =1 to signal that it did an actual step */ + int oldrunning = g->gcrunning; + g->gcrunning = 1; /* force GC to run */ + if (data == 0) { + luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */ + luaC_step(L); + } + else { /* add 'data' to total debt */ + debt = cast(l_mem, data) * 1024 + g->GCdebt; + luaE_setdebt(g, debt); + luaC_checkGC(L); + } + g->gcrunning = oldrunning; /* restore previous state */ + if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */ res = 1; /* signal it */ break; } -- cgit v1.2.3-55-g6feb