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.
This commit is contained in:
Victor Stinner 2019-05-18 03:21:27 +02:00 committed by GitHub
parent 27ee0f8551
commit bab0db6076
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 240 additions and 181 deletions

View file

@ -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;
}