[pypy-commit] pypy default: Test and fix.
arigo
noreply at buildbot.pypy.org
Wed Aug 31 18:54:04 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r46951:98ae5e7b6751
Date: 2011-08-31 18:47 +0200
http://bitbucket.org/pypy/pypy/changeset/98ae5e7b6751/
Log: Test and fix.
diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py b/pypy/rpython/lltypesystem/ll2ctypes.py
--- a/pypy/rpython/lltypesystem/ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/ll2ctypes.py
@@ -1153,7 +1153,11 @@
# an OverflowError on the following line.
cvalue = ctypes.cast(ctypes.c_void_p(cvalue), cresulttype)
else:
- cvalue = cresulttype(cvalue).value # mask high bits off if needed
+ try:
+ cvalue = cresulttype(cvalue).value # mask high bits off if needed
+ except TypeError:
+ cvalue = int(cvalue) # float -> int
+ cvalue = cresulttype(cvalue).value # try again
return ctypes2lltype(RESTYPE, cvalue)
class ForceCastEntry(ExtRegistryEntry):
diff --git a/pypy/rpython/lltypesystem/test/test_rffi.py b/pypy/rpython/lltypesystem/test/test_rffi.py
--- a/pypy/rpython/lltypesystem/test/test_rffi.py
+++ b/pypy/rpython/lltypesystem/test/test_rffi.py
@@ -699,7 +699,10 @@
def test_cast(self):
res = cast(SIZE_T, -1)
assert type(res) is r_size_t
- assert res == r_size_t(-1)
+ assert res == r_size_t(-1)
+ #
+ res = cast(lltype.Signed, 42.5)
+ assert res == 42
def test_rffi_sizeof(self):
try:
More information about the pypy-commit
mailing list