Skip to content

Commit 89487f5

Browse files
authored
bpo-34207: Fix pymain_read_conf() for UTF-8 Mode (GH-8868)
bpo-34170, bpo-34207: pymain_read_conf() now sets Py_UTF8Mode to config->utf8_mode. pymain_read_conf() calls indirectly Py_DecodeLocale() and Py_EncodeLocale() which depend on Py_UTF8Mode.
1 parent ccd9975 commit 89487f5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Modules/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ static int
12861286
pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
12871287
_PyCmdline *cmdline)
12881288
{
1289+
int init_utf8_mode = Py_UTF8Mode;
12891290
_PyCoreConfig save_config = _PyCoreConfig_INIT;
12901291
char *oldloc = NULL;
12911292
int res = -1;
@@ -1319,6 +1320,10 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
13191320
goto done;
13201321
}
13211322

1323+
/* bpo-34207: Py_DecodeLocale(), Py_EncodeLocale() and similar
1324+
functions depend on Py_UTF8Mode. */
1325+
Py_UTF8Mode = config->utf8_mode;
1326+
13221327
if (pymain_init_cmdline_argv(pymain, config, cmdline) < 0) {
13231328
goto done;
13241329
}
@@ -1383,6 +1388,7 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
13831388
setlocale(LC_ALL, oldloc);
13841389
PyMem_RawFree(oldloc);
13851390
}
1391+
Py_UTF8Mode = init_utf8_mode ;
13861392
return res;
13871393
}
13881394

0 commit comments

Comments
 (0)