From 49262cd57cf7b8589585e0bac0bc7d3d83936d34 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 23 Oct 2023 01:10:33 +0300 Subject: [PATCH 51/51] Apply lua-5.4.6 upsteam patch 2 See osdn #48895 Signed-off-by: Marko Lindqvist --- dependencies/lua-5.4/Version.txt | 2 +- dependencies/lua-5.4/src/ldebug.c | 22 ++++++++++++++++++++++ dependencies/lua-5.4/src/ldebug.h | 1 + dependencies/lua-5.4/src/lstate.h | 2 +- dependencies/lua-5.4/src/lvm.c | 13 +++---------- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/dependencies/lua-5.4/Version.txt b/dependencies/lua-5.4/Version.txt index dc5bb214cc..5e6065ad1c 100644 --- a/dependencies/lua-5.4/Version.txt +++ b/dependencies/lua-5.4/Version.txt @@ -2,7 +2,7 @@ Sources here are from lua-5.4.6 (http://www.lua.org/ftp/lua-5.4.6.tar.gz) Upstream bug fixes from https://www.lua.org/bugs.html applied: -1 +1, 2 Not entire lua distribution directory hierarchy is included here, and some files needed for Freeciv usage have been added. diff --git a/dependencies/lua-5.4/src/ldebug.c b/dependencies/lua-5.4/src/ldebug.c index 28b1caabf7..195d02f802 100644 --- a/dependencies/lua-5.4/src/ldebug.c +++ b/dependencies/lua-5.4/src/ldebug.c @@ -865,6 +865,28 @@ static int changedline (const Proto *p, int oldpc, int newpc) { } +/* +** Traces Lua calls. If code is running the first instruction of a function, +** and function is not vararg, and it is not coming from an yield, +** calls 'luaD_hookcall'. (Vararg functions will call 'luaD_hookcall' +** after adjusting its variable arguments; otherwise, they could call +** a line/count hook before the call hook. Functions coming from +** an yield already called 'luaD_hookcall' before yielding.) +*/ +int luaG_tracecall (lua_State *L) { + CallInfo *ci = L->ci; + Proto *p = ci_func(ci)->p; + ci->u.l.trap = 1; /* ensure hooks will be checked */ + if (ci->u.l.savedpc == p->code) { /* first instruction (not resuming)? */ + if (p->is_vararg) + return 0; /* hooks will start at VARARGPREP instruction */ + else if (!(ci->callstatus & CIST_HOOKYIELD)) /* not yieded? */ + luaD_hookcall(L, ci); /* check 'call' hook */ + } + return 1; /* keep 'trap' on */ +} + + /* ** Traces the execution of a Lua function. Called before the execution ** of each opcode, when debug is on. 'L->oldpc' stores the last diff --git a/dependencies/lua-5.4/src/ldebug.h b/dependencies/lua-5.4/src/ldebug.h index 2c3074c61b..2bfce3cb5e 100644 --- a/dependencies/lua-5.4/src/ldebug.h +++ b/dependencies/lua-5.4/src/ldebug.h @@ -58,6 +58,7 @@ LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, TString *src, int line); LUAI_FUNC l_noret luaG_errormsg (lua_State *L); LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); +LUAI_FUNC int luaG_tracecall (lua_State *L); #endif diff --git a/dependencies/lua-5.4/src/lstate.h b/dependencies/lua-5.4/src/lstate.h index 40ff89aaa7..007704c826 100644 --- a/dependencies/lua-5.4/src/lstate.h +++ b/dependencies/lua-5.4/src/lstate.h @@ -181,7 +181,7 @@ struct CallInfo { union { struct { /* only for Lua functions */ const Instruction *savedpc; - volatile l_signalT trap; + volatile l_signalT trap; /* function is tracing lines/counts */ int nextraargs; /* # of extra arguments in vararg functions */ } l; struct { /* only for C functions */ diff --git a/dependencies/lua-5.4/src/lvm.c b/dependencies/lua-5.4/src/lvm.c index 8493a770c5..6c194291c2 100644 --- a/dependencies/lua-5.4/src/lvm.c +++ b/dependencies/lua-5.4/src/lvm.c @@ -1155,18 +1155,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { startfunc: trap = L->hookmask; returning: /* trap already set */ - cl = clLvalue(s2v(ci->func.p)); + cl = ci_func(ci); k = cl->p->k; pc = ci->u.l.savedpc; - if (l_unlikely(trap)) { - if (pc == cl->p->code) { /* first instruction (not resuming)? */ - if (cl->p->is_vararg) - trap = 0; /* hooks will start after VARARGPREP instruction */ - else /* check 'call' hook */ - luaD_hookcall(L, ci); - } - ci->u.l.trap = 1; /* assume trap is on, for now */ - } + if (l_unlikely(trap)) + trap = luaG_tracecall(L); base = ci->func.p + 1; /* main loop of interpreter */ for (;;) { -- 2.42.0