Skip to content

Commit

Permalink
Set visibility of exceptions to default.
Browse files Browse the repository at this point in the history
Co-authored-by: XZiar <[email protected]>
  • Loading branch information
oraluben and XZiar committed May 22, 2021
1 parent f61855b commit 42b01fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,16 +723,23 @@ using expand_side_effects = bool[];

PYBIND11_NAMESPACE_END(detail)

#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.
#endif
/// C++ bindings of builtin Python exceptions
class builtin_exception : public std::runtime_error {
class PYBIND11_EXPORT builtin_exception : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
/// Set the error using the Python C API
virtual void set_error() const = 0;
};
#if defined(_MSC_VER)
# pragma warning(pop)
#endif

#define PYBIND11_RUNTIME_EXCEPTION(name, type) \
class name : public builtin_exception { public: \
class PYBIND11_EXPORT name : public builtin_exception { public: \
using builtin_exception::builtin_exception; \
name() : name("") { } \
void set_error() const override { PyErr_SetString(type, what()); } \
Expand Down
9 changes: 8 additions & 1 deletion include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,15 @@ PYBIND11_NAMESPACE_BEGIN(detail)
inline std::string error_string();
PYBIND11_NAMESPACE_END(detail)

#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.
#endif
/// Fetch and hold an error which was already set in Python. An instance of this is typically
/// 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 error_already_set : public std::runtime_error {
class PYBIND11_EXPORT 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 @@ -371,6 +375,9 @@ class error_already_set : public std::runtime_error {
private:
object m_type, m_value, m_trace;
};
#if defined(_MSC_VER)
# pragma warning(pop)
#endif

/** \defgroup python_builtins _
Unless stated otherwise, the following C++ functions behave the same
Expand Down

0 comments on commit 42b01fb

Please sign in to comment.