From 246daedd11b7b2155963ffc1bf2b77518fd9b2e0 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Thu, 31 Jul 2008 00:42:16 +0000 Subject: #2542: now that issubclass() may call arbitrary code, make sure that PyErr_ExceptionMatches returns 0 when an exception occurs there. --- Python/errors.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Python') 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; -- cgit v1.2.1