Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix normalization in PyErr_SetObject
  • Loading branch information
iritkatriel committed Mar 7, 2023
commit feef425173732849be82809e8d5f62eda74e9919
11 changes: 9 additions & 2 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
}
Py_XINCREF(value);
/* Normalize the exception */
if (value == NULL || (PyObject *)Py_TYPE(value) != exception) {
int is_subclass = 0;
if (value != NULL) {
is_subclass = PyObject_IsSubclass((PyObject*)Py_TYPE(value), exception);
Comment thread
iritkatriel marked this conversation as resolved.
Outdated
Comment thread
gvanrossum marked this conversation as resolved.
Outdated
if (is_subclass < 0) {
return;
Comment thread
iritkatriel marked this conversation as resolved.
}
}
if (value == NULL || !is_subclass) {
/* We must normalize the value right now */
PyObject *fixed_value;

Expand Down Expand Up @@ -208,7 +215,7 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
}
if (value != NULL && 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);
Comment thread
iritkatriel marked this conversation as resolved.
}

void
Expand Down