diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-13 13:37:01 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-13 13:37:01 -0300 |
| commit | 0f1cd0eba99ea6d383e75b9ae488d00ad541c210 (patch) | |
| tree | f2ae47c64153d49d26337c4eda6f17bef0f891eb | |
| parent | 127e7a6c8942b362aa3c6627f44d660a4fb75312 (diff) | |
| download | lua-0f1cd0eba99ea6d383e75b9ae488d00ad541c210.tar.gz lua-0f1cd0eba99ea6d383e75b9ae488d00ad541c210.tar.bz2 lua-0f1cd0eba99ea6d383e75b9ae488d00ad541c210.zip | |
Added test for fix 127e7a6c894
| -rw-r--r-- | testes/gengc.lua | 30 |
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 | |||
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | do -- 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 | ||
| 64 | end | ||
| 65 | |||
| 66 | |||
| 40 | if T == nil then | 67 | if 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) |
| 73 | end | 100 | end |
| 74 | 101 | ||
| 102 | -- just to make sure | ||
| 103 | assert(collectgarbage'isrunning') | ||
| 104 | |||
| 75 | 105 | ||
| 76 | 106 | ||
| 77 | -- just to make sure | 107 | -- just to make sure |
