_PyPreConfig_Read() decodes argv at each iteration (GH-20786)

_PyPreConfig_Read() now calls _PyPreCmdline_SetArgv() at each
iteration, so bytes strings are decoded from the new encoding.
This commit is contained in:
Victor Stinner 2020-06-10 19:33:11 +02:00 committed by GitHub
parent f6e58aefde
commit 8eb4aea262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -829,13 +829,6 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag;
#endif
if (args) {
status = _PyPreCmdline_SetArgv(&cmdline, args);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
}
int locale_coerced = 0;
int loops = 0;
@ -857,6 +850,15 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding;
#endif
if (args) {
// Set command line arguments at each iteration. If they are bytes
// strings, they are decoded from the new encoding.
status = _PyPreCmdline_SetArgv(&cmdline, args);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
}
status = preconfig_read(config, &cmdline);
if (_PyStatus_EXCEPTION(status)) {
goto done;
@ -896,7 +898,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
}
/* Reset the configuration before reading again the configuration,
just keep UTF-8 Mode value. */
just keep UTF-8 Mode and coerce C locale value. */
int new_utf8_mode = config->utf8_mode;
int new_coerce_c_locale = config->coerce_c_locale;
preconfig_copy(config, &save_config);