aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-11-18 11:13:47 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-11-18 11:13:47 -0200
commitce444bff336b333251ac3745f311bd9033be8f6a (patch)
tree92a3de426c0e4b66420dd3b6a911d45b3f5fd03d /lstate.c
parent2d5931ebc8c3136bae92b5c502f3de0f06c31364 (diff)
downloadlua-ce444bff336b333251ac3745f311bd9033be8f6a.tar.gz
lua-ce444bff336b333251ac3745f311bd9033be8f6a.tar.bz2
lua-ce444bff336b333251ac3745f311bd9033be8f6a.zip
(huge) simplification of GC management
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/lstate.c b/lstate.c
index cb52eac3..f02c17ed 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.62 2009/10/05 16:44:33 roberto Exp roberto $ 2** $Id: lstate.c,v 2.63 2009/10/23 19:12:19 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*/
@@ -139,7 +139,6 @@ static void f_luaopen (lua_State *L, void *ud) {
139 luaT_init(L); 139 luaT_init(L);
140 luaX_init(L); 140 luaX_init(L);
141 luaS_fix(luaS_newliteral(L, MEMERRMSG)); 141 luaS_fix(luaS_newliteral(L, MEMERRMSG));
142 g->estimate = g->totalbytes;
143 g->GCthreshold = 4*g->totalbytes; 142 g->GCthreshold = 4*g->totalbytes;
144} 143}
145 144
@@ -170,7 +169,7 @@ static void preinit_state (lua_State *L, global_State *g) {
170static void close_state (lua_State *L) { 169static void close_state (lua_State *L) {
171 global_State *g = G(L); 170 global_State *g = G(L);
172 luaF_close(L, L->stack); /* close all upvalues for this thread */ 171 luaF_close(L, L->stack); /* close all upvalues for this thread */
173 luaC_freeall(L); /* collect all objects */ 172 luaC_freeallobjects(L); /* collect all objects */
174 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); 173 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
175 luaZ_freebuffer(L, &g->buff); 174 luaZ_freebuffer(L, &g->buff);
176 freestack(L); 175 freestack(L);
@@ -241,16 +240,10 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
241 g->version = lua_version(NULL); 240 g->version = lua_version(NULL);
242 g->gcstate = GCSpause; 241 g->gcstate = GCSpause;
243 g->rootgc = obj2gco(L); 242 g->rootgc = obj2gco(L);
244 g->sweepstrgc = 0;
245 g->sweepgc = &g->rootgc;
246 g->gray = NULL;
247 g->grayagain = NULL;
248 g->weak = g->ephemeron = g->allweak = NULL;
249 g->tobefnz = NULL; 243 g->tobefnz = NULL;
250 g->estimate = g->totalbytes = sizeof(LG); 244 g->totalbytes = sizeof(LG);
251 g->gcpause = LUAI_GCPAUSE; 245 g->gcpause = LUAI_GCPAUSE;
252 g->gcstepmul = LUAI_GCMUL; 246 g->gcstepmul = LUAI_GCMUL;
253 g->gcdept = 0;
254 for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL; 247 for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
255 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { 248 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
256 /* memory allocation error: free partial state */ 249 /* memory allocation error: free partial state */
@@ -269,7 +262,6 @@ LUA_API void lua_close (lua_State *L) {
269 luaF_close(L, L->stack); /* close all upvalues for this thread */ 262 luaF_close(L, L->stack); /* close all upvalues for this thread */
270 luaC_separateudata(L, 1); /* separate all udata with GC metamethods */ 263 luaC_separateudata(L, 1); /* separate all udata with GC metamethods */
271 lua_assert(L->next == NULL); 264 lua_assert(L->next == NULL);
272 luaC_callAllGCTM(L); /* call GC metamethods for all udata */
273 luai_userstateclose(L); 265 luai_userstateclose(L);
274 close_state(L); 266 close_state(L);
275} 267}