Commit 89487f51 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

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.
parent ccd99752
...@@ -1286,6 +1286,7 @@ static int ...@@ -1286,6 +1286,7 @@ static int
pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config, pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
_PyCmdline *cmdline) _PyCmdline *cmdline)
{ {
int init_utf8_mode = Py_UTF8Mode;
_PyCoreConfig save_config = _PyCoreConfig_INIT; _PyCoreConfig save_config = _PyCoreConfig_INIT;
char *oldloc = NULL; char *oldloc = NULL;
int res = -1; int res = -1;
...@@ -1319,6 +1320,10 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config, ...@@ -1319,6 +1320,10 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
goto done; goto done;
} }
/* bpo-34207: Py_DecodeLocale(), Py_EncodeLocale() and similar
functions depend on Py_UTF8Mode. */
Py_UTF8Mode = config->utf8_mode;
if (pymain_init_cmdline_argv(pymain, config, cmdline) < 0) { if (pymain_init_cmdline_argv(pymain, config, cmdline) < 0) {
goto done; goto done;
} }
...@@ -1383,6 +1388,7 @@ done: ...@@ -1383,6 +1388,7 @@ done:
setlocale(LC_ALL, oldloc); setlocale(LC_ALL, oldloc);
PyMem_RawFree(oldloc); PyMem_RawFree(oldloc);
} }
Py_UTF8Mode = init_utf8_mode ;
return res; return res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment