]> granicus.if.org Git - python/commitdiff
In PyErr_GivenExceptionMatches, temporarily bump the recursion
authorGeorg Brandl <georg@python.org>
Thu, 2 Apr 2009 02:47:44 +0000 (02:47 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 2 Apr 2009 02:47:44 +0000 (02:47 +0000)
limit, so that in the most common case PyObject_IsSubclass will
not raise a recursion error we have to ignore anyway.

Python/errors.c

index c88a1909c7fb86b710fe18f2327d7b6a95e99818..02e9572173ad1721e1c63b4a757ac64087014cc7 100644 (file)
@@ -106,10 +106,16 @@ PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
                err = PyExceptionInstance_Class(err);
 
        if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {
-               int res = 0;
+               int res = 0, reclimit;
                PyObject *exception, *value, *tb;
                PyErr_Fetch(&exception, &value, &tb);
+               /* Temporarily bump the recursion limit, so that in the most
+                  common case PyObject_IsSubclass will not raise a recursion
+                  error we have to ignore anyway. */
+               reclimit = Py_GetRecursionLimit();
+               Py_SetRecursionLimit(reclimit + 5);
                res = PyObject_IsSubclass(err, exc);
+               Py_SetRecursionLimit(reclimit);
                /* This function must not fail, so print the error here */
                if (res == -1) {
                        PyErr_WriteUnraisable(err);