Skip to content

Commit e0a2017

Browse files
committed
fix: use PYBIND11_EXPORT_EXCEPTION
1 parent bde16f1 commit e0a2017

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

include/pybind11/detail/common.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@
8989
# endif
9090
#endif
9191

92+
// Exceptions can't be marked with __declspec(dllexport) in MinGW
93+
#if !defined(PYBIND11_EXPORT)
94+
# ifdef __MINGW32__
95+
# define PYBIND11_EXPORT_EXCEPTION
96+
# else
97+
# define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT
98+
# endif
99+
#endif
100+
101+
92102
#if defined(_MSC_VER)
93103
# define PYBIND11_NOINLINE __declspec(noinline)
94104
#else
@@ -735,12 +745,6 @@ using expand_side_effects = bool[];
735745

736746
PYBIND11_NAMESPACE_END(detail)
737747

738-
#ifdef __MINGW32__
739-
# pragma push_macro("PYBIND11_EXPORT")
740-
# undef PYBIND11_EXPORT
741-
# define PYBIND11_EXPORT
742-
#endif
743-
744748
#if defined(_MSC_VER)
745749
# pragma warning(push)
746750
# pragma warning(disable: 4275) // warning C4275: An exported class was derived from a class that wasn't exported. Can be ignored when derived from a STL class.
@@ -757,7 +761,7 @@ class PYBIND11_EXPORT builtin_exception : public std::runtime_error {
757761
#endif
758762

759763
#define PYBIND11_RUNTIME_EXCEPTION(name, type) \
760-
class PYBIND11_EXPORT name : public builtin_exception { public: \
764+
class PYBIND11_EXPORT_EXCEPTION name : public builtin_exception { public: \
761765
using builtin_exception::builtin_exception; \
762766
name() : name("") { } \
763767
void set_error() const override { PyErr_SetString(type, what()); } \
@@ -773,10 +777,6 @@ PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
773777
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
774778
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
775779

776-
#ifdef __MINGW32__
777-
# pragma pop_macro("PYBIND11_EXPORT")
778-
#endif
779-
780780
[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const char *reason) { throw std::runtime_error(reason); }
781781
[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const std::string &reason) { throw std::runtime_error(reason); }
782782

include/pybind11/pytypes.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,6 @@ PYBIND11_NAMESPACE_BEGIN(detail)
319319
inline std::string error_string();
320320
PYBIND11_NAMESPACE_END(detail)
321321

322-
#ifdef __MINGW32__
323-
# pragma push_macro("PYBIND11_EXPORT")
324-
# undef PYBIND11_EXPORT
325-
# define PYBIND11_EXPORT
326-
#endif
327-
328322
#if defined(_MSC_VER)
329323
# pragma warning(push)
330324
# pragma warning(disable: 4275 4251) // warning C4275: An exported class was derived from a class that wasn't exported. Can be ignored when derived from a STL class.
@@ -333,7 +327,7 @@ PYBIND11_NAMESPACE_END(detail)
333327
/// thrown to propagate python-side errors back through C++ which can either be caught manually or
334328
/// else falls back to the function dispatcher (which then raises the captured error back to
335329
/// python).
336-
class PYBIND11_EXPORT error_already_set : public std::runtime_error {
330+
class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
337331
public:
338332
/// Constructs a new exception from the current Python error indicator, if any. The current
339333
/// Python error indicator will be cleared.
@@ -388,10 +382,6 @@ class PYBIND11_EXPORT error_already_set : public std::runtime_error {
388382
# pragma warning(pop)
389383
#endif
390384

391-
#ifdef __MINGW32__
392-
# pragma pop_macro("PYBIND11_EXPORT")
393-
#endif
394-
395385
/** \defgroup python_builtins _
396386
Unless stated otherwise, the following C++ functions behave the same
397387
as their Python counterparts.

0 commit comments

Comments
 (0)