Skip to content

Commit a2ac8e7

Browse files
committed
Check for immortality in refcount accounting
1 parent 36ef3bf commit a2ac8e7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Include/refcount.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ static inline Py_ALWAYS_INLINE void Py_INCREF_MORTAL(PyObject *op)
249249
op->ob_refcnt++;
250250
_Py_INCREF_STAT_INC();
251251
#if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
252-
_Py_INCREF_IncRefTotal();
252+
if (!_Py_IsImmortal(op)) {
253+
_Py_INCREF_IncRefTotal();
254+
}
253255
#endif
254256
}
255257
#endif
@@ -391,7 +393,9 @@ static inline void Py_DECREF_MORTAL(const char *filename, int lineno, PyObject *
391393
}
392394
_Py_DECREF_STAT_INC();
393395
assert(!_Py_IsStaticImmortal(op));
394-
_Py_DECREF_DecRefTotal();
396+
if (!_Py_IsImmortal(op)) {
397+
_Py_DECREF_DecRefTotal();
398+
}
395399
if (--op->ob_refcnt == 0) {
396400
_Py_Dealloc(op);
397401
}
@@ -407,7 +411,9 @@ static inline void _Py_DECREF_MORTAL_SPECIALIZED(const char *filename, int linen
407411
}
408412
_Py_DECREF_STAT_INC();
409413
assert(!_Py_IsStaticImmortal(op));
410-
_Py_DECREF_DecRefTotal();
414+
if (!_Py_IsImmortal(op)) {
415+
_Py_DECREF_DecRefTotal();
416+
}
411417
if (--op->ob_refcnt == 0) {
412418
destruct(op);
413419
}

0 commit comments

Comments
 (0)