diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-06-16 16:33:02 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-06-16 16:33:02 -0300 |
| commit | 1b0f943da7dfb25987456a77259edbeea0b94edc (patch) | |
| tree | 6d095ff675b6779078e4368db338ad57562d7651 /testes/gc.lua | |
| parent | 6e22fedb74cf0c9b6656e9fce8b7331db847c605 (diff) | |
| download | lua-1b0f943da7dfb25987456a77259edbeea0b94edc.tar.gz lua-1b0f943da7dfb25987456a77259edbeea0b94edc.tar.bz2 lua-1b0f943da7dfb25987456a77259edbeea0b94edc.zip | |
Bug: new metatable in weak table can fool the GC
All-weak tables are not being revisited after being visited during
propagation; if it gets a new metatable after that, the new metatable
may not be marked.
Diffstat (limited to 'testes/gc.lua')
| -rw-r--r-- | testes/gc.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/testes/gc.lua b/testes/gc.lua index 03093e34..f017f330 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
| @@ -301,6 +301,16 @@ collectgarbage() | |||
| 301 | assert(next(a) == string.rep('$', 11)) | 301 | assert(next(a) == string.rep('$', 11)) |
| 302 | 302 | ||
| 303 | 303 | ||
| 304 | if T then -- bug since 5.3: all-weak tables are not being revisited | ||
| 305 | T.gcstate("propagate") | ||
| 306 | local t = setmetatable({}, {__mode = "kv"}) | ||
| 307 | T.gcstate("atomic") -- 't' was visited | ||
| 308 | setmetatable(t, {__mode = "kv"}) | ||
| 309 | T.gcstate("pause") -- its new metatable is not being visited | ||
| 310 | assert(getmetatable(t).__mode == "kv") | ||
| 311 | end | ||
| 312 | |||
| 313 | |||
| 304 | -- 'bug' in 5.1 | 314 | -- 'bug' in 5.1 |
| 305 | a = {} | 315 | a = {} |
| 306 | local t = {x = 10} | 316 | local t = {x = 10} |
