From c4547c03e17e0efcf6a75db848a81714f21d28c6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 7 Aug 2022 17:50:28 +0200 Subject: [PATCH] Gui: improve integrated Python console: * correctly handle the case that Py_BuildValue() can return a null pointer * fix a latin1 <-> UTF-8 conversion problem --- src/Gui/PythonConsole.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index 7b2bb66d4170..2e2324acb097 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -190,8 +190,8 @@ PyObject* InteractiveInterpreter::compile(const char* source) const PyObject* eval = PyObject_CallObject(func,args); // must decref later #endif - Py_DECREF(args); - Py_DECREF(func); + Py_XDECREF(args); + Py_XDECREF(func); if (eval){ return eval; @@ -356,11 +356,10 @@ void InteractiveInterpreter::runCode(PyCodeObject* code) const */ bool InteractiveInterpreter::push(const char* line) { - d->buffer.append(QString::fromLatin1(line)); + d->buffer.append(QString::fromUtf8(line)); QString source = d->buffer.join(QLatin1String("\n")); try { - // Source is already UTF-8, so we can use toLatin1() - bool more = runSource(source.toLatin1()); + bool more = runSource(source.toUtf8()); if (!more) d->buffer.clear(); return more;