From c3f2162aff49b0ebb74b3eec635af0ffd66b4f21 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 4 Feb 2024 16:11:24 +0100 Subject: [PATCH] added the bug fixes from liblua5.2.4 --- client/deps/liblua/ldebug.c | 57 ++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/client/deps/liblua/ldebug.c b/client/deps/liblua/ldebug.c index b29de55fc..3eee0beb6 100644 --- a/client/deps/liblua/ldebug.c +++ b/client/deps/liblua/ldebug.c @@ -32,9 +32,16 @@ #define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL) - static const char *getfuncname(lua_State *L, CallInfo *ci, const char **name); +static void swapextra (lua_State *L) { + if (L->status == LUA_YIELD) { + CallInfo *ci = L->ci; /* get function that yielded */ + StkId temp = ci->func; /* exchange its 'func' and 'extra' values */ + ci->func = restorestack(L, ci->extra); + ci->extra = savestack(L, temp); + } +} static int currentpc(CallInfo *ci) { lua_assert(isLua(ci)); @@ -115,8 +122,7 @@ static const char *findvararg(CallInfo *ci, int n, StkId *pos) { } -static const char *findlocal(lua_State *L, CallInfo *ci, int n, - StkId *pos) { +static const char *findlocal(lua_State *L, CallInfo *ci, int n, StkId *pos) { const char *name = NULL; StkId base; if (isLua(ci)) { @@ -143,6 +149,7 @@ static const char *findlocal(lua_State *L, CallInfo *ci, int n, LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) { const char *name; lua_lock(L); + swapextra(L); if (ar == NULL) { /* information about non-active function? */ if (!isLfunction(L->top - 1)) /* not a Lua function? */ name = NULL; @@ -156,6 +163,7 @@ LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) { api_incr_top(L); } } + swapextra(L); lua_unlock(L); return name; } @@ -163,11 +171,15 @@ LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) { LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n) { StkId pos = 0; /* to avoid warnings */ - const char *name = findlocal(L, ar->i_ci, n, &pos); + const char *name; lua_lock(L); - if (name) + swapextra(L); + name = findlocal(L, ar->i_ci, n, &pos); + if (name) { setobjs2s(L, pos, L->top - 1); + } L->top--; /* pop value */ + swapextra(L); lua_unlock(L); return name; } @@ -265,6 +277,8 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) { CallInfo *ci; StkId func; lua_lock(L); + swapextra(L); + if (*what == '>') { ci = NULL; func = L->top - 1; @@ -282,8 +296,11 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) { setobjs2s(L, L->top, func); api_incr_top(L); } - if (strchr(what, 'L')) + + swapextra(L); + if (strchr(what, 'L')) { collectvalidlines(L, cl); + } lua_unlock(L); return status; } @@ -320,6 +337,12 @@ static void kname(Proto *p, int pc, int c, const char **name) { *name = "?"; /* no reasonable name found */ } +static int filterpc (int pc, int jmptarget) { + if (pc < jmptarget) /* is code conditional (inside a jump)? */ + return -1; /* cannot know who sets that register */ + else + return pc; /* current position sets that register */ +} /* ** try to find last instruction before 'lastpc' that modified register 'reg' @@ -327,6 +350,7 @@ static void kname(Proto *p, int pc, int c, const char **name) { static int findsetreg(Proto *p, int lastpc, int reg) { int pc; int setreg = -1; /* keep last instruction that changed 'reg' */ + int jmptarget = 0; /* any code before this address is conditional */ for (pc = 0; pc < lastpc; pc++) { Instruction i = p->code[pc]; OpCode op = GET_OPCODE(i); @@ -335,33 +359,40 @@ static int findsetreg(Proto *p, int lastpc, int reg) { case OP_LOADNIL: { int b = GETARG_B(i); if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */ - setreg = pc; + setreg = filterpc(pc, jmptarget); break; } case OP_TFORCALL: { - if (reg >= a + 2) setreg = pc; /* affect all regs above its base */ + if (reg >= a + 2) /* affect all regs above its base */ + setreg = filterpc(pc, jmptarget); break; } case OP_CALL: case OP_TAILCALL: { - if (reg >= a) setreg = pc; /* affect all registers above base */ + if (reg >= a) /* affect all registers above base */ + filterpc(pc, jmptarget); break; } case OP_JMP: { int b = GETARG_sBx(i); int dest = pc + 1 + b; /* jump is forward and do not skip `lastpc'? */ - if (pc < dest && dest <= lastpc) + if (pc < dest && dest <= lastpc) { pc += b; /* do the jump */ + if (dest > jmptarget) { + jmptarget = dest; /* update 'jmptarget' */ + } + } break; } case OP_TEST: { - if (reg == a) setreg = pc; /* jumped code can change 'a' */ + if (reg == a) /* jumped code can change 'a' */ + filterpc(pc, jmptarget); break; } default: if (testAMode(op) && reg == a) /* any instruction that set A */ - setreg = pc; + filterpc(pc, jmptarget); break; } } @@ -541,7 +572,7 @@ l_noret luaG_typeerror(lua_State *L, const TValue *o, const char *op) { l_noret luaG_concaterror(lua_State *L, StkId p1, StkId p2) { if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; - lua_assert(!ttisstring(p1) && !ttisnumber(p2)); + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); luaG_typeerror(L, p1, "concatenate"); }