From 540385aa6da0e91598df62329ebd15a592a73218 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 28 Jan 2022 04:29:05 +0000 Subject: [PATCH 1/2] Adjust _Py_RefTotal for Py_INCREF/Py_DECREF on immortal codeobjects --- Objects/codeobject.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Objects/codeobject.c b/Objects/codeobject.c index bb8ffa794a96d32..7ba45df7288150a 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1923,4 +1923,8 @@ _PyStaticCode_Dealloc(PyCodeObject *co) PyObject_ClearWeakRefs((PyObject *)co); co->co_weakreflist = NULL; } +#ifdef Py_REF_DEBUG + /* Adjust _Py_RefTotal for Py_INCREF/Py_DECREF on immortal codeobjects */ + _Py_RefTotal += 999999999 - Py_REFCNT((PyObject *)co); +#endif } From eb51fcb8c0864fb97e95528ba74db1c7698316b4 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 28 Jan 2022 04:56:59 +0000 Subject: [PATCH 2/2] fix refcnt of immortal for embedded too --- Objects/codeobject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 7ba45df7288150a..767a53fc1741ad0 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1924,7 +1924,9 @@ _PyStaticCode_Dealloc(PyCodeObject *co) co->co_weakreflist = NULL; } #ifdef Py_REF_DEBUG - /* Adjust _Py_RefTotal for Py_INCREF/Py_DECREF on immortal codeobjects */ + /* Adjust _Py_RefTotal and refcnt for Py_INCREF/Py_DECREF + * on immortal codeobjects */ _Py_RefTotal += 999999999 - Py_REFCNT((PyObject *)co); + Py_SET_REFCNT((PyObject*)co, 999999999); #endif }