From f90cb2846a0b167d47131ba4600dcc816bccb1c6 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 22 Aug 2017 08:52:19 +0200 Subject: qobject: Explain how QNum works, and why MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suggested-by: Max Reitz Signed-off-by: Markus Armbruster Message-Id: <1503384739-17207-1-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau [Comment typos fixed] --- include/qapi/qmp/qnum.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include') diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h index 09d745c..d6b0791 100644 --- a/include/qapi/qmp/qnum.h +++ b/include/qapi/qmp/qnum.h @@ -23,6 +23,27 @@ typedef enum { QNUM_DOUBLE } QNumKind; +/* + * QNum encapsulates how our dialect of JSON fills in the blanks left + * by the JSON specification (RFC 7159) regarding numbers. + * + * Conceptually, we treat number as an abstract type with three + * concrete subtypes: floating-point, signed integer, unsigned + * integer. QNum implements this as a discriminated union of double, + * int64_t, uint64_t. + * + * The JSON parser picks the subtype as follows. If the number has a + * decimal point or an exponent, it is floating-point. Else if it + * fits into int64_t, it's signed integer. Else if it fits into + * uint64_t, it's unsigned integer. Else it's floating-point. + * + * Any number can serve as double: qnum_get_double() converts under + * the hood. + * + * An integer can serve as signed / unsigned integer as long as it is + * in range: qnum_get_try_int() / qnum_get_try_uint() check range and + * convert under the hood. + */ typedef struct QNum { QObject base; QNumKind kind; -- cgit v1.1 From 0f9afc2a8b5e78e511d79c936aa7b36deb3508bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:00 +0200 Subject: qdict: Add qdict_put_null() helper, and put it to use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170825105913.4060-2-marcandre.lureau@redhat.com> [Update to qobject.cocci squashed in, commit message tweaked] Signed-off-by: Markus Armbruster --- include/qapi/qmp/qdict.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 363e431..6588c7f 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -53,13 +53,15 @@ void qdict_destroy_obj(QObject *obj); #define qdict_put(qdict, key, obj) \ qdict_put_obj(qdict, key, QOBJECT(obj)) -/* Helpers for int, bool, and string */ +/* Helpers for int, bool, null, and string */ #define qdict_put_int(qdict, key, value) \ qdict_put(qdict, key, qnum_from_int(value)) #define qdict_put_bool(qdict, key, value) \ qdict_put(qdict, key, qbool_from_bool(value)) #define qdict_put_str(qdict, key, value) \ qdict_put(qdict, key, qstring_from_str(value)) +#define qdict_put_null(qdict, key) \ + qdict_put(qdict, key, qnull()) /* High level helpers */ double qdict_get_double(const QDict *qdict, const char *key); -- cgit v1.1 From 28035bcdf4647245743cf87cea3788331bf67a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:01 +0200 Subject: qlit: move qlit from check-qjson to qobject/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix code style issues while at it, to please checkpatch. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170825105913.4060-3-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 include/qapi/qmp/qlit.h (limited to 'include') diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h new file mode 100644 index 0000000..280db50 --- /dev/null +++ b/include/qapi/qmp/qlit.h @@ -0,0 +1,49 @@ +/* + * Copyright IBM, Corp. 2009 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster + * Marc-André Lureau + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ +#ifndef QLIT_H +#define QLIT_H + +#include "qapi-types.h" +#include "qobject.h" + +typedef struct LiteralQDictEntry LiteralQDictEntry; +typedef struct LiteralQObject LiteralQObject; + +struct LiteralQObject { + int type; + union { + int64_t qnum; + const char *qstr; + LiteralQDictEntry *qdict; + LiteralQObject *qlist; + } value; +}; + +struct LiteralQDictEntry { + const char *key; + LiteralQObject value; +}; + +#define QLIT_QNUM(val) \ + (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)} +#define QLIT_QSTR(val) \ + (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)} +#define QLIT_QDICT(val) \ + (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)} +#define QLIT_QLIST(val) \ + (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)} + +int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs); + +#endif /* QLIT_H */ -- cgit v1.1 From 082696e767db4d2b6c8c8c233d28291b83fc2b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:02 +0200 Subject: qlit: use QLit prefix consistently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename from LiteralQ to QLit. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170825105913.4060-4-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index 280db50..a4ad913 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -17,33 +17,33 @@ #include "qapi-types.h" #include "qobject.h" -typedef struct LiteralQDictEntry LiteralQDictEntry; -typedef struct LiteralQObject LiteralQObject; +typedef struct QLitDictEntry QLitDictEntry; +typedef struct QLitObject QLitObject; -struct LiteralQObject { +struct QLitObject { int type; union { int64_t qnum; const char *qstr; - LiteralQDictEntry *qdict; - LiteralQObject *qlist; + QLitDictEntry *qdict; + QLitObject *qlist; } value; }; -struct LiteralQDictEntry { +struct QLitDictEntry { const char *key; - LiteralQObject value; + QLitObject value; }; #define QLIT_QNUM(val) \ - (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)} + (QLitObject){.type = QTYPE_QNUM, .value.qnum = (val)} #define QLIT_QSTR(val) \ - (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)} + (QLitObject){.type = QTYPE_QSTRING, .value.qstr = (val)} #define QLIT_QDICT(val) \ - (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)} + (QLitObject){.type = QTYPE_QDICT, .value.qdict = (val)} #define QLIT_QLIST(val) \ - (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)} + (QLitObject){.type = QTYPE_QLIST, .value.qlist = (val)} -int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs); +int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs); #endif /* QLIT_H */ -- cgit v1.1 From d5cd8fbf130312bea91823c41de87d55818d599b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:03 +0200 Subject: qlit: Change compound literals to initializers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QLIT_QFOO() macros expand into compound literals. Sadly, gcc doesn't recognizes these as constant expressions (clang does), which makes the macros useless for initializing objects with static storage duration. There is a gcc bug about it: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71713 Change the macros to expand into initializers. Signed-off-by: Marc-André Lureau Message-Id: <20170825105913.4060-5-marcandre.lureau@redhat.com> [Commit message improved] Signed-off-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index a4ad913..f1d6eed 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -36,13 +36,13 @@ struct QLitDictEntry { }; #define QLIT_QNUM(val) \ - (QLitObject){.type = QTYPE_QNUM, .value.qnum = (val)} + { .type = QTYPE_QNUM, .value.qnum = (val) } #define QLIT_QSTR(val) \ - (QLitObject){.type = QTYPE_QSTRING, .value.qstr = (val)} + { .type = QTYPE_QSTRING, .value.qstr = (val) } #define QLIT_QDICT(val) \ - (QLitObject){.type = QTYPE_QDICT, .value.qdict = (val)} + { .type = QTYPE_QDICT, .value.qdict = (val) } #define QLIT_QLIST(val) \ - (QLitObject){.type = QTYPE_QLIST, .value.qlist = (val)} + { .type = QTYPE_QLIST, .value.qlist = (val) } int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs); -- cgit v1.1 From 60cc2eb7afd40b9cbaa35a5e0b54f365ac6e49f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:04 +0200 Subject: qlit: rename compare_litqobj_to_qobj() to qlit_equal_qobject() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit compare_litqobj_to_qobj() lacks a qlit_ prefix. Moreover, "compare" suggests -1, 0, +1 for less than, equal and greater than. The function actually returns non-zero for equal, zero for unequal. Rename to qlit_equal_qobject(). Its return type will be cleaned up in the next patch. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170825105913.4060-6-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index f1d6eed..5a18047 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -44,6 +44,6 @@ struct QLitDictEntry { #define QLIT_QLIST(val) \ { .type = QTYPE_QLIST, .value.qlist = (val) } -int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs); +int qlit_equal_qobject(QLitObject *lhs, QObject *rhs); #endif /* QLIT_H */ -- cgit v1.1 From d9eba57a6ad6d8fe8cf11bdd8345bbda66deb6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:05 +0200 Subject: qlit: make qlit_equal_qobject return a bool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make it more obvious about the expected return values. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170825105913.4060-7-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index 5a18047..35aabbd 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -44,6 +44,6 @@ struct QLitDictEntry { #define QLIT_QLIST(val) \ { .type = QTYPE_QLIST, .value.qlist = (val) } -int qlit_equal_qobject(QLitObject *lhs, QObject *rhs); +bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs); #endif /* QLIT_H */ -- cgit v1.1 From e2346a19521c6cce417250c75adb0b3a7cd5535a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:06 +0200 Subject: qlit: make qlit_equal_qobject() take const arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170825105913.4060-8-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index 35aabbd..fc1a2d8 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -44,6 +44,6 @@ struct QLitDictEntry { #define QLIT_QLIST(val) \ { .type = QTYPE_QLIST, .value.qlist = (val) } -bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs); +bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs); #endif /* QLIT_H */ -- cgit v1.1 From 6c6084c1b0802f5265d5c7dc27f7125d9fd1cceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 25 Aug 2017 12:59:07 +0200 Subject: qlit: add QLIT_QNULL and QLIT_BOOL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As they are going to be used in the following patches. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170825105913.4060-9-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index fc1a2d8..b18406b 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -23,6 +23,7 @@ typedef struct QLitObject QLitObject; struct QLitObject { int type; union { + bool qbool; int64_t qnum; const char *qstr; QLitDictEntry *qdict; @@ -35,6 +36,10 @@ struct QLitDictEntry { QLitObject value; }; +#define QLIT_QNULL \ + { .type = QTYPE_QNULL } +#define QLIT_QBOOL(val) \ + { .type = QTYPE_QBOOL, .value.qbool = (val) } #define QLIT_QNUM(val) \ { .type = QTYPE_QNUM, .value.qnum = (val) } #define QLIT_QSTR(val) \ -- cgit v1.1 From 06c60b6c468ca7cde004fe7c3ce35de312855f55 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 24 Aug 2017 10:45:57 +0200 Subject: qapi: Drop superfluous qapi_enum_parse() parameter max MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lookup tables have a sentinel, no need to make callers pass their size. Signed-off-by: Markus Armbruster Message-Id: <1503564371-26090-3-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau Reviewed-by: Eric Blake [Rebased, commit message corrected] --- include/qapi/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/qapi/util.h b/include/qapi/util.h index 7436ed8..4eb8a3f 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -12,7 +12,7 @@ #define QAPI_UTIL_H int qapi_enum_parse(const char * const lookup[], const char *buf, - int max, int def, Error **errp); + int def, Error **errp); int parse_qapi_name(const char *name, bool complete); -- cgit v1.1 From a9a72aeefbd3ef8bcbbeeccaf174ee10db2978ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 24 Aug 2017 10:45:58 +0200 Subject: tpm: Clean up driver registration & lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have a strict separation between enum TpmType and be_drivers[]: * TpmType may have any number of members. It just happens to have one. * tpm_register_driver() uses the first empty slot in be_drivers[]. If you register more than tpm_models[] has space, tpm_register_driver() fails. Its caller silently ignores the failure. If you register more than one with a given TpmType, tpm_display_backend_drivers() will shows all of them, but tpm_driver_find_by_type() and tpm_get_backend_driver() will find only the one one that registered first. Since we only ever register one driver, and be_drivers[] has space for just that one, this contraption even works. Turn be_drivers[] into a straight map from enum TpmType to driver. Much simpler, and has a decent chance to actually work should we ever acquire additional drivers. While there, use qapi_enum_parse() in tpm_get_backend_driver(). Signed-off-by: Marc-André Lureau Message-Id: <20170822132255.23945-8-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [Rebased, superfluous initializer dropped, commit message rewritten] Cc: Stefan Berger Signed-off-by: Markus Armbruster Message-Id: <1503564371-26090-4-git-send-email-armbru@redhat.com> --- include/sysemu/tpm_backend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index b58f52d..1d21c6b 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -227,6 +227,6 @@ TPMBackend *qemu_find_tpm(const char *id); const TPMDriverOps *tpm_get_backend_driver(const char *type); int tpm_register_model(enum TpmModel model); -int tpm_register_driver(const TPMDriverOps *tdo); +void tpm_register_driver(const TPMDriverOps *tdo); #endif -- cgit v1.1 From 00bbf50a50e6d6e1a4542db1c1205291395c4105 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 24 Aug 2017 10:45:59 +0200 Subject: tpm: Clean up model registration & lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have a strict separation between enum TpmModel and tpm_models[]: * TpmModel may have any number of members. It just happens to have one. * tpm_register_model() uses the first empty slot in tpm_models[]. If you register more than tpm_models[] has space, tpn_register_model() fails. Its caller silently ignores the failure. Register the same TpmModel more than once has no effect other than wasting tpm_models[] slots: tpm_model_is_registered() is happy with the first one it finds. Since we only ever register one model, and tpm_models[] has space for just that one, this contraption even works. Turn tpm_models[] into a straight map from enum TpmType to bool. Much simpler. Cc: Stefan Berger Signed-off-by: Markus Armbruster Message-Id: <1503564371-26090-5-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau [Commit message typo fixed] --- include/sysemu/tpm_backend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 1d21c6b..b0a9731 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -226,7 +226,7 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s); TPMBackend *qemu_find_tpm(const char *id); const TPMDriverOps *tpm_get_backend_driver(const char *type); -int tpm_register_model(enum TpmModel model); +void tpm_register_model(enum TpmModel model); void tpm_register_driver(const TPMDriverOps *tdo); #endif -- cgit v1.1 From 5b5f825d44306b18509cd10ba9ac6983e90d6e0f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 24 Aug 2017 10:46:07 +0200 Subject: qapi: Generate FOO_str() macro for QAPI enum FOO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Message-Id: <1503564371-26090-13-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau --- include/qapi/util.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/qapi/util.h b/include/qapi/util.h index 4eb8a3f..5e50d0c 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); -- cgit v1.1 From f7abe0ecd4973dfe36944b916c5b9cf8ec199b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 24 Aug 2017 10:46:10 +0200 Subject: qapi: Change data type of the FOO_lookup generated for enum FOO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, a FOO_lookup is an array of strings terminated by a NULL sentinel. A future patch will generate enums with "holes". NULL-termination will cease to work then. To prepare for that, store the length in the FOO_lookup by wrapping it in a struct and adding a member for the length. The sentinel will be dropped next. Signed-off-by: Marc-André Lureau Message-Id: <20170822132255.23945-13-marcandre.lureau@redhat.com> [Basically redone] Signed-off-by: Markus Armbruster Message-Id: <1503564371-26090-16-git-send-email-armbru@redhat.com> [Rebased] --- include/hw/qdev-core.h | 2 +- include/qapi/util.h | 9 +++++++-- include/qapi/visitor.h | 2 +- include/qom/object.h | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index ae31728..0891461 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -249,7 +249,7 @@ struct Property { struct PropertyInfo { const char *name; const char *description; - const char * const *enum_table; + const QEnumLookup *enum_table; int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); void (*set_default_value)(Object *obj, const Property *prop); void (*create)(Object *obj, Property *prop, Error **errp); diff --git a/include/qapi/util.h b/include/qapi/util.h index 5e50d0c..a7c3c64 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -11,8 +11,13 @@ #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, +typedef struct QEnumLookup { + const char *const *array; + int size; +} QEnumLookup; + +const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); +int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, int def, Error **errp); int parse_qapi_name(const char *name, bool complete); diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 0f3b8cb..62a51a5 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -469,7 +469,7 @@ bool visit_optional(Visitor *v, const char *name, bool *present); * that visit_type_str() must have no unwelcome side effects. */ void visit_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], Error **errp); + const QEnumLookup *lookup, Error **errp); /* * Check if visitor is an input visitor. diff --git a/include/qom/object.h b/include/qom/object.h index 1b82899..f3e5cff 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1415,14 +1415,14 @@ void object_class_property_add_bool(ObjectClass *klass, const char *name, */ void object_property_add_enum(Object *obj, const char *name, const char *typename, - const char * const *strings, + const QEnumLookup *lookup, int (*get)(Object *, Error **), void (*set)(Object *, int, Error **), Error **errp); void object_class_property_add_enum(ObjectClass *klass, const char *name, const char *typename, - const char * const *strings, + const QEnumLookup *lookup, int (*get)(Object *, Error **), void (*set)(Object *, int, Error **), Error **errp); -- cgit v1.1