comparison Python/import.c @ 5758:bfe9ba74c19e legacy-trunk

Fix problem discovered by Greg McFarlane: when an imported module replaces its own entry in sys.module, reference count errors ensue; even if there is no reference count problem, it would be preferable for the import to yield the new thing in sys.modules anyway (if only because that's what later imports will yield). This opens the road to an official hack to implement a __getattr__ like feature for modules: stick an instance in sys.modules[__name__].
author Guido van Rossum <guido@python.org>
date Thu, 10 Jul 1997 18:00:45 +0000
parents fb39d288664b
children e2df95b7be78
comparison
equal deleted inserted replaced
5757:8c0f747f1141 5758:bfe9ba74c19e
180 PyErr_Clear(); /* Not important enough to report */ 180 PyErr_Clear(); /* Not important enough to report */
181 v = PyEval_EvalCode((PyCodeObject *)co, d, d); /* XXX owner? */ 181 v = PyEval_EvalCode((PyCodeObject *)co, d, d); /* XXX owner? */
182 if (v == NULL) 182 if (v == NULL)
183 return NULL; 183 return NULL;
184 Py_DECREF(v); 184 Py_DECREF(v);
185
186 if ((m = PyDict_GetItemString(_PyImport_Modules, name)) == NULL) {
187 PyErr_SetString(PyExc_SystemError,
188 "loaded module not found in sys.modules");
189 return NULL;
190 }
191
185 Py_INCREF(m); 192 Py_INCREF(m);
186 193
187 return m; 194 return m;
188 } 195 }
189 196