| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* Macros that restrict available definitions and select implementations | ||
| * to match an ABI stability promise: | ||
| * | ||
| * - internal API/ABI (may change at any time) -- Py_BUILD_CORE* | ||
| * - general CPython API/ABI (may change in 3.x.0) -- default | ||
| * - Stable ABI: abi3, abi3t (long-term stable) -- Py_LIMITED_API, | ||
| * Py_TARGET_ABI3T, _Py_OPAQUE_PYOBJECT | ||
| * - Free-threading (incompatible with non-free-threading builds) | ||
| * -- Py_GIL_DISABLED | ||
| */ | ||
|
|
||
| #ifndef _Py_PYABI_H | ||
| #define _Py_PYABI_H | ||
|
|
||
| /* Defines to build Python and its standard library: | ||
| * | ||
| * - Py_BUILD_CORE: Build Python core. Gives access to Python internals; should | ||
| * not be used by third-party modules. | ||
| * - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module. | ||
| * - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library. | ||
| * | ||
| * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE. | ||
| * | ||
| * On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas | ||
| * Py_BUILD_CORE_BUILTIN does not. | ||
| */ | ||
| #if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE) | ||
| # define Py_BUILD_CORE | ||
| #endif | ||
| #if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE) | ||
| # define Py_BUILD_CORE | ||
| #endif | ||
|
|
||
| /* Check valid values for target ABI macros. | ||
| */ | ||
| #if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 3 | ||
| // Empty Py_LIMITED_API used to work; redefine to | ||
| // Python 3.2 to be explicit. | ||
| # undef Py_LIMITED_API | ||
| # define Py_LIMITED_API 0x03020000 | ||
| #endif | ||
| #if defined(Py_TARGET_ABI3T) && Py_TARGET_ABI3T+0 < 0x030f0000 | ||
| # error "Py_TARGET_ABI3T must be 0x030f0000 (3.15) or above" | ||
| #endif | ||
|
|
||
| /* Stable ABI for free-threaded builds (abi3t, introduced in PEP 803) | ||
| * is enabled by one of: | ||
| * - Py_TARGET_ABI3T, or | ||
| * - Py_LIMITED_API and Py_GIL_DISABLED. | ||
| * | ||
| * These affect set the following, which Python.h should use internally: | ||
| * - Py_LIMITED_API (defines the subset of API we expose) | ||
| * - _Py_OPAQUE_PYOBJECT (additionally hides what's ABI-incompatible between | ||
| * free-threaded & GIL) | ||
| * | ||
| * (Don't use Py_TARGET_ABI3T directly. It's currently only used to set these | ||
| * 2 macros, and defined for users' convenience.) | ||
| */ | ||
| #if defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED) \ | ||
| && !defined(Py_TARGET_ABI3T) | ||
| # define Py_TARGET_ABI3T Py_LIMITED_API | ||
| #endif | ||
| #if defined(Py_TARGET_ABI3T) | ||
| # define _Py_OPAQUE_PYOBJECT | ||
| # if !defined(Py_LIMITED_API) | ||
| # define Py_LIMITED_API Py_TARGET_ABI3T | ||
| # elif Py_LIMITED_API > Py_TARGET_ABI3T | ||
| // if both are defined, use the *lower* version, | ||
| // i.e. maximum compatibility | ||
| # undef Py_LIMITED_API | ||
| # define Py_LIMITED_API Py_TARGET_ABI3T | ||
| # endif | ||
| #else | ||
| # ifdef _Py_OPAQUE_PYOBJECT | ||
| // _Py_OPAQUE_PYOBJECT is a private macro; do not define it directly. | ||
| # error "Define Py_TARGET_ABI3T to target abi3t." | ||
| # endif | ||
| #endif | ||
|
|
||
| #if defined(Py_TARGET_ABI3T) | ||
| # if !defined(Py_GIL_DISABLED) | ||
| // Define Py_GIL_DISABLED for users' needs. Users check this macro to see | ||
| // whether they need extra synchronization. | ||
| # define Py_GIL_DISABLED | ||
| # endif | ||
| # if defined(_Py_IS_TESTCEXT) | ||
| // When compiling for abi3t, contents of Python.h should not depend | ||
| // 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 | ||
| // (test_cext). | ||
| // | ||
| // Clang's poisoning is stricter than GCC's: it looks in `#elif` | ||
| // expressions after matching `#if`s. We disable it for now. | ||
| // We also provide an undocumented, unsupported opt-out macro to help | ||
| // porting to other compilers. Consider reaching out if you use it. | ||
| # if defined(__GNUC__) && !defined(__clang__) && !defined(_Py_NO_GCC_POISON) | ||
| # undef Py_GIL_DISABLED | ||
| # pragma GCC poison Py_GIL_DISABLED | ||
| # endif | ||
| # endif | ||
| #endif | ||
|
|
||
| /* 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" | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt'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]
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes; these select whether PyAPI_FUNC sumbols are exported or imported. Anything compiled into the main binary needs to be exported, regardless of the API it uses. (This is currently done by including "exports.h" in the middle of pyport.h, right before Py_BUILD_CORE is undefined -- which is IMO confusing, as it makes the meaning of Py_BUILD_CORE depend on where you are in the header.)
Sorry, something went wrong.
All reactions
|
||
| */ | ||
| #ifdef Py_BUILD_CORE | ||
| # define _PyEXPORTS_CORE | ||
| #endif | ||
| #ifdef Py_BUILD_CORE_MODULE | ||
| # define _PyEXPORTS_CORE_MODULE | ||
| #endif | ||
| #ifdef Py_LIMITED_API | ||
| # undef Py_BUILD_CORE | ||
| # undef Py_BUILD_CORE_BUILTIN | ||
| # undef Py_BUILD_CORE_MODULE | ||
| #endif | ||
|
|
||
| #endif // _Py_PYABI_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Using :c:macro:`Py_LIMITED_API` on a non-Windows free-threaded build no | ||
| longer needs an extra :c:macro:`Py_GIL_DISABLED`. |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYou may move #ifdef __GNUC__ here:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis subtle style detail is intentional: I'm inviting #elifs for other compilers.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.