Skip to content

Commit 87ebc39

Browse files
committed
factor out platform_abi_id.h from internals.h (no functional changes)
1 parent 2617a04 commit 87ebc39

File tree

2 files changed

+69
-61
lines changed

2 files changed

+69
-61
lines changed

include/pybind11/detail/internals.h

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#pragma once
1111

1212
#include "common.h"
13+
#include "platform_abi_id.h"
1314

1415
#if defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
1516
# include <pybind11/gil.h>
@@ -264,72 +265,13 @@ struct type_info {
264265
bool module_local : 1;
265266
};
266267

267-
/// On MSVC, debug and release builds are not ABI-compatible!
268-
#if defined(_MSC_VER) && defined(_DEBUG)
269-
# define PYBIND11_BUILD_TYPE "_debug"
270-
#else
271-
# define PYBIND11_BUILD_TYPE ""
272-
#endif
273-
274-
/// Let's assume that different compilers are ABI-incompatible.
275-
/// A user can manually set this string if they know their
276-
/// compiler is compatible.
277-
#ifndef PYBIND11_COMPILER_TYPE
278-
# if defined(_MSC_VER)
279-
# define PYBIND11_COMPILER_TYPE "_msvc"
280-
# elif defined(__INTEL_COMPILER)
281-
# define PYBIND11_COMPILER_TYPE "_icc"
282-
# elif defined(__clang__)
283-
# define PYBIND11_COMPILER_TYPE "_clang"
284-
# elif defined(__PGI)
285-
# define PYBIND11_COMPILER_TYPE "_pgi"
286-
# elif defined(__MINGW32__)
287-
# define PYBIND11_COMPILER_TYPE "_mingw"
288-
# elif defined(__CYGWIN__)
289-
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
290-
# elif defined(__GNUC__)
291-
# define PYBIND11_COMPILER_TYPE "_gcc"
292-
# else
293-
# define PYBIND11_COMPILER_TYPE "_unknown"
294-
# endif
295-
#endif
296-
297-
/// Also standard libs
298-
#ifndef PYBIND11_STDLIB
299-
# if defined(_LIBCPP_VERSION)
300-
# define PYBIND11_STDLIB "_libcpp"
301-
# elif defined(__GLIBCXX__) || defined(__GLIBCPP__)
302-
# define PYBIND11_STDLIB "_libstdcpp"
303-
# else
304-
# define PYBIND11_STDLIB ""
305-
# endif
306-
#endif
307-
308-
/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility.
309-
/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898).
310-
#ifndef PYBIND11_BUILD_ABI
311-
# if defined(__GXX_ABI_VERSION)
312-
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION)
313-
# elif defined(_MSC_VER)
314-
# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER)
315-
# else
316-
# define PYBIND11_BUILD_ABI ""
317-
# endif
318-
#endif
319-
320-
#ifndef PYBIND11_INTERNALS_KIND
321-
# define PYBIND11_INTERNALS_KIND ""
322-
#endif
323-
324268
#define PYBIND11_INTERNALS_ID \
325269
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
326-
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
327-
PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
270+
PYBIND11_PLATFORM_ABI_ID "__"
328271

329272
#define PYBIND11_MODULE_LOCAL_ID \
330273
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
331-
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
332-
PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
274+
PYBIND11_PLATFORM_ABI_ID "__"
333275

334276
/// Each module locally stores a pointer to the `internals` data. The data
335277
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2024 The pybind Community.
2+
3+
#pragma once
4+
5+
#include "common.h"
6+
7+
/// On MSVC, debug and release builds are not ABI-compatible!
8+
#if defined(_MSC_VER) && defined(_DEBUG)
9+
# define PYBIND11_BUILD_TYPE "_debug"
10+
#else
11+
# define PYBIND11_BUILD_TYPE ""
12+
#endif
13+
14+
/// Let's assume that different compilers are ABI-incompatible.
15+
/// A user can manually set this string if they know their
16+
/// compiler is compatible.
17+
#ifndef PYBIND11_COMPILER_TYPE
18+
# if defined(_MSC_VER)
19+
# define PYBIND11_COMPILER_TYPE "_msvc"
20+
# elif defined(__INTEL_COMPILER)
21+
# define PYBIND11_COMPILER_TYPE "_icc"
22+
# elif defined(__clang__)
23+
# define PYBIND11_COMPILER_TYPE "_clang"
24+
# elif defined(__PGI)
25+
# define PYBIND11_COMPILER_TYPE "_pgi"
26+
# elif defined(__MINGW32__)
27+
# define PYBIND11_COMPILER_TYPE "_mingw"
28+
# elif defined(__CYGWIN__)
29+
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
30+
# elif defined(__GNUC__)
31+
# define PYBIND11_COMPILER_TYPE "_gcc"
32+
# else
33+
# define PYBIND11_COMPILER_TYPE "_unknown"
34+
# endif
35+
#endif
36+
37+
/// Also standard libs
38+
#ifndef PYBIND11_STDLIB
39+
# if defined(_LIBCPP_VERSION)
40+
# define PYBIND11_STDLIB "_libcpp"
41+
# elif defined(__GLIBCXX__) || defined(__GLIBCPP__)
42+
# define PYBIND11_STDLIB "_libstdcpp"
43+
# else
44+
# define PYBIND11_STDLIB ""
45+
# endif
46+
#endif
47+
48+
/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility.
49+
/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898).
50+
#ifndef PYBIND11_BUILD_ABI
51+
# if defined(__GXX_ABI_VERSION)
52+
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION)
53+
# elif defined(_MSC_VER)
54+
# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER)
55+
# else
56+
# define PYBIND11_BUILD_ABI ""
57+
# endif
58+
#endif
59+
60+
#ifndef PYBIND11_INTERNALS_KIND
61+
# define PYBIND11_INTERNALS_KIND ""
62+
#endif
63+
64+
#define PYBIND11_PLATFORM_ABI_ID \
65+
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
66+
PYBIND11_BUILD_TYPE

0 commit comments

Comments
 (0)