[pypy-commit] cffi default: Give an earlier error message when trying to declare a function
arigo
noreply at buildbot.pypy.org
Wed Aug 22 18:56:23 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r870:ede1d10ba97c
Date: 2012-08-22 18:56 +0200
http://bitbucket.org/cffi/cffi/changeset/ede1d10ba97c/
Log: Give an earlier error message when trying to declare a function
using exactly '(...)' as the argument list. It's not valid C.
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -244,7 +244,11 @@
params[-1].type.type.names == ['__dotdotdot__'])
if ellipsis:
params.pop()
- if (len(params) == 1 and
+ if not params:
+ raise api.CDefError(
+ "%s: a function with only '(...)' as argument"
+ " is not correct C" % (funcname or 'in expression'))
+ elif (len(params) == 1 and
isinstance(params[0].type, pycparser.c_ast.TypeDecl) and
isinstance(params[0].type.type, pycparser.c_ast.IdentifierType)
and list(params[0].type.type.names) == ['void']):
diff --git a/testing/test_parsing.py b/testing/test_parsing.py
--- a/testing/test_parsing.py
+++ b/testing/test_parsing.py
@@ -177,3 +177,10 @@
assert C.foo.BType == '<func (), <int>, False>'
ffi.cdef("long foo(void);", override=True)
assert C.foo.BType == '<func (), <long>, False>'
+
+def test_cannot_have_only_variadic_part():
+ # this checks that we get a sensible error if we try "int foo(...);"
+ ffi = FFI()
+ e = py.test.raises(CDefError, ffi.cdef, "int foo(...);")
+ assert str(e.value) == \
+ "foo: a function with only '(...)' as argument is not correct C"
More information about the pypy-commit
mailing list