Skip to content

Commit bdd5865

Browse files
committed
gh-105387: Limited C API implements Py_INCREF() as func
In the limited C API version 3.12, Py_INCREF() and Py_DECREF() functions are now implemented as opaque function calls to hide implementation details.
1 parent 7ba0fd9 commit bdd5865

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Doc/whatsnew/3.12.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,11 @@ New Features
16981698

16991699
(Contributed by Eddie Elizondo in :gh:`84436`.)
17001700

1701+
* In the limited C API version 3.12, :c:func:`Py_INCREF` and
1702+
:c:func:`Py_DECREF` functions are now implemented as opaque function calls to
1703+
hide implementation details.
1704+
(Contributed by Victor Stinner in :gh:`105387`.)
1705+
17011706
Porting to Python 3.12
17021707
----------------------
17031708

Include/object.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,11 @@ PyAPI_FUNC(void) _Py_DecRef(PyObject *);
610610

611611
static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
612612
{
613-
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
614-
// Stable ABI for Python built in debug mode. _Py_IncRef() was added to
615-
// Python 3.10.0a7, use Py_IncRef() on older Python versions. Py_IncRef()
616-
// accepts NULL whereas _Py_IncRef() doesn't.
613+
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
614+
// Stable ABI implements Py_INCREF() as a function call on limited C API
615+
// version 3.12 and newer, and on Python built in debug mode. _Py_IncRef()
616+
// was added to Python 3.10.0a7, use Py_IncRef() on older Python versions.
617+
// Py_IncRef() accepts NULL whereas _Py_IncRef() doesn't.
617618
# if Py_LIMITED_API+0 >= 0x030a00A7
618619
_Py_IncRef(op);
619620
# else
@@ -647,10 +648,11 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
647648
# define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
648649
#endif
649650

650-
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
651-
// Stable ABI for Python built in debug mode. _Py_DecRef() was added to Python
652-
// 3.10.0a7, use Py_DecRef() on older Python versions. Py_DecRef() accepts NULL
653-
// whereas _Py_IncRef() doesn't.
651+
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
652+
// Stable ABI implements Py_DECREF() as a function call on limited C API
653+
// version 3.12 and newer, and on Python built in debug mode. _Py_DecRef() was
654+
// added to Python 3.10.0a7, use Py_DecRef() on older Python versions.
655+
// Py_DecRef() accepts NULL whereas _Py_IncRef() doesn't.
654656
static inline void Py_DECREF(PyObject *op) {
655657
# if Py_LIMITED_API+0 >= 0x030a00A7
656658
_Py_DecRef(op);

0 commit comments

Comments
 (0)