diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-25 16:44:06 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-25 16:44:06 -0300 |
| commit | 1e64c1391f9a14115b5cc82066dbf545ae73ee27 (patch) | |
| tree | 4aa3b6c2854c920ed825bf9fe46d275826e5ab6e /testes | |
| parent | b85816b9a884cbe4cfd139a8e11ffc28ecead576 (diff) | |
| download | lua-1e64c1391f9a14115b5cc82066dbf545ae73ee27.tar.gz lua-1e64c1391f9a14115b5cc82066dbf545ae73ee27.tar.bz2 lua-1e64c1391f9a14115b5cc82066dbf545ae73ee27.zip | |
Bug: stack overflow with nesting of coroutine.close
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/cstack.lua | 26 |
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 | |||
| 84 | end | 84 | end |
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | do -- bug since 5.4.0 | ||
| 88 | local count = 0 | ||
| 89 | print("chain of 'coroutine.close'") | ||
| 90 | -- create N coroutines forming a list so that each one, when closed, | ||
| 91 | -- closes the previous one. (With a large enough N, previous Lua | ||
| 92 | -- versions crash in this test.) | ||
| 93 | local coro = false | ||
| 94 | for i = 1, 1000 do | ||
| 95 | local previous = coro | ||
| 96 | coro = coroutine.create(function() | ||
| 97 | local cc <close> = setmetatable({}, {__close=function() | ||
| 98 | count = count + 1 | ||
| 99 | if previous then | ||
| 100 | assert(coroutine.close(previous)) | ||
| 101 | end | ||
| 102 | end}) | ||
| 103 | coroutine.yield() -- leaves 'cc' pending to be closed | ||
| 104 | end) | ||
| 105 | assert(coroutine.resume(coro)) -- start it and run until it yields | ||
| 106 | end | ||
| 107 | local st, msg = coroutine.close(coro) | ||
| 108 | assert(not st and string.find(msg, "C stack overflow")) | ||
| 109 | print("final count: ", count) | ||
| 110 | end | ||
| 111 | |||
| 112 | |||
| 87 | do | 113 | do |
| 88 | print("nesting of resuming yielded coroutines") | 114 | print("nesting of resuming yielded coroutines") |
| 89 | local count = 0 | 115 | local count = 0 |
