summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-07-31 00:42:16 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-07-31 00:42:16 (GMT)
commit246daedd11b7b2155963ffc1bf2b77518fd9b2e0 (patch)
treebd2cda04804e59399b960689d9c49c10e1195d1a /Python
parentb8827c00b8f4c11e202a7c2401aca1c42531188c (diff)
downloadcpython-246daedd11b7b2155963ffc1bf2b77518fd9b2e0.zip
cpython-246daedd11b7b2155963ffc1bf2b77518fd9b2e0.tar.gz
cpython-246daedd11b7b2155963ffc1bf2b77518fd9b2e0.tar.bz2
#2542: now that issubclass() may call arbitrary code,
make sure that PyErr_ExceptionMatches returns 0 when an exception occurs there.
Diffstat (limited to 'Python')
-rw-r--r--Python/errors.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 8951d57..5d9cab5 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;