mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
bpo-42260: PyConfig_Read() only parses argv once (GH-23168)
The PyConfig_Read() function now only parses PyConfig.argv arguments once: PyConfig.parse_argv is set to 2 after arguments are parsed. Since Python arguments are strippped from PyConfig.argv, parsing arguments twice would parse the application options as Python options. * Rework the PyConfig documentation. * Fix _testinternalcapi.set_config() error handling. * SetConfigTests no longer needs parse_argv=0 when restoring the old configuration.
This commit is contained in:
parent
f3cb814315
commit
dc42af8fd1
6 changed files with 131 additions and 102 deletions
|
@ -1325,8 +1325,6 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
|
|||
GET_UINT(_init_main);
|
||||
GET_UINT(_isolated_interpreter);
|
||||
|
||||
assert(config_check_consistency(config));
|
||||
|
||||
#undef CHECK_VALUE
|
||||
#undef GET_UINT
|
||||
#undef GET_WSTR
|
||||
|
@ -2145,6 +2143,11 @@ config_read(PyConfig *config)
|
|||
config->configure_c_stdio = 1;
|
||||
}
|
||||
|
||||
// Only parse arguments once.
|
||||
if (config->parse_argv == 1) {
|
||||
config->parse_argv = 2;
|
||||
}
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
@ -2635,7 +2638,7 @@ core_read_precmdline(PyConfig *config, _PyPreCmdline *precmdline)
|
|||
{
|
||||
PyStatus status;
|
||||
|
||||
if (config->parse_argv) {
|
||||
if (config->parse_argv == 1) {
|
||||
if (_PyWideStringList_Copy(&precmdline->argv, &config->argv) < 0) {
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
|
@ -2713,7 +2716,7 @@ config_read_cmdline(PyConfig *config)
|
|||
}
|
||||
}
|
||||
|
||||
if (config->parse_argv) {
|
||||
if (config->parse_argv == 1) {
|
||||
Py_ssize_t opt_index;
|
||||
status = config_parse_cmdline(config, &cmdline_warnoptions, &opt_index);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue