[pypy-commit] pypy default: truncate python longs also when converting to unsigned types
antocuni
noreply at buildbot.pypy.org
Tue Jul 12 11:06:55 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r45500:0022eb161caa
Date: 2011-07-12 11:02 +0200
http://bitbucket.org/pypy/pypy/changeset/0022eb161caa/
Log: truncate python longs also when converting to unsigned types
diff --git a/pypy/module/_ffi/interp_ffi.py b/pypy/module/_ffi/interp_ffi.py
--- a/pypy/module/_ffi/interp_ffi.py
+++ b/pypy/module/_ffi/interp_ffi.py
@@ -149,11 +149,12 @@
raise OperationError(space.w_TypeError, space.wrap(msg))
return res
-def unwrap_truncate_int(space, w_arg):
+def unwrap_truncate_int(TP, space, w_arg):
if space.is_true(space.isinstance(w_arg, space.w_int)):
- return space.int_w(w_arg)
+ return rffi.cast(TP, space.int_w(w_arg))
else:
- return rffi.cast(rffi.LONG, space.bigint_w(w_arg).ulonglongmask())
+ return rffi.cast(TP, space.bigint_w(w_arg).ulonglongmask())
+unwrap_truncate_int._annspecialcase_ = 'specialize:arg(0)'
# ========================================================================
@@ -189,12 +190,12 @@
kind = libffi.types.getkind(w_argtype.ffitype) # XXX: remove the kind
self.arg_longlong(space, argchain, kind, w_arg)
elif w_argtype.is_signed():
- argchain.arg(unwrap_truncate_int(space, w_arg))
+ argchain.arg(unwrap_truncate_int(rffi.LONG, space, w_arg))
elif w_argtype.is_pointer():
w_arg = self.convert_pointer_arg_maybe(space, w_arg, w_argtype)
argchain.arg(intmask(space.uint_w(w_arg)))
elif w_argtype.is_unsigned():
- argchain.arg(intmask(space.uint_w(w_arg)))
+ argchain.arg(unwrap_truncate_int(rffi.ULONG, space, w_arg))
elif w_argtype.is_char():
w_arg = space.ord(w_arg)
argchain.arg(space.int_w(w_arg))
diff --git a/pypy/module/_ffi/test/test__ffi.py b/pypy/module/_ffi/test/test__ffi.py
--- a/pypy/module/_ffi/test/test__ffi.py
+++ b/pypy/module/_ffi/test/test__ffi.py
@@ -111,7 +111,6 @@
types.double)
assert pow(2, 3) == 8
-
def test_int_args(self):
"""
DLLEXPORT int sum_xy(int x, int y)
@@ -249,6 +248,9 @@
types.ulong)
assert sum_xy(sys.maxint, 12) == sys.maxint+12
assert sum_xy(sys.maxint+1, 12) == sys.maxint+13
+ #
+ res = sum_xy(sys.maxint*2+3, 0)
+ assert res == 1
def test_unsigned_short_args(self):
"""
More information about the pypy-commit
mailing list