mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2026-02-01 09:29:14 +00:00
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>
This commit is contained in:
parent
e49301ebd1
commit
6838f30079
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user