bpo-34589: C locale coercion off by default (GH-9073)
Py_Initialize() and Py_Main() cannot enable the C locale coercion
(PEP 538) anymore: it is always disabled. It can now only be enabled
by the Python program ("python3).
test_embed: get_filesystem_encoding() doesn't have to set PYTHONUTF8
nor PYTHONCOERCECLOCALE, these variables are already set in the
parent.
diff --git a/Modules/main.c b/Modules/main.c
index 6bc2917..d4ae4a0 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -1700,7 +1700,8 @@
static int
-pymain_init(_PyMain *pymain, PyInterpreterState **interp_p)
+pymain_init(_PyMain *pymain, PyInterpreterState **interp_p,
+ int use_c_locale_coercion)
{
/* 754 requires that FP exceptions run in "no stop" mode by default,
* and until C vendors implement C99's ways to control FP exceptions,
@@ -1713,6 +1714,11 @@
_PyCoreConfig local_config = _PyCoreConfig_INIT;
_PyCoreConfig *config = &local_config;
+ if (use_c_locale_coercion) {
+ /* set to -1 to be able to enable the feature */
+ config->_coerce_c_locale = -1;
+ config->_coerce_c_locale_warn = -1;
+ }
_PyCoreConfig_GetGlobalConfig(config);
@@ -1747,10 +1753,10 @@
static int
-pymain_main(_PyMain *pymain)
+pymain_main(_PyMain *pymain, int use_c_locale_coercion)
{
PyInterpreterState *interp;
- int res = pymain_init(pymain, &interp);
+ int res = pymain_init(pymain, &interp, use_c_locale_coercion);
if (res != 1) {
if (pymain_run_python(pymain, interp) < 0) {
_Py_FatalInitError(pymain->err);
@@ -1777,10 +1783,22 @@
pymain.argc = argc;
pymain.wchar_argv = argv;
- return pymain_main(&pymain);
+ return pymain_main(&pymain, 0);
}
+#ifdef MS_WINDOWS
+int
+_Py_WindowsMain(int argc, wchar_t **argv)
+{
+ _PyMain pymain = _PyMain_INIT;
+ pymain.use_bytes_argv = 0;
+ pymain.argc = argc;
+ pymain.wchar_argv = argv;
+
+ return pymain_main(&pymain, 1);
+}
+#else
int
_Py_UnixMain(int argc, char **argv)
{
@@ -1789,8 +1807,9 @@
pymain.argc = argc;
pymain.bytes_argv = argv;
- return pymain_main(&pymain);
+ return pymain_main(&pymain, 1);
}
+#endif
/* this is gonna seem *real weird*, but if you put some other code between