File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -353,68 +353,6 @@ def test_saveall(self):
353353 obj = gc .garbage .pop ()
354354 self .assertEqual (id (obj ), id_L )
355355
356- @unittest .skipIf (Py_GIL_DISABLED ,
357- "the free-threaded GC prints while the world is stopped" )
358- def test_debug_collectable_write_frees_object (self ):
359- class Node :
360- def __init__ (self ):
361- self .cycle = [self ]
362-
363- class Stderr :
364- def write (self , text ):
365- node = wr ()
366- if node is not None :
367- node .cycle .clear ()
368- return len (text )
369-
370- gc .collect ()
371- node = Node ()
372- wr = weakref .ref (node )
373- del node
374- debug = gc .get_debug ()
375- with support .swap_attr (sys , 'stderr' , Stderr ()):
376- gc .set_debug (gc .DEBUG_COLLECTABLE )
377- try :
378- gc .collect ()
379- finally :
380- gc .set_debug (debug )
381- self .assertIsNone (wr ())
382-
383- def test_debug_uncollectable_write_frees_object (self ):
384- @with_tp_del
385- class Legacy :
386- def __tp_del__ (self ):
387- pass
388-
389- class Child :
390- pass
391-
392- class Stderr :
393- def write (self , text ):
394- legacy = wr ()
395- if legacy is not None and '<Child ' in text :
396- del legacy .child
397- return len (text )
398-
399- gc .collect ()
400- legacy = Legacy ()
401- legacy .cycle = legacy
402- legacy .child = Child ()
403- wr = weakref .ref (legacy )
404- del legacy
405- debug = gc .get_debug ()
406- with support .swap_attr (sys , 'stderr' , Stderr ()):
407- gc .set_debug (gc .DEBUG_UNCOLLECTABLE )
408- try :
409- gc .collect ()
410- finally :
411- gc .set_debug (debug )
412- legacy = wr ()
413- self .assertFalse (hasattr (legacy , 'child' ))
414- self .assertIn (legacy , gc .garbage )
415- del legacy .cycle
416- gc .garbage .remove (legacy )
417-
418356 def test_del (self ):
419357 # __del__ methods can trigger collection, make this to happen
420358 thresholds = gc .get_threshold ()
Original file line number Diff line number Diff line change @@ -1012,6 +1012,9 @@ static void
10121012debug_cycles (const char * msg , PyGC_Head * list )
10131013{
10141014 PyGC_Head seen ;
1015+ /* Always take the next object from the head of `list` rather than from
1016+ * the current one, which may be freed (along with others) by debug_cycle().
1017+ */
10151018 gc_list_init (& seen );
10161019 while (!gc_list_is_empty (list )) {
10171020 PyGC_Head * gc = GC_NEXT (list );
You can’t perform that action at this time.
0 commit comments