[Python-checkins] CVS: python/dist/src/Python import.c,2.175.2.1,2.175.2.2

Thomas Wouters twouters@users.sourceforge.net
2001年7月11日 05:03:46 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv4272/Python
Modified Files:
 Tag: release21-maint
	import.c 
Log Message:
Backport of Tim's checkin 2.178:
SF bug #438295: [Windows] __init__.py cause strange behavior
Probable fix (the bug report doesn't have enough info to say for sure). 
find_init_module(): Insist on a case-sensitive match for __init__ files. 
Given __INIT__.PY instead, find_init_module() thought that was fine, but
the later attempt to do find_module("__INIT__.PY") didn't and its caller
silently suppressed the resulting ImportError. Now find_init_module()
refuses to accept __INIT__.PY to begin with.
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.175.2.1
retrieving revision 2.175.2.2
diff -C2 -r2.175.2.1 -r2.175.2.2
*** import.c	2001年05月23日 12:51:22	2.175.2.1
--- import.c	2001年07月11日 12:03:44	2.175.2.2
***************
*** 1195,1218 ****
 find_init_module(char *buf)
 {
! 	size_t save_len = strlen(buf);
 	size_t i = save_len;
 	struct stat statbuf;
 
 	if (save_len + 13 >= MAXPATHLEN)
 		return 0;
 	buf[i++] = SEP;
! 	strcpy(buf+i, "__init__.py");
 	if (stat(buf, &statbuf) == 0) {
! 		buf[save_len] = '0円';
! 		return 1;
 	}
! 	i += strlen(buf+i);
! 	if (Py_OptimizeFlag)
! 		strcpy(buf+i, "o");
! 	else
! 		strcpy(buf+i, "c");
 	if (stat(buf, &statbuf) == 0) {
! 		buf[save_len] = '0円';
! 		return 1;
 	}
 	buf[save_len] = '0円';
--- 1195,1235 ----
 find_init_module(char *buf)
 {
! 	const size_t save_len = strlen(buf);
 	size_t i = save_len;
+ 	char *pname; /* pointer to start of __init__ */
 	struct stat statbuf;
 
+ /*	For calling case_ok(buf, len, namelen, name):
+ *	/a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py0円
+ *	^ ^ ^ ^
+ *	|--------------------- buf ---------------------|
+ *	|------------------- len ------------------|
+ *	 |------ name -------|
+ *	 |----- namelen -----|
+ */
 	if (save_len + 13 >= MAXPATHLEN)
 		return 0;
 	buf[i++] = SEP;
! 	pname = buf + i;
! 	strcpy(pname, "__init__.py");
 	if (stat(buf, &statbuf) == 0) {
! 		if (case_ok(buf,
! 			 save_len + 9,	/* len("/__init__") */
! 		 8, 		/* len("__init__") */
! 		 pname)) {
! 			buf[save_len] = '0円';
! 			return 1;
! 		}
 	}
! 	i += strlen(pname);
! 	strcpy(buf+i, Py_OptimizeFlag ? "o" : "c");
 	if (stat(buf, &statbuf) == 0) {
! 		if (case_ok(buf,
! 			 save_len + 9,	/* len("/__init__") */
! 		 8, 		/* len("__init__") */
! 		 pname)) {
! 			buf[save_len] = '0円';
! 			return 1;
! 		}
 	}
 	buf[save_len] = '0円';

AltStyle によって変換されたページ (->オリジナル) /