diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-25 17:37:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-25 17:37:10 (GMT) |
commit | a6fbc4e25e1dc7d1c9a26888b9115bc6c2afc101 (patch) | |
tree | b45a6288d1bb5ac1e1df81a0b8c2fc616bc01f44 /Python/coreconfig.c | |
parent | f72346c47537657a287a862305f65eb5d7594fbf (diff) | |
download | cpython-a6fbc4e25e1dc7d1c9a26888b9115bc6c2afc101.zip cpython-a6fbc4e25e1dc7d1c9a26888b9115bc6c2afc101.tar.gz cpython-a6fbc4e25e1dc7d1c9a26888b9115bc6c2afc101.tar.bz2 |
bpo-36301: Add _Py_PreInitializeFromConfig() (GH-12536)
* Initialize _PyPreConfig.dev_mode to -1.
* _PyPreConfig_Read(): coreconfig has the priority over preconfig.
* _PyCoreConfig_Read() now calls _PyPreCmdline_Read() internally.
* config_from_cmdline() now pass _PyPreCmdline to config_read().
* Add _PyPreCmdline_Copy().
Diffstat (limited to 'Python/coreconfig.c')
-rw-r--r-- | Python/coreconfig.c | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 130dfcc..ba5abb6 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1336,16 +1336,30 @@ config_init_fs_encoding(_PyCoreConfig *config) * Py_xxx global configuration variables See _PyCoreConfig_ReadFromArgv() to parse also command line arguments. */ -_PyInitError -_PyCoreConfig_Read(_PyCoreConfig *config) +static _PyInitError +config_read_impl(_PyCoreConfig *config, _PyPreCmdline *cmdline) { _PyInitError err; - err = _Py_PreInitialize(); + err = _Py_PreInitializeFromConfig(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + + _PyPreCmdline_GetPreConfig(cmdline, &_PyRuntime.preconfig); + _PyPreCmdline_GetCoreConfig(cmdline, config); + + err = _PyPreCmdline_Read(cmdline); if (_Py_INIT_FAILED(err)) { return err; } + _PyPreCmdline_SetCoreConfig(cmdline, config); + + if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) { + return _Py_INIT_NO_MEMORY(); + } + if (_PyPreConfig_Copy(&config->preconfig, &_PyRuntime.preconfig) < 0) { return _Py_INIT_NO_MEMORY(); } @@ -1454,6 +1468,41 @@ _PyCoreConfig_Read(_PyCoreConfig *config) } +static _PyInitError +config_read(_PyCoreConfig *config, const _PyPreCmdline *src_cmdline) +{ + _PyInitError err; + + err = _Py_PreInitializeFromConfig(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + + _PyPreCmdline cmdline = _PyPreCmdline_INIT; + + if (src_cmdline) { + if (_PyPreCmdline_Copy(&cmdline, src_cmdline) < 0) { + err = _Py_INIT_NO_MEMORY(); + goto done; + } + } + + err = config_read_impl(config, &cmdline); + +done: + _PyPreCmdline_Clear(&cmdline); + return err; + +} + + +_PyInitError +_PyCoreConfig_Read(_PyCoreConfig *config) +{ + return config_read(config, NULL); +} + + static void config_init_stdio(const _PyCoreConfig *config) { @@ -2025,9 +2074,6 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline) } _PyPreCmdline_SetPreConfig(&cmdline->precmdline, &_PyRuntime.preconfig); - if (_PyWstrList_Extend(&config->xoptions, &cmdline->precmdline.xoptions) < 0) { - return _Py_INIT_NO_MEMORY(); - } err = config_parse_cmdline(config, cmdline, &need_usage); if (_Py_INIT_FAILED(err)) { @@ -2055,7 +2101,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline) return err; } - err = _PyCoreConfig_Read(config); + err = config_read(config, &cmdline->precmdline); if (_Py_INIT_FAILED(err)) { return err; } @@ -2090,7 +2136,7 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args) { _PyInitError err; - err = _Py_PreInitialize(); + err = _Py_PreInitializeFromConfig(config); if (_Py_INIT_FAILED(err)) { return err; } |