Skip to content

Commit cd66234

Browse files
Add _PyXI_ResolveCapturedException().
1 parent 4e68aaa commit cd66234

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
@@ -1414,6 +1414,26 @@ _PyXI_HasCapturedException(_PyXI_session *session)
14141414
return session->exc != NULL;
14151415
}
14161416

1417+
PyObject *
1418+
_PyXI_ResolveCapturedException(_PyXI_session *session, PyObject *excwrapper)
1419+
{
1420+
assert(!PyErr_Occurred());
1421+
assert(session->exc != NULL);
1422+
PyObject *snapshot = NULL;
1423+
if (session->exc->code == _PyXI_ERR_UNCAUGHT_EXCEPTION) {
1424+
snapshot = PyExceptionSnapshot_FromInfo(&session->exc->uncaught);
1425+
if (snapshot == NULL) {
1426+
return NULL;
1427+
}
1428+
assert(!PyErr_Occurred());
1429+
}
1430+
else {
1431+
_PyXI_ApplyCapturedException(session, excwrapper);
1432+
assert(PyErr_Occurred());
1433+
}
1434+
return snapshot;
1435+
}
1436+
14171437
int
14181438
_PyXI_Enter(_PyXI_session *session,
14191439
PyInterpreterState *interp, PyObject *nsupdates)

0 commit comments

Comments
 (0)