##// END OF EJS Templates
improved error handling on destroyed objects (since static access should still be possible)...
florianlink -
r78:eaf55225d8f6
parent child
Show More
@@ -228,16 +228,18 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
228 PyObject* dict = PyBaseObject_Type.tp_getattro(obj, name);
228 PyObject* dict = PyBaseObject_Type.tp_getattro(obj, name);
229 dict = PyDict_Copy(dict);
229 dict = PyDict_Copy(dict);
230
230
231 // only the properties are missing, the rest is already available from
231 if (wrapper->_obj) {
232 // PythonQtClassWrapper...
232 // only the properties are missing, the rest is already available from
233 QStringList l = wrapper->classInfo()->propertyList();
233 // PythonQtClassWrapper...
234 foreach (QString name, l) {
234 QStringList l = wrapper->classInfo()->propertyList();
235 PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
235 foreach (QString name, l) {
236 if (o) {
236 PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
237 PyDict_SetItemString(dict, name.toLatin1().data(), o);
237 if (o) {
238 Py_DECREF(o);
238 PyDict_SetItemString(dict, name.toLatin1().data(), o);
239 } else {
239 Py_DECREF(o);
240 std::cerr << "PythonQtInstanceWrapper: something is wrong, could not get attribute " << name.toLatin1().data();
240 } else {
241 std::cerr << "PythonQtInstanceWrapper: something is wrong, could not get attribute " << name.toLatin1().data();
242 }
241 }
243 }
242 }
244 }
243 // Note: we do not put children into the dict, is would look confusing?!
245 // Note: we do not put children into the dict, is would look confusing?!
@@ -251,12 +253,6 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
251 }
253 }
252 PyErr_Clear();
254 PyErr_Clear();
253
255
254 if (!wrapper->_obj && !wrapper->_wrappedPtr) {
255 QString error = QString("Trying to read attribute '") + attributeName + "' from a destroyed " + wrapper->classInfo()->className() + " object";
256 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
257 return NULL;
258 }
259
260 // mlabDebugConst("Python","get " << attributeName);
256 // mlabDebugConst("Python","get " << attributeName);
261
257
262 // TODO: dynamic properties are missing
258 // TODO: dynamic properties are missing
@@ -271,6 +267,10 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
271 Py_INCREF(Py_None);
267 Py_INCREF(Py_None);
272 return Py_None;
268 return Py_None;
273 }
269 }
270 } else {
271 QString error = QString("Trying to read property '") + attributeName + "' from a destroyed " + wrapper->classInfo()->className() + " object";
272 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
273 return NULL;
274 }
274 }
275 break;
275 break;
276 case PythonQtMemberInfo::Slot:
276 case PythonQtMemberInfo::Slot:
@@ -278,24 +278,24 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
278 break;
278 break;
279 case PythonQtMemberInfo::EnumValue:
279 case PythonQtMemberInfo::EnumValue:
280 {
280 {
281 PyObject* enumValue = member._enumValue;
281 PyObject* enumValue = member._enumValue;
282 Py_INCREF(enumValue);
282 Py_INCREF(enumValue);
283 return enumValue;
283 return enumValue;
284 }
284 }
285 break;
285 break;
286 case PythonQtMemberInfo::EnumWrapper:
286 case PythonQtMemberInfo::EnumWrapper:
287 {
287 {
288 PyObject* enumWrapper = member._enumWrapper;
288 PyObject* enumWrapper = member._enumWrapper;
289 Py_INCREF(enumWrapper);
289 Py_INCREF(enumWrapper);
290 return enumWrapper;
290 return enumWrapper;
291 }
291 }
292 break;
292 break;
293 default:
293 default:
294 // is an invalid type, go on
294 // is an invalid type, go on
295 break;
295 break;
296 }
296 }
297
297
298 // look for the interal methods (className(), help())
298 // look for the internal methods (className(), help())
299 PyObject* internalMethod = Py_FindMethod( PythonQtInstanceWrapper_methods, obj, (char*)attributeName);
299 PyObject* internalMethod = Py_FindMethod( PythonQtInstanceWrapper_methods, obj, (char*)attributeName);
300 if (internalMethod) {
300 if (internalMethod) {
301 return internalMethod;
301 return internalMethod;
General Comments 0
You need to be logged in to leave comments. Login now