mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-21 16:09:22 +00:00
Merge branch 'lazy-error-string' of https://github.com/superbobry/pybind11 into lazy-error-string
This commit is contained in:
commit
a8f7a9797e
@ -12,8 +12,8 @@
|
||||
#include "detail/common.h"
|
||||
#include "buffer_info.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@ -367,13 +367,6 @@ std::string error_string();
|
||||
std::string error_string(PyObject *, PyObject *, PyObject *);
|
||||
PYBIND11_NAMESPACE_END(detail)
|
||||
|
||||
inline const char *class_name(PyObject *py) {
|
||||
if (Py_TYPE(py) == &PyType_Type) {
|
||||
return reinterpret_cast<PyTypeObject *>(py)->tp_name;
|
||||
}
|
||||
return Py_TYPE(py)->tp_name;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4275 4251)
|
||||
@ -396,7 +389,9 @@ public:
|
||||
}
|
||||
|
||||
error_already_set(const error_already_set &) = default;
|
||||
error_already_set(error_already_set &&) = default;
|
||||
error_already_set(error_already_set &&e) noexcept
|
||||
: std::runtime_error(e), m_type{std::move(e.m_type)}, m_value{std::move(e.m_value)},
|
||||
m_trace{std::move(e.m_trace)}, m_lazy_what{std::move(e.m_lazy_what)} {};
|
||||
|
||||
inline ~error_already_set() override;
|
||||
|
||||
@ -415,7 +410,7 @@ public:
|
||||
if (m_type.ptr() == nullptr) {
|
||||
msg += "PYTHON_EXCEPTION_TYPE_IS_NULLPTR";
|
||||
} else {
|
||||
const char *tp_name = class_name(m_type.ptr());
|
||||
const char *tp_name = get_class_name(m_type.ptr());
|
||||
if (tp_name == nullptr) {
|
||||
msg += "PYTHON_EXCEPTION_TP_NAME_IS_NULLPTR";
|
||||
} else {
|
||||
@ -436,7 +431,11 @@ public:
|
||||
+ '"';
|
||||
}
|
||||
}
|
||||
std::cerr << msg << std::endl;
|
||||
// Use C calls to reduce include bloat
|
||||
fprintf(stderr, "%s\n", msg.c_str());
|
||||
fflush(stderr);
|
||||
fprintf(stdout, "%s\n", msg.c_str());
|
||||
fflush(stdout);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
@ -490,8 +489,15 @@ public:
|
||||
const object &trace() const { return m_trace; }
|
||||
|
||||
private:
|
||||
mutable std::string m_lazy_what;
|
||||
object m_type, m_value, m_trace;
|
||||
mutable std::string m_lazy_what;
|
||||
|
||||
static const char *get_class_name(PyObject *py) {
|
||||
if (Py_TYPE(py) == &PyType_Type) {
|
||||
return reinterpret_cast<PyTypeObject *>(py)->tp_name;
|
||||
}
|
||||
return Py_TYPE(py)->tp_name;
|
||||
}
|
||||
};
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
|
Loading…
Reference in New Issue
Block a user