summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Modules/main.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 1ab555b42d..974a0a6b78 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -1291,10 +1291,17 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag;
#endif
_PyCoreConfig save_config = _PyCoreConfig_INIT;
+ char *oldloc = NULL;
int res = -1;
- /* Set LC_CTYPE to the user preferred locale */
- _Py_SetLocaleFromEnv(LC_CTYPE);
+ 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);
int locale_coerced = 0;
int loops = 0;
@@ -1385,6 +1392,10 @@ 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 ;
#ifdef MS_WINDOWS
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;