Use an array to declare tree items instead of allocating it statically. This save a bit of memory and it also generate smaller code to read. A tree in wireshark represent an item which could be expanded. Possibly wireshark is using these registrations to save expansion state in the user interface. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- python_modules/dissector.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/python_modules/dissector.py b/python_modules/dissector.py index d9d8a87..6751534 100644 --- a/python_modules/dissector.py +++ b/python_modules/dissector.py @@ -1,6 +1,22 @@ from . import codegen + +# generate a new tree identifier +ett_writer = None +ett_num = 0 +def new_ett(writer): + global ett_writer + global ett_num + + if ett_num and ett_num % 16 == 0: + ett_writer.newline() + name = 'etts[%u]' % ett_num + ett_num = ett_num + 1 + ett_writer.write('-1, ') + return name + + hf_writer = None hf_defs = None @@ -42,6 +58,10 @@ def write_protocol_definitions(writer): writer.newline() writer.function('spice_register_fields', 'void', 'int proto, expert_module_t* expert_proto') + writer.variable_def('guint', 'n'); + writer.variable_def('gint *', 'ett[array_length(etts)]') + writer.newline() + writer.write("static hf_register_info hf[] = ") writer.begin_block() hf_defs = writer.get_subwriter() @@ -55,17 +75,25 @@ def write_protocol_definitions(writer): writer.end_block(semicolon = True) writer.newline() + with writer.for_loop('n', 'array_length(etts)'): + writer.assign('ett[n]', '&etts[n]') + writer.statement('proto_register_field_array(proto, hf, array_length(hf))') + writer.statement('proto_register_subtree_array(ett, array_length(etts))') writer.statement('expert_register_field_array(expert_proto, ei, array_length(ei))') writer.end_block() def write_protocol_parser(writer, proto): global hf_writer + global ett_writer write_parser_helpers(writer) # put fields declaration first + with writer.block('static gint etts[] =', semicolon=True) as scope: + ett_writer = scope + writer.newline() hf_writer = writer.get_subwriter() # put fields definition at last -- 2.1.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel