mirror of
https://github.com/lua/lua.git
synced 2026-06-08 08:03:49 +00:00
More effort in avoiding errors in finalizers
Before calling a finalizer, Lua not only checks stack limits, but actually ensures that a minimum number of slots are already allocated for the call. (If it cannot ensure that, it postpones the finalizer.) That avoids finalizers not running due to memory errors that the programmer cannot control.
This commit is contained in:
@@ -282,6 +282,25 @@ testamem("growing stack", function ()
|
||||
return foo(100)
|
||||
end)
|
||||
|
||||
|
||||
collectgarbage()
|
||||
collectgarbage()
|
||||
global io, T, setmetatable, collectgarbage, print
|
||||
|
||||
local Count = 0
|
||||
testamem("finalizers", function ()
|
||||
local X = false
|
||||
local obj = setmetatable({}, {__gc = function () X = true end})
|
||||
obj = nil
|
||||
T.resetCI() -- remove extra CallInfos
|
||||
T.reallocstack(18) -- remove extra stack slots
|
||||
Count = Count + 1
|
||||
io.stderr:write(Count, "\n")
|
||||
T.trick(io)
|
||||
collectgarbage()
|
||||
return X
|
||||
end)
|
||||
|
||||
-- }==================================================================
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user