summaryrefslogtreecommitdiffstats
path: root/Python/coreconfig.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-09-19 21:56:36 (GMT)
committerGitHub <noreply@github.com>2018-09-19 21:56:36 (GMT)
commit06e7608207daab9fb82d13ccf2d3664535442f11 (patch)
tree690da78834ebfbe2f3f0316972bfcbde97a67a8f /Python/coreconfig.c
parent76531e2e82319a487d659bc469441bd4b8251608 (diff)
downloadcpython-06e7608207daab9fb82d13ccf2d3664535442f11.zip
cpython-06e7608207daab9fb82d13ccf2d3664535442f11.tar.gz
cpython-06e7608207daab9fb82d13ccf2d3664535442f11.tar.bz2
Revert "bpo-34589: Add -X coerce_c_locale command line option (GH-9378)" (GH-9430)
* Revert "bpo-34589: Add -X coerce_c_locale command line option (GH-9378)" This reverts commit dbdee0073cf0b88fe541980ace1f650900f455cc. * Revert "bpo-34589: C locale coercion off by default (GH-9073)" This reverts commit 7a0791b6992d420dc52536257f2f093851ed7215. * Revert "bpo-34589: Make _PyCoreConfig.coerce_c_locale private (GH-9371)" This reverts commit 188ebfa475a6f6aa2d0ea14ca8e1fbe7865b6d27.
Diffstat (limited to 'Python/coreconfig.c')
-rw-r--r--Python/coreconfig.c129
1 files changed, 40 insertions, 89 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index b2459dc..fae32e5 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -303,8 +303,8 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
COPY_ATTR(dump_refs);
COPY_ATTR(malloc_stats);
- COPY_ATTR(_coerce_c_locale);
- COPY_ATTR(_coerce_c_locale_warn);
+ COPY_ATTR(coerce_c_locale);
+ COPY_ATTR(coerce_c_locale_warn);
COPY_ATTR(utf8_mode);
COPY_WSTR_ATTR(pycache_prefix);
@@ -705,17 +705,6 @@ config_init_utf8_mode(_PyCoreConfig *config)
return _Py_INIT_OK();
}
-#ifndef MS_WINDOWS
- /* The C locale and the POSIX locale enable the UTF-8 Mode (PEP 540) */
- const char *ctype_loc = setlocale(LC_CTYPE, NULL);
- if (ctype_loc != NULL
- && (strcmp(ctype_loc, "C") == 0 || strcmp(ctype_loc, "POSIX") == 0))
- {
- config->utf8_mode = 1;
- return _Py_INIT_OK();
- }
-#endif
-
return _Py_INIT_OK();
}
@@ -819,6 +808,23 @@ config_read_env_vars(_PyCoreConfig *config)
config->malloc_stats = 1;
}
+ const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
+ if (env) {
+ if (strcmp(env, "0") == 0) {
+ if (config->coerce_c_locale < 0) {
+ config->coerce_c_locale = 0;
+ }
+ }
+ else if (strcmp(env, "warn") == 0) {
+ config->coerce_c_locale_warn = 1;
+ }
+ else {
+ if (config->coerce_c_locale < 0) {
+ config->coerce_c_locale = 1;
+ }
+ }
+ }
+
wchar_t *path;
int res = _PyCoreConfig_GetEnvDup(config, &path,
L"PYTHONPATH", "PYTHONPATH");
@@ -958,76 +964,28 @@ config_read_complex_options(_PyCoreConfig *config)
}
-static _PyInitError
-config_init_coerce_c_locale(_PyCoreConfig *config)
+static void
+config_init_locale(_PyCoreConfig *config)
{
- const wchar_t *xopt = config_get_xoption(config, L"coerce_c_locale");
- if (xopt) {
- wchar_t *sep = wcschr(xopt, L'=');
- if (sep) {
- xopt = sep + 1;
- if (wcscmp(xopt, L"1") == 0) {
- if (config->_coerce_c_locale < 0) {
- config->_coerce_c_locale = 1;
- }
- }
- else if (wcscmp(xopt, L"0") == 0) {
- if (config->_coerce_c_locale < 0) {
- config->_coerce_c_locale = 0;
- }
- }
- else if (wcscmp(xopt, L"warn") == 0) {
- if (config->_coerce_c_locale_warn < 0) {
- config->_coerce_c_locale_warn = 1;
- }
- }
- else {
- return _Py_INIT_USER_ERR("invalid -X coerce_c_locale option value");
- }
- }
- else {
- if (config->_coerce_c_locale < 0) {
- config->_coerce_c_locale = 1;
- }
- }
-
- if (config->_coerce_c_locale_warn < 0) {
- config->_coerce_c_locale_warn = 0;
- }
- }
-
- const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
- if (env) {
- if (strcmp(env, "0") == 0) {
- if (config->_coerce_c_locale < 0) {
- config->_coerce_c_locale = 0;
- }
- }
- else if (strcmp(env, "warn") == 0) {
- if (config->_coerce_c_locale_warn < 0) {
- config->_coerce_c_locale_warn = 1;
- }
- }
- else {
- if (config->_coerce_c_locale < 0) {
- config->_coerce_c_locale = 1;
- }
- }
-
- if (config->_coerce_c_locale_warn < 0) {
- config->_coerce_c_locale_warn = 0;
- }
- }
-
- if (config->_coerce_c_locale < 0) {
+ if (config->coerce_c_locale < 0) {
/* The C locale enables the C locale coercion (PEP 538) */
if (_Py_LegacyLocaleDetected()) {
- config->_coerce_c_locale = 1;
- return _Py_INIT_OK();
+ config->coerce_c_locale = 1;
}
}
- return _Py_INIT_OK();
+#ifndef MS_WINDOWS
+ if (config->utf8_mode < 0) {
+ /* The C locale and the POSIX locale enable the UTF-8 Mode (PEP 540) */
+ const char *ctype_loc = setlocale(LC_CTYPE, NULL);
+ if (ctype_loc != NULL
+ && (strcmp(ctype_loc, "C") == 0
+ || strcmp(ctype_loc, "POSIX") == 0))
+ {
+ config->utf8_mode = 1;
+ }
+ }
+#endif
}
@@ -1333,11 +1291,8 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
}
}
- if (config->_coerce_c_locale < 0 || config->_coerce_c_locale_warn < 0) {
- err = config_init_coerce_c_locale(config);
- if (_Py_INIT_FAILED(err)) {
- return err;
- }
+ if (config->utf8_mode < 0 || config->coerce_c_locale < 0) {
+ config_init_locale(config);
}
if (config->_install_importlib) {
@@ -1366,11 +1321,8 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
if (config->tracemalloc < 0) {
config->tracemalloc = 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->coerce_c_locale < 0) {
+ config->coerce_c_locale = 0;
}
if (config->utf8_mode < 0) {
config->utf8_mode = 0;
@@ -1391,8 +1343,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
return err;
}
- assert(config->_coerce_c_locale >= 0);
- assert(config->_coerce_c_locale_warn >= 0);
+ assert(config->coerce_c_locale >= 0);
assert(config->use_environment >= 0);
assert(config->filesystem_encoding != NULL);
assert(config->filesystem_errors != NULL);