Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a953fd

Browse files
authored
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.
1 parent 7b41dba commit 5a953fd

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

Programs/_testembed.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ dump_config(void)
373373
printf("quiet = %i\n", config->quiet);
374374
printf("user_site_directory = %i\n", config->user_site_directory);
375375
printf("buffered_stdio = %i\n", config->buffered_stdio);
376+
ASSERT_EQUAL(config->buffered_stdio, !Py_UnbufferedStdioFlag);
377+
376378
/* FIXME: test legacy_windows_fs_encoding */
377379
/* FIXME: test legacy_windows_stdio */
378380

Python/coreconfig.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
367367
static _PyInitError
368368
config_init_program_name(_PyCoreConfig *config)
369369
{
370+
assert(config->program_name == NULL);
371+
370372
/* If Py_SetProgramName() was called, use its value */
371373
const wchar_t *program_name = _Py_path_config.program_name;
372374
if (program_name != NULL) {
@@ -665,16 +667,18 @@ config_read_env_vars(_PyCoreConfig *config)
665667
config->malloc_stats = 1;
666668
}
667669

668-
const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
669-
if (env) {
670-
if (strcmp(env, "0") == 0) {
671-
config->coerce_c_locale = 0;
672-
}
673-
else if (strcmp(env, "warn") == 0) {
674-
config->coerce_c_locale_warn = 1;
675-
}
676-
else {
677-
config->coerce_c_locale = 1;
670+
if (config->coerce_c_locale < 0) {
671+
const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
672+
if (env) {
673+
if (strcmp(env, "0") == 0) {
674+
config->coerce_c_locale = 0;
675+
}
676+
else if (strcmp(env, "warn") == 0) {
677+
config->coerce_c_locale_warn = 1;
678+
}
679+
else {
680+
config->coerce_c_locale = 1;
681+
}
678682
}
679683
}
680684

@@ -820,10 +824,6 @@ config_read_complex_options(_PyCoreConfig *config)
820824
static void
821825
config_init_locale(_PyCoreConfig *config)
822826
{
823-
if (config->utf8_mode >= 0 && config->coerce_c_locale >= 0) {
824-
return;
825-
}
826-
827827
if (_Py_LegacyLocaleDetected()) {
828828
/* POSIX locale: enable C locale coercion and UTF-8 Mode */
829829
if (config->utf8_mode < 0) {
@@ -832,7 +832,6 @@ config_init_locale(_PyCoreConfig *config)
832832
if (config->coerce_c_locale < 0) {
833833
config->coerce_c_locale = 1;
834834
}
835-
return;
836835
}
837836
}
838837

@@ -909,7 +908,9 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
909908
}
910909
}
911910

912-
config_init_locale(config);
911+
if (config->utf8_mode < 0 || config->coerce_c_locale < 0) {
912+
config_init_locale(config);
913+
}
913914

914915
if (config->_install_importlib) {
915916
err = _PyCoreConfig_InitPathConfig(config);

Python/pylifecycle.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ _Py_InitializeCore(PyInterpreterState **interp_p,
805805
{
806806
assert(src_config != NULL);
807807

808-
809808
PyMemAllocatorEx old_alloc;
810809
_PyInitError err;
811810

0 commit comments

Comments
 (0)