diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-17 19:01:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-17 19:01:14 +0200 |
commit | cab5d0741ee6adf2ae9ff5aaafe06b75b4b5bca3 (patch) | |
tree | 745b2e08f4a035ffb345e695216934b1a3b6ccda /Python/pylifecycle.c | |
parent | b16b4e45923f4e4dfd8e970ae4e6a934faf73b79 (diff) | |
download | cpython-git-cab5d0741ee6adf2ae9ff5aaafe06b75b4b5bca3.tar.gz |
bpo-36763: Add _PyCoreConfig_InitPythonConfig() (GH-13388)
Add new functions to get the Python interpreter behavior:
* _PyPreConfig_InitPythonConfig()
* _PyCoreConfig_InitPythonConfig()
Add new functions to get an isolated configuration:
* _PyPreConfig_InitIsolatedConfig()
* _PyCoreConfig_InitIsolatedConfig()
Replace _PyPreConfig_INIT and _PyCoreConfig_INIT with new functions
_PyPreConfig_Init() and _PyCoreConfig_Init().
_PyCoreConfig: set configure_c_stdio and parse_argv to 0 by default
to behave as Python 3.6 in the default configuration.
_PyCoreConfig_Read() no longer sets coerce_c_locale_warn to 1 if it's
equal to 0. coerce_c_locale_warn must now be set to -1 (ex: using
_PyCoreConfig_InitPythonConfig()) to enable C locale coercion
warning.
Add unit tests for _PyCoreConfig_InitPythonConfig()
and _PyCoreConfig_InitIsolatedConfig().
Changes:
* Rename _PyCoreConfig_GetCoreConfig() to _PyPreConfig_GetCoreConfig()
* Fix core_read_precmdline(): handle parse_argv=0
* Fix _Py_PreInitializeFromCoreConfig(): pass coreconfig.argv
to _Py_PreInitializeFromPyArgv(), except if parse_argv=0
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index eecb439a11..231706d2ab 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -701,7 +701,8 @@ _Py_PreInitializeFromPyArgv(const _PyPreConfig *src_config, const _PyArgv *args) return _Py_INIT_OK(); } - _PyPreConfig config = _PyPreConfig_INIT; + _PyPreConfig config; + _PyPreConfig_Init(&config); if (src_config) { if (_PyPreConfig_Copy(&config, src_config) < 0) { @@ -752,13 +753,22 @@ _PyInitError _Py_PreInitializeFromCoreConfig(const _PyCoreConfig *coreconfig, const _PyArgv *args) { - _PyPreConfig config = _PyPreConfig_INIT; + _PyPreConfig config; + _PyPreConfig_Init(&config); if (coreconfig != NULL) { - _PyCoreConfig_GetCoreConfig(&config, coreconfig); + _PyPreConfig_GetCoreConfig(&config, coreconfig); + } + + if (args == NULL && coreconfig != NULL && coreconfig->parse_argv) { + _PyArgv config_args = { + .use_bytes_argv = 0, + .argc = coreconfig->argv.length, + .wchar_argv = coreconfig->argv.items}; + return _Py_PreInitializeFromPyArgv(&config, &config_args); + } + else { + return _Py_PreInitializeFromPyArgv(&config, args); } - return _Py_PreInitializeFromPyArgv(&config, args); - /* No need to clear config: - _PyCoreConfig_GetCoreConfig() doesn't allocate memory */ } @@ -829,7 +839,8 @@ _Py_InitializeCore(_PyRuntimeState *runtime, return err; } - _PyCoreConfig local_config = _PyCoreConfig_INIT; + _PyCoreConfig local_config; + _PyCoreConfig_Init(&local_config); err = pyinit_coreconfig(runtime, &local_config, src_config, args, interp_p); _PyCoreConfig_Clear(&local_config); return err; @@ -1051,7 +1062,8 @@ Py_InitializeEx(int install_sigs) return; } - _PyCoreConfig config = _PyCoreConfig_INIT; + _PyCoreConfig config; + _PyCoreConfig_Init(&config); config.install_signal_handlers = install_sigs; err = _Py_InitializeFromConfig(&config); |