variable. The option is also enabled if the LC_CTYPE locale is "C"
and a target locale (ex: "C.UTF-8") is supported by the platform.
+ Py_Initialize() and Py_Main() must not enable C locale coercion: it is
+ always disabled. The option can only be enabled by the Python program
+ ("python3).
+
See also the _coerce_c_locale_warn option. */
int _coerce_c_locale;
Enabled by the PYTHONCOERCECLOCALE=warn environment variable.
+ Py_Initialize() and Py_Main() must not enable C locale coercion warning:
+ it is always disabled. The warning can only be enabled by the Python
+ program ("python3).
+
See also the _coerce_c_locale option. */
int _coerce_c_locale_warn;
.use_hash_seed = -1, \
.faulthandler = -1, \
.tracemalloc = -1, \
- ._coerce_c_locale = -1, \
+ ._coerce_c_locale = 0, \
+ ._coerce_c_locale_warn = 0, \
.utf8_mode = -1, \
.argc = -1, \
.nmodule_search_path = -1, \
/* Bootstrap __main__ (defined in Modules/main.c) */
PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
#ifdef Py_BUILD_CORE
+# ifdef MS_WINDOWS
+PyAPI_FUNC(int) _Py_WindowsMain(int argc, wchar_t **argv);
+# else
PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
+# endif
#endif
/* In getpath.c */
'print(sys.getfilesystemencoding(), '
'sys.getfilesystemencodeerrors())')
args = (sys.executable, '-c', code)
- env = dict(env)
- if not isolated:
- env['PYTHONCOERCECLOCALE'] = '0'
- env['PYTHONUTF8'] = '0'
proc = subprocess.run(args, text=True, env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
--- /dev/null
+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).
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,
_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);
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);
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)
{
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
putenv("PYTHONMALLOCSTATS=0");
config.malloc_stats = 1;
- /* FIXME: test _coerce_c_locale and _coerce_c_locale_warn */
-
putenv("PYTHONUTF8=0");
Py_UTF8Mode = 0;
config.utf8_mode = 1;
/* Test _PyCoreConfig.isolated=1 */
_PyCoreConfig config = _PyCoreConfig_INIT;
- /* Set _coerce_c_locale and utf8_mode to not depend on the locale */
- config._coerce_c_locale = 0;
+ /* Set utf8_mode to not depend on the locale */
config.utf8_mode = 0;
/* Use path starting with "./" avoids a search along the PATH */
config.program_name = L"./_testembed";
int
wmain(int argc, wchar_t **argv)
{
- return Py_Main(argc, argv);
+ return _Py_WindowsMain(argc, argv);
}
#else
int
}
}
else if (strcmp(env, "warn") == 0) {
- config->_coerce_c_locale_warn = 1;
+ if (config->_coerce_c_locale_warn < 0) {
+ config->_coerce_c_locale_warn = 1;
+ }
}
else {
if (config->_coerce_c_locale < 0) {
if (config->_coerce_c_locale < 0) {
config->_coerce_c_locale = 0;
}
+ if (config->_coerce_c_locale_warn < 0) {
+ config->_coerce_c_locale_warn = 0;
+ }
if (config->utf8_mode < 0) {
config->utf8_mode = 0;
}