From: Luiz Capitulino <lcapitulino@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 4/4] qapi-types: add C99 index names to arrays
Date: Mon, 23 Feb 2015 11:55:26 -0500 [thread overview]
Message-ID: <1424710526-21474-5-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1424710526-21474-1-git-send-email-lcapitulino@redhat.com>
From: "Michael S. Tsirkin" <mst@redhat.com>
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>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@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):
--
1.9.3
next prev parent reply other threads:[~2015-02-23 16:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 16:55 [Qemu-devel] [PULL 0/4] QMP queue Luiz Capitulino
2015-02-23 16:55 ` [Qemu-devel] [PULL 1/4] hmp: Fix warning from smatch (wrong argument in function call) Luiz Capitulino
2015-02-23 16:55 ` [Qemu-devel] [PULL 2/4] balloon: Fix typo Luiz Capitulino
2015-02-23 16:55 ` [Qemu-devel] [PULL 3/4] monitor: Fix missing err = NULL in client_migrate_info() Luiz Capitulino
2015-02-23 16:55 ` Luiz Capitulino [this message]
2015-02-26 13:08 ` [Qemu-devel] [PULL 0/4] QMP queue Peter Maydell
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=1424710526-21474-5-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 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).