mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-32030: Add _PyMainInterpreterConfig_ReadEnv() (#4542)
Py_GetPath() and Py_Main() now call _PyMainInterpreterConfig_ReadEnv() to share the same code to get environment variables. Changes: * Add _PyMainInterpreterConfig_ReadEnv() * Add _PyMainInterpreterConfig_Clear() * Add _PyMem_RawWcsdup() * _PyMainInterpreterConfig: rename pythonhome to home * Rename _Py_ReadMainInterpreterConfig() to _PyMainInterpreterConfig_Read() * Use _Py_INIT_USER_ERR(), instead of _Py_INIT_ERR(), for decoding errors: the user is able to fix the issue, it's not a bug in Python. Same change was made in _Py_INIT_NO_MEMORY(). * Remove _Py_GetPythonHomeWithConfig()
This commit is contained in:
parent
84c4b1938f
commit
46972b7bc3
8 changed files with 165 additions and 142 deletions
|
|
@ -689,26 +689,12 @@ error:
|
|||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
static void
|
||||
calculate_init(PyCalculatePath *calculate,
|
||||
const _PyMainInterpreterConfig *main_config)
|
||||
{
|
||||
_PyInitError err;
|
||||
|
||||
err = _Py_GetPythonHomeWithConfig(main_config, &calculate->home);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (main_config) {
|
||||
calculate->module_search_path_env = main_config->module_search_path_env;
|
||||
}
|
||||
else if (!Py_IgnoreEnvironmentFlag) {
|
||||
wchar_t *path = _wgetenv(L"PYTHONPATH");
|
||||
if (path && *path != '\0') {
|
||||
calculate->module_search_path_env = path;
|
||||
}
|
||||
}
|
||||
calculate->home = main_config->home;
|
||||
calculate->module_search_path_env = main_config->module_search_path_env;
|
||||
|
||||
calculate->path_env = _wgetenv(L"PATH");
|
||||
|
||||
|
|
@ -717,8 +703,6 @@ calculate_init(PyCalculatePath *calculate,
|
|||
prog = L"python";
|
||||
}
|
||||
calculate->prog = prog;
|
||||
|
||||
return _Py_INIT_OK();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1020,22 +1004,41 @@ calculate_free(PyCalculatePath *calculate)
|
|||
static void
|
||||
calculate_path(const _PyMainInterpreterConfig *main_config)
|
||||
{
|
||||
_PyInitError err;
|
||||
PyCalculatePath calculate;
|
||||
memset(&calculate, 0, sizeof(calculate));
|
||||
|
||||
_PyInitError err = calculate_init(&calculate, main_config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
calculate_free(&calculate);
|
||||
_Py_FatalInitError(err);
|
||||
_PyMainInterpreterConfig tmp_config;
|
||||
int use_tmp = (main_config == NULL);
|
||||
if (use_tmp) {
|
||||
tmp_config = _PyMainInterpreterConfig_INIT;
|
||||
err = _PyMainInterpreterConfig_ReadEnv(&tmp_config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
goto fatal_error;
|
||||
}
|
||||
main_config = &tmp_config;
|
||||
}
|
||||
|
||||
calculate_init(&calculate, main_config);
|
||||
|
||||
PyPathConfig new_path_config;
|
||||
memset(&new_path_config, 0, sizeof(new_path_config));
|
||||
|
||||
calculate_path_impl(&calculate, &new_path_config, main_config);
|
||||
path_config = new_path_config;
|
||||
|
||||
if (use_tmp) {
|
||||
_PyMainInterpreterConfig_Clear(&tmp_config);
|
||||
}
|
||||
calculate_free(&calculate);
|
||||
return;
|
||||
|
||||
fatal_error:
|
||||
if (use_tmp) {
|
||||
_PyMainInterpreterConfig_Clear(&tmp_config);
|
||||
}
|
||||
calculate_free(&calculate);
|
||||
_Py_FatalInitError(err);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue