]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-36443: Disable C locale coercion and UTF-8 Mode by default (GH-12589)
authorVictor Stinner <vstinner@redhat.com>
Wed, 27 Mar 2019 17:28:46 +0000 (18:28 +0100)
committerGitHub <noreply@github.com>
Wed, 27 Mar 2019 17:28:46 +0000 (18:28 +0100)
commitd929f1838a8fba881ff0148b7fc31f6265703e3d
tree36ff97834b250c4412d5a95c2206c8ba9d5cf13e
parent4a9a505d6f2474a570422dad89f8d1b344d6cd36
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.
Include/cpython/coreconfig.h
Lib/test/test_embed.py
Misc/NEWS.d/next/C API/2019-03-27-15-58-23.bpo-36443.tAfZR9.rst [new file with mode: 0644]
Modules/main.c
Programs/_testembed.c
Python/preconfig.c
Python/pylifecycle.c