diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-11-08 15:34:22 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-11-08 15:34:22 -0200 |
commit | de7cf8e63abac49100f99e60782575f940252cfd (patch) | |
tree | 951d2f7ae4a6b78f786f5e9d23c081e4f93f9d03 | |
parent | 124598917f4f314fdcb70a4165161999a645204e (diff) | |
download | lua-de7cf8e63abac49100f99e60782575f940252cfd.tar.gz lua-de7cf8e63abac49100f99e60782575f940252cfd.tar.bz2 lua-de7cf8e63abac49100f99e60782575f940252cfd.zip |
bug: should call 'luai_userstateclose' only when 'luai_userstateopen'
has been called before
-rw-r--r-- | lstate.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.114 2013/09/13 16:21:52 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.115 2013/09/17 15:40:06 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 | */ |
@@ -199,7 +199,8 @@ static void init_registry (lua_State *L, global_State *g) { | |||
199 | 199 | ||
200 | 200 | ||
201 | /* | 201 | /* |
202 | ** open parts of the state that may cause memory-allocation errors | 202 | ** open parts of the state that may cause memory-allocation errors. |
203 | ** ('g->version' != NULL flags that the state was completely build) | ||
203 | */ | 204 | */ |
204 | static void f_luaopen (lua_State *L, void *ud) { | 205 | static void f_luaopen (lua_State *L, void *ud) { |
205 | global_State *g = G(L); | 206 | global_State *g = G(L); |
@@ -213,6 +214,8 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
213 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); | 214 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); |
214 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ | 215 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ |
215 | g->gcrunning = 1; /* allow gc */ | 216 | g->gcrunning = 1; /* allow gc */ |
217 | g->version = lua_version(NULL); | ||
218 | luai_userstateopen(L); | ||
216 | } | 219 | } |
217 | 220 | ||
218 | 221 | ||
@@ -243,6 +246,8 @@ static void close_state (lua_State *L) { | |||
243 | global_State *g = G(L); | 246 | global_State *g = G(L); |
244 | luaF_close(L, L->stack); /* close all upvalues for this thread */ | 247 | luaF_close(L, L->stack); /* close all upvalues for this thread */ |
245 | luaC_freeallobjects(L); /* collect all objects */ | 248 | luaC_freeallobjects(L); /* collect all objects */ |
249 | if (g->version) /* closing a fully built state? */ | ||
250 | luai_userstateclose(L); | ||
246 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); | 251 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); |
247 | luaZ_freebuffer(L, &g->buff); | 252 | luaZ_freebuffer(L, &g->buff); |
248 | freestack(L); | 253 | freestack(L); |
@@ -313,7 +318,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
313 | setnilvalue(&g->l_registry); | 318 | setnilvalue(&g->l_registry); |
314 | luaZ_initbuffer(L, &g->buff); | 319 | luaZ_initbuffer(L, &g->buff); |
315 | g->panic = NULL; | 320 | g->panic = NULL; |
316 | g->version = lua_version(NULL); | 321 | g->version = NULL; |
317 | g->gcstate = GCSpause; | 322 | g->gcstate = GCSpause; |
318 | g->localgc = g->localfin = g->allgc = g->finobj = NULL; | 323 | g->localgc = g->localfin = g->allgc = g->finobj = NULL; |
319 | g->tobefnz = NULL; | 324 | g->tobefnz = NULL; |
@@ -332,8 +337,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
332 | close_state(L); | 337 | close_state(L); |
333 | L = NULL; | 338 | L = NULL; |
334 | } | 339 | } |
335 | else | ||
336 | luai_userstateopen(L); | ||
337 | return L; | 340 | return L; |
338 | } | 341 | } |
339 | 342 | ||
@@ -341,7 +344,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
341 | LUA_API void lua_close (lua_State *L) { | 344 | LUA_API void lua_close (lua_State *L) { |
342 | L = G(L)->mainthread; /* only the main thread can be closed */ | 345 | L = G(L)->mainthread; /* only the main thread can be closed */ |
343 | lua_lock(L); | 346 | lua_lock(L); |
344 | luai_userstateclose(L); | ||
345 | close_state(L); | 347 | close_state(L); |
346 | } | 348 | } |
347 | 349 | ||