From 551b076f1c7f9b66eecd8f6b7a12b1bd7a78b967 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 20 Dec 2010 17:40:07 -0200 Subject: change in the relationship between totalbytes and GCdebt - luaM_realloc_ is too critical to update two counters --- lstate.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index d13a3ad5..fa67e855 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.87 2010/11/26 14:32:31 roberto Exp roberto $ +** $Id: lstate.c,v 2.88 2010/12/20 18:17:46 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -65,11 +65,14 @@ typedef struct LG { #define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l))) - /* -** maximum number of nested calls made by error-handling function +** set GCdebt to a new value keeping the value (totalbytes + GCdebt) +** invariant */ -#define LUAI_EXTRACALLS 10 +void luaE_setdebt (global_State *g, l_mem debt) { + g->totalbytes -= (debt - g->GCdebt); + g->GCdebt = debt; +} CallInfo *luaE_extendCI (lua_State *L) { @@ -154,7 +157,6 @@ static void f_luaopen (lua_State *L, void *ud) { /* pre-create memory-error message */ g->memerrmsg = luaS_newliteral(L, MEMERRMSG); luaS_fix(g->memerrmsg); /* it should never be collected */ - g->GCdebt = 0; g->gcrunning = 1; /* allow gc */ } @@ -188,7 +190,7 @@ static void close_state (lua_State *L) { luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); luaZ_freebuffer(L, &g->buff); freestack(L); - lua_assert(g->totalbytes == sizeof(LG)); + lua_assert(gettotalbytes(g) == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); } @@ -258,6 +260,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->gray = g->grayagain = NULL; g->weak = g->ephemeron = g->allweak = NULL; g->totalbytes = sizeof(LG); + g->GCdebt = 0; g->gcpause = LUAI_GCPAUSE; g->gcmajorinc = LUAI_GCMAJOR; g->gcstepmul = LUAI_GCMUL; -- cgit v1.2.3-55-g6feb