Skip to content

Commit 73b00be

Browse files
authored
bpo-34544: pymain_read_conf() don't change LC_ALL (GH-9045)
bpo-34485, bpo-34544: Again, pymain_read_conf() leaves LC_ALL locale unchanged: only modify LC_CTYPE.
1 parent 2094c2b commit 73b00be

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

Modules/main.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,18 +1291,7 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
12911291
int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag;
12921292
#endif
12931293
_PyCoreConfig save_config = _PyCoreConfig_INIT;
1294-
char *oldloc = NULL;
12951294
int res = -1;
1296-
1297-
oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
1298-
if (oldloc == NULL) {
1299-
pymain->err = _Py_INIT_NO_MEMORY();
1300-
goto done;
1301-
}
1302-
1303-
/* Reconfigure the locale to the default for this process */
1304-
_Py_SetLocaleFromEnv(LC_ALL);
1305-
13061295
int locale_coerced = 0;
13071296
int loops = 0;
13081297

@@ -1311,6 +1300,9 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
13111300
goto done;
13121301
}
13131302

1303+
/* Set LC_CTYPE to the user preferred locale */
1304+
_Py_SetLocaleFromEnv(LC_CTYPE);
1305+
13141306
while (1) {
13151307
int utf8_mode = config->utf8_mode;
13161308
int encoding_changed = 0;
@@ -1392,10 +1384,6 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
13921384

13931385
done:
13941386
_PyCoreConfig_Clear(&save_config);
1395-
if (oldloc != NULL) {
1396-
setlocale(LC_ALL, oldloc);
1397-
PyMem_RawFree(oldloc);
1398-
}
13991387
Py_UTF8Mode = init_utf8_mode ;
14001388
#ifdef MS_WINDOWS
14011389
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;

0 commit comments

Comments
 (0)