[pypy-commit] cffi cffi-1.0: Copy from vengine_cpy

arigo noreply at buildbot.pypy.org
Sat Apr 18 17:58:41 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1766:947a567c3565
Date: 2015-04-18 17:59 +0200
http://bitbucket.org/cffi/cffi/changeset/947a567c3565/

Log:	Copy from vengine_cpy

diff --git a/new/recompiler.py b/new/recompiler.py
--- a/new/recompiler.py
+++ b/new/recompiler.py
@@ -400,11 +400,31 @@
                 self._do_collect_type(self._field_type(tp, name1, tp1))
 
     def _generate_cpy_struct_decl(self, tp, name):
-        if tp.fldtypes is not None:
-            prnt = self._prnt
-            prnt("struct _cffi_align_%s { char x; %s %s y; };" % (
-                name, tp.kind, name))
-            prnt()
+        if tp.fldtypes is None:
+            return
+        cname = ('%s %s' % (tp.kind, name)).strip()
+        prnt = self._prnt
+        checkfuncname = '_cffi_checkfld_%s' % (name,)
+        prnt('__attribute__((unused))')
+        prnt('static void %s(%s *p)' % (checkfuncname, cname))
+        prnt('{')
+        prnt('  /* only to generate compile-time warnings or errors */')
+        prnt('  (void)p;')
+        for fname, ftype, fbitsize in tp.enumfields():
+            if (isinstance(ftype, model.PrimitiveType)
+                and ftype.is_integer_type()) or fbitsize >= 0:
+                # accept all integers, but complain on float or double
+                prnt('  (void)((p->%s) << 1);' % fname)
+            else:
+                # only accept exactly the type declared.
+                try:
+                    prnt('  { %s = &p->%s; (void)tmp; }' % (
+                        ftype.get_c_name('*tmp', 'field %r'%fname), fname))
+                except ffiplatform.VerificationError as e:
+                    prnt('  /* %s */' % str(e))   # cannot verify it, ignore
+        prnt('}')
+        prnt('struct _cffi_align_%s { char x; %s y; };' % (name, cname))
+        prnt()
 
     def _generate_cpy_struct_ctx(self, tp, name):
         type_index = self._typesdict[tp]


More information about the pypy-commit mailing list