mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
calculate_path(): use _Py_char2wchar() to decode the PATH environment variable,
to support surrogate characters
This commit is contained in:
parent
168e117e0a
commit
dc4b2a712f
1 changed files with 4 additions and 9 deletions
|
@ -407,7 +407,6 @@ calculate_path(void)
|
||||||
wchar_t rtpypath[MAXPATHLEN+1];
|
wchar_t rtpypath[MAXPATHLEN+1];
|
||||||
wchar_t *home = Py_GetPythonHome();
|
wchar_t *home = Py_GetPythonHome();
|
||||||
char *_path = getenv("PATH");
|
char *_path = getenv("PATH");
|
||||||
wchar_t wpath[MAXPATHLEN+1];
|
|
||||||
wchar_t *path = NULL;
|
wchar_t *path = NULL;
|
||||||
wchar_t *prog = Py_GetProgramName();
|
wchar_t *prog = Py_GetProgramName();
|
||||||
wchar_t argv0_path[MAXPATHLEN+1];
|
wchar_t argv0_path[MAXPATHLEN+1];
|
||||||
|
@ -429,14 +428,8 @@ calculate_path(void)
|
||||||
char execpath[MAXPATHLEN+1];
|
char execpath[MAXPATHLEN+1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_path) {
|
if (_path)
|
||||||
size_t r = mbstowcs(wpath, _path, MAXPATHLEN+1);
|
path = _Py_char2wchar(_path, NULL);
|
||||||
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
|
/* 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
|
* assume python is on the user's $PATH, since there's no
|
||||||
|
@ -491,6 +484,8 @@ calculate_path(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
progpath[0] = '\0';
|
progpath[0] = '\0';
|
||||||
|
if (path != NULL)
|
||||||
|
PyMem_Free(path);
|
||||||
if (progpath[0] != SEP && progpath[0] != '\0')
|
if (progpath[0] != SEP && progpath[0] != '\0')
|
||||||
absolutize(progpath);
|
absolutize(progpath);
|
||||||
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue