Skip to content

Commit 44f3149

Browse files
authored
[3.13] gh-149590: Remove faulthandler_traverse (GH-150023) (#150087)
`faulthandler_traverse` visits Python objects owned by `_PyRuntime`, not by the module instance. With multi-phase init allowing multiple module instances, each instance's GC traversal decrements `gc_refs` on the same runtime-owned objects, driving it negative when two instances are collected simultaneously. (cherry picked from commit 5673748)
1 parent 8ee6aff commit 44f3149

2 files changed

Lines changed: 1 addition & 15 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash when faulthandler is imported more than once.

Modules/faulthandler.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,20 +1180,6 @@ faulthandler_stack_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
11801180
#endif /* defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_SIGACTION) */
11811181

11821182

1183-
static int
1184-
faulthandler_traverse(PyObject *module, visitproc visit, void *arg)
1185-
{
1186-
Py_VISIT(thread.file);
1187-
#ifdef FAULTHANDLER_USER
1188-
if (user_signals != NULL) {
1189-
for (size_t signum=0; signum < Py_NSIG; signum++)
1190-
Py_VISIT(user_signals[signum].file);
1191-
}
1192-
#endif
1193-
Py_VISIT(fatal_error.file);
1194-
return 0;
1195-
}
1196-
11971183
#ifdef MS_WINDOWS
11981184
static PyObject *
11991185
faulthandler_raise_exception(PyObject *self, PyObject *args)
@@ -1322,7 +1308,6 @@ static struct PyModuleDef module_def = {
13221308
.m_name = "faulthandler",
13231309
.m_doc = module_doc,
13241310
.m_methods = module_methods,
1325-
.m_traverse = faulthandler_traverse,
13261311
.m_slots = faulthandler_slots
13271312
};
13281313

0 commit comments

Comments
 (0)