Skip to content

Commit aae08b4

Browse files
committed
pythongh-102304: Fix Py_INCREF() for limited C API 3.9
When Python is built in debug mode (Py_REF_DEBUG macro), Py_INCREF() and Py_DECREF() of the limited C API 3.9 (and older) now call Py_IncRef() and Py_DecRef(), since _Py_IncRef() and _Py_DecRef() were added to Python 3.10.
1 parent 3e525d2 commit aae08b4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Include/object.h

+12
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,13 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
612612
{
613613
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
614614
// Stable ABI for Python built in debug mode
615+
# if Py_LIMITED_API+0 >= 0x030a00A7
615616
_Py_IncRef(op);
617+
# else
618+
// _Py_IncRef() was added to Python 3.10.0a7, use Py_IncRef() on older
619+
// Python versions. Py_IncRef() accepts NULL whereas _Py_IncRef() doesn't.
620+
Py_IncRef(op);
621+
# endif
616622
#else
617623
// Non-limited C API and limited C API for Python 3.9 and older access
618624
// directly PyObject.ob_refcnt.
@@ -644,7 +650,13 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
644650
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
645651
// Stable ABI for Python built in debug mode
646652
static inline void Py_DECREF(PyObject *op) {
653+
# if Py_LIMITED_API+0 >= 0x030a00A7
647654
_Py_DecRef(op);
655+
# else
656+
// _Py_DecRef() was added to Python 3.10.0a7, use Py_DecRef() on older
657+
// Python versions. Py_DecRef() accepts NULL whereas _Py_IncRef() doesn't.
658+
Py_DecRef(op);
659+
# endif
648660
}
649661
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
650662

0 commit comments

Comments
 (0)