@@ -113,6 +113,12 @@ worklist_remove(struct worklist_iter *iter)
113113 iter -> next = iter -> ptr ;
114114}
115115
116+ static inline int
117+ gc_is_frozen (PyObject * op )
118+ {
119+ return (op -> ob_gc_bits & _PyGC_BITS_FROZEN ) != 0 ;
120+ }
121+
116122static inline int
117123gc_is_unreachable (PyObject * op )
118124{
@@ -277,7 +283,7 @@ op_from_block(void *block, void *arg, bool include_frozen)
277283 if (!_PyObject_GC_IS_TRACKED (op )) {
278284 return NULL ;
279285 }
280- if (!include_frozen && (op -> ob_gc_bits & _PyGC_BITS_FROZEN ) != 0 ) {
286+ if (!include_frozen && gc_is_frozen (op ) ) {
281287 return NULL ;
282288 }
283289 return op ;
@@ -358,7 +364,7 @@ gc_visit_stackref(_PyStackRef stackref)
358364 // being dead already.
359365 if (PyStackRef_IsDeferred (stackref ) && !PyStackRef_IsNull (stackref )) {
360366 PyObject * obj = PyStackRef_AsPyObjectBorrow (stackref );
361- if (_PyObject_GC_IS_TRACKED (obj )) {
367+ if (_PyObject_GC_IS_TRACKED (obj ) && ! gc_is_frozen ( obj ) ) {
362368 gc_add_refs (obj , 1 );
363369 }
364370 }
@@ -439,7 +445,10 @@ process_delayed_frees(PyInterpreterState *interp)
439445static int
440446visit_decref (PyObject * op , void * arg )
441447{
442- if (_PyObject_GC_IS_TRACKED (op ) && !_Py_IsImmortal (op )) {
448+ if (_PyObject_GC_IS_TRACKED (op )
449+ && !_Py_IsImmortal (op )
450+ && !gc_is_frozen (op ))
451+ {
443452 // If update_refs hasn't reached this object yet, mark it
444453 // as (tentatively) unreachable and initialize ob_tid to zero.
445454 gc_maybe_init_refs (op );
@@ -1539,7 +1548,7 @@ visit_freeze(const mi_heap_t *heap, const mi_heap_area_t *area,
15391548 void * block , size_t block_size , void * args )
15401549{
15411550 PyObject * op = op_from_block (block , args , true);
1542- if (op != NULL ) {
1551+ if (op != NULL && ! gc_is_unreachable ( op ) ) {
15431552 op -> ob_gc_bits |= _PyGC_BITS_FROZEN ;
15441553 }
15451554 return true;
@@ -1584,7 +1593,7 @@ visit_count_frozen(const mi_heap_t *heap, const mi_heap_area_t *area,
15841593 void * block , size_t block_size , void * args )
15851594{
15861595 PyObject * op = op_from_block (block , args , true);
1587- if (op != NULL && (op -> ob_gc_bits & _PyGC_BITS_FROZEN ) != 0 ) {
1596+ if (op != NULL && gc_is_frozen (op ) ) {
15881597 struct count_frozen_args * arg = (struct count_frozen_args * )args ;
15891598 arg -> count ++ ;
15901599 }
0 commit comments