Author: Armin Rigo <ar...@tunes.org> Branch: cffi-1.0 Changeset: r77226:4b5f9b10219f Date: 2015-05-08 18:05 +0200 http://bitbucket.org/pypy/pypy/changeset/4b5f9b10219f/
Log: Test and fix diff --git a/pypy/module/_cffi_backend/ffi_obj.py b/pypy/module/_cffi_backend/ffi_obj.py --- a/pypy/module/_cffi_backend/ffi_obj.py +++ b/pypy/module/_cffi_backend/ffi_obj.py @@ -51,9 +51,14 @@ try: x = self.types_dict[string] except KeyError: - index = parse_c_type.parse_c_type(self.ctxobj.info, string) + info = self.ctxobj.info + index = parse_c_type.parse_c_type(info, string) if index < 0: - xxxx + num_spaces = rffi.getintfield(info, 'c_error_location') + raise oefmt(self.w_FFIError, "%s\n%s\n%s^", + rffi.charp2str(info.c_error_message), + string, + " " * num_spaces) x = realize_c_type.realize_c_type_or_func( self, self.ctxobj.info.c_output, index) self.types_dict[string] = x diff --git a/pypy/module/_cffi_backend/test/test_ffi_obj.py b/pypy/module/_cffi_backend/test/test_ffi_obj.py --- a/pypy/module/_cffi_backend/test/test_ffi_obj.py +++ b/pypy/module/_cffi_backend/test/test_ffi_obj.py @@ -165,3 +165,19 @@ assert ffi.cast("int(*)(int)", 0) == ffi.NULL ffi.callback("int(int)") # side-effect of registering this string raises(ffi.error, ffi.cast, "int(int)", 0) + + def test_ffi_invalid_type(self): + import _cffi_backend as _cffi1_backend + ffi = _cffi1_backend.FFI() + e = raises(ffi.error, ffi.cast, "", 0) + assert str(e.value) == ("identifier expected\n" + "\n" + "^") + e = raises(ffi.error, ffi.cast, "struct struct", 0) + assert str(e.value) == ("struct or union name expected\n" + "struct struct\n" + " ^") + e = raises(ffi.error, ffi.cast, "struct never_heard_of_s", 0) + assert str(e.value) == ("undefined struct/union name\n" + "struct never_heard_of_s\n" + " ^") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit