Skip to content

Commit

Permalink
Fix problems with plugins using unicode characters (fixes #15256)
Browse files Browse the repository at this point in the history
regression introduced during python3 porting
  • Loading branch information
wonder-sk committed Oct 7, 2016
1 parent fb50a3e commit 5b2646c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -28,14 +28,21 @@
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmessageoutput.h"
#include "qgsmessagelog.h"

#include <QMessageBox>
#include <QStringList>
#include <QDir>
#include <QDebug>

#if (PY_VERSION_HEX < 0x03000000)
#define PYOBJ2QSTRING(obj) PyString_AsString( obj )
QString PYOBJ2QSTRING( PyObject* obj )
{
PyObject* utf8 = PyUnicode_AsUTF8String( obj );
QString result = utf8 ? QString::fromUtf8( PyString_AS_STRING( utf8 ) ) : "(qgis error)";
Py_XDECREF( utf8 );
return result;
}
#elif (PY_VERSION_HEX < 0x03030000)
#define PYOBJ2QSTRING(obj) QString::fromUtf8( PyBytes_AsString(PyUnicode_AsUTF8String( obj ) ) )
#else
Expand Down Expand Up @@ -556,7 +563,6 @@ QString QgsPythonUtilsImpl::PyObjectToQString( PyObject* obj )
return "(qgis error)";
}


bool QgsPythonUtilsImpl::evalString( const QString& command, QString& result )
{
// acquire global interpreter lock to ensure we are in a consistent state
Expand All @@ -566,7 +572,11 @@ bool QgsPythonUtilsImpl::evalString( const QString& command, QString& result )
PyObject* res = PyRun_String( command.toUtf8().data(), Py_eval_input, mMainDict, mMainDict );
bool success = nullptr != res;

// TODO: error handling
if ( PyErr_Occurred() )
{
QString traceback = getTraceback();
QgsMessageLog::logMessage( QString( "evalString()) error!\nCommand:\n%1\nError:\n%2" ).arg( command ).arg( traceback ), "Python" );
}

if ( success )
result = PyObjectToQString( res );
Expand Down

0 comments on commit 5b2646c

Please sign in to comment.