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.
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 9901a3c..b66eef5 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -73,20 +73,34 @@
n /= 123.4567
f = 0.0
- s = marshal.dumps(f)
+ s = marshal.dumps(f, 2)
got = marshal.loads(s)
self.assertEqual(f, got)
+ # and with version <= 1 (floats marshalled differently then)
+ s = marshal.dumps(f, 1)
+ got = marshal.loads(s)
+ self.assertEqual(f, got)
n = sys.maxint * 3.7e-250
while n < small:
for expected in (-n, n):
f = float(expected)
+
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
+
+ s = marshal.dumps(f, 1)
+ got = marshal.loads(s)
+ self.assertEqual(f, got)
+
marshal.dump(f, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
+
+ marshal.dump(f, file(test_support.TESTFN, "wb"), 1)
+ got = marshal.load(file(test_support.TESTFN, "rb"))
+ self.assertEqual(f, got)
n *= 123.4567
os.unlink(test_support.TESTFN)