diff options
author | Guido van Rossum <guido@python.org> | 1995-01-26 00:41:28 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-26 00:41:28 (GMT) |
commit | 0de81bfec9cda58648f0f085144a8e60b5f12b65 (patch) | |
tree | 1f203db9fa940868bd8ab38423ebde80cb729481 /Python | |
parent | 8bf7c484c16edfc5084732fdd6d8b64a0f921930 (diff) | |
download | cpython-0de81bfec9cda58648f0f085144a8e60b5f12b65.zip cpython-0de81bfec9cda58648f0f085144a8e60b5f12b65.tar.gz cpython-0de81bfec9cda58648f0f085144a8e60b5f12b65.tar.bz2 |
don't dictclear deleted modules in doneimport
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/Python/import.c b/Python/import.c index 9219c36..58a09fd 100644 --- a/Python/import.c +++ b/Python/import.c @@ -68,24 +68,17 @@ void doneimport() { if (import_modules != NULL) { - int pos; - object *modname, *module; - /* Explicitly erase all modules; this is the safest way - to get rid of at least *some* circular dependencies */ - pos = 0; - while (mappinggetnext(import_modules, - &pos, &modname, &module)) { - if (is_moduleobject(module)) { - object *dict; - dict = getmoduledict(module); - if (dict != NULL && is_dictobject(dict)) - mappingclear(dict); - } - } - mappingclear(import_modules); - DECREF(import_modules); + object *tmp = import_modules; + import_modules = NULL; + /* This deletes all modules from sys.modules. + When a module is deallocated, it in turn clears its dictionary, + thus hopefully breaking any circular references between modules + and between a module's dictionary and its functions. + Note that "import" will fail while we are cleaning up. + */ + mappingclear(tmp); + DECREF(tmp); } - import_modules = NULL; } @@ -119,6 +112,10 @@ add_module(name) { object *m; + if (import_modules == NULL) { + err_setstr(SystemError, "sys.modules has been deleted"); + return NULL; + } if ((m = dictlookup(import_modules, name)) != NULL && is_moduleobject(m)) return m; @@ -574,6 +571,10 @@ import_module(name) { object *m; + if (import_modules == NULL) { + err_setstr(SystemError, "sys.modules has been deleted"); + return NULL; + } if ((m = dictlookup(import_modules, name)) != NULL) { INCREF(m); } @@ -615,6 +616,10 @@ reload_module(m) name = getmodulename(m); if (name == NULL) return NULL; + if (import_modules == NULL) { + err_setstr(SystemError, "sys.modules has been deleted"); + return NULL; + } if (m != dictlookup(import_modules, name)) { err_setstr(ImportError, "reload() module not in sys.modules"); return NULL; |