Skip to content

Commit c417fca

Browse files
[3.15] gh-149590: Remove faulthandler_traverse (GH-150023) (#150037)
gh-149590: Remove faulthandler_traverse (GH-150023) `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) Co-authored-by: Armaan Vakharia <43391096+armaan-v924@users.noreply.github.com>
1 parent 16f8ed5 commit c417fca

2 files changed

Lines changed: 1 addition & 16 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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,21 +1349,6 @@ faulthandler__stack_overflow_impl(PyObject *module)
13491349
#endif /* defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_SIGACTION) */
13501350

13511351

1352-
static int
1353-
faulthandler_traverse(PyObject *module, visitproc visit, void *arg)
1354-
{
1355-
Py_VISIT(thread.file);
1356-
#ifdef FAULTHANDLER_USER
1357-
if (user_signals != NULL) {
1358-
for (size_t signum=0; signum < Py_NSIG; signum++)
1359-
Py_VISIT(user_signals[signum].file);
1360-
}
1361-
#endif
1362-
Py_VISIT(fatal_error.file);
1363-
return 0;
1364-
}
1365-
1366-
13671352
#ifdef MS_WINDOWS
13681353
/*[clinic input]
13691354
faulthandler._raise_exception
@@ -1459,7 +1444,6 @@ static struct PyModuleDef module_def = {
14591444
.m_name = "faulthandler",
14601445
.m_doc = module_doc,
14611446
.m_methods = module_methods,
1462-
.m_traverse = faulthandler_traverse,
14631447
.m_slots = faulthandler_slots
14641448
};
14651449

0 commit comments

Comments
 (0)