@@ -77,8 +77,16 static int PythonQtInstanceWrapper_nonzero(PythonQtInstanceWrapper* wrapper) | |||
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | |
|
80 |
static PyObject* PythonQtInstanceWrapper_binaryfunc(Pyt |
|
|
80 | static PyObject* PythonQtInstanceWrapper_binaryfunc(PyObject* self, PyObject* other, const QByteArray& opName, const QByteArray& fallbackOpName = QByteArray()) | |
|
81 | 81 | { |
|
82 | // since we disabled type checking, we can receive any object as self, but we currently only support | |
|
83 | // different objects on the right. Otherwise we would need to generate __radd__ etc. methods. | |
|
84 | if (!PyObject_TypeCheck(self, &PythonQtInstanceWrapper_Type)) { | |
|
85 | QString error = "Unsupported operation " + opName + "(" + self->ob_type->tp_name + ", " + other->ob_type->tp_name + ")"; | |
|
86 | PyErr_SetString(PyExc_ArithmeticError, error.toLatin1().data()); | |
|
87 | return NULL; | |
|
88 | } | |
|
89 | PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)self; | |
|
82 | 90 | PyObject* result = NULL; |
|
83 | 91 | PythonQtMemberInfo opSlot = wrapper->classInfo()->member(opName); |
|
84 | 92 | if (opSlot._type == PythonQtMemberInfo::Slot) { |
@@ -90,25 +98,25 static PyObject* PythonQtInstanceWrapper_binaryfunc(PythonQtInstanceWrapper* wra | |||
|
90 | 98 | Py_DECREF(args); |
|
91 | 99 | if (!result && !fallbackOpName.isEmpty()) { |
|
92 | 100 | // try fallback if we did not get a result |
|
93 |
result = PythonQtInstanceWrapper_binaryfunc( |
|
|
101 | result = PythonQtInstanceWrapper_binaryfunc(self, other, fallbackOpName); | |
|
94 | 102 | } |
|
95 | 103 | } |
|
96 | 104 | return result; |
|
97 | 105 | } |
|
98 | 106 | |
|
99 | 107 | #define BINARY_OP(NAME) \ |
|
100 |
static PyObject* PythonQtInstanceWrapper_ ## NAME(Py |
|
|
108 | static PyObject* PythonQtInstanceWrapper_ ## NAME(PyObject* self, PyObject* other) \ | |
|
101 | 109 | { \ |
|
102 | 110 | static const QByteArray opName("__" #NAME "__"); \ |
|
103 |
return PythonQtInstanceWrapper_binaryfunc( |
|
|
111 | return PythonQtInstanceWrapper_binaryfunc(self, other, opName); \ | |
|
104 | 112 | } |
|
105 | 113 | |
|
106 | 114 | #define BINARY_OP_INPLACE(NAME) \ |
|
107 |
static PyObject* PythonQtInstanceWrapper_i ## NAME(Py |
|
|
115 | static PyObject* PythonQtInstanceWrapper_i ## NAME(PyObject* self, PyObject* other) \ | |
|
108 | 116 | { \ |
|
109 | 117 | static const QByteArray opName("__i" #NAME "__"); \ |
|
110 | 118 | static const QByteArray fallbackName("__" #NAME "__"); \ |
|
111 |
return PythonQtInstanceWrapper_binaryfunc( |
|
|
119 | return PythonQtInstanceWrapper_binaryfunc(self, other, opName, fallbackName); \ | |
|
112 | 120 | } |
|
113 | 121 | |
|
114 | 122 | BINARY_OP(add) |
General Comments 0
You need to be logged in to leave comments.
Login now