File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -294,8 +294,6 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
294
294
Py_CLEAR (interp -> codec_error_registry );
295
295
Py_CLEAR (interp -> modules );
296
296
Py_CLEAR (interp -> modules_by_index );
297
- Py_CLEAR (interp -> sysdict );
298
- Py_CLEAR (interp -> builtins );
299
297
Py_CLEAR (interp -> builtins_copy );
300
298
Py_CLEAR (interp -> importlib );
301
299
Py_CLEAR (interp -> import_func );
@@ -308,6 +306,14 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
308
306
if (_PyRuntimeState_GetFinalizing (runtime ) == NULL ) {
309
307
_PyWarnings_Fini (interp );
310
308
}
309
+ /* We don't clear sysdict and builtins until the end of this function.
310
+ Because clearing other attributes can execute arbitrary Python code
311
+ which requires sysdict and builtins. */
312
+ PyDict_Clear (interp -> sysdict );
313
+ PyDict_Clear (interp -> builtins );
314
+ Py_CLEAR (interp -> sysdict );
315
+ Py_CLEAR (interp -> builtins );
316
+
311
317
// XXX Once we have one allocator per interpreter (i.e.
312
318
// per-interpreter GC) we must ensure that all of the interpreter's
313
319
// objects have been cleaned up at the point.
You can’t perform that action at this time.
0 commit comments