Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r1864:bebb7929ea1f
Date: 2015-04-27 21:58 +0200
http://bitbucket.org/cffi/cffi/changeset/bebb7929ea1f/
Log: Basic idea: we ffi.include(baseffi), and baseffi must also be turned
into C code when ffi is. Then the name of the C module from baseffi
ends up written in the global data for ffi.
diff --git a/_cffi1/parse_c_type.h b/_cffi1/parse_c_type.h
--- a/_cffi1/parse_c_type.h
+++ b/_cffi1/parse_c_type.h
@@ -113,6 +113,7 @@
int num_struct_unions;
int num_enums;
int num_typenames;
+ const char * const *includes;
};
struct _cffi_parse_info_s {
diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -192,6 +192,19 @@
assert lst[i].startswith(' { "%s"' % tp.name)
assert len(lst) == len(self._enums)
#
+ # the declaration of '_cffi_includes'
+ if self.ffi._included_ffis:
+ prnt('static const char * const _cffi_includes[] = {')
+ for ffi_to_include in self.ffi._included_ffis:
+ if not hasattr(ffi_to_include, '_recompiler_module_name'):
+ raise ffiplatform.VerificationError(
+ "this ffi includes %r, but the latter has not been "
+ "turned into a C module" % (ffi_to_include,))
+ prnt(' "%s",' % (ffi_to_include._recompiler_module_name,))
+ prnt(' NULL')
+ prnt('};')
+ prnt()
+ #
# the declaration of '_cffi_type_context'
prnt('static const struct _cffi_type_context_s _cffi_type_context = {')
prnt(' _cffi_types,')
@@ -203,6 +216,10 @@
for step_name in ALL_STEPS:
if step_name != "field":
prnt(' %d, /* num_%ss */' % (nums[step_name], step_name))
+ if self.ffi._included_ffis:
+ prnt(' _cffi_includes,')
+ else:
+ prnt(' NULL, /* no includes */')
prnt('};')
prnt()
#
@@ -216,6 +233,7 @@
prnt(' _cffi_init_module("%s", &_cffi_type_context);' % (
self.module_name,))
prnt('}')
+ self.ffi._recompiler_module_name = self.module_name
# ----------
diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -456,7 +456,9 @@
lib.glob # does not crash
def test_include_1():
- ffi1 = FFI(); ffi1.cdef("typedef double foo_t;")
+ ffi1 = FFI()
+ ffi1.cdef("typedef double foo_t;")
+ verify(ffi1, "test_include_1_parent", "typedef double foo_t;")
ffi = FFI()
ffi.include(ffi1)
ffi.cdef("foo_t ff1(foo_t);")
@@ -464,7 +466,9 @@
assert lib.ff1(0) == 42.5
def test_include_2():
- ffi1 = FFI(); ffi1.cdef("struct foo_s { int x, y; };")
+ ffi1 = FFI()
+ ffi1.cdef("struct foo_s { int x, y; };")
+ verify(ffi1, "test_include_2_parent", "struct foo_s { int x, y; };")
ffi = FFI()
ffi.include(ffi1)
ffi.cdef("struct foo_s *ff2(struct foo_s *);")
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -70,6 +70,7 @@
self._function_caches = []
self._libraries = []
self._cdefsources = []
+ self._included_ffis = []
self._windows_unicode = None
if hasattr(backend, 'set_ffi'):
backend.set_ffi(self)
@@ -424,6 +425,7 @@
self._cdefsources.append('[')
self._cdefsources.extend(ffi_to_include._cdefsources)
self._cdefsources.append(']')
+ self._included_ffis.append(ffi_to_include)
def new_handle(self, x):
return self._backend.newp_handle(self.BVoidP, x)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit