◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
2 changes: 2 additions & 0 deletions Include/internal/pycore_pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern PyStatus _PySys_Create(
PyThreadState *tstate,
PyObject **sysmod_p);
extern PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict);
extern int _PySys_InitMain(
_PyRuntimeState *runtime,
PyThreadState *tstate);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
58 changes: 29 additions & 29 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
@@ -2037,36 +2037,43 @@ _clear_preinit_entries(_Py_PreInitEntry *optionlist)
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
}

static void
_clear_all_preinit_options(void)
{
_clear_preinit_entries(&_preinit_warnoptions);
_clear_preinit_entries(&_preinit_xoptions);
}

static int
sys_read_preinit_options(PyThreadState *tstate)
{
/* Rerun the add commands with the actual sys module available */
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;
}

_clear_all_preinit_options();
return 0;
}

static PyObject *
get_warnoptions(PyThreadState *tstate)
{
Expand Down Expand Up @@ -2235,9 +2242,7 @@ PySys_AddXOption(const wchar_t *s)
}
if (_PySys_AddXOptionWithError(s) < 0) {
/* No return value, therefore clear error state if possible */
if (tstate) {
_PyErr_Clear(tstate);
}
}
}

Expand Up @@ -2898,11 +2903,6 @@ _PySys_InitMain(_PyRuntimeState *runtime, PyThreadState *tstate)
if (get_xoptions(tstate) == NULL)
return -1;

/* Transfer any sys.warnoptions and sys._xoptions set directly
* by an embedding application from the linked list to the module. */
if (sys_read_preinit_options(tstate) != 0)
return -1;

if (_PyErr_Occurred(tstate)) {
goto err_occurred;
}
Expand Down
Toggle all file notes Toggle all file annotations