Author: Dario Bertini <berda...@gmail.com> Branch: int32on64-experiment Changeset: r45224:2e960c5fb5c2 Date: 2011-07-01 12:14 +0200 http://bitbucket.org/pypy/pypy/changeset/2e960c5fb5c2/
Log: Bunch of misc. changes diff --git a/pypy/annotation/bookkeeper.py b/pypy/annotation/bookkeeper.py --- a/pypy/annotation/bookkeeper.py +++ b/pypy/annotation/bookkeeper.py @@ -332,9 +332,7 @@ return result if tp is bool: result = SomeBool() - elif tp is int: - result = SomeInteger(nonneg = x>=0) - elif tp is long: + elif tp is int or tp is long: if -sys.maxint-1 <= x <= sys.maxint: x = int(x) result = SomeInteger(nonneg = x>=0) diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py --- a/pypy/annotation/test/test_annrpython.py +++ b/pypy/annotation/test/test_annrpython.py @@ -849,7 +849,7 @@ assert s == annmodel.SomeInteger(nonneg = True, unsigned = True) def test_large_unsigned(self): - large_constant = sys.maxint * 2 + 1 # 0xFFFFFFFF on 32-bit platforms + large_constant = 2**64-1 # 0xFFFFFFFF on 32-bit platforms def f(): return large_constant a = self.RPythonAnnotator() diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py --- a/pypy/rlib/rarithmetic.py +++ b/pypy/rlib/rarithmetic.py @@ -41,7 +41,7 @@ _bits = 0 _itest = 1 _Ltest = 1L -while _itest == _Ltest and type(_itest) is int: +while _itest == _Ltest and _itest <= sys.maxint: _itest *= 2 _Ltest *= 2 _bits += 1 @@ -59,11 +59,11 @@ assert LONG_BIT_SHIFT < 99, "LONG_BIT_SHIFT value not found?" def intmask(n): - if isinstance(n, int): - return int(n) # possibly bool->int if isinstance(n, objectmodel.Symbolic): return n # assume Symbolics don't overflow assert not isinstance(n, float) + if -sys.maxint -1 < n < sys.maxint: + return int(n) n = long(n) n &= LONG_MASK if n >= LONG_TEST: @@ -107,8 +107,8 @@ # raise OverflowError if the operation did overflow assert not isinstance(r, r_uint), "unexpected ovf check on unsigned" assert not isinstance(r, r_longlong), "ovfcheck not supported on r_longlong" - assert not isinstance(r,r_ulonglong),"ovfcheck not supported on r_ulonglong" - if type(r) is long: + assert not isinstance(r, r_ulonglong), "ovfcheck not supported on r_ulonglong" + if r > sys.maxint or r < -sys.maxint - 1: raise OverflowError, "signed integer expression did overflow" return r @@ -116,7 +116,7 @@ # a copy of the above, because we cannot call ovfcheck # in a context where no primitiveoperator is involved. assert not isinstance(r, r_uint), "unexpected ovf check on unsigned" - if isinstance(r, long): + if r > sys.maxint or r < -sys.maxint - 1: raise OverflowError, "signed integer expression did overflow" return r diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py --- a/pypy/rpython/lltypesystem/rffi.py +++ b/pypy/rpython/lltypesystem/rffi.py @@ -904,11 +904,11 @@ offsetof._annspecialcase_ = 'specialize:memo' # check that we have a sane configuration -assert sys.maxint == (1 << (8 * sizeof(lltype.Signed) - 1)) - 1, ( - "Mixed configuration of the word size of the machine:\n\t" - "the underlying Python was compiled with maxint=%d,\n\t" - "but the C compiler says that 'long' is %d bytes" % ( - sys.maxint, sizeof(lltype.Signed))) +#assert sys.maxint == (1 << (8 * sizeof(lltype.Signed) - 1)) - 1, ( + #"Mixed configuration of the word size of the machine:\n\t" + #"the underlying Python was compiled with maxint=%d,\n\t" + #"but the C compiler says that 'long' is %d bytes" % ( + #sys.maxint, sizeof(lltype.Signed))) # ********************** some helpers ******************* diff --git a/pypy/rpython/test/test_rint.py b/pypy/rpython/test/test_rint.py --- a/pypy/rpython/test/test_rint.py +++ b/pypy/rpython/test/test_rint.py @@ -389,12 +389,32 @@ return objectmodel.compute_hash(x) res = self.interpret(f, [123456789]) assert res == 123456789 - res = self.interpret(f, [r_int64(123456789012345678)]) - if sys.maxint == 2147483647: + num = r_int64(123456789012345678) + res = self.interpret(f, [num]) + if isinstance(num, r_longlong): # check the way we compute such a hash so far assert res == -1506741426 + 9 * 28744523 else: assert res == 123456789012345678 + + def test_strange_behaviour(self): + def f(x): + return objectmodel.compute_hash(x) + + #happened on 64bit when changing sys.maxint + old_maxint = sys.maxint + sys.maxint = 2**31-1 + num1 = r_int64(2**32 - 1) + num2 = r_int64(2**32) + + interpreted_res = self.interpret(f, [num1]) + res = f(num1) + sys.maxint = old_maxint + assert res == interpreted_res + + interpreted_res = self.interpret(f, [num2]) + res = f(num2) + assert res == interpreted_res def test_int_between(self): def fn(a, b, c): diff --git a/pypy/test_all.py b/pypy/test_all.py --- a/pypy/test_all.py +++ b/pypy/test_all.py @@ -11,6 +11,8 @@ """ import sys, os +sys.maxint = (2**31)-1 + if len(sys.argv) == 1 and os.path.dirname(sys.argv[0]) in '.': print >> sys.stderr, __doc__ sys.exit(2) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit