summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python_modules/demarshal.py10
-rw-r--r--python_modules/marshal.py4
-rw-r--r--python_modules/ptypes.py15
3 files changed, 18 insertions, 11 deletions
diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index 4d3e79b..5391e53 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -309,7 +309,7 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star
if element_type.is_fixed_sizeof() and want_mem_size and not is_byte_size:
# TODO: Overflow check the multiplication
- if array.ptr_array:
+ if array.has_attr("ptr_array"):
writer.assign(mem_size, "sizeof(void *) + SPICE_ALIGN(%s * %s, 4)" % (element_type.sizeof(), nelements))
else:
writer.assign(mem_size, "%s * %s" % (element_type.sizeof(), nelements))
@@ -373,7 +373,7 @@ def write_validate_array_item(writer, container, item, scope, parent_scope, star
if not array.is_extra_size():
writer.increment(mem_size, element_mem_size)
if want_is_extra_size:
- if array.ptr_array:
+ if array.has_attr("ptr_array"):
writer.increment(extra_size, "sizeof(void *) + SPICE_ALIGN(%s, 4)" % element_mem_size)
else:
writer.increment(extra_size, "%s + %s" % (element_mem_size, element_extra_size))
@@ -741,7 +741,7 @@ def write_array_parser(writer, nelements, array, dest, scope):
scope.variable_def("uint32_t", real_nelements)
writer.assign("array_end", "end + %s" % nelements)
writer.assign(real_nelements, 0)
- if array.ptr_array:
+ if array.has_attr("ptr_array"):
scope.variable_def("void **", "ptr_array")
scope.variable_def("int", "ptr_array_index")
writer.assign("ptr_array_index", 0)
@@ -749,7 +749,7 @@ def write_array_parser(writer, nelements, array, dest, scope):
writer.increment("end", "sizeof(void *) * %s" % nelements)
with writer.index(no_block = is_byte_size) as index:
with writer.while_loop("end < array_end") if is_byte_size else writer.for_loop(index, nelements) as array_scope:
- if array.ptr_array:
+ if array.has_attr("ptr_array"):
writer.statement("ptr_array[ptr_array_index++] = end")
if is_byte_size:
writer.increment(real_nelements, 1)
@@ -760,7 +760,7 @@ def write_array_parser(writer, nelements, array, dest, scope):
dest2 = dest.child_at_end(writer, element_type)
dest2.reuse_scope = array_scope
write_container_parser(writer, element_type, dest2)
- if array.ptr_array:
+ if array.has_attr("ptr_array"):
writer.comment("Align ptr_array element to 4 bytes").newline()
writer.assign("end", "(uint8_t *)SPICE_ALIGN((size_t)end, 4)")
if is_byte_size:
diff --git a/python_modules/marshal.py b/python_modules/marshal.py
index 95413fc..f151d94 100644
--- a/python_modules/marshal.py
+++ b/python_modules/marshal.py
@@ -186,13 +186,13 @@ def write_array_marshaller(writer, at_end, member, array, container_src, scope):
element = "%s__element" % member.name
if not scope.variable_defined(element):
- if array.ptr_array:
+ if array.has_attr("ptr_array"):
stars = " **"
else:
stars = " *"
scope.variable_def(element_type.c_type() + stars, element)
element_array = element
- if array.ptr_array:
+ if array.has_attr("ptr_array"):
element = "*" + element
if not at_end:
diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index 055034e..cc74b72 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -55,6 +55,13 @@ class FixedSize:
s = s + " + ((minor >= %d)?%d:0)" % (i, self.vals[i])
return s
+# Some attribute are propagated from member to the type as they really
+# are part of the type definition, rather than the member. This applies
+# only to attributes that affect pointer or array attributes, as these
+# are member local types, unlike e.g. a Struct that may be used by
+# other members
+propagated_attributes=["ptr_array"]
+
class Type:
def __init__(self):
self.attributes = {}
@@ -353,7 +360,6 @@ class ArrayType(Type):
self.element_type = element_type
self.size = size
- self.ptr_array = False
def __str__(self):
if self.size == None:
@@ -416,7 +422,7 @@ class ArrayType(Type):
raise Exception, "Pointer names in arrays not supported"
def is_extra_size(self):
- return self.ptr_array
+ return self.has_attr("ptr_array")
def contains_extra_size(self):
return self.element_type.contains_extra_size()
@@ -516,8 +522,9 @@ class Member(Containee):
self.member_type.register()
if self.has_attr("ptr32") and self.member_type.is_pointer():
self.member_type.set_ptr_size(4)
- if self.has_attr("ptr_array") and self.member_type.is_array():
- self.member_type.ptr_array = True
+ for i in propagated_attributes:
+ if self.has_attr(i):
+ self.member_type.attributes[i] = self.attributes[i]
return self
def is_primitive(self):