Skip to content
Permalink
Browse files

Fix problems with plugins using unicode characters (fixes #15256)

regression introduced during python3 porting
  • Loading branch information
wonder-sk committed Oct 7, 2016
1 parent fb50a3e commit 5b2646cf0560a85899a7e258ff311daa91d48e94
Showing with 13 additions and 3 deletions.
  1. +13 −3 src/python/qgspythonutilsimpl.cpp
@@ -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
@@ -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
@@ -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 );

0 comments on commit 5b2646c

Please sign in to comment.
You can’t perform that action at this time.