diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-17 20:44:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-17 20:44:16 (GMT) |
commit | bcfbbd704646622e919c1306a91fba61d603483d (patch) | |
tree | 51238f56ba837c49330424bd995b2de71b5a5a48 /Python | |
parent | 98ff4d5fb6a9d01b0176b7786db61346952e5295 (diff) | |
download | cpython-bcfbbd704646622e919c1306a91fba61d603483d.zip cpython-bcfbbd704646622e919c1306a91fba61d603483d.tar.gz cpython-bcfbbd704646622e919c1306a91fba61d603483d.tar.bz2 |
bpo-36945: Add _PyPreConfig.configure_locale (GH-13368)
_PyPreConfig_InitIsolatedConfig() sets configure_locale to 0 to
prevent Python to modify the LC_CTYPE locale. In that case,
coerce_c_locale an coerce_c_locale_warn are set to 0 as well.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/preconfig.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/Python/preconfig.c b/Python/preconfig.c index 7814ee0..985af39 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -286,6 +286,7 @@ _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config) { _PyPreConfig_Init(config); + config->configure_locale = 0; config->isolated = 1; config->use_environment = 0; #ifdef MS_WINDOWS @@ -312,6 +313,7 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2) COPY_ATTR(isolated); COPY_ATTR(use_environment); + COPY_ATTR(configure_locale); COPY_ATTR(dev_mode); COPY_ATTR(coerce_c_locale); COPY_ATTR(coerce_c_locale_warn); @@ -360,6 +362,7 @@ _PyPreConfig_AsDict(const _PyPreConfig *config) SET_ITEM_INT(isolated); SET_ITEM_INT(use_environment); + SET_ITEM_INT(configure_locale); SET_ITEM_INT(coerce_c_locale); SET_ITEM_INT(coerce_c_locale_warn); SET_ITEM_INT(utf8_mode); @@ -603,6 +606,12 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline) static void preconfig_init_coerce_c_locale(_PyPreConfig *config) { + if (!config->configure_locale) { + config->coerce_c_locale = 0; + config->coerce_c_locale_warn = 0; + return; + } + const char *env = _Py_GetEnv(config->use_environment, "PYTHONCOERCECLOCALE"); if (env) { if (strcmp(env, "0") == 0) { @@ -746,7 +755,9 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) } /* Set LC_CTYPE to the user preferred locale */ - _Py_SetLocaleFromEnv(LC_CTYPE); + if (config->configure_locale) { + _Py_SetLocaleFromEnv(LC_CTYPE); + } _PyPreCmdline cmdline = _PyPreCmdline_INIT; int init_utf8_mode = Py_UTF8Mode; @@ -879,12 +890,14 @@ _PyPreConfig_Write(const _PyPreConfig *config) _PyPreConfig_SetGlobalConfig(config); - if (config->coerce_c_locale) { - _Py_CoerceLegacyLocale(config->coerce_c_locale_warn); - } + if (config->configure_locale) { + if (config->coerce_c_locale) { + _Py_CoerceLegacyLocale(config->coerce_c_locale_warn); + } - /* Set LC_CTYPE to the user preferred locale */ - _Py_SetLocaleFromEnv(LC_CTYPE); + /* Set LC_CTYPE to the user preferred locale */ + _Py_SetLocaleFromEnv(LC_CTYPE); + } /* Write the new pre-configuration into _PyRuntime */ PyMemAllocatorEx old_alloc; |