Commit 221fd847 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

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
parent 52ad33ab
......@@ -673,6 +673,13 @@ def collect_windows(info_add):
res = bool(RtlAreLongPathsEnabled())
info_add('windows.RtlAreLongPathsEnabled', res)
try:
import _winapi
dll_path = _winapi.GetModuleFileName(sys.dllhandle)
info_add('windows.dll_path', dll_path)
except (ImportError, AttributeError):
pass
def collect_info(info):
error = False
......
This diff is collapsed.
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment