From bd1e9509a4475266b21ff432c7875efc289bc0ca Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 18 May 2024 16:56:27 -0400 Subject: [PATCH] [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. --- Include/internal/pycore_object.h | 2 +- .../2024-05-13-16-00-05.gh-issue-118997.GWqWdt.rst | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-05-13-16-00-05.gh-issue-118997.GWqWdt.rst 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. -- 2.47.3