diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-23 04:12:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-23 04:12:27 +0200 |
commit | 20e1e2582e5e69e43af88ff58699c8883d146acb (patch) | |
tree | 2726fa5c02f6b7ddd00eede7ecdaa2f5587e6fd7 /Python | |
parent | bc2aa816620c5e02ad8e94d8514b7e8f3f551ca1 (diff) | |
download | cpython-git-20e1e2582e5e69e43af88ff58699c8883d146acb.tar.gz |
bpo-36763: Fix _PyPreConfig_InitCompatConfig() utf8_mode (GH-13518)
* _PyPreConfig_InitCompatConfig() sets utf8_mode to 0.
* Change Py_UTF8Mode default value to 0.
* Fix _PyPreConfig_Copy(): copy also _config_init attrbibute.
* _PyPreConfig_AsDict() exports _config_init
* Fix _PyPreConfig_GetGlobalConfig(): use Py_UTF8Mode if it's greater
than 0, even if utf8_mode >= 0.
* Add unit tests on environment variables using Python API.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/coreconfig.c | 5 | ||||
-rw-r--r-- | Python/preconfig.c | 17 |
2 files changed, 17 insertions, 5 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 40dba4ee5e..89ccff4c9b 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -107,9 +107,8 @@ static const char usage_6[] = /* --- Global configuration variables ----------------------------- */ /* UTF-8 mode (PEP 540): if equals to 1, use the UTF-8 encoding, and change - stdin and stdout error handler to "surrogateescape". It is equal to - -1 by default: unknown, will be set by Py_Main() */ -int Py_UTF8Mode = -1; + stdin and stdout error handler to "surrogateescape". */ +int Py_UTF8Mode = 0; int Py_DebugFlag = 0; /* Needed by parser.c */ int Py_VerboseFlag = 0; /* Needed by import.c */ int Py_QuietFlag = 0; /* Needed by sysmodule.c */ diff --git a/Python/preconfig.c b/Python/preconfig.c index 392324ff20..a6d1346eb4 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -272,7 +272,16 @@ _PyPreConfig_InitCompatConfig(_PyPreConfig *config) config->isolated = -1; config->use_environment = -1; config->configure_locale = 1; - config->utf8_mode = -1; + + /* bpo-36443: C locale coercion (PEP 538) and UTF-8 Mode (PEP 540) + are disabled by default using the Compat configuration. + + Py_UTF8Mode=1 enables the UTF-8 mode. PYTHONUTF8 environment variable + is ignored (even if use_environment=1). */ + config->utf8_mode = 0; + config->coerce_c_locale = 0; + config->coerce_c_locale_warn = 0; + config->dev_mode = -1; config->allocator = PYMEM_ALLOCATOR_NOT_SET; #ifdef MS_WINDOWS @@ -353,6 +362,7 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2) { #define COPY_ATTR(ATTR) config->ATTR = config2->ATTR + COPY_ATTR(_config_init); COPY_ATTR(parse_argv); COPY_ATTR(isolated); COPY_ATTR(use_environment); @@ -393,6 +403,7 @@ _PyPreConfig_AsDict(const _PyPreConfig *config) } \ } while (0) + SET_ITEM_INT(_config_init); SET_ITEM_INT(parse_argv); SET_ITEM_INT(isolated); SET_ITEM_INT(use_environment); @@ -452,7 +463,9 @@ _PyPreConfig_GetGlobalConfig(_PyPreConfig *config) COPY_FLAG(isolated, Py_IsolatedFlag); COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag); - COPY_FLAG(utf8_mode, Py_UTF8Mode); + if (Py_UTF8Mode > 0) { + config->utf8_mode = Py_UTF8Mode; + } #ifdef MS_WINDOWS COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag); #endif |