From 6838f30079e6401f89597f1209f09bdea257ce28 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Fri, 25 Sep 2020 16:37:13 +0100 Subject: codegen: Add a check to array type If the size is not constant the array has to be allocated in some way in the output and so there must be a specification for the output (as default is write into the C structure all data). The only exceptions are when the length is constant (in this case a constant length array in the C structure is used) or a pointer (in this case the pointer allocate the array). Signed-off-by: Frediano Ziglio Acked-by: Victor Toso --- python_modules/ptypes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'python_modules') diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py index 91bd0cd..71bb7f7 100644 --- a/python_modules/ptypes.py +++ b/python_modules/ptypes.py @@ -501,6 +501,16 @@ class ArrayType(Type): return self.element_type.c_type() def check_valid(self, member): + # If the size is not constant the array has to be allocated in some + # way in the output and so there must be a specification for the + # output (as default is write into the C structure all data). + # The only exceptions are when the length is constant (in this case + # a constant length array in the C structure is used) or a pointer + # (in this case the pointer allocate the array). + if (not self.is_constant_length() + and len(output_attributes.intersection(member.attributes.keys())) == 0 + and not member.member_type.is_pointer()): + raise Exception("Array length must be a constant or some output specifiers must be set") # These attribute corresponds to specific structure size if member.has_attr("chunk") or member.has_attr("as_ptr"): return -- cgit v1.2.3