aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-11 13:44:16 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-11 13:44:16 -0300
commite288c5a91883793d14ed9e9d93464f6ee0b08915 (patch)
treef563f9b4d218c9e35ff3e56eda068cfddb039651 /ldo.c
parent5853c37a83ec66ccb45094f9aeac23dfdbcde671 (diff)
downloadlua-e288c5a91883793d14ed9e9d93464f6ee0b08915.tar.gz
lua-e288c5a91883793d14ed9e9d93464f6ee0b08915.tar.bz2
lua-e288c5a91883793d14ed9e9d93464f6ee0b08915.zip
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.
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c4
1 files changed, 4 insertions, 0 deletions
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) {
792 lua_assert(L->status == LUA_YIELD); 792 lua_assert(L->status == LUA_YIELD);
793 L->status = LUA_OK; /* mark that it is running (again) */ 793 L->status = LUA_OK; /* mark that it is running (again) */
794 if (isLua(ci)) { /* yielded inside a hook? */ 794 if (isLua(ci)) { /* yielded inside a hook? */
795 /* undo increment made by 'luaG_traceexec': instruction was not
796 executed yet */
797 lua_assert(ci->callstatus & CIST_HOOKYIELD);
798 ci->u.l.savedpc--;
795 L->top.p = firstArg; /* discard arguments */ 799 L->top.p = firstArg; /* discard arguments */
796 luaV_execute(L, ci); /* just continue running Lua code */ 800 luaV_execute(L, ci); /* just continue running Lua code */
797 } 801 }