diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-27 12:40:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-27 12:40:14 (GMT) |
commit | 5ac27a50ff2b42216746fedc0522a92c53089bb3 (patch) | |
tree | 5fbf53a0b5e47f6704f01397de3e01799bf87d41 /Python/coreconfig.c | |
parent | 364f0b0f19cc3f0d5e63f571ec9163cf41c62958 (diff) | |
download | cpython-5ac27a50ff2b42216746fedc0522a92c53089bb3.zip cpython-5ac27a50ff2b42216746fedc0522a92c53089bb3.tar.gz cpython-5ac27a50ff2b42216746fedc0522a92c53089bb3.tar.bz2 |
bpo-36444: Rework _Py_InitializeFromConfig() API (GH-12576)
Diffstat (limited to 'Python/coreconfig.c')
-rw-r--r-- | Python/coreconfig.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c index ecb22e5..13aa227 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1465,12 +1465,7 @@ static _PyInitError config_read(_PyCoreConfig *config, _PyPreCmdline *cmdline) { _PyInitError err; - const _PyPreConfig *preconfig = &_PyRuntime.preconfig; - err = _PyPreCmdline_Read(cmdline, preconfig, config); - if (_Py_INIT_FAILED(err)) { - return err; - } if (_PyPreCmdline_SetCoreConfig(cmdline, config) < 0) { return _Py_INIT_NO_MEMORY(); @@ -2016,6 +2011,35 @@ config_usage(int error, const wchar_t* program) } +static _PyInitError +core_read_precmdline(_PyCoreConfig *config, const _PyArgv *args, + _PyPreCmdline *precmdline) +{ + _PyInitError err; + + if (args) { + err = _PyPreCmdline_SetArgv(precmdline, args); + if (_Py_INIT_FAILED(err)) { + return err; + } + } + + _PyPreConfig preconfig = _PyPreConfig_INIT; + if (_PyPreConfig_Copy(&preconfig, &_PyRuntime.preconfig) < 0) { + err = _Py_INIT_NO_MEMORY(); + goto done; + } + + _PyCoreConfig_GetCoreConfig(&preconfig, config); + + err = _PyPreCmdline_Read(precmdline, &preconfig); + +done: + _PyPreConfig_Clear(&preconfig); + return err; +} + + /* Read the configuration into _PyCoreConfig from: * Command line arguments @@ -2026,7 +2050,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) { _PyInitError err; - err = _Py_PreInitializeFromConfig(config); + err = _Py_PreInitializeFromCoreConfig(config); if (_Py_INIT_FAILED(err)) { return err; } @@ -2034,11 +2058,9 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) _PyCoreConfig_GetGlobalConfig(config); _PyPreCmdline precmdline = _PyPreCmdline_INIT; - if (args) { - err = _PyPreCmdline_SetArgv(&precmdline, args); - if (_Py_INIT_FAILED(err)) { - goto done; - } + err = core_read_precmdline(config, args, &precmdline); + if (_Py_INIT_FAILED(err)) { + goto done; } if (config->program == NULL) { @@ -2048,12 +2070,6 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) } } - const _PyPreConfig *preconfig = &_PyRuntime.preconfig; - err = _PyPreCmdline_Read(&precmdline, preconfig, config); - if (_Py_INIT_FAILED(err)) { - goto done; - } - _PyCmdline cmdline; memset(&cmdline, 0, sizeof(cmdline)); |