[Python-checkins] r68254 - in python/branches/release30-maint: Misc/NEWS Modules/gcmodule.c

georg.brandl python-checkins at python.org
Sun Jan 4 00:28:57 CET 2009


Author: georg.brandl
Date: Sun Jan  4 00:28:57 2009
New Revision: 68254

Log:
Merged revisions 67834 via svnmerge from 
svn+ssh://svn.python.org/python/branches/py3k

................
  r67834 | antoine.pitrou | 2008-12-18 00:18:19 +0100 (Thu, 18 Dec 2008) | 10 lines
  
  Merged revisions 67832 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r67832 | antoine.pitrou | 2008-12-17 23:46:54 +0100 (mer., 17 d?\195?\169c. 2008) | 4 lines
    
    Issue #2467: gc.DEBUG_STATS reports invalid elapsed times.
    Patch by Neil Schemenauer, very slightly modified.
  ........
................


Modified:
   python/branches/release30-maint/   (props changed)
   python/branches/release30-maint/Misc/NEWS
   python/branches/release30-maint/Modules/gcmodule.c

Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS	(original)
+++ python/branches/release30-maint/Misc/NEWS	Sun Jan  4 00:28:57 2009
@@ -16,6 +16,12 @@
   one byte. Also fixes the meaning of len() so that it returns the number of
   items, rather than the size in bytes.
 
+- Issue #2467: gc.DEBUG_STATS reported invalid elapsed times. Also, always
+  print elapsed times, not only when some objects are uncollectable /
+  unreachable. Original patch by Neil Schemenauer.
+
+- Issue #3439: Add a bit_length method to int.
+
 - Issue #4747: When the terminal does not use utf-8, executing a script with
   non-ascii characters in its name could fail with a "SyntaxError: None" error.
 

Modified: python/branches/release30-maint/Modules/gcmodule.c
==============================================================================
--- python/branches/release30-maint/Modules/gcmodule.c	(original)
+++ python/branches/release30-maint/Modules/gcmodule.c	Sun Jan  4 00:28:57 2009
@@ -709,6 +709,24 @@
 	(void)PyFloat_ClearFreeList();
 }
 
+static double
+get_time(void)
+{
+	double result = 0;
+	if (tmod != NULL) {
+		PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
+		if (f == NULL) {
+			PyErr_Clear();
+		}
+		else {
+			if (PyFloat_Check(f))
+				result = PyFloat_AsDouble(f);
+			Py_DECREF(f);
+		}
+	}
+	return result;
+}
+
 /* This is the main function.  Read this to understand how the
  * collection process works. */
 static Py_ssize_t
@@ -731,16 +749,7 @@
 	}
 
 	if (debug & DEBUG_STATS) {
-		if (tmod != NULL) {
-			PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
-			if (f == NULL) {
-				PyErr_Clear();
-			}
-			else {
-				t1 = PyFloat_AsDouble(f);
-				Py_DECREF(f);
-			}
-		}
+		t1 = get_time();
 		PySys_WriteStderr("gc: collecting generation %d...\n",
 				  generation);
 		PySys_WriteStderr("gc: objects in each generation:");
@@ -813,17 +822,6 @@
 		if (debug & DEBUG_COLLECTABLE) {
 			debug_cycle("collectable", FROM_GC(gc));
 		}
-		if (tmod != NULL && (debug & DEBUG_STATS)) {
-			PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
-			if (f == NULL) {
-				PyErr_Clear();
-			}
-			else {
-				t1 = PyFloat_AsDouble(f)-t1;
-				Py_DECREF(f);
-				PySys_WriteStderr("gc: %.4fs elapsed.\n", t1);
-			}
-		}
 	}
 
 	/* Clear weakrefs and invoke callbacks as necessary. */
@@ -845,14 +843,19 @@
 			debug_cycle("uncollectable", FROM_GC(gc));
 	}
 	if (debug & DEBUG_STATS) {
+		double t2 = get_time();
 		if (m == 0 && n == 0)
-			PySys_WriteStderr("gc: done.\n");
+			PySys_WriteStderr("gc: done");
 		else
 			PySys_WriteStderr(
 			    "gc: done, "
 			    "%" PY_FORMAT_SIZE_T "d unreachable, "
-			    "%" PY_FORMAT_SIZE_T "d uncollectable.\n",
+			    "%" PY_FORMAT_SIZE_T "d uncollectable",
 			    n+m, n);
+		if (t1 && t2) {
+			PySys_WriteStderr(", %.4fs elapsed", t2-t1);
+		}
+		PySys_WriteStderr(".\n");
 	}
 
 	/* Append instances in the uncollectable set to a Python


More information about the Python-checkins mailing list