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:
Victor Stinner 2020-11-05 18:58:07 +01:00 committed by GitHub
parent f3cb814315
commit dc42af8fd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 131 additions and 102 deletions

View file

@ -253,14 +253,17 @@ test_set_config(PyObject *Py_UNUSED(self), PyObject *dict)
PyConfig config;
PyConfig_InitIsolatedConfig(&config);
if (_PyConfig_FromDict(&config, dict) < 0) {
PyConfig_Clear(&config);
return NULL;
goto error;
}
if (_PyInterpreterState_SetConfig(&config) < 0) {
return NULL;
goto error;
}
PyConfig_Clear(&config);
Py_RETURN_NONE;
error:
PyConfig_Clear(&config);
return NULL;
}