bpo-34523: Fix C locale coercion on FreeBSD CURRENT (GH-10672)
bpo-34523, bpo-35290: C locale coercion now resets the Python
internal "force ASCII" mode. This change fix the filesystem encoding
on FreeBSD CURRENT, which has a new "C.UTF-8" locale, when
the UTF-8 mode is disabled.
Add _Py_ResetForceASCII(): _Py_SetLocaleFromEnv() now calls it.
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index af3d5ef..6de32de 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -5,6 +5,7 @@
#include "Python-ast.h"
#undef Yield /* undefine macro conflicting with <winbase.h> */
#include "pycore_context.h"
+#include "pycore_fileutils.h"
#include "pycore_hamt.h"
#include "pycore_pathconfig.h"
#include "pycore_pylifecycle.h"
@@ -394,6 +395,7 @@
char *
_Py_SetLocaleFromEnv(int category)
{
+ char *res;
#ifdef __ANDROID__
const char *locale;
const char **pvar;
@@ -440,10 +442,12 @@
}
}
#endif
- return setlocale(category, utf8_locale);
-#else /* __ANDROID__ */
- return setlocale(category, "");
-#endif /* __ANDROID__ */
+ res = setlocale(category, utf8_locale);
+#else /* !defined(__ANDROID__) */
+ res = setlocale(category, "");
+#endif
+ _Py_ResetForceASCII();
+ return res;
}