Skip to content

Commit 5298304

Browse files
committed
gh-102304: Fix Py_INCREF() stable ABI in debug mode
When Python is built in debug mode (if the Py_REF_DEBUG macro is defined), the Py_INCREF() and Py_DECREF() function are now always implemented as opaque functions to avoid leaking implementation details like "_Py_RefTotal".
1 parent 586aca3 commit 5298304

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Include/object.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,7 @@ you can count such references to the type object.)
586586
*/
587587

588588
#ifdef Py_REF_DEBUG
589-
# if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030A0000
590-
extern Py_ssize_t _Py_RefTotal;
591-
# define _Py_INC_REFTOTAL() _Py_RefTotal++
592-
# define _Py_DEC_REFTOTAL() _Py_RefTotal--
593-
# elif !defined(Py_LIMITED_API) || Py_LIMITED_API+0 > 0x030D0000
589+
# ifndef Py_LIMITED_API
594590
PyAPI_FUNC(void) _Py_IncRefTotal_DO_NOT_USE_THIS(void);
595591
PyAPI_FUNC(void) _Py_DecRefTotal_DO_NOT_USE_THIS(void);
596592
# define _Py_INC_REFTOTAL() _Py_IncRefTotal_DO_NOT_USE_THIS()
@@ -616,8 +612,8 @@ PyAPI_FUNC(void) _Py_DecRef(PyObject *);
616612

617613
static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
618614
{
619-
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000
620-
// Stable ABI for Python 3.10 built in debug mode.
615+
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
616+
// Stable ABI for Python built in debug mode
621617
_Py_IncRef(op);
622618
#else
623619
// Non-limited C API and limited C API for Python 3.9 and older access
@@ -647,8 +643,8 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
647643
# define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
648644
#endif
649645

650-
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000
651-
// Stable ABI for limited C API version 3.10 of Python debug build
646+
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
647+
// Stable ABI for Python built in debug mode
652648
static inline void Py_DECREF(PyObject *op) {
653649
_Py_DecRef(op);
654650
}

0 commit comments

Comments
 (0)