summaryrefslogtreecommitdiff
path: root/python_modules
diff options
context:
space:
mode:
authorFrediano Ziglio <freddy77@gmail.com>2020-09-25 16:37:13 +0100
committerFrediano Ziglio <freddy77@gmail.com>2021-02-22 09:11:28 +0000
commit6838f30079e6401f89597f1209f09bdea257ce28 (patch)
tree2c2097034a91fa94aefb796bda59dff8f4bd2590 /python_modules
parente49301ebd157057864dbd98dae558a3e7c6c4e9b (diff)
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 <freddy77@gmail.com> Acked-by: Victor Toso <victortoso@redhat.com>
Diffstat (limited to 'python_modules')
-rw-r--r--python_modules/ptypes.py10
1 files changed, 10 insertions, 0 deletions
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