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).
This commit is contained in:
parent
86b993b6cf
commit
2f74fddfc1
|
@ -254,7 +254,7 @@ def test_trashcan():
|
||||||
gc.disable()
|
gc.disable()
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, someattribute):
|
||||||
del self.attr
|
del self.attr
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
||||||
|
@ -265,11 +265,16 @@ def test_boom():
|
||||||
b.attr = a
|
b.attr = a
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
garbagelen = len(gc.garbage)
|
||||||
del a, b
|
del a, b
|
||||||
# the collection will invoke the getattr and decref one of the
|
# a<->b are in a trash cycle now. Collection will invoke C.__getattr__
|
||||||
# object. so they are deallocated without being reported as
|
# (to see whether a and b have __del__ methods), and __getattr__ deletes
|
||||||
# part of a cycle.
|
# 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(gc.collect(), 0, "boom")
|
||||||
|
expect(len(gc.garbage), garbagelen, "boom")
|
||||||
|
|
||||||
def test_all():
|
def test_all():
|
||||||
gc.collect() # Delete 2nd generation garbage
|
gc.collect() # Delete 2nd generation garbage
|
||||||
|
|
Loading…
Reference in New Issue