summaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorPaulo Alcantara <pcacjr@gmail.com>2011-12-22 16:27:42 -0300
committerPaulo Alcantara <pcacjr@gmail.com>2011-12-22 17:02:23 -0300
commitfaf9f948deb70df76a8e7f91eba861fae78e5273 (patch)
tree6542e9379d5b409e1e6ef9032d4dc892992f56a0 /libshiboken
parent9f40693c728aa652987cebb49fb6b174e22abef8 (diff)
downloadshiboken-faf9f948deb70df76a8e7f91eba861fae78e5273.tar.gz
shiboken-faf9f948deb70df76a8e7f91eba861fae78e5273.tar.xz
shiboken-faf9f948deb70df76a8e7f91eba861fae78e5273.zip
Fix BUG #1097 - "QtGui.QShortcut.setKey requires QKeySequence"
E.g., when calling QtGui.QShortcut.setKey(QtCore.Qt.CTRL + QtCore.Qt.Key_Delete) it was being called as QtGui.QShortcut.setKey(long) (in Python 2) when it should be actually QtGui.QShortcut.setKey(int). So that resulted in a TypeError exception when using Python version 2 with that small code. See http://bugs.pyside.org/show_bug.cgi?id=1097. Signed-off-by: Paulo Alcantara <pcacjr@gmail.com> Reviewed-by: Marcelo Lira <marcelo.lira@openbossa.org> Reviewed-by: Hugo Parente Lima <hugo.pl@gmail.com>
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/sbkenum.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/libshiboken/sbkenum.cpp b/libshiboken/sbkenum.cpp
index 306ffc8d..419ceee3 100644
--- a/libshiboken/sbkenum.cpp
+++ b/libshiboken/sbkenum.cpp
@@ -27,13 +27,13 @@
#include "sbkdbg.h"
#include "autodecref.h"
#include "typeresolver.h"
+#include "sbkpython.h"
#include <string.h>
#include <cstring>
#include <list>
-
-#define SBK_ENUM(ENUM) reinterpret_cast<SbkEnumObject*>(ENUM)
+#define SBK_ENUM(ENUM) reinterpret_cast<SbkEnumObject*>(ENUM)
extern "C"
{
@@ -100,13 +100,17 @@ static PyObject* SbkEnum_tp_new(PyTypeObject* type, PyObject* args, PyObject* kw
return reinterpret_cast<PyObject*>(self);
}
+/* Notes:
+ * On Py3k land we use long type when using integer numbers. However, on older
+ * versions of Python (version 2) we need to convert it to int type,
+ * respectively.
+ *
+ * Thus calling PyInt_FromLong() will result in calling PyLong_FromLong in
+ * Py3k.
+ */
static PyObject* enum_int(PyObject* v)
{
-#ifdef IS_PY3K
- return PyLong_FromLong(SBK_ENUM(v)->ob_value);
-#else
return PyInt_FromLong(SBK_ENUM(v)->ob_value);
-#endif
}
static long getNumberValue(PyObject* v)
@@ -117,7 +121,6 @@ static long getNumberValue(PyObject* v)
return result;
}
-
static PyObject* enum_and(PyObject* self, PyObject* b)
{
if (!PyNumber_Check(b)) {
@@ -127,7 +130,7 @@ static PyObject* enum_and(PyObject* self, PyObject* b)
long valA = SBK_ENUM(self)->ob_value;
long valB = getNumberValue(b);
- return PyLong_FromLong(valA & valB);
+ return PyInt_FromLong(valA & valB);
}
static PyObject* enum_or(PyObject* self, PyObject* b)
@@ -139,7 +142,7 @@ static PyObject* enum_or(PyObject* self, PyObject* b)
long valA = SBK_ENUM(self)->ob_value;
long valB = getNumberValue(b);
- return PyLong_FromLong(valA | valB);
+ return PyInt_FromLong(valA | valB);
}
static PyObject* enum_xor(PyObject* self, PyObject* b)
@@ -151,10 +154,9 @@ static PyObject* enum_xor(PyObject* self, PyObject* b)
long valA = SBK_ENUM(self)->ob_value;
long valB = getNumberValue(b);
- return PyLong_FromLong(valA ^ valB);
+ return PyInt_FromLong(valA ^ valB);
}
-
static int enum_bool(PyObject* v)
{
return (SBK_ENUM(v)->ob_value > 0);
@@ -164,21 +166,21 @@ static PyObject* enum_add(PyObject* self, PyObject* v)
{
long valA = SBK_ENUM(self)->ob_value;
long valB = getNumberValue(v);
- return PyLong_FromLong(valA + valB);
+ return PyInt_FromLong(valA + valB);
}
static PyObject* enum_subtract(PyObject* self, PyObject* v)
{
long valA = SBK_ENUM(self)->ob_value;
long valB = getNumberValue(v);
- return PyLong_FromLong(valA - valB);
+ return PyInt_FromLong(valA - valB);
}
static PyObject* enum_multiply(PyObject* self, PyObject* v)
{
long valA = SBK_ENUM(self)->ob_value;
long valB = getNumberValue(v);
- return PyLong_FromLong(valA * valB);
+ return PyInt_FromLong(valA * valB);
}
#ifndef IS_PY3K
@@ -511,7 +513,6 @@ PyObject* newItem(PyTypeObject* enumType, long itemValue, const char* itemName)
return reinterpret_cast<PyObject*>(enumObj);
}
-
PyTypeObject* newType(const char* name)
{
return newTypeWithName(name, "");