Skip to content

Commit 865de27

Browse files
authored
bpo-30598: _PySys_EndInit() now duplicates warnoptions (#1998)
Fix a reference in subinterpreters, like test_callbacks_leak() of test_atexit. warnoptions is a list used to pass options from the command line to the sys module constructor. Before this change, the list was shared by multiple interpreter which is not the expected behaviour. Each interpreter should have their own independent mutable world. This change duplicates the list in each interpreter. So each interpreter owns its own list, so each interpreter can clear its own list.
1 parent ab1cb80 commit 865de27

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Python/sysmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,10 +2136,10 @@ _PySys_EndInit(PyObject *sysdict)
21362136
if (warnoptions == NULL)
21372137
return -1;
21382138
}
2139-
else {
2140-
Py_INCREF(warnoptions);
2141-
}
2142-
SET_SYS_FROM_STRING_BORROW_INT_RESULT("warnoptions", warnoptions);
2139+
2140+
SET_SYS_FROM_STRING_INT_RESULT("warnoptions",
2141+
PyList_GetSlice(warnoptions,
2142+
0, Py_SIZE(warnoptions)));
21432143

21442144
SET_SYS_FROM_STRING_BORROW_INT_RESULT("_xoptions", get_xoptions());
21452145

0 commit comments

Comments
 (0)