Avoid any code before locks in the API

For consistency in the C API, avoid any initializations before
callling lua_lock.
This commit is contained in:
Roberto Ierusalimschy
2020-07-06 14:06:47 -03:00
parent d39ea8b3ce
commit 314c6057b7
3 changed files with 22 additions and 12 deletions

View File

@@ -318,9 +318,10 @@ static void close_state (lua_State *L) {
LUA_API lua_State *lua_newthread (lua_State *L) {
global_State *g = G(L);
global_State *g;
lua_State *L1;
lua_lock(L);
g = G(L);
luaC_checkGC(L);
/* create new thread */
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) {
LUA_API void lua_close (lua_State *L) {
L = G(L)->mainthread; /* only the main thread can be closed */
lua_lock(L);
L = G(L)->mainthread; /* only the main thread can be closed */
close_state(L);
}