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.
_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) {
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)