From 225dbae67e8f03d1788339d30f41b9b9e43f329f Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Sun, 20 Feb 2022 12:40:27 -0500 Subject: [PATCH] Reviewer suggestions --- .github/workflows/ci.yml | 3 ++- include/pybind11/detail/type_caster_base.h | 20 +++++++++----------- include/pybind11/pytypes.h | 3 --- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab138c9be..d6b74dfbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -402,7 +402,8 @@ jobs: -DCMAKE_CXX_STANDARD=11 \ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \ -DCMAKE_CXX_FLAGS="-Wc,--pending_instantiations=0" \ - -DPYBIND11_TEST_FILTER="test_smart_ptr.cpp;test_virtual_functions.cpp"\ + -DPYBIND11_TEST_FILTER="test_smart_ptr.cpp;test_virtual_functions.cpp" \ + -DCMAKE_BUILD_TYPE=Debug # Building before installing Pip should produce a warning but not an error - name: Build diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index dadbe1708..abd0c67b9 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -469,22 +469,23 @@ PYBIND11_NOINLINE bool isinstance_generic(handle obj, const std::type_info &tp) return isinstance(obj, type); } -PYBIND11_NOINLINE std::string error_string(PyObject *type, PyObject *value, PyObject *trace) { - if (!type) { +PYBIND11_NOINLINE std::string +error_string(PyObject *exc_type, PyObject *exc_value, PyObject *exc_trace) { + if (!exc_type) { PyErr_SetString(PyExc_RuntimeError, "Unknown internal error occurred"); return "Unknown internal error occurred"; } - auto result = handle(type).attr("__name__").cast(); + auto result = handle(exc_type).attr("__name__").cast(); result += ": "; - if (value) { - result += (std::string) str(value); + if (exc_value) { + result += (std::string) str(exc_value); } - if (trace) { + if (exc_trace) { #if !defined(PYPY_VERSION) - auto *tb = (PyTracebackObject *) trace; + auto *tb = (PyTracebackObject *) exc_trace; // Get the deepest trace possible. while (tb->tb_next) { @@ -507,7 +508,7 @@ PYBIND11_NOINLINE std::string error_string(PyObject *type, PyObject *value, PyOb frame = frame->f_back; Py_DECREF(f_code); } -#endif +#endif //! defined(PYPY_VERSION) } return result; @@ -517,9 +518,6 @@ 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 eda653c31..8abb85cc3 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -387,9 +387,6 @@ public: PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); if (m_type) { PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); - /*if (m_trace) { - PyException_SetTraceback(m_value.ptr(), m_trace.ptr()); - }*/ } }