From a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 29 Mar 2010 14:43:14 -0300 Subject: [PATCH] global table now is only kept in the registry --- lapi.c | 16 +++++++++++----- lgc.c | 4 +--- lstate.c | 8 +++----- lstate.h | 3 +-- ltests.c | 3 +-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lapi.c b/lapi.c index adae47b8..4a96b9a4 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.116 2010/03/25 19:37:23 roberto Exp roberto $ +** $Id: lapi.c,v 2.117 2010/03/26 20:58:11 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -843,11 +843,17 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, if (!chunkname) chunkname = "?"; luaZ_init(L, &z, reader, data); status = luaD_protectedparser(L, &z, chunkname); - if (status == LUA_OK) { - Closure *f = clvalue(L->top - 1); + if (status == LUA_OK) { /* no errors? */ + Closure *f = clvalue(L->top - 1); /* get newly created function */ lua_assert(!f->c.isC); - if (f->l.nupvalues == 1) - sethvalue(L, f->l.upvals[0]->v, G(L)->l_gt); + if (f->l.nupvalues == 1) { /* does it have one upvalue? */ + /* get global table from registry */ + Table *reg = hvalue(&G(L)->l_registry); + const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); + /* set global table as 1st upvalue of 'f' (may be _ENV) */ + setobj(L, f->l.upvals[0]->v, gt); + luaC_barrier(L, f, gt); + } } lua_unlock(L); return status; diff --git a/lgc.c b/lgc.c index 0612f4a5..64c662b1 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.73 2010/03/25 19:37:23 roberto Exp roberto $ +** $Id: lgc.c,v 2.74 2010/03/26 20:58:11 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -235,8 +235,6 @@ static void markroot (lua_State *L) { g->grayagain = NULL; g->weak = g->ephemeron = g->allweak = NULL; markobject(g, g->mainthread); - /* make global table and registry to be traversed before main stack */ - markobject(g, g->l_gt); markvalue(g, &g->l_registry); markmt(g); markbeingfnz(g); /* mark any finalizing object left from previous cycle */ diff --git a/lstate.c b/lstate.c index d47e01c8..aad526c2 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.74 2010/03/25 19:37:23 roberto Exp roberto $ +** $Id: lstate.c,v 2.75 2010/03/26 20:58:11 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -140,8 +140,8 @@ static void init_registry (lua_State *L, global_State *g) { cp->c.f = ccall; setclvalue(L, &mt, cp); setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CCALL), &mt); - /* registry[LUA_RIDX_GLOBALS] = l_gt */ - sethvalue(L, &mt, g->l_gt); + /* registry[LUA_RIDX_GLOBALS] = table of globals */ + sethvalue(L, &mt, luaH_new(L)); setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt); } @@ -153,7 +153,6 @@ static void f_luaopen (lua_State *L, void *ud) { global_State *g = G(L); UNUSED(ud); stack_init(L, L); /* init stack */ - g->l_gt = luaH_new(L); /* table of globals */ init_registry(L, g); luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ luaT_init(L); @@ -256,7 +255,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->strt.nuse = 0; g->strt.hash = NULL; setnilvalue(&g->l_registry); - g->l_gt = NULL; luaZ_initbuffer(L, &g->buff); g->panic = NULL; g->version = lua_version(NULL); diff --git a/lstate.h b/lstate.h index 17abe10b..caaa70ec 100644 --- a/lstate.h +++ b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.57 2010/03/25 19:37:23 roberto Exp roberto $ +** $Id: lstate.h,v 2.58 2010/03/26 20:58:11 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -121,7 +121,6 @@ typedef struct global_State { lu_mem lastmajormem; /* memory in use after last major collection */ stringtable strt; /* hash table for strings */ TValue l_registry; - struct Table *l_gt; /* table of globals */ unsigned short nCcalls; /* number of nested C calls */ lu_byte currentwhite; lu_byte gcstate; /* state of garbage collector */ diff --git a/ltests.c b/ltests.c index 15d02872..4b64fe32 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.89 2010/03/25 13:06:36 roberto Exp roberto $ +** $Id: ltests.c,v 2.90 2010/03/26 20:58:11 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -372,7 +372,6 @@ int lua_checkmemory (lua_State *L) { GCObject *o; UpVal *uv; checkliveness(g, &g->l_registry); - lua_assert(!isdead(g, obj2gco(g->l_gt))); checkstack(g, g->mainthread); for (o = g->allgc; o != NULL; o = gch(o)->next) { lua_assert(!testbits(o->gch.marked, bitmask(SEPARATED)));