@@ -3551,7 +3551,7 @@ slot_tp_del(PyObject *self)
35513551
35523552 /* Temporarily resurrect the object. */
35533553 assert (Py_REFCNT (self ) == 0 );
3554- Py_REFCNT (self ) = 1 ;
3554+ Py_SET_REFCNT (self , 1 ) ;
35553555
35563556 /* Save the current exception, if any. */
35573557 PyErr_Fetch (& error_type , & error_value , & error_traceback );
@@ -3574,7 +3574,8 @@ slot_tp_del(PyObject *self)
35743574 * cause a recursive call.
35753575 */
35763576 assert (Py_REFCNT (self ) > 0 );
3577- if (-- Py_REFCNT (self ) == 0 ) {
3577+ Py_SET_REFCNT (self , Py_REFCNT (self ) - 1 );
3578+ if (Py_REFCNT (self ) == 0 ) {
35783579 /* this is the normal path out */
35793580 return ;
35803581 }
@@ -3585,7 +3586,7 @@ slot_tp_del(PyObject *self)
35853586 {
35863587 Py_ssize_t refcnt = Py_REFCNT (self );
35873588 _Py_NewReference (self );
3588- Py_REFCNT (self ) = refcnt ;
3589+ Py_SET_REFCNT (self , refcnt ) ;
35893590 }
35903591 assert (!PyType_IS_GC (Py_TYPE (self )) || _PyObject_GC_IS_TRACKED (self ));
35913592 /* If Py_REF_DEBUG macro is defined, _Py_NewReference() increased
@@ -4621,7 +4622,7 @@ check_pyobject_uninitialized_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
46214622 return NULL ;
46224623 }
46234624 /* Initialize reference count to avoid early crash in ceval or GC */
4624- Py_REFCNT (op ) = 1 ;
4625+ Py_SET_REFCNT (op , 1 ) ;
46254626 /* object fields like ob_type are uninitialized! */
46264627 return test_pyobject_is_freed ("check_pyobject_uninitialized_is_freed" , op );
46274628}
@@ -4636,7 +4637,7 @@ check_pyobject_forbidden_bytes_is_freed(PyObject *self, PyObject *Py_UNUSED(args
46364637 return NULL ;
46374638 }
46384639 /* Initialize reference count to avoid early crash in ceval or GC */
4639- Py_REFCNT (op ) = 1 ;
4640+ Py_SET_REFCNT (op , 1 ) ;
46404641 /* ob_type field is after the memory block: part of "forbidden bytes"
46414642 when using debug hooks on memory allocators! */
46424643 return test_pyobject_is_freed ("check_pyobject_forbidden_bytes_is_freed" , op );
@@ -4652,7 +4653,7 @@ check_pyobject_freed_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
46524653 }
46534654 Py_TYPE (op )-> tp_dealloc (op );
46544655 /* Reset reference count to avoid early crash in ceval or GC */
4655- Py_REFCNT (op ) = 1 ;
4656+ Py_SET_REFCNT (op , 1 ) ;
46564657 /* object memory is freed! */
46574658 return test_pyobject_is_freed ("check_pyobject_freed_is_freed" , op );
46584659}
@@ -5134,7 +5135,7 @@ negative_refcount(PyObject *self, PyObject *Py_UNUSED(args))
51345135 }
51355136 assert (Py_REFCNT (obj ) == 1 );
51365137
5137- Py_REFCNT (obj ) = 0 ;
5138+ Py_SET_REFCNT (obj , 0 ) ;
51385139 /* Py_DECREF() must call _Py_NegativeRefcount() and abort Python */
51395140 Py_DECREF (obj );
51405141
0 commit comments