[pypy-commit] pypy default: Fix for rffi.cast(lltype.SingleFloat, <some r_singlefloat>), if the input type is the same as the restype, just retunr the obj.

alex_gaynor noreply at buildbot.pypy.org
Fri Nov 11 17:25:47 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r49325:a780603cc0b5
Date: 2011-11-11 11:22 -0500
http://bitbucket.org/pypy/pypy/changeset/a780603cc0b5/

Log:	Fix for rffi.cast(lltype.SingleFloat, <some r_singlefloat>), if the
	input type is the same as the restype, just retunr the obj.

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
@@ -1179,6 +1179,8 @@
         cvalue = ord(cvalue)     # character -> integer
     elif hasattr(RESTYPE, "_type") and issubclass(RESTYPE._type, base_int):
         cvalue = int(cvalue)
+    elif RESTYPE is TYPE1:
+        return value
 
     if not isinstance(cvalue, (int, long, float)):
         raise NotImplementedError("casting %r to %r" % (TYPE1, RESTYPE))
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
@@ -18,6 +18,7 @@
 from pypy.conftest import option
 from pypy.objspace.flow.model import summary
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.rlib.rarithmetic import r_singlefloat
 
 class BaseTestRffi:
     def test_basic(self):
@@ -704,6 +705,11 @@
         res = cast(lltype.Signed, 42.5)
         assert res == 42
     
+        res = cast(lltype.SingleFloat, 12.3)
+        assert res == r_singlefloat(12.3)
+        res = cast(lltype.SingleFloat, res)
+        assert res == r_singlefloat(12.3)
+
     def test_rffi_sizeof(self):
         try:
             import ctypes


More information about the pypy-commit mailing list