[Python-checkins] r85583 - python/branches/py3k/Modules/getpath.c

victor.stinner python-checkins at python.org
Sun Oct 17 01:34:23 CEST 2010


Author: victor.stinner
Date: Sun Oct 17 01:34:22 2010
New Revision: 85583

Log:
calculate_path(): use _Py_char2wchar() to decode the PATH environment variable,
to support surrogate characters


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

Modified: python/branches/py3k/Modules/getpath.c
==============================================================================
--- python/branches/py3k/Modules/getpath.c	(original)
+++ python/branches/py3k/Modules/getpath.c	Sun Oct 17 01:34:22 2010
@@ -407,7 +407,6 @@
     wchar_t rtpypath[MAXPATHLEN+1];
     wchar_t *home = Py_GetPythonHome();
     char *_path = getenv("PATH");
-    wchar_t wpath[MAXPATHLEN+1];
     wchar_t *path = NULL;
     wchar_t *prog = Py_GetProgramName();
     wchar_t argv0_path[MAXPATHLEN+1];
@@ -429,14 +428,8 @@
         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;
-        }
-    }
+    if (_path)
+        path = _Py_char2wchar(_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
@@ -491,6 +484,8 @@
     }
     else
         progpath[0] = '\0';
+    if (path != NULL)
+        PyMem_Free(path);
     if (progpath[0] != SEP && progpath[0] != '\0')
         absolutize(progpath);
     wcsncpy(argv0_path, progpath, MAXPATHLEN);


More information about the Python-checkins mailing list