diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-09-25 00:54:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-25 00:54:25 (GMT) |
commit | 221fd84703c545408bbb4a6e0b58459651331f5c (patch) | |
tree | b7fbeb8590e192b205f85267871828279c152d6c /PC | |
parent | 52ad33abbfb6637d74932617c7013bae0ccf6e32 (diff) | |
download | cpython-221fd84703c545408bbb4a6e0b58459651331f5c.zip cpython-221fd84703c545408bbb4a6e0b58459651331f5c.tar.gz cpython-221fd84703c545408bbb4a6e0b58459651331f5c.tar.bz2 |
bpo-38234: Cleanup getpath.c (GH-16367)
* search_for_prefix() directly calls reduce() if found is greater
than 0.
* Add calculate_pybuilddir() subfunction.
* search_for_prefix(): add path string buffer for readability.
* Fix some error handling code paths: release resources on error.
* calculate_read_pyenv(): rename tmpbuffer to filename.
* test.pythoninfo now also logs windows.dll_path
Diffstat (limited to 'PC')
-rw-r--r-- | PC/getpathp.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c index c4c0636..0eb75b8 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -757,34 +757,34 @@ static void calculate_pyvenv_file(PyCalculatePath *calculate, wchar_t *argv0_path, size_t argv0_path_len) { - wchar_t envbuffer[MAXPATHLEN+1]; + wchar_t filename[MAXPATHLEN+1]; const wchar_t *env_cfg = L"pyvenv.cfg"; - wcscpy_s(envbuffer, MAXPATHLEN+1, argv0_path); - join(envbuffer, env_cfg); + /* Filename: <argv0_path_len> / "pyvenv.cfg" */ + wcscpy_s(filename, MAXPATHLEN+1, argv0_path); + join(filename, env_cfg); - FILE *env_file = _Py_wfopen(envbuffer, L"r"); + FILE *env_file = _Py_wfopen(filename, L"r"); if (env_file == NULL) { errno = 0; - reduce(envbuffer); - reduce(envbuffer); - join(envbuffer, env_cfg); + /* Filename: <basename(basename(argv0_path_len))> / "pyvenv.cfg" */ + reduce(filename); + reduce(filename); + join(filename, env_cfg); - env_file = _Py_wfopen(envbuffer, L"r"); + env_file = _Py_wfopen(filename, L"r"); if (env_file == NULL) { errno = 0; + return; } } - if (env_file == NULL) { - return; - } - /* Look for a 'home' variable and set argv0_path to it, if found */ - wchar_t tmpbuffer[MAXPATHLEN+1]; - if (_Py_FindEnvConfigValue(env_file, L"home", tmpbuffer, MAXPATHLEN)) { - wcscpy_s(argv0_path, argv0_path_len, tmpbuffer); + wchar_t home[MAXPATHLEN+1]; + if (_Py_FindEnvConfigValue(env_file, L"home", + home, Py_ARRAY_LENGTH(home))) { + wcscpy_s(argv0_path, argv0_path_len, home); } fclose(env_file); } |