Skip to content

Commit 26bc2cc

Browse files
[3.12] gh-105387: Limited C API implements Py_INCREF() as func (GH-105388) (#105763)
gh-105387: Limited C API implements Py_INCREF() as func (GH-105388) 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. (cherry picked from commit b542972) Co-authored-by: Victor Stinner <[email protected]>
1 parent 33d3069 commit 26bc2cc

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Doc/whatsnew/3.12.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,11 @@ New Features
16931693

16941694
(Contributed by Eddie Elizondo in :gh:`84436`.)
16951695

1696+
* In the limited C API version 3.12, :c:func:`Py_INCREF` and
1697+
:c:func:`Py_DECREF` functions are now implemented as opaque function calls to
1698+
hide implementation details.
1699+
(Contributed by Victor Stinner in :gh:`105387`.)
1700+
16961701
Porting to Python 3.12
16971702
----------------------
16981703

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);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In the limited C API version 3.12, :c:func:`Py_INCREF` and
2+
:c:func:`Py_DECREF` functions are now implemented as opaque function calls
3+
to hide implementation details. Patch by Victor Stinner.

0 commit comments

Comments
 (0)