Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 48107:0fbddc04aee1 legacy-trunk
#2542: now that issubclass() may call arbitrary code,
make sure that PyErr_ExceptionMatches returns 0 when an exception occurs there.
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> |
|---|---|
| date | Thu, 31 Jul 2008 00:42:16 +0000 |
| parents | 52294af4b663 |
| children | d01c1d768841 |
comparison
equal
deleted
inserted
replaced
| 48106:8a133663ebde | 48107:0fbddc04aee1 |
|---|---|
| 104 /* err might be an instance, so check its class. */ | 104 /* err might be an instance, so check its class. */ |
| 105 if (PyExceptionInstance_Check(err)) | 105 if (PyExceptionInstance_Check(err)) |
| 106 err = PyExceptionInstance_Class(err); | 106 err = PyExceptionInstance_Class(err); |
| 107 | 107 |
| 108 if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) { | 108 if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) { |
| 109 /* problems here!? not sure PyObject_IsSubclass expects to | 109 int res = 0; |
| 110 be called with an exception pending... */ | 110 PyObject *exception, *value, *tb; |
| 111 return PyObject_IsSubclass(err, exc); | 111 PyErr_Fetch(&exception, &value, &tb); |
| 112 res = PyObject_IsSubclass(err, exc); | |
| 113 /* This function must not fail, so print the error here */ | |
| 114 if (res == -1) { | |
| 115 PyErr_WriteUnraisable(err); | |
| 116 /* issubclass did not succeed */ | |
| 117 res = 0; | |
| 118 } | |
| 119 PyErr_Restore(exception, value, tb); | |
| 120 return res; | |
| 112 } | 121 } |
| 113 | 122 |
| 114 return err == exc; | 123 return err == exc; |
| 115 } | 124 } |
| 116 | 125 |
