[pypy-commit] cffi cffi-1.0: Remove the dependency on the header files in _cffi1

arigo noreply at buildbot.pypy.org
Sat Apr 25 12:24:57 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1820:a721107bac60
Date: 2015-04-25 12:25 +0200
http://bitbucket.org/cffi/cffi/changeset/a721107bac60/

Log:	Remove the dependency on the header files in _cffi1

diff --git a/_cffi1/parse_c_type.c b/_cffi1/parse_c_type.c
--- a/_cffi1/parse_c_type.c
+++ b/_cffi1/parse_c_type.c
@@ -2,6 +2,8 @@
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
+
+#define _CFFI_INTERNAL
 #include "parse_c_type.h"
 
 
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
@@ -69,17 +69,18 @@
 struct _cffi_struct_union_s {
     const char *name;
     int type_index;          // -> _cffi_types, on a OP_STRUCT_UNION
-    int flags;               // CT_UNION?  CT_IS_OPAQUE?
+    int flags;               // CT_UNION?  CT_CUSTOM_FIELD_POS?
     size_t size;
     int alignment;
     int first_field_index;   // -> _cffi_fields array
     int num_fields;
 };
+#ifdef _CFFI_INTERNAL
 #define CT_UNION              128
-#define CT_IS_OPAQUE          4096
 #define CT_CUSTOM_FIELD_POS   32768
 /* ^^^ if not CUSTOM_FIELD_POS, complain if fields are not in the
    "standard layout" and/or if some are missing */
+#endif
 
 struct _cffi_field_s {
     const char *name;
@@ -122,8 +123,10 @@
     const char *error_message;
 };
 
+#ifdef _CFFI_INTERNAL
 int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
 int search_in_globals(const struct _cffi_type_context_s *ctx,
                       const char *search, size_t search_len);
 int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
                             const char *search, size_t search_len);
+#endif
diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -111,12 +111,21 @@
         # a KeyError here is a bug.  please report it! :-)
         return self._typesdict[type]
 
+    def _rel_readlines(self, filename):
+        g = open(os.path.join(os.path.dirname(__file__), filename), 'r')
+        lines = g.readlines()
+        g.close()
+        return lines
+
     def write_source_to_f(self, f, preamble):
         self._f = f
         prnt = self._prnt
         #
-        # first the '#include'
-        prnt('#include "_cffi_include.h"')
+        # first the '#include' (actually done by inlining the file's content)
+        lines = self._rel_readlines('_cffi_include.h')
+        i = lines.index('#include "parse_c_type.h"\n')
+        lines[i:i+1] = self._rel_readlines('parse_c_type.h')
+        prnt(''.join(lines))
         #
         # then paste the C source given by the user, verbatim.
         prnt('/************************************************************/')
@@ -447,12 +456,11 @@
 
     def _struct_ctx(self, tp, cname, approxname):
         type_index = self._typesdict[tp]
-        flags = []
+        flags = 0
         if tp.partial or tp.has_anonymous_struct_fields():
-            flags.append('CT_CUSTOM_FIELD_POS')
+            flags |= 32768  # CT_CUSTOM_FIELD_POS
         if isinstance(tp, model.UnionType):
-            flags.append('CT_UNION')
-        flags = ('|'.join(flags)) or '0'
+            flags |= 128    # CT_UNION
         if tp.fldtypes is not None:
             c_field = [approxname]
             enumfields = list(tp.enumfields())
@@ -494,7 +502,7 @@
         else:
             size_align = ' (size_t)-1, -1, -1, 0 /* opaque */ },'
         self._lsts["struct_union"].append(
-            '  { "%s", %d, %s,' % (tp.name, type_index, flags) + size_align)
+            '  { "%s", %d, 0x%x,' % (tp.name, type_index, flags) + size_align)
         self._seen_struct_unions.add(tp)
 
     def _add_missing_struct_unions(self):
@@ -744,8 +752,6 @@
 
 def _get_extension(module_name, c_file, kwds):
     source_name = ffiplatform.maybe_relative_path(c_file)
-    include_dirs = kwds.setdefault('include_dirs', [])
-    include_dirs.insert(0, '.')   # XXX
     return ffiplatform.get_extension(source_name, module_name, **kwds)
 
 def recompile(ffi, module_name, preamble, tmpdir='.', **kwds):
diff --git a/_cffi1/test_parse_c_type.py b/_cffi1/test_parse_c_type.py
--- a/_cffi1/test_parse_c_type.py
+++ b/_cffi1/test_parse_c_type.py
@@ -5,9 +5,11 @@
 
 r_macro = re.compile(r"#define \w+[(][^\n]*|#include [^\n]*")
 r_define = re.compile(r"(#define \w+) [^\n]*")
+r_ifdefs = re.compile(r"(#ifdef |#endif)[^\n]*")
 header = open('parse_c_type.h').read()
 header = r_macro.sub(r"", header)
 header = r_define.sub(r"\1 ...", header)
+header = r_ifdefs.sub(r"", header)
 
 ffi = cffi.FFI()
 ffi.cdef(header)


More information about the pypy-commit mailing list