diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-21 15:21:45 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-21 15:21:45 -0300 |
commit | f9d29b0c442447ebe429bcaad1e2b4bf13c5dc93 (patch) | |
tree | 05864d5bb96e6efe207e7d7eeff0fd251494562b /testes | |
parent | 409256b7849ec5ab3296cb0ab9eba3d65955d5ea (diff) | |
download | lua-f9d29b0c442447ebe429bcaad1e2b4bf13c5dc93.tar.gz lua-f9d29b0c442447ebe429bcaad1e2b4bf13c5dc93.tar.bz2 lua-f9d29b0c442447ebe429bcaad1e2b4bf13c5dc93.zip |
Upvalues removed from 'openupval' before being closed
Undo commit c220b0a5d0: '__close' is not called again in case of
errors. (Upvalue is removed from the list before the call.) The
common error that justified that change was C stack overflows, which
are much rarer with the stackless implementation.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/locals.lua | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/testes/locals.lua b/testes/locals.lua index e2f6f35c..d32a9a3e 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
@@ -392,21 +392,13 @@ do print("testing errors in __close") | |||
392 | 392 | ||
393 | local y <close> = | 393 | local y <close> = |
394 | func2close(function (self, msg) | 394 | func2close(function (self, msg) |
395 | assert(string.find(msg, "@z")) -- first error in 'z' | 395 | assert(string.find(msg, "@z")) -- error in 'z' |
396 | checkwarn("@z") -- second error in 'z' generated a warning | ||
397 | error("@y") | 396 | error("@y") |
398 | end) | 397 | end) |
399 | 398 | ||
400 | local first = true | ||
401 | local z <close> = | 399 | local z <close> = |
402 | -- 'z' close is called twice | ||
403 | func2close(function (self, msg) | 400 | func2close(function (self, msg) |
404 | if first then | 401 | assert(msg == nil) |
405 | assert(msg == nil) | ||
406 | first = false | ||
407 | else | ||
408 | assert(string.find(msg, "@z")) -- own error | ||
409 | end | ||
410 | error("@z") | 402 | error("@z") |
411 | end) | 403 | end) |
412 | 404 | ||
@@ -468,8 +460,8 @@ do print("testing errors in __close") | |||
468 | local function foo (...) | 460 | local function foo (...) |
469 | do | 461 | do |
470 | local x1 <close> = | 462 | local x1 <close> = |
471 | func2close(function () | 463 | func2close(function (self, msg) |
472 | checkwarn("@X") | 464 | assert(string.find(msg, "@X")) |
473 | error("@Y") | 465 | error("@Y") |
474 | end) | 466 | end) |
475 | 467 | ||
@@ -494,8 +486,6 @@ do print("testing errors in __close") | |||
494 | local st, msg = xpcall(foo, debug.traceback) | 486 | local st, msg = xpcall(foo, debug.traceback) |
495 | assert(string.match(msg, "^[^ ]* @x123")) | 487 | assert(string.match(msg, "^[^ ]* @x123")) |
496 | assert(string.find(msg, "in metamethod 'close'")) | 488 | assert(string.find(msg, "in metamethod 'close'")) |
497 | checkwarn("@x123") -- from second call to close 'x123' | ||
498 | |||
499 | endwarn() | 489 | endwarn() |
500 | end | 490 | end |
501 | 491 | ||
@@ -686,8 +676,10 @@ do | |||
686 | local x = 0 | 676 | local x = 0 |
687 | local y = 0 | 677 | local y = 0 |
688 | co = coroutine.wrap(function () | 678 | co = coroutine.wrap(function () |
689 | local xx <close> = func2close(function () | 679 | local xx <close> = func2close(function (_, err) |
690 | y = y + 1; checkwarn("XXX"); error("YYY") | 680 | y = y + 1; |
681 | assert(string.find(err, "XXX")) | ||
682 | error("YYY") | ||
691 | end) | 683 | end) |
692 | local xv <close> = func2close(function () | 684 | local xv <close> = func2close(function () |
693 | x = x + 1; error("XXX") | 685 | x = x + 1; error("XXX") |
@@ -697,7 +689,7 @@ do | |||
697 | end) | 689 | end) |
698 | assert(co() == 100); assert(x == 0) | 690 | assert(co() == 100); assert(x == 0) |
699 | local st, msg = pcall(co) | 691 | local st, msg = pcall(co) |
700 | assert(x == 2 and y == 1) -- first close is called twice | 692 | assert(x == 1 and y == 1) |
701 | -- should get first error raised | 693 | -- should get first error raised |
702 | assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX")) | 694 | assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX")) |
703 | checkwarn("YYY") | 695 | checkwarn("YYY") |