[pypy-commit] cffi cffi-1.0: for now, we don't check the cdef value given in a "#define X Y"
arigo
noreply at buildbot.pypy.org
Fri Apr 24 16:12:29 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1803:ba730ccef0e0
Date: 2015-04-24 15:24 +0200
http://bitbucket.org/cffi/cffi/changeset/ba730ccef0e0/
Log: for now, we don't check the cdef value given in a "#define X Y"
diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -563,9 +563,7 @@
# ----------
# constants, declared with "static const ..."
- def _generate_cpy_const(self, is_int, name, tp=None, category='const',
- check_value=None):
- assert check_value is None # XXX
+ def _generate_cpy_const(self, is_int, name, tp=None, category='const'):
prnt = self._prnt
funcname = '_cffi_%s_%s' % (category, name)
if is_int:
@@ -603,7 +601,7 @@
# ----------
# enums
-
+
def _generate_cpy_enum_collecttype(self, tp, name):
self._do_collect_type(tp)
@@ -614,11 +612,9 @@
pass
def _generate_cpy_macro_decl(self, tp, name):
- if tp == '...':
- check_value = None
- else:
- check_value = tp # an integer
- self._generate_cpy_const(True, name, check_value=check_value)
+ # for now, we ignore the value (if != ',,,') given in the cdef
+ # and always trust the value coming from the C compiler
+ self._generate_cpy_const(True, name)
def _generate_cpy_macro_ctx(self, tp, name):
self._lsts["global"].append(
diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -1,4 +1,4 @@
-import py
+import sys, py
from cffi import FFI
from _cffi1 import recompiler
@@ -160,6 +160,18 @@
assert lib.FOOBAR == -6912
py.test.raises(AttributeError, "lib.FOOBAR = 2")
+def test_macro_check_value_ok():
+ ffi = FFI()
+ ffi.cdef("#define FOOBAR 42")
+ lib = verify(ffi, 'test_macro_check_value_ok', "#define FOOBAR 42")
+ assert lib.FOOBAR == 42
+
+def test_macro_check_value_fail():
+ ffi = FFI()
+ ffi.cdef("#define FOOBAR 42")
+ lib = verify(ffi, 'test_macro_check_value_fail', "#define FOOBAR 43")
+ assert lib.FOOBAR == 43 # for now, we don't check the cdef value
+
def test_constant():
ffi = FFI()
ffi.cdef("static const int FOOBAR;")
@@ -251,6 +263,17 @@
assert ffi1.typeof("void(*)(struct foo_s*)") is not (
ffi2.typeof("void(*)(struct foo_s*)"))
+def test_verify_enum():
+ py.test.skip("in-progress")
+ ffi = FFI()
+ ffi.cdef("""enum e1 { B1, A1, ... };""")
+ lib = verify(ffi, 'test_verify_enum',
+ "enum e1 { A1, B1, C1=%d };" % sys.maxint)
+ ffi.typeof("enum e1")
+ assert lib.A1 == 0
+ assert lib.B1 == 0
+ assert ffi.sizeof("enum e1") == ffi.sizeof("long")
+
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