From 947c1b7bffd873dc748d00700ce87f9fffc725d1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 13 May 2024 15:57:47 +0200 Subject: [PATCH] gh-118997: Fix _Py_ClearImmortal() assertion 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 7a2f13a21bda76..63e74a65f43c01 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 00000000000000..85d6dc80ed9c24 --- /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.