diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-04-05 17:46:04 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-04-05 17:46:04 (GMT) |
commit | 2f74fddfc1bd81838cb80e726d391f4c810e525a (patch) | |
tree | 3d8ef5ba2b81c9f45feeeb74bfc3b9a1199b50e6 /Lib | |
parent | 86b993b6cfffa6fee144054d30fd94d02a3717cb (diff) | |
download | cpython-2f74fddfc1bd81838cb80e726d391f4c810e525a.zip cpython-2f74fddfc1bd81838cb80e726d391f4c810e525a.tar.gz cpython-2f74fddfc1bd81838cb80e726d391f4c810e525a.tar.bz2 |
test_boom: More comments. Also check that len(gc.garbage) doesn't
change (it would be another kind of bug if the trash cycle weren't
reclaimed).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_gc.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index f190fa4..5ec87b9 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -254,7 +254,7 @@ def test_trashcan(): gc.disable() class C: - def __getattr__(self, attr): + def __getattr__(self, someattribute): del self.attr raise AttributeError @@ -265,11 +265,16 @@ def test_boom(): b.attr = a gc.collect() + garbagelen = len(gc.garbage) del a, b - # the collection will invoke the getattr and decref one of the - # object. so they are deallocated without being reported as - # part of a cycle. + # a<->b are in a trash cycle now. Collection will invoke C.__getattr__ + # (to see whether a and b have __del__ methods), and __getattr__ deletes + # the internal "attr" attributes as a side effect. That causes the + # trash cycle to get reclaimed via refcounts falling to 0, thus mutating + # the trash graph as a side effect of merely asking whether __del__ + # exists. This used to (before 2.3b1) crash Python. expect(gc.collect(), 0, "boom") + expect(len(gc.garbage), garbagelen, "boom") def test_all(): gc.collect() # Delete 2nd generation garbage |