[3.14] gh-132775: Clean Up Cross-Interpreter Error Handling (gh-135492)

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.

(cherry picked from commit c7f4a80079, AKA gh-135369)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-06-14 04:08:25 +02:00 committed by GitHub
parent f77a911c52
commit 0fe5463877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1359 additions and 1128 deletions

View file

@ -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);