summaryrefslogtreecommitdiff
path: root/Python/errors.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-07-31 01:47:08 +0000
committerBenjamin Peterson <benjamin@python.org>2008-07-31 01:47:08 +0000
commitb6b713ff7cc67125566b5702f8c689b9f50ae229 (patch)
tree6371e9ad92baac31b6d7b5c70b1d6af4d57622e1 /Python/errors.c
parentcd63ce6f78d04c646dce4766bdf81f378f583420 (diff)
downloadcpython-b6b713ff7cc67125566b5702f8c689b9f50ae229.tar.gz
Merged revisions 65320 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r65320 | amaury.forgeotdarc | 2008-07-30 19:42:16 -0500 (Wed, 30 Jul 2008) | 3 lines #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 3b86c48bfb..a06ec02d9a 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -157,9 +157,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;