mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Empty all modules' symbol tables, so most circular references are
cleared up. (A function definition references its module's symbol table but the symbol table of course references the function...)
This commit is contained in:
parent
392ab32859
commit
5b3138bec0
1 changed files with 41 additions and 6 deletions
|
@ -131,6 +131,7 @@ initsys(argc, argv)
|
||||||
dictinsert(sysdict, "exit", exit);
|
dictinsert(sysdict, "exit", exit);
|
||||||
if (err_occurred())
|
if (err_occurred())
|
||||||
fatal("can't insert sys.* objects in sys dict");
|
fatal("can't insert sys.* objects in sys dict");
|
||||||
|
DECREF(exit);
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
/* The other symbols are added elsewhere */
|
/* The other symbols are added elsewhere */
|
||||||
|
|
||||||
|
@ -141,16 +142,50 @@ initsys(argc, argv)
|
||||||
fatal("can't create sys module");
|
fatal("can't create sys module");
|
||||||
if (setmoduledict(v, sysdict) != 0)
|
if (setmoduledict(v, sysdict) != 0)
|
||||||
fatal("can't assign sys dict to sys module");
|
fatal("can't assign sys dict to sys module");
|
||||||
|
DECREF(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cleardict(d)
|
||||||
|
object *d;
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = getdictsize(d); --i >= 0; ) {
|
||||||
|
char *k;
|
||||||
|
k = getdictkey(d, i);
|
||||||
|
if (k != NULL) {
|
||||||
|
(void) dictremove(d, k);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
closesys()
|
closesys()
|
||||||
{
|
{
|
||||||
object *mtab;
|
object *modules;
|
||||||
mtab = sysget("modules");
|
modules = sysget("modules");
|
||||||
if (mtab != NULL && is_dictobject(mtab))
|
if (modules != NULL && is_dictobject(modules)) {
|
||||||
dictremove(mtab, "sys"); /* Get rid of recursion */
|
int i;
|
||||||
else
|
/* Explicitly erase all modules; this is the safest way
|
||||||
fprintf(stderr, "[module sys not found]\n");
|
to get rid of at least *some* circular dependencies */
|
||||||
|
INCREF(modules);
|
||||||
|
for (i = getdictsize(modules); --i >= 0; ) {
|
||||||
|
char *k;
|
||||||
|
k = getdictkey(modules, i);
|
||||||
|
if (k != NULL) {
|
||||||
|
object *m;
|
||||||
|
m = dictlookup(modules, k);
|
||||||
|
if (m != NULL && is_moduleobject(m)) {
|
||||||
|
object *d;
|
||||||
|
d = getmoduledict(m);
|
||||||
|
if (d != NULL && is_dictobject(d)) {
|
||||||
|
cleardict(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cleardict(modules);
|
||||||
|
DECREF(modules);
|
||||||
|
}
|
||||||
DECREF(sysdict);
|
DECREF(sysdict);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue