[Python-checkins] r84798 - in python/branches/py3k: Lib/test/test_gc.py Modules/gcmodule.c

antoine.pitrou python-checkins at python.org
Tue Sep 14 11:48:39 CEST 2010


Author: antoine.pitrou
Date: Tue Sep 14 11:48:39 2010
New Revision: 84798

Log:
Do not print additional shutdown message when gc.DEBUG_SAVEALL is set



Modified:
   python/branches/py3k/Lib/test/test_gc.py
   python/branches/py3k/Modules/gcmodule.c

Modified: python/branches/py3k/Lib/test/test_gc.py
==============================================================================
--- python/branches/py3k/Lib/test/test_gc.py	(original)
+++ python/branches/py3k/Lib/test/test_gc.py	Tue Sep 14 11:48:39 2010
@@ -482,8 +482,7 @@
             x.x = x
             x.y = X('second')
             del x
-            if %d:
-                gc.set_debug(gc.DEBUG_UNCOLLECTABLE)
+            gc.set_debug(%s)
         """
         def run_command(code):
             p = subprocess.Popen([sys.executable, "-c", code],
@@ -494,13 +493,19 @@
             self.assertEqual(stdout.strip(), b"")
             return strip_python_stderr(stderr)
 
-        stderr = run_command(code % 0)
+        stderr = run_command(code % "0")
         self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
         self.assertNotIn(b"[<X 'first'>, <X 'second'>]", stderr)
         # With DEBUG_UNCOLLECTABLE, the garbage list gets printed
-        stderr = run_command(code % 1)
+        stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
         self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
         self.assertIn(b"[<X 'first'>, <X 'second'>]", stderr)
+        # 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).
+        stderr = run_command(code % "gc.DEBUG_SAVEALL")
+        self.assertNotIn(b"uncollectable objects at shutdown", stderr)
+
 
 class GCTogglingTests(unittest.TestCase):
     def setUp(self):

Modified: python/branches/py3k/Modules/gcmodule.c
==============================================================================
--- python/branches/py3k/Modules/gcmodule.c	(original)
+++ python/branches/py3k/Modules/gcmodule.c	Tue Sep 14 11:48:39 2010
@@ -1366,7 +1366,8 @@
 void
 _PyGC_Fini(void)
 {
-    if (garbage != NULL && PyList_GET_SIZE(garbage) > 0) {
+    if (!(debug & DEBUG_SAVEALL)
+        && garbage != NULL && PyList_GET_SIZE(garbage) > 0) {
         PySys_WriteStderr(
             "gc: "
             "%" PY_FORMAT_SIZE_T "d uncollectable objects at shutdown:\n",


More information about the Python-checkins mailing list