diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-09-20 23:02:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-20 23:02:56 (GMT) |
commit | c422167749f92d4170203e996a2c619c818335ea (patch) | |
tree | 23cc4f024fefc0d5d708503fb5dbd6e07a509207 /PC | |
parent | b1542583bee204130934c2b90684041e29378250 (diff) | |
download | cpython-c422167749f92d4170203e996a2c619c818335ea.zip cpython-c422167749f92d4170203e996a2c619c818335ea.tar.gz cpython-c422167749f92d4170203e996a2c619c818335ea.tar.bz2 |
bpo-38234: Remove _PyPathConfig.dll_path (GH-16307)
The DLL path is not computed from any user configuration and cannot
be configured by PyConfig. Instead, add a new _Py_dll_path global variable.
Remove _PyConfig_SetPathConfig(): replaced with _PyPathConfig_Init().
Py_Initialize() now longer sets the "global path configuration",
but only initialize _Py_dll_path.
Diffstat (limited to 'PC')
-rw-r--r-- | PC/getpathp.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c index 7465d31..01455a6 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -128,6 +128,8 @@ typedef struct { wchar_t argv0_path[MAXPATHLEN+1]; wchar_t zip_path[MAXPATHLEN+1]; + + wchar_t *dll_path; } PyCalculatePath; @@ -666,28 +668,36 @@ error: } -static void +static PyStatus calculate_init(PyCalculatePath *calculate, const PyConfig *config) { calculate->home = config->home; calculate->path_env = _wgetenv(L"PATH"); + + calculate->dll_path = _Py_GetDLLPath(); + if (calculate->dll_path == NULL) { + return _PyStatus_NO_MEMORY(); + } + + return _PyStatus_OK(); } static int -get_pth_filename(wchar_t *spbuffer, _PyPathConfig *pathconfig) +get_pth_filename(PyCalculatePath *calculate, wchar_t *filename, + const _PyPathConfig *pathconfig) { - if (pathconfig->dll_path[0]) { - if (!change_ext(spbuffer, pathconfig->dll_path, L"._pth") && - exists(spbuffer)) + if (calculate->dll_path[0]) { + if (!change_ext(filename, calculate->dll_path, L"._pth") && + exists(filename)) { return 1; } } if (pathconfig->program_full_path[0]) { - if (!change_ext(spbuffer, pathconfig->program_full_path, L"._pth") && - exists(spbuffer)) + if (!change_ext(filename, pathconfig->program_full_path, L"._pth") && + exists(filename)) { return 1; } @@ -697,15 +707,16 @@ get_pth_filename(wchar_t *spbuffer, _PyPathConfig *pathconfig) static int -calculate_pth_file(_PyPathConfig *pathconfig, wchar_t *prefix) +calculate_pth_file(PyCalculatePath *calculate, _PyPathConfig *pathconfig, + wchar_t *prefix) { - wchar_t spbuffer[MAXPATHLEN+1]; + wchar_t filename[MAXPATHLEN+1]; - if (!get_pth_filename(spbuffer, pathconfig)) { + if (!get_pth_filename(calculate, filename, pathconfig)) { return 0; } - return read_pth_file(pathconfig, prefix, spbuffer); + return read_pth_file(pathconfig, prefix, filename); } @@ -966,13 +977,6 @@ calculate_path_impl(const PyConfig *config, { PyStatus status; - assert(pathconfig->dll_path == NULL); - - pathconfig->dll_path = _Py_GetDLLPath(); - if (pathconfig->dll_path == NULL) { - return _PyStatus_NO_MEMORY(); - } - status = get_program_full_path(config, calculate, pathconfig); if (_PyStatus_EXCEPTION(status)) { return status; @@ -986,7 +990,7 @@ calculate_path_impl(const PyConfig *config, memset(prefix, 0, sizeof(prefix)); /* Search for a sys.path file */ - if (calculate_pth_file(pathconfig, prefix)) { + if (calculate_pth_file(calculate, pathconfig, prefix)) { goto done; } @@ -994,7 +998,7 @@ calculate_path_impl(const PyConfig *config, /* Calculate zip archive path from DLL or exe path */ change_ext(calculate->zip_path, - pathconfig->dll_path[0] ? pathconfig->dll_path : pathconfig->program_full_path, + calculate->dll_path[0] ? calculate->dll_path : pathconfig->program_full_path, L".zip"); calculate_home_prefix(calculate, prefix); @@ -1023,23 +1027,23 @@ calculate_free(PyCalculatePath *calculate) { PyMem_RawFree(calculate->machine_path); PyMem_RawFree(calculate->user_path); + PyMem_RawFree(calculate->dll_path); } PyStatus _PyPathConfig_Calculate(_PyPathConfig *pathconfig, const PyConfig *config) { + PyStatus status; PyCalculatePath calculate; memset(&calculate, 0, sizeof(calculate)); - calculate_init(&calculate, config); - - PyStatus status = calculate_path_impl(config, &calculate, pathconfig); + status = calculate_init(&calculate, config); if (_PyStatus_EXCEPTION(status)) { goto done; } - status = _PyStatus_OK(); + status = calculate_path_impl(config, &calculate, pathconfig); done: calculate_free(&calculate); @@ -1067,7 +1071,12 @@ _Py_CheckPython3(void) /* If there is a python3.dll next to the python3y.dll, assume this is a build tree; use that DLL */ - wcscpy(py3path, _Py_path_config.dll_path); + if (_Py_dll_path != NULL) { + wcscpy(py3path, _Py_dll_path); + } + else { + wcscpy(py3path, L""); + } s = wcsrchr(py3path, L'\\'); if (!s) { s = py3path; |