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