aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testes/gengc.lua30
1 files changed, 30 insertions, 0 deletions
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
37end 37end
38 38
39 39
40do -- bug in 5.4.0
41-- When an object aged OLD1 is finalized, it is moved from the list
42-- 'finobj' to the *beginning* of the list 'allgc', but that part of the
43-- list was not being visited by 'markold'.
44 local A = {}
45 A[1] = false -- old anchor for object
46
47 -- obj finalizer
48 local function gcf (obj)
49 A[1] = obj -- anchor object
50 assert(not T or T.gcage(obj) == "old1")
51 obj = nil -- remove it from the stack
52 collectgarbage("step", 0) -- do a young collection
53 print(getmetatable(A[1]).x) -- metatable was collected
54 end
55
56 collectgarbage() -- make A old
57 local obj = {} -- create a new object
58 collectgarbage("step", 0) -- make it a survival
59 assert(not T or T.gcage(obj) == "survival")
60 setmetatable(obj, {__gc = gcf, x = "ok"}) -- create its metatable
61 assert(not T or T.gcage(getmetatable(obj)) == "new")
62 obj = nil -- clear object
63 collectgarbage("step", 0) -- will call obj's finalizer
64end
65
66
40if T == nil then 67if T == nil then
41 (Message or print)('\n >>> testC not active: \z 68 (Message or print)('\n >>> testC not active: \z
42 skipping some generational tests <<<\n') 69 skipping some generational tests <<<\n')
@@ -72,6 +99,9 @@ do
72 assert(debug.getuservalue(U).x[1] == 234) 99 assert(debug.getuservalue(U).x[1] == 234)
73end 100end
74 101
102-- just to make sure
103assert(collectgarbage'isrunning')
104
75 105
76 106
77-- just to make sure 107-- just to make sure