summaryrefslogtreecommitdiff
path: root/wrappers
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2016-02-01 13:29:50 +0000
committerJose Fonseca <jfonseca@vmware.com>2016-03-05 17:17:30 +0000
commit83e6ddf6e0807174cae1bbdfb669e3b9ddd9b662 (patch)
treee2b1318f0e76264a31547ed02bb0653dab45f6c4 /wrappers
parente22c5bcc15d469240585c39b628eef9ec69e5328 (diff)
trace: Improve handling of structures with no members.
Diffstat (limited to 'wrappers')
-rw-r--r--wrappers/trace.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/wrappers/trace.py b/wrappers/trace.py
index c1504cd7..ab326aa1 100644
--- a/wrappers/trace.py
+++ b/wrappers/trace.py
@@ -67,20 +67,29 @@ class ComplexValueSerializer(stdapi.OnceVisitor):
self.visit(const.type)
def visitStruct(self, struct):
- # Ensure member array has nonzero length to avoid MSVC error C2466
- print 'static const char * _struct%s_members[%u] = {' % (struct.tag, max(len(struct.members), 1))
- for type, name, in struct.members:
- if name is None:
- print ' "",'
- else:
- print ' "%s",' % (name,)
- print '};'
+ # Write array with structure's member names
+ numMembers = len(struct.members)
+ if numMembers:
+ # Ensure member array has nonzero length to avoid MSVC error C2466
+ memberNames = '_struct%s_members' % (struct.tag,)
+ print 'static const char * %s[%u] = {' % (memberNames, numMembers)
+ for type, name, in struct.members:
+ if name is None:
+ print ' "",'
+ else:
+ print ' "%s",' % (name,)
+ print '};'
+ else:
+ sys.stderr.write('warning: %s has no members\n' % struct.name)
+ memberNames = 'nullptr'
+
+ # Write structure's signature
print 'static const trace::StructSig _struct%s_sig = {' % (struct.tag,)
if struct.name is None:
structName = '""'
else:
structName = '"%s"' % struct.name
- print ' %u, %s, %u, _struct%s_members' % (struct.id, structName, len(struct.members), struct.tag)
+ print ' %u, %s, %u, %s' % (struct.id, structName, numMembers, memberNames)
print '};'
print