Skip to content

Commit c9f5a46

Browse files
committed
pybind11 internals: separate different compilers
1 parent 09f0829 commit c9f5a46

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

include/pybind11/detail/internals.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,33 @@ struct type_info {
147147
# define PYBIND11_BUILD_TYPE ""
148148
#endif
149149

150+
/// Let's assume that different compilers are ABI-incompatible.
151+
#if defined(_MSC_VER)
152+
# define PYBIND11_COMPILER_TYPE "_msvc"
153+
#elif defined(__INTEL_COMPILER)
154+
# define PYBIND11_COMPILER_TYPE "_icc"
155+
#elif defined(__clang__)
156+
# define PYBIND11_COMPILER_TYPE "_clang"
157+
#elif defined(__PGI)
158+
# define PYBIND11_COMPILER_TYPE "_pgi"
159+
#elif defined(__MINGW32__)
160+
# define PYBIND11_COMPILER_TYPE "_mingw"
161+
#elif defined(__CYGWIN__)
162+
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
163+
#elif defined(__GNUC__)
164+
# define PYBIND11_COMPILER_TYPE "_gcc"
165+
#else
166+
# define PYBIND11_COMPILER_TYPE "_unknown"
167+
#endif
168+
169+
#if defined(_LIBCPP_VERSION)
170+
# define PYBIND11_STDLIB "_libcpp"
171+
#elif defined(__GLIBCXX__) || defined(__GLIBCPP__)
172+
# define PYBIND11_STDLIB "_libstdcpp"
173+
#else
174+
# define PYBIND11_STDLIB ""
175+
#endif
176+
150177
/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility.
151178
#if defined(__GXX_ABI_VERSION)
152179
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION)
@@ -161,10 +188,10 @@ struct type_info {
161188
#endif
162189

163190
#define PYBIND11_INTERNALS_ID "__pybind11_internals_v" \
164-
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
191+
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
165192

166193
#define PYBIND11_MODULE_LOCAL_ID "__pybind11_module_local_v" \
167-
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
194+
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
168195

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

0 commit comments

Comments
 (0)