summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-08-09 15:58:59 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-08-09 15:58:59 (GMT)
commitc7c8d8e32d4bee468db1b2a5272231a0a19f2a87 (patch)
tree12e8f61ae63d5c1a5747b9a4c0626ddaa4b0f5df
parent48c703445400346d7d0b7c98830ace2937677ab6 (diff)
downloadcpython-c7c8d8e32d4bee468db1b2a5272231a0a19f2a87.zip
cpython-c7c8d8e32d4bee468db1b2a5272231a0a19f2a87.tar.gz
cpython-c7c8d8e32d4bee468db1b2a5272231a0a19f2a87.tar.bz2
Add get_objects function. This is a low level function (like
get_referents, and is not yet documented in the library manual). Suggestions for a better name welcome.
-rw-r--r--Modules/gcmodule.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 9c8125d..98a0ee5 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -725,6 +725,42 @@ gc_get_referents(PyObject *self, PyObject* args)
return result;
}
+static char gc_get_objects__doc__[] =
+"get_objects() -> [...]\n"
+"\n"
+"Return a list of objects tracked by the collector (excluding the list\n"
+"returned).\n"
+;
+
+/* appending objects in a GC list to a Python list */
+static void
+append_objects(PyObject *py_list, PyGC_Head *gc_list)
+{
+ PyGC_Head *gc;
+ for (gc = gc_list->gc_next; gc != gc_list; gc = gc->gc_next) {
+ PyObject *op = PyObject_FROM_GC(gc);
+ if (op != py_list) {
+ Py_INCREF(op);
+ PyList_Append(py_list, op);
+ }
+ }
+}
+
+static PyObject *
+gc_get_objects(PyObject *self, PyObject *args)
+{
+ PyObject* result;
+
+ if (!PyArg_ParseTuple(args, ":get_objects")) /* check no args */
+ return NULL;
+ result = PyList_New(0);
+ append_objects(result, &generation0);
+ append_objects(result, &generation1);
+ append_objects(result, &generation2);
+ return result;
+}
+
+
static char gc__doc__ [] =
"This module provides access to the garbage collector for reference cycles.\n"
"\n"
@@ -736,6 +772,7 @@ static char gc__doc__ [] =
"get_debug() -- Get debugging flags.\n"
"set_threshold() -- Set the collection thresholds.\n"
"get_threshold() -- Return the current the collection thresholds.\n"
+"get_objects() -- Return a list of all objects tracked by the collector.\n"
"get_referents() -- Return the list of objects that refer to an object.\n"
;
@@ -748,6 +785,7 @@ static PyMethodDef GcMethods[] = {
{"set_threshold", gc_set_thresh, METH_VARARGS, gc_set_thresh__doc__},
{"get_threshold", gc_get_thresh, METH_VARARGS, gc_get_thresh__doc__},
{"collect", gc_collect, METH_VARARGS, gc_collect__doc__},
+ {"get_objects", gc_get_objects,METH_VARARGS, gc_get_objects__doc__},
{"get_referents", gc_get_referents, METH_VARARGS,
gc_get_referents__doc__},
{NULL, NULL} /* Sentinel */