From ab159c62fe0fc63fcb53269d0f189b21c1bf4df0 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Thu, 5 Oct 2017 18:24:04 +0200 Subject: [PATCH] Bug while retrieving Python stack trace from C++. --- Core/Tools/PyEmbeddedUtils.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Core/Tools/PyEmbeddedUtils.cpp b/Core/Tools/PyEmbeddedUtils.cpp index 13266b63aef..e268e00d6a4 100644 --- a/Core/Tools/PyEmbeddedUtils.cpp +++ b/Core/Tools/PyEmbeddedUtils.cpp @@ -167,14 +167,13 @@ std::string PyEmbeddedUtils::pythonStackTrace() result << "\n"; PyObject* pyth_func = PyObject_GetAttrString(pyth_module, "format_exception"); if (pyth_func && PyCallable_Check(pyth_func)) { - PyObject* pyth_val; - - pyth_val = PyObject_CallFunctionObjArgs(pyth_func, ptype, pvalue, ptraceback, NULL); - - pystr = PyObject_Str(pyth_val); - if (char* str = PyString_AsString(pystr)) - result << std::string(str); - Py_DECREF(pyth_val); + PyObject* pyth_val = PyObject_CallFunctionObjArgs(pyth_func, ptype, pvalue, ptraceback, NULL); + if (pyth_val) { + pystr = PyObject_Str(pyth_val); + if (char* str = PyString_AsString(pystr)) + result << std::string(str); + Py_DECREF(pyth_val); + } } result << "\n"; } -- GitLab