diff options
Diffstat (limited to 'testes/gc.lua')
-rw-r--r-- | testes/gc.lua | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/testes/gc.lua b/testes/gc.lua index 09bfe09a..62713dac 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | -- $Id: testes/gc.lua $ | 1 | -- $Id: testes/gc.lua $ |
2 | -- See Copyright Notice in file all.lua | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | print('testing incremental garbage collection') | 4 | print('testing incremental garbage collection') |
5 | 5 | ||
@@ -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") |
@@ -601,6 +616,21 @@ end | |||
601 | 616 | ||
602 | 617 | ||
603 | if T then | 618 | if T then |
619 | collectgarbage("stop") | ||
620 | T.gcstate("pause") | ||
621 | local sup = {x = 0} | ||
622 | local a = setmetatable({}, {__newindex = sup}) | ||
623 | T.gcstate("enteratomic") | ||
624 | assert(T.gccolor(sup) == "black") | ||
625 | a.x = {} -- should not break the invariant | ||
626 | assert(not (T.gccolor(sup) == "black" and T.gccolor(sup.x) == "white")) | ||
627 | T.gcstate("pause") -- complete the GC cycle | ||
628 | sup.x.y = 10 | ||
629 | collectgarbage("restart") | ||
630 | end | ||
631 | |||
632 | |||
633 | if T then | ||
604 | print("emergency collections") | 634 | print("emergency collections") |
605 | collectgarbage() | 635 | collectgarbage() |
606 | collectgarbage() | 636 | collectgarbage() |
@@ -629,7 +659,7 @@ do | |||
629 | assert(getmetatable(o) == tt) | 659 | assert(getmetatable(o) == tt) |
630 | -- create new objects during GC | 660 | -- create new objects during GC |
631 | local a = 'xuxu'..(10+3)..'joao', {} | 661 | local a = 'xuxu'..(10+3)..'joao', {} |
632 | ___Glob = o -- ressurrect object! | 662 | ___Glob = o -- resurrect object! |
633 | setmetatable({}, tt) -- creates a new one with same metatable | 663 | setmetatable({}, tt) -- creates a new one with same metatable |
634 | print(">>> closing state " .. "<<<\n") | 664 | print(">>> closing state " .. "<<<\n") |
635 | end | 665 | end |