[Python-checkins] CVS: python/dist/src/Python import.c,2.161,2.162
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 20 Feb 2001 13:43:26 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv4811
Modified Files:
import.c
Log Message:
The code in PyImport_Import() tried to save itself a bit of work and
save the __builtin__ module in a static variable. But this doesn't
work across Py_Finalise()/Py_Initialize()! It also doesn't work when
using multiple interpreter states created with PyInterpreterState_New().
So I'm ripping out this small optimization.
This was probably broken since PyImport_Import() was introduced in
1997! We really need a better test suite for multiple interpreter
states and repeatedly initializing.
This fixes the problems Barry reported in Demo/embed/loop.c.
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.161
retrieving revision 2.162
diff -C2 -r2.161 -r2.162
*** import.c 2001/02/09 19:40:15 2.161
--- import.c 2001/02/20 21:43:24 2.162
***************
*** 1155,1159 ****
return 0;
}
! if ( namelen > fss.name[0] || strncmp(name, (char *)fss.name+1, namelen) != 0 ) {
PyErr_Format(PyExc_NameError,
"Case mismatch for module name %.100s\n(filename %.300s)",
--- 1155,1160 ----
return 0;
}
! if (namelen > fss.name[0] ||
! strncmp(name, (char *)fss.name+1, namelen) != 0) {
PyErr_Format(PyExc_NameError,
"Case mismatch for module name %.100s\n(filename %.300s)",
***************
*** 1874,1878 ****
static PyObject *builtins_str = NULL;
static PyObject *import_str = NULL;
- static PyObject *standard_builtins = NULL;
PyObject *globals = NULL;
PyObject *import = NULL;
--- 1875,1878 ----
***************
*** 1895,1899 ****
/* Get the builtins from current globals */
globals = PyEval_GetGlobals();
! if(globals != NULL) {
Py_INCREF(globals);
builtins = PyObject_GetItem(globals, builtins_str);
--- 1895,1899 ----
/* Get the builtins from current globals */
globals = PyEval_GetGlobals();
! if (globals != NULL) {
Py_INCREF(globals);
builtins = PyObject_GetItem(globals, builtins_str);
***************
*** 1905,1918 ****
PyErr_Clear();
! if (standard_builtins == NULL) {
! standard_builtins =
! PyImport_ImportModuleEx("__builtin__",
! NULL, NULL, NULL);
! if (standard_builtins == NULL)
! return NULL;
! }
!
! builtins = standard_builtins;
! Py_INCREF(builtins);
globals = Py_BuildValue("{OO}", builtins_str, builtins);
if (globals == NULL)
--- 1905,1912 ----
PyErr_Clear();
! builtins = PyImport_ImportModuleEx("__builtin__",
! NULL, NULL, NULL);
! if (builtins == NULL)
! return NULL;
globals = Py_BuildValue("{OO}", builtins_str, builtins);
if (globals == NULL)