bpo-46417: Py_Finalize() clears static types (GH-30743)

Add _PyTypes_FiniTypes() best-effort function to clear static types:
don't deallocate a type if it still has subclasses.

remove_subclass() now sets tp_subclasses to NULL when removing the
last subclass.
This commit is contained in:
Victor Stinner 2022-01-21 13:06:34 +01:00 committed by GitHub
parent ea38e436fe
commit 595225e86d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 144 additions and 85 deletions

View file

@ -1676,6 +1676,7 @@ finalize_interp_types(PyInterpreterState *interp)
_PyThread_FiniType(interp);
_PyErr_FiniTypes(interp);
_PyTypes_Fini(interp);
_PyTypes_FiniTypes(interp);
// Call _PyUnicode_ClearInterned() before _PyDict_Fini() since it uses
// a dict internally.