Commits

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.

Comments (0)

Files changed (2)

pyobjc/Modules/objc/class-builder.m

 	PyObject* ptype, *pvalue, *ptraceback;
 	PyGILState_STATE state = PyGILState_Ensure();
 
-
 	PyErr_Fetch(&ptype, &pvalue, &ptraceback);
 
 	CHECK_MAGIC(GETISA(self));

pyobjc/Modules/objc/objc-object.m

 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);
+
 	unregister_proxy(PyObjCObject_GetObject(obj));
 
 	/* If the object is not yet initialized we try to initialize it before
 #else
 	obj->ob_type->tp_free(obj);
 #endif
+
+	PyErr_Restore(ptype, pvalue, ptraceback);
 }
 
 
 	if (res) goto done;
 
 	PyErr_Format(PyExc_AttributeError,
-		     "'%.50s' object has no attribute '%.400s'",
-		     tp->tp_name, namestr);
+	     "'%.50s' object has no attribute '%.400s'",
+	     tp->tp_name, namestr);
+
   done:
 	if (res != NULL) {
 		/* class methods cannot be accessed through instances */
 		if (PyObjCSelector_Check(res) 
 				&& PyObjCSelector_IsClassMethod(res)) {
+			Py_DECREF(res);
 			PyErr_Format(PyExc_AttributeError,
 			     "'%.50s' object has no attribute '%.400s'",
 			     tp->tp_name, PyString_AS_STRING(name));
-			Py_DECREF(res);
 			res = NULL;
 		}
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.