--- a/Lib/test/test_marshal.py Thu Jul 12 21:17:59 2012 +0200 +++ b/Lib/test/test_marshal.py Sat Jul 28 12:52:40 2012 +0200 @@ -7,6 +7,7 @@ import unittest import os import types +import struct class HelperMixin: def helper(self, sample, *extra): @@ -18,19 +19,38 @@ with open(support.TESTFN, "rb") as f: new = marshal.load(f) self.assertEqual(sample, new) + with open(support.TESTFN, "rb") as f: + return f.read() finally: support.unlink(support.TESTFN) +# The TYPE_INT64 code is used if one of the C 'long' or 'long long' +# types can hold 64 bits. +has_int64 = False +if struct.calcsize('l') >= 8: + has_int64 = True +try: + if struct.calcsize('q') >= 8: + has_int64 = True +except struct.error: + pass + class IntTestCase(unittest.TestCase, HelperMixin): def test_ints(self): # Test the full range of Python ints. - n = sys.maxsize - while n: - for expected in (-n, n): - self.helper(expected) - n = n >> 1 + self.assertEqual(self.helper(0), b'i\0\0\0\0') + for scale in range(100): + n = 1 << scale + for expected in (-n-1, -n, -n+1, n-1, n, n+1): + s = self.helper(expected) + if -(1 << 31) <= expected < (1 << 31): + self.assertEqual(s[0], ord('i')) + elif -(1 << 63) <= expected < (1 << 63) and has_int64: + self.assertEqual(s[0], ord('I')) + else: + self.assertEqual(s[0], ord('l')) - def test_int64(self): + def test_load_int64(self): # Simulate int marshaling on a 64-bit box. This is most interesting if # we're running the test on a 32-bit box, of course.