Browse Source

Added test for fix 127e7a6c894

Roberto Ierusalimschy 5 years ago
parent
commit
0f1cd0eba9
1 changed files with 30 additions and 0 deletions
  1. 30 0
      testes/gengc.lua

+ 30 - 0
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