[Python-checkins] CVS: python/dist/src/Python import.c,2.178,2.179
Guido van Rossum
gvanrossum@users.sourceforge.net
Mon, 23 Jul 2001 06:27:51 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv16226
Modified Files:
import.c
Log Message:
SF Patch #441791, with changes: when "import foo.bar" fails with an
exception in the execution of bar, ensure that foo.bar exists.
(Previously, while sys.modules['foo.bar'] would exist, foo.bar would
only be created upon successful execution of bar. This is
inconvenient; some would say wrong. :-)
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.178
retrieving revision 2.179
diff -C2 -r2.178 -r2.179
*** import.c 2001/07/05 03:47:53 2.178
--- import.c 2001/07/23 13:27:49 2.179
***************
*** 1790,1794 ****
{
PyObject *modules = PyImport_GetModuleDict();
! PyObject *m;
/* Require:
--- 1790,1794 ----
{
PyObject *modules = PyImport_GetModuleDict();
! PyObject *m, *res = NULL;
/* Require:
***************
*** 1830,1836 ****
if (fp)
fclose(fp);
! if (m != NULL && mod != Py_None) {
! if (PyObject_SetAttrString(mod, subname, m) < 0) {
! Py_DECREF(m);
m = NULL;
}
--- 1830,1848 ----
if (fp)
fclose(fp);
! if (mod != Py_None) {
! /* Irrespective of the success of this load, make a
! reference to it in the parent package module.
! A copy gets saved in the modules dictionary
! under the full name, so get a reference from
! there, if need be. (The exception is when
! the load failed with a SyntaxError -- then
! there's no trace in sys.modules. In that case,
! of course, do nothing extra.) */
! res = m;
! if (res == NULL)
! res = PyDict_GetItemString(modules, fullname);
! if (res != NULL &&
! PyObject_SetAttrString(mod, subname, res) < 0) {
! Py_XDECREF(m);
m = NULL;
}