Kaydet (Commit) 85cd1d69 authored tarafından Guido van Rossum's avatar Guido van Rossum

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.
üst 8b41116c
...@@ -1154,7 +1154,8 @@ check_case(char *buf, int len, int namelen, char *name) ...@@ -1154,7 +1154,8 @@ check_case(char *buf, int len, int namelen, char *name)
name, buf); name, buf);
return 0; return 0;
} }
if ( namelen > fss.name[0] || strncmp(name, (char *)fss.name+1, namelen) != 0 ) { if (namelen > fss.name[0] ||
strncmp(name, (char *)fss.name+1, namelen) != 0) {
PyErr_Format(PyExc_NameError, PyErr_Format(PyExc_NameError,
"Case mismatch for module name %.100s\n(filename %.300s)", "Case mismatch for module name %.100s\n(filename %.300s)",
name, fss.name); name, fss.name);
...@@ -1873,7 +1874,6 @@ PyImport_Import(PyObject *module_name) ...@@ -1873,7 +1874,6 @@ PyImport_Import(PyObject *module_name)
static PyObject *silly_list = NULL; static PyObject *silly_list = NULL;
static PyObject *builtins_str = NULL; static PyObject *builtins_str = NULL;
static PyObject *import_str = NULL; static PyObject *import_str = NULL;
static PyObject *standard_builtins = NULL;
PyObject *globals = NULL; PyObject *globals = NULL;
PyObject *import = NULL; PyObject *import = NULL;
PyObject *builtins = NULL; PyObject *builtins = NULL;
...@@ -1894,7 +1894,7 @@ PyImport_Import(PyObject *module_name) ...@@ -1894,7 +1894,7 @@ PyImport_Import(PyObject *module_name)
/* Get the builtins from current globals */ /* Get the builtins from current globals */
globals = PyEval_GetGlobals(); globals = PyEval_GetGlobals();
if(globals != NULL) { if (globals != NULL) {
Py_INCREF(globals); Py_INCREF(globals);
builtins = PyObject_GetItem(globals, builtins_str); builtins = PyObject_GetItem(globals, builtins_str);
if (builtins == NULL) if (builtins == NULL)
...@@ -1904,16 +1904,10 @@ PyImport_Import(PyObject *module_name) ...@@ -1904,16 +1904,10 @@ PyImport_Import(PyObject *module_name)
/* No globals -- use standard builtins, and fake globals */ /* No globals -- use standard builtins, and fake globals */
PyErr_Clear(); PyErr_Clear();
if (standard_builtins == NULL) { builtins = PyImport_ImportModuleEx("__builtin__",
standard_builtins = NULL, NULL, NULL);
PyImport_ImportModuleEx("__builtin__", if (builtins == NULL)
NULL, NULL, NULL); return NULL;
if (standard_builtins == NULL)
return NULL;
}
builtins = standard_builtins;
Py_INCREF(builtins);
globals = Py_BuildValue("{OO}", builtins_str, builtins); globals = Py_BuildValue("{OO}", builtins_str, builtins);
if (globals == NULL) if (globals == NULL)
goto err; goto err;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment