1. Ronald Oussoren
  2. pyobjc


Ronald Oussoren  committed 320a9c0

This fixes the symptoms(sp?) of a bug, not sure if this is the correct fix...

The bug: I sometimes get 'SystemError: error return without exception set' when
I have a typo in the name of an initialiser method. This never happens on the
toplevel, but in a callback. The bug is always triggered by code like this:

foo = SomeClass.alloc().inti() # Oops can't spell init

The "fix" saves the exception information before actually deallocating the
uninitialized Objective-C object and restores that information afterwards.

  • Participants
  • Parent commits 7dded5d
  • Branches default

Comments (0)

Files changed (2)

File pyobjc/Modules/objc/class-builder.m

View file
 	PyObject* ptype, *pvalue, *ptraceback;
 	PyGILState_STATE state = PyGILState_Ensure();
 	PyErr_Fetch(&ptype, &pvalue, &ptraceback);

File pyobjc/Modules/objc/objc-object.m

View file
 static void
 object_dealloc(PyObject* obj)
+	/* XXX: This should not be necessary, but if we don't do this we
+	 * sometimes loose exception information...
+	 */
+	PyObject* ptype, *pvalue, *ptraceback;
+	PyErr_Fetch(&ptype, &pvalue, &ptraceback);
 	/* If the object is not yet initialized we try to initialize it before
+	PyErr_Restore(ptype, pvalue, ptraceback);
 	if (res) goto done;
-		     "'%.50s' object has no attribute '%.400s'",
-		     tp->tp_name, namestr);
+	     "'%.50s' object has no attribute '%.400s'",
+	     tp->tp_name, namestr);
 	if (res != NULL) {
 		/* class methods cannot be accessed through instances */
 		if (PyObjCSelector_Check(res) 
 				&& PyObjCSelector_IsClassMethod(res)) {
+			Py_DECREF(res);
 			     "'%.50s' object has no attribute '%.400s'",
 			     tp->tp_name, PyString_AS_STRING(name));
-			Py_DECREF(res);
 			res = NULL;