Author: Armin Rigo <ar...@tunes.org> Branch: cpy-extension Changeset: r322:33174f82d210 Date: 2012-06-14 11:06 +0200 http://bitbucket.org/cffi/cffi/changeset/33174f82d210/
Log: - One more step in the test. - Add some more tests. diff --git a/cffi/cparser.py b/cffi/cparser.py --- a/cffi/cparser.py +++ b/cffi/cparser.py @@ -3,6 +3,7 @@ import pycparser, weakref, re _r_partial_enum = re.compile(r"\.\.\.\s*\}") +_r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$") _parser_cache = None def _get_parser(): @@ -303,16 +304,22 @@ if key in self._declarations: return self._declarations[key] if decls is not None: - enumerators = tuple([enum.name for enum in decls.enumerators]) + enumerators = [enum.name for enum in decls.enumerators] + partial = False + if enumerators and _r_enum_dotdotdot.match(enumerators[-1]): + enumerators.pop() + partial = True + enumerators = tuple(enumerators) enumvalues = [] nextenumvalue = 0 - for enum in decls.enumerators: + for enum in decls.enumerators[:len(enumerators)]: if enum.value is not None: nextenumvalue = self._parse_constant(enum.value) enumvalues.append(nextenumvalue) nextenumvalue += 1 enumvalues = tuple(enumvalues) tp = model.EnumType(name, enumerators, enumvalues) + tp.partial = partial self._declare(key, tp) else: # opaque enum enumerators = () diff --git a/cffi/model.py b/cffi/model.py --- a/cffi/model.py +++ b/cffi/model.py @@ -228,6 +228,7 @@ class EnumType(BaseType): _attrs_ = ('name',) + partial = False def __init__(self, name, enumerators, enumvalues): self.name = name @@ -237,6 +238,12 @@ def get_c_name(self, replace_with=''): return 'enum %s%s' % (self.name, replace_with) + def check_not_partial(self): + if self.partial: + from . import ffiplatform + raise ffiplatform.VerificationMissing(self.get_c_name()) + def new_backend_type(self, ffi): + self.check_not_partial() return ffi._backend.new_enum_type(self.name, self.enumerators, self.enumvalues) diff --git a/testing/test_verify.py b/testing/test_verify.py --- a/testing/test_verify.py +++ b/testing/test_verify.py @@ -138,6 +138,16 @@ py.test.raises(VerificationError, ffi.verify, "typedef %s foo_t;" % real) +def test_missing_typedef(): + py.test.skip("in-progress") + ffi = FFI() + ffi.cdef("typedef ... foo_t; int bar(foo_t *);") + py.test.raises(VerificationMissing, ffi.new, "foo_t") + lib = ffi.verify("typedef struct foo_s { int x; } foo_t;\n" + "int bar(foo_t *f) { return 42; }\n") + f = ffi.new("foo_t") + assert lib.bar(f) == 42 + def test_ffi_full_struct(): ffi = FFI() @@ -275,5 +285,22 @@ def test_nonfull_enum(): ffi = FFI() ffi.cdef("enum ee { EE1, EE2, EE3, ... \n \t };") + py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE2') py.test.skip("in-progress") - py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE2') + ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };") + assert int(ffi.cast('enum ee', 'EE2')) == 11 + assert int(ffi.cast('enum ee', 'EE3')) == -10 + py.test.raises(AttributeError, ffi.cast, 'enum ee', '__dotdotdot0__') + +def test_full_enum(): + py.test.skip("in-progress") + ffi = FFI() + ffi.cdef("enum ee { EE1, EE2, EE3 };") + ffi.verify("enum ee { EE1, EE2, EE3 };") + for real in [ + "enum ee { EE1, EE2 };" + "enum ee { EE1, EE3, EE2 };" + ]: + py.test.raises(VerificationError, ffi.verify, real) + # extra items cannot be seen and have no bad consequence anyway + ffi.verify("enum ee { EE1, EE2, EE3, EE4 };") _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit