diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 5ff74856b1..17d22be867 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -654,15 +654,23 @@ using expand_side_effects = bool[]; NAMESPACE_END(detail) /// C++ bindings of builtin Python exceptions -class builtin_exception : public std::runtime_error { +// +#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 +#endif +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()); } \ diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 3329fda2d4..4815defc30 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -43,7 +43,7 @@ using list_accessor = accessor; using tuple_accessor = accessor; /// Tag and check to identify a class which implements the Python object API -class pyobject_tag { }; +class PYBIND11_EXPORT pyobject_tag { }; template using is_pyobject = std::is_base_of>; /** \rst @@ -51,7 +51,7 @@ template using is_pyobject = std::is_base_of -class object_api : public pyobject_tag { +class PYBIND11_EXPORT object_api : public pyobject_tag { const Derived &derived() const { return static_cast(*this); } public: @@ -171,7 +171,7 @@ NAMESPACE_END(detail) The `object` class inherits from `handle` and adds automatic reference counting features. \endrst */ -class handle : public detail::object_api { +class PYBIND11_EXPORT handle : public detail::object_api { public: /// The default constructor creates a handle with a ``nullptr``-valued pointer handle() = default; @@ -227,7 +227,7 @@ class handle : public detail::object_api { scope and is destructed. When using `object` instances consistently, it is much easier to get reference counting right at the first attempt. \endrst */ -class object : public handle { +class PYBIND11_EXPORT object : public handle { public: object() = default; PYBIND11_DEPRECATED("Use reinterpret_borrow() or reinterpret_steal()") @@ -319,7 +319,11 @@ 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 error_already_set : public std::runtime_error { +#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 +#endif +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. @@ -349,7 +353,9 @@ class error_already_set : public std::runtime_error { private: object type, value, trace; }; - +#if defined(_MSC_VER) +# pragma warning(pop) +#endif /** \defgroup python_builtins _ Unless stated otherwise, the following C++ functions behave the same as their Python counterparts.