From: Jakub Kicinski <kuba@kernel.org>
To: Donald Hunter <donald.hunter@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org, donald.hunter@redhat.com
Subject: Re: [patch net-next v1 1/2] tools: ynl: Use dict of predefined Structs to decode scalar types
Date: Mon, 22 May 2023 19:37:19 -0700 [thread overview]
Message-ID: <20230522193719.1428a3bf@kernel.org> (raw)
In-Reply-To: <20230521170733.13151-2-donald.hunter@gmail.com>
On Sun, 21 May 2023 18:07:32 +0100 Donald Hunter wrote:
> Use a dict of predefined Struct() objects to decode scalar types in native,
> big or little endian format. This removes the repetitive code for the
> scalar variants and ensures all the signed variants are supported.
> @@ -115,17 +116,17 @@ class NlAttr:
> return self.raw
>
> def as_c_array(self, type):
> - format, _ = self.type_formats[type]
> - return list({ x[0] for x in struct.iter_unpack(format, self.raw) })
> + format = self.get_format(type)
> + return list({ x[0] for x in format.iter_unpack(self.raw) })
I probably asked about this before, and maybe not the question
for this series but - why list({ ... }) and not [...]?
> else:
> - raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}')
> + try:
> + format = NlAttr.get_format(attr['type'], attr.byte_order)
> + attr_payload = format.pack(int(value))
> + except:
> + raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}')
Could we do:
elif attr["type"] in NlAttr.type_formats:
instead? Maybe my C brain treats exceptions as too exceptional..
> + elif attr_spec["type"]:
> + try:
> + decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order)
> + except:
> + raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')
Same here.
Nice cleanup!
next prev parent reply other threads:[~2023-05-23 2:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-21 17:07 [patch net-next v1 0/2] tools: ynl: Add byte-order support for struct members Donald Hunter
2023-05-21 17:07 ` [patch net-next v1 1/2] tools: ynl: Use dict of predefined Structs to decode scalar types Donald Hunter
2023-05-23 2:37 ` Jakub Kicinski [this message]
2023-05-23 8:21 ` Donald Hunter
2023-05-21 17:07 ` [patch net-next v1 2/2] tools: ynl: Handle byte-order in struct members Donald Hunter
2023-05-23 2:38 ` Jakub Kicinski
2023-05-23 8:22 ` Donald Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230522193719.1428a3bf@kernel.org \
--to=kuba@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=donald.hunter@redhat.com \
--cc=edumazet@google.com \
--cc=linux-doc@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.