From d231f15996c4cfc578307a61ed9fb9b937b3bc20 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 15 Feb 2022 12:16:18 -0500 Subject: [PATCH] Try to debug PGI --- include/pybind11/detail/type_caster_base.h | 5 ++++- include/pybind11/pytypes.h | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index e3a6ecbd4..dadbe1708 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -479,7 +479,7 @@ PYBIND11_NOINLINE std::string error_string(PyObject *type, PyObject *value, PyOb result += ": "; if (value) { - result += str(value).cast(); + result += (std::string) str(value); } if (trace) { @@ -517,6 +517,9 @@ PYBIND11_NOINLINE std::string error_string() { error_scope scope; // Preserve error state. if (scope.type) { PyErr_NormalizeException(&scope.type, &scope.value, &scope.trace); + /*if (scope.trace != nullptr){ + PyErr_SetTraceback(scope.value, scope.trace); + }*/ } return error_string(scope.type, scope.value, scope.trace); } diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index fec563208..73a47ec88 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -12,6 +12,7 @@ #include "detail/common.h" #include "buffer_info.h" +#include #include #include @@ -397,9 +398,15 @@ public: inline ~error_already_set() override; const char *what() const noexcept override { - if (m_lazy_what.empty() && m_type) { + if (m_lazy_what.empty()) { try { m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr()); + } catch (const std::exception &e) { + m_lazy_what + = std::string( + "Unknown internal error occurred while constructing error_string:") + + e.what(); + return m_lazy_what.c_str(); } catch (...) { m_lazy_what = "Unknown internal error occurred"; }