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.
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index be144bf..df4725e 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -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;
}