Skip to content

gh-76785: Add an Internal ExceptionSnapshot Type #111572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
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 _PyExc_FiniHeapObjects(), to call before _PyInterpreterState_Clea…
…r().
  • Loading branch information
ericsnowcurrently committed Nov 6, 2023
commit ce2db5d7e6315a0835872dc3578b2c729cd34585
3 changes: 2 additions & 1 deletion Include/internal/pycore_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern "C" {
extern PyStatus _PyExc_InitState(PyInterpreterState *);
extern PyStatus _PyExc_InitGlobalObjects(PyInterpreterState *);
extern int _PyExc_InitTypes(PyInterpreterState *);
extern void _PyExc_FiniHeapObjects(PyInterpreterState *);
extern void _PyExc_FiniTypes(PyInterpreterState *);
extern void _PyExc_Fini(PyInterpreterState *);


Expand All @@ -32,7 +34,6 @@ struct _Py_exc_state {
PyTypeObject *ExceptionSnapshotType;
};

extern void _PyExc_ClearExceptionGroupType(PyInterpreterState *);

/* other API */

Expand Down
25 changes: 8 additions & 17 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3682,14 +3682,9 @@ _PyExc_InitTypes(PyInterpreterState *interp)
return 0;
}


static void
_exc_snapshot_clear_type(PyInterpreterState *interp);

static void
void
_PyExc_FiniTypes(PyInterpreterState *interp)
{
_exc_snapshot_clear_type(interp);
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_exceptions) - 1; i >= 0; i--) {
PyTypeObject *exc = static_exceptions[i].exc;
_PyStaticType_Dealloc(interp, exc);
Expand Down Expand Up @@ -3806,11 +3801,16 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod)
return 0;
}


// _PyExc_FiniHeapObjects() must be called before the interpreter
// state is cleared, since there are heap types to clean up.

void
_PyExc_ClearExceptionGroupType(PyInterpreterState *interp)
_PyExc_FiniHeapObjects(PyInterpreterState *interp)
{
struct _Py_exc_state *state = &interp->exc_state;
struct _Py_exc_state *state = get_exc_state(interp);
Py_CLEAR(state->PyExc_ExceptionGroup);
Py_CLEAR(state->ExceptionSnapshotType);
}

void
Expand All @@ -3819,8 +3819,6 @@ _PyExc_Fini(PyInterpreterState *interp)
struct _Py_exc_state *state = &interp->exc_state;
free_preallocated_memerrors(state);
Py_CLEAR(state->errnomap);

_PyExc_FiniTypes(interp);
}

int
Expand Down Expand Up @@ -3972,13 +3970,6 @@ _exc_snapshot_init_type(PyInterpreterState *interp)
return 0;
}

static void
_exc_snapshot_clear_type(PyInterpreterState *interp)
{
struct _Py_exc_state *state = get_exc_state(interp);
Py_CLEAR(state->ExceptionSnapshotType);
}

PyTypeObject *
_PyExc_GetExceptionSnapshotType(PyInterpreterState *interp)
{
Expand Down
5 changes: 3 additions & 2 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ finalize_interp_types(PyInterpreterState *interp)
{
_PyUnicode_FiniTypes(interp);
_PySys_FiniTypes(interp);
_PyExc_Fini(interp);
_PyExc_FiniTypes(interp);
_PyAsyncGen_Fini(interp);
_PyContext_Fini(interp);
_PyFloat_FiniType(interp);
Expand Down Expand Up @@ -1779,7 +1779,7 @@ finalize_interp_clear(PyThreadState *tstate)
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);

_PyXI_Fini(tstate->interp);
_PyExc_ClearExceptionGroupType(tstate->interp);
_PyExc_FiniHeapObjects(tstate->interp);
_Py_clear_generic_types(tstate->interp);

/* Clear interpreter state and all thread states */
Expand All @@ -1799,6 +1799,7 @@ finalize_interp_clear(PyThreadState *tstate)
_PyPerfTrampoline_Fini();
}

_PyExc_Fini(tstate->interp);
finalize_interp_types(tstate->interp);
}

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy