Skip to content

Commit 80a0eba

Browse files
authored
bpo-34207: Fix pymain_read_conf() for UTF-8 Mode (GH-8868) (GH-8870)
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. (cherry picked from commit 89487f5)
1 parent 0420826 commit 80a0eba

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Modules/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,7 @@ pymain_read_conf_impl(_PyMain *pymain, _Py_CommandLineDetails *cmdline)
19821982
static int
19831983
pymain_read_conf(_PyMain *pymain, _Py_CommandLineDetails *cmdline)
19841984
{
1985+
int init_utf8_mode = Py_UTF8Mode;
19851986
_PyCoreConfig *config = &pymain->config;
19861987
_PyCoreConfig save_config = _PyCoreConfig_INIT;
19871988
int res = -1;
@@ -2016,6 +2017,10 @@ pymain_read_conf(_PyMain *pymain, _Py_CommandLineDetails *cmdline)
20162017
goto done;
20172018
}
20182019

2020+
/* bpo-34207: Py_DecodeLocale(), Py_EncodeLocale() and similar
2021+
functions depend on Py_UTF8Mode. */
2022+
Py_UTF8Mode = config->utf8_mode;
2023+
20192024
if (pymain_init_cmdline_argv(pymain, cmdline) < 0) {
20202025
goto done;
20212026
}
@@ -2086,7 +2091,7 @@ pymain_read_conf(_PyMain *pymain, _Py_CommandLineDetails *cmdline)
20862091
setlocale(LC_ALL, oldloc);
20872092
PyMem_RawFree(oldloc);
20882093
}
2089-
2094+
Py_UTF8Mode = init_utf8_mode ;
20902095
return res;
20912096
}
20922097

0 commit comments

Comments
 (0)