diff Python/errors.c @ 48107:0fbddc04aee1 legacy-trunk

#2542: now that issubclass() may call arbitrary code, make sure that PyErr_ExceptionMatches returns 0 when an exception occurs there.
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Thu, 31 Jul 2008 00:42:16 +0000
parents 52294af4b663
children d01c1d768841
line wrap: on
line diff
--- a/Python/errors.c	Wed Jul 30 23:49:28 2008 +0000
+++ b/Python/errors.c	Thu Jul 31 00:42:16 2008 +0000
@@ -106,9 +106,18 @@
 		err = PyExceptionInstance_Class(err);
 
 	if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {
-		/* problems here!?  not sure PyObject_IsSubclass expects to
-		   be called with an exception pending... */
-		return PyObject_IsSubclass(err, exc);
+		int res = 0;
+		PyObject *exception, *value, *tb;
+		PyErr_Fetch(&exception, &value, &tb);
+		res = PyObject_IsSubclass(err, exc);
+		/* This function must not fail, so print the error here */
+		if (res == -1) {
+			PyErr_WriteUnraisable(err);
+			/* issubclass did not succeed */
+			res = 0;
+		}
+		PyErr_Restore(exception, value, tb);
+		return res;
 	}
 
 	return err == exc;