mirror of
https://github.com/python/cpython.git
synced 2025-11-11 14:44:57 +00:00
bpo-46417: Py_Finalize() clears static exceptioins (GH-30805)
The Py_Finalize() function now clears exceptions implemented as static types. Add _PyExc_FiniTypes() function, called by _PyExc_Fini().
This commit is contained in:
parent
f1bcdeaca6
commit
621a45ccac
1 changed files with 26 additions and 1 deletions
|
|
@ -3536,13 +3536,36 @@ _PyExc_InitTypes(PyInterpreterState *interp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
_PyExc_FiniTypes(PyInterpreterState *interp)
|
||||||
|
{
|
||||||
|
if (!_Py_IsMainInterpreter(interp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_exceptions) - 1; i >= 0; 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
|
PyStatus
|
||||||
_PyExc_InitGlobalObjects(PyInterpreterState *interp)
|
_PyExc_InitGlobalObjects(PyInterpreterState *interp)
|
||||||
{
|
{
|
||||||
|
if (!_Py_IsMainInterpreter(interp)) {
|
||||||
|
return _PyStatus_OK();
|
||||||
|
}
|
||||||
|
|
||||||
if (preallocate_memerrors() < 0) {
|
if (preallocate_memerrors() < 0) {
|
||||||
return _PyStatus_NO_MEMORY();
|
return _PyStatus_NO_MEMORY();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _PyStatus_OK();
|
return _PyStatus_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3656,6 +3679,8 @@ _PyExc_Fini(PyInterpreterState *interp)
|
||||||
struct _Py_exc_state *state = &interp->exc_state;
|
struct _Py_exc_state *state = &interp->exc_state;
|
||||||
free_preallocated_memerrors(state);
|
free_preallocated_memerrors(state);
|
||||||
Py_CLEAR(state->errnomap);
|
Py_CLEAR(state->errnomap);
|
||||||
|
|
||||||
|
_PyExc_FiniTypes(interp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to do the equivalent of "raise X from Y" in C, but always using
|
/* Helper to do the equivalent of "raise X from Y" in C, but always using
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue