summaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-10-25 16:44:06 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-10-25 16:44:06 -0300
commit1e64c1391f9a14115b5cc82066dbf545ae73ee27 (patch)
tree4aa3b6c2854c920ed825bf9fe46d275826e5ab6e /testes
parentb85816b9a884cbe4cfd139a8e11ffc28ecead576 (diff)
downloadlua-github-1e64c1391f9a14115b5cc82066dbf545ae73ee27.tar.gz
Bug: stack overflow with nesting of coroutine.close
Diffstat (limited to 'testes')
-rw-r--r--testes/cstack.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/testes/cstack.lua b/testes/cstack.lua
index ca76c872..97afe9fd 100644
--- a/testes/cstack.lua
+++ b/testes/cstack.lua
@@ -84,6 +84,32 @@ do -- bug in 5.4.0
end
+do -- bug since 5.4.0
+ local count = 0
+ print("chain of 'coroutine.close'")
+ -- create N coroutines forming a list so that each one, when closed,
+ -- closes the previous one. (With a large enough N, previous Lua
+ -- versions crash in this test.)
+ local coro = false
+ for i = 1, 1000 do
+ local previous = coro
+ coro = coroutine.create(function()
+ local cc <close> = setmetatable({}, {__close=function()
+ count = count + 1
+ if previous then
+ assert(coroutine.close(previous))
+ end
+ end})
+ coroutine.yield() -- leaves 'cc' pending to be closed
+ end)
+ assert(coroutine.resume(coro)) -- start it and run until it yields
+ end
+ local st, msg = coroutine.close(coro)
+ assert(not st and string.find(msg, "C stack overflow"))
+ print("final count: ", count)
+end
+
+
do
print("nesting of resuming yielded coroutines")
local count = 0