@@ -597,7 +597,7 @@ class C(object):
597
597
# deallocation of c2.
598
598
del c2
599
599
600
- def test_callback_in_cycle_1 (self ):
600
+ def test_callback_in_cycle (self ):
601
601
import gc
602
602
603
603
class J (object ):
@@ -637,40 +637,11 @@ def acallback(self, ignore):
637
637
del I , J , II
638
638
gc .collect ()
639
639
640
- def test_callback_in_cycle_2 (self ):
640
+ def test_callback_reachable_one_way (self ):
641
641
import gc
642
642
643
- # This is just like test_callback_in_cycle_1, except that II is an
644
- # old-style class. The symptom is different then: an instance of an
645
- # old-style class looks in its own __dict__ first. 'J' happens to
646
- # get cleared from I.__dict__ before 'wr', and 'J' was never in II's
647
- # __dict__, so the attribute isn't found. The difference is that
648
- # the old-style II doesn't have a NULL __mro__ (it doesn't have any
649
- # __mro__), so no segfault occurs. Instead it got:
650
- # test_callback_in_cycle_2 (__main__.ReferencesTestCase) ...
651
- # Exception exceptions.AttributeError:
652
- # "II instance has no attribute 'J'" in <bound method II.acallback
653
- # of <?.II instance at 0x00B9B4B8>> ignored
654
-
655
- class J (object ):
656
- pass
657
-
658
- class II :
659
- def acallback (self , ignore ):
660
- self .J
661
-
662
- I = II ()
663
- I .J = J
664
- I .wr = weakref .ref (J , I .acallback )
665
-
666
- del I , J , II
667
- gc .collect ()
668
-
669
- def test_callback_in_cycle_3 (self ):
670
- import gc
671
-
672
- # This one broke the first patch that fixed the last two. In this
673
- # case, the objects reachable from the callback aren't also reachable
643
+ # This one broke the first patch that fixed the previous test. In this case,
644
+ # the objects reachable from the callback aren't also reachable
674
645
# from the object (c1) *triggering* the callback: you can get to
675
646
# c1 from c2, but not vice-versa. The result was that c2's __dict__
676
647
# got tp_clear'ed by the time the c2.cb callback got invoked.
@@ -690,10 +661,10 @@ def cb(self, ignore):
690
661
del c1 , c2
691
662
gc .collect ()
692
663
693
- def test_callback_in_cycle_4 (self ):
664
+ def test_callback_different_classes (self ):
694
665
import gc
695
666
696
- # Like test_callback_in_cycle_3 , except c2 and c1 have different
667
+ # Like test_callback_reachable_one_way , except c2 and c1 have different
697
668
# classes. c2's class (C) isn't reachable from c1 then, so protecting
698
669
# objects reachable from the dying object (c1) isn't enough to stop
699
670
# c2's class (C) from getting tp_clear'ed before c2.cb is invoked.
0 commit comments