summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2022-07-18 15:55:46 +0200
committerArmin Rigo <arigo@tunes.org>2022-07-18 15:55:46 +0200
commitf0a33ae0ce2e62eb3a625c7baef175f385328b17 (patch)
treea7ad2efb5518473f36d97d8d92c4a3894f3d602d
parentd19553253e3c2967238777b4005abb5dc57f656d (diff)
downloadcffi-f0a33ae0ce2e62eb3a625c7baef175f385328b17.tar.gz
Tentative fix for issue #542
-rw-r--r--cffi/model.py3
-rw-r--r--testing/cffi0/test_model.py13
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)