Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d29e86b

Browse filesBrowse files
authored
[3.12] gh-102304: Fix Py_INCREF() for limited C API 3.9 (#105553)
* 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. (cherry picked from commit 7ba0fd9) * gh-102304: Remove Py_INCREF() doc change (#105552) Py_INCREF() was made compatible again with Python 3.9 and older in the limited API of Python debug mode. (cherry picked from commit 58e4b69)
1 parent 2f4a2d6 commit d29e86b
Copy full SHA for d29e86b

File tree

Expand file treeCollapse file tree

2 files changed

+14
-11
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-11
lines changed

‎Doc/whatsnew/3.12.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.12.rst
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,15 +1536,6 @@ Build Changes
15361536
:file:`!configure`.
15371537
(Contributed by Christian Heimes in :gh:`89886`.)
15381538

1539-
* C extensions built with the :ref:`limited C API <limited-c-api>`
1540-
on :ref:`Python build in debug mode <debug-build>` no longer support Python
1541-
3.9 and older. In this configuration, :c:func:`Py_INCREF` and
1542-
:c:func:`Py_DECREF` are now always implemented as opaque function calls,
1543-
but the called functions were added to Python 3.10. Build C extensions
1544-
with a release build of Python or with Python 3.12 and older, to keep support
1545-
for Python 3.9 and older.
1546-
(Contributed by Victor Stinner in :gh:`102304`.)
1547-
15481539

15491540
C API Changes
15501541
=============

‎Include/object.h

Copy file name to clipboardExpand all lines: Include/object.h
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,14 @@ PyAPI_FUNC(void) _Py_DecRef(PyObject *);
611611
static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
612612
{
613613
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
614-
// Stable ABI for Python built in debug mode
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.
617+
# if Py_LIMITED_API+0 >= 0x030a00A7
615618
_Py_IncRef(op);
619+
# else
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.
@@ -642,9 +648,15 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
642648
#endif
643649

644650
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
645-
// Stable ABI for Python built in debug mode
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.
646654
static inline void Py_DECREF(PyObject *op) {
655+
# if Py_LIMITED_API+0 >= 0x030a00A7
647656
_Py_DecRef(op);
657+
# else
658+
Py_DecRef(op);
659+
# endif
648660
}
649661
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
650662

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.