bug fix: error_string(PyObject **, ...)

This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-05-11 03:48:08 -07:00
parent 58ad49b05e
commit 90b2453cbd
2 changed files with 12 additions and 12 deletions

View File

@ -471,24 +471,24 @@ PYBIND11_NOINLINE bool isinstance_generic(handle obj, const std::type_info &tp)
}
PYBIND11_NOINLINE std::string
error_string(PyObject *exc_type, PyObject *exc_value, PyObject *exc_trace) {
if (!exc_type) {
error_string(PyObject **exc_type, PyObject **exc_value, PyObject **exc_trace) {
if (*exc_type == nullptr) {
pybind11_fail(
"Internal error: pybind11::detail::error_string() called with exc_type == nullptr");
}
PyErr_NormalizeException(&exc_type, &exc_value, &exc_trace);
PyErr_NormalizeException(exc_type, exc_value, exc_trace);
auto result = handle(exc_type).attr("__name__").cast<std::string>();
auto result = handle(*exc_type).attr("__name__").cast<std::string>();
result += ": ";
if (exc_value) {
result += (std::string) str(exc_value);
if (*exc_value) {
result += (std::string) str(*exc_value);
}
if (exc_trace) {
if (*exc_trace) {
#if !defined(PYPY_VERSION)
auto *tb = (PyTracebackObject *) exc_trace;
auto *tb = reinterpret_cast<PyTracebackObject *>(*exc_trace);
// Get the deepest trace possible.
while (tb->tb_next) {
@ -531,7 +531,7 @@ error_string(PyObject *exc_type, PyObject *exc_value, PyObject *exc_trace) {
PYBIND11_NOINLINE std::string error_string() {
error_scope scope; // Fetch error state.
return error_string(scope.type, scope.value, scope.trace);
return error_string(&scope.type, &scope.value, &scope.trace);
}
PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_info *type) {

View File

@ -364,7 +364,7 @@ T reinterpret_steal(handle h) {
PYBIND11_NAMESPACE_BEGIN(detail)
std::string error_string();
std::string error_string(PyObject *, PyObject *, PyObject *);
std::string error_string(PyObject **, PyObject **, PyObject **);
inline const char *obj_class_name(PyObject *obj) {
if (Py_TYPE(obj) == &PyType_Type) {
@ -409,7 +409,7 @@ public:
const char *what() const noexcept override {
if (m_lazy_what.empty()) {
try {
m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr());
m_lazy_what = detail::error_string(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
// Negate the if condition to test the catch(...) block below.
if (m_lazy_what.empty()) {
throw std::runtime_error(
@ -497,7 +497,7 @@ public:
const object &trace() const { return m_trace; }
private:
object m_type, m_value, m_trace;
mutable object m_type, m_value, m_trace;
mutable std::string m_lazy_what;
};
#if defined(_MSC_VER)