mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Change base parameter type in register_exception and exception constructor from PyObject* to handle (#2467)
* Change base parameter type in register_exception and excepion constructor from PyObject* to handle * Fix compilation error passing `handle` to `PyObject*`
This commit is contained in:
parent
e7bafc8ec1
commit
16f199f8d9
@ -80,7 +80,7 @@ module and automatically converts any encountered exceptions of type ``CppExp``
|
||||
into Python exceptions of type ``PyExp``.
|
||||
|
||||
It is possible to specify base class for the exception using the third
|
||||
parameter, a pointer to `PyObject`:
|
||||
parameter, a `handle`:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
|
@ -1868,10 +1868,10 @@ template <typename type>
|
||||
class exception : public object {
|
||||
public:
|
||||
exception() = default;
|
||||
exception(handle scope, const char *name, PyObject *base = PyExc_Exception) {
|
||||
exception(handle scope, const char *name, handle base = PyExc_Exception) {
|
||||
std::string full_name = scope.attr("__name__").cast<std::string>() +
|
||||
std::string(".") + name;
|
||||
m_ptr = PyErr_NewException(const_cast<char *>(full_name.c_str()), base, NULL);
|
||||
m_ptr = PyErr_NewException(const_cast<char *>(full_name.c_str()), base.ptr(), NULL);
|
||||
if (hasattr(scope, name))
|
||||
pybind11_fail("Error during initialization: multiple incompatible "
|
||||
"definitions with name \"" + std::string(name) + "\"");
|
||||
@ -1901,7 +1901,7 @@ PYBIND11_NAMESPACE_END(detail)
|
||||
template <typename CppException>
|
||||
exception<CppException> ®ister_exception(handle scope,
|
||||
const char *name,
|
||||
PyObject *base = PyExc_Exception) {
|
||||
handle base = PyExc_Exception) {
|
||||
auto &ex = detail::get_exception_object<CppException>();
|
||||
if (!ex) ex = exception<CppException>(scope, name, base);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user