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/preconfig.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/preconfig.c')
-rw-r--r-- | Python/preconfig.c | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/Python/preconfig.c b/Python/preconfig.c index c16f340..ac87a7a 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -110,6 +110,22 @@ _PyPreCmdline_Clear(_PyPreCmdline *cmdline) } +int +_PyPreCmdline_Copy(_PyPreCmdline *cmdline, const _PyPreCmdline *cmdline2) +{ + _PyPreCmdline_Clear(cmdline); + if (_PyWstrList_Copy(&cmdline->argv, &cmdline2->argv) < 0) { + return -1; + } + if (_PyWstrList_Copy(&cmdline->xoptions, &cmdline2->xoptions) < 0) { + return -1; + } + cmdline->use_environment = cmdline2->use_environment; + cmdline->isolated = cmdline2->isolated; + return 0; +} + + _PyInitError _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) { @@ -117,7 +133,7 @@ _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) } -static void +void _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) { #define COPY_ATTR(ATTR) \ @@ -132,6 +148,36 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) } +void +_PyPreCmdline_GetCoreConfig(_PyPreCmdline *cmdline, const _PyCoreConfig *config) +{ +#define COPY_ATTR(ATTR) \ + if (config->preconfig.ATTR != -1) { \ + cmdline->ATTR = config->preconfig.ATTR; \ + } + + COPY_ATTR(use_environment); + COPY_ATTR(isolated); + +#undef COPY_ATTR +} + + +void +_PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config) +{ +#define COPY_ATTR(ATTR) \ + if (config->preconfig.ATTR == -1 && cmdline->ATTR != -1) { \ + config->preconfig.ATTR = cmdline->ATTR; \ + } + + COPY_ATTR(use_environment); + COPY_ATTR(isolated); + +#undef COPY_ATTR +} + + /* --- _PyPreConfig ----------------------------------------------- */ void @@ -628,7 +674,8 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline) See _PyPreConfig_ReadFromArgv() to parse also command line arguments. */ _PyInitError -_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) +_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args, + const _PyCoreConfig *coreconfig) { _PyInitError err; _PyPreCmdline cmdline = _PyPreCmdline_INIT; @@ -642,8 +689,17 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) /* Set LC_CTYPE to the user preferred locale */ _Py_SetLocaleFromEnv(LC_CTYPE); + _PyPreConfig_GetGlobalConfig(config); + _PyPreCmdline_GetPreConfig(&cmdline, config); + if (coreconfig) { + _PyPreCmdline_GetCoreConfig(&cmdline, coreconfig); + if (config->dev_mode == -1) { + config->dev_mode = coreconfig->preconfig.dev_mode; + } + } + if (args) { err = _PyPreCmdline_SetArgv(&cmdline, args); if (_Py_INIT_FAILED(err)) { @@ -724,7 +780,7 @@ _PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; #endif - err = _PyPreConfig_Read(config, args); + err = _PyPreConfig_Read(config, args, NULL); if (_Py_INIT_FAILED(err)) { goto done; } |