Introduce PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE:

This makes it possible to achieve these two goals:

* Avoid the leading underscore in `PYBIND11_PLATFORM_ABI_ID` (see https://github.com/pybind/pybind11/pull/5439#issuecomment-2503762161)

* Maintain backward compatibility for use cases as reported under https://github.com/pybind/pybind11/pull/5439#issuecomment-2510212677

`PYBIND11_INTERNALS_KIND` is removed in this commit to ensure that `PYBIND11_COMPILER_TYPE` is the first element of the `PYBIND11_PLATFORM_ABI_ID`, so that `PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE` can meaningfully be used as a prefix for `PYBIND11_PLATFORM_ABI_ID` in pybind11/detail/internals.h.
This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-12-02 12:38:42 -08:00
parent b47be2d359
commit e071edc7d6
No known key found for this signature in database
2 changed files with 12 additions and 17 deletions

View File

@ -12,18 +12,19 @@
#define PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x) #x #define PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x) #x
#define PYBIND11_PLATFORM_ABI_ID_TOSTRING(x) PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x) #define PYBIND11_PLATFORM_ABI_ID_TOSTRING(x) PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x)
// Let's assume that different compilers are ABI-incompatible. #ifdef PYBIND11_COMPILER_TYPE
// A user can manually set this string if they know their // // To maintain backward compatibility (see PR #5439).
// compiler is compatible. # define PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE ""
#ifndef PYBIND11_COMPILER_TYPE #else
# define PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE "_"
# if defined(__MINGW32__) # if defined(__MINGW32__)
# define PYBIND11_COMPILER_TYPE "_mingw" # define PYBIND11_COMPILER_TYPE "mingw"
# elif defined(__CYGWIN__) # elif defined(__CYGWIN__)
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin" # define PYBIND11_COMPILER_TYPE "gcc_cygwin"
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# define PYBIND11_COMPILER_TYPE "_msvc" # define PYBIND11_COMPILER_TYPE "msvc"
# elif defined(__INTEL_COMPILER) || defined(__clang__) || defined(__GNUC__) # elif defined(__INTEL_COMPILER) || defined(__clang__) || defined(__GNUC__)
# define PYBIND11_COMPILER_TYPE "_system" // Assumed compatible with system compiler. # define PYBIND11_COMPILER_TYPE "system" // Assumed compatible with system compiler.
# else # else
# error "Unknown PYBIND11_COMPILER_TYPE: PLEASE REVISE THIS CODE." # error "Unknown PYBIND11_COMPILER_TYPE: PLEASE REVISE THIS CODE."
# endif # endif
@ -82,11 +83,5 @@
# define PYBIND11_BUILD_TYPE "" # define PYBIND11_BUILD_TYPE ""
#endif #endif
// Obsolete and slated for removal. DO NOT USE!
#ifndef PYBIND11_INTERNALS_KIND
# define PYBIND11_INTERNALS_KIND ""
#endif
#define PYBIND11_PLATFORM_ABI_ID \ #define PYBIND11_PLATFORM_ABI_ID \
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \ PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE
PYBIND11_BUILD_TYPE

View File

@ -272,11 +272,11 @@ struct type_info {
#define PYBIND11_INTERNALS_ID \ #define PYBIND11_INTERNALS_ID \
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \ "__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
PYBIND11_PLATFORM_ABI_ID "__" PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE PYBIND11_PLATFORM_ABI_ID "__"
#define PYBIND11_MODULE_LOCAL_ID \ #define PYBIND11_MODULE_LOCAL_ID \
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \ "__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
PYBIND11_PLATFORM_ABI_ID "__" PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE PYBIND11_PLATFORM_ABI_ID "__"
/// Each module locally stores a pointer to the `internals` data. The data /// Each module locally stores a pointer to the `internals` data. The data
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`. /// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.