diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-09-21 01:50:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-21 01:50:16 +0200 |
commit | e267793aa4101b2771ed0e66aaff5743d23f59af (patch) | |
tree | f1378008cb479ac5d1841bc10ef2f055a5d98bf6 | |
parent | 77af2290e594479002aa7d8f914d1f38b14a4854 (diff) | |
download | cpython-git-e267793aa4101b2771ed0e66aaff5743d23f59af.tar.gz |
bpo-38234: Fix PyConfig_Read() when Py_SetPath() was called (GH-16298)
* If Py_SetPath() has been called, _PyConfig_InitPathConfig() now
uses its value.
* Py_Initialize() now longer copies path configuration from PyConfig
to the global path configuration (_Py_path_config).
-rw-r--r-- | Misc/NEWS.d/next/C API/2019-09-20-17-22-41.bpo-38234.ZbquVK.rst | 2 | ||||
-rw-r--r-- | Modules/getpath.c | 10 | ||||
-rw-r--r-- | PC/getpathp.c | 9 | ||||
-rw-r--r-- | Python/pathconfig.c | 7 |
4 files changed, 21 insertions, 7 deletions
diff --git a/Misc/NEWS.d/next/C API/2019-09-20-17-22-41.bpo-38234.ZbquVK.rst b/Misc/NEWS.d/next/C API/2019-09-20-17-22-41.bpo-38234.ZbquVK.rst new file mode 100644 index 0000000000..6310f19f00 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-09-20-17-22-41.bpo-38234.ZbquVK.rst @@ -0,0 +1,2 @@ +Python ignored path passed to :c:func:`Py_SetPath`, fix Python +initialization to use the specified path. diff --git a/Modules/getpath.c b/Modules/getpath.c index 36f9860ea1..3946623862 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -1213,10 +1213,12 @@ calculate_path_impl(const PyConfig *config, "Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n"); } - status = calculate_module_search_path(config, calculate, - prefix, exec_prefix, pathconfig); - if (_PyStatus_EXCEPTION(status)) { - return status; + if (pathconfig->module_search_path == NULL) { + status = calculate_module_search_path(config, calculate, + prefix, exec_prefix, pathconfig); + if (_PyStatus_EXCEPTION(status)) { + return status; + } } status = calculate_reduce_prefix(calculate, prefix, Py_ARRAY_LENGTH(prefix)); diff --git a/PC/getpathp.c b/PC/getpathp.c index 01455a660b..0ee53080bf 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -1003,9 +1003,12 @@ calculate_path_impl(const PyConfig *config, calculate_home_prefix(calculate, prefix); - status = calculate_module_search_path(config, calculate, pathconfig, prefix); - if (_PyStatus_EXCEPTION(status)) { - return status; + if (pathconfig->module_search_path == NULL) { + status = calculate_module_search_path(config, calculate, + pathconfig, prefix); + if (_PyStatus_EXCEPTION(status)) { + return status; + } } done: diff --git a/Python/pathconfig.c b/Python/pathconfig.c index ccab832742..2d00f4b6b1 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -74,6 +74,13 @@ pathconfig_calculate(_PyPathConfig *pathconfig, const PyConfig *config) PyMemAllocatorEx old_alloc; _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + if (copy_wstr(&new_config.module_search_path, + _Py_path_config.module_search_path) < 0) + { + status = _PyStatus_NO_MEMORY(); + goto error; + } + /* Calculate program_full_path, prefix, exec_prefix, dll_path (Windows), and module_search_path */ status = _PyPathConfig_Calculate(&new_config, config); |