Kaydet (Commit) c869529e authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka Kaydeden (comit) Łukasz Langa

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

üst 629338f1
...@@ -2781,29 +2781,30 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase): ...@@ -2781,29 +2781,30 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
# object again, the third serialized form should be identical to the # object again, the third serialized form should be identical to the
# first one we obtained. # first one we obtained.
data = ["abcdefg", "abcdefg", 44] data = ["abcdefg", "abcdefg", 44]
f = io.BytesIO() for proto in protocols:
pickler = self.pickler_class(f) f = io.BytesIO()
pickler = self.pickler_class(f, proto)
pickler.dump(data) pickler.dump(data)
first_pickled = f.getvalue() first_pickled = f.getvalue()
# Reset BytesIO object. # Reset BytesIO object.
f.seek(0) f.seek(0)
f.truncate() f.truncate()
pickler.dump(data) pickler.dump(data)
second_pickled = f.getvalue() second_pickled = f.getvalue()
# Reset the Pickler and BytesIO objects. # Reset the Pickler and BytesIO objects.
pickler.clear_memo() pickler.clear_memo()
f.seek(0) f.seek(0)
f.truncate() f.truncate()
pickler.dump(data) pickler.dump(data)
third_pickled = f.getvalue() third_pickled = f.getvalue()
self.assertNotEqual(first_pickled, second_pickled) self.assertNotEqual(first_pickled, second_pickled)
self.assertEqual(first_pickled, third_pickled) self.assertEqual(first_pickled, third_pickled)
def test_priming_pickler_memo(self): def test_priming_pickler_memo(self):
# Verify that we can set the Pickler's memo attribute. # Verify that we can set the Pickler's memo attribute.
......
End framing at the end of C implementation of :func:`pickle.Pickler.dump`.
...@@ -4152,9 +4152,10 @@ dump(PicklerObject *self, PyObject *obj) ...@@ -4152,9 +4152,10 @@ dump(PicklerObject *self, PyObject *obj)
} }
if (save(self, obj, 0) < 0 || 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; return -1;
self->framing = 0;
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment