summaryrefslogtreecommitdiff
path: root/Python/preconfig.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-10 19:33:11 +0200
committerGitHub <noreply@github.com>2020-06-10 19:33:11 +0200
commit8eb4aea26297daf105108c4866d4c692bd8b81f9 (patch)
treec77362cb36d66e17b76d08bef69e8552744fa1af /Python/preconfig.c
parentf6e58aefde2e57e4cb11ea7743955da53a3f1e80 (diff)
downloadcpython-git-8eb4aea26297daf105108c4866d4c692bd8b81f9.tar.gz
_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.
Diffstat (limited to 'Python/preconfig.c')
-rw-r--r--Python/preconfig.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Python/preconfig.c b/Python/preconfig.c
index fd94d7dda1..149afcd99a 100644
--- a/Python/preconfig.c
+++ b/Python/preconfig.c
@@ -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;
@@ -846,7 +839,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
loops++;
if (loops == 3) {
status = _PyStatus_ERR("Encoding changed twice while "
- "reading the configuration");
+ "reading the configuration");
goto done;
}
@@ -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);