[Python-checkins] r72942 - in python/branches/py3k: Lib/test/pickletester.py Modules/_pickle.c

collin.winter python-checkins at python.org
Tue May 26 18:53:41 CEST 2009


Author: collin.winter
Date: Tue May 26 18:53:41 2009
New Revision: 72942

Log:
Merged revisions 72930 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72930 | collin.winter | 2009-05-25 21:12:39 -0700 (Mon, 25 May 2009) | 1 line
  
  Issue 5794: fix cPickle's unpickling of recursive tuples.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/pickletester.py
   python/branches/py3k/Modules/_pickle.c

Modified: python/branches/py3k/Lib/test/pickletester.py
==============================================================================
--- python/branches/py3k/Lib/test/pickletester.py	(original)
+++ python/branches/py3k/Lib/test/pickletester.py	Tue May 26 18:53:41 2009
@@ -432,6 +432,16 @@
             self.assertEqual(len(x), 1)
             self.assert_(x is x[0])
 
+    def test_recursive_tuple(self):
+        t = ([],)
+        t[0].append(t)
+        for proto in protocols:
+            s = self.dumps(t, proto)
+            x = self.loads(s)
+            self.assertEqual(len(x), 1)
+            self.assertEqual(len(x[0]), 1)
+            self.assert_(x is x[0][0])
+
     def test_recursive_dict(self):
         d = {}
         d[1] = d

Modified: python/branches/py3k/Modules/_pickle.c
==============================================================================
--- python/branches/py3k/Modules/_pickle.c	(original)
+++ python/branches/py3k/Modules/_pickle.c	Tue May 26 18:53:41 2009
@@ -3639,25 +3639,24 @@
 static int
 load_pop(UnpicklerObject *self)
 {
-    int len;
-
-    if ((len = self->stack->length) <= 0)
-        return stack_underflow();
+    int len = self->stack->length;
 
     /* Note that we split the (pickle.py) stack into two stacks,
      * an object stack and a mark stack. We have to be clever and
      * pop the right one. We do this by looking at the top of the
-     * mark stack.
+     * mark stack first, and only signalling a stack underflow if
+     * the object stack is empty and the mark stack doesn't match
+     * our expectations.
      */
-
-    if ((self->num_marks > 0) && (self->marks[self->num_marks - 1] == len))
+    if (self->num_marks > 0 && self->marks[self->num_marks - 1] == len) {
         self->num_marks--;
-    else {
+    } else if (len >= 0) {
         len--;
         Py_DECREF(self->stack->data[len]);
         self->stack->length = len;
+    } else {
+        return stack_underflow();
     }
-
     return 0;
 }
 


More information about the Python-checkins mailing list