[pypy-svn] r44204 - in pypy/branch/kill-ctypes/pypy/rpython/lltypesystem: . test

fijal at codespeak.net fijal at codespeak.net
Tue Jun 12 21:24:53 CEST 2007


Author: fijal
Date: Tue Jun 12 21:24:53 2007
New Revision: 44204

Modified:
   pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py
   pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py
Log:
A simple test and minor fix


Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py	Tue Jun 12 21:24:53 2007
@@ -18,12 +18,13 @@
     def lltype(self):
         return self.TP
 
-def llexternal(name, args, result, sources=[], includes=[], libraries=[]):
+def llexternal(name, args, result, _callable=None, sources=[], includes=[], libraries=[]):
     ext_type = lltype.FuncType(args, result)
     return lltype.functionptr(ext_type, name, external='C',
                               sources=tuple(sources),
                               includes=tuple(includes),
-                              libraries=tuple(libraries))
+                              libraries=tuple(libraries),
+                              _callable=_callable)
 
 def setup():
     """ creates necessary c-level types

Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py	(original)
+++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py	Tue Jun 12 21:24:53 2007
@@ -5,6 +5,7 @@
 from pypy.rpython.lltypesystem.lltype import Signed, Ptr, Char, malloc
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.udir import udir
+from pypy.rpython.test.test_llinterp import interpret
 
 def test_basic():
     c_source = """
@@ -162,3 +163,13 @@
     import errno
     assert gn() == errno.EBADF
 
+def test_external_callable():
+    """ Try to call some llexternal function with llinterp
+    """
+    z = llexternal('z', [Signed], Signed, _callable=lambda x:x+1)
+    
+    def f():
+        return z(2)
+
+    res = interpret(f, [])
+    assert res == 3



More information about the Pypy-commit mailing list