bpo-1635741: Clean sysdict and builtins of interpreter at exit (GH-21605)

This commit is contained in:
Hai Shi 2020-08-13 05:23:30 +08:00 committed by GitHub
parent 423e77d6de
commit 8ecc0c4d39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -294,8 +294,6 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
Py_CLEAR(interp->codec_error_registry); Py_CLEAR(interp->codec_error_registry);
Py_CLEAR(interp->modules); Py_CLEAR(interp->modules);
Py_CLEAR(interp->modules_by_index); Py_CLEAR(interp->modules_by_index);
Py_CLEAR(interp->sysdict);
Py_CLEAR(interp->builtins);
Py_CLEAR(interp->builtins_copy); Py_CLEAR(interp->builtins_copy);
Py_CLEAR(interp->importlib); Py_CLEAR(interp->importlib);
Py_CLEAR(interp->import_func); Py_CLEAR(interp->import_func);
@ -308,6 +306,14 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
if (_PyRuntimeState_GetFinalizing(runtime) == NULL) { if (_PyRuntimeState_GetFinalizing(runtime) == NULL) {
_PyWarnings_Fini(interp); _PyWarnings_Fini(interp);
} }
/* We don't clear sysdict and builtins until the end of this function.
Because clearing other attributes can execute arbitrary Python code
which requires sysdict and builtins. */
PyDict_Clear(interp->sysdict);
PyDict_Clear(interp->builtins);
Py_CLEAR(interp->sysdict);
Py_CLEAR(interp->builtins);
// XXX Once we have one allocator per interpreter (i.e. // XXX Once we have one allocator per interpreter (i.e.
// per-interpreter GC) we must ensure that all of the interpreter's // per-interpreter GC) we must ensure that all of the interpreter's
// objects have been cleaned up at the point. // objects have been cleaned up at the point.