@@ -473,8 +473,9 @@ update_refs(PyGC_Head *containers)
473
473
474
474
while (gc != containers ) {
475
475
next = GC_NEXT (gc );
476
- assert (!_Py_IsImmortal (FROM_GC (gc )));
477
- gc_reset_refs (gc , Py_REFCNT (FROM_GC (gc )));
476
+ PyObject * op = FROM_GC (gc );
477
+ _PyObject_ASSERT (op , !_Py_IsImmortal (op ));
478
+ gc_reset_refs (gc , Py_REFCNT (op ));
478
479
/* Python's cyclic gc should never see an incoming refcount
479
480
* of 0: if something decref'ed to 0, it should have been
480
481
* deallocated immediately at that time.
@@ -493,7 +494,7 @@ update_refs(PyGC_Head *containers)
493
494
* so serious that maybe this should be a release-build
494
495
* check instead of an assert?
495
496
*/
496
- _PyObject_ASSERT (FROM_GC ( gc ) , gc_get_refs (gc ) != 0 );
497
+ _PyObject_ASSERT (op , gc_get_refs (gc ) != 0 );
497
498
gc = next ;
498
499
}
499
500
}
@@ -559,7 +560,7 @@ visit_reachable(PyObject *op, void *arg)
559
560
}
560
561
// It would be a logic error elsewhere if the collecting flag were set on
561
562
// an untracked object.
562
- assert ( gc -> _gc_next != 0 );
563
+ _PyObject_ASSERT ( op , gc -> _gc_next != 0 );
563
564
564
565
if (gc -> _gc_next & NEXT_MASK_UNREACHABLE ) {
565
566
/* This had gc_refs = 0 when move_unreachable got
@@ -736,7 +737,9 @@ static void
736
737
move_legacy_finalizers (PyGC_Head * unreachable , PyGC_Head * finalizers )
737
738
{
738
739
PyGC_Head * gc , * next ;
739
- assert ((unreachable -> _gc_next & NEXT_MASK_UNREACHABLE ) == 0 );
740
+ _PyObject_ASSERT (
741
+ FROM_GC (unreachable ),
742
+ (unreachable -> _gc_next & NEXT_MASK_UNREACHABLE ) == 0 );
740
743
741
744
/* March over unreachable. Move objects with finalizers into
742
745
* `finalizers`.
@@ -759,10 +762,14 @@ static inline void
759
762
clear_unreachable_mask (PyGC_Head * unreachable )
760
763
{
761
764
/* Check that the list head does not have the unreachable bit set */
762
- assert (((uintptr_t )unreachable & NEXT_MASK_UNREACHABLE ) == 0 );
765
+ _PyObject_ASSERT (
766
+ FROM_GC (unreachable ),
767
+ ((uintptr_t )unreachable & NEXT_MASK_UNREACHABLE ) == 0 );
763
768
764
769
PyGC_Head * gc , * next ;
765
- assert ((unreachable -> _gc_next & NEXT_MASK_UNREACHABLE ) == 0 );
770
+ _PyObject_ASSERT (
771
+ FROM_GC (unreachable ),
772
+ (unreachable -> _gc_next & NEXT_MASK_UNREACHABLE ) == 0 );
766
773
for (gc = GC_NEXT (unreachable ); gc != unreachable ; gc = next ) {
767
774
_PyObject_ASSERT ((PyObject * )FROM_GC (gc ), gc -> _gc_next & NEXT_MASK_UNREACHABLE );
768
775
next = GC_NEXT (gc );
@@ -916,7 +923,7 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
916
923
*/
917
924
if (gc_is_collecting (AS_GC ((PyObject * )wr ))) {
918
925
/* it should already have been cleared above */
919
- assert ( wr -> wr_object == Py_None );
926
+ _PyObject_ASSERT (( PyObject * ) wr , wr -> wr_object == Py_None );
920
927
continue ;
921
928
}
922
929
@@ -927,9 +934,8 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
927
934
928
935
/* Move wr to wrcb_to_call, for the next pass. */
929
936
wrasgc = AS_GC ((PyObject * )wr );
930
- assert (wrasgc != next ); /* wrasgc is reachable, but
931
- next isn't, so they can't
932
- be the same */
937
+ // wrasgc is reachable, but next isn't, so they can't be the same
938
+ _PyObject_ASSERT (wr , wrasgc != next );
933
939
gc_list_move (wrasgc , & wrcb_to_call );
934
940
}
935
941
}
@@ -1317,7 +1323,7 @@ visit_add_to_container(PyObject *op, void *arg)
1317
1323
PyGC_Head * gc = AS_GC (op );
1318
1324
if (_PyObject_GC_IS_TRACKED (op ) &&
1319
1325
gc_old_space (gc ) != visited ) {
1320
- assert ( !_Py_IsImmortal (op ));
1326
+ _PyObject_ASSERT ( op , !_Py_IsImmortal (op ));
1321
1327
gc_flip_old_space (gc );
1322
1328
gc_list_move (gc , cf -> container );
1323
1329
}
@@ -1965,13 +1971,14 @@ _Py_ScheduleGC(PyInterpreterState *interp)
1965
1971
void
1966
1972
_PyObject_GC_Link (PyObject * op )
1967
1973
{
1968
- PyGC_Head * g = AS_GC (op );
1969
- assert (((uintptr_t )g & (sizeof (uintptr_t )-1 )) == 0 ); // g must be correctly aligned
1974
+ PyGC_Head * gc = AS_GC (op );
1975
+ // gc must be correctly aligned
1976
+ _PyObject_ASSERT (op , ((uintptr_t )gc & (sizeof (uintptr_t )-1 )) == 0 );
1970
1977
1971
1978
PyThreadState * tstate = _PyThreadState_GET ();
1972
1979
GCState * gcstate = & tstate -> interp -> gc ;
1973
- g -> _gc_next = 0 ;
1974
- g -> _gc_prev = 0 ;
1980
+ gc -> _gc_next = 0 ;
1981
+ gc -> _gc_prev = 0 ;
1975
1982
gcstate -> young .count ++ ; /* number of allocated GC objects */
1976
1983
if (gcstate -> young .count > gcstate -> young .threshold &&
1977
1984
gcstate -> enabled &&
0 commit comments