summaryrefslogtreecommitdiffstats
path: root/Modules/getpath.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 23:34:22 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 23:34:22 (GMT)
commitdc4b2a712f96aa6a27d65af27ca877b084a584ca (patch)
tree74a061ba0f035d3c9c6c401d2498090b599df985 /Modules/getpath.c
parent168e117e0a8825bc3ae0c08f0b08a33ac351a14f (diff)
downloadcpython-dc4b2a712f96aa6a27d65af27ca877b084a584ca.zip
cpython-dc4b2a712f96aa6a27d65af27ca877b084a584ca.tar.gz
cpython-dc4b2a712f96aa6a27d65af27ca877b084a584ca.tar.bz2
calculate_path(): use _Py_char2wchar() to decode the PATH environment variable,
to support surrogate characters
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r--Modules/getpath.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 2275c84..776c464 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -407,7 +407,6 @@ calculate_path(void)
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 @@ calculate_path(void)
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 @@ calculate_path(void)
}
else
progpath[0] = '\0';
+ if (path != NULL)
+ PyMem_Free(path);
if (progpath[0] != SEP && progpath[0] != '\0')
absolutize(progpath);
wcsncpy(argv0_path, progpath, MAXPATHLEN);