From e288c5a91883793d14ed9e9d93464f6ee0b08915 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 11 Jan 2024 13:44:16 -0300 Subject: Bug: Yielding in a hook stops in the wrong instruction Yielding in a hook must decrease the program counter, because it already counted an instruction that, in the end, was not executed. However, that decrement should be done only when about to restart the thread. Otherwise, inspecting the thread with the debug library shows it one instruction behind of where it really is. --- ldo.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ldo.c') diff --git a/ldo.c b/ldo.c index bd8d965f..ea052950 100644 --- a/ldo.c +++ b/ldo.c @@ -792,6 +792,10 @@ static void resume (lua_State *L, void *ud) { lua_assert(L->status == LUA_YIELD); L->status = LUA_OK; /* mark that it is running (again) */ if (isLua(ci)) { /* yielded inside a hook? */ + /* undo increment made by 'luaG_traceexec': instruction was not + executed yet */ + lua_assert(ci->callstatus & CIST_HOOKYIELD); + ci->u.l.savedpc--; L->top.p = firstArg; /* discard arguments */ luaV_execute(L, ci); /* just continue running Lua code */ } -- cgit v1.2.3-55-g6feb