[Python-checkins] bpo-34170: _PyCoreConfig_Read() don't replace coerce_c_locale (GH-8658)

Victor Stinner webhook-mailer at python.org
Fri Aug 3 16:49:10 EDT 2018


https://github.com/python/cpython/commit/5a953fd0ab4d0f792f4c1537616b2ce8ee40d976
commit: 5a953fd0ab4d0f792f4c1537616b2ce8ee40d976
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-08-03T22:49:07+02:00
summary:

bpo-34170: _PyCoreConfig_Read() don't replace coerce_c_locale (GH-8658)

If coerce_c_locale is already set (>= 0), use its value: don't
override it.

files:
M Programs/_testembed.c
M Python/coreconfig.c
M Python/pylifecycle.c

diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 027de484545f..f1d30f6c54dd 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -373,6 +373,8 @@ dump_config(void)
     printf("quiet = %i\n", config->quiet);
     printf("user_site_directory = %i\n", config->user_site_directory);
     printf("buffered_stdio = %i\n", config->buffered_stdio);
+    ASSERT_EQUAL(config->buffered_stdio, !Py_UnbufferedStdioFlag);
+
     /* FIXME: test legacy_windows_fs_encoding */
     /* FIXME: test legacy_windows_stdio */
 
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index 829592c3c9b2..1a32525b7b31 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -367,6 +367,8 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
 static _PyInitError
 config_init_program_name(_PyCoreConfig *config)
 {
+    assert(config->program_name == NULL);
+
     /* If Py_SetProgramName() was called, use its value */
     const wchar_t *program_name = _Py_path_config.program_name;
     if (program_name != NULL) {
@@ -665,16 +667,18 @@ config_read_env_vars(_PyCoreConfig *config)
         config->malloc_stats = 1;
     }
 
-    const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
-    if (env) {
-        if (strcmp(env, "0") == 0) {
-            config->coerce_c_locale = 0;
-        }
-        else if (strcmp(env, "warn") == 0) {
-            config->coerce_c_locale_warn = 1;
-        }
-        else {
-            config->coerce_c_locale = 1;
+    if (config->coerce_c_locale < 0) {
+        const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
+        if (env) {
+            if (strcmp(env, "0") == 0) {
+                config->coerce_c_locale = 0;
+            }
+            else if (strcmp(env, "warn") == 0) {
+                config->coerce_c_locale_warn = 1;
+            }
+            else {
+                config->coerce_c_locale = 1;
+            }
         }
     }
 
@@ -820,10 +824,6 @@ config_read_complex_options(_PyCoreConfig *config)
 static void
 config_init_locale(_PyCoreConfig *config)
 {
-    if (config->utf8_mode >= 0 && config->coerce_c_locale >= 0) {
-        return;
-    }
-
     if (_Py_LegacyLocaleDetected()) {
         /* POSIX locale: enable C locale coercion and UTF-8 Mode */
         if (config->utf8_mode < 0) {
@@ -832,7 +832,6 @@ config_init_locale(_PyCoreConfig *config)
         if (config->coerce_c_locale < 0) {
             config->coerce_c_locale = 1;
         }
-        return;
     }
 }
 
@@ -909,7 +908,9 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
         }
     }
 
-    config_init_locale(config);
+    if (config->utf8_mode < 0 || config->coerce_c_locale < 0) {
+        config_init_locale(config);
+    }
 
     if (config->_install_importlib) {
         err = _PyCoreConfig_InitPathConfig(config);
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index c2ee4ffc4681..28704c1c228b 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -805,7 +805,6 @@ _Py_InitializeCore(PyInterpreterState **interp_p,
 {
     assert(src_config != NULL);
 
-
     PyMemAllocatorEx old_alloc;
     _PyInitError err;
 



More information about the Python-checkins mailing list