Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.6
Changeset: r97422:5ec0fce493e7
Date: 2019-09-10 21:32 +0200
http://bitbucket.org/pypy/pypy/changeset/5ec0fce493e7/
Log: re-add support for unmarshalling TYPE_INT64, since there's now a
test for it in the CPython test suite
diff --git a/pypy/module/marshal/test/test_marshal.py
b/pypy/module/marshal/test/test_marshal.py
--- a/pypy/module/marshal/test/test_marshal.py
+++ b/pypy/module/marshal/test/test_marshal.py
@@ -250,6 +250,21 @@
raises(ValueError, marshal.loads, s)
run_tests(2**20, check)
+ def test_int64(self):
+ # another CPython test
+
+ import marshal
+ res = marshal.loads(b'I\xff\xff\xff\xff\xff\xff\xff\x7f')
+ assert res == 0x7fffffffffffffff
+ res = marshal.loads(b'I\xfe\xdc\xba\x98\x76\x54\x32\x10')
+ assert res == 0x1032547698badcfe
+ res = marshal.loads(b'I\x01\x23\x45\x67\x89\xab\xcd\xef')
+ assert res == -0x1032547698badcff
+ res = marshal.loads(b'I\x08\x19\x2a\x3b\x4c\x5d\x6e\x7f')
+ assert res == 0x7f6e5d4c3b2a1908
+ res = marshal.loads(b'I\xf7\xe6\xd5\xc4\xb3\xa2\x91\x80')
+ assert res == -0x7f6e5d4c3b2a1909
+
@pytest.mark.skipif('config.option.runappdirect or sys.maxint > 2 ** 32')
class AppTestSmallLong(AppTestMarshal):
spaceconfig = AppTestMarshal.spaceconfig.copy()
diff --git a/pypy/objspace/std/marshal_impl.py
b/pypy/objspace/std/marshal_impl.py
--- a/pypy/objspace/std/marshal_impl.py
+++ b/pypy/objspace/std/marshal_impl.py
@@ -50,6 +50,8 @@
FLAG_REF = 0x80 # bit added to mean "add obj to index"
FLAG_DONE = '\x00'
+TYPE_INT64 = 'I' # no longer generated
+
# the following typecodes have been added in version 4.
TYPE_ASCII = 'a' # never generated so far by pypy
TYPE_ASCII_INTERNED = 'A' # never generated so far by pypy
@@ -174,6 +176,20 @@
def unmarshal_int(space, u, tc):
return space.newint(u.get_int())
+@unmarshaller(TYPE_INT64)
+def unmarshal_int64(space, u, tc):
+ from rpython.rlib.rbigint import rbigint
+ # no longer generated, but we still support unmarshalling
+ lo = u.get_int() # get the first 32 bits
+ hi = u.get_int() # get the next 32 bits
+ if LONG_BIT >= 64:
+ x = (hi << 32) | (lo & (2**32-1)) # result fits in an int
+ return space.newint(x)
+ else:
+ x = (r_longlong(hi) << 32) | r_longlong(r_uint(lo)) # get a r_longlong
+ result = rbigint.fromrarith_int(x)
+ return space.newlong_from_rbigint(result)
+
@marshaller(W_AbstractLongObject)
def marshal_long(space, w_long, m):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit