[Python-checkins] python/dist/src/Modules collectionsmodule.c, 1.35, 1.36

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Nov 9 08:27:37 CET 2004


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

Modified Files:
	collectionsmodule.c 
Log Message:
SF patch #1062279:  deque pickling problems
(Contributed by Dima Dorfman.)

* Support pickling of dictionaries in instances of deque subclasses.
* Support pickling of recursive deques.



Index: collectionsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/collectionsmodule.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- collectionsmodule.c	2 Nov 2004 02:11:35 -0000	1.35
+++ collectionsmodule.c	9 Nov 2004 07:27:34 -0000	1.36
@@ -550,19 +550,21 @@
 static PyObject *
 deque_reduce(dequeobject *deque)
 {
-	PyObject *seq, *args, *result;
+	PyObject *dict, *result, *it;
 
-	seq = PySequence_Tuple((PyObject *)deque);
-	if (seq == NULL)
-		return NULL;
-	args = PyTuple_Pack(1, seq);
-	if (args == NULL) {
-		Py_DECREF(seq);
+	dict = PyObject_GetAttrString((PyObject *)deque, "__dict__");
+	if (dict == NULL) {
+		PyErr_Clear();
+		dict = Py_None;
+		Py_INCREF(dict);
+	}
+	it = PyObject_GetIter((PyObject *)deque);
+	if (it == NULL) {
+		Py_DECREF(dict);
 		return NULL;
 	}
-	result = PyTuple_Pack(2, deque->ob_type, args);
-	Py_DECREF(seq);
-	Py_DECREF(args);
+	result = Py_BuildValue("O()ON", deque->ob_type, dict, it);
+	Py_DECREF(dict);
 	return result;
 }
 



More information about the Python-checkins mailing list