diff Python/sysmodule.c @ 12965:04c89d77dfdb legacy-trunk

Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows). Also removed a redundant cast from sys.getrefcount(), as discussed on the patches list.
author Mark Hammond <mhammond@skippinet.com.au>
date Tue, 20 Jun 2000 08:12:48 +0000
parents 78231bbe605d
children 8c8de5b736dc
line wrap: on
line diff
--- a/Python/sysmodule.c	Tue Jun 20 07:42:23 2000 +0000
+++ b/Python/sysmodule.c	Tue Jun 20 08:12:48 2000 +0000
@@ -265,9 +265,21 @@
 	PyObject *arg;
 	if (!PyArg_ParseTuple(args, "O:getrefcount", &arg))
 		return NULL;
-	return PyInt_FromLong((long) arg->ob_refcnt);
+	return PyInt_FromLong(arg->ob_refcnt);
 }
 
+#ifdef Py_TRACE_REFS
+static PyObject *
+sys_gettotalrefcount(PyObject *self, PyObject *args)
+{
+	extern long _Py_RefTotal;
+	if (!PyArg_ParseTuple(args, ":gettotalrefcount"))
+		return NULL;
+	return PyInt_FromLong(_Py_RefTotal);
+}
+
+#endif /* Py_TRACE_REFS */
+
 static char getrefcount_doc[] =
 "getrefcount(object) -> integer\n\
 \n\
@@ -310,6 +322,7 @@
 #endif
 #ifdef Py_TRACE_REFS
 	{"getobjects",	_Py_GetObjects, 1},
+	{"gettotalrefcount", sys_gettotalrefcount, 1},
 #endif
 	{"getrefcount",	sys_getrefcount, 1, getrefcount_doc},
 #ifdef USE_MALLOPT