diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-17-12-59-18.gh-issue-94526.k6c3hr.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-17-12-59-18.gh-issue-94526.k6c3hr.rst new file mode 100644 index 00000000000000..7271f06347e691 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-17-12-59-18.gh-issue-94526.k6c3hr.rst @@ -0,0 +1 @@ +Force ``utf8`` encoding in ``_bootstrap_python`` to fix compilation under path containing non-ascii characters. Patch by Kumar Aditya. diff --git a/Programs/_bootstrap_python.c b/Programs/_bootstrap_python.c index 6ecbf0c72b5ff4..042259007042e3 100644 --- a/Programs/_bootstrap_python.c +++ b/Programs/_bootstrap_python.c @@ -63,6 +63,17 @@ main(int argc, char **argv) { PyStatus status; + PyPreConfig preconfig; + PyPreConfig_InitIsolatedConfig(&preconfig); + // To keep code simple, pre-initialization doesn't parse argv. + // It ignores -E, -I and -X dev command line options etc. + // Force utf8 encoding + preconfig.utf8_mode = 1; + status = Py_PreInitialize(&preconfig); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); + } + PyConfig config; PyConfig_InitIsolatedConfig(&config); // don't warn, pybuilddir.txt does not exist yet