aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-06 14:06:47 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-06 14:06:47 -0300
commit314c6057b785cd94ac88905ccfce61724107d66b (patch)
tree6948ee4fec2cacb850307dab1632bfdb4f777459 /lstate.c
parentd39ea8b3ce684728c1ad5005192766d39d2e8baa (diff)
downloadlua-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.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lstate.c b/lstate.c
index b1f487ff..28853dc7 100644
--- a/lstate.c
+++ b/lstate.c
@@ -318,9 +318,10 @@ static void close_state (lua_State *L) {
318 318
319 319
320LUA_API lua_State *lua_newthread (lua_State *L) { 320LUA_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
439LUA_API void lua_close (lua_State *L) { 440LUA_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