##// END OF EJS Templates
fixed binary operations where first argument is not a wrapper...
florianlink -
r136:90c7a1edb395
parent child
Show More
@@ -77,8 +77,16 static int PythonQtInstanceWrapper_nonzero(PythonQtInstanceWrapper* wrapper)
77 }
77 }
78
78
79
79
80 static PyObject* PythonQtInstanceWrapper_binaryfunc(PythonQtInstanceWrapper* wrapper, PyObject* other, const QByteArray& opName, const QByteArray& fallbackOpName = QByteArray())
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 PyObject* result = NULL;
90 PyObject* result = NULL;
83 PythonQtMemberInfo opSlot = wrapper->classInfo()->member(opName);
91 PythonQtMemberInfo opSlot = wrapper->classInfo()->member(opName);
84 if (opSlot._type == PythonQtMemberInfo::Slot) {
92 if (opSlot._type == PythonQtMemberInfo::Slot) {
@@ -90,25 +98,25 static PyObject* PythonQtInstanceWrapper_binaryfunc(PythonQtInstanceWrapper* wra
90 Py_DECREF(args);
98 Py_DECREF(args);
91 if (!result && !fallbackOpName.isEmpty()) {
99 if (!result && !fallbackOpName.isEmpty()) {
92 // try fallback if we did not get a result
100 // try fallback if we did not get a result
93 result = PythonQtInstanceWrapper_binaryfunc(wrapper, other, fallbackOpName);
101 result = PythonQtInstanceWrapper_binaryfunc(self, other, fallbackOpName);
94 }
102 }
95 }
103 }
96 return result;
104 return result;
97 }
105 }
98
106
99 #define BINARY_OP(NAME) \
107 #define BINARY_OP(NAME) \
100 static PyObject* PythonQtInstanceWrapper_ ## NAME(PythonQtInstanceWrapper* wrapper, PyObject* other) \
108 static PyObject* PythonQtInstanceWrapper_ ## NAME(PyObject* self, PyObject* other) \
101 { \
109 { \
102 static const QByteArray opName("__" #NAME "__"); \
110 static const QByteArray opName("__" #NAME "__"); \
103 return PythonQtInstanceWrapper_binaryfunc(wrapper, other, opName); \
111 return PythonQtInstanceWrapper_binaryfunc(self, other, opName); \
104 }
112 }
105
113
106 #define BINARY_OP_INPLACE(NAME) \
114 #define BINARY_OP_INPLACE(NAME) \
107 static PyObject* PythonQtInstanceWrapper_i ## NAME(PythonQtInstanceWrapper* wrapper, PyObject* other) \
115 static PyObject* PythonQtInstanceWrapper_i ## NAME(PyObject* self, PyObject* other) \
108 { \
116 { \
109 static const QByteArray opName("__i" #NAME "__"); \
117 static const QByteArray opName("__i" #NAME "__"); \
110 static const QByteArray fallbackName("__" #NAME "__"); \
118 static const QByteArray fallbackName("__" #NAME "__"); \
111 return PythonQtInstanceWrapper_binaryfunc(wrapper, other, opName, fallbackName); \
119 return PythonQtInstanceWrapper_binaryfunc(self, other, opName, fallbackName); \
112 }
120 }
113
121
114 BINARY_OP(add)
122 BINARY_OP(add)
General Comments 0
You need to be logged in to leave comments. Login now