Skip to content

bpo-34544: pymain_read_conf() don't change LC_ALL #9045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,18 +1291,7 @@ 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;

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;

Expand All @@ -1311,6 +1300,9 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
goto done;
}

/* Set LC_CTYPE to the user preferred locale */
_Py_SetLocaleFromEnv(LC_CTYPE);

while (1) {
int utf8_mode = config->utf8_mode;
int encoding_changed = 0;
Expand Down Expand Up @@ -1392,10 +1384,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 ;
#ifdef MS_WINDOWS
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;
Expand Down