Use an array to declare tree items instead of allocating it statically. This save a bit of memory and it also generates smaller code to read. A tree in wireshark represents 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 ++++++++++++++++++++++++++++ tests/dissector_test.c | 13 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/python_modules/dissector.py b/python_modules/dissector.py index 3e9835f..cf44e3c 100644 --- a/python_modules/dissector.py +++ b/python_modules/dissector.py @@ -4,6 +4,22 @@ import re dissector_short_name = 'spice2' + +# 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 @@ -56,6 +72,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() @@ -68,17 +88,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 diff --git a/tests/dissector_test.c b/tests/dissector_test.c index 6189da0..3212655 100644 --- a/tests/dissector_test.c +++ b/tests/dissector_test.c @@ -13,9 +13,11 @@ enum { first_hf_registered = 0x10000, first_ei_registered = 0x20000, + first_tree_registered = 0x30000, }; static int last_hf_registered = first_hf_registered - 1; static int last_ei_registered = first_ei_registered - 1; +static int last_tree_registered = first_tree_registered - 1; WS_DLL_PUBLIC void proto_register_field_array(const int parent, hf_register_info *hf, const int num_records) @@ -31,6 +33,17 @@ proto_register_field_array(const int parent, hf_register_info *hf, const int num } WS_DLL_PUBLIC void +proto_register_subtree_array(gint *const *indices, const int num_indices) +{ + int i; + assert(num_indices >= 0); + for (i = 0; i < num_indices; ++i) { + assert(indices && *indices[i] == -1); + *indices[i] = ++last_tree_registered; + } +} + +WS_DLL_PUBLIC void expert_register_field_array(expert_module_t* module, ei_register_info *ei, const int num_records) { int i; -- 2.4.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel