[Python-checkins] CVS: python/dist/src/Python import.c,2.187,2.188
Guido van Rossum
gvanrossum@users.sourceforge.net
Thu, 18 Oct 2001 11:54:13 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv11485
Modified Files:
import.c
Log Message:
First part of SF patch #416704: More robust freeze, by Toby Dickenson.
This fixes the behavior reported by SF bug #404545, where a file
x.y.py could be imported by the statement "import x.y" when there's a
frozen package x (I believe even if x.y also exists as a frozen
module).
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.187
retrieving revision 2.188
diff -C2 -d -r2.187 -r2.188
*** import.c 2001/10/04 14:52:06 2.187
--- import.c 2001/10/18 18:54:11 2.188
***************
*** 878,882 ****
if (strlen(realname) > MAXPATHLEN) {
! PyErr_SetString(PyExc_OverflowError, "module name is too long");
return NULL;
}
--- 878,883 ----
if (strlen(realname) > MAXPATHLEN) {
! PyErr_SetString(PyExc_OverflowError,
! "module name is too long");
return NULL;
}
***************
*** 884,890 ****
if (path != NULL && PyString_Check(path)) {
! /* Submodule of "frozen" package:
! Set name to the fullname, path to NULL
! and continue as "usual" */
if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) {
PyErr_SetString(PyExc_ImportError,
--- 885,890 ----
if (path != NULL && PyString_Check(path)) {
! /* The only type of submodule allowed inside a "frozen"
! package are other frozen modules or packages. */
if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) {
PyErr_SetString(PyExc_ImportError,
***************
*** 896,900 ****
strcat(buf, name);
strcpy(name, buf);
! path = NULL;
}
if (path == NULL) {
--- 896,906 ----
strcat(buf, name);
strcpy(name, buf);
! if (find_frozen(name) != NULL) {
! strcpy(buf, name);
! return &fd_frozen;
! }
! PyErr_Format(PyExc_ImportError,
! "No frozen submodule named %.200s", name);
! return NULL;
}
if (path == NULL) {
***************
*** 1442,1445 ****
--- 1448,1457 ----
return NULL;
}
+ if (p->code == NULL) {
+ PyErr_Format(PyExc_ImportError,
+ "Excluded frozen object named %.200s",
+ name);
+ return NULL;
+ }
size = p->size;
if (size < 0)
***************
*** 1464,1467 ****
--- 1476,1485 ----
if (p == NULL)
return 0;
+ if (p->code == NULL) {
+ PyErr_Format(PyExc_ImportError,
+ "Excluded frozen object named %.200s",
+ name);
+ return -1;
+ }
size = p->size;
ispackage = (size < 0);