diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
commit | ea7bc055b08fb442986e0735b1b5b325b0b51ecc (patch) | |
tree | 20c2b837c787daf7e95ece075e6544627b17625a /Modules/getpath.c | |
parent | c32365d2ce552d1d17279e30a564509235ffb1db (diff) | |
parent | c2c9c905706160bf34aea12f2348210aac3e0da2 (diff) | |
download | cpython-ea7bc055b08fb442986e0735b1b5b325b0b51ecc.tar.gz |
Merge #14399: corrected news item
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r-- | Modules/getpath.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c index b7f9573f69..709087994d 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -406,7 +406,7 @@ calculate_path(void) static wchar_t delimiter[2] = {DELIM, '\0'}; static wchar_t separator[2] = {SEP, '\0'}; char *_rtpypath = Py_GETENV("PYTHONPATH"); /* XXX use wide version on Windows */ - wchar_t rtpypath[MAXPATHLEN+1]; + wchar_t *rtpypath = NULL; wchar_t *home = Py_GetPythonHome(); char *_path = getenv("PATH"); wchar_t *path_buffer = NULL; @@ -606,12 +606,12 @@ calculate_path(void) bufsz = 0; if (_rtpypath) { - 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 */ + size_t rtpypath_len; + rtpypath = _Py_char2wchar(_rtpypath, &rtpypath_len); + if (rtpypath != NULL) + bufsz += rtpypath_len + 1; + else _rtpypath = NULL; - if (_rtpypath) - bufsz += wcslen(rtpypath) + 1; } defpath = _pythonpath; @@ -645,7 +645,7 @@ calculate_path(void) } else { /* Run-time value of $PYTHONPATH goes first */ - if (_rtpypath) { + if (rtpypath) { wcscpy(buf, rtpypath); wcscat(buf, delimiter); } @@ -719,6 +719,8 @@ calculate_path(void) PyMem_Free(_pythonpath); PyMem_Free(_prefix); PyMem_Free(_exec_prefix); + if (rtpypath != NULL) + PyMem_Free(rtpypath); } |