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

victor.stinner python-checkins at python.org
Wed Jul 14 01:47:52 CEST 2010


Author: victor.stinner
Date: Wed Jul 14 01:47:52 2010
New Revision: 82864

Log:
calculate_path() uses _Py_char2wchar()

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	Wed Jul 14 01:47:52 2010
@@ -447,8 +447,7 @@
     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 *path = NULL, *free_path = NULL;
     wchar_t *prog = Py_GetProgramName();
     wchar_t argv0_path[MAXPATHLEN+1];
     wchar_t zip_path[MAXPATHLEN+1];
@@ -470,13 +469,8 @@
 #endif
 
     if (_path) {
-        /* 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;
-        }
+        path = _Py_char2wchar(_path);
+        free_path = path;
     }
 
     /* If there is no slash in the argv0 path, then we have to
@@ -537,6 +531,8 @@
         absolutize(progpath);
     wcsncpy(argv0_path, progpath, MAXPATHLEN);
     argv0_path[MAXPATHLEN] = '\0';
+    if (free_path != NULL)
+        PyMem_Free(free_path);
 
 #ifdef WITH_NEXT_FRAMEWORK
     /* On Mac OS X we have a special case if we're running from a framework.


More information about the Python-checkins mailing list