diff options
author | Guido van Rossum <guido@python.org> | 1997-07-10 18:00:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-07-10 18:00:45 (GMT) |
commit | b65e85cb738e4bc555dd65111b57c56f27259677 (patch) | |
tree | 6998d7bea6c42585c3e79669d251206fa462a5b8 /Python | |
parent | e6648967b703c5f8ee24c23d25be2d5ce5f963d5 (diff) | |
download | cpython-b65e85cb738e4bc555dd65111b57c56f27259677.zip cpython-b65e85cb738e4bc555dd65111b57c56f27259677.tar.gz cpython-b65e85cb738e4bc555dd65111b57c56f27259677.tar.bz2 |
Fix problem discovered by Greg McFarlane: when an imported module
replaces its own entry in sys.module, reference count errors ensue;
even if there is no reference count problem, it would be preferable
for the import to yield the new thing in sys.modules anyway (if only
because that's what later imports will yield). This opens the road to
an official hack to implement a __getattr__ like feature for modules:
stick an instance in sys.modules[__name__].
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c index e44dc8c..2a4b5cc 100644 --- a/Python/import.c +++ b/Python/import.c @@ -182,6 +182,13 @@ PyImport_ExecCodeModule(name, co) if (v == NULL) return NULL; Py_DECREF(v); + + if ((m = PyDict_GetItemString(_PyImport_Modules, name)) == NULL) { + PyErr_SetString(PyExc_SystemError, + "loaded module not found in sys.modules"); + return NULL; + } + Py_INCREF(m); return m; |