Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 84680:a685f4c6e0b6
Issue #18408: Fix PyErr_NormalizeException(), handle PyObject_IsSubclass() failure
PyObject_IsSubclass() can fail and raise a new exception!
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Wed, 17 Jul 2013 00:44:53 +0200 |
| parents | 2f7c4df5cc46 |
| children | 573f7d485ce8 |
comparison
equal
deleted
inserted
replaced
| 84679:cf8f42eadbd0 | 84680:a685f4c6e0b6 |
|---|---|
| 225 | 225 |
| 226 /* Normalize the exception so that if the type is a class, the | 226 /* Normalize the exception so that if the type is a class, the |
| 227 value will be an instance. | 227 value will be an instance. |
| 228 */ | 228 */ |
| 229 if (PyExceptionClass_Check(type)) { | 229 if (PyExceptionClass_Check(type)) { |
| 230 int is_subclass; | |
| 231 if (inclass) { | |
| 232 is_subclass = PyObject_IsSubclass(inclass, type); | |
| 233 if (is_subclass < 0) | |
| 234 goto finally; | |
| 235 } | |
| 236 else | |
| 237 is_subclass = 0; | |
| 238 | |
| 230 /* if the value was not an instance, or is not an instance | 239 /* if the value was not an instance, or is not an instance |
| 231 whose class is (or is derived from) type, then use the | 240 whose class is (or is derived from) type, then use the |
| 232 value as an argument to instantiation of the type | 241 value as an argument to instantiation of the type |
| 233 class. | 242 class. |
| 234 */ | 243 */ |
| 235 if (!inclass || !PyObject_IsSubclass(inclass, type)) { | 244 if (!inclass || !is_subclass) { |
| 236 PyObject *args, *res; | 245 PyObject *args, *res; |
| 237 | 246 |
| 238 if (value == Py_None) | 247 if (value == Py_None) |
| 239 args = PyTuple_New(0); | 248 args = PyTuple_New(0); |
| 240 else if (PyTuple_Check(value)) { | 249 else if (PyTuple_Check(value)) { |
