Skip to content

Commit 8f2ffe1

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 the "_Py_RefTotal" variable. Remove _Py_IncRefTotal_DO_NOT_USE_THIS() and _Py_DecRefTotal_DO_NOT_USE_THIS() from the stable ABI.
1 parent 85e5d03 commit 8f2ffe1

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

Include/object.h

Lines changed: 5 additions & 9 deletions
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 >= 0x030C0000
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
}

Misc/stable_abi.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,12 +2409,3 @@
24092409
added = '3.12'
24102410
[const.Py_TPFLAGS_ITEMS_AT_END]
24112411
added = '3.12'
2412-
2413-
[function._Py_IncRefTotal_DO_NOT_USE_THIS]
2414-
added = '3.12'
2415-
ifdef = 'Py_REF_DEBUG'
2416-
abi_only = true
2417-
[function._Py_DecRefTotal_DO_NOT_USE_THIS]
2418-
added = '3.12'
2419-
ifdef = 'Py_REF_DEBUG'
2420-
abi_only = true

0 commit comments

Comments
 (0)