[pypy-commit] cffi default: Issue #113: Test and fix: Values of anonymous enums are not exposed

arigo noreply at buildbot.pypy.org
Sat Oct 26 09:10:30 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r1381:fae3707c5431
Date: 2013-10-26 09:10 +0200
http://bitbucket.org/cffi/cffi/changeset/fae3707c5431/

Log:	Issue #113: Test and fix: Values of anonymous enums are not exposed

diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -378,6 +378,12 @@
         self.baseinttype = baseinttype
         self.build_c_name_with_marker()
 
+    def force_the_name(self, forcename):
+        StructOrUnionOrEnum.force_the_name(self, forcename)
+        if self.forcename is None:
+            name = self.get_official_name()
+            self.forcename = '$' + name.replace(' ', '_')
+
     def check_not_partial(self):
         if self.partial and not self.partial_resolved:
             from . import ffiplatform
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -616,6 +616,21 @@
     s.x = 17
     assert s.x == 17
 
+def test_anonymous_enum():
+    ffi = FFI()
+    ffi.cdef("enum { EE1 }; enum { EE2, EE3 };")
+    lib = ffi.verify("enum { EE1 }; enum { EE2, EE3 };")
+    assert lib.EE1 == 0
+    assert lib.EE2 == 0
+    assert lib.EE3 == 1
+
+def test_nonfull_anonymous_enum():
+    ffi = FFI()
+    ffi.cdef("enum { EE1, ... }; enum { EE3, ... };")
+    lib = ffi.verify("enum { EE2, EE1 }; enum { EE3 };")
+    assert lib.EE1 == 1
+    assert lib.EE3 == 0
+
 def test_nonfull_enum_syntax2():
     ffi = FFI()
     ffi.cdef("enum ee { EE1, EE2=\t..., EE3 };")


More information about the pypy-commit mailing list