[pypy-svn] r59981 - in pypy/branch/oo-jit/pypy/rpython: . lltypesystem/test

arigo at codespeak.net arigo at codespeak.net
Tue Nov 18 15:28:08 CET 2008


Author: arigo
Date: Tue Nov 18 15:28:06 2008
New Revision: 59981

Modified:
   pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
   pypy/branch/oo-jit/pypy/rpython/rtyper.py
   pypy/branch/oo-jit/pypy/rpython/typesystem.py
Log:
Remember the void constants in calls made by getcallable().


Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	Tue Nov 18 15:28:06 2008
@@ -11,6 +11,8 @@
 from pypy.rlib import rposix
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.tool.udir import udir
+from pypy.annotation.annrpython import RPythonAnnotator
+from pypy.rpython.rtyper import RPythonTyper
 
 class TestLL2Ctypes(object):
 
@@ -879,3 +881,20 @@
         fn3 = ctypes2lltype(lltype.Ptr(F), fn2)
         fn3(-5)
         assert ftest == [-5, -5, -5]
+
+    def test_c_callback_with_void_arg_3(self):
+        import pypy
+        def f(i):
+            x = 'X' * i
+            return x[-2]
+        a = RPythonAnnotator()
+        r = a.build_types(f, [int])
+        rtyper = RPythonTyper(a)
+        rtyper.specialize()
+        a.translator.rtyper = rtyper
+        graph = a.translator.graphs[0]
+        op = graph.startblock.operations[-1]
+        assert op.opname == 'direct_call'
+        assert op.args[0].value._obj._callable == pypy.rpython.lltypesystem.rstr.LLHelpers.ll_stritem.im_func
+        assert op.args[1].value == pypy.rpython.lltypesystem.rstr.LLHelpers
+        assert op.args[3].value == -2

Modified: pypy/branch/oo-jit/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/rtyper.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/rtyper.py	Tue Nov 18 15:28:06 2008
@@ -616,11 +616,11 @@
         cls = clsdef.classdesc.pyobj
         return self.classes_with_wrapper[cls], self.wrapper_context
 
-    def getcallable(self, graph):
+    def getcallable(self, graph, setup=None):
         def getconcretetype(v):
             return self.bindingrepr(v).lowleveltype
 
-        return self.type_system.getcallable(graph, getconcretetype)
+        return self.type_system.getcallable(graph, getconcretetype, setup)
 
     def annotate_helper(self, ll_function, argtypes):
         """Annotate the given low-level helper function and return its graph
@@ -879,6 +879,7 @@
         rtyper = self.rtyper
         args_s = []
         newargs_v = []
+        setup = []
         for v in args_v:
             if v.concretetype is Void:
                 s_value = rtyper.binding(v, default=annmodel.s_None)
@@ -887,8 +888,10 @@
                 if not isinstance(s_value, annmodel.SomePBC):
                     raise TyperError("non-PBC Void argument: %r", (s_value,))
                 args_s.append(s_value)
+                setup.append(s_value.const)
             else:
                 args_s.append(annmodel.lltype_to_annotation(v.concretetype))
+                setup.append(None)
             newargs_v.append(v)
         
         self.rtyper.call_all_setups()  # compute ForwardReferences now
@@ -898,6 +901,7 @@
             bk = rtyper.annotator.bookkeeper
             args_s.insert(0, bk.immutablevalue(ll_function.im_self))
             newargs_v.insert(0, inputconst(Void, ll_function.im_self))
+            setup.insert(0, ll_function.im_self)
             ll_function = ll_function.im_func
 
         graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s,
@@ -905,7 +909,7 @@
         self.record_extra_call(graph)
 
         # build the 'direct_call' operation
-        f = self.rtyper.getcallable(graph)
+        f = self.rtyper.getcallable(graph, setup)
         c = inputconst(typeOf(f), f)
         fobj = self.rtyper.type_system_deref(f)
         return self.genop('direct_call', [c]+newargs_v,

Modified: pypy/branch/oo-jit/pypy/rpython/typesystem.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/typesystem.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/typesystem.py	Tue Nov 18 15:28:06 2008
@@ -50,7 +50,7 @@
         cls = self.callable_trait[0]
         return cls(ARGS, RESTYPE)
         
-    def getcallable(self, graph, getconcretetype=None):
+    def getcallable(self, graph, getconcretetype=None, setup=None):
         """Return callable given a Python function."""
         if getconcretetype is None:
             getconcretetype = self.getconcretetype
@@ -58,7 +58,7 @@
         lloutput = getconcretetype(graph.getreturnvar())
 
         typ, constr = self.callable_trait
-        
+
         FT = typ(llinputs, lloutput)
         name = graph.name
         if hasattr(graph, 'func') and callable(graph.func):
@@ -75,11 +75,19 @@
                 fnobjattrs = {}
             # _callable is normally graph.func, but can be overridden:
             # see fakeimpl in extfunc.py
-            _callable = fnobjattrs.pop('_callable', graph.func)
-            return constr(FT, name, graph = graph, _callable = _callable,
-                          **fnobjattrs)
+            if '_callable' not in fnobjattrs:
+                fnobjattrs['_callable'] = graph.func
         else:
-            return constr(FT, name, graph = graph)
+            fnobjattrs = {}
+        if setup is not None:
+            setup_data = {}
+            for i, setup_i in enumerate(setup):
+                if setup_i is not None:
+                    setup_data[i] = setup_i
+            for i, ARGTYPE in enumerate(FT.ARGS):
+                if ARGTYPE is lltype.Void and i in setup_data:
+                    fnobjattrs['_void' + str(i)] = setup_data[i]
+        return constr(FT, name, graph = graph, **fnobjattrs)
 
     def getexternalcallable(self, ll_args, ll_result, name, **kwds):
         typ, constr = self.callable_trait



More information about the Pypy-commit mailing list