From a6da1472c0c5e05ff249325f979531ad51533110 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 27 Jul 2020 10:26:20 -0300 Subject: Fixed bug: barriers cannot be active during sweep Barriers cannot be active during sweep, even in generational mode. (Although gen. mode is not incremental, it can hit a barrier when deleting a thread and closing its upvalues.) The colors of objects are being changed during sweep and, therefore, cannot be trusted. --- testes/gengc.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'testes') 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 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 + setmetatable(obj, {__gc = gcf, x = "+"}) -- 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 +do -- another bug in 5.4.0 + local old = {10} + collectgarbage() -- make 'old' old + local co = coroutine.create( + function () + local x = nil + local f = function () + return x[1] + end + x = coroutine.yield(f) + coroutine.yield() + end + ) + local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine + collectgarbage("step", 0) -- make upvalue a survival + old[1] = {"hello"} -- 'old' go to grayagain as 'touched1' + coroutine.resume(co, {123}) -- its value will be new + co = nil + collectgarbage("step", 0) -- hit the barrier + assert(f() == 123 and old[1][1] == "hello") + collectgarbage("step", 0) -- run the collector once more + -- make sure old[1] was not collected + assert(f() == 123 and old[1][1] == "hello") +end + + if T == nil then (Message or print)('\n >>> testC not active: \z skipping some generational tests <<<\n') -- cgit v1.2.3-55-g6feb