mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
bpo-37369: Fix initialization of sys members when launched via an app container (GH-14467)
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
This commit is contained in:
parent
0cba121029
commit
323e743d48
17 changed files with 411 additions and 278 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue