diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-09-17 23:22:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-17 23:22:29 (GMT) |
commit | 7a0791b6992d420dc52536257f2f093851ed7215 (patch) | |
tree | d41edd6bc79c92232213480fc853dd86530780bf /Modules/main.c | |
parent | 1fa2ec49bec50bea1847b558b883c5c904334734 (diff) | |
download | cpython-7a0791b6992d420dc52536257f2f093851ed7215.zip cpython-7a0791b6992d420dc52536257f2f093851ed7215.tar.gz cpython-7a0791b6992d420dc52536257f2f093851ed7215.tar.bz2 |
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.
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 29 |
1 files changed, 24 insertions, 5 deletions
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 @@ pymain_cmdline(_PyMain *pymain, _PyCoreConfig *config) 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 @@ pymain_init(_PyMain *pymain, PyInterpreterState **interp_p) _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 @@ pymain_init(_PyMain *pymain, PyInterpreterState **interp_p) 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 @@ Py_Main(int argc, wchar_t **argv) 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 @@ _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 |