Commits

Greg Price  committed f53b6d3

signature: support pointer types

  • Participants
  • Parent commits 4134223

Comments (0)

Files changed (2)

File pypy/rlib/test/test_signature.py

 from pypy.rlib import types
 from pypy.annotation import model
 from pypy.translator.translator import TranslationContext, graphof
+from pypy.rpython.lltypesystem import rstr
+from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
 
 
-def annotate_at(f):
+def annotate_at(f, policy=None):
     t = TranslationContext()
-    a = t.buildannotator()
-    a.annotate_helper(f, [model.s_ImpossibleValue]*f.func_code.co_argcount)
+    a = t.buildannotator(policy=policy)
+    a.annotate_helper(f, [model.s_ImpossibleValue]*f.func_code.co_argcount, policy=policy)
     return a
 
 def sigof(a, f):
     g = graphof(a.translator, f)
     return [a.bindings[v] for v in g.startblock.inputargs] + [a.bindings[g.getreturnvar()]]
 
-def getsig(f):
-    a = annotate_at(f)
+def getsig(f, policy=None):
+    a = annotate_at(f, policy=policy)
     return sigof(a, f)
 
 def check_annotator_fails(caller):
     assert getsig(f) == [model.SomeUnicodeString(), model.SomeInteger()]
 
 
+def test_ptr():
+    policy = LowLevelAnnotatorPolicy()
+    @signature(types.ptr(rstr.STR), returns=types.none())
+    def f(buf):
+        pass
+    argtype = getsig(f, policy=policy)[0]
+    assert isinstance(argtype, model.SomePtr)
+    assert argtype.ll_ptrtype.TO == rstr.STR
+
+    def g():
+        f(rstr.mallocstr(10))
+    getsig(g, policy=policy)
+
+
 def test_list():
     @signature(types.list(types.int()), returns=types.int())
     def f(a):

File pypy/rlib/types.py

     return model.SomeChar()
 
 
+def ptr(ll_type):
+    from pypy.rpython.lltypesystem.lltype import Ptr
+    return model.SomePtr(Ptr(ll_type))
+
+
 def list(element):
     listdef = ListDef(None, element, mutated=True, resized=True)
     return model.SomeList(listdef)