diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-29 14:43:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-29 14:43:14 -0300 |
commit | a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57 (patch) | |
tree | bda3a46753aff65cef00562e405b999c47fbb15b | |
parent | 064e406f67c0153999a5246deb1d616b06ee9bb0 (diff) | |
download | lua-a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57.tar.gz lua-a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57.tar.bz2 lua-a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57.zip |
global table now is only kept in the registry
-rw-r--r-- | lapi.c | 16 | ||||
-rw-r--r-- | lgc.c | 4 | ||||
-rw-r--r-- | lstate.c | 8 | ||||
-rw-r--r-- | lstate.h | 3 | ||||
-rw-r--r-- | ltests.c | 3 |
5 files changed, 17 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.116 2010/03/25 19:37:23 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.117 2010/03/26 20:58:11 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -843,11 +843,17 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
843 | if (!chunkname) chunkname = "?"; | 843 | if (!chunkname) chunkname = "?"; |
844 | luaZ_init(L, &z, reader, data); | 844 | luaZ_init(L, &z, reader, data); |
845 | status = luaD_protectedparser(L, &z, chunkname); | 845 | status = luaD_protectedparser(L, &z, chunkname); |
846 | if (status == LUA_OK) { | 846 | if (status == LUA_OK) { /* no errors? */ |
847 | Closure *f = clvalue(L->top - 1); | 847 | Closure *f = clvalue(L->top - 1); /* get newly created function */ |
848 | lua_assert(!f->c.isC); | 848 | lua_assert(!f->c.isC); |
849 | if (f->l.nupvalues == 1) | 849 | if (f->l.nupvalues == 1) { /* does it have one upvalue? */ |
850 | sethvalue(L, f->l.upvals[0]->v, G(L)->l_gt); | 850 | /* get global table from registry */ |
851 | Table *reg = hvalue(&G(L)->l_registry); | ||
852 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | ||
853 | /* set global table as 1st upvalue of 'f' (may be _ENV) */ | ||
854 | setobj(L, f->l.upvals[0]->v, gt); | ||
855 | luaC_barrier(L, f, gt); | ||
856 | } | ||
851 | } | 857 | } |
852 | lua_unlock(L); | 858 | lua_unlock(L); |
853 | return status; | 859 | return status; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.73 2010/03/25 19:37:23 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.74 2010/03/26 20:58:11 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -235,8 +235,6 @@ static void markroot (lua_State *L) { | |||
235 | g->grayagain = NULL; | 235 | g->grayagain = NULL; |
236 | g->weak = g->ephemeron = g->allweak = NULL; | 236 | g->weak = g->ephemeron = g->allweak = NULL; |
237 | markobject(g, g->mainthread); | 237 | markobject(g, g->mainthread); |
238 | /* make global table and registry to be traversed before main stack */ | ||
239 | markobject(g, g->l_gt); | ||
240 | markvalue(g, &g->l_registry); | 238 | markvalue(g, &g->l_registry); |
241 | markmt(g); | 239 | markmt(g); |
242 | markbeingfnz(g); /* mark any finalizing object left from previous cycle */ | 240 | markbeingfnz(g); /* mark any finalizing object left from previous cycle */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.74 2010/03/25 19:37:23 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.75 2010/03/26 20:58:11 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -140,8 +140,8 @@ static void init_registry (lua_State *L, global_State *g) { | |||
140 | cp->c.f = ccall; | 140 | cp->c.f = ccall; |
141 | setclvalue(L, &mt, cp); | 141 | setclvalue(L, &mt, cp); |
142 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CCALL), &mt); | 142 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CCALL), &mt); |
143 | /* registry[LUA_RIDX_GLOBALS] = l_gt */ | 143 | /* registry[LUA_RIDX_GLOBALS] = table of globals */ |
144 | sethvalue(L, &mt, g->l_gt); | 144 | sethvalue(L, &mt, luaH_new(L)); |
145 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt); | 145 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt); |
146 | } | 146 | } |
147 | 147 | ||
@@ -153,7 +153,6 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
153 | global_State *g = G(L); | 153 | global_State *g = G(L); |
154 | UNUSED(ud); | 154 | UNUSED(ud); |
155 | stack_init(L, L); /* init stack */ | 155 | stack_init(L, L); /* init stack */ |
156 | g->l_gt = luaH_new(L); /* table of globals */ | ||
157 | init_registry(L, g); | 156 | init_registry(L, g); |
158 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ | 157 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ |
159 | luaT_init(L); | 158 | luaT_init(L); |
@@ -256,7 +255,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
256 | g->strt.nuse = 0; | 255 | g->strt.nuse = 0; |
257 | g->strt.hash = NULL; | 256 | g->strt.hash = NULL; |
258 | setnilvalue(&g->l_registry); | 257 | setnilvalue(&g->l_registry); |
259 | g->l_gt = NULL; | ||
260 | luaZ_initbuffer(L, &g->buff); | 258 | luaZ_initbuffer(L, &g->buff); |
261 | g->panic = NULL; | 259 | g->panic = NULL; |
262 | g->version = lua_version(NULL); | 260 | g->version = lua_version(NULL); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.57 2010/03/25 19:37:23 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.58 2010/03/26 20:58:11 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -121,7 +121,6 @@ typedef struct global_State { | |||
121 | lu_mem lastmajormem; /* memory in use after last major collection */ | 121 | lu_mem lastmajormem; /* memory in use after last major collection */ |
122 | stringtable strt; /* hash table for strings */ | 122 | stringtable strt; /* hash table for strings */ |
123 | TValue l_registry; | 123 | TValue l_registry; |
124 | struct Table *l_gt; /* table of globals */ | ||
125 | unsigned short nCcalls; /* number of nested C calls */ | 124 | unsigned short nCcalls; /* number of nested C calls */ |
126 | lu_byte currentwhite; | 125 | lu_byte currentwhite; |
127 | lu_byte gcstate; /* state of garbage collector */ | 126 | lu_byte gcstate; /* state of garbage collector */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.89 2010/03/25 13:06:36 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.90 2010/03/26 20:58:11 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -372,7 +372,6 @@ int lua_checkmemory (lua_State *L) { | |||
372 | GCObject *o; | 372 | GCObject *o; |
373 | UpVal *uv; | 373 | UpVal *uv; |
374 | checkliveness(g, &g->l_registry); | 374 | checkliveness(g, &g->l_registry); |
375 | lua_assert(!isdead(g, obj2gco(g->l_gt))); | ||
376 | checkstack(g, g->mainthread); | 375 | checkstack(g, g->mainthread); |
377 | for (o = g->allgc; o != NULL; o = gch(o)->next) { | 376 | for (o = g->allgc; o != NULL; o = gch(o)->next) { |
378 | lua_assert(!testbits(o->gch.marked, bitmask(SEPARATED))); | 377 | lua_assert(!testbits(o->gch.marked, bitmask(SEPARATED))); |