diff options
-rw-r--r-- | cffi/model.py | 3 | ||||
-rw-r--r-- | testing/cffi0/test_model.py | 13 |
2 files changed, 13 insertions, 3 deletions
diff --git a/cffi/model.py b/cffi/model.py index ad1c176..1708f43 100644 --- a/cffi/model.py +++ b/cffi/model.py @@ -264,9 +264,10 @@ class PointerType(BaseType): def __init__(self, totype, quals=0): self.totype = totype self.quals = quals - extra = qualify(quals, " *&") + extra = " *&" if totype.is_array_type: extra = "(%s)" % (extra.lstrip(),) + extra = qualify(quals, extra) self.c_name_with_marker = totype.c_name_with_marker.replace('&', extra) def build_backend_type(self, ffi, finishlist): diff --git a/testing/cffi0/test_model.py b/testing/cffi0/test_model.py index bb653ca..328ba2d 100644 --- a/testing/cffi0/test_model.py +++ b/testing/cffi0/test_model.py @@ -54,8 +54,17 @@ def test_const_pointer_type(): ptr_type = ConstPointerType(PrimitiveType("int")) assert ptr_type.get_c_name("x") == "int const * x" ptr_type = ConstPointerType(ArrayType(PrimitiveType("int"), 5)) - assert ptr_type.get_c_name("") == "int(const *)[5]" - assert ptr_type.get_c_name("*x") == "int(const * *x)[5]" + assert ptr_type.get_c_name("") == "int const (*)[5]" + assert ptr_type.get_c_name("*x") == "int const (* *x)[5]" + ptr_type = ConstPointerType(ArrayType( + ConstPointerType(PrimitiveType("int")), 5)) + assert ptr_type.get_c_name("x") == "int const * const (* x)[5]" + ptr_type = PointerType(ArrayType( + ConstPointerType(PrimitiveType("int")), 5)) + assert ptr_type.get_c_name("x") == "int const *(* x)[5]" + ptr_type = ConstPointerType(ArrayType( + PointerType(PrimitiveType("int")), 5)) + assert ptr_type.get_c_name("x") == "int * const (* x)[5]" def test_qual_pointer_type(): ptr_type = PointerType(PrimitiveType("long long"), Q_RESTRICT) |