1.1 --- a/generator.py Tue Nov 09 22:11:58 2021 +0100
1.2 +++ b/generator.py Wed Nov 10 00:10:44 2021 +0100
1.3 @@ -278,7 +278,8 @@
1.4
1.5 table = []
1.6 self.populate_table(Reference(kind, path), table)
1.7 - self.write_table(f_decls, f_defs, table_name, structure_size, table)
1.8 + self.write_table(f_decls, f_defs, table_name, structure_size, table,
1.9 + self.get_trailing_data_type(Reference(kind, path)))
1.10
1.11 # Generate function instances.
1.12
1.13 @@ -770,14 +771,20 @@
1.14 f_consts.write(" %s = %d" % (pos_encoder(attrname), i))
1.15 print >>f_consts, "\n };"
1.16
1.17 - def write_table(self, f_decls, f_defs, table_name, structure_size, table):
1.18 + def write_table(self, f_decls, f_defs, table_name, structure_size, table,
1.19 + trailing_data_type):
1.20
1.21 """
1.22 Write the declarations to 'f_decls' and definitions to 'f_defs' for
1.23 the object having the given 'table_name' and the given 'structure_size',
1.24 with 'table' details used to populate the definition.
1.25 +
1.26 + To support value copying, the trailing data size is also written if
1.27 + 'trailing_data_type' is defined.
1.28 """
1.29
1.30 + trailing_size = trailing_data_type and "sizeof(%s)" % trailing_data_type or "0"
1.31 +
1.32 print >>f_decls, "extern const __table %s;\n" % table_name
1.33
1.34 # Write the corresponding definition.
1.35 @@ -785,11 +792,12 @@
1.36 print >>f_defs, """\
1.37 const __table %s = {
1.38 %s,
1.39 + %s,
1.40 {
1.41 %s
1.42 }
1.43 };
1.44 -""" % (table_name, structure_size,
1.45 +""" % (table_name, structure_size, trailing_size,
1.46 ",\n ".join(table))
1.47
1.48 def write_parameter_table(self, f_decls, f_defs, table_name, min_parameters,
1.49 @@ -1141,13 +1149,24 @@
1.50 the 'attrs' mapping, adding entries to the 'trailing' member collection.
1.51 """
1.52
1.53 + if self.get_trailing_data_type(ref):
1.54 + trailing.append(encode_literal_constant_value(attrs["__trailing__"]))
1.55 +
1.56 + def get_trailing_data_type(self, ref):
1.57 +
1.58 + """
1.59 + For the structure having the given 'ref', return the type of any
1.60 + trailing data.
1.61 + """
1.62 +
1.63 structure_ref = self.get_target_structure(ref)
1.64
1.65 # Instances with trailing data.
1.66
1.67 - if structure_ref.get_kind() == "<instance>" and \
1.68 - structure_ref.get_origin() in self.trailing_data_types:
1.69 - trailing.append(encode_literal_constant_value(attrs["__trailing__"]))
1.70 + if structure_ref.get_kind() == "<instance>":
1.71 + return self.trailing_data_types.get(structure_ref.get_origin())
1.72 + else:
1.73 + return None
1.74
1.75 def get_target_structure(self, ref):
1.76