Author: Brian Kearns <[email protected]>
Branch:
Changeset: r62663:5b912b8c74cf
Date: 2013-03-22 17:05 -0400
http://bitbucket.org/pypy/pypy/changeset/5b912b8c74cf/
Log: make sure smalllongobject can be unwrapped, add tests (thanks
xentac)
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
@@ -26,6 +26,9 @@
b = b.lshift(3).or_(rbigint.fromint(tag))
return space.newlong_from_rbigint(b)
+ def unwrap(w_self, space): #YYYYYY
+ return w_self.longval()
+
class W_LongObject(W_AbstractLongObject):
"""This is a wrapper of rbigint."""
@@ -42,9 +45,6 @@
def longval(self):
return self.num.tolong()
- def unwrap(w_self, space): #YYYYYY
- return w_self.longval()
-
def tofloat(self):
return self.num.tofloat()
diff --git a/pypy/objspace/std/smalllongobject.py
b/pypy/objspace/std/smalllongobject.py
--- a/pypy/objspace/std/smalllongobject.py
+++ b/pypy/objspace/std/smalllongobject.py
@@ -36,6 +36,9 @@
def asbigint(w_self):
return rbigint.fromrarith_int(w_self.longlong)
+ def longval(self):
+ return self.longlong
+
def __repr__(w_self):
return '<W_SmallLongObject(%d)>' % w_self.longlong
diff --git a/pypy/objspace/std/test/test_longobject.py
b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -15,6 +15,9 @@
w_obj = space.wrap(123.456)
space.raises_w(space.w_TypeError, space.bigint_w, w_obj)
+ w_obj = fromlong(42)
+ assert space.unwrap(w_obj) == 42
+
def test_rint_variants(self):
py.test.skip("XXX broken!")
from rpython.rtyper.tool.rfficache import platform
diff --git a/pypy/objspace/std/test/test_smalllongobject.py
b/pypy/objspace/std/test/test_smalllongobject.py
--- a/pypy/objspace/std/test/test_smalllongobject.py
+++ b/pypy/objspace/std/test/test_smalllongobject.py
@@ -39,6 +39,9 @@
wx = space.and_(w14000000000000, w_huge)
assert space.is_true(space.eq(wx, w14000000000000))
+ w_obj = W_SmallLongObject.fromint(42)
+ assert space.unwrap(w_obj) == 42
+
class AppTestSmallLong(test_longobject.AppTestLong):
spaceconfig = {"objspace.std.withsmalllong": True}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit