Skip to content

Commit 1164dfc

Browse files
committed
Issue #19219: Speed up marshal.loads(), and make pyc files slightly (5% to 10%) smaller.
1 parent 4c6ed25 commit 1164dfc

File tree

4 files changed

+3471
-3554
lines changed

4 files changed

+3471
-3554
lines changed

Include/marshal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
extern "C" {
88
#endif
99

10-
#define Py_MARSHAL_VERSION 3
10+
#define Py_MARSHAL_VERSION 4
1111

1212
PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int);
1313
PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int);

Lib/test/test_marshal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ def test_loads_reject_unicode_strings(self):
262262

263263
def test_bad_reader(self):
264264
class BadReader(io.BytesIO):
265-
def read(self, n=-1):
266-
b = super().read(n)
265+
def readinto(self, buf):
266+
n = super().readinto(buf)
267267
if n is not None and n > 4:
268-
b += b' ' * 10**6
269-
return b
268+
n += 10**6
269+
return n
270270
for value in (1.0, 1j, b'0123456789', '0123456789'):
271271
self.assertRaises(ValueError, marshal.load,
272272
BadReader(marshal.dumps(value)))

0 commit comments

Comments
 (0)