8000 bpo-46417: Py_Finalize() clears static exceptioins by vstinner · Pull Request #30805 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46417: Py_Finalize() clears static exceptioins #30805

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

Merged
merged 2 commits into from
Jan 22, 2022
Merged
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
Next Next commit
bpo-46417: Py_Finalize() clears static exceptioins
The Py_Finalize() function now clears exceptions implemented as
static types.

Add _PyExc_FiniTypes() function, called by _PyExc_Fini().
  • Loading branch information
vstinner committed Jan 22, 2022
commit 4312bd311e8e7b2cac1383e01540b9c0560ba5c0
27 changes: 26 additions & 1 deletion Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3536,13 +3536,36 @@ _PyExc_InitTypes(PyInterpreterState *interp)
}


static void
_PyExc_FiniTypes(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
return;
}

for (size_t i=0; i < Py_ARRAY_LENGTH(static_exceptions); i++) {
PyTypeObject *exc = static_exceptions[i].exc;

// Cannot delete a type if it still has subclasses
if (exc->tp_subclasses != NULL) {
continue;
}

_PyStaticType_Dealloc(exc);
}
}


PyStatus
_PyExc_InitGlobalObjects(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
return _PyStatus_OK();
}

if (preallocate_memerrors() < 0) {
return _PyStatus_NO_MEMORY();
}

return _PyStatus_OK();
}

Expand Down Expand Up @@ -3656,6 +3679,8 @@ _PyExc_Fini(PyInterpreterState *interp)
struct _Py_exc_state *state = &interp->exc_state;
free_preallocated_memerrors(state);
Py_CLEAR(state->errnomap);

_PyExc_FiniTypes(interp);
}

/* Helper to do the equivalent of "raise X from Y" in C, but always using
Expand Down
0