[Python-checkins] bpo-32011: Revert "Issue GH-15480: Remove the deprecated and unused TYPE_INT64 code from marshal." (GH-4381) (#4405)
Serhiy Storchaka
webhook-mailer at python.org
Wed Nov 15 11:06:01 EST 2017
https://github.com/python/cpython/commit/d15bb5fcad584e113836486d17c6abcbf2168a86
commit: d15bb5fcad584e113836486d17c6abcbf2168a86
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2017-11-15T18:05:58+02:00
summary:
bpo-32011: Revert "Issue GH-15480: Remove the deprecated and unused TYPE_INT64 code from marshal." (GH-4381) (#4405)
Simplify the reverted code.
This reverts commit e9bbe8b87ba2874efba0474af5cc7d5941dbf742.
(cherry picked from commit 00987f6230fcdbecc8d9ab4b2b9fae8f99a1a4a9)
files:
A Misc/NEWS.d/next/Library/2017-11-12-20-47-59.bpo-32011.NzVDdZ.rst
M Lib/test/test_marshal.py
M Python/marshal.c
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index b378ffea00c..29dda987d0b 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -34,6 +34,29 @@ def test_ints(self):
self.helper(expected)
n = n >> 1
+ def test_int64(self):
+ # Simulate int marshaling with TYPE_INT64.
+ maxint64 = (1 << 63) - 1
+ minint64 = -maxint64-1
+ for base in maxint64, minint64, -maxint64, -(minint64 >> 1):
+ while base:
+ s = b'I' + int.to_bytes(base, 8, 'little', signed=True)
+ got = marshal.loads(s)
+ self.assertEqual(base, got)
+ if base == -1: # a fixed-point for shifting right 1
+ base = 0
+ else:
+ base >>= 1
+
+ got = marshal.loads(b'I\xfe\xdc\xba\x98\x76\x54\x32\x10')
+ self.assertEqual(got, 0x1032547698badcfe)
+ got = marshal.loads(b'I\x01\x23\x45\x67\x89\xab\xcd\xef')
+ self.assertEqual(got, -0x1032547698badcff)
+ got = marshal.loads(b'I\x08\x19\x2a\x3b\x4c\x5d\x6e\x7f')
+ self.assertEqual(got, 0x7f6e5d4c3b2a1908)
+ got = marshal.loads(b'I\xf7\xe6\xd5\xc4\xb3\xa2\x91\x80')
+ self.assertEqual(got, -0x7f6e5d4c3b2a1909)
+
def test_bool(self):
for b in (True, False):
self.helper(b)
diff --git a/Misc/NEWS.d/next/Library/2017-11-12-20-47-59.bpo-32011.NzVDdZ.rst b/Misc/NEWS.d/next/Library/2017-11-12-20-47-59.bpo-32011.NzVDdZ.rst
new file mode 100644
index 00000000000..e2ba502c657
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-11-12-20-47-59.bpo-32011.NzVDdZ.rst
@@ -0,0 +1,2 @@
+Restored support of loading marshal files with the TYPE_INT64 code. These
+files can be produced in Python 2.7.
diff --git a/Python/marshal.c b/Python/marshal.c
index 22ca49c7562..91a57c293b0 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -32,6 +32,9 @@
#define TYPE_STOPITER 'S'
#define TYPE_ELLIPSIS '.'
#define TYPE_INT 'i'
+/* TYPE_INT64 is not generated anymore.
+ Supported for backward compatibility only. */
+#define TYPE_INT64 'I'
#define TYPE_FLOAT 'f'
#define TYPE_BINARY_FLOAT 'g'
#define TYPE_COMPLEX 'x'
@@ -777,6 +780,19 @@ r_long(RFILE *p)
return x;
}
+/* r_long64 deals with the TYPE_INT64 code. */
+static PyObject *
+r_long64(RFILE *p)
+{
+ const unsigned char *buffer = (const unsigned char *) r_string(8, p);
+ if (buffer == NULL) {
+ return NULL;
+ }
+ return _PyLong_FromByteArray(buffer, 8,
+ 1 /* little endian */,
+ 1 /* signed */);
+}
+
static PyObject *
r_PyLong(RFILE *p)
{
@@ -976,6 +992,11 @@ r_object(RFILE *p)
R_REF(retval);
break;
+ case TYPE_INT64:
+ retval = r_long64(p);
+ R_REF(retval);
+ break;
+
case TYPE_LONG:
retval = r_PyLong(p);
R_REF(retval);
More information about the Python-checkins
mailing list