bpo-36763: PyConfig_Read() handles PySys_AddXOption() (GH-15431) (GH-15435)
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.
(cherry picked from commit 120b707a6d43452e067daa55a8fdca69f9424abc)
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 @@
}
+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 @@
{"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},