mirror of
https://github.com/lua/lua.git
synced 2026-08-12 08:11:53 +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:
@@ -1,10 +1,15 @@
|
||||
-- track collections
|
||||
|
||||
|
||||
local M = {}
|
||||
|
||||
-- import list
|
||||
local setmetatable, stderr, collectgarbage =
|
||||
setmetatable, io.stderr, collectgarbage
|
||||
local stderr, collectgarbage = io.stderr, collectgarbage
|
||||
|
||||
-- the debug version of setmetatable does not create any object (such as
|
||||
-- a '__metatable' string), and so it is more appropriate to be used in
|
||||
-- a finalizer
|
||||
local setmetatable = require"debug".setmetatable
|
||||
|
||||
global none
|
||||
|
||||
|
||||
Reference in New Issue
Block a user