summaryrefslogtreecommitdiff
path: root/Python/preconfig.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-18 03:21:27 +0200
committerGitHub <noreply@github.com>2019-05-18 03:21:27 +0200
commitbab0db6076900cd828588be8595b3cdfade7e7e9 (patch)
tree4506d3bcfa77235fd79a66563098ef2066962819 /Python/preconfig.c
parent27ee0f8551a6d576a65e20da90acf9f3cb412c35 (diff)
downloadcpython-git-bab0db6076900cd828588be8595b3cdfade7e7e9.tar.gz
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/preconfig.c')
-rw-r--r--Python/preconfig.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/Python/preconfig.c b/Python/preconfig.c
index b7bcfeb9b2..0f4bd8ece5 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;
}