From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 43/47] qapi: Generate FOO_str() macro for QAPI enum FOO
Date: Fri, 1 Sep 2017 14:56:07 +0200 [thread overview]
Message-ID: <20170901125611.29295-44-armbru@redhat.com> (raw)
In-Reply-To: <20170901125611.29295-1-armbru@redhat.com>
The next commit will put it to use. May look pointless now, but we're
going to change the FOO_lookup's type, and then it'll help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1503564371-26090-13-git-send-email-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
block.c | 1 -
block/blkdebug.c | 1 -
block/file-posix.c | 1 -
block/file-win32.c | 1 -
block/gluster.c | 1 -
block/parallels.c | 1 -
block/qcow2.c | 1 -
block/quorum.c | 1 -
blockdev.c | 1 -
crypto/block-luks.c | 1 -
docs/devel/qapi-code-gen.txt | 3 +++
hmp.c | 1 -
include/qapi/util.h | 1 +
migration/global_state.c | 1 -
migration/migration.c | 1 -
qapi/qapi-util.c | 8 +++++++-
qapi/qapi-visit-core.c | 1 -
qemu-img.c | 1 -
qemu-nbd.c | 1 -
scripts/qapi-event.py | 1 +
scripts/qapi-types.py | 4 ++++
scripts/qapi.py | 3 +++
tests/test-qapi-util.c | 1 -
tpm.c | 1 -
util/keyval.c | 1 -
25 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/block.c b/block.c
index af48b0d26b..845eff8177 100644
--- a/block.c
+++ b/block.c
@@ -42,7 +42,6 @@
#include "qapi-event.h"
#include "qemu/cutils.h"
#include "qemu/id.h"
-#include "qapi/util.h"
#ifdef CONFIG_BSD
#include <sys/ioctl.h>
diff --git a/block/blkdebug.c b/block/blkdebug.c
index f1bbee9497..b370fcedfb 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -32,7 +32,6 @@
#include "qapi/qmp/qbool.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
#include "sysemu/qtest.h"
typedef struct BDRVBlkdebugState {
diff --git a/block/file-posix.c b/block/file-posix.c
index 97e8a92e23..d81eccc191 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -31,7 +31,6 @@
#include "block/thread-pool.h"
#include "qemu/iov.h"
#include "block/raw-aio.h"
-#include "qapi/util.h"
#include "qapi/qmp/qstring.h"
#if defined(__APPLE__) && (__MACH__)
diff --git a/block/file-win32.c b/block/file-win32.c
index 978d8058fe..192ea819d9 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -31,7 +31,6 @@
#include "block/thread-pool.h"
#include "qemu/iov.h"
#include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
#include <windows.h>
#include <winioctl.h>
diff --git a/block/gluster.c b/block/gluster.c
index 8367e806d0..0614e0c8aa 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -12,7 +12,6 @@
#include "block/block_int.h"
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
-#include "qapi/util.h"
#include "qemu/uri.h"
#include "qemu/error-report.h"
#include "qemu/cutils.h"
diff --git a/block/parallels.c b/block/parallels.c
index eb92366e51..d812210b4f 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -35,7 +35,6 @@
#include "qemu/module.h"
#include "qemu/bswap.h"
#include "qemu/bitmap.h"
-#include "qapi/util.h"
/**************************************************************/
diff --git a/block/qcow2.c b/block/qcow2.c
index 470a0dedaa..3a93983e3f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -30,7 +30,6 @@
#include "qemu/error-report.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qbool.h"
-#include "qapi/util.h"
#include "qapi/qmp/types.h"
#include "qapi-event.h"
#include "trace.h"
diff --git a/block/quorum.c b/block/quorum.c
index cb6617703c..8d1c9f6306 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -22,7 +22,6 @@
#include "qapi/qmp/qjson.h"
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
#include "qapi-event.h"
#include "crypto/hash.h"
diff --git a/blockdev.c b/blockdev.c
index 722a61e3fb..f90bc9399a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -44,7 +44,6 @@
#include "qapi-visit.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qobject-output-visitor.h"
-#include "qapi/util.h"
#include "sysemu/sysemu.h"
#include "block/block_int.h"
#include "qmp-commands.h"
diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index c3cacdb1ed..84d189a426 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -20,7 +20,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
-#include "qapi/util.h"
#include "qemu/bswap.h"
#include "crypto/block-luks.h"
diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index ae05327869..f04c63fe82 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -1275,6 +1275,9 @@ Example:
EXAMPLE_QAPI_EVENT__MAX = 1,
} example_QAPIEvent;
+ #define example_QAPIEvent_str(val) \
+ qapi_enum_lookup(example_QAPIEvent_lookup, (val))
+
extern const char *const example_QAPIEvent_lookup[];
#endif
diff --git a/hmp.c b/hmp.c
index 2b6e919501..5d980acb1e 100644
--- a/hmp.c
+++ b/hmp.c
@@ -31,7 +31,6 @@
#include "qapi/qmp/qerror.h"
#include "qapi/string-input-visitor.h"
#include "qapi/string-output-visitor.h"
-#include "qapi/util.h"
#include "qapi-visit.h"
#include "qom/object_interfaces.h"
#include "ui/console.h"
diff --git a/include/qapi/util.h b/include/qapi/util.h
index 4eb8a3fe2f..5e50d0c1ce 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -11,6 +11,7 @@
#ifndef QAPI_UTIL_H
#define QAPI_UTIL_H
+const char *qapi_enum_lookup(const char *const lookup[], int val);
int qapi_enum_parse(const char * const lookup[], const char *buf,
int def, Error **errp);
diff --git a/migration/global_state.c b/migration/global_state.c
index 88c55f8cdb..76cd3a13d4 100644
--- a/migration/global_state.c
+++ b/migration/global_state.c
@@ -14,7 +14,6 @@
#include "qemu/cutils.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
-#include "qapi/util.h"
#include "migration.h"
#include "migration/global_state.h"
#include "migration/vmstate.h"
diff --git a/migration/migration.c b/migration/migration.c
index c3fe0ed9ca..1a2b3ebd1a 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -31,7 +31,6 @@
#include "migration/vmstate.h"
#include "block/block.h"
#include "qapi/qmp/qerror.h"
-#include "qapi/util.h"
#include "qemu/rcu.h"
#include "block.h"
#include "postcopy-ram.h"
diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c
index ee7594ff19..7af2f04d36 100644
--- a/qapi/qapi-util.c
+++ b/qapi/qapi-util.c
@@ -13,7 +13,13 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
-#include "qapi/util.h"
+
+const char *qapi_enum_lookup(const char *const lookup[], int val)
+{
+ assert(val >= 0);
+
+ return lookup[val];
+}
int qapi_enum_parse(const char * const lookup[], const char *buf,
int def, Error **errp)
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index ec83ff68f9..f285879d72 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -14,7 +14,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
-#include "qapi/util.h"
#include "qemu-common.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qerror.h"
diff --git a/qemu-img.c b/qemu-img.c
index 611ab7ddf3..a72a2e3133 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -26,7 +26,6 @@
#include "qemu-version.h"
#include "qapi/error.h"
-#include "qapi/util.h"
#include "qapi-visit.h"
#include "qapi/qobject-output-visitor.h"
#include "qapi/qmp/qerror.h"
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 96e10d62dc..a97f3f4540 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -34,7 +34,6 @@
#include "qemu/log.h"
#include "qemu/systemd.h"
#include "block/snapshot.h"
-#include "qapi/util.h"
#include "qapi/qmp/qstring.h"
#include "qom/object_interfaces.h"
#include "io/channel-socket.h"
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index bcbef1035f..07b4b70199 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -217,6 +217,7 @@ fdef.write(mcgen('''
fdecl.write(mcgen('''
#include "qapi/error.h"
+#include "qapi/util.h"
#include "qapi/qmp/qdict.h"
#include "%(prefix)sqapi-types.h"
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index b45e7b5634..7e3051dbb9 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -292,6 +292,10 @@ fdef.write(mcgen('''
''',
prefix=prefix))
+fdecl.write(mcgen('''
+#include "qapi/util.h"
+'''))
+
schema = QAPISchema(input_file)
gen = QAPISchemaGenTypeVisitor()
schema.visit(gen)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 3693b520da..8736b9c786 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1894,6 +1894,9 @@ typedef enum %(c_name)s {
ret += mcgen('''
+#define %(c_name)s_str(val) \\
+ qapi_enum_lookup(%(c_name)s_lookup, (val))
+
extern const char *const %(c_name)s_lookup[];
''',
c_name=c_name(name))
diff --git a/tests/test-qapi-util.c b/tests/test-qapi-util.c
index d72ee8c4e7..7e1be1d851 100644
--- a/tests/test-qapi-util.c
+++ b/tests/test-qapi-util.c
@@ -12,7 +12,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
-#include "qapi/util.h"
#include "test-qapi-types.h"
static void test_qapi_enum_parse(void)
diff --git a/tpm.c b/tpm.c
index 7635fc779b..38f3eb827f 100644
--- a/tpm.c
+++ b/tpm.c
@@ -14,7 +14,6 @@
#include "qemu/osdep.h"
#include "qapi/qmp/qerror.h"
-#include "qapi/util.h"
#include "sysemu/tpm_backend.h"
#include "sysemu/tpm.h"
#include "qemu/config-file.h"
diff --git a/util/keyval.c b/util/keyval.c
index 7dbda62305..7dfc75cf01 100644
--- a/util/keyval.c
+++ b/util/keyval.c
@@ -82,7 +82,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
#include "qemu/cutils.h"
#include "qemu/option.h"
--
2.13.5
next prev parent reply other threads:[~2017-09-01 12:56 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-01 12:55 [Qemu-devel] [PULL 00/47] QAPI patches for 2017-09-01 Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 01/47] qapi: Fix error handling code on alternate conflict Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 02/47] tests/qmp-test: Add generic, basic test of query commands Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 03/47] qobject: Explain how QNum works, and why Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 04/47] qdict: Add qdict_put_null() helper, and put it to use Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 05/47] qlit: move qlit from check-qjson to qobject/ Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 06/47] qlit: use QLit prefix consistently Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 07/47] qlit: Change compound literals to initializers Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 08/47] qlit: rename compare_litqobj_to_qobj() to qlit_equal_qobject() Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 09/47] qlit: make qlit_equal_qobject return a bool Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 10/47] qlit: make qlit_equal_qobject() take const arguments Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 11/47] qlit: add QLIT_QNULL and QLIT_BOOL Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 12/47] qlit: Replace open-coded qnum_get_int() by call Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 13/47] tests/check-qlit: New, covering qobject/qlit.c Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 14/47] qlit: Tighten QLit dict vs QDict comparison Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 15/47] qlit: Tighten QLit list vs QList comparison Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 16/47] qapi-schema: Document how generated documentation is ordered Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 17/47] qapi-schema: Introspection doc is in the wrong section, fix Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 18/47] qapi-schema: Rocker doc section contains unrelated stuff, fix Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 19/47] qapi-schema: Collect sockets stuff in qapi/sockets.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 20/47] qapi-schema: Collect run state stuff in qapi/run-state.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 21/47] qapi-schema: Collect char device stuff in qapi/char.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 22/47] qapi-schema: Collect net device stuff in qapi/net.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 23/47] qapi-schema: Collect UI stuff in qapi/ui.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 24/47] qapi-schema: Collect migration stuff in qapi/migration.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 25/47] qapi-schema: Collect transaction stuff in qapi/transaction.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 26/47] qapi-schema: Collect TPM stuff in qapi/tpm.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 27/47] qapi-schema: Move block events from event.json to block.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 28/47] qapi-schema: Fold event.json back into qapi-schema.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 29/47] qapi-schema: Make block-core.json self-contained Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 30/47] qapi-schema: Move queries from common.json to qapi-schema.json Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 31/47] qapi-schema: Improve section headings Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 32/47] qapi: Update qapi-code-gen.txt examples to match current code Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 33/47] qapi: Drop superfluous qapi_enum_parse() parameter max Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 34/47] tpm: Clean up driver registration & lookup Markus Armbruster
2017-09-01 12:55 ` [Qemu-devel] [PULL 35/47] tpm: Clean up model " Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 36/47] hmp: Use qapi_enum_parse() in hmp_migrate_set_capability() Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 37/47] hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter() Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 38/47] block: Use qemu_enum_parse() in blkdebug_debug_breakpoint() Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 39/47] quorum: Use qapi_enum_parse() in quorum_open() Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 40/47] crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup() Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 41/47] qapi: Use qapi_enum_parse() in input_type_enum() Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 42/47] qapi: Avoid unnecessary use of enum lookup table's sentinel Markus Armbruster
2017-09-01 12:56 ` Markus Armbruster [this message]
2017-09-01 12:56 ` [Qemu-devel] [PULL 44/47] qapi: Mechanically convert FOO_lookup[...] to FOO_str(...) Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 45/47] qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup() Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 46/47] qapi: Change data type of the FOO_lookup generated for enum FOO Markus Armbruster
2017-09-01 12:56 ` [Qemu-devel] [PULL 47/47] qapi: drop the sentinel in enum array Markus Armbruster
2017-09-01 13:58 ` [Qemu-devel] [PULL 00/47] QAPI patches for 2017-09-01 no-reply
2017-09-01 14:34 ` Markus Armbruster
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=20170901125611.29295-44-armbru@redhat.com \
--to=armbru@redhat.com \
--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).