mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-132775: Clean Up Cross-Interpreter Error Handling (gh-135369)
In this refactor we: * move some code around * make a couple of typedefs opaque * decouple errors from session state * improve tracebacks for propagated exceptions This change helps simplify several upcoming changes.
This commit is contained in:
parent
6eb6c5dbfb
commit
c7f4a80079
5 changed files with 527 additions and 315 deletions
File diff suppressed because it is too large
Load diff
|
@ -88,6 +88,33 @@ _PyXIData_FormatNotShareableError(PyThreadState *tstate,
|
|||
va_end(vargs);
|
||||
}
|
||||
|
||||
int
|
||||
_PyXI_UnwrapNotShareableError(PyThreadState * tstate, _PyXI_failure *failure)
|
||||
{
|
||||
PyObject *exctype = get_notshareableerror_type(tstate);
|
||||
assert(exctype != NULL);
|
||||
if (!_PyErr_ExceptionMatches(tstate, exctype)) {
|
||||
return -1;
|
||||
}
|
||||
PyObject *exc = _PyErr_GetRaisedException(tstate);
|
||||
if (failure != NULL) {
|
||||
_PyXI_errcode code = _PyXI_ERR_NOT_SHAREABLE;
|
||||
if (_PyXI_InitFailure(failure, code, exc) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
PyObject *cause = PyException_GetCause(exc);
|
||||
if (cause != NULL) {
|
||||
Py_DECREF(exc);
|
||||
exc = cause;
|
||||
}
|
||||
else {
|
||||
assert(PyException_GetContext(exc) == NULL);
|
||||
}
|
||||
_PyErr_SetRaisedException(tstate, exc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
_PyXIData_getdata_t
|
||||
_PyXIData_Lookup(PyThreadState *tstate, PyObject *obj)
|
||||
|
|
|
@ -7,13 +7,6 @@ _ensure_current_cause(PyThreadState *tstate, PyObject *cause)
|
|||
}
|
||||
PyObject *exc = _PyErr_GetRaisedException(tstate);
|
||||
assert(exc != NULL);
|
||||
PyObject *ctx = PyException_GetContext(exc);
|
||||
if (ctx == NULL) {
|
||||
PyException_SetContext(exc, Py_NewRef(cause));
|
||||
}
|
||||
else {
|
||||
Py_DECREF(ctx);
|
||||
}
|
||||
assert(PyException_GetCause(exc) == NULL);
|
||||
PyException_SetCause(exc, Py_NewRef(cause));
|
||||
_PyErr_SetRaisedException(tstate, exc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue