mirror of https://github.com/xemu-project/xemu.git
QAPI patches for 2020-04-30
-----BEGIN PGP SIGNATURE----- iQJGBAABCAAwFiEENUvIs9frKmtoZ05fOHC0AOuRhlMFAl6qYi4SHGFybWJydUBy ZWRoYXQuY29tAAoJEDhwtADrkYZTc88QAJKjuyBjYZY8/SFbn+WVcv736NUoqEC+ /T2YDR8utR836/JK3uSIvz6BQINsAsIScHc2cboto6mjFzMJTVmSqxKZbNVofJr6 KOM13kyIY9NujxM+dcSqKzitwvcZN6aGVTKMVxOqdbmujyqYezFQ7SzMvva1orhG LCFDukvd9MDSoAme/RZnBbYS6qt9k/8bamaBnjZZWjo59xXvSvP9dcDLNp4Q4PmA /vPMjo15cmL5RxPVbXh0YcXkrepNwAVVkMYwBSKkH2pf8MFp3RGVYo5bODPhu/7p K6debFrN2tgPw42HKXU3t7coQq/EP6ectdM9aC9tCXn8ctII83htV22TY9+utzom Hu0BZFhPV9GwKglPYvQiqraG3GFmTqmxdAV2cBDBgsCNdNzitT/LYHJ56NCt2uPm arnJJOE8PjpVRvxDmo/DhX1K5Lo2lDc3XPjQgOqD+R9eyEJJIxTWxSvbYaFqv/QE 5F2pMPFTR+fKvRIF+4OHDUn113CnRMFaGNvnXmXMJSXLZFgJoREb5NiU2sI9XLas 7+buU7qYWpmxt0U+y4rG56Do+tp9Wb5WROMvr9SZxP6AIc/NNdCUYVSdSDV8StgW qhafnxqXy5JeVaiLvuOjvb0ykBXCerrY4bqHA2XYD3LL6ei3lMgVMfir30JiMyJw blp6BssOQUNw =dqCT -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-04-30' into staging QAPI patches for 2020-04-30 # gpg: Signature made Thu 30 Apr 2020 06:29:18 BST # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2020-04-30: qapi: Generate simpler marshalling code when no arguments qapi: Disallow qmp_marshal_FOO(NULL, ...) qom: Simplify object_property_get_enum() qapi: Only input visitors can actually fail qapi: Assert non-input visitors see only valid alternate tags qapi: Clean up visitor's recovery from input with invalid type qapi: Assert non-input visitors see only valid narrow integers qapi: Assert output visitors see only valid enum values qapi: Fix Visitor contract for start_alternate() qapi: Assert incomplete object occurs only in dealloc visitor qapi: Polish prose in visitor.h qapi: Document @errp usage more thoroughly in visitor.h qapi: Fix typo in visit_start_list()'s contract qapi: Fix the virtual walk example in visitor.h's big comment qapi: Belatedly update visitor.h's big comment for QAPI modules qemu-option: Clean up after the previous commit qobject: Eliminate qdict_iter(), use qdict_first(), qdict_next() qobject: Eliminate qlist_iter(), use QLIST_FOREACH_ENTRY() instead qobject: Factor out helper json_pretty_newline() qobject: Clean up QLIST_FOREACH_ENTRY() Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
68bfd7db1e
9
block.c
9
block.c
|
@ -2982,7 +2982,6 @@ BdrvChild *bdrv_open_child(const char *filename,
|
||||||
BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
|
BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs = NULL;
|
BlockDriverState *bs = NULL;
|
||||||
Error *local_err = NULL;
|
|
||||||
QObject *obj = NULL;
|
QObject *obj = NULL;
|
||||||
QDict *qdict = NULL;
|
QDict *qdict = NULL;
|
||||||
const char *reference = NULL;
|
const char *reference = NULL;
|
||||||
|
@ -2995,11 +2994,7 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
|
||||||
assert(ref->type == QTYPE_QDICT);
|
assert(ref->type == QTYPE_QDICT);
|
||||||
|
|
||||||
v = qobject_output_visitor_new(&obj);
|
v = qobject_output_visitor_new(&obj);
|
||||||
visit_type_BlockdevOptions(v, NULL, &options, &local_err);
|
visit_type_BlockdevOptions(v, NULL, &options, &error_abort);
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
|
|
||||||
qdict = qobject_to(QDict, obj);
|
qdict = qobject_to(QDict, obj);
|
||||||
|
@ -3017,8 +3012,6 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
|
||||||
|
|
||||||
bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp);
|
bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp);
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
|
|
||||||
fail:
|
|
||||||
qobject_unref(obj);
|
qobject_unref(obj);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
return bs;
|
return bs;
|
||||||
|
|
|
@ -1854,19 +1854,12 @@ static int sd_create_prealloc(BlockdevOptionsSheepdog *location, int64_t size,
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
QObject *obj = NULL;
|
QObject *obj = NULL;
|
||||||
QDict *qdict;
|
QDict *qdict;
|
||||||
Error *local_err = NULL;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
v = qobject_output_visitor_new(&obj);
|
v = qobject_output_visitor_new(&obj);
|
||||||
visit_type_BlockdevOptionsSheepdog(v, NULL, &location, &local_err);
|
visit_type_BlockdevOptionsSheepdog(v, NULL, &location, &error_abort);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
qobject_unref(obj);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
qdict = qobject_to(QDict, obj);
|
qdict = qobject_to(QDict, obj);
|
||||||
qdict_flatten(qdict);
|
qdict_flatten(qdict);
|
||||||
|
|
||||||
|
|
16
blockdev.c
16
blockdev.c
|
@ -3725,14 +3725,8 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
Visitor *v = qobject_output_visitor_new(&obj);
|
Visitor *v = qobject_output_visitor_new(&obj);
|
||||||
QDict *qdict;
|
QDict *qdict;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
visit_type_BlockdevOptions(v, NULL, &options, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
visit_type_BlockdevOptions(v, NULL, &options, &error_abort);
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
qdict = qobject_to(QDict, obj);
|
qdict = qobject_to(QDict, obj);
|
||||||
|
|
||||||
|
@ -3760,7 +3754,6 @@ void qmp_x_blockdev_reopen(BlockdevOptions *options, Error **errp)
|
||||||
AioContext *ctx;
|
AioContext *ctx;
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
Visitor *v = qobject_output_visitor_new(&obj);
|
Visitor *v = qobject_output_visitor_new(&obj);
|
||||||
Error *local_err = NULL;
|
|
||||||
BlockReopenQueue *queue;
|
BlockReopenQueue *queue;
|
||||||
QDict *qdict;
|
QDict *qdict;
|
||||||
|
|
||||||
|
@ -3777,12 +3770,7 @@ void qmp_x_blockdev_reopen(BlockdevOptions *options, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put all options in a QDict and flatten it */
|
/* Put all options in a QDict and flatten it */
|
||||||
visit_type_BlockdevOptions(v, NULL, &options, &local_err);
|
visit_type_BlockdevOptions(v, NULL, &options, &error_abort);
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
qdict = qobject_to(QDict, obj);
|
qdict = qobject_to(QDict, obj);
|
||||||
|
|
||||||
|
|
|
@ -1446,6 +1446,8 @@ Example:
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!*obj) {
|
if (!*obj) {
|
||||||
|
/* incomplete */
|
||||||
|
assert(visit_is_dealloc(v));
|
||||||
goto out_obj;
|
goto out_obj;
|
||||||
}
|
}
|
||||||
visit_type_UserDefOne_members(v, *obj, &err);
|
visit_type_UserDefOne_members(v, *obj, &err);
|
||||||
|
@ -1577,8 +1579,8 @@ Example:
|
||||||
void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp)
|
void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp)
|
||||||
{
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
UserDefOne *retval;
|
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
|
UserDefOne *retval;
|
||||||
q_obj_my_command_arg arg = {0};
|
q_obj_my_command_arg arg = {0};
|
||||||
|
|
||||||
v = qobject_input_visitor_new(QOBJECT(args));
|
v = qobject_input_visitor_new(QOBJECT(args));
|
||||||
|
|
|
@ -113,7 +113,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
|
||||||
|
|
||||||
while (m) {
|
while (m) {
|
||||||
v = string_output_visitor_new(false, &str);
|
v = string_output_visitor_new(false, &str);
|
||||||
visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
|
visit_type_uint16List(v, NULL, &m->value->host_nodes, &error_abort);
|
||||||
monitor_printf(mon, "memory backend: %s\n", m->value->id);
|
monitor_printf(mon, "memory backend: %s\n", m->value->id);
|
||||||
monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
|
monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
|
||||||
monitor_printf(mon, " merge: %s\n",
|
monitor_printf(mon, " merge: %s\n",
|
||||||
|
|
|
@ -40,9 +40,6 @@ void qdict_del(QDict *qdict, const char *key);
|
||||||
int qdict_haskey(const QDict *qdict, const char *key);
|
int qdict_haskey(const QDict *qdict, const char *key);
|
||||||
QObject *qdict_get(const QDict *qdict, const char *key);
|
QObject *qdict_get(const QDict *qdict, const char *key);
|
||||||
bool qdict_is_equal(const QObject *x, const QObject *y);
|
bool qdict_is_equal(const QObject *x, const QObject *y);
|
||||||
void qdict_iter(const QDict *qdict,
|
|
||||||
void (*iter)(const char *key, QObject *obj, void *opaque),
|
|
||||||
void *opaque);
|
|
||||||
const QDictEntry *qdict_first(const QDict *qdict);
|
const QDictEntry *qdict_first(const QDict *qdict);
|
||||||
const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry);
|
const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry);
|
||||||
void qdict_destroy_obj(QObject *obj);
|
void qdict_destroy_obj(QObject *obj);
|
||||||
|
|
|
@ -34,10 +34,10 @@ void qlist_append_int(QList *qlist, int64_t value);
|
||||||
void qlist_append_null(QList *qlist);
|
void qlist_append_null(QList *qlist);
|
||||||
void qlist_append_str(QList *qlist, const char *value);
|
void qlist_append_str(QList *qlist, const char *value);
|
||||||
|
|
||||||
#define QLIST_FOREACH_ENTRY(qlist, var) \
|
#define QLIST_FOREACH_ENTRY(qlist, var) \
|
||||||
for ((var) = ((qlist)->head.tqh_first); \
|
for ((var) = QTAILQ_FIRST(&(qlist)->head); \
|
||||||
(var); \
|
(var); \
|
||||||
(var) = ((var)->next.tqe_next))
|
(var) = QTAILQ_NEXT((var), next))
|
||||||
|
|
||||||
static inline QObject *qlist_entry_obj(const QListEntry *entry)
|
static inline QObject *qlist_entry_obj(const QListEntry *entry)
|
||||||
{
|
{
|
||||||
|
@ -47,8 +47,6 @@ static inline QObject *qlist_entry_obj(const QListEntry *entry)
|
||||||
QList *qlist_new(void);
|
QList *qlist_new(void);
|
||||||
QList *qlist_copy(QList *src);
|
QList *qlist_copy(QList *src);
|
||||||
void qlist_append_obj(QList *qlist, QObject *obj);
|
void qlist_append_obj(QList *qlist, QObject *obj);
|
||||||
void qlist_iter(const QList *qlist,
|
|
||||||
void (*iter)(QObject *obj, void *opaque), void *opaque);
|
|
||||||
QObject *qlist_pop(QList *qlist);
|
QObject *qlist_pop(QList *qlist);
|
||||||
QObject *qlist_peek(QList *qlist);
|
QObject *qlist_peek(QList *qlist);
|
||||||
int qlist_empty(const QList *qlist);
|
int qlist_empty(const QList *qlist);
|
||||||
|
|
|
@ -43,6 +43,10 @@ typedef enum VisitorType {
|
||||||
|
|
||||||
struct Visitor
|
struct Visitor
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Only input visitors may fail!
|
||||||
|
*/
|
||||||
|
|
||||||
/* Must be set to visit structs */
|
/* Must be set to visit structs */
|
||||||
void (*start_struct)(Visitor *v, const char *name, void **obj,
|
void (*start_struct)(Visitor *v, const char *name, void **obj,
|
||||||
size_t size, Error **errp);
|
size_t size, Error **errp);
|
||||||
|
@ -67,13 +71,12 @@ struct Visitor
|
||||||
/* Must be set */
|
/* Must be set */
|
||||||
void (*end_list)(Visitor *v, void **list);
|
void (*end_list)(Visitor *v, void **list);
|
||||||
|
|
||||||
/* Must be set by input and dealloc visitors to visit alternates;
|
/* Must be set by input and clone visitors to visit alternates */
|
||||||
* optional for output visitors. */
|
|
||||||
void (*start_alternate)(Visitor *v, const char *name,
|
void (*start_alternate)(Visitor *v, const char *name,
|
||||||
GenericAlternate **obj, size_t size,
|
GenericAlternate **obj, size_t size,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
|
|
||||||
/* Optional, needed for dealloc visitor */
|
/* Optional */
|
||||||
void (*end_alternate)(Visitor *v, void **obj);
|
void (*end_alternate)(Visitor *v, void **obj);
|
||||||
|
|
||||||
/* Must be set */
|
/* Must be set */
|
||||||
|
|
|
@ -25,19 +25,21 @@
|
||||||
* for doing work at each node of a QAPI graph; it can also be used
|
* for doing work at each node of a QAPI graph; it can also be used
|
||||||
* for a virtual walk, where there is no actual QAPI C struct.
|
* for a virtual walk, where there is no actual QAPI C struct.
|
||||||
*
|
*
|
||||||
* There are four kinds of visitor classes: input visitors (QObject,
|
* There are four kinds of visitors: input visitors (QObject, string,
|
||||||
* string, and QemuOpts) parse an external representation and build
|
* and QemuOpts) parse an external representation and build the
|
||||||
* the corresponding QAPI graph, output visitors (QObject and string) take
|
* corresponding QAPI object, output visitors (QObject and string)
|
||||||
* a completed QAPI graph and generate an external representation, the
|
* take a QAPI object and generate an external representation, the
|
||||||
* dealloc visitor can take a QAPI graph (possibly partially
|
* dealloc visitor takes a QAPI object (possibly partially
|
||||||
* constructed) and recursively free its resources, and the clone
|
* constructed) and recursively frees it, and the clone visitor
|
||||||
* visitor performs a deep clone of one QAPI object to another. While
|
* performs a deep clone of a QAPI object.
|
||||||
* the dealloc and QObject input/output visitors are general, the string,
|
*
|
||||||
* QemuOpts, and clone visitors have some implementation limitations;
|
* While the dealloc and QObject input/output visitors are general,
|
||||||
* see the documentation for each visitor for more details on what it
|
* the string, QemuOpts, and clone visitors have some implementation
|
||||||
* supports. Also, see visitor-impl.h for the callback contracts
|
* limitations; see the documentation for each visitor for more
|
||||||
* implemented by each visitor, and docs/devel/qapi-code-gen.txt for more
|
* details on what it supports. Also, see visitor-impl.h for the
|
||||||
* about the QAPI code generator.
|
* callback contracts implemented by each visitor, and
|
||||||
|
* docs/devel/qapi-code-gen.txt for more about the QAPI code
|
||||||
|
* generator.
|
||||||
*
|
*
|
||||||
* All of the visitors are created via:
|
* All of the visitors are created via:
|
||||||
*
|
*
|
||||||
|
@ -45,11 +47,15 @@
|
||||||
*
|
*
|
||||||
* A visitor should be used for exactly one top-level visit_type_FOO()
|
* A visitor should be used for exactly one top-level visit_type_FOO()
|
||||||
* or virtual walk; if that is successful, the caller can optionally
|
* or virtual walk; if that is successful, the caller can optionally
|
||||||
* call visit_complete() (for now, useful only for output visits, but
|
* call visit_complete() (useful only for output visits, but safe to
|
||||||
* safe to call on all visits). Then, regardless of success or
|
* call on all visits). Then, regardless of success or failure, the
|
||||||
* failure, the user should call visit_free() to clean up resources.
|
* user should call visit_free() to clean up resources. It is okay to
|
||||||
* It is okay to free the visitor without completing the visit, if
|
* free the visitor without completing the visit, if some other error
|
||||||
* some other error is detected in the meantime.
|
* is detected in the meantime.
|
||||||
|
*
|
||||||
|
* The clone and dealloc visitor should not be used directly outside
|
||||||
|
* of QAPI code. Use the qapi_free_FOO() and QAPI_CLONE() instead,
|
||||||
|
* described below.
|
||||||
*
|
*
|
||||||
* All QAPI types have a corresponding function with a signature
|
* All QAPI types have a corresponding function with a signature
|
||||||
* roughly compatible with this:
|
* roughly compatible with this:
|
||||||
|
@ -58,7 +64,7 @@
|
||||||
*
|
*
|
||||||
* where T is FOO for scalar types, and FOO * otherwise. The scalar
|
* where T is FOO for scalar types, and FOO * otherwise. The scalar
|
||||||
* visitors are declared here; the remaining visitors are generated in
|
* visitors are declared here; the remaining visitors are generated in
|
||||||
* qapi-visit.h.
|
* qapi-visit-MODULE.h.
|
||||||
*
|
*
|
||||||
* The @name parameter of visit_type_FOO() describes the relation
|
* The @name parameter of visit_type_FOO() describes the relation
|
||||||
* between this QAPI value and its parent container. When visiting
|
* between this QAPI value and its parent container. When visiting
|
||||||
|
@ -68,55 +74,56 @@
|
||||||
* alternate, @name should equal the name used for visiting the
|
* alternate, @name should equal the name used for visiting the
|
||||||
* alternate.
|
* alternate.
|
||||||
*
|
*
|
||||||
* The visit_type_FOO() functions expect a non-null @obj argument;
|
* The visit_type_FOO() functions take a non-null @obj argument; they
|
||||||
* they allocate *@obj during input visits, leave it unchanged on
|
* allocate *@obj during input visits, leave it unchanged during
|
||||||
* output visits, and recursively free any resources during a dealloc
|
* output and clone visits, and free it (recursively) during a dealloc
|
||||||
* visit. Each function also takes the customary @errp argument (see
|
* visit.
|
||||||
|
*
|
||||||
|
* Each function also takes the customary @errp argument (see
|
||||||
* qapi/error.h for details), for reporting any errors (such as if a
|
* qapi/error.h for details), for reporting any errors (such as if a
|
||||||
* member @name is not present, or is present but not the specified
|
* member @name is not present, or is present but not the specified
|
||||||
* type).
|
* type). Only input visitors can fail.
|
||||||
*
|
*
|
||||||
* If an error is detected during visit_type_FOO() with an input
|
* If an error is detected during visit_type_FOO() with an input
|
||||||
* visitor, then *@obj will be NULL for pointer types, and left
|
* visitor, then *@obj will be set to NULL for pointer types, and left
|
||||||
* unchanged for scalar types. Using an output or clone visitor with
|
* unchanged for scalar types.
|
||||||
* an incomplete object has undefined behavior (other than a special
|
*
|
||||||
* case for visit_type_str() treating NULL like ""), while the dealloc
|
* Using an output or clone visitor with an incomplete object has
|
||||||
* visitor safely handles incomplete objects. Since input visitors
|
* undefined behavior (other than a special case for visit_type_str()
|
||||||
* never produce an incomplete object, such an object is possible only
|
* treating NULL like ""), while the dealloc visitor safely handles
|
||||||
* by manual construction.
|
* incomplete objects. Since input visitors never produce an
|
||||||
|
* incomplete object, such an object is possible only by manual
|
||||||
|
* construction.
|
||||||
*
|
*
|
||||||
* For the QAPI object types (structs, unions, and alternates), there
|
* For the QAPI object types (structs, unions, and alternates), there
|
||||||
* is an additional generated function in qapi-visit.h compatible
|
* is an additional generated function in qapi-visit-MODULE.h
|
||||||
* with:
|
* compatible with:
|
||||||
*
|
*
|
||||||
* void visit_type_FOO_members(Visitor *v, FOO *obj, Error **errp);
|
* void visit_type_FOO_members(Visitor *v, FOO *obj, Error **errp);
|
||||||
*
|
*
|
||||||
* for visiting the members of a type without also allocating the QAPI
|
* for visiting the members of a type without also allocating the QAPI
|
||||||
* struct.
|
* struct.
|
||||||
*
|
*
|
||||||
* Additionally, in qapi-types.h, all QAPI pointer types (structs,
|
* Additionally, QAPI pointer types (structs, unions, alternates, and
|
||||||
* unions, alternates, and lists) have a generated function compatible
|
* lists) have a generated function in qapi-types-MODULE.h compatible
|
||||||
* with:
|
* with:
|
||||||
*
|
*
|
||||||
* void qapi_free_FOO(FOO *obj);
|
* void qapi_free_FOO(FOO *obj);
|
||||||
*
|
*
|
||||||
* where behaves like free() in that @obj may be NULL. Such objects
|
* Does nothing when @obj is NULL.
|
||||||
* may also be used with the following macro, provided alongside the
|
*
|
||||||
* clone visitor:
|
* Such objects may also be used with macro
|
||||||
*
|
*
|
||||||
* Type *QAPI_CLONE(Type, src);
|
* Type *QAPI_CLONE(Type, src);
|
||||||
*
|
*
|
||||||
* in order to perform a deep clone of @src. Because of the generated
|
* in order to perform a deep clone of @src.
|
||||||
* qapi_free functions and the QAPI_CLONE() macro, the clone and
|
|
||||||
* dealloc visitor should not be used directly outside of QAPI code.
|
|
||||||
*
|
*
|
||||||
* QAPI types can also inherit from a base class; when this happens, a
|
* For QAPI types can that inherit from a base type, a function is
|
||||||
* function is generated for easily going from the derived type to the
|
* generated for going from the derived type to the base type:
|
||||||
* base type:
|
|
||||||
*
|
*
|
||||||
* BASE *qapi_CHILD_base(CHILD *obj);
|
* BASE *qapi_CHILD_base(CHILD *obj);
|
||||||
*
|
*
|
||||||
* For a real QAPI struct, typical input usage involves:
|
* Typical input visitor usage involves:
|
||||||
*
|
*
|
||||||
* <example>
|
* <example>
|
||||||
* Foo *f;
|
* Foo *f;
|
||||||
|
@ -153,36 +160,22 @@
|
||||||
* qapi_free_FooList(l);
|
* qapi_free_FooList(l);
|
||||||
* </example>
|
* </example>
|
||||||
*
|
*
|
||||||
* Similarly, typical output usage is:
|
* Typical output visitor usage:
|
||||||
*
|
*
|
||||||
* <example>
|
* <example>
|
||||||
* Foo *f = ...obtain populated object...
|
* Foo *f = ...obtain populated object...
|
||||||
* Error *err = NULL;
|
|
||||||
* Visitor *v;
|
* Visitor *v;
|
||||||
* Type *result;
|
* Type *result;
|
||||||
*
|
*
|
||||||
* v = FOO_visitor_new(..., &result);
|
* v = FOO_visitor_new(..., &result);
|
||||||
* visit_type_Foo(v, NULL, &f, &err);
|
* visit_type_Foo(v, NULL, &f, &error_abort);
|
||||||
* if (err) {
|
* visit_complete(v, &result);
|
||||||
* ...handle error...
|
|
||||||
* } else {
|
|
||||||
* visit_complete(v, &result);
|
|
||||||
* ...use result...
|
|
||||||
* }
|
|
||||||
* visit_free(v);
|
* visit_free(v);
|
||||||
|
* ...use result...
|
||||||
* </example>
|
* </example>
|
||||||
*
|
*
|
||||||
* When visiting a real QAPI struct, this file provides several
|
|
||||||
* helpers that rely on in-tree information to control the walk:
|
|
||||||
* visit_optional() for the 'has_member' field associated with
|
|
||||||
* optional 'member' in the C struct; and visit_next_list() for
|
|
||||||
* advancing through a FooList linked list. Similarly, the
|
|
||||||
* visit_is_input() helper makes it possible to write code that is
|
|
||||||
* visitor-agnostic everywhere except for cleanup. Only the generated
|
|
||||||
* visit_type functions need to use these helpers.
|
|
||||||
*
|
|
||||||
* It is also possible to use the visitors to do a virtual walk, where
|
* It is also possible to use the visitors to do a virtual walk, where
|
||||||
* no actual QAPI struct is present. In this situation, decisions
|
* no actual QAPI object is present. In this situation, decisions
|
||||||
* about what needs to be walked are made by the calling code, and
|
* about what needs to be walked are made by the calling code, and
|
||||||
* structured visits are split between pairs of start and end methods
|
* structured visits are split between pairs of start and end methods
|
||||||
* (where the end method must be called if the start function
|
* (where the end method must be called if the start function
|
||||||
|
@ -215,6 +208,9 @@
|
||||||
* goto outlist;
|
* goto outlist;
|
||||||
* }
|
* }
|
||||||
* outlist:
|
* outlist:
|
||||||
|
* if (!err) {
|
||||||
|
* visit_check_list(v, &err);
|
||||||
|
* }
|
||||||
* visit_end_list(v, NULL);
|
* visit_end_list(v, NULL);
|
||||||
* if (!err) {
|
* if (!err) {
|
||||||
* visit_check_struct(v, &err);
|
* visit_check_struct(v, &err);
|
||||||
|
@ -222,9 +218,14 @@
|
||||||
* outobj:
|
* outobj:
|
||||||
* visit_end_struct(v, NULL);
|
* visit_end_struct(v, NULL);
|
||||||
* out:
|
* out:
|
||||||
* error_propagate(errp, err);
|
|
||||||
* visit_free(v);
|
* visit_free(v);
|
||||||
* </example>
|
* </example>
|
||||||
|
*
|
||||||
|
* This file provides helpers for use by the generated
|
||||||
|
* visit_type_FOO(): visit_optional() for the 'has_member' field
|
||||||
|
* associated with optional 'member' in the C struct,
|
||||||
|
* visit_next_list() for advancing through a FooList linked list, and
|
||||||
|
* visit_is_input() for cleaning up on failure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*** Useful types ***/
|
/*** Useful types ***/
|
||||||
|
@ -282,9 +283,8 @@ void visit_free(Visitor *v);
|
||||||
* into *@obj. @obj may also be NULL for a virtual walk, in which
|
* into *@obj. @obj may also be NULL for a virtual walk, in which
|
||||||
* case @size is ignored.
|
* case @size is ignored.
|
||||||
*
|
*
|
||||||
* @errp obeys typical error usage, and reports failures such as a
|
* On failure, set *@obj to NULL and store an error through @errp.
|
||||||
* member @name is not present, or present but not an object. On
|
* Can happen only when @v is an input visitor.
|
||||||
* error, input visitors set *@obj to NULL.
|
|
||||||
*
|
*
|
||||||
* After visit_start_struct() succeeds, the caller may visit its
|
* After visit_start_struct() succeeds, the caller may visit its
|
||||||
* members one after the other, passing the member's name and address
|
* members one after the other, passing the member's name and address
|
||||||
|
@ -301,8 +301,8 @@ void visit_start_struct(Visitor *v, const char *name, void **obj,
|
||||||
/*
|
/*
|
||||||
* Prepare for completing an object visit.
|
* Prepare for completing an object visit.
|
||||||
*
|
*
|
||||||
* @errp obeys typical error usage, and reports failures such as
|
* On failure, store an error through @errp. Can happen only when @v
|
||||||
* unparsed keys remaining in the input stream.
|
* is an input visitor.
|
||||||
*
|
*
|
||||||
* Should be called prior to visit_end_struct() if all other
|
* Should be called prior to visit_end_struct() if all other
|
||||||
* intermediate visit steps were successful, to allow the visitor one
|
* intermediate visit steps were successful, to allow the visitor one
|
||||||
|
@ -338,14 +338,13 @@ void visit_end_struct(Visitor *v, void **obj);
|
||||||
* allow @list to be NULL for a virtual walk, in which case @size is
|
* allow @list to be NULL for a virtual walk, in which case @size is
|
||||||
* ignored.
|
* ignored.
|
||||||
*
|
*
|
||||||
* @errp obeys typical error usage, and reports failures such as a
|
* On failure, set *@list to NULL and store an error through @errp.
|
||||||
* member @name is not present, or present but not a list. On error,
|
* Can happen only when @v is an input visitor.
|
||||||
* input visitors set *@list to NULL.
|
|
||||||
*
|
*
|
||||||
* After visit_start_list() succeeds, the caller may visit its members
|
* After visit_start_list() succeeds, the caller may visit its members
|
||||||
* one after the other. A real visit (where @obj is non-NULL) uses
|
* one after the other. A real visit (where @list is non-NULL) uses
|
||||||
* visit_next_list() for traversing the linked list, while a virtual
|
* visit_next_list() for traversing the linked list, while a virtual
|
||||||
* visit (where @obj is NULL) uses other means. For each list
|
* visit (where @list is NULL) uses other means. For each list
|
||||||
* element, call the appropriate visit_type_FOO() with name set to
|
* element, call the appropriate visit_type_FOO() with name set to
|
||||||
* NULL and obj set to the address of the value member of the list
|
* NULL and obj set to the address of the value member of the list
|
||||||
* element. Finally, visit_end_list() needs to be called with the
|
* element. Finally, visit_end_list() needs to be called with the
|
||||||
|
@ -374,8 +373,8 @@ GenericList *visit_next_list(Visitor *v, GenericList *tail, size_t size);
|
||||||
/*
|
/*
|
||||||
* Prepare for completing a list visit.
|
* Prepare for completing a list visit.
|
||||||
*
|
*
|
||||||
* @errp obeys typical error usage, and reports failures such as
|
* On failure, store an error through @errp. Can happen only when @v
|
||||||
* unvisited list tail remaining in the input stream.
|
* is an input visitor.
|
||||||
*
|
*
|
||||||
* Should be called prior to visit_end_list() if all other
|
* Should be called prior to visit_end_list() if all other
|
||||||
* intermediate visit steps were successful, to allow the visitor one
|
* intermediate visit steps were successful, to allow the visitor one
|
||||||
|
@ -407,8 +406,11 @@ void visit_end_list(Visitor *v, void **list);
|
||||||
*
|
*
|
||||||
* @obj must not be NULL. Input and clone visitors use @size to
|
* @obj must not be NULL. Input and clone visitors use @size to
|
||||||
* determine how much memory to allocate into *@obj, then determine
|
* determine how much memory to allocate into *@obj, then determine
|
||||||
* the qtype of the next thing to be visited, stored in (*@obj)->type.
|
* the qtype of the next thing to be visited, and store it in
|
||||||
* Other visitors will leave @obj unchanged.
|
* (*@obj)->type. Other visitors leave @obj unchanged.
|
||||||
|
*
|
||||||
|
* On failure, set *@obj to NULL and store an error through @errp.
|
||||||
|
* Can happen only when @v is an input visitor.
|
||||||
*
|
*
|
||||||
* If successful, this must be paired with visit_end_alternate() with
|
* If successful, this must be paired with visit_end_alternate() with
|
||||||
* the same @obj to clean up, even if visiting the contents of the
|
* the same @obj to clean up, even if visiting the contents of the
|
||||||
|
@ -461,12 +463,15 @@ bool visit_optional(Visitor *v, const char *name, bool *present);
|
||||||
*
|
*
|
||||||
* Currently, all input visitors parse text input, and all output
|
* Currently, all input visitors parse text input, and all output
|
||||||
* visitors produce text output. The mapping between enumeration
|
* visitors produce text output. The mapping between enumeration
|
||||||
* values and strings is done by the visitor core, using @strings; it
|
* values and strings is done by the visitor core, using @lookup.
|
||||||
* should be the ENUM_lookup array from visit-types.h.
|
*
|
||||||
|
* On failure, store an error through @errp. Can happen only when @v
|
||||||
|
* is an input visitor.
|
||||||
*
|
*
|
||||||
* May call visit_type_str() under the hood, and the enum visit may
|
* May call visit_type_str() under the hood, and the enum visit may
|
||||||
* fail even if the corresponding string visit succeeded; this implies
|
* fail even if the corresponding string visit succeeded; this implies
|
||||||
* that visit_type_str() must have no unwelcome side effects.
|
* that an input visitor's visit_type_str() must have no unwelcome
|
||||||
|
* side effects.
|
||||||
*/
|
*/
|
||||||
void visit_type_enum(Visitor *v, const char *name, int *obj,
|
void visit_type_enum(Visitor *v, const char *name, int *obj,
|
||||||
const QEnumLookup *lookup, Error **errp);
|
const QEnumLookup *lookup, Error **errp);
|
||||||
|
@ -476,6 +481,11 @@ void visit_type_enum(Visitor *v, const char *name, int *obj,
|
||||||
*/
|
*/
|
||||||
bool visit_is_input(Visitor *v);
|
bool visit_is_input(Visitor *v);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if visitor is a dealloc visitor.
|
||||||
|
*/
|
||||||
|
bool visit_is_dealloc(Visitor *v);
|
||||||
|
|
||||||
/*** Visiting built-in types ***/
|
/*** Visiting built-in types ***/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -486,6 +496,9 @@ bool visit_is_input(Visitor *v);
|
||||||
*
|
*
|
||||||
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
||||||
* other visitors will leave *@obj unchanged.
|
* other visitors will leave *@obj unchanged.
|
||||||
|
*
|
||||||
|
* On failure, store an error through @errp. Can happen only when @v
|
||||||
|
* is an input visitor.
|
||||||
*/
|
*/
|
||||||
void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp);
|
void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp);
|
||||||
|
|
||||||
|
@ -562,6 +575,9 @@ void visit_type_size(Visitor *v, const char *name, uint64_t *obj,
|
||||||
*
|
*
|
||||||
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
||||||
* other visitors will leave *@obj unchanged.
|
* other visitors will leave *@obj unchanged.
|
||||||
|
*
|
||||||
|
* On failure, store an error through @errp. Can happen only when @v
|
||||||
|
* is an input visitor.
|
||||||
*/
|
*/
|
||||||
void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp);
|
void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp);
|
||||||
|
|
||||||
|
@ -579,6 +595,9 @@ void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp);
|
||||||
* It is safe to cast away const when preparing a (const char *) value
|
* It is safe to cast away const when preparing a (const char *) value
|
||||||
* into @obj for use by an output visitor.
|
* into @obj for use by an output visitor.
|
||||||
*
|
*
|
||||||
|
* On failure, set *@obj to NULL and store an error through @errp.
|
||||||
|
* Can happen only when @v is an input visitor.
|
||||||
|
*
|
||||||
* FIXME: Callers that try to output NULL *obj should not be allowed.
|
* FIXME: Callers that try to output NULL *obj should not be allowed.
|
||||||
*/
|
*/
|
||||||
void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp);
|
void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp);
|
||||||
|
@ -592,6 +611,9 @@ void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp);
|
||||||
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
||||||
* other visitors will leave *@obj unchanged. Visitors should
|
* other visitors will leave *@obj unchanged. Visitors should
|
||||||
* document if infinity or NaN are not permitted.
|
* document if infinity or NaN are not permitted.
|
||||||
|
*
|
||||||
|
* On failure, store an error through @errp. Can happen only when @v
|
||||||
|
* is an input visitor.
|
||||||
*/
|
*/
|
||||||
void visit_type_number(Visitor *v, const char *name, double *obj,
|
void visit_type_number(Visitor *v, const char *name, double *obj,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
|
@ -606,6 +628,9 @@ void visit_type_number(Visitor *v, const char *name, double *obj,
|
||||||
* other visitors will leave *@obj unchanged. *@obj must be non-NULL
|
* other visitors will leave *@obj unchanged. *@obj must be non-NULL
|
||||||
* for output visitors.
|
* for output visitors.
|
||||||
*
|
*
|
||||||
|
* On failure, set *@obj to NULL and store an error through @errp.
|
||||||
|
* Can happen only when @v is an input visitor.
|
||||||
|
*
|
||||||
* Note that some kinds of input can't express arbitrary QObject.
|
* Note that some kinds of input can't express arbitrary QObject.
|
||||||
* E.g. the visitor returned by qobject_input_visitor_new_keyval()
|
* E.g. the visitor returned by qobject_input_visitor_new_keyval()
|
||||||
* can't create numbers or booleans, only strings.
|
* can't create numbers or booleans, only strings.
|
||||||
|
@ -620,6 +645,9 @@ void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp);
|
||||||
*
|
*
|
||||||
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
* @obj must be non-NULL. Input visitors set *@obj to the value;
|
||||||
* other visitors ignore *@obj.
|
* other visitors ignore *@obj.
|
||||||
|
*
|
||||||
|
* On failure, set *@obj to NULL and store an error through @errp.
|
||||||
|
* Can happen only when @v is an input visitor.
|
||||||
*/
|
*/
|
||||||
void visit_type_null(Visitor *v, const char *name, QNull **obj,
|
void visit_type_null(Visitor *v, const char *name, QNull **obj,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
|
|
|
@ -334,7 +334,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
char *str;
|
char *str;
|
||||||
v = string_output_visitor_new(false, &str);
|
v = string_output_visitor_new(false, &str);
|
||||||
visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
|
visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime,
|
||||||
|
&error_abort);
|
||||||
visit_complete(v, &str);
|
visit_complete(v, &str);
|
||||||
monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
|
monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
|
||||||
g_free(str);
|
g_free(str);
|
||||||
|
|
|
@ -322,9 +322,12 @@ static QDict *qmp_greeting(MonitorQMP *mon)
|
||||||
{
|
{
|
||||||
QList *cap_list = qlist_new();
|
QList *cap_list = qlist_new();
|
||||||
QObject *ver = NULL;
|
QObject *ver = NULL;
|
||||||
|
QDict *args;
|
||||||
QMPCapability cap;
|
QMPCapability cap;
|
||||||
|
|
||||||
qmp_marshal_query_version(NULL, &ver, NULL);
|
args = qdict_new();
|
||||||
|
qmp_marshal_query_version(args, &ver, NULL);
|
||||||
|
qobject_unref(args);
|
||||||
|
|
||||||
for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) {
|
for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) {
|
||||||
if (mon->capab_offered[cap]) {
|
if (mon->capab_offered[cap]) {
|
||||||
|
|
|
@ -34,12 +34,6 @@ static void qapi_dealloc_end_struct(Visitor *v, void **obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qapi_dealloc_start_alternate(Visitor *v, const char *name,
|
|
||||||
GenericAlternate **obj, size_t size,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
|
static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
|
||||||
{
|
{
|
||||||
if (obj) {
|
if (obj) {
|
||||||
|
@ -123,7 +117,6 @@ Visitor *qapi_dealloc_visitor_new(void)
|
||||||
v->visitor.type = VISITOR_DEALLOC;
|
v->visitor.type = VISITOR_DEALLOC;
|
||||||
v->visitor.start_struct = qapi_dealloc_start_struct;
|
v->visitor.start_struct = qapi_dealloc_start_struct;
|
||||||
v->visitor.end_struct = qapi_dealloc_end_struct;
|
v->visitor.end_struct = qapi_dealloc_end_struct;
|
||||||
v->visitor.start_alternate = qapi_dealloc_start_alternate;
|
|
||||||
v->visitor.end_alternate = qapi_dealloc_end_alternate;
|
v->visitor.end_alternate = qapi_dealloc_end_alternate;
|
||||||
v->visitor.start_list = qapi_dealloc_start_list;
|
v->visitor.start_list = qapi_dealloc_start_list;
|
||||||
v->visitor.next_list = qapi_dealloc_next_list;
|
v->visitor.next_list = qapi_dealloc_next_list;
|
||||||
|
|
|
@ -142,6 +142,11 @@ bool visit_is_input(Visitor *v)
|
||||||
return v->type == VISITOR_INPUT;
|
return v->type == VISITOR_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool visit_is_dealloc(Visitor *v)
|
||||||
|
{
|
||||||
|
return v->type == VISITOR_DEALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp)
|
void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp)
|
||||||
{
|
{
|
||||||
assert(obj);
|
assert(obj);
|
||||||
|
@ -155,10 +160,13 @@ static void visit_type_uintN(Visitor *v, uint64_t *obj, const char *name,
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
uint64_t value = *obj;
|
uint64_t value = *obj;
|
||||||
|
|
||||||
|
assert(v->type == VISITOR_INPUT || value <= max);
|
||||||
|
|
||||||
v->type_uint64(v, name, &value, &err);
|
v->type_uint64(v, name, &value, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
} else if (value > max) {
|
} else if (value > max) {
|
||||||
|
assert(v->type == VISITOR_INPUT);
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||||
name ? name : "null", type);
|
name ? name : "null", type);
|
||||||
} else {
|
} else {
|
||||||
|
@ -214,10 +222,13 @@ static void visit_type_intN(Visitor *v, int64_t *obj, const char *name,
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
int64_t value = *obj;
|
int64_t value = *obj;
|
||||||
|
|
||||||
|
assert(v->type == VISITOR_INPUT || (value >= min && value <= max));
|
||||||
|
|
||||||
v->type_int64(v, name, &value, &err);
|
v->type_int64(v, name, &value, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
} else if (value < min || value > max) {
|
} else if (value < min || value > max) {
|
||||||
|
assert(v->type == VISITOR_INPUT);
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
||||||
name ? name : "null", type);
|
name ? name : "null", type);
|
||||||
} else {
|
} else {
|
||||||
|
@ -336,15 +347,6 @@ static void output_type_enum(Visitor *v, const char *name, int *obj,
|
||||||
int value = *obj;
|
int value = *obj;
|
||||||
char *enum_str;
|
char *enum_str;
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO why is this an error, not an assertion? If assertion:
|
|
||||||
* delete, and rely on qapi_enum_lookup()
|
|
||||||
*/
|
|
||||||
if (value < 0 || value >= lookup->size) {
|
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER, name ? name : "null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum_str = (char *)qapi_enum_lookup(lookup, value);
|
enum_str = (char *)qapi_enum_lookup(lookup, value);
|
||||||
visit_type_str(v, name, &enum_str, errp);
|
visit_type_str(v, name, &enum_str, errp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,31 +203,32 @@ static const char *qobject_input_get_keyval(QObjectInputVisitor *qiv,
|
||||||
return qstring_get_str(qstr);
|
return qstring_get_str(qstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qdict_add_key(const char *key, QObject *obj, void *opaque)
|
|
||||||
{
|
|
||||||
GHashTable *h = opaque;
|
|
||||||
g_hash_table_insert(h, (gpointer) key, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
|
static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
|
||||||
const char *name,
|
const char *name,
|
||||||
QObject *obj, void *qapi)
|
QObject *obj, void *qapi)
|
||||||
{
|
{
|
||||||
GHashTable *h;
|
GHashTable *h;
|
||||||
StackObject *tos = g_new0(StackObject, 1);
|
StackObject *tos = g_new0(StackObject, 1);
|
||||||
|
QDict *qdict = qobject_to(QDict, obj);
|
||||||
|
QList *qlist = qobject_to(QList, obj);
|
||||||
|
const QDictEntry *entry;
|
||||||
|
|
||||||
assert(obj);
|
assert(obj);
|
||||||
tos->name = name;
|
tos->name = name;
|
||||||
tos->obj = obj;
|
tos->obj = obj;
|
||||||
tos->qapi = qapi;
|
tos->qapi = qapi;
|
||||||
|
|
||||||
if (qobject_type(obj) == QTYPE_QDICT) {
|
if (qdict) {
|
||||||
h = g_hash_table_new(g_str_hash, g_str_equal);
|
h = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
qdict_iter(qobject_to(QDict, obj), qdict_add_key, h);
|
for (entry = qdict_first(qdict);
|
||||||
|
entry;
|
||||||
|
entry = qdict_next(qdict, entry)) {
|
||||||
|
g_hash_table_insert(h, (void *)qdict_entry_key(entry), NULL);
|
||||||
|
}
|
||||||
tos->h = h;
|
tos->h = h;
|
||||||
} else {
|
} else {
|
||||||
assert(qobject_type(obj) == QTYPE_QLIST);
|
assert(qlist);
|
||||||
tos->entry = qlist_first(qobject_to(QList, obj));
|
tos->entry = qlist_first(qlist);
|
||||||
tos->index = -1;
|
tos->index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -298,25 +298,6 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key)
|
||||||
return qstr ? qstring_get_str(qstr) : NULL;
|
return qstr ? qstring_get_str(qstr) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* qdict_iter(): Iterate over all the dictionary's stored values.
|
|
||||||
*
|
|
||||||
* This function allows the user to provide an iterator, which will be
|
|
||||||
* called for each stored value in the dictionary.
|
|
||||||
*/
|
|
||||||
void qdict_iter(const QDict *qdict,
|
|
||||||
void (*iter)(const char *key, QObject *obj, void *opaque),
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
QDictEntry *entry;
|
|
||||||
|
|
||||||
for (i = 0; i < QDICT_BUCKET_MAX; i++) {
|
|
||||||
QLIST_FOREACH(entry, &qdict->table[i], next)
|
|
||||||
iter(entry->key, entry->value, opaque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static QDictEntry *qdict_next_entry(const QDict *qdict, int first_bucket)
|
static QDictEntry *qdict_next_entry(const QDict *qdict, int first_bucket)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
107
qobject/qjson.c
107
qobject/qjson.c
|
@ -149,58 +149,18 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...)
|
||||||
return qdict;
|
return qdict;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct ToJsonIterState
|
|
||||||
{
|
|
||||||
int indent;
|
|
||||||
int pretty;
|
|
||||||
int count;
|
|
||||||
QString *str;
|
|
||||||
} ToJsonIterState;
|
|
||||||
|
|
||||||
static void to_json(const QObject *obj, QString *str, int pretty, int indent);
|
static void to_json(const QObject *obj, QString *str, int pretty, int indent);
|
||||||
|
|
||||||
static void to_json_dict_iter(const char *key, QObject *obj, void *opaque)
|
static void json_pretty_newline(QString *str, bool pretty, int indent)
|
||||||
{
|
{
|
||||||
ToJsonIterState *s = opaque;
|
int i;
|
||||||
QString *qkey;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
if (s->count) {
|
if (pretty) {
|
||||||
qstring_append(s->str, s->pretty ? "," : ", ");
|
qstring_append(str, "\n");
|
||||||
|
for (i = 0; i < indent; i++) {
|
||||||
|
qstring_append(str, " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->pretty) {
|
|
||||||
qstring_append(s->str, "\n");
|
|
||||||
for (j = 0 ; j < s->indent ; j++)
|
|
||||||
qstring_append(s->str, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
qkey = qstring_from_str(key);
|
|
||||||
to_json(QOBJECT(qkey), s->str, s->pretty, s->indent);
|
|
||||||
qobject_unref(qkey);
|
|
||||||
|
|
||||||
qstring_append(s->str, ": ");
|
|
||||||
to_json(obj, s->str, s->pretty, s->indent);
|
|
||||||
s->count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void to_json_list_iter(QObject *obj, void *opaque)
|
|
||||||
{
|
|
||||||
ToJsonIterState *s = opaque;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
if (s->count) {
|
|
||||||
qstring_append(s->str, s->pretty ? "," : ", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->pretty) {
|
|
||||||
qstring_append(s->str, "\n");
|
|
||||||
for (j = 0 ; j < s->indent ; j++)
|
|
||||||
qstring_append(s->str, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
to_json(obj, s->str, s->pretty, s->indent);
|
|
||||||
s->count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void to_json(const QObject *obj, QString *str, int pretty, int indent)
|
static void to_json(const QObject *obj, QString *str, int pretty, int indent)
|
||||||
|
@ -273,40 +233,49 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QTYPE_QDICT: {
|
case QTYPE_QDICT: {
|
||||||
ToJsonIterState s;
|
|
||||||
QDict *val = qobject_to(QDict, obj);
|
QDict *val = qobject_to(QDict, obj);
|
||||||
|
const char *comma = pretty ? "," : ", ";
|
||||||
|
const char *sep = "";
|
||||||
|
const QDictEntry *entry;
|
||||||
|
QString *qkey;
|
||||||
|
|
||||||
s.count = 0;
|
|
||||||
s.str = str;
|
|
||||||
s.indent = indent + 1;
|
|
||||||
s.pretty = pretty;
|
|
||||||
qstring_append(str, "{");
|
qstring_append(str, "{");
|
||||||
qdict_iter(val, to_json_dict_iter, &s);
|
|
||||||
if (pretty) {
|
for (entry = qdict_first(val);
|
||||||
int j;
|
entry;
|
||||||
qstring_append(str, "\n");
|
entry = qdict_next(val, entry)) {
|
||||||
for (j = 0 ; j < indent ; j++)
|
qstring_append(str, sep);
|
||||||
qstring_append(str, " ");
|
json_pretty_newline(str, pretty, indent + 1);
|
||||||
|
|
||||||
|
qkey = qstring_from_str(qdict_entry_key(entry));
|
||||||
|
to_json(QOBJECT(qkey), str, pretty, indent + 1);
|
||||||
|
qobject_unref(qkey);
|
||||||
|
|
||||||
|
qstring_append(str, ": ");
|
||||||
|
to_json(qdict_entry_value(entry), str, pretty, indent + 1);
|
||||||
|
sep = comma;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_pretty_newline(str, pretty, indent);
|
||||||
qstring_append(str, "}");
|
qstring_append(str, "}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QTYPE_QLIST: {
|
case QTYPE_QLIST: {
|
||||||
ToJsonIterState s;
|
|
||||||
QList *val = qobject_to(QList, obj);
|
QList *val = qobject_to(QList, obj);
|
||||||
|
const char *comma = pretty ? "," : ", ";
|
||||||
|
const char *sep = "";
|
||||||
|
QListEntry *entry;
|
||||||
|
|
||||||
s.count = 0;
|
|
||||||
s.str = str;
|
|
||||||
s.indent = indent + 1;
|
|
||||||
s.pretty = pretty;
|
|
||||||
qstring_append(str, "[");
|
qstring_append(str, "[");
|
||||||
qlist_iter(val, (void *)to_json_list_iter, &s);
|
|
||||||
if (pretty) {
|
QLIST_FOREACH_ENTRY(val, entry) {
|
||||||
int j;
|
qstring_append(str, sep);
|
||||||
qstring_append(str, "\n");
|
json_pretty_newline(str, pretty, indent + 1);
|
||||||
for (j = 0 ; j < indent ; j++)
|
to_json(qlist_entry_obj(entry), str, pretty, indent + 1);
|
||||||
qstring_append(str, " ");
|
sep = comma;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_pretty_newline(str, pretty, indent);
|
||||||
qstring_append(str, "]");
|
qstring_append(str, "]");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,20 +34,17 @@ QList *qlist_new(void)
|
||||||
return qlist;
|
return qlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qlist_copy_elem(QObject *obj, void *opaque)
|
|
||||||
{
|
|
||||||
QList *dst = opaque;
|
|
||||||
|
|
||||||
qobject_ref(obj);
|
|
||||||
qlist_append_obj(dst, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList *qlist_copy(QList *src)
|
QList *qlist_copy(QList *src)
|
||||||
{
|
{
|
||||||
QList *dst = qlist_new();
|
QList *dst = qlist_new();
|
||||||
|
QListEntry *entry;
|
||||||
|
QObject *elt;
|
||||||
|
|
||||||
qlist_iter(src, qlist_copy_elem, dst);
|
QLIST_FOREACH_ENTRY(src, entry) {
|
||||||
|
elt = qlist_entry_obj(entry);
|
||||||
|
qobject_ref(elt);
|
||||||
|
qlist_append_obj(dst, elt);
|
||||||
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,21 +83,6 @@ void qlist_append_null(QList *qlist)
|
||||||
qlist_append(qlist, qnull());
|
qlist_append(qlist, qnull());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* qlist_iter(): Iterate over all the list's stored values.
|
|
||||||
*
|
|
||||||
* This function allows the user to provide an iterator, which will be
|
|
||||||
* called for each stored value in the list.
|
|
||||||
*/
|
|
||||||
void qlist_iter(const QList *qlist,
|
|
||||||
void (*iter)(QObject *obj, void *opaque), void *opaque)
|
|
||||||
{
|
|
||||||
QListEntry *entry;
|
|
||||||
|
|
||||||
QTAILQ_FOREACH(entry, &qlist->head, next)
|
|
||||||
iter(entry->value, opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
QObject *qlist_pop(QList *qlist)
|
QObject *qlist_pop(QList *qlist)
|
||||||
{
|
{
|
||||||
QListEntry *entry;
|
QListEntry *entry;
|
||||||
|
@ -137,16 +119,14 @@ int qlist_empty(const QList *qlist)
|
||||||
return QTAILQ_EMPTY(&qlist->head);
|
return QTAILQ_EMPTY(&qlist->head);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qlist_size_iter(QObject *obj, void *opaque)
|
|
||||||
{
|
|
||||||
size_t *count = opaque;
|
|
||||||
(*count)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t qlist_size(const QList *qlist)
|
size_t qlist_size(const QList *qlist)
|
||||||
{
|
{
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
qlist_iter(qlist, qlist_size_iter, &count);
|
QListEntry *entry;
|
||||||
|
|
||||||
|
QLIST_FOREACH_ENTRY(qlist, entry) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1550,11 +1550,9 @@ int object_property_get_enum(Object *obj, const char *name,
|
||||||
}
|
}
|
||||||
visit_complete(v, &str);
|
visit_complete(v, &str);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
v = string_input_visitor_new(str);
|
|
||||||
visit_type_enum(v, name, &ret, enumprop->lookup, errp);
|
|
||||||
|
|
||||||
|
ret = qapi_enum_parse(enumprop->lookup, str, -1, errp);
|
||||||
g_free(str);
|
g_free(str);
|
||||||
visit_free(v);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ def gen_marshal(name, arg_type, boxed, ret_type):
|
||||||
%(proto)s
|
%(proto)s
|
||||||
{
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
Visitor *v;
|
||||||
''',
|
''',
|
||||||
proto=build_marshal_proto(name))
|
proto=build_marshal_proto(name))
|
||||||
|
|
||||||
|
@ -114,44 +115,38 @@ def gen_marshal(name, arg_type, boxed, ret_type):
|
||||||
c_type=ret_type.c_type())
|
c_type=ret_type.c_type())
|
||||||
|
|
||||||
if have_args:
|
if have_args:
|
||||||
visit_members = ('visit_type_%s_members(v, &arg, &err);'
|
|
||||||
% arg_type.c_name())
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
Visitor *v;
|
|
||||||
%(c_name)s arg = {0};
|
%(c_name)s arg = {0};
|
||||||
|
|
||||||
''',
|
''',
|
||||||
c_name=arg_type.c_name())
|
c_name=arg_type.c_name())
|
||||||
else:
|
|
||||||
visit_members = ''
|
|
||||||
ret += mcgen('''
|
|
||||||
Visitor *v = NULL;
|
|
||||||
|
|
||||||
if (args) {
|
|
||||||
''')
|
|
||||||
push_indent()
|
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
|
|
||||||
v = qobject_input_visitor_new(QOBJECT(args));
|
v = qobject_input_visitor_new(QOBJECT(args));
|
||||||
visit_start_struct(v, NULL, NULL, 0, &err);
|
visit_start_struct(v, NULL, NULL, 0, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
%(visit_members)s
|
''')
|
||||||
|
|
||||||
|
if have_args:
|
||||||
|
ret += mcgen('''
|
||||||
|
visit_type_%(c_arg_type)s_members(v, &arg, &err);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
visit_check_struct(v, &err);
|
visit_check_struct(v, &err);
|
||||||
}
|
}
|
||||||
|
''',
|
||||||
|
c_arg_type=arg_type.c_name())
|
||||||
|
else:
|
||||||
|
ret += mcgen('''
|
||||||
|
visit_check_struct(v, &err);
|
||||||
|
''')
|
||||||
|
|
||||||
|
ret += mcgen('''
|
||||||
visit_end_struct(v, NULL);
|
visit_end_struct(v, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
''',
|
|
||||||
visit_members=visit_members)
|
|
||||||
|
|
||||||
if not have_args:
|
|
||||||
pop_indent()
|
|
||||||
ret += mcgen('''
|
|
||||||
}
|
|
||||||
''')
|
''')
|
||||||
|
|
||||||
ret += gen_call(name, arg_type, boxed, ret_type)
|
ret += gen_call(name, arg_type, boxed, ret_type)
|
||||||
|
@ -163,29 +158,20 @@ out:
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
''')
|
''')
|
||||||
|
|
||||||
if have_args:
|
|
||||||
visit_members = ('visit_type_%s_members(v, &arg, NULL);'
|
|
||||||
% arg_type.c_name())
|
|
||||||
else:
|
|
||||||
visit_members = ''
|
|
||||||
ret += mcgen('''
|
|
||||||
if (args) {
|
|
||||||
''')
|
|
||||||
push_indent()
|
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
v = qapi_dealloc_visitor_new();
|
v = qapi_dealloc_visitor_new();
|
||||||
visit_start_struct(v, NULL, NULL, 0, NULL);
|
visit_start_struct(v, NULL, NULL, 0, NULL);
|
||||||
%(visit_members)s
|
''')
|
||||||
|
|
||||||
|
if have_args:
|
||||||
|
ret += mcgen('''
|
||||||
|
visit_type_%(c_arg_type)s_members(v, &arg, NULL);
|
||||||
|
''',
|
||||||
|
c_arg_type=arg_type.c_name())
|
||||||
|
|
||||||
|
ret += mcgen('''
|
||||||
visit_end_struct(v, NULL);
|
visit_end_struct(v, NULL);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
''',
|
|
||||||
visit_members=visit_members)
|
|
||||||
|
|
||||||
if not have_args:
|
|
||||||
pop_indent()
|
|
||||||
ret += mcgen('''
|
|
||||||
}
|
|
||||||
''')
|
''')
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
|
|
|
@ -189,6 +189,8 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!*obj) {
|
if (!*obj) {
|
||||||
|
/* incomplete */
|
||||||
|
assert(visit_is_dealloc(v));
|
||||||
goto out_obj;
|
goto out_obj;
|
||||||
}
|
}
|
||||||
switch ((*obj)->type) {
|
switch ((*obj)->type) {
|
||||||
|
@ -230,8 +232,12 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
|
||||||
case QTYPE_NONE:
|
case QTYPE_NONE:
|
||||||
abort();
|
abort();
|
||||||
default:
|
default:
|
||||||
|
assert(visit_is_input(v));
|
||||||
error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
||||||
"%(name)s");
|
"%(name)s");
|
||||||
|
/* Avoid passing invalid *obj to qapi_free_%(c_name)s() */
|
||||||
|
g_free(*obj);
|
||||||
|
*obj = NULL;
|
||||||
}
|
}
|
||||||
out_obj:
|
out_obj:
|
||||||
visit_end_alternate(v, (void **)obj);
|
visit_end_alternate(v, (void **)obj);
|
||||||
|
@ -260,6 +266,8 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!*obj) {
|
if (!*obj) {
|
||||||
|
/* incomplete */
|
||||||
|
assert(visit_is_dealloc(v));
|
||||||
goto out_obj;
|
goto out_obj;
|
||||||
}
|
}
|
||||||
visit_type_%(c_name)s_members(v, *obj, &err);
|
visit_type_%(c_name)s_members(v, *obj, &err);
|
||||||
|
|
|
@ -61,40 +61,31 @@ static void qobject_to_qlist_test(void)
|
||||||
qobject_unref(qlist);
|
qobject_unref(qlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int iter_called;
|
|
||||||
static const int iter_max = 42;
|
|
||||||
|
|
||||||
static void iter_func(QObject *obj, void *opaque)
|
|
||||||
{
|
|
||||||
QNum *qi;
|
|
||||||
int64_t val;
|
|
||||||
|
|
||||||
g_assert(opaque == NULL);
|
|
||||||
|
|
||||||
qi = qobject_to(QNum, obj);
|
|
||||||
g_assert(qi != NULL);
|
|
||||||
|
|
||||||
g_assert(qnum_get_try_int(qi, &val));
|
|
||||||
g_assert_cmpint(val, >=, 0);
|
|
||||||
g_assert_cmpint(val, <=, iter_max);
|
|
||||||
|
|
||||||
iter_called++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qlist_iter_test(void)
|
static void qlist_iter_test(void)
|
||||||
{
|
{
|
||||||
|
const int iter_max = 42;
|
||||||
int i;
|
int i;
|
||||||
QList *qlist;
|
QList *qlist;
|
||||||
|
QListEntry *entry;
|
||||||
|
QNum *qi;
|
||||||
|
int64_t val;
|
||||||
|
|
||||||
qlist = qlist_new();
|
qlist = qlist_new();
|
||||||
|
|
||||||
for (i = 0; i < iter_max; i++)
|
for (i = 0; i < iter_max; i++)
|
||||||
qlist_append_int(qlist, i);
|
qlist_append_int(qlist, i);
|
||||||
|
|
||||||
iter_called = 0;
|
i = 0;
|
||||||
qlist_iter(qlist, iter_func, NULL);
|
QLIST_FOREACH_ENTRY(qlist, entry) {
|
||||||
|
qi = qobject_to(QNum, qlist_entry_obj(entry));
|
||||||
|
g_assert(qi != NULL);
|
||||||
|
|
||||||
g_assert(iter_called == iter_max);
|
g_assert(qnum_get_try_int(qi, &val));
|
||||||
|
g_assert_cmpint(val, ==, i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert(i == iter_max);
|
||||||
|
|
||||||
qobject_unref(qlist);
|
qobject_unref(qlist);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,21 +141,6 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
|
|
||||||
const void *unused)
|
|
||||||
{
|
|
||||||
EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 };
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
|
|
||||||
Error *err = NULL;
|
|
||||||
|
|
||||||
visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err);
|
|
||||||
error_free_or_abort(&err);
|
|
||||||
visitor_reset(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void test_visitor_out_struct(TestOutputVisitorData *data,
|
static void test_visitor_out_struct(TestOutputVisitorData *data,
|
||||||
const void *unused)
|
const void *unused)
|
||||||
{
|
{
|
||||||
|
@ -234,26 +219,6 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
|
||||||
qapi_free_UserDefTwo(ud2);
|
qapi_free_UserDefTwo(ud2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_visitor_out_struct_errors(TestOutputVisitorData *data,
|
|
||||||
const void *unused)
|
|
||||||
{
|
|
||||||
EnumOne bad_values[] = { ENUM_ONE__MAX, -1 };
|
|
||||||
UserDefOne u = {0};
|
|
||||||
UserDefOne *pu = &u;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
|
|
||||||
Error *err = NULL;
|
|
||||||
|
|
||||||
u.has_enum1 = true;
|
|
||||||
u.enum1 = bad_values[i];
|
|
||||||
visit_type_UserDefOne(data->ov, "unused", &pu, &err);
|
|
||||||
error_free_or_abort(&err);
|
|
||||||
visitor_reset(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void test_visitor_out_list(TestOutputVisitorData *data,
|
static void test_visitor_out_list(TestOutputVisitorData *data,
|
||||||
const void *unused)
|
const void *unused)
|
||||||
{
|
{
|
||||||
|
@ -821,14 +786,10 @@ int main(int argc, char **argv)
|
||||||
&out_visitor_data, test_visitor_out_no_string);
|
&out_visitor_data, test_visitor_out_no_string);
|
||||||
output_visitor_test_add("/visitor/output/enum",
|
output_visitor_test_add("/visitor/output/enum",
|
||||||
&out_visitor_data, test_visitor_out_enum);
|
&out_visitor_data, test_visitor_out_enum);
|
||||||
output_visitor_test_add("/visitor/output/enum-errors",
|
|
||||||
&out_visitor_data, test_visitor_out_enum_errors);
|
|
||||||
output_visitor_test_add("/visitor/output/struct",
|
output_visitor_test_add("/visitor/output/struct",
|
||||||
&out_visitor_data, test_visitor_out_struct);
|
&out_visitor_data, test_visitor_out_struct);
|
||||||
output_visitor_test_add("/visitor/output/struct-nested",
|
output_visitor_test_add("/visitor/output/struct-nested",
|
||||||
&out_visitor_data, test_visitor_out_struct_nested);
|
&out_visitor_data, test_visitor_out_struct_nested);
|
||||||
output_visitor_test_add("/visitor/output/struct-errors",
|
|
||||||
&out_visitor_data, test_visitor_out_struct_errors);
|
|
||||||
output_visitor_test_add("/visitor/output/list",
|
output_visitor_test_add("/visitor/output/list",
|
||||||
&out_visitor_data, test_visitor_out_list);
|
&out_visitor_data, test_visitor_out_list);
|
||||||
output_visitor_test_add("/visitor/output/any",
|
output_visitor_test_add("/visitor/output/any",
|
||||||
|
|
|
@ -203,19 +203,6 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
|
|
||||||
const void *unused)
|
|
||||||
{
|
|
||||||
EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 };
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
|
|
||||||
Error *err = NULL;
|
|
||||||
|
|
||||||
visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err);
|
|
||||||
error_free_or_abort(&err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
output_visitor_test_add(const char *testpath,
|
output_visitor_test_add(const char *testpath,
|
||||||
TestOutputVisitorData *data,
|
TestOutputVisitorData *data,
|
||||||
|
@ -260,12 +247,6 @@ int main(int argc, char **argv)
|
||||||
&out_visitor_data, test_visitor_out_enum, false);
|
&out_visitor_data, test_visitor_out_enum, false);
|
||||||
output_visitor_test_add("/string-visitor/output/enum-human",
|
output_visitor_test_add("/string-visitor/output/enum-human",
|
||||||
&out_visitor_data, test_visitor_out_enum, true);
|
&out_visitor_data, test_visitor_out_enum, true);
|
||||||
output_visitor_test_add("/string-visitor/output/enum-errors",
|
|
||||||
&out_visitor_data, test_visitor_out_enum_errors,
|
|
||||||
false);
|
|
||||||
output_visitor_test_add("/string-visitor/output/enum-errors-human",
|
|
||||||
&out_visitor_data, test_visitor_out_enum_errors,
|
|
||||||
true);
|
|
||||||
output_visitor_test_add("/string-visitor/output/intList",
|
output_visitor_test_add("/string-visitor/output/intList",
|
||||||
&out_visitor_data, test_visitor_out_intList, false);
|
&out_visitor_data, test_visitor_out_intList, false);
|
||||||
output_visitor_test_add("/string-visitor/output/intList-human",
|
output_visitor_test_add("/string-visitor/output/intList-human",
|
||||||
|
|
|
@ -965,18 +965,16 @@ void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
|
||||||
assert(opts);
|
assert(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct OptsFromQDictState {
|
static void qemu_opts_from_qdict_entry(QemuOpts *opts,
|
||||||
QemuOpts *opts;
|
const QDictEntry *entry,
|
||||||
Error **errp;
|
Error **errp)
|
||||||
} OptsFromQDictState;
|
|
||||||
|
|
||||||
static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
|
|
||||||
{
|
{
|
||||||
OptsFromQDictState *state = opaque;
|
const char *key = qdict_entry_key(entry);
|
||||||
|
QObject *obj = qdict_entry_value(entry);
|
||||||
char buf[32], *tmp = NULL;
|
char buf[32], *tmp = NULL;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
if (!strcmp(key, "id") || *state->errp) {
|
if (!strcmp(key, "id")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,7 +995,7 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_opt_set(state->opts, key, value, state->errp);
|
qemu_opt_set(opts, key, value, errp);
|
||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1010,9 +1008,9 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
|
||||||
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
|
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
OptsFromQDictState state;
|
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
|
const QDictEntry *entry;
|
||||||
|
|
||||||
opts = qemu_opts_create(list, qdict_get_try_str(qdict, "id"), 1,
|
opts = qemu_opts_create(list, qdict_get_try_str(qdict, "id"), 1,
|
||||||
&local_err);
|
&local_err);
|
||||||
|
@ -1023,13 +1021,15 @@ QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
|
||||||
|
|
||||||
assert(opts != NULL);
|
assert(opts != NULL);
|
||||||
|
|
||||||
state.errp = &local_err;
|
for (entry = qdict_first(qdict);
|
||||||
state.opts = opts;
|
entry;
|
||||||
qdict_iter(qdict, qemu_opts_from_qdict_1, &state);
|
entry = qdict_next(qdict, entry)) {
|
||||||
if (local_err) {
|
qemu_opts_from_qdict_entry(opts, entry, &local_err);
|
||||||
error_propagate(errp, local_err);
|
if (local_err) {
|
||||||
qemu_opts_del(opts);
|
error_propagate(errp, local_err);
|
||||||
return NULL;
|
qemu_opts_del(opts);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
|
@ -1048,21 +1048,16 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp)
|
||||||
|
|
||||||
while (entry != NULL) {
|
while (entry != NULL) {
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
OptsFromQDictState state = {
|
|
||||||
.errp = &local_err,
|
|
||||||
.opts = opts,
|
|
||||||
};
|
|
||||||
|
|
||||||
next = qdict_next(qdict, entry);
|
next = qdict_next(qdict, entry);
|
||||||
|
|
||||||
if (find_desc_by_name(opts->list->desc, entry->key)) {
|
if (find_desc_by_name(opts->list->desc, entry->key)) {
|
||||||
qemu_opts_from_qdict_1(entry->key, entry->value, &state);
|
qemu_opts_from_qdict_entry(opts, entry, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
qdict_del(qdict, entry->key);
|
|
||||||
}
|
}
|
||||||
|
qdict_del(qdict, entry->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = next;
|
entry = next;
|
||||||
|
|
Loading…
Reference in New Issue