[Python-checkins] python/dist/src/Modules itertoolsmodule.c, 1.37, 1.38

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sun Oct 17 18:40:16 CEST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4458/Modules

Modified Files:
	itertoolsmodule.c 
Log Message:
Fix and test weak referencing of itertools.tee objects.

Index: itertoolsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/itertoolsmodule.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- itertoolsmodule.c	2 Oct 2004 10:56:43 -0000	1.37
+++ itertoolsmodule.c	17 Oct 2004 16:40:14 -0000	1.38
@@ -329,6 +329,7 @@
 	PyObject_HEAD
 	teedataobject *dataobj;
 	int index;
+	PyObject *weakreflist;
 } teeobject;
 
 static PyTypeObject teedataobject_type;
@@ -452,6 +453,7 @@
 	Py_INCREF(to->dataobj);
 	newto->dataobj = to->dataobj;
 	newto->index = to->index;
+	newto->weakreflist = NULL;
 	return (PyObject *)newto;
 }
 
@@ -476,6 +478,7 @@
 		goto done;
 	to->dataobj = (teedataobject *)teedataobject_new(it);
 	to->index = 0;
+	to->weakreflist = NULL;
 done:
 	Py_XDECREF(it);
 	return (PyObject *)to;
@@ -494,6 +497,8 @@
 static void
 tee_dealloc(teeobject *to)
 {
+	if (to->weakreflist != NULL)
+		PyObject_ClearWeakRefs((PyObject *) to);
 	Py_XDECREF(to->dataobj);
 	PyObject_Del(to);
 }
@@ -533,7 +538,7 @@
 	0,				/* tp_traverse */
 	0,				/* tp_clear */
 	0,				/* tp_richcompare */
-	0,				/* tp_weaklistoffset */
+	offsetof(teeobject, weakreflist),	/* tp_weaklistoffset */
 	PyObject_SelfIter,		/* tp_iter */
 	(iternextfunc)tee_next,		/* tp_iternext */
 	tee_methods,			/* tp_methods */



More information about the Python-checkins mailing list