Skip to content

Commit

Permalink
fix: use PYBIND11_EXPORT_EXCEPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Jul 30, 2021
1 parent bde16f1 commit e0a2017
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
22 changes: 11 additions & 11 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@
# endif
#endif

// Exceptions can't be marked with __declspec(dllexport) in MinGW
#if !defined(PYBIND11_EXPORT)
# ifdef __MINGW32__
# define PYBIND11_EXPORT_EXCEPTION
# else
# define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT
# endif
#endif


#if defined(_MSC_VER)
# define PYBIND11_NOINLINE __declspec(noinline)
#else
Expand Down Expand Up @@ -735,12 +745,6 @@ using expand_side_effects = bool[];

PYBIND11_NAMESPACE_END(detail)

#ifdef __MINGW32__
# pragma push_macro("PYBIND11_EXPORT")
# undef PYBIND11_EXPORT
# define PYBIND11_EXPORT
#endif

#if defined(_MSC_VER)
# pragma warning(push)
# 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.
Expand All @@ -757,7 +761,7 @@ class PYBIND11_EXPORT builtin_exception : public std::runtime_error {
#endif

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

#ifdef __MINGW32__
# pragma pop_macro("PYBIND11_EXPORT")
#endif

[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const char *reason) { throw std::runtime_error(reason); }
[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const std::string &reason) { throw std::runtime_error(reason); }

Expand Down
12 changes: 1 addition & 11 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,6 @@ PYBIND11_NAMESPACE_BEGIN(detail)
inline std::string error_string();
PYBIND11_NAMESPACE_END(detail)

#ifdef __MINGW32__
# pragma push_macro("PYBIND11_EXPORT")
# undef PYBIND11_EXPORT
# define PYBIND11_EXPORT
#endif

#if defined(_MSC_VER)
# pragma warning(push)
# 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.
Expand All @@ -333,7 +327,7 @@ PYBIND11_NAMESPACE_END(detail)
/// thrown to propagate python-side errors back through C++ which can either be caught manually or
/// else falls back to the function dispatcher (which then raises the captured error back to
/// python).
class PYBIND11_EXPORT error_already_set : public std::runtime_error {
class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
public:
/// Constructs a new exception from the current Python error indicator, if any. The current
/// Python error indicator will be cleared.
Expand Down Expand Up @@ -388,10 +382,6 @@ class PYBIND11_EXPORT error_already_set : public std::runtime_error {
# pragma warning(pop)
#endif

#ifdef __MINGW32__
# pragma pop_macro("PYBIND11_EXPORT")
#endif

/** \defgroup python_builtins _
Unless stated otherwise, the following C++ functions behave the same
as their Python counterparts.
Expand Down

0 comments on commit e0a2017

Please sign in to comment.