summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-11-08 15:45:31 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-11-08 15:45:31 -0200
commit2fb7d94bd606715d0163cab7b4546f8a4d1f3426 (patch)
tree44d3830b92678ab692cdb7a14f3ef0252d158b9d
parentc23f7053495934bc7fbce7328af1e7f03f248de1 (diff)
downloadlua-2fb7d94bd606715d0163cab7b4546f8a4d1f3426.tar.gz
lua-2fb7d94bd606715d0163cab7b4546f8a4d1f3426.tar.bz2
lua-2fb7d94bd606715d0163cab7b4546f8a4d1f3426.zip
bug: Call to macro 'luai_userstateclose' should be done only
after the calls to __gc methods.
-rw-r--r--lstate.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lstate.c b/lstate.c
index 207a106d..e20507db 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.99 2012/10/02 17:40:53 roberto Exp $ 2** $Id: lstate.c,v 2.99.1.1 2013/04/12 18:48:47 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*/
@@ -192,6 +192,8 @@ static void f_luaopen (lua_State *L, void *ud) {
192 g->memerrmsg = luaS_newliteral(L, MEMERRMSG); 192 g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
193 luaS_fix(g->memerrmsg); /* it should never be collected */ 193 luaS_fix(g->memerrmsg); /* it should never be collected */
194 g->gcrunning = 1; /* allow gc */ 194 g->gcrunning = 1; /* allow gc */
195 g->version = lua_version(NULL);
196 luai_userstateopen(L);
195} 197}
196 198
197 199
@@ -222,6 +224,8 @@ static void close_state (lua_State *L) {
222 global_State *g = G(L); 224 global_State *g = G(L);
223 luaF_close(L, L->stack); /* close all upvalues for this thread */ 225 luaF_close(L, L->stack); /* close all upvalues for this thread */
224 luaC_freeallobjects(L); /* collect all objects */ 226 luaC_freeallobjects(L); /* collect all objects */
227 if (g->version) /* closing a fully built state? */
228 luai_userstateclose(L);
225 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); 229 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
226 luaZ_freebuffer(L, &g->buff); 230 luaZ_freebuffer(L, &g->buff);
227 freestack(L); 231 freestack(L);
@@ -287,7 +291,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
287 setnilvalue(&g->l_registry); 291 setnilvalue(&g->l_registry);
288 luaZ_initbuffer(L, &g->buff); 292 luaZ_initbuffer(L, &g->buff);
289 g->panic = NULL; 293 g->panic = NULL;
290 g->version = lua_version(NULL); 294 g->version = NULL;
291 g->gcstate = GCSpause; 295 g->gcstate = GCSpause;
292 g->allgc = NULL; 296 g->allgc = NULL;
293 g->finobj = NULL; 297 g->finobj = NULL;
@@ -306,8 +310,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
306 close_state(L); 310 close_state(L);
307 L = NULL; 311 L = NULL;
308 } 312 }
309 else
310 luai_userstateopen(L);
311 return L; 313 return L;
312} 314}
313 315
@@ -315,7 +317,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
315LUA_API void lua_close (lua_State *L) { 317LUA_API void lua_close (lua_State *L) {
316 L = G(L)->mainthread; /* only the main thread can be closed */ 318 L = G(L)->mainthread; /* only the main thread can be closed */
317 lua_lock(L); 319 lua_lock(L);
318 luai_userstateclose(L);
319 close_state(L); 320 close_state(L);
320} 321}
321 322