Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1958:2b0c7caf579e
Date: 2015-05-10 12:09 +0200
http://bitbucket.org/cffi/cffi/changeset/2b0c7caf579e/
Log: Support doing a bit more things with a "typedef struct { } *name;"
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -293,9 +293,13 @@
assert '__dotdotdot__' not in name.split()
self._declarations[name] = obj
- def _get_type_pointer(self, type, const=False):
+ def _get_type_pointer(self, type, const=False, declname=None):
if isinstance(type, model.RawFunctionType):
return type.as_function_pointer()
+ if (isinstance(type, model.StructOrUnionOrEnum) and
+ type.name.startswith('$') and type.name[1:].isdigit() and
+ type.forcename is None and declname is not None):
+ return model.NamedPointerType(type, declname)
if const:
return model.ConstPointerType(type)
return model.PointerType(type)
@@ -322,7 +326,8 @@
# pointer type
const = (isinstance(typenode.type, pycparser.c_ast.TypeDecl)
and 'const' in typenode.type.quals)
- return self._get_type_pointer(self._get_type(typenode.type), const)
+ return self._get_type_pointer(self._get_type(typenode.type), const,
+ declname=name)
#
if isinstance(typenode, pycparser.c_ast.TypeDecl):
type = typenode.type
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1281,9 +1281,9 @@
def test_cannot_name_struct_type():
ffi = FFI()
- ffi.cdef("typedef struct { int x; } *sp; void foo(sp);")
+ ffi.cdef("typedef struct { int x; } **sp; void foo(sp);")
e = py.test.raises(VerificationError, ffi.verify,
- "typedef struct { int x; } *sp; void foo(sp);")
+ "typedef struct { int x; } **sp; void foo(sp x) { }")
assert 'in argument of foo: unknown type name' in str(e.value)
def test_dont_check_unnamable_fields():
@@ -1709,6 +1709,17 @@
res = lib2.myfunc(lib2.AA)
assert res == 2
+def test_named_pointer_as_argument():
+ ffi = FFI()
+ ffi.cdef("typedef struct { int x; } *mystruct_p;\n"
+ "mystruct_p ff5a(mystruct_p);")
+ lib = ffi.verify("typedef struct { int x; } *mystruct_p;\n"
+ "mystruct_p ff5a(mystruct_p p) { p->x += 40; return p; }")
+ p = ffi.new("mystruct_p", [-2])
+ q = lib.ff5a(p)
+ assert q == p
+ assert p.x == 38
+
def test_enum_size():
cases = [('123', 4, 4294967295),
('4294967295U', 4, 4294967295),
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit