[pypy-commit] cffi default: Test and fix (reported by sarvi)

arigo noreply at buildbot.pypy.org
Wed May 20 09:26:16 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2061:a0f4efcdb20b
Date: 2015-05-20 09:26 +0200
http://bitbucket.org/cffi/cffi/changeset/a0f4efcdb20b/

Log:	Test and fix (reported by sarvi)

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -604,19 +604,21 @@
 
     def _build_enum_type(self, explicit_name, decls):
         if decls is not None:
-            enumerators1 = [enum.name for enum in decls.enumerators]
-            enumerators = [s for s in enumerators1
-                             if not _r_enum_dotdotdot.match(s)]
-            partial = len(enumerators) < len(enumerators1)
-            enumerators = tuple(enumerators)
+            partial = False
+            enumerators = []
             enumvalues = []
             nextenumvalue = 0
-            for enum in decls.enumerators[:len(enumerators)]:
+            for enum in decls.enumerators:
+                if _r_enum_dotdotdot.match(enum.name):
+                    partial = True
+                    continue
                 if enum.value is not None:
                     nextenumvalue = self._parse_constant(enum.value)
+                enumerators.append(enum.name)
                 enumvalues.append(nextenumvalue)
                 self._add_constants(enum.name, nextenumvalue)
                 nextenumvalue += 1
+            enumerators = tuple(enumerators)
             enumvalues = tuple(enumvalues)
             tp = model.EnumType(explicit_name, enumerators, enumvalues)
             tp.partial = partial
diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py
--- a/testing/cffi0/test_verify.py
+++ b/testing/cffi0/test_verify.py
@@ -764,6 +764,11 @@
     assert ffi.string(ffi.cast('enum ee2', -1239)) == 'EE4'
     assert ffi.string(ffi.cast('enum ee2', -1238)) == 'EE5'
 
+def test_nonfull_enum_bug3():
+    ffi = FFI()
+    ffi.cdef("enum ee2 { EE4=..., EE5=... };")
+    ffi.cdef("enum ee6 { EE7=10, EE8=..., EE9=... };")
+
 def test_get_set_errno():
     ffi = FFI()
     ffi.cdef("int foo(int);")


More information about the pypy-commit mailing list