From c1a98d66be08f33bcae297cde7a32bb633efb182 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 16 Feb 2013 12:47:52 +0100 Subject: [PATCH] Fix PythonLanguage::ExceptionInfoToString(). --- lib/python/pythoninterpreter.cpp | 2 +- lib/python/pythonlanguage.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/python/pythoninterpreter.cpp b/lib/python/pythoninterpreter.cpp index ba1cc5dc4..8cd1b3937 100644 --- a/lib/python/pythoninterpreter.cpp +++ b/lib/python/pythoninterpreter.cpp @@ -105,7 +105,7 @@ void PythonInterpreter::ProcessCall(const ScriptTask::Ptr& task, const String& f Py_XDECREF(pvalue); Py_XDECREF(ptraceback); - BOOST_THROW_EXCEPTION(runtime_error("Error in Python script:" + msg)); + BOOST_THROW_EXCEPTION(runtime_error("Error in Python script: " + msg)); } Value vresult = PythonLanguage::MarshalFromPython(result); diff --git a/lib/python/pythonlanguage.cpp b/lib/python/pythonlanguage.cpp index d6d8337db..62ab582cf 100644 --- a/lib/python/pythonlanguage.cpp +++ b/lib/python/pythonlanguage.cpp @@ -225,13 +225,25 @@ String PythonLanguage::ExceptionInfoToString(PyObject *type, PyObject *exc, PyOb Py_DECREF(format_exception); Py_DECREF(tb_dict); - if (!result || !PyString_Check(result)) { + if (!result || !PyList_Check(result)) { Py_XDECREF(result); - return "format_exception() returned something that is not a string."; + return "format_exception() returned something that is not a list."; } - String msg = PyString_AsString(result); + String msg; + + for (Py_ssize_t i = 0; i < PyList_Size(result); i++) { + PyObject *li = PyList_GetItem(result, i); + + if (!li || !PyString_Check(li)) { + Py_DECREF(result); + + return "format_exception() returned something that is not a list of strings."; + } + + msg += PyString_AsString(li); + } Py_DECREF(result);