Skip to content

Commit

Permalink
Gui: improve integrated Python console:
Browse files Browse the repository at this point in the history
* correctly handle the case that Py_BuildValue() can return a null pointer
* fix a latin1 <-> UTF-8 conversion problem
  • Loading branch information
wwmayer committed Aug 7, 2022
1 parent 460efa3 commit c4547c0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Gui/PythonConsole.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c4547c0

Please sign in to comment.