diff Python/errors.c @ 84680:a685f4c6e0b6

Issue #18408: Fix PyErr_NormalizeException(), handle PyObject_IsSubclass() failure PyObject_IsSubclass() can fail and raise a new exception!
author Victor Stinner <victor.stinner@gmail.com>
date Wed, 17 Jul 2013 00:44:53 +0200
parents 2f7c4df5cc46
children 573f7d485ce8
line wrap: on
line diff
--- a/Python/errors.c	Wed Jul 17 00:17:15 2013 +0200
+++ b/Python/errors.c	Wed Jul 17 00:44:53 2013 +0200
@@ -227,12 +227,21 @@
        value will be an instance.
     */
     if (PyExceptionClass_Check(type)) {
+        int is_subclass;
+        if (inclass) {
+            is_subclass = PyObject_IsSubclass(inclass, type);
+            if (is_subclass < 0)
+                goto finally;
+        }
+        else
+            is_subclass = 0;
+
         /* if the value was not an instance, or is not an instance
            whose class is (or is derived from) type, then use the
            value as an argument to instantiation of the type
            class.
         */
-        if (!inclass || !PyObject_IsSubclass(inclass, type)) {
+        if (!inclass || !is_subclass) {
             PyObject *args, *res;
 
             if (value == Py_None)