gh-141510: Change marshal version to 6 (#145551) · python/cpython@4fce98a · GitHub
Skip to content

Commit 4fce98a

Browse files
authored
gh-141510: Change marshal version to 6 (#145551)
Fix SliceTestCase: test also that version 4 fails with ValueError.
1 parent c3fb0d9 commit 4fce98a

6 files changed

Lines changed: 29 additions & 5 deletions

File tree

Doc/library/marshal.rst

Lines changed: 9 additions & 2 deletions

Include/cpython/marshal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(const char *,
66
Py_ssize_t);
77
PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
88

9-
#define Py_MARSHAL_VERSION 5
9+
#define Py_MARSHAL_VERSION 6
1010

1111
PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *);
1212
PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *);

Lib/test/test_marshal.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,15 @@ def testDict(self):
570570
self.helper(dictobj)
571571
self.helper3(dictobj)
572572

573+
def testFrozenDict(self):
574+
for obj in self.keys:
575+
dictobj = frozendict({"hello": obj, "goodbye": obj, obj: "hello"})
576+
self.helper(dictobj)
577+
578+
for version in range(6):
579+
with self.assertRaises(ValueError):
580+
marshal.dumps(dictobj, version)
581+
573582
def testModule(self):
574583
with open(__file__, "rb") as f:
575584
code = f.read()
@@ -635,7 +644,7 @@ def test_slice(self):
635644
with self.subTest(obj=str(obj)):
636645
self.helper(obj)
637646

638-
for version in range(4):
647+
for version in range(5):
639648
with self.assertRaises(ValueError):
640649
marshal.dumps(obj, version)
641650

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`marshal` now supports :class:`frozendict` objects. The marshal format
2+
version was increased to 6. Patch by Victor Stinner.

Programs/_freeze_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ compile_and_marshal(const char *name, const char *text)
134134
return NULL;
135135
}
136136

137-
assert(Py_MARSHAL_VERSION >= 5);
137+
assert(Py_MARSHAL_VERSION >= 6);
138138
PyObject *marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION);
139139
Py_CLEAR(code);
140140
if (marshalled == NULL) {

Python/marshal.c

Lines changed: 6 additions & 0 deletions

0 commit comments

Comments
 (0)