Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-102304: Debug mode no longer supports Limited API 3.9 #105391

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1536,13 +1536,10 @@ Build Changes
:file:`!configure`.
(Contributed by Christian Heimes in :gh:`89886`.)

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


Expand Down
6 changes: 6 additions & 0 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ whose size is determined when the object is allocated.
# error Py_LIMITED_API is incompatible with Py_TRACE_REFS
#endif

// gh-102304: In debug mode, the limited API implements Py_INCREF() by calling
// _Py_IncRef() which was added to Python 3.10.
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000
# error "Python built in debug mode is incompatible with limited C API older than 3.10"
#endif

#ifdef Py_TRACE_REFS
/* Define pointers to support a doubly-linked list of all live heap objects. */
#define _PyObject_HEAD_EXTRA \
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_xxlimited.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import types

xxlimited = import_helper.import_module('xxlimited')
xxlimited_35 = import_helper.import_module('xxlimited_35')
try:
import xxlimited_35
except ImportError:
xxlimited_35 = None


class CommonTests:
Expand Down Expand Up @@ -70,6 +73,7 @@ def test_buffer(self):
self.assertEqual(b2[0], 1)


@unittest.skipIf(xxlimited_35 is None, 'need xxlimited_35 extension')
class TestXXLimited35(CommonTests, unittest.TestCase):
module = xxlimited_35

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Python built in debug mode can no longer build C extensions using the
:ref:`limited C API <limited-c-api>` version 3.9 and older. Build C
extensions with a release build of Python (recommended), or with Python 3.12
and older. Patch by Victor Stinner.
2 changes: 1 addition & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7390,7 +7390,9 @@ dnl Limited API template modules.
dnl The limited C API is not compatible with the Py_TRACE_REFS macro.
dnl Emscripten does not support shared libraries yet.
PY_STDLIB_MOD([xxlimited], [test "$with_trace_refs" = "no"], [test "$ac_cv_func_dlopen" = yes])
PY_STDLIB_MOD([xxlimited_35], [test "$with_trace_refs" = "no"], [test "$ac_cv_func_dlopen" = yes])
dnl xxlimited_35 cannot be built with Python built in debug mode
dnl (if the Py_REF_DEBUG macro is defined)
PY_STDLIB_MOD([xxlimited_35], [test "$with_trace_refs" = "no" -a "$Py_DEBUG" != "true"], [test "$ac_cv_func_dlopen" = yes])

# substitute multiline block, must come after last PY_STDLIB_MOD()
AC_SUBST([MODULE_BLOCK])
Expand Down