64-bit INTs on 32-bit boxes (where they become longs). Also exploit that
int(str) and long(str) will ignore a trailing newline (saves creating a
new string at the Python level).
pickletester.py: Simulate reading a pickle produced by a 64-bit box.
dispatch[NONE] = load_none
def load_int(self):
- self.append(int(self.readline()[:-1]))
+ data = self.readline()
+ try:
+ self.append(int(data))
+ except ValueError:
+ self.append(long(data))
dispatch[INT] = load_int
def load_binint(self):
repr(s),
got))
n = n >> 1
+
+ # Fake a pickle from a sizeof(long)==8 box.
+ maxint64 = (1L << 63) - 1
+ data = 'I' + str(maxint64) + '\n.'
+ got = pickle.loads(data)
+ if maxint64 != got:
+ raise TestFailed("maxint64 test failed %r %r" % (maxint64, got))
+ # Try too with a bogus literal.
+ data = 'I' + str(maxint64) + 'JUNK\n.'
+ try:
+ got = pickle.loads(data)
+ except ValueError:
+ pass
+ else:
+ raise TestFailed("should have raised error on bogus INT literal")