[Python-checkins] bpo-33209: End framing at the end of C implementation of pickle.Pickler.dump(). (GH-6363)

Miss Islington (bot) webhook-mailer at python.org
Tue Apr 3 18:05:20 EDT 2018


https://github.com/python/cpython/commit/a5c8830637cde632ab3bcf5475698dcf0fb0546d
commit: a5c8830637cde632ab3bcf5475698dcf0fb0546d
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-04-03T15:05:11-07:00
summary:

bpo-33209: End framing at the end of C implementation of pickle.Pickler.dump(). (GH-6363)

(cherry picked from commit c869529ea9fbed574d34cf7ac139ca3f81b62ef0)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-04-03-10-37-13.bpo-33209.9sGWE_.rst
M Lib/test/pickletester.py
M Modules/_pickle.c

diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index a1c0bd726fe2..764057a86641 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -2667,29 +2667,30 @@ def test_clear_pickler_memo(self):
         # 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
index 000000000000..d98b1e174e55
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-04-03-10-37-13.bpo-33209.9sGWE_.rst
@@ -0,0 +1 @@
+End framing at the end of C implementation of :func:`pickle.Pickler.dump`.
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 7e9bb9895ca2..792c7604b59e 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4061,9 +4061,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;
 }
 



More information about the Python-checkins mailing list