From 115a757a5d18753659d495c1ceca4541b8f0e0ca Mon Sep 17 00:00:00 2001 From: Sergei Lebedev Date: Thu, 29 Aug 2019 14:56:36 +0100 Subject: [PATCH] Fixed PyPy build --- include/pybind11/cast.h | 4 ++-- include/pybind11/pytypes.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 8ff1871e7..d6af10ed8 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -415,8 +415,8 @@ PYBIND11_NOINLINE inline std::string error_string(PyObject *type, PyObject *valu if (value) result += str(value).cast(); -#if !defined(PYPY_VERSION) if (trace) { +#if !defined(PYPY_VERSION) PyTracebackObject *tb = (PyTracebackObject *) trace; // Get the deepest trace possible. @@ -433,8 +433,8 @@ PYBIND11_NOINLINE inline std::string error_string(PyObject *type, PyObject *valu handle(frame->f_code->co_name).cast() + "\n"; frame = frame->f_back; } - } #endif + } return result; } diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 2945d9133..df0cc70df 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -335,8 +335,10 @@ public: virtual const char* what() const noexcept override { if (m_lazy_what.empty()) { - try { + if (m_type) PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); + + try { m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr()); } catch (...) { return "Unknown internal error occurred";