@@ -227,6 +227,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
227227 uint32_t local = _Py_atomic_load_uint32_relaxed (& op -> ob_ref_local );
228228 uint32_t new_local = local + 1 ;
229229 if (new_local == 0 ) {
230+ _Py_INCREF_IMMORTAL_STAT_INC ();
230231 // local is equal to _Py_IMMORTAL_REFCNT: do nothing
231232 return ;
232233 }
@@ -241,6 +242,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
241242 PY_UINT32_T cur_refcnt = op -> ob_refcnt_split [PY_BIG_ENDIAN ];
242243 PY_UINT32_T new_refcnt = cur_refcnt + 1 ;
243244 if (new_refcnt == 0 ) {
245+ _Py_INCREF_IMMORTAL_STAT_INC ();
244246 // cur_refcnt is equal to _Py_IMMORTAL_REFCNT: the object is immortal,
245247 // do nothing
246248 return ;
@@ -249,6 +251,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
249251#else
250252 // Explicitly check immortality against the immortal value
251253 if (_Py_IsImmortal (op )) {
254+ _Py_INCREF_IMMORTAL_STAT_INC ();
252255 return ;
253256 }
254257 op -> ob_refcnt ++ ;
@@ -295,6 +298,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
295298{
296299 uint32_t local = _Py_atomic_load_uint32_relaxed (& op -> ob_ref_local );
297300 if (local == _Py_IMMORTAL_REFCNT_LOCAL ) {
301+ _Py_DECREF_IMMORTAL_STAT_INC ();
298302 return ;
299303 }
300304 _Py_DECREF_STAT_INC ();
@@ -320,6 +324,7 @@ static inline void Py_DECREF(PyObject *op)
320324{
321325 uint32_t local = _Py_atomic_load_uint32_relaxed (& op -> ob_ref_local );
322326 if (local == _Py_IMMORTAL_REFCNT_LOCAL ) {
327+ _Py_DECREF_IMMORTAL_STAT_INC ();
323328 return ;
324329 }
325330 _Py_DECREF_STAT_INC ();
@@ -343,6 +348,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
343348 _Py_NegativeRefcount (filename , lineno , op );
344349 }
345350 if (_Py_IsImmortal (op )) {
351+ _Py_DECREF_IMMORTAL_STAT_INC ();
346352 return ;
347353 }
348354 _Py_DECREF_STAT_INC ();
@@ -359,6 +365,7 @@ static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
359365 // Non-limited C API and limited C API for Python 3.9 and older access
360366 // directly PyObject.ob_refcnt.
361367 if (_Py_IsImmortal (op )) {
368+ _Py_DECREF_IMMORTAL_STAT_INC ();
362369 return ;
363370 }
364371 _Py_DECREF_STAT_INC ();
0 commit comments