This is my patch: · pythoncapi/cpython@df88846 · GitHub
Skip to content

Commit df88846

Browse files
author
Michael W. Hudson
committed
This is my patch:
[ 1180995 ] binary formats for marshalling floats Adds 2 new type codes for marshal (binary floats and binary complexes), a new marshal version (2), updates MAGIC and fiddles the de-serializing of code objects to be less likely to clobber the real reason for failing if it fails.
1 parent 268e61c commit df88846

5 files changed

Lines changed: 196 additions & 68 deletions

File tree

Include/marshal.h

Lines changed: 1 addition & 1 deletion

Lib/test/test_marshal.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,34 @@ def test_floats(self):
7373
n /= 123.4567
7474

7575
f = 0.0
76-
s = marshal.dumps(f)
76+
s = marshal.dumps(f, 2)
7777
got = marshal.loads(s)
7878
self.assertEqual(f, got)
79+
# and with version <= 1 (floats marshalled differently then)
80+
s = marshal.dumps(f, 1)
81+
got = marshal.loads(s)
82+
self.assertEqual(f, got)
7983

8084
n = sys.maxint * 3.7e-250
8185
while n < small:
8286
for expected in (-n, n):
8387
f = float(expected)
88+
8489
s = marshal.dumps(f)
8590
got = marshal.loads(s)
8691
self.assertEqual(f, got)
92+
93+
s = marshal.dumps(f, 1)
94+
got = marshal.loads(s)
95+
self.assertEqual(f, got)
96+
8797
marshal.dump(f, file(test_support.TESTFN, "wb"))
8898
got = marshal.load(file(test_support.TESTFN, "rb"))
8999
self.assertEqual(f, got)
100+
101+
marshal.dump(f, file(test_support.TESTFN, "wb"), 1)
102+
got = marshal.load(file(test_support.TESTFN, "rb"))
103+
self.assertEqual(f, got)
90104
n *= 123.4567
91105
os.unlink(test_support.TESTFN)
92106

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- SF patch #1180995: marshal now uses a binary format by default when
16+
serializing floats.
17+
1518
- SF patch #1181301: on platforms that appear to use IEEE 754 floats,
1619
the routines that promise to produce IEEE 754 binary representations
1720
of floats now simply copy bytes around.

Python/import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
5050
Python 2.4a0: 62041
5151
Python 2.4a3: 62051
5252
Python 2.4b1: 62061
53+
Python 2.5a0: 62071
5354
*/
54-
#define MAGIC (62061 | ((long)'\r'<<16) | ((long)'\n'<<24))
55+
#define MAGIC (62071 | ((long)'\r'<<16) | ((long)'\n'<<24))
5556

5657
/* Magic word as global; note that _PyImport_Init() can change the
5758
value of this global to accommodate for alterations of how the

Python/marshal.c

Lines changed: 175 additions & 65 deletions

0 commit comments

Comments
 (0)