diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-03-28 23:18:08 +0000 |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-03-28 23:18:08 +0000 |
commit | 2457a7e3688158717d3a7d87e84ae2021651fe5b (patch) | |
tree | 5048025ffd5df39741f4604e2ebeeb227e3abdd0 | |
parent | Backport to 2.2.1: (diff) | |
download | cpython-2457a7e3688158717d3a7d87e84ae2021651fe5b.tar.gz cpython-2457a7e3688158717d3a7d87e84ae2021651fe5b.tar.bz2 cpython-2457a7e3688158717d3a7d87e84ae2021651fe5b.zip |
Backport of a new test to check the interaction between cyclic GC
and the trashcan mechanism.
-rw-r--r-- | Lib/test/test_gc.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index d4fcf7b223a..22f7e74114b 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -171,6 +171,34 @@ def test_del(): gc.disable() apply(gc.set_threshold, thresholds) +class Ouch: + n = 0 + def __del__(self): + Ouch.n = Ouch.n + 1 + if Ouch.n % 7 == 0: + gc.collect() + +def test_trashcan(): + # "trashcan" is a hack to prevent stack overflow when deallocating + # very deeply nested tuples etc. It works in part by abusing the + # type pointer and refcount fields, and that can yield horrible + # problems when gc tries to traverse the structures. + # If this test fails (as it does in 2.0, 2.1 and 2.2), it will + # most likely die via segfault. + + gc.enable() + N = 200 + for count in range(3): + t = [] + for i in range(N): + t = [t, Ouch()] + u = [] + for i in range(N): + u = [u, Ouch()] + v = {} + for i in range(N): + v = {1: v, 2: Ouch()} + gc.disable() def test_all(): gc.collect() # Delete 2nd generation garbage @@ -187,6 +215,7 @@ def test_all(): run_test("finalizers", test_finalizer) run_test("__del__", test_del) run_test("saveall", test_saveall) + run_test("trashcan", test_trashcan) def test(): if verbose: |