diff options
author | Steve Dower <steve.dower@python.org> | 2019-06-29 17:34:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-29 17:34:11 (GMT) |
commit | 9048c49322a5229ff99610aba35913ffa295ebb7 (patch) | |
tree | caad6f4a3b44e547208ac70cc1746c4df349ac8f /Python | |
parent | 80097e089ba22a42d804e65fbbcf35e5e49eed00 (diff) | |
download | cpython-9048c49322a5229ff99610aba35913ffa295ebb7.zip cpython-9048c49322a5229ff99610aba35913ffa295ebb7.tar.gz cpython-9048c49322a5229ff99610aba35913ffa295ebb7.tar.bz2 |
bpo-37369: Fix initialization of sys members when launched via an app container (GH-14428)
sys._base_executable is now always defined on all platforms, and can be overridden through configuration.
Also adds test.support.PythonSymlink to encapsulate platform-specific logic for symlinking sys.executable
Diffstat (limited to 'Python')
-rw-r--r-- | Python/initconfig.c | 4 | ||||
-rw-r--r-- | Python/pathconfig.c | 30 | ||||
-rw-r--r-- | Python/sysmodule.c | 1 |
3 files changed, 35 insertions, 0 deletions
diff --git a/Python/initconfig.c b/Python/initconfig.c index 9c4cfbe..786f694 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -528,6 +528,7 @@ PyConfig_Clear(PyConfig *config) config->module_search_paths_set = 0; CLEAR(config->executable); + CLEAR(config->base_executable); CLEAR(config->prefix); CLEAR(config->base_prefix); CLEAR(config->exec_prefix); @@ -765,6 +766,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2) COPY_ATTR(module_search_paths_set); COPY_WSTR_ATTR(executable); + COPY_WSTR_ATTR(base_executable); COPY_WSTR_ATTR(prefix); COPY_WSTR_ATTR(base_prefix); COPY_WSTR_ATTR(exec_prefix); @@ -865,6 +867,7 @@ config_as_dict(const PyConfig *config) SET_ITEM_WSTR(home); SET_ITEM_WSTRLIST(module_search_paths); SET_ITEM_WSTR(executable); + SET_ITEM_WSTR(base_executable); SET_ITEM_WSTR(prefix); SET_ITEM_WSTR(base_prefix); SET_ITEM_WSTR(exec_prefix); @@ -2404,6 +2407,7 @@ PyConfig_Read(PyConfig *config) assert(config->module_search_paths_set != 0); /* don't check config->module_search_paths */ assert(config->executable != NULL); + assert(config->base_executable != NULL); assert(config->prefix != NULL); assert(config->base_prefix != NULL); assert(config->exec_prefix != NULL); diff --git a/Python/pathconfig.c b/Python/pathconfig.c index ec67405..79ec4af 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -57,6 +57,7 @@ pathconfig_clear(_PyPathConfig *config) CLEAR(config->module_search_path); CLEAR(config->home); CLEAR(config->program_name); + CLEAR(config->base_executable); #undef CLEAR PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); @@ -89,6 +90,14 @@ pathconfig_calculate(_PyPathConfig *pathconfig, const PyConfig *config) status = _PyStatus_NO_MEMORY(); goto error; } + if (config->base_executable) { + PyMem_RawFree(new_config.base_executable); + if (copy_wstr(&new_config.base_executable, + config->base_executable) < 0) { + status = _PyStatus_NO_MEMORY(); + goto error; + } + } pathconfig_clear(pathconfig); *pathconfig = new_config; @@ -132,6 +141,7 @@ _PyPathConfig_SetGlobal(const _PyPathConfig *config) COPY_ATTR(module_search_path); COPY_ATTR(program_name); COPY_ATTR(home); + COPY_ATTR(base_executable); pathconfig_clear(&_Py_path_config); /* Steal new_config strings; don't clear new_config */ @@ -224,6 +234,9 @@ _PyConfig_SetPathConfig(const PyConfig *config) if (copy_wstr(&pathconfig.home, config->home) < 0) { goto no_memory; } + if (copy_wstr(&pathconfig.base_executable, config->base_executable) < 0) { + goto no_memory; + } status = _PyPathConfig_SetGlobal(&pathconfig); if (_PyStatus_EXCEPTION(status)) { @@ -321,6 +334,13 @@ config_calculate_pathconfig(PyConfig *config) } } + if (config->base_executable == NULL) { + if (copy_wstr(&config->base_executable, + pathconfig.base_executable) < 0) { + goto no_memory; + } + } + if (pathconfig.isolated != -1) { config->isolated = pathconfig.isolated; } @@ -367,6 +387,14 @@ _PyConfig_InitPathConfig(PyConfig *config) return _PyStatus_NO_MEMORY(); } } + + if (config->base_executable == NULL) { + if (copy_wstr(&config->base_executable, + config->executable) < 0) { + return _PyStatus_NO_MEMORY(); + } + } + return _PyStatus_OK(); } @@ -434,6 +462,8 @@ Py_SetPath(const wchar_t *path) _Py_path_config.home = NULL; new_config.program_name = _Py_path_config.program_name; _Py_path_config.program_name = NULL; + new_config.base_executable = _Py_path_config.base_executable; + _Py_path_config.base_executable = NULL; pathconfig_clear(&_Py_path_config); _Py_path_config = new_config; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1c57561..dc198a5 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2850,6 +2850,7 @@ _PySys_InitMain(_PyRuntimeState *runtime, PyThreadState *tstate) COPY_LIST("path", config->module_search_paths); SET_SYS_FROM_WSTR("executable", config->executable); + SET_SYS_FROM_WSTR("_base_executable", config->base_executable); SET_SYS_FROM_WSTR("prefix", config->prefix); SET_SYS_FROM_WSTR("base_prefix", config->base_prefix); SET_SYS_FROM_WSTR("exec_prefix", config->exec_prefix); |