[pypy-commit] cffi cffi-1.0: A clearer way to complain

arigo noreply at buildbot.pypy.org
Sat Apr 25 11:15:50 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1813:bdb89e5e392e
Date: 2015-04-25 11:16 +0200
http://bitbucket.org/cffi/cffi/changeset/bdb89e5e392e/

Log:	A clearer way to complain

diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -142,6 +142,7 @@
         #
         # call generate_cpy_xxx_decl(), for every xxx found from
         # ffi._parser._declarations.  This generates all the functions.
+        self._seen_constants = set()
         self._generate("decl")
         #
         # the declaration of '_cffi_globals' and '_cffi_typenames'
@@ -567,6 +568,11 @@
     # constants, declared with "static const ..."
 
     def _generate_cpy_const(self, is_int, name, tp=None, category='const'):
+        if (category, name) in self._seen_constants:
+            raise ffiplatform.VerificationError(
+                "duplicate declaration of %s '%s'" % (category, name))
+        self._seen_constants.add((category, name))
+        #
         prnt = self._prnt
         funcname = '_cffi_%s_%s' % (category, name)
         if is_int:
diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -1,5 +1,5 @@
 import sys, py
-from cffi import FFI
+from cffi import FFI, VerificationError
 from _cffi1 import recompiler
 
 
@@ -277,7 +277,13 @@
     assert lib.B2 == 1
     assert ffi.sizeof("enum e1") == ffi.sizeof("long")
     assert ffi.sizeof("enum e2") == ffi.sizeof("int")
- 
+
+def test_duplicate_enum():
+    ffi = FFI()
+    ffi.cdef("enum e1 { A1, ... }; enum e2 { A1, ... };")
+    py.test.raises(VerificationError, verify, ffi, 'test_duplicate_enum',
+                    "enum e1 { A1 }; enum e2 { B1 };")
+
 def test_dotdotdot_length_of_array_field():
     ffi = FFI()
     ffi.cdef("struct foo_s { int a[...]; int b[...]; };")


More information about the pypy-commit mailing list