diff options
author | Alexander Larsson <alexl@redhat.com> | 2010-07-20 11:34:23 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2010-07-20 11:34:23 +0200 |
commit | 2e9604d00d655f276f22b9ad1cce4fb631ac06a8 (patch) | |
tree | 51ddc427773a95f852744eb3fd8089c33d6ad893 /python_modules/demarshal.py | |
parent | 5f664e0ffb62c4a1d13b7647aea3c1115150eb88 (diff) | |
download | spice-2e9604d00d655f276f22b9ad1cce4fb631ac06a8.tar.gz spice-2e9604d00d655f276f22b9ad1cce4fb631ac06a8.tar.xz spice-2e9604d00d655f276f22b9ad1cce4fb631ac06a8.zip |
demarshaller: Fix palette marshalling
It turns out that using base + sizeof(struct) is not a good way to
access an array at the end of a struct. For SpicePalette sizeof is 16, but
offset of ents is 12. Using this calculation in the demarshaller breaks
things badly, so now we use the actual array member.
Diffstat (limited to 'python_modules/demarshal.py')
-rw-r--r-- | python_modules/demarshal.py | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py index a4345d4d..c588f980 100644 --- a/python_modules/demarshal.py +++ b/python_modules/demarshal.py @@ -797,29 +797,47 @@ def write_array_parser(writer, member, nelements, array, dest, scope): is_byte_size = array.is_bytes_length() element_type = array.element_type + if member: + array_start = dest.get_ref(member.name) + at_end = member.has_attr("end") + else: + array_start = "end" + at_end = True + if element_type == ptypes.uint8 or element_type == ptypes.int8: - if not member or member.has_attr("end"): - writer.statement("memcpy(end, in, %s)" % (nelements)) - writer.increment("end", nelements) - else: - writer.statement("memcpy(%s, in, %s)" % (dest.get_ref(member.name), nelements)) + writer.statement("memcpy(%s, in, %s)" % (array_start, nelements)) writer.increment("in", nelements) + if at_end: + writer.increment("end", nelements) else: - 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) - writer.assign("ptr_array", "(void **)end") - writer.increment("end", "sizeof(void *) * %s" % nelements) with writer.index() as index: + if member: + array_pos = "%s[%s]" % (array_start, index) + else: + array_pos = "*(%s *)end" % (element_type.c_type()) + + 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) + writer.assign("ptr_array", "(void **)%s" % array_start) + writer.increment("end", "sizeof(void *) * %s" % nelements) + array_start = "end" + array_pos = "*(%s *)end" % (element_type.c_type()) + at_end = True + with writer.for_loop(index, nelements) as array_scope: if array.has_attr("ptr_array"): writer.statement("ptr_array[ptr_array_index++] = end") if element_type.is_primitive(): - writer.statement("*(%s *)end = consume_%s(&in)" % (element_type.c_type(), element_type.primitive_type())) - writer.increment("end", element_type.sizeof()) + writer.statement("%s = consume_%s(&in)" % (array_pos, element_type.primitive_type())) + if at_end: + writer.increment("end", element_type.sizeof()) else: - dest2 = dest.child_at_end(writer, element_type) + if at_end: + dest2 = dest.child_at_end(writer, element_type) + else: + dest2 = RootDemarshallingDestination(dest, element_type.c_type(), element_type.c_type(), array_pos) dest2.reuse_scope = array_scope write_container_parser(writer, element_type, dest2) if array.has_attr("ptr_array"): |