From 947ce094f432aea3d5791604aac9a2eaa80a57bc 2009-05-24 09:28:55 From: florianlink Date: 2009-05-24 09:28:55 Subject: [PATCH] improved strictness when enum values are used git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@88 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp index a29c488..4eda03c 100644 --- a/src/PythonQtConversion.cpp +++ b/src/PythonQtConversion.cpp @@ -635,12 +635,15 @@ int PythonQtConv::PyObjGetInt(PyObject* val, bool strict, bool &ok) { qint64 PythonQtConv::PyObjGetLongLong(PyObject* val, bool strict, bool &ok) { qint64 d = 0; ok = true; - if (PyObject_TypeCheck(val, &PyInt_Type)) { + if (val->ob_type == &PyInt_Type) { d = PyInt_AS_LONG(val); } else if (val->ob_type == &PyLong_Type) { d = PyLong_AsLongLong(val); } else if (!strict) { - if (val->ob_type == &PyFloat_Type) { + if (PyObject_TypeCheck(val, &PyInt_Type)) { + // support for derived int classes, e.g. for our enums + d = PyInt_AS_LONG(val); + } else if (val->ob_type == &PyFloat_Type) { d = floor(PyFloat_AS_DOUBLE(val)); } else if (val == Py_False) { d = 0; @@ -663,7 +666,10 @@ quint64 PythonQtConv::PyObjGetULongLong(PyObject* val, bool strict, bool &ok) { } else if (val->ob_type == &PyLong_Type) { d = PyLong_AsLongLong(val); } else if (!strict) { - if (val->ob_type == &PyFloat_Type) { + if (PyObject_TypeCheck(val, &PyInt_Type)) { + // support for derived int classes, e.g. for our enums + d = PyInt_AS_LONG(val); + } else if (val->ob_type == &PyFloat_Type) { d = floor(PyFloat_AS_DOUBLE(val)); } else if (val == Py_False) { d = 0;