From f9d29b0c442447ebe429bcaad1e2b4bf13c5dc93 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 21 Dec 2020 15:21:45 -0300 Subject: 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. --- testes/locals.lua | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'testes') 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") local y = func2close(function (self, msg) - assert(string.find(msg, "@z")) -- first error in 'z' - checkwarn("@z") -- second error in 'z' generated a warning + assert(string.find(msg, "@z")) -- error in 'z' error("@y") end) - local first = true local z = - -- 'z' close is called twice func2close(function (self, msg) - if first then - assert(msg == nil) - first = false - else - assert(string.find(msg, "@z")) -- own error - end + assert(msg == nil) error("@z") end) @@ -468,8 +460,8 @@ do print("testing errors in __close") local function foo (...) do local x1 = - func2close(function () - checkwarn("@X") + func2close(function (self, msg) + assert(string.find(msg, "@X")) error("@Y") end) @@ -494,8 +486,6 @@ do print("testing errors in __close") local st, msg = xpcall(foo, debug.traceback) assert(string.match(msg, "^[^ ]* @x123")) assert(string.find(msg, "in metamethod 'close'")) - checkwarn("@x123") -- from second call to close 'x123' - endwarn() end @@ -686,8 +676,10 @@ do local x = 0 local y = 0 co = coroutine.wrap(function () - local xx = func2close(function () - y = y + 1; checkwarn("XXX"); error("YYY") + local xx = func2close(function (_, err) + y = y + 1; + assert(string.find(err, "XXX")) + error("YYY") end) local xv = func2close(function () x = x + 1; error("XXX") @@ -697,7 +689,7 @@ do end) assert(co() == 100); assert(x == 0) local st, msg = pcall(co) - assert(x == 2 and y == 1) -- first close is called twice + assert(x == 1 and y == 1) -- should get first error raised assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX")) checkwarn("YYY") -- cgit v1.2.3-55-g6feb