@@ -367,6 +367,8 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
367367static _PyInitError
368368config_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)
820824static void
821825config_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 );
0 commit comments