|
17 | 17 | // Additional convention: 0xD = dev |
18 | 18 | #define PYBIND11_VERSION_HEX 0x020B00D1 |
19 | 19 |
|
20 | | -#define PYBIND11_NAMESPACE_BEGIN(name) namespace name { |
21 | | -#define PYBIND11_NAMESPACE_END(name) } |
| 20 | +// Define some generic pybind11 helper macros for warning management. |
| 21 | +// |
| 22 | +// Note that compiler-specific push/pop pairs are baked into the |
| 23 | +// PYBIND11_NAMESPACE_BEGIN/PYBIND11_NAMESPACE_END pair of macros. Therefore manual |
| 24 | +// PYBIND11_WARNING_PUSH/PYBIND11_WARNING_POP are usually only needed in `#include` sections. |
| 25 | +// |
| 26 | +// If you find you need to suppress a warning, please try to make the suppression as local as |
| 27 | +// possible using these macros. Please also be sure to push/pop with the pybind11 macros. Please |
| 28 | +// only use compiler specifics if you need to check specific versions, e.g. Apple Clang vs. vanilla |
| 29 | +// Clang. |
| 30 | +#if defined(_MSC_VER) |
| 31 | +# define PYBIND11_COMPILER_MSVC |
| 32 | +# define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__) |
| 33 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push)) |
| 34 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning(pop)) |
| 35 | +#elif defined(__INTEL_COMPILER) |
| 36 | +# define PYBIND11_COMPILER_INTEL |
| 37 | +# define PYBIND11_PRAGMA(...) _Pragma(# __VA_ARGS__) |
| 38 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning push) |
| 39 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning pop) |
| 40 | +#elif defined(__clang__) |
| 41 | +# define PYBIND11_COMPILER_CLANG |
| 42 | +# define PYBIND11_PRAGMA(...) _Pragma(# __VA_ARGS__) |
| 43 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(clang diagnostic push) |
| 44 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(clang diagnostic push) |
| 45 | +#elif defined(__GNUC__) |
| 46 | +# define PYBIND11_COMPILER_GCC |
| 47 | +# define PYBIND11_PRAGMA(...) _Pragma(# __VA_ARGS__) |
| 48 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(GCC diagnostic push) |
| 49 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(GCC diagnostic pop) |
| 50 | +#endif |
| 51 | + |
| 52 | +#ifdef PYBIND11_COMPILER_MSVC |
| 53 | +# define PYBIND11_WARNING_DISABLE_MSVC(name) PYBIND11_PRAGMA(warning(disable : name)) |
| 54 | +#else |
| 55 | +# define PYBIND11_WARNING_DISABLE_MSVC(name) |
| 56 | +#endif |
| 57 | + |
| 58 | +#ifdef PYBIND11_COMPILER_CLANG |
| 59 | +# define PYBIND11_WARNING_DISABLE_CLANG(name) PYBIND11_PRAGMA(clang diagnostic ignored name) |
| 60 | +#else |
| 61 | +# define PYBIND11_WARNING_DISABLE_CLANG(name) |
| 62 | +#endif |
| 63 | + |
| 64 | +#ifdef PYBIND11_COMPILER_GCC |
| 65 | +# define PYBIND11_WARNING_DISABLE_GCC(name) PYBIND11_PRAGMA(GCC diagnostic ignored name) |
| 66 | +#else |
| 67 | +# define PYBIND11_WARNING_DISABLE_GCC(name) |
| 68 | +#endif |
| 69 | + |
| 70 | +#ifdef PYBIND11_COMPILER_INTEL |
| 71 | +# define PYBIND11_WARNING_DISABLE_INTEL(name) PYBIND11_PRAGMA(warning disable name) |
| 72 | +#else |
| 73 | +# define PYBIND11_WARNING_DISABLE_INTEL(name) |
| 74 | +#endif |
| 75 | + |
| 76 | +#define PYBIND11_NAMESPACE_BEGIN(name) \ |
| 77 | + namespace name { \ |
| 78 | + PYBIND11_WARNING_PUSH |
| 79 | + |
| 80 | +#define PYBIND11_NAMESPACE_END(name) \ |
| 81 | + PYBIND11_WARNING_POP \ |
| 82 | + } |
22 | 83 |
|
23 | 84 | // Robust support for some features and loading modules compiled against different pybind versions |
24 | 85 | // requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute |
|
96 | 157 | #endif |
97 | 158 |
|
98 | 159 | #if !defined(PYBIND11_EXPORT_EXCEPTION) |
99 | | -# ifdef __MINGW32__ |
100 | | -// workaround for: |
101 | | -// error: 'dllexport' implies default visibility, but xxx has already been declared with a |
102 | | -// different visibility |
103 | | -# define PYBIND11_EXPORT_EXCEPTION |
104 | | -# else |
| 160 | +# if defined(__apple_build_version__) |
105 | 161 | # define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT |
| 162 | +# else |
| 163 | +# define PYBIND11_EXPORT_EXCEPTION |
106 | 164 | # endif |
107 | 165 | #endif |
108 | 166 |
|
|
154 | 212 |
|
155 | 213 | /// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode |
156 | 214 | #if defined(_MSC_VER) |
157 | | -# pragma warning(push) |
| 215 | +PYBIND11_WARNING_PUSH |
| 216 | +PYBIND11_WARNING_DISABLE_MSVC(4505) |
158 | 217 | // C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only) |
159 | | -# pragma warning(disable : 4505) |
160 | 218 | # if defined(_DEBUG) && !defined(Py_DEBUG) |
161 | 219 | // Workaround for a VS 2022 issue. |
162 | 220 | // NOTE: This workaround knowingly violates the Python.h include order requirement: |
|
206 | 264 | #endif |
207 | 265 |
|
208 | 266 | #include <Python.h> |
| 267 | +// Reminder: WITH_THREAD is always defined if PY_VERSION_HEX >= 0x03070000 |
209 | 268 | #if PY_VERSION_HEX < 0x03060000 |
210 | 269 | # error "PYTHON < 3.6 IS UNSUPPORTED. pybind11 v2.9 was the last to support Python 2 and 3.5." |
211 | 270 | #endif |
|
229 | 288 | # undef copysign |
230 | 289 | #endif |
231 | 290 |
|
| 291 | +#if defined(PYPY_VERSION) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT) |
| 292 | +# define PYBIND11_SIMPLE_GIL_MANAGEMENT |
| 293 | +#endif |
| 294 | + |
232 | 295 | #if defined(_MSC_VER) |
233 | 296 | # if defined(PYBIND11_DEBUG_MARKER) |
234 | 297 | # define _DEBUG |
235 | 298 | # undef PYBIND11_DEBUG_MARKER |
236 | 299 | # endif |
237 | | -# pragma warning(pop) |
| 300 | +PYBIND11_WARNING_POP |
238 | 301 | #endif |
239 | 302 |
|
240 | 303 | #include <cstddef> |
@@ -899,22 +962,13 @@ using expand_side_effects = bool[]; |
899 | 962 |
|
900 | 963 | PYBIND11_NAMESPACE_END(detail) |
901 | 964 |
|
902 | | -#if defined(_MSC_VER) |
903 | | -# pragma warning(push) |
904 | | -# pragma warning(disable : 4275) |
905 | | -// warning C4275: An exported class was derived from a class that wasn't exported. |
906 | | -// Can be ignored when derived from a STL class. |
907 | | -#endif |
908 | 965 | /// C++ bindings of builtin Python exceptions |
909 | 966 | class PYBIND11_EXPORT_EXCEPTION builtin_exception : public std::runtime_error { |
910 | 967 | public: |
911 | 968 | using std::runtime_error::runtime_error; |
912 | 969 | /// Set the error using the Python C API |
913 | 970 | virtual void set_error() const = 0; |
914 | 971 | }; |
915 | | -#if defined(_MSC_VER) |
916 | | -# pragma warning(pop) |
917 | | -#endif |
918 | 972 |
|
919 | 973 | #define PYBIND11_RUNTIME_EXCEPTION(name, type) \ |
920 | 974 | class PYBIND11_EXPORT_EXCEPTION name : public builtin_exception { \ |
@@ -1143,17 +1197,6 @@ constexpr |
1143 | 1197 | # define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...) |
1144 | 1198 | #endif |
1145 | 1199 |
|
1146 | | -#if defined(_MSC_VER) // All versions (as of July 2021). |
1147 | | - |
1148 | | -// warning C4127: Conditional expression is constant |
1149 | | -constexpr inline bool silence_msvc_c4127(bool cond) { return cond; } |
1150 | | - |
1151 | | -# define PYBIND11_SILENCE_MSVC_C4127(...) ::pybind11::detail::silence_msvc_c4127(__VA_ARGS__) |
1152 | | - |
1153 | | -#else |
1154 | | -# define PYBIND11_SILENCE_MSVC_C4127(...) __VA_ARGS__ |
1155 | | -#endif |
1156 | | - |
1157 | 1200 | #if defined(__clang__) \ |
1158 | 1201 | && (defined(__apple_build_version__) /* AppleClang 13.0.0.13000029 was the only data point \ |
1159 | 1202 | available. */ \ |
|
0 commit comments