Skip to content
Closed
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
Add the ExceptionSnapshot type.
  • Loading branch information
ericsnowcurrently committed Nov 6, 2023
commit 73e49185ae43fc2b32b0c31a4fcf74b589bfadc8
23 changes: 23 additions & 0 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ add_new_exception(PyObject *mod, const char *name, PyObject *base)
/* module state *************************************************************/

typedef struct {
/* heap types */
PyTypeObject *ExceptionSnapshotType;

/* exceptions */
PyObject *RunFailedError;
} module_state;
Expand All @@ -67,6 +70,9 @@ get_module_state(PyObject *mod)
static int
traverse_module_state(module_state *state, visitproc visit, void *arg)
{
/* heap types */
Py_VISIT(state->ExceptionSnapshotType);

/* exceptions */
Py_VISIT(state->RunFailedError);

Expand All @@ -76,6 +82,9 @@ traverse_module_state(module_state *state, visitproc visit, void *arg)
static int
clear_module_state(module_state *state)
{
/* heap types */
Py_CLEAR(state->ExceptionSnapshotType);

/* exceptions */
Py_CLEAR(state->RunFailedError);

Expand Down Expand Up @@ -759,6 +768,11 @@ The 'interpreters' module provides a more convenient interface.");
static int
module_exec(PyObject *mod)
{
module_state *state = get_module_state(mod);
if (state == NULL) {
goto error;
}

/* Add exception types */
if (exceptions_init(mod) != 0) {
goto error;
Expand All @@ -769,6 +783,15 @@ module_exec(PyObject *mod)
goto error;
}

// ExceptionSnapshot
state->ExceptionSnapshotType = PyStructSequence_NewType(&exc_snapshot_desc);
if (state->ExceptionSnapshotType == NULL) {
goto error;
}
if (PyModule_AddType(mod, state->ExceptionSnapshotType) < 0) {
goto error;
}

return 0;

error:
Expand Down