[Python-checkins] python/dist/src/Python import.c,2.206,2.207

doerwalter@users.sourceforge.net doerwalter@users.sourceforge.net
2002年6月17日 03:44:07 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv5793/Python
Modified Files:
	import.c 
Log Message:
Apply diff2.txt from SF patch http://www.python.org/sf/566999
This patch enhances Python/import.c/find_module() so
that unicode objects found in sys.path will be treated
as legal directory names (The current code ignores
anything that is not a str). The unicode name is
converted to str using Py_FileSystemDefaultEncoding.
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.206
retrieving revision 2.207
diff -C2 -d -r2.206 -r2.207
*** import.c	14 Jun 2002 01:07:39 -0000	2.206
--- import.c	17 Jun 2002 10:43:59 -0000	2.207
***************
*** 970,982 ****
 	namelen = strlen(name);
 	for (i = 0; i < npath; i++) {
 		PyObject *v = PyList_GetItem(path, i);
 		if (!PyString_Check(v))
 			continue;
 		len = PyString_Size(v);
! 		if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen)
 			continue; /* Too long */
 		strcpy(buf, PyString_AsString(v));
! 		if (strlen(buf) != len)
 			continue; /* v contains '0円' */
 #ifdef macintosh
 		/*
--- 970,997 ----
 	namelen = strlen(name);
 	for (i = 0; i < npath; i++) {
+ 		PyObject *copy = NULL;
 		PyObject *v = PyList_GetItem(path, i);
+ #ifdef Py_USING_UNICODE
+ 		if (PyUnicode_Check(v)) {
+ 			copy = PyUnicode_Encode(PyUnicode_AS_UNICODE(v),
+ 				PyUnicode_GET_SIZE(v), Py_FileSystemDefaultEncoding, NULL);
+ 			if (copy == NULL)
+ 				return NULL;
+ 			v = copy;
+ 		}
+ 		else
+ #endif
 		if (!PyString_Check(v))
 			continue;
 		len = PyString_Size(v);
! 		if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
! 			Py_XDECREF(copy);
 			continue; /* Too long */
+ 		}
 		strcpy(buf, PyString_AsString(v));
! 		if (strlen(buf) != len) {
! 			Py_XDECREF(copy);
 			continue; /* v contains '0円' */
+ 		}
 #ifdef macintosh
 		/*
***************
*** 992,995 ****
--- 1007,1011 ----
 				{"", "", PY_RESOURCE};
 
+ 			Py_XDECREF(copy);
 			return &resfiledescr;
 		}
***************
*** 998,1001 ****
--- 1014,1018 ----
 				{"", "", PY_CODERESOURCE};
 
+ 			Py_XDECREF(copy);
 			return &resfiledescr;
 		}
***************
*** 1013,1021 ****
 		 and there's an __init__ module in that directory */
 #ifdef HAVE_STAT
! 		if (stat(buf, &statbuf) == 0 && /* it exists */
! 		 S_ISDIR(statbuf.st_mode) && /* it's a directory */
! 		 find_init_module(buf) && /* it has __init__.py */
! 		 case_ok(buf, len, namelen, name)) /* and case matches */
 			return &fd_package;
 #else
 		/* XXX How are you going to test for directories? */
--- 1030,1040 ----
 		 and there's an __init__ module in that directory */
 #ifdef HAVE_STAT
! 		if (stat(buf, &statbuf) == 0 && /* it exists */
! 		 S_ISDIR(statbuf.st_mode) && /* it's a directory */
! 		 find_init_module(buf) && /* it has __init__.py */
! 		 case_ok(buf, len, namelen, name)) { /* and case matches */
! 			Py_XDECREF(copy);
 			return &fd_package;
+ 		}
 #else
 		/* XXX How are you going to test for directories? */
***************
*** 1023,1028 ****
 		if (isdir(buf) &&
 		 find_init_module(buf) &&
! 		 case_ok(buf, len, namelen, name))
 			return &fd_package;
 #endif
 #endif
--- 1042,1049 ----
 		if (isdir(buf) &&
 		 find_init_module(buf) &&
! 		 case_ok(buf, len, namelen, name)) {
! 			Py_XDECREF(copy);
 			return &fd_package;
+ 		}
 #endif
 #endif
***************
*** 1096,1099 ****
--- 1117,1121 ----
 		}
 #endif
+ 		Py_XDECREF(copy);
 		if (fp != NULL)
 			break;

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