Wireshark-dev: Re: [Wireshark-dev] Regenerating packet-parlay.c
From: Luke Mewburn <luke@xxxxxxxxxxx>
Date: Fri, 1 May 2020 12:13:26 +1000
On 20-04-30 20:30, Jaap Keuter wrote: | On 4/30/20 2:41 AM, Luke Mewburn wrote: | > On 20-04-30 10:35, Luke Mewburn wrote: | > | As to the problem; looking at the use of .keys() in wireshark_gen.py, | > | there's a couple of places where the code is either: | > | - get_intlist(), sorted: | > | ret = list(ex_hash.keys()) | > | ret.sort() | > | return ret | > | - get_exceptionList(), unsorted: | > | ret = list(ex_hash.keys()) | > | return ret | > | | > | Both could be simplified to an ordered result using sorted(): | > | ret = sorted(ex_hash.keys()) | > | return ret | > | > I actually meant: | > ret = sorted(ex_hash) | > return ret | > | > Because sorted() takes an iterable. | > That seems to work in both python2 and python3. | > | > | > Luke. | | Hi, | | tried this, but: in get_exceptionList | ret = sorted(ex_hash.keys()) | TypeError: '<' not supported between instances of 'Exception' and 'Exception' I've reproduced the problem; the correct invocation is: ret = sorted(ex_hash, key=lambda ex: ex.identifier()) return ret However, looking at the code some more, it appears that generally wireshark_gen.py generates code in the order the operations are defined; the exception (hah!) is the user exceptions. If I instead add at the top import collections and change get_exceptionList() from ex_hash = {} # holds a hash of unique exceptions. to ex_hash = collections.OrderedDict() # holds a hash of unique exceptions. This results in consistent generated code with both python 2.7 (CentOS 7) and python 3.7 (Fedora 31). I've also fixed a whitespace issue in the generated code by indenting the break in template_helper_switch_msgtype_default_end, so that it matches the epan/dissectors code and other default statements. Here's a patch with my suggested fixes. Or would you prefer a commit/pull request (etc)? regards, Luke.
From 034db92a2119250c6f278b55f2f223ea1ace9d1a Mon Sep 17 00:00:00 2001 From: Luke Mewburn <luke@xxxxxxxxxxx> Date: Fri, 1 May 2020 11:22:03 +1000 Subject: [PATCH] idl2wrs: generation improvements Consistent user exception ordering. Fix switch msgtype default indenting. Change-Id: Id345013d558bb458f5476b3225dc91a0b6afeb42 --- tools/wireshark_gen.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/wireshark_gen.py b/tools/wireshark_gen.py index f58470f1f6..f28f7edffe 100755 --- a/tools/wireshark_gen.py +++ b/tools/wireshark_gen.py @@ -54,6 +54,7 @@ from __future__ import print_function +import collections import tempfile from omniidl import idlast, idltype, idlutil, output @@ -1747,7 +1748,7 @@ class wireshark_gen_C: to generate dissect_exception_XXX functions. """ - ex_hash = {} # holds a hash of unique exceptions. + ex_hash = collections.OrderedDict() # holds a hash of unique exceptions. for op in oplist: for ex in op.raises(): if ex not in ex_hash: @@ -1945,7 +1946,7 @@ default: expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);""" template_helper_switch_msgtype_default_end = """\ -break;""" + break;""" template_helper_switch_msgtype_end = """\ } /* switch(header->message_type) */""" -- 2.24.2 (Apple Git-127)
Attachment:
pgpigcHd7AVEz.pgp
Description: PGP signature
- Follow-Ups:
- Re: [Wireshark-dev] Regenerating packet-parlay.c
- From: Jaap Keuter
- Re: [Wireshark-dev] Regenerating packet-parlay.c
- Next by Date: Re: [Wireshark-dev] Regenerating packet-parlay.c
- Next by thread: Re: [Wireshark-dev] Regenerating packet-parlay.c
- Index(es):