[pypy-commit] cffi default: Revert a side-effect of f31f43f81992: allow again multiple declarations
arigo
noreply at buildbot.pypy.org
Tue Nov 18 11:34:20 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1574:22b3062ac3a9
Date: 2014-11-18 11:34 +0100
http://bitbucket.org/cffi/cffi/changeset/22b3062ac3a9/
Log: Revert a side-effect of f31f43f81992: allow again multiple
declarations of the same constant. Occurs in cases of ffi.include()
overuse.
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -208,6 +208,8 @@
def _add_constants(self, key, val):
if key in self._int_constants:
+ if self._int_constants[key] == val:
+ return # ignore identical double declarations
raise api.FFIError(
"multiple declarations of constant: %s" % (key,))
self._int_constants[key] = val
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -1,7 +1,7 @@
import py
import platform
import sys, ctypes
-from cffi import FFI, CDefError
+from cffi import FFI, CDefError, FFIError
from testing.support import *
SIZE_OF_INT = ctypes.sizeof(ctypes.c_int)
@@ -1564,6 +1564,12 @@
p = ffi2.new("foo_p", [142])
assert p.x == 142
+ def test_ignore_multiple_declarations_of_constant(self):
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("#define FOO 42")
+ ffi.cdef("#define FOO 42")
+ py.test.raises(FFIError, ffi.cdef, "#define FOO 43")
+
def test_struct_packed(self):
ffi = FFI(backend=self.Backend())
ffi.cdef("struct nonpacked { char a; int b; };")
More information about the pypy-commit
mailing list