[Python-checkins] CVS: python/dist/src/Python importdl.c,2.68,2.68.6.1

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 15 Jan 2002 13:14:40 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv21375

Modified Files:
      Tag: release21-maint
	importdl.c 
Log Message:
Backport revision 2.69.

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.


Index: importdl.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/importdl.c,v
retrieving revision 2.68
retrieving revision 2.68.6.1
diff -C2 -d -r2.68 -r2.68.6.1
*** importdl.c	2000/09/01 23:29:28	2.68
--- importdl.c	2002/01/15 21:14:38	2.68.6.1
***************
*** 23,27 ****
  {
  	PyObject *m, *d, *s;
! 	char *lastdot, *shortname, *packagecontext;
  	dl_funcptr p;
  
--- 23,27 ----
  {
  	PyObject *m, *d, *s;
! 	char *lastdot, *shortname, *packagecontext, *oldcontext;
  	dl_funcptr p;
  
***************
*** 49,55 ****
  		return NULL;
  	}
  	_Py_PackageContext = packagecontext;
  	(*p)();
! 	_Py_PackageContext = NULL;
  	if (PyErr_Occurred())
  		return NULL;
--- 49,56 ----
  		return NULL;
  	}
+         oldcontext = _Py_PackageContext;
  	_Py_PackageContext = packagecontext;
  	(*p)();
! 	_Py_PackageContext = oldcontext;
  	if (PyErr_Occurred())
  		return NULL;