summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-06-23 14:18:11 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-06-23 14:18:11 (GMT)
commit8caad49c30d2f9ecd09c8838bb691360e40c2665 (patch)
tree367db742417367edaea6a4dee1eea3ff2885d3db /Objects/listobject.c
parenta392dcb2117739ad0dc7f67bd550083ee860226b (diff)
downloadcpython-8caad49c30d2f9ecd09c8838bb691360e40c2665.zip
cpython-8caad49c30d2f9ecd09c8838bb691360e40c2665.tar.gz
cpython-8caad49c30d2f9ecd09c8838bb691360e40c2665.tar.bz2
Round 1 of Neil Schemenauer's GC patches:
This patch adds the type methods traverse and clear necessary for GC implementation.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 163ba2a..65dfb18 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1418,6 +1418,30 @@ listremove(self, args)
return NULL;
}
+static int
+list_traverse(PyListObject *o, visitproc visit, void *arg)
+{
+ int i, err;
+ PyObject *x;
+
+ for (i = o->ob_size; --i >= 0; ) {
+ x = o->ob_item[i];
+ if (x != NULL) {
+ err = visit(x, arg);
+ if (err)
+ return err;
+ }
+ }
+ return 0;
+}
+
+static int
+list_clear(PyListObject *lp)
+{
+ (void) PyList_SetSlice((PyObject *)lp, 0, lp->ob_size, 0);
+ return 0;
+}
+
static char append_doc[] =
"L.append(object) -- append object to end";
static char extend_doc[] =
@@ -1491,6 +1515,9 @@ PyTypeObject PyList_Type = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
+ 0, /* tp_doc */
+ (traverseproc)list_traverse, /* tp_traverse */
+ (inquiry)list_clear, /* tp_clear */
};
@@ -1567,5 +1594,7 @@ static PyTypeObject immutable_list_type = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
+ 0, /* tp_doc */
+ (traverseproc)list_traverse, /* tp_traverse */
};