summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-06-10 22:54:18 +0100
committerJose Fonseca <jfonseca@vmware.com>2015-06-10 22:57:43 +0100
commit41efd945c841175f733ef764fe5f6a85c592970b (patch)
tree8e72180e98c491a4053823558aa29b89e1d9b383
parenta9b61380090fa1d726fb41aade658ac145ac0617 (diff)
retrace: Ensure we allocate struct members that are pointers to arrays.
As opposed to array members. Should fix issue #348.
-rw-r--r--retrace/retrace.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/retrace/retrace.py b/retrace/retrace.py
index 13e4d925..83ac16ad 100644
--- a/retrace/retrace.py
+++ b/retrace/retrace.py
@@ -124,12 +124,22 @@ class ValueDeserializer(stdapi.Visitor, stdapi.ExpanderMixin):
self.visit(bitmask.type, lvalue, rvalue)
def visitArray(self, array, lvalue, rvalue):
-
tmp = '_a_' + array.tag + '_' + str(self.seq)
self.seq += 1
print ' if (%s) {' % (lvalue,)
print ' const trace::Array *%s = (%s).toArray();' % (tmp, rvalue)
+
+ if self.insideStruct:
+ if isinstance(array.length, int):
+ # Member is an array
+ print r' static_assert( std::is_array< std::remove_reference< decltype( %s ) >::type >::value , "lvalue must be an array" );' % lvalue
+ print r' static_assert( std::extent< std::remove_reference< decltype( %s ) >::type >::value == %s, "array size mismatch" );' % (lvalue, array.length)
+ else:
+ # Member is a pointer to an array, hence must be allocated
+ print r' static_assert( std::is_pointer< std::remove_reference< decltype( %s ) >::type >::value , "lvalue must be a pointer" );' % lvalue
+ print r' %s = _allocator.allocArray<%s>(&%s);' % (lvalue, array.type, rvalue)
+
length = '%s->values.size()' % (tmp,)
index = '_j' + array.tag
print ' for (size_t {i} = 0; {i} < {length}; ++{i}) {{'.format(i = index, length = length)
@@ -186,16 +196,22 @@ class ValueDeserializer(stdapi.Visitor, stdapi.ExpanderMixin):
seq = 0
+ insideStruct = 0
+
def visitStruct(self, struct, lvalue, rvalue):
tmp = '_s_' + struct.tag + '_' + str(self.seq)
self.seq += 1
+ self.insideStruct += 1
+
print ' const trace::Struct *%s = (%s).toStruct();' % (tmp, rvalue)
print ' assert(%s);' % (tmp)
for i in range(len(struct.members)):
member = struct.members[i]
self.visitMember(member, lvalue, '*%s->members[%s]' % (tmp, i))
+ self.insideStruct -= 1
+
def visitPolymorphic(self, polymorphic, lvalue, rvalue):
if polymorphic.defaultType is None:
switchExpr = self.expand(polymorphic.switchExpr)