[pypy-svn] pypy default: Fix for smalllong: make more systematically sure that the created
arigo
commits-noreply at bitbucket.org
Sat Feb 5 14:09:09 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41633:1bae24f77155
Date: 2011-02-05 14:08 +0100
http://bitbucket.org/pypy/pypy/changeset/1bae24f77155/
Log: Fix for smalllong: make more systematically sure that the created
long objects are W_SmallLongs if possible, by using systematically
newlong() instead of directly W_LongObject().
diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py
--- a/pypy/objspace/std/longobject.py
+++ b/pypy/objspace/std/longobject.py
@@ -32,8 +32,8 @@
def toint(self):
return self.num.toint()
- def fromfloat(f):
- return W_LongObject(rbigint.fromfloat(f))
+ def fromfloat(space, f):
+ return newlong(space, rbigint.fromfloat(f))
fromfloat = staticmethod(fromfloat)
def fromlong(l):
diff --git a/pypy/objspace/std/inttype.py b/pypy/objspace/std/inttype.py
--- a/pypy/objspace/std/inttype.py
+++ b/pypy/objspace/std/inttype.py
@@ -82,8 +82,8 @@
except ParseStringError, e:
raise OperationError(space.w_ValueError,
space.wrap(e.msg))
- from pypy.objspace.std.longobject import W_LongObject
- return W_LongObject(bigint)
+ from pypy.objspace.std.longobject import newlong
+ return newlong(space, bigint)
def descr__new__(space, w_inttype, w_x=0, w_base=gateway.NoneNotWrapped):
from pypy.objspace.std.intobject import W_IntObject
diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py
--- a/pypy/objspace/std/test/test_floatobject.py
+++ b/pypy/objspace/std/test/test_floatobject.py
@@ -39,7 +39,7 @@
from pypy.objspace.std.longobject import W_LongObject
space = self.space
saved = W_LongObject.__dict__['fromfloat']
- W_LongObject.fromfloat = lambda x: disabled
+ W_LongObject.fromfloat = lambda space, x: disabled
try:
w_i = space.wrap(12)
w_f = space.wrap(12.3)
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
@@ -28,7 +28,7 @@
from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std.ropeobject import W_RopeObject
from pypy.objspace.std.typeobject import W_TypeObject
-from pypy.objspace.std.longobject import W_LongObject
+from pypy.objspace.std.longobject import W_LongObject, newlong
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
@@ -265,7 +265,7 @@
if digits[-1] == 0:
raise_exception(space, 'bad marshal data')
result = rbigint(digits, sign)
- w_long = W_LongObject(result)
+ w_long = newlong(space, result)
return w_long
register(TYPE_LONG, unmarshal_Long)
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
@@ -17,6 +17,7 @@
f.seek(0)
x = marshal.load(f)
assert x == case and type(x) is type(case)
+ return x
def test_None(self):
case = None
@@ -179,3 +180,18 @@
from pypy.conftest import gettestobjspace
cls.space = gettestobjspace(**{"objspace.std.withrope": True})
AppTestMarshal.setup_class.im_func(cls)
+
+class AppTestSmallLong(AppTestMarshal):
+ def setup_class(cls):
+ from pypy.conftest import gettestobjspace
+ cls.space = gettestobjspace(**{"objspace.std.withsmalllong": True})
+ AppTestMarshal.setup_class.im_func(cls)
+
+ def test_smalllong(self):
+ import __pypy__
+ x = -123456789012345L
+ assert 'SmallLong' in __pypy__.internal_repr(x)
+ y = self.marshal_check(x)
+ assert y == x
+ # must be unpickled as a small long
+ assert 'SmallLong' in __pypy__.internal_repr(y)
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -74,7 +74,7 @@
def long__Float(space, w_floatobj):
try:
- return W_LongObject.fromfloat(w_floatobj.floatval)
+ return W_LongObject.fromfloat(space, w_floatobj.floatval)
except OverflowError:
if isnan(w_floatobj.floatval):
raise OperationError(
@@ -288,7 +288,7 @@
except OverflowError:
# Convert to long and use its hash.
try:
- w_lval = W_LongObject.fromfloat(v)
+ w_lval = W_LongObject.fromfloat(space, v)
except OverflowError:
# can't convert to long int -- arbitrary
if v < 0:
@@ -530,7 +530,7 @@
break
float_part *= 2.0
exp -= 1
- w_num = W_LongObject.fromfloat(float_part)
+ w_num = W_LongObject.fromfloat(space, float_part)
w_den = space.newlong(1)
w_exp = space.newlong(abs(exp))
w_exp = space.lshift(w_den, w_exp)
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
@@ -22,7 +22,7 @@
from pypy.objspace.std.floatobject import W_FloatObject
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.listobject import W_ListObject
-from pypy.objspace.std.longobject import W_LongObject
+from pypy.objspace.std.longobject import W_LongObject, newlong
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.objectobject import W_ObjectObject
from pypy.objspace.std.ropeobject import W_RopeObject
@@ -292,7 +292,7 @@
return W_LongObject.fromint(self, val)
def newlong_from_rbigint(self, val):
- return W_LongObject(val)
+ return newlong(self, val)
def newtuple(self, list_w):
assert isinstance(list_w, list)
More information about the Pypy-commit
mailing list