diff Python/sysmodule.c @ 3024:54aa87b1ccee legacy-trunk

Implemented two new functions in sys: getcounts() returns a list of counts of allocations and deallocations for all different object types. getobjects(n [, type ]) returns a list of recently allocated and not-yet-freed objects of the given type (all objects if no type given). Only the n most recent (all if n==0) objects are returned. getcounts is only available if compiled with -DCOUNT_ALLOCS, getobjects is only available if compiled with -DTRACE_REFS. Note that everything must be compiled with these options!
author Sjoerd Mullender <sjoerd@acm.org>
date Tue, 29 Aug 1995 09:18:14 +0000
parents fc2190ec1bea
children 1eab8495462f
line wrap: on
line diff
--- a/Python/sysmodule.c	Mon Aug 28 19:41:35 1995 +0000
+++ b/Python/sysmodule.c	Tue Aug 29 09:18:14 1995 +0000
@@ -154,8 +154,42 @@
 }
 #endif /* USE_MALLOPT */
 
+static object *
+sys_getrefcount(self, args)
+	object *self;
+	object *args;
+{
+	object *arg;
+	if (!getargs(args, "O", &arg))
+		return NULL;
+	return newintobject((long) arg->ob_refcnt);
+}
+
+#ifdef COUNT_ALLOCS
+static PyObject *
+sys_getcounts(self, args)
+	PyObject *self, *args;
+{
+	extern PyObject *get_counts Py_PROTO((void));
+
+	if (!PyArg_Parse(args, ""))
+		return NULL;
+	return get_counts();
+}
+#endif
+
+#ifdef TRACE_REFS
+extern PyObject *getobjects Py_PROTO((PyObject *, PyObject *));
+#endif
 static struct methodlist sys_methods[] = {
 	{"exit",	sys_exit, 0},
+	{"getrefcount",	sys_getrefcount, 0},
+#ifdef COUNT_ALLOCS
+	{"getcounts",	sys_getcounts, 0},
+#endif
+#ifdef TRACE_REFS
+	{"getobjects",	getobjects, 1},
+#endif
 #ifdef USE_MALLOPT
 	{"mdebug",	sys_mdebug, 0},
 #endif