diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-08-23 17:03:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-23 17:03:08 (GMT) |
commit | 120b707a6d43452e067daa55a8fdca69f9424abc (patch) | |
tree | 1a58f651b55fde0a820646fdbf8b568657883273 /Programs | |
parent | 1beb7c3de9c3d0e802e4267a11d937e8f024d661 (diff) | |
download | cpython-120b707a6d43452e067daa55a8fdca69f9424abc.zip cpython-120b707a6d43452e067daa55a8fdca69f9424abc.tar.gz cpython-120b707a6d43452e067daa55a8fdca69f9424abc.tar.bz2 |
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.
Diffstat (limited to 'Programs')
-rw-r--r-- | Programs/_testembed.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 3873009..c3ccc0e 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1375,6 +1375,54 @@ fail: } +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}, |