diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-08-23 19:16:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-23 19:16:51 (GMT) |
commit | af84a88ef8b3288da528d2f52b7d3fbafb8dc8a6 (patch) | |
tree | b9f0a48a09eb7783ee3b35e9f2381ea2f791b9d9 /Python/sysmodule.c | |
parent | 3921d12174c1998d9df7a08d036a7fef2d587a64 (diff) | |
download | cpython-af84a88ef8b3288da528d2f52b7d3fbafb8dc8a6.zip cpython-af84a88ef8b3288da528d2f52b7d3fbafb8dc8a6.tar.gz cpython-af84a88ef8b3288da528d2f52b7d3fbafb8dc8a6.tar.bz2 |
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)
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 577b6fb..93ffce2 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2071,37 +2071,43 @@ _clear_preinit_entries(_Py_PreInitEntry *optionlist) PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } -static void -_clear_all_preinit_options(void) + +PyStatus +_PySys_ReadPreinitWarnOptions(PyConfig *config) { + PyStatus status; + _Py_PreInitEntry entry; + + for (entry = _preinit_warnoptions; entry != NULL; entry = entry->next) { + status = PyWideStringList_Append(&config->warnoptions, entry->value); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + } + _clear_preinit_entries(&_preinit_warnoptions); - _clear_preinit_entries(&_preinit_xoptions); + return _PyStatus_OK(); } -static int -_PySys_ReadPreInitOptions(void) + +PyStatus +_PySys_ReadPreinitXOptions(PyConfig *config) { - /* Rerun the add commands with the actual sys module available */ - PyThreadState *tstate = _PyThreadState_GET(); - if (tstate == NULL) { - /* Still don't have a thread state, so something is wrong! */ - return -1; - } - _Py_PreInitEntry entry = _preinit_warnoptions; - while (entry != NULL) { - PySys_AddWarnOption(entry->value); - entry = entry->next; - } - entry = _preinit_xoptions; - while (entry != NULL) { - PySys_AddXOption(entry->value); - entry = entry->next; + PyStatus status; + _Py_PreInitEntry entry; + + for (entry = _preinit_xoptions; entry != NULL; entry = entry->next) { + status = PyWideStringList_Append(&config->xoptions, entry->value); + if (_PyStatus_EXCEPTION(status)) { + return status; + } } - _clear_all_preinit_options(); - return 0; + _clear_preinit_entries(&_preinit_xoptions); + return _PyStatus_OK(); } + static PyObject * get_warnoptions(void) { @@ -2265,9 +2271,7 @@ PySys_AddXOption(const wchar_t *s) } if (_PySys_AddXOptionWithError(s) < 0) { /* No return value, therefore clear error state if possible */ - if (_PyThreadState_UncheckedGet()) { - PyErr_Clear(); - } + PyErr_Clear(); } } @@ -2926,13 +2930,9 @@ _PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp) if (get_xoptions() == NULL) return -1; - /* Transfer any sys.warnoptions and sys._xoptions set directly - * by an embedding application from the linked list to the module. */ - if (_PySys_ReadPreInitOptions() != 0) - return -1; - if (PyErr_Occurred()) return -1; + return 0; err_occurred: |