aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/gc.lua2
-rw-r--r--testes/gengc.lua30
2 files changed, 16 insertions, 16 deletions
diff --git a/testes/gc.lua b/testes/gc.lua
index 61b5da9c..8bacffa0 100644
--- a/testes/gc.lua
+++ b/testes/gc.lua
@@ -504,7 +504,7 @@ end
504do 504do
505 collectgarbage() 505 collectgarbage()
506 collectgarbage"stop" 506 collectgarbage"stop"
507 collectgarbage("step", 0) -- steps should not unblock the collector 507 collectgarbage("step") -- steps should not unblock the collector
508 local x = gcinfo() 508 local x = gcinfo()
509 repeat 509 repeat
510 for i=1,1000 do _ENV.a = {} end -- no collection during the loop 510 for i=1,1000 do _ENV.a = {} end -- no collection during the loop
diff --git a/testes/gengc.lua b/testes/gengc.lua
index cae07285..51872cc1 100644
--- a/testes/gengc.lua
+++ b/testes/gengc.lua
@@ -24,12 +24,12 @@ do
24 assert(not T or (T.gcage(U) == "touched1" and T.gcage(U[1]) == "new")) 24 assert(not T or (T.gcage(U) == "touched1" and T.gcage(U[1]) == "new"))
25 25
26 -- both U and the table survive one more collection 26 -- both U and the table survive one more collection
27 collectgarbage("step", 0) 27 collectgarbage("step")
28 assert(not T or (T.gcage(U) == "touched2" and T.gcage(U[1]) == "survival")) 28 assert(not T or (T.gcage(U) == "touched2" and T.gcage(U[1]) == "survival"))
29 29
30 -- both U and the table survive yet another collection 30 -- both U and the table survive yet another collection
31 -- now everything is old 31 -- now everything is old
32 collectgarbage("step", 0) 32 collectgarbage("step")
33 assert(not T or (T.gcage(U) == "old" and T.gcage(U[1]) == "old1")) 33 assert(not T or (T.gcage(U) == "old" and T.gcage(U[1]) == "old1"))
34 34
35 -- data was not corrupted 35 -- data was not corrupted
@@ -46,10 +46,10 @@ do
46 assert(not T or T.gcage(old) == "old") 46 assert(not T or T.gcage(old) == "old")
47 setmetatable(old, {}) -- new table becomes OLD0 (barrier) 47 setmetatable(old, {}) -- new table becomes OLD0 (barrier)
48 assert(not T or T.gcage(getmetatable(old)) == "old0") 48 assert(not T or T.gcage(getmetatable(old)) == "old0")
49 collectgarbage("step", 0) -- new table becomes OLD1 and firstold1 49 collectgarbage("step") -- new table becomes OLD1 and firstold1
50 assert(not T or T.gcage(getmetatable(old)) == "old1") 50 assert(not T or T.gcage(getmetatable(old)) == "old1")
51 setmetatable(getmetatable(old), {__gc = foo}) -- get it out of allgc list 51 setmetatable(getmetatable(old), {__gc = foo}) -- get it out of allgc list
52 collectgarbage("step", 0) -- should not seg. fault 52 collectgarbage("step") -- should not seg. fault
53end 53end
54 54
55 55
@@ -65,18 +65,18 @@ do -- bug in 5.4.0
65 A[1] = obj -- anchor object 65 A[1] = obj -- anchor object
66 assert(not T or T.gcage(obj) == "old1") 66 assert(not T or T.gcage(obj) == "old1")
67 obj = nil -- remove it from the stack 67 obj = nil -- remove it from the stack
68 collectgarbage("step", 0) -- do a young collection 68 collectgarbage("step") -- do a young collection
69 print(getmetatable(A[1]).x) -- metatable was collected 69 print(getmetatable(A[1]).x) -- metatable was collected
70 end 70 end
71 71
72 collectgarbage() -- make A old 72 collectgarbage() -- make A old
73 local obj = {} -- create a new object 73 local obj = {} -- create a new object
74 collectgarbage("step", 0) -- make it a survival 74 collectgarbage("step") -- make it a survival
75 assert(not T or T.gcage(obj) == "survival") 75 assert(not T or T.gcage(obj) == "survival")
76 setmetatable(obj, {__gc = gcf, x = "+"}) -- create its metatable 76 setmetatable(obj, {__gc = gcf, x = "+"}) -- create its metatable
77 assert(not T or T.gcage(getmetatable(obj)) == "new") 77 assert(not T or T.gcage(getmetatable(obj)) == "new")
78 obj = nil -- clear object 78 obj = nil -- clear object
79 collectgarbage("step", 0) -- will call obj's finalizer 79 collectgarbage("step") -- will call obj's finalizer
80end 80end
81 81
82 82
@@ -94,13 +94,13 @@ do -- another bug in 5.4.0
94 end 94 end
95 ) 95 )
96 local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine 96 local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine
97 collectgarbage("step", 0) -- make upvalue a survival 97 collectgarbage("step") -- make upvalue a survival
98 old[1] = {"hello"} -- 'old' go to grayagain as 'touched1' 98 old[1] = {"hello"} -- 'old' go to grayagain as 'touched1'
99 coroutine.resume(co, {123}) -- its value will be new 99 coroutine.resume(co, {123}) -- its value will be new
100 co = nil 100 co = nil
101 collectgarbage("step", 0) -- hit the barrier 101 collectgarbage("step") -- hit the barrier
102 assert(f() == 123 and old[1][1] == "hello") 102 assert(f() == 123 and old[1][1] == "hello")
103 collectgarbage("step", 0) -- run the collector once more 103 collectgarbage("step") -- run the collector once more
104 -- make sure old[1] was not collected 104 -- make sure old[1] was not collected
105 assert(f() == 123 and old[1][1] == "hello") 105 assert(f() == 123 and old[1][1] == "hello")
106end 106end
@@ -112,12 +112,12 @@ do -- bug introduced in commit 9cf3299fa
112 assert(not T or T.gcage(t) == "old") 112 assert(not T or T.gcage(t) == "old")
113 t[1] = {10} 113 t[1] = {10}
114 assert(not T or (T.gcage(t) == "touched1" and T.gccolor(t) == "gray")) 114 assert(not T or (T.gcage(t) == "touched1" and T.gccolor(t) == "gray"))
115 collectgarbage("step", 0) -- minor collection 115 collectgarbage("step") -- minor collection
116 assert(not T or (T.gcage(t) == "touched2" and T.gccolor(t) == "black")) 116 assert(not T or (T.gcage(t) == "touched2" and T.gccolor(t) == "black"))
117 collectgarbage("step", 0) -- minor collection 117 collectgarbage("step") -- minor collection
118 assert(not T or T.gcage(t) == "old") -- t should be black, but it was gray 118 assert(not T or T.gcage(t) == "old") -- t should be black, but it was gray
119 t[1] = {10} -- no barrier here, so t was still old 119 t[1] = {10} -- no barrier here, so t was still old
120 collectgarbage("step", 0) -- minor collection 120 collectgarbage("step") -- minor collection
121 -- t, being old, is ignored by the collection, so it is not cleared 121 -- t, being old, is ignored by the collection, so it is not cleared
122 assert(t[1] == nil) -- fails with the bug 122 assert(t[1] == nil) -- fails with the bug
123end 123end
@@ -144,13 +144,13 @@ do
144 T.gcage(debug.getuservalue(U)) == "new") 144 T.gcage(debug.getuservalue(U)) == "new")
145 145
146 -- both U and the table survive one more collection 146 -- both U and the table survive one more collection
147 collectgarbage("step", 0) 147 collectgarbage("step")
148 assert(T.gcage(U) == "touched2" and 148 assert(T.gcage(U) == "touched2" and
149 T.gcage(debug.getuservalue(U)) == "survival") 149 T.gcage(debug.getuservalue(U)) == "survival")
150 150
151 -- both U and the table survive yet another collection 151 -- both U and the table survive yet another collection
152 -- now everything is old 152 -- now everything is old
153 collectgarbage("step", 0) 153 collectgarbage("step")
154 assert(T.gcage(U) == "old" and 154 assert(T.gcage(U) == "old" and
155 T.gcage(debug.getuservalue(U)) == "old1") 155 T.gcage(debug.getuservalue(U)) == "old1")
156 156