[pypy-commit] pypy py3.5: Create W_IntObject instead of W_LongObject from space.newlong_from_rbigint()
rlamy
pypy.commits at gmail.com
Thu Apr 5 20:01:09 EDT 2018
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r94256:0af136eb60af
Date: 2018-04-06 00:59 +0100
http://bitbucket.org/pypy/pypy/changeset/0af136eb60af/
Log: Create W_IntObject instead of W_LongObject from
space.newlong_from_rbigint() whenever possible.
In particular, make sure that unmarshalling an int constant that
fits in 64 bits gives a W_IntObject. Fixes #2785.
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
@@ -229,7 +229,7 @@
BadReader(marshal.dumps(value)))
- at pytest.mark.skipif('config.option.runappdirect')
+ at pytest.mark.skipif('config.option.runappdirect or sys.maxint > 2 ** 32')
class AppTestSmallLong(AppTestMarshal):
spaceconfig = AppTestMarshal.spaceconfig.copy()
spaceconfig["objspace.std.withsmalllong"] = True
diff --git a/pypy/module/marshal/test/test_marshalimpl.py b/pypy/module/marshal/test/test_marshalimpl.py
--- a/pypy/module/marshal/test/test_marshalimpl.py
+++ b/pypy/module/marshal/test/test_marshalimpl.py
@@ -1,5 +1,6 @@
from pypy.module.marshal import interp_marshal
from pypy.interpreter.error import OperationError
+from pypy.objspace.std.intobject import W_IntObject
import sys
@@ -100,3 +101,15 @@
for i in range(100):
_marshal_check(sign * ((1L << i) - 1L))
_marshal_check(sign * (1L << i))
+
+def test_int_roundtrip(space):
+ a = 0xffffffff
+ w_a = space.newint(a)
+ m = interp_marshal.StringMarshaller(space, 4)
+ interp_marshal.marshal(space, w_a, m)
+ s = m.get_value()
+ u = interp_marshal.StringUnmarshaller(space, space.newbytes(s))
+ w_res = u.load_w_obj()
+
+ assert type(w_res) is W_IntObject
+ assert w_res.intval == w_a.intval == a
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -312,7 +312,10 @@
return W_LongObject.fromrarith_int(val)
def newlong_from_rbigint(self, val):
- return newlong(self, val)
+ try:
+ return self.newint(val.toint())
+ except OverflowError:
+ return newlong(self, val)
def newtuple(self, list_w):
from pypy.objspace.std.tupleobject import wraptuple
More information about the pypy-commit
mailing list