diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-09 11:13:45 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-09 11:13:45 -0300 |
commit | 389116d8abcc96db3cfe2f3cc25789c089fe12d6 (patch) | |
tree | f3d07b50c17f28ba09cf547d5a67519ffe3271a4 /testes/db.lua | |
parent | 01bded3d8cd88a2d7f472b45f706565f1a9ef3b1 (diff) | |
download | lua-389116d8abcc96db3cfe2f3cc25789c089fe12d6.tar.gz lua-389116d8abcc96db3cfe2f3cc25789c089fe12d6.tar.bz2 lua-389116d8abcc96db3cfe2f3cc25789c089fe12d6.zip |
Coroutines do not unwind the stack in case of errors
Back to how it was, a coroutine does not unwind its stack in case of
errors (and therefore do not close its to-be-closed variables). This
allows the stack to be examined after the error. The program can
use 'coroutine.kill' to close the variables.
The function created by 'coroutine.wrap', however, closes the
coroutine's variables in case of errors, as it is impossible to examine
the stack any way.
Diffstat (limited to 'testes/db.lua')
-rw-r--r-- | testes/db.lua | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/testes/db.lua b/testes/db.lua index 95275fb4..3d94f776 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
@@ -734,18 +734,24 @@ a, b = coroutine.resume(co, 100) | |||
734 | assert(a and b == 30) | 734 | assert(a and b == 30) |
735 | 735 | ||
736 | 736 | ||
737 | -- check traceback of suspended coroutines | 737 | -- check traceback of suspended (or dead with error) coroutines |
738 | |||
739 | function f(i) | ||
740 | if i == 0 then error(i) | ||
741 | else coroutine.yield(); f(i-1) | ||
742 | end | ||
743 | end | ||
738 | 744 | ||
739 | function f(i) coroutine.yield(i == 0); f(i - 1) end | ||
740 | 745 | ||
741 | co = coroutine.create(function (x) f(x) end) | 746 | co = coroutine.create(function (x) f(x) end) |
742 | a, b = coroutine.resume(co, 3) | 747 | a, b = coroutine.resume(co, 3) |
743 | t = {"'coroutine.yield'", "'f'", "in function <"} | 748 | t = {"'coroutine.yield'", "'f'", "in function <"} |
744 | repeat | 749 | while coroutine.status(co) == "suspended" do |
745 | checktraceback(co, t) | 750 | checktraceback(co, t) |
746 | a, b = coroutine.resume(co) | 751 | a, b = coroutine.resume(co) |
747 | table.insert(t, 2, "'f'") -- one more recursive call to 'f' | 752 | table.insert(t, 2, "'f'") -- one more recursive call to 'f' |
748 | until b | 753 | end |
754 | t[1] = "'error'" | ||
749 | checktraceback(co, t) | 755 | checktraceback(co, t) |
750 | 756 | ||
751 | 757 | ||