[pypy-commit] cffi cffi-1.0: anonymous enums

arigo noreply at buildbot.pypy.org
Fri Apr 24 18:01:24 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1807:779034948ac1
Date: 2015-04-24 18:01 +0200
http://bitbucket.org/cffi/cffi/changeset/779034948ac1/

Log:	anonymous enums

diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -616,23 +616,20 @@
                 '  { "%s", _cffi_const_%s, %s },' % (enumerator, enumerator,
                                                      type_op))
         #
-        if cname is not None:
+        if cname is not None and '$' not in cname:
             size = "sizeof(%s)" % cname
             signed = "((%s)-1) <= 0" % cname
-            prim = "_cffi_prim_int(%s, %s)" % (size, signed)
-            allenums = ",".join(tp.enumerators)
         else:
-            size = xxxx
+            basetp = tp.build_baseinttype(self.ffi, [])
+            size = self.ffi.sizeof(basetp)
+            signed = int(int(self.ffi.cast(basetp, -1)) < 0)
+        allenums = ",".join(tp.enumerators)
         self._lsts["enum"].append(
-            '  { "%s", %d, %s,\n    "%s" },' % (tp.name, type_index,
-                                                prim, allenums))
+            '  { "%s", %d, _cffi_prim_int(%s, %s),\n'
+            '    "%s" },' % (tp.name, type_index, size, signed, allenums))
 
     def _generate_cpy_enum_ctx(self, tp, name):
-        if tp.has_c_name():
-            cname = tp.get_c_name('')
-        else:
-            cname = None
-        self._enum_ctx(tp, cname)
+        self._enum_ctx(tp, tp._get_c_name())
 
     # ----------
     # macros: for now only for integers
diff --git a/_cffi1/test_verify1.py b/_cffi1/test_verify1.py
--- a/_cffi1/test_verify1.py
+++ b/_cffi1/test_verify1.py
@@ -697,9 +697,10 @@
     ffi.cdef("enum ee { EE1, EE2, EE3 };")
     ffi.verify("enum ee { EE1, EE2, EE3 };")
     py.test.raises(VerificationError, ffi.verify, "enum ee { EE1, EE2 };")
-    e = py.test.raises(VerificationError, ffi.verify,
-                       "enum ee { EE1, EE3, EE2 };")
-    assert str(e.value) == 'enum ee: EE2 has the real value 2, not 1'
+    # disabled: for now, we always accept and fix transparently constant values
+    #e = py.test.raises(VerificationError, ffi.verify,
+    #                   "enum ee { EE1, EE3, EE2 };")
+    #assert str(e.value) == 'enum ee: EE2 has the real value 2, not 1'
     # extra items cannot be seen and have no bad consequence anyway
     lib = ffi.verify("enum ee { EE1, EE2, EE3, EE4 };")
     assert lib.EE3 == 2


More information about the pypy-commit mailing list