From 0f1cd0eba99ea6d383e75b9ae488d00ad541c210 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 Jul 2020 13:37:01 -0300 Subject: [PATCH] Added test for fix 127e7a6c894 --- testes/gengc.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/testes/gengc.lua b/testes/gengc.lua index b02f471b..4e80dd7e 100644 --- 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