]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-149590: Remove faulthandler_traverse (GH-150023) (#150088)
authorArmaan Vakharia <43391096+armaan-v924@users.noreply.github.com>
Tue, 19 May 2026 15:08:58 +0000 (08:08 -0700)
committerGitHub <noreply@github.com>
Tue, 19 May 2026 15:08:58 +0000 (15:08 +0000)
`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 56737483c2ffdaadfec648fd38d409c6b10941c0)

Misc/NEWS.d/next/Core_and_Builtins/2026-05-18-13-47-17.gh-issue-149590.IPBeQx.rst [new file with mode: 0644]
Modules/faulthandler.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-18-13-47-17.gh-issue-149590.IPBeQx.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-18-13-47-17.gh-issue-149590.IPBeQx.rst
new file mode 100644 (file)
index 0000000..8d3b29d
--- /dev/null
@@ -0,0 +1 @@
+Fix crash when faulthandler is imported more than once.
index 2495faa38170b79b3ae07d0e258ffe5daba02a07..09b910f4cf7d192e2f23e949ff73883f437c0fbc 100644 (file)
@@ -1248,20 +1248,6 @@ faulthandler_stack_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
 #endif   /* defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_SIGACTION) */
 
 
-static int
-faulthandler_traverse(PyObject *module, visitproc visit, void *arg)
-{
-    Py_VISIT(thread.file);
-#ifdef FAULTHANDLER_USER
-    if (user_signals != NULL) {
-        for (size_t signum=0; signum < Py_NSIG; signum++)
-            Py_VISIT(user_signals[signum].file);
-    }
-#endif
-    Py_VISIT(fatal_error.file);
-    return 0;
-}
-
 #ifdef MS_WINDOWS
 static PyObject *
 faulthandler_raise_exception(PyObject *self, PyObject *args)
@@ -1394,7 +1380,6 @@ static struct PyModuleDef module_def = {
     .m_name = "faulthandler",
     .m_doc = module_doc,
     .m_methods = module_methods,
-    .m_traverse = faulthandler_traverse,
     .m_slots = faulthandler_slots
 };