[pypy-commit] cffi default: Test and fix.
arigo
noreply at buildbot.pypy.org
Sun Jun 17 11:58:03 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r400:08e97a7d719f
Date: 2012-06-17 11:57 +0200
http://bitbucket.org/cffi/cffi/changeset/08e97a7d719f/
Log: Test and fix.
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -86,7 +86,6 @@
if (isinstance(decl.type.type, pycparser.c_ast.IdentifierType)
and decl.type.type.names == ['__dotdotdot__']):
realtype = model.unknown_type(decl.name)
- self._declare('anonymous ' + decl.name, realtype)
else:
realtype = self._get_type(decl.type, name=decl.name)
self._declare('typedef ' + decl.name, realtype)
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -268,7 +268,6 @@
def unknown_type(name):
- tp = StructType('$%s' % name, [], [], [])
- tp.partial = True
+ tp = StructType('$%s' % name, None, None, None)
tp.forcename = name
return tp
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -455,7 +455,11 @@
def test_unknown_type():
ffi = FFI()
- ffi.cdef("typedef ... token_t; int foo(token_t *);")
+ ffi.cdef("""
+ typedef ... token_t;
+ int foo(token_t *);
+ #define TOKEN_SIZE ...
+ """)
lib = ffi.verify("""
typedef float token_t;
static int foo(token_t *tk) {
@@ -464,8 +468,19 @@
*tk += 1.601;
return (int)*tk;
}
+ #define TOKEN_SIZE sizeof(token_t)
""")
- tk = ffi.new("token_t") # zero-initialized
+ # we cannot let ffi.new("token_t") work, because we don't know ahead of
+ # time if it's ok to ask 'sizeof(token_t)' in the C code or not.
+ # See test_unknown_type_2. Workaround.
+ tkmem = ffi.new("char[]", lib.TOKEN_SIZE) # zero-initialized
+ tk = ffi.cast("token_t *", tkmem)
results = [lib.foo(tk) for i in range(6)]
assert results == [1, 3, 4, 6, 8, 9]
assert lib.foo(None) == -42
+
+def test_unknown_type_2():
+ ffi = FFI()
+ ffi.cdef("typedef ... token_t;")
+ lib = ffi.verify("typedef struct token_s token_t;")
+ # assert did not crash, even though 'sizeof(token_t)' is not valid in C.
More information about the pypy-commit
mailing list