mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
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
This commit is contained in:
parent
52ad33abbf
commit
221fd84703
3 changed files with 138 additions and 88 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue