diff options
author | Victor Stinner <vstinner@python.org> | 2023-06-09 09:30:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 09:30:41 (GMT) |
commit | 7ba0fd9f87ad75f8eda8e002c2fc71049b815f33 (patch) | |
tree | 0f7c30e32dee7d2bba813c1b0b6535f0229f0ab8 /Include/object.h | |
parent | 947ec7ab02e7673956eb7f235c330a49f11e157a (diff) | |
download | cpython-7ba0fd9f87ad75f8eda8e002c2fc71049b815f33.zip cpython-7ba0fd9f87ad75f8eda8e002c2fc71049b815f33.tar.gz cpython-7ba0fd9f87ad75f8eda8e002c2fc71049b815f33.tar.bz2 |
gh-102304: Fix Py_INCREF() for limited C API 3.9 (#105550)
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.
Diffstat (limited to 'Include/object.h')
-rw-r--r-- | Include/object.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Include/object.h b/Include/object.h index dc5b087..ad16b72c 100644 --- a/Include/object.h +++ b/Include/object.h @@ -611,8 +611,14 @@ PyAPI_FUNC(void) _Py_DecRef(PyObject *); static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op) { #if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) - // Stable ABI for Python built in debug mode + // Stable ABI for Python built in debug mode. _Py_IncRef() was added to + // Python 3.10.0a7, use Py_IncRef() on older Python versions. Py_IncRef() + // accepts NULL whereas _Py_IncRef() doesn't. +# if Py_LIMITED_API+0 >= 0x030a00A7 _Py_IncRef(op); +# else + Py_IncRef(op); +# endif #else // Non-limited C API and limited C API for Python 3.9 and older access // directly PyObject.ob_refcnt. @@ -642,9 +648,15 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op) #endif #if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) -// Stable ABI for Python built in debug mode +// Stable ABI for Python built in debug mode. _Py_DecRef() was added to Python +// 3.10.0a7, use Py_DecRef() on older Python versions. Py_DecRef() accepts NULL +// whereas _Py_IncRef() doesn't. static inline void Py_DECREF(PyObject *op) { +# if Py_LIMITED_API+0 >= 0x030a00A7 _Py_DecRef(op); +# else + Py_DecRef(op); +# endif } #define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op)) |