summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-08-29 09:25:15 (GMT)
committerGitHub <noreply@github.com>2018-08-29 09:25:15 (GMT)
commit177d921c8c03d30daa32994362023f777624b10d (patch)
tree48447c8a88ccde0129cebcdbad97560a37a22790 /Python
parent315877dc361d554bec34b4b62c270479ad36a1be (diff)
downloadcpython-177d921c8c03d30daa32994362023f777624b10d.zip
cpython-177d921c8c03d30daa32994362023f777624b10d.tar.gz
cpython-177d921c8c03d30daa32994362023f777624b10d.tar.bz2
bpo-34485, Windows: LC_CTYPE set to user preference (GH-8988)
On Windows, the LC_CTYPE is now set to the user preferred locale at startup: _Py_SetLocaleFromEnv(LC_CTYPE) is now called during the Python initialization. Previously, the LC_CTYPE locale was "C" at startup, but changed when calling setlocale(LC_CTYPE, "") or setlocale(LC_ALL, ""). pymain_read_conf() now also calls _Py_SetLocaleFromEnv(LC_CTYPE) to behave as _Py_InitializeCore(). Moreover, it doesn't save/restore the LC_ALL anymore. On Windows, standard streams like sys.stdout now always use surrogateescape error handler by default (ignore the locale).
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 33af06e..88403f4 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -343,6 +343,7 @@ static _LocaleCoercionTarget _TARGET_LOCALES[] = {
static const char *
get_stdio_errors(void)
{
+#ifndef MS_WINDOWS
const char *ctype_loc = setlocale(LC_CTYPE, NULL);
if (ctype_loc != NULL) {
/* surrogateescape is the default in the legacy C and POSIX locales */
@@ -362,6 +363,10 @@ get_stdio_errors(void)
}
return "strict";
+#else
+ /* On Windows, always use surrogateescape by default */
+ return "surrogateescape";
+#endif
}
#ifdef PY_COERCE_C_LOCALE
@@ -751,11 +756,8 @@ _Py_InitializeCore(PyInterpreterState **interp_p,
(and the input configuration is read only). */
_PyCoreConfig config = _PyCoreConfig_INIT;
-#ifndef MS_WINDOWS
- /* Set up the LC_CTYPE locale, so we can obtain the locale's charset
- without having to switch locales. */
+ /* Set LC_CTYPE to the user preferred locale */
_Py_SetLocaleFromEnv(LC_CTYPE);
-#endif
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
if (_PyCoreConfig_Copy(&config, src_config) >= 0) {