diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-06 14:06:47 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-06 14:06:47 -0300 |
commit | 314c6057b785cd94ac88905ccfce61724107d66b (patch) | |
tree | 6948ee4fec2cacb850307dab1632bfdb4f777459 /lstate.c | |
parent | d39ea8b3ce684728c1ad5005192766d39d2e8baa (diff) | |
download | lua-314c6057b785cd94ac88905ccfce61724107d66b.tar.gz lua-314c6057b785cd94ac88905ccfce61724107d66b.tar.bz2 lua-314c6057b785cd94ac88905ccfce61724107d66b.zip |
Avoid any code before locks in the API
For consistency in the C API, avoid any initializations before
callling lua_lock.
Diffstat (limited to 'lstate.c')
-rw-r--r-- | lstate.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -318,9 +318,10 @@ static void close_state (lua_State *L) { | |||
318 | 318 | ||
319 | 319 | ||
320 | LUA_API lua_State *lua_newthread (lua_State *L) { | 320 | LUA_API lua_State *lua_newthread (lua_State *L) { |
321 | global_State *g = G(L); | 321 | global_State *g; |
322 | lua_State *L1; | 322 | lua_State *L1; |
323 | lua_lock(L); | 323 | lua_lock(L); |
324 | g = G(L); | ||
324 | luaC_checkGC(L); | 325 | luaC_checkGC(L); |
325 | /* create new thread */ | 326 | /* create new thread */ |
326 | L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l; | 327 | L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l; |
@@ -437,8 +438,8 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
437 | 438 | ||
438 | 439 | ||
439 | LUA_API void lua_close (lua_State *L) { | 440 | LUA_API void lua_close (lua_State *L) { |
440 | L = G(L)->mainthread; /* only the main thread can be closed */ | ||
441 | lua_lock(L); | 441 | lua_lock(L); |
442 | L = G(L)->mainthread; /* only the main thread can be closed */ | ||
442 | close_state(L); | 443 | close_state(L); |
443 | } | 444 | } |
444 | 445 | ||