Skip to content

Commit fa9773e

Browse files
authored
[3.14] gh-149590: Remove faulthandler_traverse (GH-150023) (#150088)
`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 1243cd6 commit fa9773e

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
@@ -1248,20 +1248,6 @@ faulthandler_stack_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
12481248
#endif /* defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_SIGACTION) */
12491249

12501250

1251-
static int
1252-
faulthandler_traverse(PyObject *module, visitproc visit, void *arg)
1253-
{
1254-
Py_VISIT(thread.file);
1255-
#ifdef FAULTHANDLER_USER
1256-
if (user_signals != NULL) {
1257-
for (size_t signum=0; signum < Py_NSIG; signum++)
1258-
Py_VISIT(user_signals[signum].file);
1259-
}
1260-
#endif
1261-
Py_VISIT(fatal_error.file);
1262-
return 0;
1263-
}
1264-
12651251
#ifdef MS_WINDOWS
12661252
static PyObject *
12671253
faulthandler_raise_exception(PyObject *self, PyObject *args)
@@ -1394,7 +1380,6 @@ static struct PyModuleDef module_def = {
13941380
.m_name = "faulthandler",
13951381
.m_doc = module_doc,
13961382
.m_methods = module_methods,
1397-
.m_traverse = faulthandler_traverse,
13981383
.m_slots = faulthandler_slots
13991384
};
14001385

0 commit comments

Comments
 (0)