* [Qemu-devel] [PATCH] qapi-types: add C99 index names to arrays
@ 2015-02-19 10:13 Michael S. Tsirkin
2015-02-19 15:55 ` Eric Blake
0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2015-02-19 10:13 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Markus Armbruster, Wenchao Xia, Luiz Capitulino
It's not easy to figure out how monitor translates
strings: most QEMU code deals with translated indexes,
these are translated using _lookup arrays,
so you need to find the array name, and find the
appropriate offset.
This patch adds C99 indexes to lookup arrays, which makes it possible to
find the correct key using simple grep, and see that the matching is
correct at a glance.
Example:
Before:
const char *MigrationCapability_lookup[] = {
"xbzrle",
"rdma-pin-all",
"auto-converge",
"zero-blocks",
NULL,
};
After:
const char *MigrationCapability_lookup[] = {
[MIGRATION_CAPABILITY_XBZRLE] = "xbzrle",
[MIGRATION_CAPABILITY_RDMA_PIN_ALL] = "rdma-pin-all",
[MIGRATION_CAPABILITY_AUTO_CONVERGE] = "auto-converge",
[MIGRATION_CAPABILITY_ZERO_BLOCKS] = "zero-blocks",
[MIGRATION_CAPABILITY_MAX] = NULL,
};
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
scripts/qapi-types.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 1eb272d..db87218 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -123,16 +123,19 @@ const char *%(name)s_lookup[] = {
name=name)
i = 0
for value in values:
+ index = generate_enum_full_value(name, value)
ret += mcgen('''
- "%(value)s",
+ [%(index)s] = "%(value)s",
''',
- value=value)
+ index = index, value = value)
+ max_index = generate_enum_full_value(name, 'MAX')
ret += mcgen('''
- NULL,
+ [%(max_index)s] = NULL,
};
-''')
+''',
+ max_index=max_index)
return ret
def generate_enum(name, values):
--
MST
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi-types: add C99 index names to arrays
2015-02-19 10:13 [Qemu-devel] [PATCH] qapi-types: add C99 index names to arrays Michael S. Tsirkin
@ 2015-02-19 15:55 ` Eric Blake
0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2015-02-19 15:55 UTC (permalink / raw)
To: Michael S. Tsirkin, qemu-devel
Cc: Peter Maydell, Markus Armbruster, Wenchao Xia, Luiz Capitulino
[-- Attachment #1: Type: text/plain, Size: 1330 bytes --]
On 02/19/2015 03:13 AM, Michael S. Tsirkin wrote:
> It's not easy to figure out how monitor translates
> strings: most QEMU code deals with translated indexes,
> these are translated using _lookup arrays,
> so you need to find the array name, and find the
> appropriate offset.
>
> This patch adds C99 indexes to lookup arrays, which makes it possible to
> find the correct key using simple grep, and see that the matching is
> correct at a glance.
>
> Example:
>
> Before:
>
> const char *MigrationCapability_lookup[] = {
> "xbzrle",
> "rdma-pin-all",
> "auto-converge",
> "zero-blocks",
> NULL,
> };
>
> After:
>
> const char *MigrationCapability_lookup[] = {
> [MIGRATION_CAPABILITY_XBZRLE] = "xbzrle",
> [MIGRATION_CAPABILITY_RDMA_PIN_ALL] = "rdma-pin-all",
> [MIGRATION_CAPABILITY_AUTO_CONVERGE] = "auto-converge",
> [MIGRATION_CAPABILITY_ZERO_BLOCKS] = "zero-blocks",
> [MIGRATION_CAPABILITY_MAX] = NULL,
> };
I like it :)
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> scripts/qapi-types.py | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-19 15:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-19 10:13 [Qemu-devel] [PATCH] qapi-types: add C99 index names to arrays Michael S. Tsirkin
2015-02-19 15:55 ` Eric Blake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).