@@ -829,13 +829,6 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
829
829
int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag ;
830
830
#endif
831
831
832
- if (args ) {
833
- status = _PyPreCmdline_SetArgv (& cmdline , args );
834
- if (_PyStatus_EXCEPTION (status )) {
835
- goto done ;
836
- }
837
- }
838
-
839
832
int locale_coerced = 0 ;
840
833
int loops = 0 ;
841
834
@@ -846,7 +839,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
846
839
loops ++ ;
847
840
if (loops == 3 ) {
848
841
status = _PyStatus_ERR ("Encoding changed twice while "
849
- "reading the configuration" );
842
+ "reading the configuration" );
850
843
goto done ;
851
844
}
852
845
@@ -857,6 +850,15 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
857
850
Py_LegacyWindowsFSEncodingFlag = config -> legacy_windows_fs_encoding ;
858
851
#endif
859
852
853
+ if (args ) {
854
+ // Set command line arguments at each iteration. If they are bytes
855
+ // strings, they are decoded from the new encoding.
856
+ status = _PyPreCmdline_SetArgv (& cmdline , args );
857
+ if (_PyStatus_EXCEPTION (status )) {
858
+ goto done ;
859
+ }
860
+ }
861
+
860
862
status = preconfig_read (config , & cmdline );
861
863
if (_PyStatus_EXCEPTION (status )) {
862
864
goto done ;
@@ -896,7 +898,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
896
898
}
897
899
898
900
/* Reset the configuration before reading again the configuration,
899
- just keep UTF-8 Mode value. */
901
+ just keep UTF-8 Mode and coerce C locale value. */
900
902
int new_utf8_mode = config -> utf8_mode ;
901
903
int new_coerce_c_locale = config -> coerce_c_locale ;
902
904
preconfig_copy (config , & save_config );
0 commit comments