[pypy-commit] pypy cffi-1.0: next include test passing

arigo noreply at buildbot.pypy.org
Fri May 8 17:56:03 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r77222:1814131f1188
Date: 2015-05-08 17:36 +0200
http://bitbucket.org/pypy/pypy/changeset/1814131f1188/

Log:	next include test passing

diff --git a/pypy/module/_cffi_backend/cffi1_module.py b/pypy/module/_cffi_backend/cffi1_module.py
--- a/pypy/module/_cffi_backend/cffi1_module.py
+++ b/pypy/module/_cffi_backend/cffi1_module.py
@@ -31,6 +31,8 @@
 
     ffi = W_FFIObject(space, src_ctx)
     lib = W_LibObject(ffi, name)
+    if src_ctx.c_includes:
+        lib.make_includes_from(src_ctx.c_includes)
 
     w_name = space.wrap(name)
     module = Module(space, w_name)
diff --git a/pypy/module/_cffi_backend/lib_obj.py b/pypy/module/_cffi_backend/lib_obj.py
--- a/pypy/module/_cffi_backend/lib_obj.py
+++ b/pypy/module/_cffi_backend/lib_obj.py
@@ -25,6 +25,20 @@
     def descr_repr(self):
         return self.space.wrap("<Lib object for '%s'>" % self.libname)
 
+    def make_includes_from(self, c_includes):
+        space = self.space
+        num = 0
+        includes = []
+        while c_includes[num]:
+            include_name = rffi.charp2str(c_includes[num])
+            w_lib1 = space.appexec([space.wrap(include_name)], """(modname):
+                mod = __import__(modname, None, None, ['ffi', 'lib'])
+                return mod.lib""")
+            lib1 = space.interp_w(W_LibObject, w_lib1)
+            includes.append(lib1)
+            num += 1
+        self.includes = includes[:]
+
     @jit.elidable_promote()
     def _get_attr_elidable(self, attr):
         try:
@@ -32,6 +46,10 @@
         except KeyError:
             index = parse_c_type.search_in_globals(self.ctx, attr)
             if index < 0:
+                for lib1 in self.includes:
+                    w_result = lib1._get_attr_elidable(attr)
+                    if w_result is not None:
+                        return w_result
                 return None     # no active caching, but still @elidable
 
             space = self.space
diff --git a/pypy/module/_cffi_backend/test/test_recompiler.py b/pypy/module/_cffi_backend/test/test_recompiler.py
--- a/pypy/module/_cffi_backend/test/test_recompiler.py
+++ b/pypy/module/_cffi_backend/test/test_recompiler.py
@@ -484,14 +484,16 @@
             includes=[ffi1])
         assert lib.ff1(0) == 42.5
 
-    def test_include_1b():
-        ffi1 = FFI()
-        ffi1.cdef("int foo1(int);")
-        verify(ffi1, "test_include_1b_parent", "int foo1(int x) { return x + 10; }")
-        ffi = FFI()
-        ffi.include(ffi1)
-        ffi.cdef("int foo2(int);")
-        lib = verify(ffi, "test_include_1b", "int foo2(int x) { return x - 5; }")
+    def test_include_1b(self):
+        ffi1, lib1 = self.prepare(
+            "int foo1(int);",
+            "test_include_1b_parent",
+            "int foo1(int x) { return x + 10; }")
+        ffi, lib = self.prepare(
+            "int foo2(int);",
+            "test_include_1b",
+            "int foo2(int x) { return x - 5; }",
+            includes=[ffi1])
         assert lib.foo2(42) == 37
         assert lib.foo1(42) == 52
 


More information about the pypy-commit mailing list