Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r49331:bef362009dda
Date: 2011-11-11 17:45 +0100
http://bitbucket.org/pypy/pypy/changeset/bef362009dda/

Log:    merge heads

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
@@ -1163,10 +1163,14 @@
         value = value.adr
     if isinstance(value, llmemory.fakeaddress):
         value = value.ptr or 0
+    if isinstance(value, r_singlefloat):
+        value = float(value)
     TYPE1 = lltype.typeOf(value)
     cvalue = lltype2ctypes(value)
     cresulttype = get_ctypes_type(RESTYPE)
-    if isinstance(TYPE1, lltype.Ptr):
+    if RESTYPE == TYPE1:
+        return value
+    elif isinstance(TYPE1, lltype.Ptr):
         if isinstance(RESTYPE, lltype.Ptr):
             # shortcut: ptr->ptr cast
             cptr = ctypes.cast(cvalue, cresulttype)
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,14 @@
         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)
+
+        res = cast(lltype.Float, r_singlefloat(12.))
+        assert res == 12.
+
     def test_rffi_sizeof(self):
         try:
             import ctypes
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to