Skip to content

Commit c869529

Browse files
serhiy-storchakaambv
authored andcommitted
bpo-33209: End framing at the end of C implementation of pickle.Pickler.dump(). (GH-6363)
1 parent 629338f commit c869529

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

Lib/test/pickletester.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,29 +2781,30 @@ def test_clear_pickler_memo(self):
27812781
# object again, the third serialized form should be identical to the
27822782
# first one we obtained.
27832783
data = ["abcdefg", "abcdefg", 44]
2784-
f = io.BytesIO()
2785-
pickler = self.pickler_class(f)
2784+
for proto in protocols:
2785+
f = io.BytesIO()
2786+
pickler = self.pickler_class(f, proto)
27862787

2787-
pickler.dump(data)
2788-
first_pickled = f.getvalue()
2788+
pickler.dump(data)
2789+
first_pickled = f.getvalue()
27892790

2790-
# Reset BytesIO object.
2791-
f.seek(0)
2792-
f.truncate()
2791+
# Reset BytesIO object.
2792+
f.seek(0)
2793+
f.truncate()
27932794

2794-
pickler.dump(data)
2795-
second_pickled = f.getvalue()
2795+
pickler.dump(data)
2796+
second_pickled = f.getvalue()
27962797

2797-
# Reset the Pickler and BytesIO objects.
2798-
pickler.clear_memo()
2799-
f.seek(0)
2800-
f.truncate()
2798+
# Reset the Pickler and BytesIO objects.
2799+
pickler.clear_memo()
2800+
f.seek(0)
2801+
f.truncate()
28012802

2802-
pickler.dump(data)
2803-
third_pickled = f.getvalue()
2803+
pickler.dump(data)
2804+
third_pickled = f.getvalue()
28042805

2805-
self.assertNotEqual(first_pickled, second_pickled)
2806-
self.assertEqual(first_pickled, third_pickled)
2806+
self.assertNotEqual(first_pickled, second_pickled)
2807+
self.assertEqual(first_pickled, third_pickled)
28072808

28082809
def test_priming_pickler_memo(self):
28092810
# Verify that we can set the Pickler's memo attribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
End framing at the end of C implementation of :func:`pickle.Pickler.dump`.

Modules/_pickle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,9 +4152,10 @@ dump(PicklerObject *self, PyObject *obj)
41524152
}
41534153

41544154
if (save(self, obj, 0) < 0 ||
4155-
_Pickler_Write(self, &stop_op, 1) < 0)
4155+
_Pickler_Write(self, &stop_op, 1) < 0 ||
4156+
_Pickler_CommitFrame(self) < 0)
41564157
return -1;
4157-
4158+
self->framing = 0;
41584159
return 0;
41594160
}
41604161

0 commit comments

Comments
 (0)