]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-136517: Print uncollectable objects if DEBUG_UNCOLLECTABLE mode was set...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 11 Jul 2025 14:20:05 +0000 (16:20 +0200)
committerGitHub <noreply@github.com>
Fri, 11 Jul 2025 14:20:05 +0000 (15:20 +0100)
gh-136517: Print uncollectable objects if DEBUG_UNCOLLECTABLE mode was set (GH-136518)
(cherry picked from commit c560df9658f1a24edea995fe6f9c84c55b37cfb3)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Lib/test/test_gc.py
Misc/NEWS.d/next/Core_and_Builtins/2025-07-10-23-23-50.gh-issue-136517._NHJyv.rst [new file with mode: 0644]
Python/gc.c

index b4cbfb6d774080a1d7f3a9ea46695810947ea5f6..d9e9622992f5433c22ec95f9552a768044e0b0b6 100644 (file)
@@ -726,6 +726,9 @@ class GCTests(unittest.TestCase):
         self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
                       b"shutdown; use", stderr)
         self.assertNotIn(b"<X 'first'>", stderr)
+        one_line_re = b"gc: uncollectable <X 0x[0-9A-Fa-f]+>"
+        expected_re = one_line_re + b"\r?\n" + one_line_re
+        self.assertNotRegex(stderr, expected_re)
         # With DEBUG_UNCOLLECTABLE, the garbage list gets printed
         stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
         self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
@@ -733,6 +736,8 @@ class GCTests(unittest.TestCase):
         self.assertTrue(
             (b"[<X 'first'>, <X 'second'>]" in stderr) or
             (b"[<X 'second'>, <X 'first'>]" in stderr), stderr)
+        # we expect two lines with uncollectable objects
+        self.assertRegex(stderr, expected_re)
         # With DEBUG_SAVEALL, no additional message should get printed
         # (because gc.garbage also contains normally reclaimable cyclic
         # references, and its elements get printed at runtime anyway).
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-10-23-23-50.gh-issue-136517._NHJyv.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-10-23-23-50.gh-issue-136517._NHJyv.rst
new file mode 100644 (file)
index 0000000..bf26c4e
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed a typo that prevented printing of uncollectable objects when the
+:const:`gc.DEBUG_UNCOLLECTABLE` mode was set.
index 7b0e6d6e80350475b5a355366b244529a6560661..41854265361b2454d3abed0cf23a1dfd4e4e5369 100644 (file)
@@ -1763,7 +1763,7 @@ gc_collect_region(PyThreadState *tstate,
     Py_ssize_t n = 0;
     for (gc = GC_NEXT(&finalizers); gc != &finalizers; gc = GC_NEXT(gc)) {
         n++;
-        if (gcstate->debug & _PyGC_DEBUG_COLLECTABLE)
+        if (gcstate->debug & _PyGC_DEBUG_UNCOLLECTABLE)
             debug_cycle("uncollectable", FROM_GC(gc));
     }
     stats->uncollectable = n;