From cf3ab5d5e06d1441b00eae61c221467c5952dfd0 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Tue, 8 Aug 2023 20:26:37 +0200 Subject: [PATCH] fxconv: copy elements in += ObjectData instead of referencing subobject This way, after o1 += o2, when o1 is linked all the outer data of o2 is linked alongside the outer data of o1, and the inner data remains contiguous. This is important for arrays, where we don't want the outer data of o2 to appear before the next inner field of o1. With this commit, an update to o2 after o1 += o2 no longer updates o1. This wasn't a feature in the first place. --- fxconv/fxconv.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/fxconv/fxconv.py b/fxconv/fxconv.py index 20a4e34..cb7d586 100644 --- a/fxconv/fxconv.py +++ b/fxconv/fxconv.py @@ -250,7 +250,7 @@ class ObjectData: elif isinstance(other, Sym): self.inner.append(other) elif isinstance(other, ObjectData): - self.inner.append(other) + self.inner += other.inner return self @staticmethod @@ -273,22 +273,10 @@ class ObjectData: return padding def link(self, symbol): - inner = [] + inner = self.inner outer = [] elements = [] - size = 0 - - # First unfold all structures within [inner] as we accumulate the total - # size of the inner data - for el in self.inner: - if isinstance(el, ObjectData): - size += self.align(size, el.alignment, inner) - code, code_size = el.link(f"{symbol} + {size}") - inner.append((code, code_size)) - size += code_size - else: - inner.append(el) - size += self.element_size(el) + size = sum(self.element_size(el) for el in inner) # Then replace complex references with unfolded data appended at the # end of the structure