]> granicus.if.org Git - python/commitdiff
bpo-33209: End framing at the end of C implementation of pickle.Pickler.dump(). ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 3 Apr 2018 21:35:11 +0000 (14:35 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Tue, 3 Apr 2018 21:35:11 +0000 (14:35 -0700)
(cherry picked from commit c869529ea9fbed574d34cf7ac139ca3f81b62ef0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/pickletester.py
Misc/NEWS.d/next/Library/2018-04-03-10-37-13.bpo-33209.9sGWE_.rst [new file with mode: 0644]
Modules/_pickle.c

index b84b87861d01dd52ec6216cccb9bd77090269d66..71c2feadb613d2450adcc5276f2c3fcf500fd208 100644 (file)
@@ -2781,29 +2781,30 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
         # object again, the third serialized form should be identical to the
         # first one we obtained.
         data = ["abcdefg", "abcdefg", 44]
-        f = io.BytesIO()
-        pickler = self.pickler_class(f)
+        for proto in protocols:
+            f = io.BytesIO()
+            pickler = self.pickler_class(f, proto)
 
-        pickler.dump(data)
-        first_pickled = f.getvalue()
+            pickler.dump(data)
+            first_pickled = f.getvalue()
 
-        # Reset BytesIO object.
-        f.seek(0)
-        f.truncate()
+            # Reset BytesIO object.
+            f.seek(0)
+            f.truncate()
 
-        pickler.dump(data)
-        second_pickled = f.getvalue()
+            pickler.dump(data)
+            second_pickled = f.getvalue()
 
-        # Reset the Pickler and BytesIO objects.
-        pickler.clear_memo()
-        f.seek(0)
-        f.truncate()
+            # Reset the Pickler and BytesIO objects.
+            pickler.clear_memo()
+            f.seek(0)
+            f.truncate()
 
-        pickler.dump(data)
-        third_pickled = f.getvalue()
+            pickler.dump(data)
+            third_pickled = f.getvalue()
 
-        self.assertNotEqual(first_pickled, second_pickled)
-        self.assertEqual(first_pickled, third_pickled)
+            self.assertNotEqual(first_pickled, second_pickled)
+            self.assertEqual(first_pickled, third_pickled)
 
     def test_priming_pickler_memo(self):
         # Verify that we can set the Pickler's memo attribute.
diff --git a/Misc/NEWS.d/next/Library/2018-04-03-10-37-13.bpo-33209.9sGWE_.rst b/Misc/NEWS.d/next/Library/2018-04-03-10-37-13.bpo-33209.9sGWE_.rst
new file mode 100644 (file)
index 0000000..d98b1e1
--- /dev/null
@@ -0,0 +1 @@
+End framing at the end of C implementation of :func:`pickle.Pickler.dump`.
index 9525ad6d9661bcc8c22f8c8df163e52ccac01c78..6a684f25fefd386e6e60dcb2faeeac2979c9d95e 100644 (file)
@@ -4152,9 +4152,10 @@ dump(PicklerObject *self, PyObject *obj)
     }
 
     if (save(self, obj, 0) < 0 ||
-        _Pickler_Write(self, &stop_op, 1) < 0)
+        _Pickler_Write(self, &stop_op, 1) < 0 ||
+        _Pickler_CommitFrame(self) < 0)
         return -1;
-
+    self->framing = 0;
     return 0;
 }