From 921832be8d7f687d2cd891654c8680c6e9d6584c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 17 Mar 2025 14:32:08 -0300 Subject: New function 'resetCI' New function 'resetCI' resets the CallInfo list of a thread, ensuring a proper state when creating a new thread, closing a thread, or closing a state, so that we can run code after that. (When closing a thread, we need to run its __close metamethods; when closing a state, we need to run its __close metamethods and its finalizers.) --- testes/coroutine.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'testes') diff --git a/testes/coroutine.lua b/testes/coroutine.lua index 680fc605..17f6ceba 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua @@ -505,6 +505,25 @@ assert(not pcall(a, a)) a = nil +do + -- bug in 5.4: thread can use message handler higher in the stack + -- than the variable being closed + local c = coroutine.create(function() + local clo = setmetatable({}, {__close=function() + local x = 134 -- will overwrite message handler + error(x) + end}) + -- yields coroutine but leaves a new message handler for it, + -- that would be used when closing the coroutine (except that it + -- will be overwritten) + xpcall(coroutine.yield, function() return "XXX" end) + end) + + assert(coroutine.resume(c)) -- start coroutine + local st, msg = coroutine.close(c) + assert(not st and msg == 134) +end + -- access to locals of erroneous coroutines local x = coroutine.create (function () local a = 10 -- cgit v1.2.3-55-g6feb