|
116 | 116 | # define PYBIND11_NOINLINE_DISABLED |
117 | 117 | #endif |
118 | 118 |
|
119 | | -// The PYBIND11_NOINLINE macro is for function DEFINITIONS. |
120 | | -// In contrast, FORWARD DECLARATIONS should never use this macro: |
121 | | -// https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions |
| 119 | +// PYBIND11_INLINE should be used for function definitions in '-inl' files, so they |
| 120 | +// can be made non-inline when compiles as a static library. |
| 121 | +#if defined(PYBIND11_AS_STATIC_LIBRARY) |
| 122 | +# define PYBIND11_INLINE |
| 123 | +#else |
| 124 | +# define PYBIND11_INLINE inline |
| 125 | +#endif |
| 126 | + |
| 127 | + |
122 | 128 | #if defined(PYBIND11_NOINLINE_DISABLED) // Option for maximum portability and experimentation. |
123 | | -# define PYBIND11_NOINLINE inline |
| 129 | +# define PYBIND11_NOINLINE_ATTR |
124 | 130 | #elif defined(_MSC_VER) |
125 | | -# define PYBIND11_NOINLINE __declspec(noinline) inline |
| 131 | +# define PYBIND11_NOINLINE_ATTR __declspec(noinline) |
126 | 132 | #else |
127 | | -# define PYBIND11_NOINLINE __attribute__((noinline)) inline |
| 133 | +# define PYBIND11_NOINLINE_ATTR __attribute__((noinline)) |
128 | 134 | #endif |
129 | 135 |
|
| 136 | +// The PYBIND11_NOINLINE macro is for function DEFINITIONS. |
| 137 | +// In contrast, FORWARD DECLARATIONS should never use this macro: |
| 138 | +// https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions |
| 139 | +// This macro shouldn't be used in '-inl' files. Instead, use `PYBIND11_NOINLINE_ATTR PYBIND11_INLINE`. |
| 140 | +#define PYBIND11_NOINLINE PYBIND11_NOINLINE_ATTR inline |
| 141 | + |
130 | 142 | #if defined(__MINGW32__) |
131 | 143 | // For unknown reasons all PYBIND11_DEPRECATED member trigger a warning when declared |
132 | 144 | // whether it is used or not |
@@ -935,14 +947,8 @@ PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybin |
935 | 947 | /// casting error |
936 | 948 | PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally |
937 | 949 |
|
938 | | -[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason) { |
939 | | - assert(!PyErr_Occurred()); |
940 | | - throw std::runtime_error(reason); |
941 | | -} |
942 | | -[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const std::string &reason) { |
943 | | - assert(!PyErr_Occurred()); |
944 | | - throw std::runtime_error(reason); |
945 | | -} |
| 950 | +[[noreturn]] void pybind11_fail(const char *reason); |
| 951 | +[[noreturn]] void pybind11_fail(const std::string &reason); |
946 | 952 |
|
947 | 953 | template <typename T, typename SFINAE = void> |
948 | 954 | struct format_descriptor {}; |
@@ -991,10 +997,10 @@ constexpr const char |
991 | 997 | /// RAII wrapper that temporarily clears any Python error state |
992 | 998 | struct error_scope { |
993 | 999 | PyObject *type, *value, *trace; |
994 | | - error_scope() { PyErr_Fetch(&type, &value, &trace); } |
| 1000 | + error_scope(); |
995 | 1001 | error_scope(const error_scope &) = delete; |
996 | 1002 | error_scope &operator=(const error_scope &) = delete; |
997 | | - ~error_scope() { PyErr_Restore(type, value, trace); } |
| 1003 | + ~error_scope(); |
998 | 1004 | }; |
999 | 1005 |
|
1000 | 1006 | /// Dummy destructor wrapper that can be used to expose classes with a private destructor |
@@ -1166,3 +1172,7 @@ constexpr inline bool silence_msvc_c4127(bool cond) { return cond; } |
1166 | 1172 |
|
1167 | 1173 | PYBIND11_NAMESPACE_END(detail) |
1168 | 1174 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) |
| 1175 | + |
| 1176 | +#ifndef PYBIND11_AS_STATIC_LIBRARY |
| 1177 | +# include "common-inl.h" |
| 1178 | +#endif |
0 commit comments