summaryrefslogtreecommitdiff
path: root/Python/errors.c
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-07-31 00:42:16 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-07-31 00:42:16 +0000
commit9261d3003b24ff4c8442bcd10abb8fe1366c033b (patch)
treeed60e76e7f96c722968a15439f9e34418bf34af9 /Python/errors.c
parent22ef213b5440ad1df260ff4ff924e2e937fd3005 (diff)
downloadcpython-9261d3003b24ff4c8442bcd10abb8fe1366c033b.tar.gz
#2542: now that issubclass() may call arbitrary code,
make sure that PyErr_ExceptionMatches returns 0 when an exception occurs there.
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 8951d57935..5d9cab5a4c 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -106,9 +106,18 @@ PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
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;