diff options
author | Tim Peters <tim@python.org> | 2014-05-08 22:42:19 (GMT) |
---|---|---|
committer | Tim Peters <tim@python.org> | 2014-05-08 22:42:19 (GMT) |
commit | 5fbc7b12f776109678dc34fdb49b420750a3e5ff (patch) | |
tree | bfd1be75cbf62cc59f5b65e13cfc5239b1b1d220 /Lib/test/test_gc.py | |
parent | c644e7c39f7adf0ed783e128b0278665133bf523 (diff) | |
download | cpython-5fbc7b12f776109678dc34fdb49b420750a3e5ff.zip cpython-5fbc7b12f776109678dc34fdb49b420750a3e5ff.tar.gz cpython-5fbc7b12f776109678dc34fdb49b420750a3e5ff.tar.bz2 |
Issue #21435: Segfault in gc with cyclic trash
Changed the iteration logic in finalize_garbage() to tolerate objects vanishing
from the list as a side effect of executing a finalizer.
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 7eb104a..c0be537 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -580,6 +580,38 @@ class GCTests(unittest.TestCase): # would be damaged, with an empty __dict__. self.assertEqual(x, None) + def test_bug21435(self): + # This is a poor test - its only virtue is that it happened to + # segfault on Tim's Windows box before the patch for 21435 was + # applied. That's a nasty bug relying on specific pieces of cyclic + # trash appearing in exactly the right order in finalize_garbage()'s + # input list. + # But there's no reliable way to force that order from Python code, + # so over time chances are good this test won't really be testing much + # of anything anymore. Still, if it blows up, there's _some_ + # problem ;-) + gc.collect() + + class A: + pass + + class B: + def __init__(self, x): + self.x = x + + def __del__(self): + self.attr = None + + def do_work(): + a = A() + b = B(A()) + + a.attr = b + b.attr = a + + do_work() + gc.collect() # this blows up (bad C pointer) when it fails + @cpython_only def test_garbage_at_shutdown(self): import subprocess |