@@ -490,7 +490,21 @@ you can count such references to the type object.)
490490*/ 
491491
492492#ifdef  Py_REF_DEBUG 
493- PyAPI_DATA (Py_ssize_t ) _Py_RefTotal ;
493+ #  if  defined(Py_LIMITED_API ) &&  Py_LIMITED_API + 0  <  0x030A0000 
494+ extern  Py_ssize_t  _Py_RefTotal ;
495+ #    define  _Py_INC_REFTOTAL () _Py_RefTotal++
496+ #    define  _Py_DEC_REFTOTAL () _Py_RefTotal--
497+ #  elif  defined(Py_BUILD_CORE ) &&  !defined(Py_BUILD_CORE_MODULE )
498+ extern  void  _Py_IncRefTotal (void );
499+ extern  void  _Py_DecRefTotal (void );
500+ #    define  _Py_INC_REFTOTAL () _Py_IncRefTotal()
501+ #    define  _Py_DEC_REFTOTAL () _Py_DecRefTotal()
502+ #  elif  !defined(Py_LIMITED_API ) ||  Py_LIMITED_API + 0  >  0x030C0000 
503+ extern  void  _Py_IncRefTotal_DO_NOT_USE_THIS (void );
504+ extern  void  _Py_DecRefTotal_DO_NOT_USE_THIS (void );
505+ #    define  _Py_INC_REFTOTAL () _Py_IncRefTotal_DO_NOT_USE_THIS()
506+ #    define  _Py_DEC_REFTOTAL () _Py_DecRefTotal_DO_NOT_USE_THIS()
507+ #  endif 
494508PyAPI_FUNC (void ) _Py_NegativeRefcount (const  char  * filename , int  lineno ,
495509                                      PyObject  * op );
496510#endif  /* Py_REF_DEBUG */ 
@@ -519,8 +533,8 @@ static inline void Py_INCREF(PyObject *op)
519533    // Non-limited C API and limited C API for Python 3.9 and older access 
520534    // directly PyObject.ob_refcnt. 
521535#ifdef  Py_REF_DEBUG 
522-     _Py_RefTotal ++ ;
523- #endif 
536+     _Py_INC_REFTOTAL () ;
537+ #endif    // Py_REF_DEBUG 
524538    op -> ob_refcnt ++ ;
525539#endif 
526540}
@@ -539,7 +553,7 @@ static inline void Py_DECREF(PyObject *op) {
539553static  inline  void  Py_DECREF (const  char  * filename , int  lineno , PyObject  * op )
540554{
541555    _Py_DECREF_STAT_INC ();
542-     _Py_RefTotal -- ;
556+     _Py_DEC_REFTOTAL () ;
543557    if  (-- op -> ob_refcnt  !=  0 ) {
544558        if  (op -> ob_refcnt  <  0 ) {
545559            _Py_NegativeRefcount (filename , lineno , op );
@@ -564,6 +578,9 @@ static inline void Py_DECREF(PyObject *op)
564578#define  Py_DECREF (op ) Py_DECREF(_PyObject_CAST(op))
565579#endif 
566580
581+ #undef  _Py_INC_REFTOTAL
582+ #undef  _Py_DEC_REFTOTAL
583+ 
567584
568585/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear 
569586 * and tp_dealloc implementations. 
0 commit comments