aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/gengc.lua28
1 files changed, 27 insertions, 1 deletions
diff --git a/testes/gengc.lua b/testes/gengc.lua
index 4e80dd7e..7a7dabdd 100644
--- a/testes/gengc.lua
+++ b/testes/gengc.lua
@@ -57,13 +57,39 @@ do -- bug in 5.4.0
57 local obj = {} -- create a new object 57 local obj = {} -- create a new object
58 collectgarbage("step", 0) -- make it a survival 58 collectgarbage("step", 0) -- make it a survival
59 assert(not T or T.gcage(obj) == "survival") 59 assert(not T or T.gcage(obj) == "survival")
60 setmetatable(obj, {__gc = gcf, x = "ok"}) -- create its metatable 60 setmetatable(obj, {__gc = gcf, x = "+"}) -- create its metatable
61 assert(not T or T.gcage(getmetatable(obj)) == "new") 61 assert(not T or T.gcage(getmetatable(obj)) == "new")
62 obj = nil -- clear object 62 obj = nil -- clear object
63 collectgarbage("step", 0) -- will call obj's finalizer 63 collectgarbage("step", 0) -- will call obj's finalizer
64end 64end
65 65
66 66
67do -- another bug in 5.4.0
68 local old = {10}
69 collectgarbage() -- make 'old' old
70 local co = coroutine.create(
71 function ()
72 local x = nil
73 local f = function ()
74 return x[1]
75 end
76 x = coroutine.yield(f)
77 coroutine.yield()
78 end
79 )
80 local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine
81 collectgarbage("step", 0) -- make upvalue a survival
82 old[1] = {"hello"} -- 'old' go to grayagain as 'touched1'
83 coroutine.resume(co, {123}) -- its value will be new
84 co = nil
85 collectgarbage("step", 0) -- hit the barrier
86 assert(f() == 123 and old[1][1] == "hello")
87 collectgarbage("step", 0) -- run the collector once more
88 -- make sure old[1] was not collected
89 assert(f() == 123 and old[1][1] == "hello")
90end
91
92
67if T == nil then 93if T == nil then
68 (Message or print)('\n >>> testC not active: \z 94 (Message or print)('\n >>> testC not active: \z
69 skipping some generational tests <<<\n') 95 skipping some generational tests <<<\n')