mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-102493: fix normalization in PyErr_SetObject (#102502)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
54060ae91d
commit
a33ca2ad1f
4 changed files with 56 additions and 4 deletions
|
@ -149,9 +149,16 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
|
|||
exception);
|
||||
return;
|
||||
}
|
||||
Py_XINCREF(value);
|
||||
/* Normalize the exception */
|
||||
if (value == NULL || (PyObject *)Py_TYPE(value) != exception) {
|
||||
int is_subclass = 0;
|
||||
if (value != NULL && PyExceptionInstance_Check(value)) {
|
||||
is_subclass = PyObject_IsSubclass((PyObject *)Py_TYPE(value), exception);
|
||||
if (is_subclass < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Py_XINCREF(value);
|
||||
if (!is_subclass) {
|
||||
/* We must normalize the value right now */
|
||||
PyObject *fixed_value;
|
||||
|
||||
|
@ -206,9 +213,10 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
|
|||
Py_DECREF(exc_value);
|
||||
}
|
||||
}
|
||||
if (value != NULL && PyExceptionInstance_Check(value))
|
||||
assert(value != NULL);
|
||||
if (PyExceptionInstance_Check(value))
|
||||
tb = PyException_GetTraceback(value);
|
||||
_PyErr_Restore(tstate, Py_XNewRef(exception), value, tb);
|
||||
_PyErr_Restore(tstate, Py_NewRef(Py_TYPE(value)), value, tb);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue