diff options
Diffstat (limited to 'testes/gc.lua')
-rw-r--r-- | testes/gc.lua | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/testes/gc.lua b/testes/gc.lua index 0693837c..62713dac 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
@@ -288,6 +288,21 @@ x,y,z=nil | |||
288 | collectgarbage() | 288 | collectgarbage() |
289 | assert(next(a) == string.rep('$', 11)) | 289 | assert(next(a) == string.rep('$', 11)) |
290 | 290 | ||
291 | do -- invalid mode | ||
292 | local a = setmetatable({}, {__mode = 34}) | ||
293 | collectgarbage() | ||
294 | end | ||
295 | |||
296 | |||
297 | if T then -- bug since 5.3: all-weak tables are not being revisited | ||
298 | T.gcstate("propagate") | ||
299 | local t = setmetatable({}, {__mode = "kv"}) | ||
300 | T.gcstate("enteratomic") -- 't' was visited | ||
301 | setmetatable(t, {__mode = "kv"}) | ||
302 | T.gcstate("pause") -- its new metatable is not being visited | ||
303 | assert(getmetatable(t).__mode == "kv") | ||
304 | end | ||
305 | |||
291 | 306 | ||
292 | -- 'bug' in 5.1 | 307 | -- 'bug' in 5.1 |
293 | a = {} | 308 | a = {} |
@@ -446,8 +461,8 @@ do -- tests for string keys in weak tables | |||
446 | local m = collectgarbage("count") -- current memory | 461 | local m = collectgarbage("count") -- current memory |
447 | local a = setmetatable({}, {__mode = "kv"}) | 462 | local a = setmetatable({}, {__mode = "kv"}) |
448 | a[string.rep("a", 2^22)] = 25 -- long string key -> number value | 463 | a[string.rep("a", 2^22)] = 25 -- long string key -> number value |
449 | a[string.rep("b", 2^22)] = {} -- long string key -> colectable value | 464 | a[string.rep("b", 2^22)] = {} -- long string key -> collectable value |
450 | a[{}] = 14 -- colectable key | 465 | a[{}] = 14 -- collectable key |
451 | collectgarbage() | 466 | collectgarbage() |
452 | local k, v = next(a) -- string key with number value preserved | 467 | local k, v = next(a) -- string key with number value preserved |
453 | assert(k == string.rep("a", 2^22) and v == 25) | 468 | assert(k == string.rep("a", 2^22) and v == 25) |
@@ -459,7 +474,7 @@ do -- tests for string keys in weak tables | |||
459 | assert(next(a) == nil) | 474 | assert(next(a) == nil) |
460 | -- make sure will not try to compare with dead key | 475 | -- make sure will not try to compare with dead key |
461 | assert(a[string.rep("b", 100)] == undef) | 476 | assert(a[string.rep("b", 100)] == undef) |
462 | assert(collectgarbage("count") <= m + 1) -- eveything collected | 477 | assert(collectgarbage("count") <= m + 1) -- everything collected |
463 | end | 478 | end |
464 | 479 | ||
465 | 480 | ||
@@ -524,7 +539,7 @@ do | |||
524 | local co = coroutine.create(f) | 539 | local co = coroutine.create(f) |
525 | assert(coroutine.resume(co, co)) | 540 | assert(coroutine.resume(co, co)) |
526 | end | 541 | end |
527 | -- Now, thread and closure are not reacheable any more. | 542 | -- Now, thread and closure are not reachable any more. |
528 | collectgarbage() | 543 | collectgarbage() |
529 | assert(collected) | 544 | assert(collected) |
530 | collectgarbage("restart") | 545 | collectgarbage("restart") |
@@ -644,7 +659,7 @@ do | |||
644 | assert(getmetatable(o) == tt) | 659 | assert(getmetatable(o) == tt) |
645 | -- create new objects during GC | 660 | -- create new objects during GC |
646 | local a = 'xuxu'..(10+3)..'joao', {} | 661 | local a = 'xuxu'..(10+3)..'joao', {} |
647 | ___Glob = o -- ressurrect object! | 662 | ___Glob = o -- resurrect object! |
648 | setmetatable({}, tt) -- creates a new one with same metatable | 663 | setmetatable({}, tt) -- creates a new one with same metatable |
649 | print(">>> closing state " .. "<<<\n") | 664 | print(">>> closing state " .. "<<<\n") |
650 | end | 665 | end |