[pypy-commit] pypy arm-backend-2: merge disable_merge_different_int_types
bivab
noreply at buildbot.pypy.org
Tue Nov 29 16:47:35 CET 2011
Author: David Schneider <david.schneider at picle.org>
Branch: arm-backend-2
Changeset: r49972:cbf05f6c40ef
Date: 2011-11-29 14:38 +0100
http://bitbucket.org/pypy/pypy/changeset/cbf05f6c40ef/
Log: merge disable_merge_different_int_types
diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -252,7 +252,26 @@
# unsignedness is considered a rare and contagious disease
def union((int1, int2)):
- knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
+ if int1.unsigned == int2.unsigned:
+ knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
+ else:
+ t1 = int1.knowntype
+ if t1 is bool:
+ t1 = int
+ t2 = int2.knowntype
+ if t2 is bool:
+ t2 = int
+
+ if t2 is int:
+ if int2.nonneg == False:
+ raise UnionError, "Merging %s and a possibly negative int is not allowed" % t1
+ knowntype = t1
+ elif t1 is int:
+ if int1.nonneg == False:
+ raise UnionError, "Merging %s and a possibly negative int is not allowed" % t2
+ knowntype = t2
+ else:
+ raise UnionError, "Merging these types (%s, %s) is not supported" % (t1, t2)
return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
knowntype=knowntype)
diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -591,13 +591,11 @@
immutable = True
def __init__(self, method):
self.method = method
-
-NUMBER = object()
+
annotation_to_ll_map = [
(SomeSingleFloat(), lltype.SingleFloat),
(s_None, lltype.Void), # also matches SomeImpossibleValue()
(s_Bool, lltype.Bool),
- (SomeInteger(knowntype=r_ulonglong), NUMBER),
(SomeFloat(), lltype.Float),
(SomeLongFloat(), lltype.LongFloat),
(SomeChar(), lltype.Char),
@@ -623,10 +621,11 @@
return lltype.Ptr(p.PARENTTYPE)
if isinstance(s_val, SomePtr):
return s_val.ll_ptrtype
+ if type(s_val) is SomeInteger:
+ return lltype.build_number(None, s_val.knowntype)
+
for witness, T in annotation_to_ll_map:
if witness.contains(s_val):
- if T is NUMBER:
- return lltype.build_number(None, s_val.knowntype)
return T
if info is None:
info = ''
@@ -635,7 +634,7 @@
raise ValueError("%sshould return a low-level type,\ngot instead %r" % (
info, s_val))
-ll_to_annotation_map = dict([(ll, ann) for ann, ll in annotation_to_ll_map if ll is not NUMBER])
+ll_to_annotation_map = dict([(ll, ann) for ann, ll in annotation_to_ll_map])
def lltype_to_annotation(T):
try:
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
@@ -856,6 +856,46 @@
py.test.raises(Exception, a.build_types, f, [])
# if you want to get a r_uint, you have to be explicit about it
+ def test_add_different_ints(self):
+ def f(a, b):
+ return a + b
+ a = self.RPythonAnnotator()
+ py.test.raises(Exception, a.build_types, f, [r_uint, int])
+
+ def test_merge_different_ints(self):
+ def f(a, b):
+ if a:
+ c = a
+ else:
+ c = b
+ return c
+ a = self.RPythonAnnotator()
+ py.test.raises(Exception, a.build_types, f, [r_uint, int])
+
+ def test_merge_ruint_zero(self):
+ def f(a):
+ if a:
+ c = a
+ else:
+ c = 0
+ return c
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [r_uint])
+ assert s == annmodel.SomeInteger(nonneg = True, unsigned = True)
+
+ def test_merge_ruint_nonneg_signed(self):
+ def f(a, b):
+ if a:
+ c = a
+ else:
+ assert b >= 0
+ c = b
+ return c
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [r_uint, int])
+ assert s == annmodel.SomeInteger(nonneg = True, unsigned = True)
+
+
def test_prebuilt_long_that_is_not_too_long(self):
small_constant = 12L
def f():
@@ -3029,7 +3069,7 @@
if g(x, y):
g(x, r_uint(y))
a = self.RPythonAnnotator()
- a.build_types(f, [int, int])
+ py.test.raises(Exception, a.build_types, f, [int, int])
def test_compare_with_zero(self):
def g():
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -10,7 +10,7 @@
from pypy.rlib.objectmodel import we_are_translated, instantiate
from pypy.rlib.jit import hint
from pypy.rlib.debug import make_sure_not_resized, check_nonneg
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, r_uint
from pypy.rlib import jit
from pypy.tool import stdlib_opcode
from pypy.tool.stdlib_opcode import host_bytecode_spec
@@ -167,7 +167,7 @@
# Execution starts just after the last_instr. Initially,
# last_instr is -1. After a generator suspends it points to
# the YIELD_VALUE instruction.
- next_instr = self.last_instr + 1
+ next_instr = r_uint(self.last_instr + 1)
if next_instr != 0:
self.pushvalue(w_inputvalue)
#
@@ -691,6 +691,7 @@
handlerposition = space.int_w(w_handlerposition)
valuestackdepth = space.int_w(w_valuestackdepth)
assert valuestackdepth >= 0
+ assert handlerposition >= 0
blk = instantiate(get_block_class(opname))
blk.handlerposition = handlerposition
blk.valuestackdepth = valuestackdepth
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -837,6 +837,7 @@
raise Yield
def jump_absolute(self, jumpto, next_instr, ec):
+ check_nonneg(jumpto)
return jumpto
def JUMP_FORWARD(self, jumpby, next_instr):
@@ -1278,7 +1279,7 @@
def handle(self, frame, unroller):
next_instr = self.really_handle(frame, unroller) # JIT hack
- return next_instr
+ return r_uint(next_instr)
def really_handle(self, frame, unroller):
""" Purely abstract method
diff --git a/pypy/jit/backend/llsupport/asmmemmgr.py b/pypy/jit/backend/llsupport/asmmemmgr.py
--- a/pypy/jit/backend/llsupport/asmmemmgr.py
+++ b/pypy/jit/backend/llsupport/asmmemmgr.py
@@ -37,25 +37,25 @@
self._add_free_block(smaller_stop, stop)
stop = smaller_stop
result = (start, stop)
- self.total_mallocs += stop - start
+ self.total_mallocs += r_uint(stop - start)
return result # pair (start, stop)
def free(self, start, stop):
"""Free a block (start, stop) returned by a previous malloc()."""
- self.total_mallocs -= (stop - start)
+ self.total_mallocs -= r_uint(stop - start)
self._add_free_block(start, stop)
def open_malloc(self, minsize):
"""Allocate at least minsize bytes. Returns (start, stop)."""
result = self._allocate_block(minsize)
(start, stop) = result
- self.total_mallocs += stop - start
+ self.total_mallocs += r_uint(stop - start)
return result
def open_free(self, middle, stop):
"""Used for freeing the end of an open-allocated block of memory."""
if stop - middle >= self.min_fragment:
- self.total_mallocs -= (stop - middle)
+ self.total_mallocs -= r_uint(stop - middle)
self._add_free_block(middle, stop)
return True
else:
@@ -77,7 +77,7 @@
# Hack to make sure that mcs are not within 32-bits of one
# another for testing purposes
rmmap.hint.pos += 0x80000000 - size
- self.total_memory_allocated += size
+ self.total_memory_allocated += r_uint(size)
data = rffi.cast(lltype.Signed, data)
return self._add_free_block(data, data + size)
diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -1053,35 +1053,20 @@
# jit.codewriter.support.
for _op, _oopspec in [('llong_invert', 'INVERT'),
- ('ullong_invert', 'INVERT'),
('llong_lt', 'LT'),
('llong_le', 'LE'),
('llong_eq', 'EQ'),
('llong_ne', 'NE'),
('llong_gt', 'GT'),
('llong_ge', 'GE'),
- ('ullong_lt', 'ULT'),
- ('ullong_le', 'ULE'),
- ('ullong_eq', 'EQ'),
- ('ullong_ne', 'NE'),
- ('ullong_gt', 'UGT'),
- ('ullong_ge', 'UGE'),
('llong_add', 'ADD'),
('llong_sub', 'SUB'),
('llong_mul', 'MUL'),
('llong_and', 'AND'),
('llong_or', 'OR'),
('llong_xor', 'XOR'),
- ('ullong_add', 'ADD'),
- ('ullong_sub', 'SUB'),
- ('ullong_mul', 'MUL'),
- ('ullong_and', 'AND'),
- ('ullong_or', 'OR'),
- ('ullong_xor', 'XOR'),
('llong_lshift', 'LSHIFT'),
('llong_rshift', 'RSHIFT'),
- ('ullong_lshift', 'LSHIFT'),
- ('ullong_rshift', 'URSHIFT'),
('cast_int_to_longlong', 'FROM_INT'),
('truncate_longlong_to_int', 'TO_INT'),
('cast_float_to_longlong', 'FROM_FLOAT'),
@@ -1104,6 +1089,21 @@
('cast_uint_to_ulonglong', 'FROM_UINT'),
('cast_float_to_ulonglong', 'FROM_FLOAT'),
('cast_ulonglong_to_float', 'U_TO_FLOAT'),
+ ('ullong_invert', 'INVERT'),
+ ('ullong_lt', 'ULT'),
+ ('ullong_le', 'ULE'),
+ ('ullong_eq', 'EQ'),
+ ('ullong_ne', 'NE'),
+ ('ullong_gt', 'UGT'),
+ ('ullong_ge', 'UGE'),
+ ('ullong_add', 'ADD'),
+ ('ullong_sub', 'SUB'),
+ ('ullong_mul', 'MUL'),
+ ('ullong_and', 'AND'),
+ ('ullong_or', 'OR'),
+ ('ullong_xor', 'XOR'),
+ ('ullong_lshift', 'LSHIFT'),
+ ('ullong_rshift', 'URSHIFT'),
]:
exec py.code.Source('''
def rewrite_op_%s(self, op):
@@ -1134,7 +1134,7 @@
def rewrite_op_llong_is_true(self, op):
v = varoftype(op.args[0].concretetype)
- op0 = SpaceOperation('cast_int_to_longlong',
+ op0 = SpaceOperation('cast_primitive',
[Constant(0, lltype.Signed)],
v)
args = [op.args[0], v]
diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -258,6 +258,9 @@
y = ~r_ulonglong(xll)
return u_to_longlong(y)
+def _ll_1_ullong_invert(xull):
+ return ~xull
+
def _ll_2_llong_lt(xll, yll):
return xll < yll
@@ -276,16 +279,22 @@
def _ll_2_llong_ge(xll, yll):
return xll >= yll
-def _ll_2_llong_ult(xull, yull):
+def _ll_2_ullong_eq(xull, yull):
+ return xull == yull
+
+def _ll_2_ullong_ne(xull, yull):
+ return xull != yull
+
+def _ll_2_ullong_ult(xull, yull):
return xull < yull
-def _ll_2_llong_ule(xull, yull):
+def _ll_2_ullong_ule(xull, yull):
return xull <= yull
-def _ll_2_llong_ugt(xull, yull):
+def _ll_2_ullong_ugt(xull, yull):
return xull > yull
-def _ll_2_llong_uge(xull, yull):
+def _ll_2_ullong_uge(xull, yull):
return xull >= yull
def _ll_2_llong_add(xll, yll):
@@ -312,14 +321,41 @@
z = r_ulonglong(xll) ^ r_ulonglong(yll)
return u_to_longlong(z)
+def _ll_2_ullong_add(xull, yull):
+ z = (xull) + (yull)
+ return (z)
+
+def _ll_2_ullong_sub(xull, yull):
+ z = (xull) - (yull)
+ return (z)
+
+def _ll_2_ullong_mul(xull, yull):
+ z = (xull) * (yull)
+ return (z)
+
+def _ll_2_ullong_and(xull, yull):
+ z = (xull) & (yull)
+ return (z)
+
+def _ll_2_ullong_or(xull, yull):
+ z = (xull) | (yull)
+ return (z)
+
+def _ll_2_ullong_xor(xull, yull):
+ z = (xull) ^ (yull)
+ return (z)
+
def _ll_2_llong_lshift(xll, y):
z = r_ulonglong(xll) << y
return u_to_longlong(z)
+def _ll_2_ullong_lshift(xull, y):
+ return xull << y
+
def _ll_2_llong_rshift(xll, y):
return xll >> y
-def _ll_2_llong_urshift(xull, y):
+def _ll_2_ullong_urshift(xull, y):
return xull >> y
def _ll_1_llong_from_int(x):
diff --git a/pypy/jit/metainterp/optimizeopt/fficall.py b/pypy/jit/metainterp/optimizeopt/fficall.py
--- a/pypy/jit/metainterp/optimizeopt/fficall.py
+++ b/pypy/jit/metainterp/optimizeopt/fficall.py
@@ -7,7 +7,7 @@
from pypy.rlib.libffi import Func
from pypy.rlib.objectmodel import we_are_translated
from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
-from pypy.rpython.lltypesystem import llmemory
+from pypy.rpython.lltypesystem import llmemory, rffi
class FuncInfo(object):
@@ -237,7 +237,7 @@
else:
assert False, "unsupported ffitype or kind"
#
- fieldsize = ffitype.c_size
+ fieldsize = rffi.getintfield(ffitype, 'c_size')
return self.optimizer.cpu.interiorfielddescrof_dynamic(
offset, width, fieldsize, is_pointer, is_float, is_signed
)
diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py
--- a/pypy/module/mmap/interp_mmap.py
+++ b/pypy/module/mmap/interp_mmap.py
@@ -3,7 +3,7 @@
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.gateway import interp2app, unwrap_spec, NoneNotWrapped
from pypy.rlib import rmmap
-from pypy.rlib.rmmap import RValueError, RTypeError, ROverflowError
+from pypy.rlib.rmmap import RValueError, RTypeError
class W_MMap(Wrappable):
@@ -212,8 +212,6 @@
raise OperationError(space.w_ValueError, space.wrap(e.message))
except RTypeError, e:
raise OperationError(space.w_TypeError, space.wrap(e.message))
- except ROverflowError, e:
- raise OperationError(space.w_OverflowError, space.wrap(e.message))
return space.wrap(self)
elif rmmap._MS_WINDOWS:
@@ -233,8 +231,6 @@
raise OperationError(space.w_ValueError, space.wrap(e.message))
except RTypeError, e:
raise OperationError(space.w_TypeError, space.wrap(e.message))
- except ROverflowError, e:
- raise OperationError(space.w_OverflowError, space.wrap(e.message))
return space.wrap(self)
W_MMap.typedef = TypeDef("mmap",
diff --git a/pypy/module/rctime/interp_time.py b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -3,7 +3,7 @@
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.gateway import unwrap_spec
from pypy.rpython.lltypesystem import lltype
-from pypy.rlib.rarithmetic import ovfcheck_float_to_int
+from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask
from pypy.rlib import rposix
from pypy.translator.tool.cbuild import ExternalCompilationInfo
import os
@@ -585,7 +585,7 @@
# More likely, the format yields an empty result,
# e.g. an empty format, or %Z when the timezone
# is unknown.
- result = rffi.charp2strn(outbuf, buflen)
+ result = rffi.charp2strn(outbuf, intmask(buflen))
return space.wrap(result)
finally:
lltype.free(outbuf, flavor='raw')
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -453,12 +453,12 @@
multi = r_uint(1822399083) + r_uint(1822399083) + 1
if w_set.hash != 0:
return space.wrap(w_set.hash)
- hash = 1927868237
- hash *= (len(w_set.setdata) + 1)
+ hash = r_uint(1927868237)
+ hash *= r_uint(len(w_set.setdata) + 1)
for w_item in w_set.setdata:
h = space.hash_w(w_item)
- value = ((h ^ (h << 16) ^ 89869747) * multi)
- hash = intmask(hash ^ value)
+ value = (r_uint(h ^ (h << 16) ^ 89869747) * multi)
+ hash = hash ^ value
hash = hash * 69069 + 907133923
if hash == 0:
hash = 590923713
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -143,7 +143,9 @@
return self_type
if self_type in (bool, int, long):
return other_type
- return build_int(None, self_type.SIGNED and other_type.SIGNED, max(self_type.BITS, other_type.BITS))
+ if self_type.SIGNED == other_type.SIGNED:
+ return build_int(None, self_type.SIGNED, max(self_type.BITS, other_type.BITS))
+ raise AssertionError, "Merging these types (%s, %s) is not supported" % (self_type, other_type)
def signedtype(t):
if t in (bool, int, long):
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -229,7 +229,7 @@
sign = self.sign
if intmask(x) < 0 and (sign > 0 or (x << 1) != 0):
raise OverflowError
- return intmask(x * sign)
+ return intmask(intmask(x) * sign)
def tolonglong(self):
return _AsLongLong(self)
@@ -1384,7 +1384,7 @@
# Now remove the excess 2 bits, rounding to nearest integer (with
# ties rounded to even).
- q = (q >> 2) + (bool(q & 2) and bool(q & 5))
+ q = (q >> 2) + r_uint((bool(q & 2) and bool(q & 5)))
if exp > DBL_MAX_EXP or (exp == DBL_MAX_EXP and
q == r_ulonglong(1) << DBL_MANT_DIG):
@@ -1540,8 +1540,8 @@
assert extra_bits == 2 or extra_bits == 3
# Round by remembering a modified copy of the low digit of x
- mask = 1 << (extra_bits - 1)
- low = x.udigit(0) | inexact
+ mask = r_uint(1 << (extra_bits - 1))
+ low = x.udigit(0) | r_uint(inexact)
if (low & mask) != 0 and (low & (3*mask-1)) != 0:
low += mask
x_digit_0 = low & ~(mask-1)
@@ -1790,7 +1790,7 @@
i = v.numdigits() - 1
while i >= 0:
prev = x
- x = (x << SHIFT) + v.widedigit(i)
+ x = (x << SHIFT) + r_ulonglong(v.widedigit(i))
if (x >> SHIFT) != prev:
raise OverflowError(
"long int too large to convert to unsigned long long int")
@@ -1833,8 +1833,8 @@
if x < v.udigit(i):
x += 1
i -= 1
- x = intmask(x * sign)
- return x
+ res = intmask(intmask(x) * sign)
+ return res
#_________________________________________________________________
diff --git a/pypy/rlib/rmmap.py b/pypy/rlib/rmmap.py
--- a/pypy/rlib/rmmap.py
+++ b/pypy/rlib/rmmap.py
@@ -23,10 +23,6 @@
def __init__(self, message):
self.message = message
-class ROverflowError(Exception):
- def __init__(self, message):
- self.message = message
-
includes = ["sys/types.h"]
if _POSIX:
includes += ['unistd.h', 'sys/mman.h']
@@ -597,8 +593,6 @@
def _check_map_size(size):
if size < 0:
raise RTypeError("memory mapped size must be positive")
- if rffi.cast(size_t, size) != size:
- raise ROverflowError("memory mapped size is too large (limited by C int)")
if _POSIX:
def mmap(fileno, length, flags=MAP_SHARED,
diff --git a/pypy/rlib/rrandom.py b/pypy/rlib/rrandom.py
--- a/pypy/rlib/rrandom.py
+++ b/pypy/rlib/rrandom.py
@@ -31,7 +31,7 @@
mt[0]= s & MASK_32
for mti in range(1, N):
mt[mti] = (MAGIC_CONSTANT_A *
- (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti)
+ (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + r_uint(mti))
# See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.
# In the previous versions, MSBs of the seed affect
# only MSBs of the array mt[].
@@ -52,7 +52,7 @@
for k in range(max_k, 0, -1):
mt[i] = ((mt[i] ^
((mt[i - 1] ^ (mt[i - 1] >> 30)) * MAGIC_CONSTANT_C))
- + init_key[j] + j) # non linear
+ + init_key[j] + r_uint(j)) # non linear
mt[i] &= MASK_32 # for WORDSIZE > 32 machines
i += 1
j += 1
@@ -104,5 +104,5 @@
j = n % i
mt[i], mt[j] = mt[j], mt[i]
for i in range(N):
- mt[i] += i + 1
+ mt[i] += r_uint(i + 1)
self.index = N
diff --git a/pypy/rlib/rsocket.py b/pypy/rlib/rsocket.py
--- a/pypy/rlib/rsocket.py
+++ b/pypy/rlib/rsocket.py
@@ -17,7 +17,7 @@
from pypy.rlib.objectmodel import instantiate, keepalive_until_here
from pypy.rlib import _rsocket_rffi as _c
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, r_uint
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rpython.lltypesystem.rffi import sizeof, offsetof
@@ -131,11 +131,12 @@
from_object = staticmethod(from_object)
@staticmethod
- def _check_port(space, port):
+ def make_ushort_port(space, port):
from pypy.interpreter.error import OperationError
if port < 0 or port > 0xffff:
raise OperationError(space.w_ValueError, space.wrap(
"port must be 0-65535."))
+ return rffi.cast(rffi.USHORT, port)
def fill_from_object(self, space, w_address):
""" Purely abstract
@@ -167,7 +168,7 @@
# IPv4 also supports the special name "<broadcast>".
if name == '<broadcast>':
- return makeipv4addr(intmask(INADDR_BROADCAST), result)
+ return makeipv4addr(r_uint(INADDR_BROADCAST), result)
# "dd.dd.dd.dd" format.
digits = name.split('.')
@@ -184,9 +185,11 @@
0 <= d1 <= 255 and
0 <= d2 <= 255 and
0 <= d3 <= 255):
- return makeipv4addr(intmask(htonl(
- (intmask(d0 << 24)) | (d1 << 16) | (d2 << 8) | (d3 << 0))),
- result)
+
+ addr = intmask(d0 << 24) | (d1 << 16) | (d2 << 8) | (d3 << 0)
+ addr = rffi.cast(rffi.UINT, addr)
+ addr = htonl(addr)
+ return makeipv4addr(addr, result)
# generic host name to IP conversion
info = getaddrinfo(name, None, family=family, address_to_fill=result)
@@ -236,7 +239,9 @@
def get_protocol(self):
a = self.lock(_c.sockaddr_ll)
- res = ntohs(rffi.getintfield(a, 'c_sll_protocol'))
+ proto = rffi.getintfield(a, 'c_sll_protocol')
+ proto = rffi.cast(rffi.USHORT, proto)
+ res = ntohs(proto)
self.unlock()
return res
@@ -277,6 +282,7 @@
def __init__(self, host, port):
makeipaddr(host, self)
a = self.lock(_c.sockaddr_in)
+ port = rffi.cast(rffi.USHORT, port)
rffi.setintfield(a, 'c_sin_port', htons(port))
self.unlock()
@@ -309,7 +315,7 @@
raise TypeError("AF_INET address must be a tuple of length 2")
host = space.str_w(w_host)
port = space.int_w(w_port)
- Address._check_port(space, port)
+ port = Address.make_ushort_port(space, port)
return INETAddress(host, port)
from_object = staticmethod(from_object)
@@ -318,7 +324,7 @@
from pypy.interpreter.error import OperationError
_, w_port = space.unpackiterable(w_address, 2)
port = space.int_w(w_port)
- self._check_port(space, port)
+ port = self.make_ushort_port(space, port)
a = self.lock(_c.sockaddr_in)
rffi.setintfield(a, 'c_sin_port', htons(port))
self.unlock()
@@ -403,7 +409,7 @@
"to 4, not %d" % len(pieces_w))
host = space.str_w(pieces_w[0])
port = space.int_w(pieces_w[1])
- Address._check_port(space, port)
+ port = Address.make_ushort_port(space, port)
if len(pieces_w) > 2: flowinfo = space.uint_w(pieces_w[2])
else: flowinfo = 0
if len(pieces_w) > 3: scope_id = space.uint_w(pieces_w[3])
@@ -419,7 +425,7 @@
raise RSocketError("AF_INET6 address must be a tuple of length 2 "
"to 4, not %d" % len(pieces_w))
port = space.int_w(pieces_w[1])
- self._check_port(space, port)
+ port = self.make_ushort_port(space, port)
if len(pieces_w) > 2: flowinfo = space.uint_w(pieces_w[2])
else: flowinfo = 0
if len(pieces_w) > 3: scope_id = space.uint_w(pieces_w[3])
@@ -1295,9 +1301,13 @@
servent = _c.getservbyname(name, proto)
if not servent:
raise RSocketError("service/proto not found")
- return ntohs(servent.c_s_port)
+ port = rffi.cast(rffi.UINT, servent.c_s_port)
+ return ntohs(port)
def getservbyport(port, proto=None):
+ # This function is only called from pypy/module/_socket and the range of
+ # port is checked there
+ port = rffi.cast(rffi.USHORT, port)
servent = _c.getservbyport(htons(port), proto)
if not servent:
raise RSocketError("port/proto not found")
diff --git a/pypy/rlib/rstruct/standardfmttable.py b/pypy/rlib/rstruct/standardfmttable.py
--- a/pypy/rlib/rstruct/standardfmttable.py
+++ b/pypy/rlib/rstruct/standardfmttable.py
@@ -206,7 +206,7 @@
if signed and i == 0 and x >= 128:
x -= 256
intvalue <<= 8
- intvalue |= x
+ intvalue |= inttype(x)
idx += 1
else:
for i in unroll_range_size:
diff --git a/pypy/rlib/test/test_rarithmetic.py b/pypy/rlib/test/test_rarithmetic.py
--- a/pypy/rlib/test/test_rarithmetic.py
+++ b/pypy/rlib/test/test_rarithmetic.py
@@ -126,13 +126,18 @@
cmp = f(r_uint(arg))
assert res == cmp
- def binary_test(self, f, rargs = None):
+ def binary_test(self, f, rargs = None, translated=False):
mask = maxint_mask
if not rargs:
rargs = (1, 3, 55)
+ # when translated merging different int types is not allowed
+ if translated:
+ alltypes = [(r_uint, r_uint)]
+ else:
+ alltypes = [(int, r_uint), (r_uint, int), (r_uint, r_uint)]
for larg in (0, 1, 2, 3, 1234):
for rarg in rargs:
- for types in ((int, r_uint), (r_uint, int), (r_uint, r_uint)):
+ for types in alltypes:
res = f(larg, rarg)
left, right = types
cmp = f(left(larg), right(rarg))
@@ -335,6 +340,14 @@
from pypy.rpython.lltypesystem.rffi import r_int_real
assert compute_restype(r_int_real, r_int_real) is r_int_real
+def test_compute_restype_incompatible():
+ from pypy.rpython.lltypesystem.rffi import r_int_real, r_short, r_ushort
+ testcases = [(r_uint, r_longlong), (r_int_real, r_uint),
+ (r_short, r_ushort)]
+ for t1, t2 in testcases:
+ py.test.raises(AssertionError, compute_restype, t1, t2)
+ py.test.raises(AssertionError, compute_restype, t2, t1)
+
def test_most_neg_value_of():
assert most_neg_value_of_same_type(123) == -sys.maxint-1
assert most_neg_value_of_same_type(r_uint(123)) == 0
diff --git a/pypy/rlib/test/test_rrandom.py b/pypy/rlib/test/test_rrandom.py
--- a/pypy/rlib/test/test_rrandom.py
+++ b/pypy/rlib/test/test_rrandom.py
@@ -1,4 +1,5 @@
from pypy.rlib.rrandom import Random, N, r_uint
+from pypy.rlib.rarithmetic import intmask
import _random
# the numbers were created by using CPython's _randommodule.c
@@ -24,13 +25,13 @@
def test_init_by_array():
rnd = Random()
- rnd.init_by_array([1, 2, 3, 4])
+ rnd.init_by_array([r_uint(n) for n in [1, 2, 3, 4]])
assert rnd.state[:14] == [2147483648, 1269538435, 699006892, 381364451,
172015551, 3237099449, 3609464087, 2187366456, 654585064,
2665903765, 3735624613, 1241943673, 2038528247, 3774211972]
# try arrays of various sizes to test for corner cases
for size in [N, N - 1, N + 1, N // 2, 2 * N]:
- rnd.init_by_array(range(N))
+ rnd.init_by_array([r_uint(n) for n in range(N)])
def test_jumpahead():
rnd = Random()
@@ -47,8 +48,8 @@
def f(x, y):
rnd = Random(x)
rnd.init_by_array([x, y])
- rnd.jumpahead(y)
+ rnd.jumpahead(intmask(y))
return rnd.genrand32(), rnd.random()
t = Translation(f)
- fc = t.compile_c([int, int])
- assert fc(1, 2) == f(1, 2)
+ fc = t.compile_c([r_uint, r_uint])
+ assert fc(r_uint(1), r_uint(2)) == f(r_uint(1), r_uint(2))
diff --git a/pypy/rpython/memory/gc/minimark.py b/pypy/rpython/memory/gc/minimark.py
--- a/pypy/rpython/memory/gc/minimark.py
+++ b/pypy/rpython/memory/gc/minimark.py
@@ -711,7 +711,7 @@
#
# Record the newly allocated object and its full malloced size.
# The object is young or old depending on the argument.
- self.rawmalloced_total_size += allocsize
+ self.rawmalloced_total_size += r_uint(allocsize)
if can_make_young:
if not self.young_rawmalloced_objects:
self.young_rawmalloced_objects = self.AddressDict()
@@ -886,8 +886,8 @@
#return (num_bits + (LONG_BIT - 1)) >> LONG_BIT_SHIFT
# --- Optimized version:
return intmask(
- ((r_uint(length) + ((LONG_BIT << self.card_page_shift) - 1)) >>
- (self.card_page_shift + LONG_BIT_SHIFT)))
+ ((r_uint(length) + r_uint((LONG_BIT << self.card_page_shift) - 1)) >>
+ (self.card_page_shift + LONG_BIT_SHIFT)))
def card_marking_bytes_for_length(self, length):
# --- Unoptimized version:
@@ -895,7 +895,7 @@
#return (num_bits + 7) >> 3
# --- Optimized version:
return intmask(
- ((r_uint(length) + ((8 << self.card_page_shift) - 1)) >>
+ ((r_uint(length) + r_uint((8 << self.card_page_shift) - 1)) >>
(self.card_page_shift + 3)))
def debug_check_consistency(self):
@@ -1523,7 +1523,7 @@
llarena.arena_reserve(arena, totalsize)
#
size_gc_header = self.gcheaderbuilder.size_gc_header
- self.rawmalloced_total_size += raw_malloc_usage(totalsize)
+ self.rawmalloced_total_size += r_uint(raw_malloc_usage(totalsize))
self.old_rawmalloced_objects.append(arena + size_gc_header)
return arena
@@ -1689,7 +1689,7 @@
allocsize += extra_words * WORD
#
llarena.arena_free(arena)
- self.rawmalloced_total_size -= allocsize
+ self.rawmalloced_total_size -= r_uint(allocsize)
def free_unvisited_rawmalloc_objects(self):
list = self.old_rawmalloced_objects
diff --git a/pypy/rpython/memory/gc/minimarkpage.py b/pypy/rpython/memory/gc/minimarkpage.py
--- a/pypy/rpython/memory/gc/minimarkpage.py
+++ b/pypy/rpython/memory/gc/minimarkpage.py
@@ -149,7 +149,7 @@
ll_assert(nsize > 0, "malloc: size is null or negative")
ll_assert(nsize <= self.small_request_threshold,"malloc: size too big")
ll_assert((nsize & (WORD-1)) == 0, "malloc: size is not aligned")
- self.total_memory_used += nsize
+ self.total_memory_used += r_uint(nsize)
#
# Get the page to use from the size
size_class = nsize >> WORD_POWER_2
@@ -474,7 +474,7 @@
obj += block_size
#
# Update the global total size of objects.
- self.total_memory_used += surviving * block_size
+ self.total_memory_used += r_uint(surviving * block_size)
#
# Return the number of surviving objects.
return surviving
diff --git a/pypy/rpython/module/ll_termios.py b/pypy/rpython/module/ll_termios.py
--- a/pypy/rpython/module/ll_termios.py
+++ b/pypy/rpython/module/ll_termios.py
@@ -72,9 +72,14 @@
def tcsetattr_llimpl(fd, when, attributes):
c_struct = lltype.malloc(TERMIOSP.TO, flavor='raw')
- c_struct.c_c_iflag, c_struct.c_c_oflag, c_struct.c_c_cflag, \
- c_struct.c_c_lflag, ispeed, ospeed, cc = attributes
try:
+ c_struct.c_c_iflag = r_uint(attributes[0])
+ c_struct.c_c_oflag = r_uint(attributes[1])
+ c_struct.c_c_cflag = r_uint(attributes[2])
+ c_struct.c_c_lflag = r_uint(attributes[3])
+ ispeed = r_uint(attributes[4])
+ ospeed = r_uint(attributes[5])
+ cc = attributes[6]
for i in range(NCCS):
c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i][0]))
if c_cfsetispeed(c_struct, ispeed) < 0:
@@ -87,8 +92,8 @@
lltype.free(c_struct, flavor='raw')
r_uint = rffi.r_uint
-register_external(rtermios.tcsetattr, [int, int, (r_uint, r_uint, r_uint,
- r_uint, r_uint, r_uint, [str])], llimpl=tcsetattr_llimpl,
+register_external(rtermios.tcsetattr, [int, int, (int, int, int,
+ int, int, int, [str])], llimpl=tcsetattr_llimpl,
export_name='termios.tcsetattr')
# a bit C-c C-v code follows...
diff --git a/pypy/translator/c/test/test_lltyped.py b/pypy/translator/c/test/test_lltyped.py
--- a/pypy/translator/c/test/test_lltyped.py
+++ b/pypy/translator/c/test/test_lltyped.py
@@ -476,12 +476,13 @@
def f(n):
result = ()
for cls in classes:
+ nn = cls(n)
for OP in operators:
x = getmin(cls)
- res1 = OP(x, n)
+ res1 = OP(x, nn)
result = result + (res1,)
x = getmax(cls)
- res1 = OP(x, n)
+ res1 = OP(x, nn)
result = result + (res1,)
return result
diff --git a/pypy/translator/c/test/test_standalone.py b/pypy/translator/c/test/test_standalone.py
--- a/pypy/translator/c/test/test_standalone.py
+++ b/pypy/translator/c/test/test_standalone.py
@@ -224,7 +224,7 @@
filename = str(udir.join('test_standalone_largefile'))
r4800000000 = r_longlong(4800000000L)
def entry_point(argv):
- assert str(r4800000000 + len(argv)) == '4800000003'
+ assert str(r4800000000 + r_longlong(len(argv))) == '4800000003'
fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0644)
os.lseek(fd, r4800000000, 0)
newpos = os.lseek(fd, 0, 1)
diff --git a/pypy/translator/c/test/test_typed.py b/pypy/translator/c/test/test_typed.py
--- a/pypy/translator/c/test/test_typed.py
+++ b/pypy/translator/c/test/test_typed.py
@@ -261,7 +261,7 @@
f._annspecialcase_ = "specialize:argtype(0)"
def g(n):
if n > 0:
- return f(r_longlong(0))
+ return intmask(f(r_longlong(0)))
else:
return f(0)
diff --git a/pypy/translator/jvm/test/test_rarithmetic.py b/pypy/translator/jvm/test/test_rarithmetic.py
--- a/pypy/translator/jvm/test/test_rarithmetic.py
+++ b/pypy/translator/jvm/test/test_rarithmetic.py
@@ -32,7 +32,7 @@
cache[types] = fun
return cache[types](x, y)
return f(x,y)
- super(BaseAdaptedTest,self).binary_test(new_func, rargs)
+ super(BaseAdaptedTest,self).binary_test(new_func, rargs, translated=True)
class Test_r_uint(BaseAdaptedTest, BaseTest_r_uint):
RTYPE = ra.r_uint
More information about the pypy-commit
mailing list