Skip to content

Commit 5e9b17e

Browse files
Add _PyXI_ResolveCapturedException().
1 parent 8be52ae commit 5e9b17e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Include/internal/pycore_crossinterp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ PyAPI_FUNC(void) _PyXI_Exit(_PyXI_session *session);
258258
PyAPI_FUNC(void) _PyXI_ApplyCapturedException(
259259
_PyXI_session *session,
260260
PyObject *excwrapper);
261+
PyAPI_FUNC(PyObject *) _PyXI_ResolveCapturedException(
262+
_PyXI_session *session,
263+
PyObject *excwrapper);
261264
PyAPI_FUNC(int) _PyXI_HasCapturedException(_PyXI_session *session);
262265

263266

Python/crossinterp.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,26 @@ _PyXI_HasCapturedException(_PyXI_session *session)
15841584
return session->exc != NULL;
15851585
}
15861586

1587+
PyObject *
1588+
_PyXI_ResolveCapturedException(_PyXI_session *session, PyObject *excwrapper)
1589+
{
1590+
assert(!PyErr_Occurred());
1591+
assert(session->exc != NULL);
1592+
PyObject *snapshot = NULL;
1593+
if (session->exc->code == _PyXI_ERR_UNCAUGHT_EXCEPTION) {
1594+
snapshot = PyExceptionSnapshot_FromInfo(&session->exc->uncaught);
1595+
if (snapshot == NULL) {
1596+
return NULL;
1597+
}
1598+
assert(!PyErr_Occurred());
1599+
}
1600+
else {
1601+
_PyXI_ApplyCapturedException(session, excwrapper);
1602+
assert(PyErr_Occurred());
1603+
}
1604+
return snapshot;
1605+
}
1606+
15871607
int
15881608
_PyXI_Enter(_PyXI_session *session,
15891609
PyInterpreterState *interp, PyObject *nsupdates)

0 commit comments

Comments
 (0)