| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1beb7c3 commit 120b707
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,8 @@ extern PyStatus _PySys_Create( | |||
| 43 | 43 | PyThreadState *tstate, | |
| 44 | 44 | PyObject **sysmod_p); | |
| 45 | 45 | extern PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict); | |
| 46 | + extern PyStatus _PySys_ReadPreinitWarnOptions(PyConfig *config); | ||
| 47 | + extern PyStatus _PySys_ReadPreinitXOptions(PyConfig *config); | ||
| 46 | 48 | extern int _PySys_InitMain( | |
| 47 | 49 | _PyRuntimeState *runtime, | |
| 48 | 50 | PyThreadState *tstate); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -902,6 +902,23 @@ def modify_path(path): | |||
| 902 | 902 | api=API_PYTHON, | |
| 903 | 903 | modify_path_cb=modify_path) | |
| 904 | 904 | ||
| 905 | + def test_init_sys_add(self): | ||
| 906 | + config = { | ||
| 907 | + 'faulthandler': 1, | ||
| 908 | + 'xoptions': [ | ||
| 909 | + 'config_xoption', | ||
| 910 | + 'cmdline_xoption', | ||
| 911 | + 'sysadd_xoption', | ||
| 912 | + 'faulthandler', | ||
| 913 | + ], | ||
| 914 | + 'warnoptions': [ | ||
| 915 | + 'ignore:::config_warnoption', | ||
| 916 | + 'ignore:::cmdline_warnoption', | ||
| 917 | + 'ignore:::sysadd_warnoption', | ||
| 918 | + ], | ||
| 919 | + } | ||
| 920 | + self.check_all_configs("test_init_sys_add", config, api=API_PYTHON) | ||
| 921 | + | ||
| 905 | 922 | def test_init_run_main(self): | |
| 906 | 923 | code = ('import _testinternalcapi, json; ' | |
| 907 | 924 | 'print(json.dumps(_testinternalcapi.get_configs()))') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Options added by ``PySys_AddXOption()`` are now handled the same way than | ||
| 2 | + ``PyConfig.xoptions`` and command line ``-X`` options. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1375,6 +1375,54 @@ static int test_init_read_set(void) | |||
| 1375 | 1375 | } | |
| 1376 | 1376 | ||
| 1377 | 1377 | ||
| 1378 | + static int test_init_sys_add(void) | ||
| 1379 | + { | ||
| 1380 | + PySys_AddXOption(L"sysadd_xoption"); | ||
| 1381 | + PySys_AddXOption(L"faulthandler"); | ||
| 1382 | + PySys_AddWarnOption(L"ignore:::sysadd_warnoption"); | ||
| 1383 | + | ||
| 1384 | + PyConfig config; | ||
| 1385 | + PyStatus status; | ||
| 1386 | + status = PyConfig_InitPythonConfig(&config); | ||
| 1387 | + if (PyStatus_Exception(status)) { | ||
| 1388 | + goto fail; | ||
| 1389 | + } | ||
| 1390 | + | ||
| 1391 | + wchar_t* argv[] = { | ||
| 1392 | + L"python3", | ||
| 1393 | + L"-W", | ||
| 1394 | + L"ignore:::cmdline_warnoption", | ||
| 1395 | + L"-X", | ||
| 1396 | + L"cmdline_xoption", | ||
| 1397 | + }; | ||
| 1398 | + config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); | ||
| 1399 | + config.parse_argv = 1; | ||
| 1400 | + | ||
| 1401 | + status = PyWideStringList_Append(&config.xoptions, | ||
| 1402 | + L"config_xoption"); | ||
| 1403 | + if (PyStatus_Exception(status)) { | ||
| 1404 | + goto fail; | ||
| 1405 | + } | ||
| 1406 | + | ||
| 1407 | + status = PyWideStringList_Append(&config.warnoptions, | ||
| 1408 | + L"ignore:::config_warnoption"); | ||
| 1409 | + if (PyStatus_Exception(status)) { | ||
| 1410 | + goto fail; | ||
| 1411 | + } | ||
| 1412 | + | ||
| 1413 | + config_set_program_name(&config); | ||
| 1414 | + init_from_config_clear(&config); | ||
| 1415 | + | ||
| 1416 | + dump_config(); | ||
| 1417 | + Py_Finalize(); | ||
| 1418 | + return 0; | ||
| 1419 | + | ||
| 1420 | + fail: | ||
| 1421 | + PyConfig_Clear(&config); | ||
| 1422 | + Py_ExitStatusException(status); | ||
| 1423 | + } | ||
| 1424 | + | ||
| 1425 | + | ||
| 1378 | 1426 | static void configure_init_main(PyConfig *config) | |
| 1379 | 1427 | { | |
| 1380 | 1428 | wchar_t* argv[] = { | |
@@ -1510,6 +1558,7 @@ static struct TestCase TestCases[] = { | |||
| 1510 | 1558 | {"test_init_read_set", test_init_read_set}, | |
| 1511 | 1559 | {"test_init_run_main", test_init_run_main}, | |
| 1512 | 1560 | {"test_init_main", test_init_main}, | |
| 1561 | + {"test_init_sys_add", test_init_sys_add}, | ||
| 1513 | 1562 | {"test_run_main", test_run_main}, | |
| 1514 | 1563 | {"test_open_code_hook", test_open_code_hook}, | |
| 1515 | 1564 | {"test_audit", test_audit}, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2069,6 +2069,7 @@ config_init_warnoptions(PyConfig *config, | |||
| 2069 | 2069 | /* The priority order for warnings configuration is (highest precedence | |
| 2070 | 2070 | * first): | |
| 2071 | 2071 | * | |
| 2072 | + * - early PySys_AddWarnOption() calls | ||
| 2072 | 2073 | * - the BytesWarning filter, if needed ('-b', '-bb') | |
| 2073 | 2074 | * - any '-W' command line options; then | |
| 2074 | 2075 | * - the 'PYTHONWARNINGS' environment variable; then | |
@@ -2124,6 +2125,13 @@ config_init_warnoptions(PyConfig *config, | |||
| 2124 | 2125 | return status; | |
| 2125 | 2126 | } | |
| 2126 | 2127 | } | |
| 2128 | + | ||
| 2129 | + /* Handle early PySys_AddWarnOption() calls */ | ||
| 2130 | + status = _PySys_ReadPreinitWarnOptions(config); | ||
| 2131 | + if (_PyStatus_EXCEPTION(status)) { | ||
| 2132 | + return status; | ||
| 2133 | + } | ||
| 2134 | + | ||
| 2127 | 2135 | return _PyStatus_OK(); | |
| 2128 | 2136 | } | |
| 2129 | 2137 | ||
@@ -2293,7 +2301,8 @@ config_read_cmdline(PyConfig *config) | |||
| 2293 | 2301 | } | |
| 2294 | 2302 | ||
| 2295 | 2303 | status = config_init_warnoptions(config, | |
| 2296 | - &cmdline_warnoptions, &env_warnoptions); | ||
| 2304 | + &cmdline_warnoptions, | ||
| 2305 | + &env_warnoptions); | ||
| 2297 | 2306 | if (_PyStatus_EXCEPTION(status)) { | |
| 2298 | 2307 | goto done; | |
| 2299 | 2308 | } | |
@@ -2403,6 +2412,12 @@ PyConfig_Read(PyConfig *config) | |||
| 2403 | 2412 | goto done; | |
| 2404 | 2413 | } | |
| 2405 | 2414 | ||
| 2415 | + /* Handle early PySys_AddXOption() calls */ | ||
| 2416 | + status = _PySys_ReadPreinitXOptions(config); | ||
| 2417 | + if (_PyStatus_EXCEPTION(status)) { | ||
| 2418 | + goto done; | ||
| 2419 | + } | ||
| 2420 | + | ||
| 2406 | 2421 | status = config_read(config); | |
| 2407 | 2422 | if (_PyStatus_EXCEPTION(status)) { | |
| 2408 | 2423 | goto done; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2037,36 +2037,43 @@ _clear_preinit_entries(_Py_PreInitEntry *optionlist) | |||
| 2037 | 2037 | PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); | |
| 2038 | 2038 | } | |
| 2039 | 2039 | ||
| 2040 | - static void | ||
| 2041 | - _clear_all_preinit_options(void) | ||
| 2040 | + | ||
| 2041 | + PyStatus | ||
| 2042 | + _PySys_ReadPreinitWarnOptions(PyConfig *config) | ||
| 2042 | 2043 | { | |
| 2044 | + PyStatus status; | ||
| 2045 | + _Py_PreInitEntry entry; | ||
| 2046 | + | ||
| 2047 | + for (entry = _preinit_warnoptions; entry != NULL; entry = entry->next) { | ||
| 2048 | + status = PyWideStringList_Append(&config->warnoptions, entry->value); | ||
| 2049 | + if (_PyStatus_EXCEPTION(status)) { | ||
| 2050 | + return status; | ||
| 2051 | + } | ||
| 2052 | + } | ||
| 2053 | + | ||
| 2043 | 2054 | _clear_preinit_entries(&_preinit_warnoptions); | |
| 2044 | - _clear_preinit_entries(&_preinit_xoptions); | ||
| 2055 | + return _PyStatus_OK(); | ||
| 2045 | 2056 | } | |
| 2046 | 2057 | ||
| 2047 | - static int | ||
| 2048 | - sys_read_preinit_options(PyThreadState *tstate) | ||
| 2058 | + | ||
| 2059 | + PyStatus | ||
| 2060 | + _PySys_ReadPreinitXOptions(PyConfig *config) | ||
| 2049 | 2061 | { | |
| 2050 | - /* Rerun the add commands with the actual sys module available */ | ||
| 2051 | - if (tstate == NULL) { | ||
| 2052 | - /* Still don't have a thread state, so something is wrong! */ | ||
| 2053 | - return -1; | ||
| 2054 | - } | ||
| 2055 | - _Py_PreInitEntry entry = _preinit_warnoptions; | ||
| 2056 | - while (entry != NULL) { | ||
| 2057 | - PySys_AddWarnOption(entry->value); | ||
| 2058 | - entry = entry->next; | ||
| 2059 | - } | ||
| 2060 | - entry = _preinit_xoptions; | ||
| 2061 | - while (entry != NULL) { | ||
| 2062 | - PySys_AddXOption(entry->value); | ||
| 2063 | - entry = entry->next; | ||
| 2062 | + PyStatus status; | ||
| 2063 | + _Py_PreInitEntry entry; | ||
| 2064 | + | ||
| 2065 | + for (entry = _preinit_xoptions; entry != NULL; entry = entry->next) { | ||
| 2066 | + status = PyWideStringList_Append(&config->xoptions, entry->value); | ||
| 2067 | + if (_PyStatus_EXCEPTION(status)) { | ||
| 2068 | + return status; | ||
| 2069 | + } | ||
| 2064 | 2070 | } | |
| 2065 | 2071 | ||
| 2066 | - _clear_all_preinit_options(); | ||
| 2067 | - return 0; | ||
| 2072 | + _clear_preinit_entries(&_preinit_xoptions); | ||
| 2073 | + return _PyStatus_OK(); | ||
| 2068 | 2074 | } | |
| 2069 | 2075 | ||
| 2076 | + | ||
| 2070 | 2077 | static PyObject * | |
| 2071 | 2078 | get_warnoptions(PyThreadState *tstate) | |
| 2072 | 2079 | { | |
@@ -2235,9 +2242,7 @@ PySys_AddXOption(const wchar_t *s) | |||
| 2235 | 2242 | } | |
| 2236 | 2243 | if (_PySys_AddXOptionWithError(s) < 0) { | |
| 2237 | 2244 | /* No return value, therefore clear error state if possible */ | |
| 2238 | - if (tstate) { | ||
| 2239 | - _PyErr_Clear(tstate); | ||
| 2240 | - } | ||
| 2245 | + _PyErr_Clear(tstate); | ||
| 2241 | 2246 | } | |
| 2242 | 2247 | } | |
| 2243 | 2248 | ||
@@ -2898,11 +2903,6 @@ _PySys_InitMain(_PyRuntimeState *runtime, PyThreadState *tstate) | |||
| 2898 | 2903 | if (get_xoptions(tstate) == NULL) | |
| 2899 | 2904 | return -1; | |
| 2900 | 2905 | ||
| 2901 | - /* Transfer any sys.warnoptions and sys._xoptions set directly | ||
| 2902 | - * by an embedding application from the linked list to the module. */ | ||
| 2903 | - if (sys_read_preinit_options(tstate) != 0) | ||
| 2904 | - return -1; | ||
| 2905 | - | ||
| 2906 | 2906 | if (_PyErr_Occurred(tstate)) { | |
| 2907 | 2907 | goto err_occurred; | |
| 2908 | 2908 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments