Skip to content

Commit

Permalink
Fixed crash in Windows on Python exceptions.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@6928 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed May 3, 2007
1 parent 7732781 commit 2d29cc2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/app/qgspythonutils.cpp
Expand Up @@ -21,9 +21,11 @@
#include "qgspythonutils.h"

#include "qgsapplication.h"
#include "qgslogger.h"

#include <QMessageBox>


QString QgsPythonUtils::mPluginsPath;
PyObject* QgsPythonUtils::mMainModule;
PyObject* QgsPythonUtils::mMainDict;
Expand Down Expand Up @@ -167,6 +169,33 @@ bool QgsPythonUtils::runString(const QString& command)
}


QString QgsPythonUtils::getTypeAsString(PyObject* obj)
{
if (obj == NULL)
return NULL;

if (PyClass_Check(obj))
{
QgsDebugMsg("got class");
return QString(PyString_AsString(((PyClassObject*)obj)->cl_name));
}
else if (PyType_Check(obj))
{
QgsDebugMsg("got type");
return QString(((PyTypeObject*)obj)->tp_name);
}
else
{
QgsDebugMsg("got object");
PyObject* s = PyObject_Str(obj);
QString str;
if (s && PyString_Check(s))
str = QString(PyString_AsString(s));
Py_XDECREF(s);
return str;
}
}

bool QgsPythonUtils::getError(QString& errorClassName, QString& errorText)
{
if (!PyErr_Occurred())
Expand All @@ -179,9 +208,9 @@ bool QgsPythonUtils::getError(QString& errorClassName, QString& errorText)

// get the exception information
PyErr_Fetch(&err_type, &err_value, &err_tb);

// get exception's class name
errorClassName = PyString_AS_STRING(((PyClassObject*)err_type)->cl_name);
errorClassName = getTypeAsString(err_type);

// get exception's text
if (err_value != NULL && err_value != Py_None)
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgspythonutils.h
Expand Up @@ -57,6 +57,9 @@ class QgsPythonUtils

static bool evalString(const QString& command, QString& result);

//! @return object's type name as a string
static QString getTypeAsString(PyObject* obj);

//! get information about error to the supplied arguments
//! @return false if there was no python error
static bool getError(QString& errorClassName, QString& errorText);
Expand Down

0 comments on commit 2d29cc2

Please sign in to comment.