gh-146636: Improve ABI/feature selection, add new header for it#148302
Open
encukou wants to merge 6 commits intopython:mainfrom
Open
gh-146636: Improve ABI/feature selection, add new header for it#148302encukou wants to merge 6 commits intopython:mainfrom
encukou wants to merge 6 commits intopython:mainfrom
Conversation
…ABLED Add a test that Python headers themselves don't use Py_GIL_DISABLED in abi3t: abi3 and abi3t ought to be the same except the _Py_OPAQUE_PYOBJECT differences. This is done using the GCC-only poison pragma.
8 tasks
vstinner
reviewed
Apr 9, 2026
| # define Py_GIL_DISABLED | ||
| # endif | ||
| # if defined(_Py_IS_TESTCEXT) | ||
| // When compiling for abi3t, contents of Python.h should not depend |
Member
There was a problem hiding this comment.
Suggested change
| // When compiling for abi3t, contents of Python.h should not depend | |
| // When compiling for abi3t, contents of Python.h should not depend |
| // whether they need extra synchronization. | ||
| # define Py_GIL_DISABLED | ||
| # endif | ||
| # if defined(_Py_IS_TESTCEXT) |
Member
There was a problem hiding this comment.
You may move #ifdef __GNUC__ here:
Suggested change
| # if defined(_Py_IS_TESTCEXT) | |
| # if defined(_Py_IS_TESTCEXT) && defined(__GNUC__) |
| // on Py_GIL_DISABLED. | ||
| // We ask GCC to error if it sees the macro from this point on. | ||
| // Since users are free to the macro, and there's no way to undo the | ||
| // poisoning at the end of Python.h, we only do this in a test module. |
Member
There was a problem hiding this comment.
You may mention test_cext explicitly:
Suggested change
| // poisoning at the end of Python.h, we only do this in a test module. | |
| // poisoning at the end of Python.h, we only do this in a test module | |
| // (test_cext). |
|
|
||
| /* The internal C API must not be used with the limited C API: make sure | ||
| * that Py_BUILD_CORE* macros are not defined in this case. | ||
| * But, keep the "original" values, under different names, for "exports.h" |
Member
There was a problem hiding this comment.
It's surprising that _PyEXPORTS_CORE and _PyEXPORTS_CORE_MODULE are defined even if Py_LIMITED_API is defined. I tried to undefine Py_BUILD_CORE if Py_LIMITED_API is defined before _PyEXPORTS_CORE code, but I got linker errors on Windows. Examples:
LINK : warning LNK4217: symbol 'PyType_GetFlags' defined in 'typeobject.obj' is imported by '_stat.obj' in fu
nction '_PyLong_AsMode_t' [C:\victor\python\main\PCbuild\pythoncore.vcxproj]
LINK : warning LNK4217: symbol '_Py_DecRef' defined in 'object.obj' is imported by '_stat.obj' in function '_
PyLong_AsMode_t' [C:\victor\python\main\PCbuild\pythoncore.vcxproj]
LINK : warning LNK4286: symbol '_Py_DecRef' defined in 'object.obj' is imported by 'errnomodule.obj' [C:\vict
or\python\main\PCbuild\pythoncore.vcxproj]
LINK : warning LNK4217: symbol 'PyUnicode_FromStringAndSize' defined in 'unicodeobject.obj' is imported by '_
stat.obj' in function 'stat_filemode' [C:\victor\python\main\PCbuild\pythoncore.vcxproj]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature/ABI selection headers (Py_BUILD_CORE, Py_LIMITED_API, Py_GIL_DISABLED) need to be defined early (so they affect all definitions), but after the version (
patchlevel.h) and configuration (pyconfig.h).Put them in their own header to make this more obvious, and easier for contributors to keep them in the proper place.
Add a test that Python headers themselves don't use Py_GIL_DISABLED, since abi3 and abi3t ought to be identical except for the _Py_OPAQUE_PYOBJECT differences.
This is done using the GCC-only poison pragma, which tells the compiler/preprocessor to error if it ever sees the identifier after the pragma.
This needs some rewriting:
#if defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED)needs to be split into two lines, as the poisoning doesn't honour short-circuiting.This should fix gh-148267, but I'm attaching the PR to the abi3t issue, gh-146636, as it continues that effort (GH-148142 specifically).