[pypy-svn] r46002 - in pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem: . test

fijal at codespeak.net fijal at codespeak.net
Sun Aug 26 23:45:36 CEST 2007


Author: fijal
Date: Sun Aug 26 23:45:35 2007
New Revision: 46002

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py
Log:
A preliminary version of implicit casting in llexternal. More types should
go there


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py	Sun Aug 26 23:45:35 2007
@@ -9,6 +9,8 @@
 from pypy.rlib import rarithmetic
 from pypy.rpython.rbuiltin import parse_kwds
 from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rlib.unroll import unrolling_iterable
+from pypy.tool.sourcetools import func_with_new_name
 import os
 
 class CConstant(Symbolic):
@@ -41,7 +43,17 @@
                                  canraise=canraise)  
     if isinstance(_callable, ll2ctypes.LL2CtypesCallable):
         _callable.funcptr = funcptr
-    return funcptr
+
+    unrolling_arg_tps = unrolling_iterable(enumerate(args))
+    def wrapper(*args):
+        real_args = ()
+        for i, tp in unrolling_arg_tps:
+            if tp is USHORT:
+                real_args = real_args + (cast(tp, args[i]),)
+            else:
+                real_args = real_args + (args[i],)
+        return funcptr(*real_args)
+    return func_with_new_name(wrapper, name)
 
 from pypy.rpython.tool.rfficache import platform
 

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py	Sun Aug 26 23:45:35 2007
@@ -6,6 +6,12 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.udir import udir
 from pypy.rpython.test.test_llinterp import interpret
+from pypy.annotation.annrpython import RPythonAnnotator
+from pypy.rpython.rtyper import RPythonTyper
+from pypy.translator.backendopt.all import backend_optimizations
+from pypy.translator.translator import graphof
+from pypy.conftest import option
+from pypy.objspace.flow.model import summary
 
 def test_basic():
     c_source = py.code.Source("""
@@ -302,3 +308,22 @@
         return p.c_one
     assert f() == 3
     assert interpret(f, []) == 3
+
+def test_implicit_cast():
+    z = llexternal('z', [USHORT], USHORT)
+
+    def f():
+        return z(3)
+
+    a = RPythonAnnotator()
+    r = a.build_types(f, [])
+    rtyper = RPythonTyper(a)
+    rtyper.specialize()
+    a.translator.rtyper = rtyper
+    backend_optimizations(a.translator)
+    if option.view:
+        a.translator.view()
+    graph = graphof(a.translator, f)
+    s = summary(graph)
+    # there should be not too many operations here by now
+    assert s.keys() == ['direct_call']



More information about the Pypy-commit mailing list