[Python-checkins] r82827 - python/branches/import_unicode/Modules/getpath.c

victor.stinner python-checkins at python.org
Sun Jul 11 22:20:43 CEST 2010


Author: victor.stinner
Date: Sun Jul 11 22:20:43 2010
New Revision: 82827

Log:
getpath.c: reindent and add FIXME

Modified:
   python/branches/import_unicode/Modules/getpath.c

Modified: python/branches/import_unicode/Modules/getpath.c
==============================================================================
--- python/branches/import_unicode/Modules/getpath.c	(original)
+++ python/branches/import_unicode/Modules/getpath.c	Sun Jul 11 22:20:43 2010
@@ -466,25 +466,26 @@
 #else
     unsigned long nsexeclength = MAXPATHLEN;
 #endif
-        char execpath[MAXPATHLEN+1];
+    char execpath[MAXPATHLEN+1];
 #endif
 
     if (_path) {
-            size_t r = mbstowcs(wpath, _path, MAXPATHLEN+1);
-            path = wpath;
-            if (r == (size_t)-1 || r > MAXPATHLEN) {
-                    /* Could not convert PATH, or it's too long. */
-                    path = NULL;
-            }
+        /* FIXME: use _Py_char2wchar() */
+        size_t r = mbstowcs(wpath, _path, MAXPATHLEN+1);
+        path = wpath;
+        if (r == (size_t)-1 || r > MAXPATHLEN) {
+                /* Could not convert PATH, or it's too long. */
+                path = NULL;
+        }
     }
 
-        /* If there is no slash in the argv0 path, then we have to
-         * assume python is on the user's $PATH, since there's no
-         * other way to find a directory to start the search from.  If
-         * $PATH isn't exported, you lose.
-         */
-        if (wcschr(prog, SEP))
-                wcsncpy(progpath, prog, MAXPATHLEN);
+    /* If there is no slash in the argv0 path, then we have to
+     * assume python is on the user's $PATH, since there's no
+     * other way to find a directory to start the search from.  If
+     * $PATH isn't exported, you lose.
+     */
+    if (wcschr(prog, SEP))
+        wcsncpy(progpath, prog, MAXPATHLEN);
 #ifdef __APPLE__
      /* On Mac OS X, if a script uses an interpreter of the form
       * "#!/opt/python2.3/bin/python", the kernel only passes "python"
@@ -496,52 +497,53 @@
       * will fail if a relative path was used. but in that case,
       * absolutize() should help us out below
       */
-        else if(0 == _NSGetExecutablePath(execpath, &nsexeclength) && execpath[0] == SEP) {
-                size_t r = mbstowcs(progpath, execpath, MAXPATHLEN+1);
-                if (r == (size_t)-1 || r > MAXPATHLEN) {
-                        /* Could not convert execpath, or it's too long. */
-                        progpath[0] = '\0';
-                }
+    else if(0 == _NSGetExecutablePath(execpath, &nsexeclength) && execpath[0] == SEP) {
+        /* FIXME: use _Py_char2wchar() */
+        size_t r = mbstowcs(progpath, execpath, MAXPATHLEN+1);
+        if (r == (size_t)-1 || r > MAXPATHLEN) {
+            /* Could not convert execpath, or it's too long. */
+            progpath[0] = '\0';
         }
+    }
 #endif /* __APPLE__ */
-        else if (path) {
-                while (1) {
-                        wchar_t *delim = wcschr(path, DELIM);
-
-                        if (delim) {
-                                size_t len = delim - path;
-                                if (len > MAXPATHLEN)
-                                        len = MAXPATHLEN;
-                                wcsncpy(progpath, path, len);
-                                *(progpath + len) = '\0';
-                        }
-                        else
-                                wcsncpy(progpath, path, MAXPATHLEN);
-
-                        joinpath(progpath, prog);
-                        if (isxfile(progpath))
-                                break;
-
-                        if (!delim) {
-                                progpath[0] = L'\0';
-                                break;
-                        }
-                        path = delim + 1;
-                }
+    else if (path) {
+        while (1) {
+            wchar_t *delim = wcschr(path, DELIM);
+
+            if (delim) {
+                size_t len = delim - path;
+                if (len > MAXPATHLEN)
+                    len = MAXPATHLEN;
+                wcsncpy(progpath, path, len);
+                *(progpath + len) = '\0';
+            }
+            else
+                wcsncpy(progpath, path, MAXPATHLEN);
+
+            joinpath(progpath, prog);
+            if (isxfile(progpath))
+                break;
+
+            if (!delim) {
+                progpath[0] = L'\0';
+                break;
+            }
+            path = delim + 1;
         }
-        else
-                progpath[0] = '\0';
-        if (progpath[0] != SEP && progpath[0] != '\0')
-                absolutize(progpath);
-        wcsncpy(argv0_path, progpath, MAXPATHLEN);
-        argv0_path[MAXPATHLEN] = '\0';
+    }
+    else
+        progpath[0] = '\0';
+    if (progpath[0] != SEP && progpath[0] != '\0')
+        absolutize(progpath);
+    wcsncpy(argv0_path, progpath, MAXPATHLEN);
+    argv0_path[MAXPATHLEN] = '\0';
 
 #ifdef WITH_NEXT_FRAMEWORK
-        /* On Mac OS X we have a special case if we're running from a framework.
-        ** This is because the python home should be set relative to the library,
-        ** which is in the framework, not relative to the executable, which may
-        ** be outside of the framework. Except when we're in the build directory...
-        */
+    /* On Mac OS X we have a special case if we're running from a framework.
+     ** This is because the python home should be set relative to the library,
+     ** which is in the framework, not relative to the executable, which may
+     ** be outside of the framework. Except when we're in the build directory...
+     */
     pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
     /* Use dylib functions to find out where the framework was loaded from */
     buf = (wchar_t *)NSLibraryNameForModule(pythonModule);
@@ -636,6 +638,7 @@
     bufsz = 0;
 
     if (_rtpypath) {
+        /* FIXME: use _Py_char2wchar() */
         size_t s = mbstowcs(rtpypath, _rtpypath, sizeof(rtpypath)/sizeof(wchar_t));
         if (s == (size_t)-1 || s >=sizeof(rtpypath))
             /* XXX deal with errors more gracefully */


More information about the Python-checkins mailing list