From 552f73e960b7214d6648e244950c4b56de9f17fb Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 14 Oct 2021 12:11:46 -0600 Subject: [PATCH] Do not set PyConfig.stdlib_dir in Py_SetPythonHome(). --- Lib/test/test_embed.py | 7 ++++++- Python/pathconfig.c | 5 +---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 41e092019c49a3..4cbb4c2c1ce366 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1247,6 +1247,11 @@ def test_init_setpythonhome(self): self.fail(f"Unable to find home in {paths!r}") prefix = exec_prefix = home + if MS_WINDOWS: + stdlib = os.path.join(home, sys.platlibdir) + else: + version = f'{sys.version_info.major}.{sys.version_info.minor}' + stdlib = os.path.join(home, sys.platlibdir, f'python{version}') expected_paths = self.module_search_paths(prefix=home, exec_prefix=home) config = { @@ -1257,7 +1262,7 @@ def test_init_setpythonhome(self): 'exec_prefix': exec_prefix, 'base_exec_prefix': exec_prefix, 'pythonpath_env': paths_str, - 'stdlib_dir': home, + 'stdlib_dir': stdlib, } self.default_program_name(config) env = {'TESTHOME': home, 'PYTHONPATH': paths_str} diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 2ebb9d39b8c2cf..ad22222e000fc0 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -530,13 +530,10 @@ Py_SetPythonHome(const wchar_t *home) PyMem_RawFree(_Py_path_config.home); _Py_path_config.home = _PyMem_RawWcsdup(home); - if (_Py_path_config.home != NULL) { - _Py_path_config.stdlib_dir = _PyMem_RawWcsdup(home); - } PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - if (_Py_path_config.home == NULL || _Py_path_config.stdlib_dir == NULL) { + if (_Py_path_config.home == NULL) { path_out_of_memory(__func__); } }