Skip to content

Commit e071edc

Browse files
committed
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 #5439 (comment)) * Maintain backward compatibility for use cases as reported under #5439 (comment) `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.
1 parent b47be2d commit e071edc

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

include/pybind11/conduit/pybind11_platform_abi_id.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
#define PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x) #x
1313
#define PYBIND11_PLATFORM_ABI_ID_TOSTRING(x) PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x)
1414

15-
// Let's assume that different compilers are ABI-incompatible.
16-
// A user can manually set this string if they know their
17-
// compiler is compatible.
18-
#ifndef PYBIND11_COMPILER_TYPE
15+
#ifdef PYBIND11_COMPILER_TYPE
16+
// // To maintain backward compatibility (see PR #5439).
17+
# define PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE ""
18+
#else
19+
# define PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE "_"
1920
# if defined(__MINGW32__)
20-
# define PYBIND11_COMPILER_TYPE "_mingw"
21+
# define PYBIND11_COMPILER_TYPE "mingw"
2122
# elif defined(__CYGWIN__)
22-
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
23+
# define PYBIND11_COMPILER_TYPE "gcc_cygwin"
2324
# elif defined(_MSC_VER)
24-
# define PYBIND11_COMPILER_TYPE "_msvc"
25+
# define PYBIND11_COMPILER_TYPE "msvc"
2526
# elif defined(__INTEL_COMPILER) || defined(__clang__) || defined(__GNUC__)
26-
# define PYBIND11_COMPILER_TYPE "_system" // Assumed compatible with system compiler.
27+
# define PYBIND11_COMPILER_TYPE "system" // Assumed compatible with system compiler.
2728
# else
2829
# error "Unknown PYBIND11_COMPILER_TYPE: PLEASE REVISE THIS CODE."
2930
# endif
@@ -82,11 +83,5 @@
8283
# define PYBIND11_BUILD_TYPE ""
8384
#endif
8485

85-
// Obsolete and slated for removal. DO NOT USE!
86-
#ifndef PYBIND11_INTERNALS_KIND
87-
# define PYBIND11_INTERNALS_KIND ""
88-
#endif
89-
9086
#define PYBIND11_PLATFORM_ABI_ID \
91-
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
92-
PYBIND11_BUILD_TYPE
87+
PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE

include/pybind11/detail/internals.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ struct type_info {
272272

273273
#define PYBIND11_INTERNALS_ID \
274274
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
275-
PYBIND11_PLATFORM_ABI_ID "__"
275+
PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE PYBIND11_PLATFORM_ABI_ID "__"
276276

277277
#define PYBIND11_MODULE_LOCAL_ID \
278278
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
279-
PYBIND11_PLATFORM_ABI_ID "__"
279+
PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE PYBIND11_PLATFORM_ABI_ID "__"
280280

281281
/// Each module locally stores a pointer to the `internals` data. The data
282282
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.

0 commit comments

Comments
 (0)