[pypy-svn] r50641 - in pypy/branch/applevel-ctypes2/pypy/rlib: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Jan 15 17:26:28 CET 2008
Author: arigo
Date: Tue Jan 15 17:26:26 2008
New Revision: 50641
Modified:
pypy/branch/applevel-ctypes2/pypy/rlib/rarithmetic.py
pypy/branch/applevel-ctypes2/pypy/rlib/test/test_rarithmetic.py
Log:
(fijal, arigo)
Fix intmask() to work on r_somesmallintegerclass() too.
This should include r_int on 64-bit architectures.
Modified: pypy/branch/applevel-ctypes2/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/rlib/rarithmetic.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/rlib/rarithmetic.py Tue Jan 15 17:26:26 2008
@@ -60,10 +60,9 @@
def intmask(n):
if isinstance(n, int):
return int(n) # possibly bool->int
- if isinstance(n, unsigned_int):
- n = long(n)
- elif isinstance(n, objectmodel.Symbolic):
+ if isinstance(n, objectmodel.Symbolic):
return n # assume Symbolics don't overflow
+ n = long(n)
n &= LONG_MASK
if n >= LONG_TEST:
n -= 2*LONG_TEST
Modified: pypy/branch/applevel-ctypes2/pypy/rlib/test/test_rarithmetic.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/rlib/test/test_rarithmetic.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/rlib/test/test_rarithmetic.py Tue Jan 15 17:26:26 2008
@@ -184,6 +184,19 @@
assert intmask(r_uint(-1)) == -1
assert intmask(r_ulonglong(-1)) == -1
+def test_intmask_small():
+ from pypy.rpython.lltypesystem import rffi
+ for tp in [rffi.r_signedchar, rffi.r_short, rffi.r_int,
+ rffi.r_long, rffi.r_longlong]:
+ x = intmask(tp(5))
+ assert (type(x), x) == (int, 5)
+ x = intmask(tp(-5))
+ assert (type(x), x) == (int, -5)
+ for tp in [rffi.r_uchar, rffi.r_ushort, rffi.r_uint,
+ rffi.r_ulong, rffi.r_ulonglong]:
+ x = intmask(tp(5))
+ assert (type(x), x) == (int, 5)
+
def test_ovfcheck():
one = 1
x = sys.maxint
More information about the Pypy-commit
mailing list