From 9a871dd3db1baf8c7ac3bb94f03eb1f1bc3532e9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 28 Aug 2013 15:30:26 -0300 Subject: [PATCH] tables and userdata all go to local list, too --- lgc.c | 6 ++++-- lstate.c | 10 +++++++++- lstring.c | 4 ++-- ltable.c | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lgc.c b/lgc.c index f905d9d5..8661fe8d 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.153 2013/08/27 18:53:35 roberto Exp roberto $ +** $Id: lgc.c,v 2.154 2013/08/27 20:04:00 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -867,11 +867,13 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { g->sweepgc = sweeptolive(L, g->sweepgc, NULL); } /* search for pointer pointing to 'o' */ - for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ } + p = (testbit(ho->marked, LOCALMARK)) ? &g->allgc : &g->localgc; + for (; *p != o; p = &gch(*p)->next) { /* empty */ } *p = ho->next; /* remove 'o' from 'allgc' list */ ho->next = g->finobj; /* link it in list 'finobj' */ g->finobj = o; l_setbit(ho->marked, FINALIZEDBIT); /* mark it as such */ + l_setbit(ho->marked, LOCALMARK); /* not in 'localgc' anymore */ if (!keepinvariant(g)) /* not keeping invariant? */ makewhite(g, o); /* "sweep" object */ } diff --git a/lstate.c b/lstate.c index 4d141aec..1fe59cd3 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.106 2013/08/26 12:41:10 roberto Exp roberto $ +** $Id: lstate.c,v 2.107 2013/08/27 18:53:35 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -165,6 +165,14 @@ static void init_registry (lua_State *L, global_State *g) { sethvalue(L, &g->l_registry, registry); luaH_resize(L, registry, LUA_RIDX_LAST, 0); nolocal(obj2gco(registry)); + /* registry is the first "regular" object created by a state; move it + from 'localgc' to 'allgc' so that it act as a "sentinel" there */ + lua_assert(g->allgc == NULL && + registry->next == NULL && + g->localgc == obj2gco(registry)); + g->allgc = g->localgc; + g->localgc = NULL; + l_setbit(registry->marked, LOCALMARK); /* mark that it is not in 'localgc' */ /* registry[LUA_RIDX_MAINTHREAD] = L */ setthvalue(L, &temp, L); /* temp = L */ luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp); diff --git a/lstring.c b/lstring.c index 3fb86ab2..c76b6724 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.31 2013/08/23 13:34:54 roberto Exp roberto $ +** $Id: lstring.c,v 2.32 2013/08/27 20:04:00 roberto Exp roberto $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -213,7 +213,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { Udata *u; if (s > MAX_SIZE - sizeof(Udata)) luaM_toobig(L); - u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, &G(L)->allgc, 0)->u; + u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u; u->uv.len = s; u->uv.metatable = NULL; u->uv.env = e; diff --git a/ltable.c b/ltable.c index ed5d9977..f7efdc59 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.79 2013/08/18 16:12:18 roberto Exp roberto $ +** $Id: ltable.c,v 2.80 2013/08/27 20:04:00 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -378,7 +378,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) { Table *luaH_new (lua_State *L) { - Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), &G(L)->allgc, 0)->h; + Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h; t->metatable = NULL; t->flags = cast_byte(~0); t->array = NULL;