commit 0f1cd0eba99ea6d383e75b9ae488d00ad541c210
parent 127e7a6c8942b362aa3c6627f44d660a4fb75312
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 13 Jul 2020 13:36:34 -0300
Added test for fix 127e7a6c894
Diffstat:
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/testes/gengc.lua b/testes/gengc.lua
@@ -37,6 +37,33 @@ do
end
+do -- bug in 5.4.0
+-- When an object aged OLD1 is finalized, it is moved from the list
+-- 'finobj' to the *beginning* of the list 'allgc', but that part of the
+-- list was not being visited by 'markold'.
+ local A = {}
+ A[1] = false -- old anchor for object
+
+ -- obj finalizer
+ local function gcf (obj)
+ A[1] = obj -- anchor object
+ assert(not T or T.gcage(obj) == "old1")
+ obj = nil -- remove it from the stack
+ collectgarbage("step", 0) -- do a young collection
+ print(getmetatable(A[1]).x) -- metatable was collected
+ end
+
+ collectgarbage() -- make A old
+ local obj = {} -- create a new object
+ collectgarbage("step", 0) -- make it a survival
+ assert(not T or T.gcage(obj) == "survival")
+ setmetatable(obj, {__gc = gcf, x = "ok"}) -- create its metatable
+ assert(not T or T.gcage(getmetatable(obj)) == "new")
+ obj = nil -- clear object
+ collectgarbage("step", 0) -- will call obj's finalizer
+end
+
+
if T == nil then
(Message or print)('\n >>> testC not active: \z
skipping some generational tests <<<\n')
@@ -72,6 +99,9 @@ do
assert(debug.getuservalue(U).x[1] == 234)
end
+-- just to make sure
+assert(collectgarbage'isrunning')
+
-- just to make sure