Skip to content

Commit a5c8830

Browse files
bpo-33209: End framing at the end of C implementation of pickle.Pickler.dump(). (pythonGH-6363)
(cherry picked from commit c869529) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent fa5157e commit a5c8830

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

Lib/test/pickletester.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -2667,29 +2667,30 @@ def test_clear_pickler_memo(self):
26672667
# object again, the third serialized form should be identical to the
26682668
# first one we obtained.
26692669
data = ["abcdefg", "abcdefg", 44]
2670-
f = io.BytesIO()
2671-
pickler = self.pickler_class(f)
2670+
for proto in protocols:
2671+
f = io.BytesIO()
2672+
pickler = self.pickler_class(f, proto)
26722673

2673-
pickler.dump(data)
2674-
first_pickled = f.getvalue()
2674+
pickler.dump(data)
2675+
first_pickled = f.getvalue()
26752676

2676-
# Reset BytesIO object.
2677-
f.seek(0)
2678-
f.truncate()
2677+
# Reset BytesIO object.
2678+
f.seek(0)
2679+
f.truncate()
26792680

2680-
pickler.dump(data)
2681-
second_pickled = f.getvalue()
2681+
pickler.dump(data)
2682+
second_pickled = f.getvalue()
26822683

2683-
# Reset the Pickler and BytesIO objects.
2684-
pickler.clear_memo()
2685-
f.seek(0)
2686-
f.truncate()
2684+
# Reset the Pickler and BytesIO objects.
2685+
pickler.clear_memo()
2686+
f.seek(0)
2687+
f.truncate()
26872688

2688-
pickler.dump(data)
2689-
third_pickled = f.getvalue()
2689+
pickler.dump(data)
2690+
third_pickled = f.getvalue()
26902691

2691-
self.assertNotEqual(first_pickled, second_pickled)
2692-
self.assertEqual(first_pickled, third_pickled)
2692+
self.assertNotEqual(first_pickled, second_pickled)
2693+
self.assertEqual(first_pickled, third_pickled)
26932694

26942695
def test_priming_pickler_memo(self):
26952696
# Verify that we can set the Pickler's memo attribute.
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -4061,9 +4061,10 @@ dump(PicklerObject *self, PyObject *obj)
40614061
}
40624062

40634063
if (save(self, obj, 0) < 0 ||
4064-
_Pickler_Write(self, &stop_op, 1) < 0)
4064+
_Pickler_Write(self, &stop_op, 1) < 0 ||
4065+
_Pickler_CommitFrame(self) < 0)
40654066
return -1;
4066-
4067+
self->framing = 0;
40674068
return 0;
40684069
}
40694070

0 commit comments

Comments
 (0)