Skip to content

gh-85283: If Py_LIMITED_API is defined, undefine Py_BUILD_CORE #110725

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

Merged
merged 2 commits into from
Oct 11, 2023
Merged
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
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,11 @@ Porting to Python 3.13
:c:func:`!Py_TOLOWER`.
(Contributed by Victor Stinner in :gh:`108765`.)

* If the :c:macro:`Py_LIMITED_API` macro is defined, :c:macro:`!Py_BUILD_CORE`,
:c:macro:`!Py_BUILD_CORE_BUILTIN` and :c:macro:`!Py_BUILD_CORE_MODULE` macros
are now undefined by ``<Python.h>``.
(Contributed by Victor Stinner in :gh:`85283`.)

Deprecated
----------

Expand Down
13 changes: 9 additions & 4 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
# define Py_BUILD_CORE
#endif

#if defined(Py_LIMITED_API) && defined(Py_BUILD_CORE)
# error "Py_LIMITED_API is not compatible with Py_BUILD_CORE"
#endif


/**************************************************************************
Symbols and macros to supply platform-independent interfaces to basic
Expand Down Expand Up @@ -361,6 +357,15 @@ extern "C" {

#include "exports.h"

#ifdef Py_LIMITED_API
// The internal C API must not be used with the limited C API: make sure
// that Py_BUILD_CORE macro is not defined in this case. These 3 macros are
// used by exports.h, so only undefine them afterwards.
# undef Py_BUILD_CORE
# undef Py_BUILD_CORE_BUILTIN
# undef Py_BUILD_CORE_MODULE
#endif

/* limits.h constants that may be missing */

#ifndef INT_MAX
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
If the :c:macro:`Py_LIMITED_API` macro is defined, :c:macro:`!Py_BUILD_CORE`,
:c:macro:`!Py_BUILD_CORE_BUILTIN` and :c:macro:`!Py_BUILD_CORE_MODULE` macros
are now undefined by ``<Python.h>``. Patch by Victor Stinner.