[Python-checkins] cpython (2.7): Moved directory detection into an isdir function

jason.coombs python-checkins at python.org
Thu Mar 8 15:40:41 CET 2012


http://hg.python.org/cpython/rev/2218a6cf75fc
changeset: 75490:2218a6cf75fc
branch: 2.7
parent: 75488:ac776931ac81
user: Jason R. Coombs <jaraco at jaraco.com>
date: Fri Jan 13 17:12:25 2012 -0500
summary:
 Moved directory detection into an isdir function
files:
 Python/import.c | 42 ++++++++++++------------------------
 1 files changed, 14 insertions(+), 28 deletions(-)
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -114,6 +114,19 @@
 };
 #endif
 
+#ifdef HAVE_STAT
+int isdir(char *path) {
+ struct stat statbuf;
+	return stat(path, &statbuf) == 0 && S_ISDIR(statbuf.st_mode);
+}
+#else
+/* with RISCOS, isdir is in unixstuff */
+#ifndef RISCOS
+int isdir(char *path) {
+	return 0;
+}
+#endif
+#endif
 
 /* Initialize things */
 
@@ -1204,9 +1217,6 @@
 char *filemode;
 FILE *fp = NULL;
 PyObject *path_hooks, *path_importer_cache;
-#ifndef RISCOS
- struct stat statbuf;
-#endif
 static struct filedescr fd_frozen = {"", "", PY_FROZEN};
 static struct filedescr fd_builtin = {"", "", C_BUILTIN};
 static struct filedescr fd_package = {"", "", PKG_DIRECTORY};
@@ -1392,9 +1402,7 @@
 
 /* Check for package import (buf holds a directory name,
 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 */
+ if (isdir(buf) && /* it's an existing directory */
 case_ok(buf, len, namelen, name)) { /* case matches */
 if (find_init_module(buf)) { /* and has __init__.py */
 Py_XDECREF(copy);
@@ -1412,28 +1420,6 @@
 }
 }
 }
-#else
- /* XXX How are you going to test for directories? */
-#ifdef RISCOS
- if (isdir(buf) &&
- case_ok(buf, len, namelen, name)) {
- if (find_init_module(buf)) {
- Py_XDECREF(copy);
- return &fd_package;
- }
- else {
- char warnstr[MAXPATHLEN+80];
- sprintf(warnstr, "Not importing directory "
- "'%.*s': missing __init__.py",
- MAXPATHLEN, buf);
- if (PyErr_Warn(PyExc_ImportWarning,
- warnstr)) {
- Py_XDECREF(copy);
- return NULL;
- }
- }
-#endif
-#endif
 #if defined(PYOS_OS2)
 /* take a snapshot of the module spec for restoration
 * after the 8 character DLL hackery
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

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