From d929f1838a8fba881ff0148b7fc31f6265703e3d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Mar 2019 18:28:46 +0100 Subject: bpo-36443: Disable C locale coercion and UTF-8 Mode by default (GH-12589) bpo-36443, bpo-36202: Since Python 3.7.0, calling Py_DecodeLocale() before Py_Initialize() produces mojibake if the LC_CTYPE locale is coerced and/or if the UTF-8 Mode is enabled by the user configuration. This change fix the issue by disabling LC_CTYPE coercion and UTF-8 Mode by default. They must now be enabled explicitly (opt-in) using the new _Py_PreInitialize() API with _PyPreConfig. When embedding Python, set coerce_c_locale and utf8_mode attributes of _PyPreConfig to -1 to enable automatically these parameters depending on the LC_CTYPE locale, environment variables and command line arguments Alternative: Setting Py_UTF8Mode to 1 always explicitly enables the UTF-8 Mode. Changes: * _PyPreConfig_INIT now sets coerce_c_locale and utf8_mode to 0 by default. * _Py_InitializeFromArgs() and _Py_InitializeFromWideArgs() can now be called with config=NULL. --- Python/preconfig.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Python/preconfig.c') diff --git a/Python/preconfig.c b/Python/preconfig.c index 011ed53a8e..7ac645d7f0 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -386,7 +386,9 @@ _PyPreConfig_GetGlobalConfig(_PyPreConfig *config) #ifdef MS_WINDOWS COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag); #endif - COPY_FLAG(utf8_mode, Py_UTF8Mode); + if (Py_UTF8Mode > 0) { + config->utf8_mode = 1; + } #undef COPY_FLAG #undef COPY_NOT_FLAG -- cgit v1.2.1