aboutsummaryrefslogtreecommitdiff
path: root/testes
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 /testes
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 'testes')
-rw-r--r--testes/coroutine.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index de7e46fb..e566c86e 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -610,18 +610,20 @@ else
610 -- (bug in 5.2/5.3) 610 -- (bug in 5.2/5.3)
611 c = coroutine.create(function (a, ...) 611 c = coroutine.create(function (a, ...)
612 T.sethook("yield 0", "l") -- will yield on next two lines 612 T.sethook("yield 0", "l") -- will yield on next two lines
613 assert(a == 10) 613 local b = a
614 return ... 614 return ...
615 end) 615 end)
616 616
617 assert(coroutine.resume(c, 1, 2, 3)) -- start coroutine 617 assert(coroutine.resume(c, 1, 2, 3)) -- start coroutine
618 local n,v = debug.getlocal(c, 0, 1) -- check its local 618 local n,v = debug.getlocal(c, 0, 1) -- check its local
619 assert(n == "a" and v == 1) 619 assert(n == "a" and v == 1 and debug.getlocal(c, 0, 2) ~= "b")
620 assert(debug.setlocal(c, 0, 1, 10)) -- test 'setlocal' 620 assert(debug.setlocal(c, 0, 1, 10)) -- test 'setlocal'
621 local t = debug.getinfo(c, 0) -- test 'getinfo' 621 local t = debug.getinfo(c, 0) -- test 'getinfo'
622 assert(t.currentline == t.linedefined + 1) 622 assert(t.currentline == t.linedefined + 2)
623 assert(not debug.getinfo(c, 1)) -- no other level 623 assert(not debug.getinfo(c, 1)) -- no other level
624 assert(coroutine.resume(c)) -- run next line 624 assert(coroutine.resume(c)) -- run next line
625 local n,v = debug.getlocal(c, 0, 2) -- check next local
626 assert(n == "b" and v == 10)
625 v = {coroutine.resume(c)} -- finish coroutine 627 v = {coroutine.resume(c)} -- finish coroutine
626 assert(v[1] == true and v[2] == 2 and v[3] == 3 and v[4] == undef) 628 assert(v[1] == true and v[2] == 2 and v[3] == 3 and v[4] == undef)
627 assert(not coroutine.resume(c)) 629 assert(not coroutine.resume(c))