mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Provide a dummy empty directory as f_builtins instead of failing, when
no valid directory is passed in. This prevents __del__ to fail when invoked after __builtins__ has already been discarded. Also add PyFrame_Fini() to discard the cache of frames.
This commit is contained in:
parent
a0d349f46a
commit
404b95d9ba
1 changed files with 22 additions and 7 deletions
|
|
@ -167,11 +167,8 @@ PyFrame_New(tstate, code, globals, locals)
|
|||
builtins = PyDict_GetItem(globals, builtin_object);
|
||||
if (builtins != NULL && PyModule_Check(builtins))
|
||||
builtins = PyModule_GetDict(builtins);
|
||||
if (builtins == NULL || !PyDict_Check(builtins)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"bad __builtins__ dictionary");
|
||||
return NULL;
|
||||
}
|
||||
if (builtins != NULL && !PyDict_Check(builtins))
|
||||
builtins = NULL;
|
||||
if (free_list == NULL) {
|
||||
f = (PyFrameObject *)
|
||||
malloc(sizeof(PyFrameObject) +
|
||||
|
|
@ -195,12 +192,18 @@ PyFrame_New(tstate, code, globals, locals)
|
|||
f->ob_type = &PyFrame_Type;
|
||||
_Py_NewReference(f);
|
||||
}
|
||||
if (builtins == NULL) {
|
||||
builtins = PyDict_New();
|
||||
if (builtins == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
Py_XINCREF(builtins);
|
||||
f->f_builtins = builtins;
|
||||
Py_XINCREF(back);
|
||||
f->f_back = back;
|
||||
Py_INCREF(code);
|
||||
f->f_code = code;
|
||||
Py_XINCREF(builtins);
|
||||
f->f_builtins = builtins;
|
||||
Py_INCREF(globals);
|
||||
f->f_globals = globals;
|
||||
if (code->co_flags & CO_NEWLOCALS) {
|
||||
|
|
@ -352,3 +355,15 @@ PyFrame_LocalsToFast(f, clear)
|
|||
}
|
||||
PyErr_Restore(error_type, error_value, error_traceback);
|
||||
}
|
||||
|
||||
/* Clear out the free list */
|
||||
|
||||
void
|
||||
PyFrame_Fini()
|
||||
{
|
||||
while (free_list != NULL) {
|
||||
PyFrameObject *f = free_list;
|
||||
free_list = free_list->f_back;
|
||||
PyMem_DEL(f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue