diff options
author | Guido van Rossum <guido@python.org> | 2001-10-16 20:07:34 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-10-16 20:07:34 +0000 |
commit | ae9e7960d33d9d2c2f63f5611fc808db293c2ed5 (patch) | |
tree | 82de45b4caf4ae51603fefe7076bca9d91dadfe6 /Python/importdl.c | |
parent | b6aca6afe2c46b57810c0f3e726e6dae5336d324 (diff) | |
download | cpython-git-ae9e7960d33d9d2c2f63f5611fc808db293c2ed5.tar.gz |
SF patch #471839: Bug when extensions import extensions (Shane Hathaway)
When an extension imports another extension in its
initXXX() function, the variable _Py_PackageContext is
prematurely reset to NULL. If the outer extension then
calls Py_InitModule(), the extension is installed in
sys.modules without its package name. The
manifestation of this bug is a "SystemError:
_PyImport_FixupExtension: module <package>.<extension>
not loaded".
To fix this, importdl.c just needs to retain the old
value of _Py_PackageContext and restore it after the
initXXX() method is called. The attached patch does this.
This patch applies to Python 2.1.1 and the current CVS.
Diffstat (limited to 'Python/importdl.c')
-rw-r--r-- | Python/importdl.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Python/importdl.c b/Python/importdl.c index 4a1048d496..9255bbf584 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -22,7 +22,7 @@ PyObject * _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) { PyObject *m, *d, *s; - char *lastdot, *shortname, *packagecontext; + char *lastdot, *shortname, *packagecontext, *oldcontext; dl_funcptr p; if ((m = _PyImport_FindExtension(name, pathname)) != NULL) { @@ -48,9 +48,10 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) shortname); return NULL; } + oldcontext = _Py_PackageContext; _Py_PackageContext = packagecontext; (*p)(); - _Py_PackageContext = NULL; + _Py_PackageContext = oldcontext; if (PyErr_Occurred()) return NULL; if (_PyImport_FixupExtension(name, pathname) == NULL) |