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/pylifecycle.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/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index ea1b731..66cadc9 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -715,7 +715,9 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, static _PyInitError -pyinit_preinit(_PyPreConfig *config, const _PyPreConfig *src_config) +pyinit_preinit(_PyPreConfig *config, + const _PyPreConfig *src_config, + const _PyCoreConfig *coreconfig) { _PyInitError err; @@ -729,13 +731,17 @@ pyinit_preinit(_PyPreConfig *config, const _PyPreConfig *src_config) return _Py_INIT_OK(); } + if (!src_config && coreconfig) { + src_config = &coreconfig->preconfig; + } + if (src_config) { if (_PyPreConfig_Copy(config, src_config) < 0) { return _Py_INIT_ERR("failed to copy pre config"); } } - err = _PyPreConfig_Read(config, NULL); + err = _PyPreConfig_Read(config, NULL, coreconfig); if (_Py_INIT_FAILED(err)) { return err; } @@ -751,17 +757,27 @@ pyinit_preinit(_PyPreConfig *config, const _PyPreConfig *src_config) _PyInitError +_Py_PreInitialize(void) +{ + _PyPreConfig config = _PyPreConfig_INIT; + _PyInitError err = pyinit_preinit(&config, NULL, NULL); + _PyPreConfig_Clear(&config); + return err; +} + + +_PyInitError _Py_PreInitializeFromPreConfig(_PyPreConfig *config) { - return pyinit_preinit(config, NULL); + return pyinit_preinit(config, NULL, NULL); } _PyInitError -_Py_PreInitialize(void) +_Py_PreInitializeFromConfig(const _PyCoreConfig *coreconfig) { _PyPreConfig config = _PyPreConfig_INIT; - _PyInitError err = pyinit_preinit(&config, NULL); + _PyInitError err = pyinit_preinit(&config, NULL, coreconfig); _PyPreConfig_Clear(&config); return err; } @@ -814,16 +830,13 @@ _Py_InitializeCore(PyInterpreterState **interp_p, assert(src_config != NULL); - _PyCoreConfig local_config = _PyCoreConfig_INIT; - - err = pyinit_preinit(&local_config.preconfig, &src_config->preconfig); + err = _Py_PreInitializeFromConfig(src_config); if (_Py_INIT_FAILED(err)) { - goto done; + return err; } + _PyCoreConfig local_config = _PyCoreConfig_INIT; err = pyinit_coreconfig(&local_config, src_config, interp_p); - -done: _PyCoreConfig_Clear(&local_config); return err; } |