Author: Armin Rigo <[email protected]>
Branch:
Changeset: r53625:170dc1d7fae3
Date: 2012-03-14 17:05 -0700
http://bitbucket.org/pypy/pypy/changeset/170dc1d7fae3/
Log: space.wraplong() to have a non-RPython way to wrap a real long
object.
diff --git a/pypy/module/cpyext/test/test_longobject.py
b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -101,9 +101,9 @@
space.wrap((2, 7)))):
py.test.skip("unsupported before Python 2.7")
- assert api._PyLong_Sign(space.wrap(0L)) == 0
- assert api._PyLong_Sign(space.wrap(2L)) == 1
- assert api._PyLong_Sign(space.wrap(-2L)) == -1
+ assert api._PyLong_Sign(space.wraplong(0L)) == 0
+ assert api._PyLong_Sign(space.wraplong(2L)) == 1
+ assert api._PyLong_Sign(space.wraplong(-2L)) == -1
assert api._PyLong_NumBits(space.wrap(0)) == 0
assert api._PyLong_NumBits(space.wrap(1)) == 1
diff --git a/pypy/module/cpyext/test/test_number.py
b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -6,12 +6,12 @@
class TestIterator(BaseApiTest):
def test_check(self, space, api):
assert api.PyIndex_Check(space.wrap(12))
- assert api.PyIndex_Check(space.wrap(-12L))
+ assert api.PyIndex_Check(space.wraplong(-12L))
assert not api.PyIndex_Check(space.wrap(12.1))
assert not api.PyIndex_Check(space.wrap('12'))
assert api.PyNumber_Check(space.wrap(12))
- assert api.PyNumber_Check(space.wrap(-12L))
+ assert api.PyNumber_Check(space.wraplong(-12L))
assert api.PyNumber_Check(space.wrap(12.1))
assert not api.PyNumber_Check(space.wrap('12'))
assert not api.PyNumber_Check(space.wrap(1+3j))
@@ -21,7 +21,7 @@
assert api.PyLong_CheckExact(w_l)
def test_number_int(self, space, api):
- w_l = api.PyNumber_Int(space.wrap(123L))
+ w_l = api.PyNumber_Int(space.wraplong(123L))
assert api.PyInt_CheckExact(w_l)
w_l = api.PyNumber_Int(space.wrap(2 << 65))
assert api.PyLong_CheckExact(w_l)
@@ -29,7 +29,7 @@
assert api.PyInt_CheckExact(w_l)
def test_number_index(self, space, api):
- w_l = api.PyNumber_Index(space.wrap(123L))
+ w_l = api.PyNumber_Index(space.wraplong(123L))
assert api.PyLong_CheckExact(w_l)
w_l = api.PyNumber_Index(space.wrap(42.3))
assert w_l is None
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
@@ -217,17 +217,7 @@
# The following cases are even stranger.
# Really really only for tests.
if type(x) is long:
- if self.config.objspace.std.withsmalllong:
- from pypy.rlib.rarithmetic import r_longlong
- try:
- rx = r_longlong(x)
- except OverflowError:
- pass
- else:
- from pypy.objspace.std.smalllongobject import \
- W_SmallLongObject
- return W_SmallLongObject(rx)
- return W_LongObject.fromlong(x)
+ return self.wraplong(x)
if isinstance(x, slice):
return W_SliceObject(self.wrap(x.start),
self.wrap(x.stop),
@@ -268,6 +258,20 @@
return w_result
return None
+ def wraplong(self, x):
+ "NOT_RPYTHON"
+ if self.config.objspace.std.withsmalllong:
+ from pypy.rlib.rarithmetic import r_longlong
+ try:
+ rx = r_longlong(x)
+ except OverflowError:
+ pass
+ else:
+ from pypy.objspace.std.smalllongobject import \
+ W_SmallLongObject
+ return W_SmallLongObject(rx)
+ return W_LongObject.fromlong(x)
+
def unwrap(self, w_obj):
"""NOT_RPYTHON"""
if isinstance(w_obj, Wrappable):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit