diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-18 01:21:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-18 01:21:27 (GMT) |
commit | bab0db6076900cd828588be8595b3cdfade7e7e9 (patch) | |
tree | 4506d3bcfa77235fd79a66563098ef2066962819 /Python | |
parent | 27ee0f8551a6d576a65e20da90acf9f3cb412c35 (diff) | |
download | cpython-bab0db6076900cd828588be8595b3cdfade7e7e9.zip cpython-bab0db6076900cd828588be8595b3cdfade7e7e9.tar.gz cpython-bab0db6076900cd828588be8595b3cdfade7e7e9.tar.bz2 |
bpo-36763: Use _PyCoreConfig_InitPythonConfig() (GH-13398)
_PyPreConfig_InitPythonConfig() and _PyCoreConfig_InitPythonConfig()
no longer inherit their values from global configuration variables.
Changes:
* _PyPreCmdline_Read() now ignores -X dev and PYTHONDEVMODE
if dev_mode is already set.
* Inline _PyPreConfig_INIT macro into _PyPreConfig_Init() function.
* Inline _PyCoreConfig_INIT macro into _PyCoreConfig_Init() function.
* Replace _PyCoreConfig_Init() with _PyCoreConfig_InitPythonConfig()
in most tests of _testembed.c.
* Replace _PyCoreConfig_Init() with _PyCoreConfig_InitIsolatedConfig()
in _freeze_importlib.c.
* Move some initialization functions from the internal
to the private API.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/coreconfig.c | 77 | ||||
-rw-r--r-- | Python/frozenmain.c | 2 | ||||
-rw-r--r-- | Python/preconfig.c | 23 |
3 files changed, 78 insertions, 24 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c index fd45726..3678d12 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -551,14 +551,69 @@ _PyCoreConfig_Clear(_PyCoreConfig *config) void _PyCoreConfig_Init(_PyCoreConfig *config) { - *config = _PyCoreConfig_INIT; + memset(config, 0, sizeof(*config)); + + config->_config_version = _Py_CONFIG_VERSION; + config->isolated = -1; + config->use_environment = -1; + config->dev_mode = -1; + config->install_signal_handlers = 1; + config->use_hash_seed = -1; + config->faulthandler = -1; + config->tracemalloc = -1; + config->use_module_search_paths = 0; + config->parse_argv = 0; + config->site_import = -1; + config->bytes_warning = -1; + config->inspect = -1; + config->interactive = -1; + config->optimization_level = -1; + config->parser_debug= -1; + config->write_bytecode = -1; + config->verbose = -1; + config->quiet = -1; + config->user_site_directory = -1; + config->configure_c_stdio = 0; + config->buffered_stdio = -1; + config->_install_importlib = 1; + config->check_hash_pycs_mode = NULL; + config->pathconfig_warnings = -1; + config->_init_main = 1; +#ifdef MS_WINDOWS + config->legacy_windows_stdio = -1; +#endif +} + + +static void +_PyCoreConfig_InitDefaults(_PyCoreConfig *config) +{ + _PyCoreConfig_Init(config); + + config->isolated = 0; + config->use_environment = 1; + config->site_import = 1; + config->bytes_warning = 0; + config->inspect = 0; + config->interactive = 0; + config->optimization_level = 0; + config->parser_debug= 0; + config->write_bytecode = 1; + config->verbose = 0; + config->quiet = 0; + config->user_site_directory = 1; + config->buffered_stdio = 1; + config->pathconfig_warnings = 1; +#ifdef MS_WINDOWS + config->legacy_windows_stdio = 0; +#endif } _PyInitError _PyCoreConfig_InitPythonConfig(_PyCoreConfig *config) { - _PyCoreConfig_Init(config); + _PyCoreConfig_InitDefaults(config); config->configure_c_stdio = 1; config->parse_argv = 1; @@ -570,30 +625,16 @@ _PyCoreConfig_InitPythonConfig(_PyCoreConfig *config) _PyInitError _PyCoreConfig_InitIsolatedConfig(_PyCoreConfig *config) { - _PyCoreConfig_Init(config); + _PyCoreConfig_InitDefaults(config); - /* set to 1 */ config->isolated = 1; - config->site_import = 1; - config->write_bytecode = 1; - config->buffered_stdio = 1; - - /* set to 0 */ config->use_environment = 0; + config->user_site_directory = 0; config->dev_mode = 0; config->install_signal_handlers = 0; config->use_hash_seed = 0; config->faulthandler = 0; config->tracemalloc = 0; - config->bytes_warning = 0; - config->inspect = 0; - config->interactive = 0; - config->optimization_level = 0; - config->parser_debug = 0; - config->verbose = 0; - config->quiet = 0; - config->user_site_directory = 0; - config->configure_c_stdio = 0; config->pathconfig_warnings = 0; #ifdef MS_WINDOWS config->legacy_windows_stdio = 0; diff --git a/Python/frozenmain.c b/Python/frozenmain.c index 7b232bb..a51fb58 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -40,7 +40,7 @@ Py_FrozenMain(int argc, char **argv) } _PyCoreConfig config; - _PyCoreConfig_Init(&config); + _PyCoreConfig_InitPythonConfig(&config); config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */ if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') diff --git a/Python/preconfig.c b/Python/preconfig.c index b7bcfeb..0f4bd8e 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -241,8 +241,9 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, } /* dev_mode */ - if ((cmdline && _Py_get_xoption(&cmdline->xoptions, L"dev")) - || _Py_GetEnv(cmdline->use_environment, "PYTHONDEVMODE")) + if ((cmdline->dev_mode < 0) + && (_Py_get_xoption(&cmdline->xoptions, L"dev") + || _Py_GetEnv(cmdline->use_environment, "PYTHONDEVMODE"))) { cmdline->dev_mode = 1; } @@ -260,10 +261,22 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, /* --- _PyPreConfig ----------------------------------------------- */ + void _PyPreConfig_Init(_PyPreConfig *config) { - *config = _PyPreConfig_INIT; + memset(config, 0, sizeof(*config)); + + config->_config_version = _Py_CONFIG_VERSION; + config->isolated = -1; + config->use_environment = -1; + config->configure_locale = 1; + config->utf8_mode = -2; + config->dev_mode = -1; + config->allocator = PYMEM_ALLOCATOR_NOT_SET; +#ifdef MS_WINDOWS + config->legacy_windows_fs_encoding = -1; +#endif } @@ -289,11 +302,11 @@ _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config) config->configure_locale = 0; config->isolated = 1; config->use_environment = 0; + config->utf8_mode = 0; + config->dev_mode = 0; #ifdef MS_WINDOWS config->legacy_windows_fs_encoding = 0; #endif - config->utf8_mode = 0; - config->dev_mode = 0; } |