summaryrefslogtreecommitdiffstats
path: root/Modules
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 /Modules
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 'Modules')
-rw-r--r--Modules/main.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/Modules/main.c b/Modules/main.c
index f93ca4d..3a15b2b 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -1280,25 +1280,18 @@ pymain_read_conf_impl(_PyMain *pymain, _PyCoreConfig *config,
}
-/* Read the configuration, but initialize also the LC_CTYPE locale:
- enable UTF-8 mode (PEP 540) and/or coerce the C locale (PEP 538) */
+/* Read the configuration and initialize the LC_CTYPE locale:
+ enable UTF-8 mode (PEP 540) and/or coerce the C locale (PEP 538). */
static int
pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
_PyCmdline *cmdline)
{
int init_utf8_mode = Py_UTF8Mode;
_PyCoreConfig save_config = _PyCoreConfig_INIT;
- char *oldloc = NULL;
int res = -1;
- oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
- if (oldloc == NULL) {
- pymain->err = _Py_INIT_NO_MEMORY();
- goto done;
- }
-
- /* Reconfigure the locale to the default for this process */
- _Py_SetLocaleFromEnv(LC_ALL);
+ /* Set LC_CTYPE to the user preferred locale */
+ _Py_SetLocaleFromEnv(LC_CTYPE);
int locale_coerced = 0;
int loops = 0;
@@ -1386,10 +1379,6 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
done:
_PyCoreConfig_Clear(&save_config);
- if (oldloc != NULL) {
- setlocale(LC_ALL, oldloc);
- PyMem_RawFree(oldloc);
- }
Py_UTF8Mode = init_utf8_mode ;
return res;
}