[pypy-commit] pypy gmp: in-progress.

arigo noreply at buildbot.pypy.org
Thu Oct 20 17:59:18 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: gmp
Changeset: r48272:d81a2c7c6ca1
Date: 2011-10-20 17:58 +0200
http://bitbucket.org/pypy/pypy/changeset/d81a2c7c6ca1/

Log:	in-progress.

diff --git a/pypy/rlib/_rbigint_gmp.py b/pypy/rlib/_rbigint_gmp.py
--- a/pypy/rlib/_rbigint_gmp.py
+++ b/pypy/rlib/_rbigint_gmp.py
@@ -36,9 +36,15 @@
 # ____________________________________________________________
 
 
+ at specialize.argtype(0)
 def _fromint(value):
     r = lltype.malloc(RBIGINT)
-    mpz_init_set_si(r.mpz, value)
+    #
+    T = type(value)
+    if T is int or T is r_int:
+        mpz_init_set_si(r.mpz, value)
+    elif ...
+    
     return r
 
 def _str_base_10(r):
@@ -60,6 +66,11 @@
         return _fromint(int(b))    # maybe do some caching?
 
     @typeMethod
+    @specialize.argtype(1)
+    def fromrarith_int(RBIGINT, i):
+        return _fromint(widen(i))
+
+    @typeMethod
     def fromlong(RBIGINT, l):
         "NOT_RPYTHON"
         r = lltype.malloc(RBIGINT)
diff --git a/pypy/rlib/test/test_rbigint_gmp.py b/pypy/rlib/test/test_rbigint_gmp.py
--- a/pypy/rlib/test/test_rbigint_gmp.py
+++ b/pypy/rlib/test/test_rbigint_gmp.py
@@ -117,7 +117,6 @@
             yield -s
 
 def bigint(lst, sign):
-    XXX
     for digit in lst:
         assert digit & MASK == digit    # wrongly written test!
     return rbigint(map(_store_digit, lst), sign)
@@ -126,6 +125,7 @@
 class Test_rbigint(object):
 
     def test_args_from_long(self):
+        py.test.skip("not valid")
         BASE = 1 << SHIFT
         assert rbigint.fromlong(0).eq(bigint([0], 0))
         assert rbigint.fromlong(17).eq(bigint([17], 1))
@@ -139,7 +139,17 @@
 #        assert rbigint.fromlong(-sys.maxint-1).eq(
 #            rbigint.digits_for_most_neg_long(-sys.maxint-1), -1)
 
+    def test_args_from_int_simple(self):
+        IMAX = sys.maxint
+        LLMAX = r_longlong(2**63 - 1)
+        assert rbigint.fromrarith_int(-17).eq(rbigint.fromlong(-17))
+        assert rbigint.fromrarith_int(IMAX).eq(rbigint.fromlong(IMAX))
+        assert rbigint.fromrarith_int(LLMAX).eq(rbigint.fromlong(LLMAX))
+        assert rbigint.fromrarith_int(-IMAX-1).eq(rbigint.fromlong(-IMAX))
+        assert rbigint.fromrarith_int(-LLMAX-1).eq(rbigint.fromlong(-LLMAX-1))
+
     def test_args_from_int(self):
+        py.test.skip("not valid")
         BASE = 1 << SHIFT
         MAX = int(BASE-1)
         assert rbigint.fromrarith_int(0).eq(bigint([0], 0))


More information about the pypy-commit mailing list