From: Victor Stinner Date: Sat, 18 May 2024 20:56:27 +0000 (-0400) Subject: [3.12] gh-118997: Fix _Py_ClearImmortal() assertion (#119001) X-Git-Tag: v3.12.4~93 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd1e9509a4475266b21ff432c7875efc289bc0ca;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-118997: Fix _Py_ClearImmortal() assertion (#119001) Fix _Py_ClearImmortal() assertion: use _Py_IsImmortal() to tolerate reference count lower than _Py_IMMORTAL_REFCNT. Fix the assertion for the stable ABI, when a C extension is built with Python 3.11 or lower. --- diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 7a2f13a21bda..63e74a65f43c 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -80,7 +80,7 @@ static inline void _Py_SetImmortal(PyObject *op) static inline void _Py_ClearImmortal(PyObject *op) { if (op) { - assert(op->ob_refcnt == _Py_IMMORTAL_REFCNT); + assert(_Py_IsImmortal(op)); op->ob_refcnt = 1; Py_DECREF(op); } diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-13-16-00-05.gh-issue-118997.GWqWdt.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-13-16-00-05.gh-issue-118997.GWqWdt.rst new file mode 100644 index 000000000000..85d6dc80ed9c --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-05-13-16-00-05.gh-issue-118997.GWqWdt.rst @@ -0,0 +1,4 @@ +Fix _Py_ClearImmortal() assertion: use _Py_IsImmortal() to tolerate +reference count lower than _Py_IMMORTAL_REFCNT. Fix the assertion for the +stable ABI, when a C extension is built with Python 3.11 or lower. Patch by +Victor Stinner.