bpo-36763: PyConfig_Read() handles PySys_AddXOption() (GH-15431)

PyConfig_Read() is now responsible to handle early calls to
PySys_AddXOption() and PySys_AddWarnOption().

Options added by PySys_AddXOption() are now handled the same way than
PyConfig.xoptions and command line -X options.

For example, PySys_AddXOption(L"faulthandler") enables faulthandler
as expected.
This commit is contained in:
Victor Stinner 2019-08-23 18:03:08 +01:00 committed by GitHub
parent 1beb7c3de9
commit 120b707a6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 115 additions and 30 deletions

View file

@ -1375,6 +1375,54 @@ static int test_init_read_set(void)
}
static int test_init_sys_add(void)
{
PySys_AddXOption(L"sysadd_xoption");
PySys_AddXOption(L"faulthandler");
PySys_AddWarnOption(L"ignore:::sysadd_warnoption");
PyConfig config;
PyStatus status;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
goto fail;
}
wchar_t* argv[] = {
L"python3",
L"-W",
L"ignore:::cmdline_warnoption",
L"-X",
L"cmdline_xoption",
};
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config.parse_argv = 1;
status = PyWideStringList_Append(&config.xoptions,
L"config_xoption");
if (PyStatus_Exception(status)) {
goto fail;
}
status = PyWideStringList_Append(&config.warnoptions,
L"ignore:::config_warnoption");
if (PyStatus_Exception(status)) {
goto fail;
}
config_set_program_name(&config);
init_from_config_clear(&config);
dump_config();
Py_Finalize();
return 0;
fail:
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
static void configure_init_main(PyConfig *config)
{
wchar_t* argv[] = {
@ -1510,6 +1558,7 @@ static struct TestCase TestCases[] = {
{"test_init_read_set", test_init_read_set},
{"test_init_run_main", test_init_run_main},
{"test_init_main", test_init_main},
{"test_init_sys_add", test_init_sys_add},
{"test_run_main", test_run_main},
{"test_open_code_hook", test_open_code_hook},
{"test_audit", test_audit},