2011-07-19 23:50:33 +04:00
|
|
|
/*
|
|
|
|
* Input Visitor
|
|
|
|
*
|
2016-01-29 16:48:59 +03:00
|
|
|
* Copyright (C) 2012-2016 Red Hat, Inc.
|
2011-07-19 23:50:33 +04:00
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-29 20:49:57 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2016-09-30 17:45:27 +03:00
|
|
|
#include "qapi/qobject-input-visitor.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/visitor-impl.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/queue.h"
|
2011-07-19 23:50:33 +04:00
|
|
|
#include "qemu-common.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/qmp/types.h"
|
|
|
|
#include "qapi/qmp/qerror.h"
|
2011-07-19 23:50:33 +04:00
|
|
|
|
|
|
|
#define QIV_STACK_SIZE 1024
|
|
|
|
|
|
|
|
typedef struct StackObject
|
|
|
|
{
|
2016-04-29 00:45:12 +03:00
|
|
|
QObject *obj; /* Object being visited */
|
qapi: Add parameter to visit_end_*
Rather than making the dealloc visitor track of stack of pointers
remembered during visit_start_* in order to free them during
visit_end_*, it's a lot easier to just make all callers pass the
same pointer to visit_end_*. The generated code has access to the
same pointer, while all other users are doing virtual walks and
can pass NULL. The dealloc visitor is then greatly simplified.
All three visit_end_*() functions intentionally take a void**,
even though the visit_start_*() functions differ between void**,
GenericList**, and GenericAlternate**. This is done for several
reasons: when doing a virtual walk, passing NULL doesn't care
what the type is, but when doing a generated walk, we already
have to cast the caller's specific FOO* to call visit_start,
while using void** lets us use visit_end without a cast. Also,
an upcoming patch will add a clone visitor that wants to use
the same implementation for all three visit_end callbacks,
which is made easier if all three share the same signature.
For visitors with already track per-object state (the QMP visitors
via a stack, and the string visitors which do not allow nesting),
add an assertion that the caller is indeed passing the same
pointer to paired calls.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-4-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 19:48:34 +03:00
|
|
|
void *qapi; /* sanity check that caller uses same pointer */
|
2016-04-29 00:45:12 +03:00
|
|
|
|
|
|
|
GHashTable *h; /* If obj is dict: unvisited keys */
|
|
|
|
const QListEntry *entry; /* If obj is list: unvisited tail */
|
2016-07-07 18:53:18 +03:00
|
|
|
|
|
|
|
QSLIST_ENTRY(StackObject) node;
|
2011-07-19 23:50:33 +04:00
|
|
|
} StackObject;
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
struct QObjectInputVisitor
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
|
|
|
Visitor visitor;
|
2016-04-29 00:45:12 +03:00
|
|
|
|
2016-04-29 00:45:18 +03:00
|
|
|
/* Root of visit at visitor creation. */
|
|
|
|
QObject *root;
|
|
|
|
|
|
|
|
/* Stack of objects being visited (all entries will be either
|
|
|
|
* QDict or QList). */
|
2016-07-07 18:53:18 +03:00
|
|
|
QSLIST_HEAD(, StackObject) stack;
|
2016-04-29 00:45:12 +03:00
|
|
|
|
|
|
|
/* True to reject parse in visit_end_struct() if unvisited keys remain. */
|
2012-03-22 15:51:10 +04:00
|
|
|
bool strict;
|
2011-07-19 23:50:33 +04:00
|
|
|
};
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static QObjectInputVisitor *to_qiv(Visitor *v)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
return container_of(v, QObjectInputVisitor, visitor);
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static QObject *qobject_input_get_object(QObjectInputVisitor *qiv,
|
|
|
|
const char *name,
|
|
|
|
bool consume, Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-04-29 00:45:18 +03:00
|
|
|
StackObject *tos;
|
|
|
|
QObject *qobj;
|
2016-04-29 00:45:15 +03:00
|
|
|
QObject *ret;
|
2016-04-29 00:45:12 +03:00
|
|
|
|
2016-07-07 18:53:18 +03:00
|
|
|
if (QSLIST_EMPTY(&qiv->stack)) {
|
2016-04-29 00:45:18 +03:00
|
|
|
/* Starting at root, name is ignored. */
|
2016-09-30 12:59:46 +03:00
|
|
|
assert(qiv->root);
|
2016-04-29 00:45:18 +03:00
|
|
|
return qiv->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We are in a container; find the next element. */
|
2016-07-07 18:53:18 +03:00
|
|
|
tos = QSLIST_FIRST(&qiv->stack);
|
2016-04-29 00:45:18 +03:00
|
|
|
qobj = tos->obj;
|
2016-04-29 00:45:12 +03:00
|
|
|
assert(qobj);
|
|
|
|
|
2016-04-29 00:45:18 +03:00
|
|
|
if (qobject_type(qobj) == QTYPE_QDICT) {
|
|
|
|
assert(name);
|
2016-04-29 00:45:15 +03:00
|
|
|
ret = qdict_get(qobject_to_qdict(qobj), name);
|
|
|
|
if (tos->h && consume && ret) {
|
|
|
|
bool removed = g_hash_table_remove(tos->h, name);
|
|
|
|
assert(removed);
|
2011-12-18 20:05:04 +04:00
|
|
|
}
|
2016-09-30 12:59:48 +03:00
|
|
|
if (!ret) {
|
|
|
|
error_setg(errp, QERR_MISSING_PARAMETER, name);
|
|
|
|
}
|
2016-04-29 00:45:18 +03:00
|
|
|
} else {
|
2016-04-29 00:45:12 +03:00
|
|
|
assert(qobject_type(qobj) == QTYPE_QLIST);
|
2016-04-29 00:45:18 +03:00
|
|
|
assert(!name);
|
|
|
|
ret = qlist_entry_obj(tos->entry);
|
2016-09-30 12:59:47 +03:00
|
|
|
assert(ret);
|
qmp-input: Refactor when list is advanced
In the QMP input visitor, visiting a list traverses two objects:
the QAPI GenericList of the caller (which gets advanced in
visit_next_list() regardless of this patch), and the QList input
that we are converting to QAPI. For consistency with QDict
visits, we want to consume elements from the input QList during
the visit_type_FOO() for the list element; that is, we want ALL
the code for consuming an input to live in qmp_input_get_object(),
rather than having it split according to whether we are visiting
a dict or a list. Making qmp_input_get_object() the common point
of consumption will make it easier for a later patch to refactor
visit_start_list() to cover the GenericList * head of a QAPI list,
and in turn will get rid of the 'first' flag (which lived in
qmp_input_next_list() pre-patch, and is hoisted to StackObject
by this patch).
This patch is therefore altering the post-condition use of 'entry',
while keeping what gets visited unchanged, from:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry NULL 1st elt 1st elt last elt last elt NULL gone
where type_ELT() returns (entry ? entry : 1st elt) and next_list() steps
entry
to this usage:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry 1st elt 1nd elt 2nd elt last elt NULL NULL gone
where type_ELT() steps entry and returns the old entry, and next_list()
leaves entry alone.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-12-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:19 +03:00
|
|
|
if (consume) {
|
|
|
|
tos->entry = qlist_next(tos->entry);
|
|
|
|
}
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-04-29 00:45:18 +03:00
|
|
|
return ret;
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2012-03-22 15:51:10 +04:00
|
|
|
static void qdict_add_key(const char *key, QObject *obj, void *opaque)
|
|
|
|
{
|
|
|
|
GHashTable *h = opaque;
|
|
|
|
g_hash_table_insert(h, (gpointer) key, NULL);
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
|
|
|
|
QObject *obj, void *qapi,
|
|
|
|
Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2012-03-22 15:51:10 +04:00
|
|
|
GHashTable *h;
|
2016-07-07 18:53:18 +03:00
|
|
|
StackObject *tos = g_new0(StackObject, 1);
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-04-29 00:45:12 +03:00
|
|
|
assert(obj);
|
|
|
|
tos->obj = obj;
|
qapi: Add parameter to visit_end_*
Rather than making the dealloc visitor track of stack of pointers
remembered during visit_start_* in order to free them during
visit_end_*, it's a lot easier to just make all callers pass the
same pointer to visit_end_*. The generated code has access to the
same pointer, while all other users are doing virtual walks and
can pass NULL. The dealloc visitor is then greatly simplified.
All three visit_end_*() functions intentionally take a void**,
even though the visit_start_*() functions differ between void**,
GenericList**, and GenericAlternate**. This is done for several
reasons: when doing a virtual walk, passing NULL doesn't care
what the type is, but when doing a generated walk, we already
have to cast the caller's specific FOO* to call visit_start,
while using void** lets us use visit_end without a cast. Also,
an upcoming patch will add a clone visitor that wants to use
the same implementation for all three visit_end callbacks,
which is made easier if all three share the same signature.
For visitors with already track per-object state (the QMP visitors
via a stack, and the string visitors which do not allow nesting),
add an assertion that the caller is indeed passing the same
pointer to paired calls.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-4-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 19:48:34 +03:00
|
|
|
tos->qapi = qapi;
|
2012-03-22 15:51:10 +04:00
|
|
|
|
|
|
|
if (qiv->strict && qobject_type(obj) == QTYPE_QDICT) {
|
|
|
|
h = g_hash_table_new(g_str_hash, g_str_equal);
|
|
|
|
qdict_iter(qobject_to_qdict(obj), qdict_add_key, h);
|
2016-04-29 00:45:12 +03:00
|
|
|
tos->h = h;
|
qmp-input: Refactor when list is advanced
In the QMP input visitor, visiting a list traverses two objects:
the QAPI GenericList of the caller (which gets advanced in
visit_next_list() regardless of this patch), and the QList input
that we are converting to QAPI. For consistency with QDict
visits, we want to consume elements from the input QList during
the visit_type_FOO() for the list element; that is, we want ALL
the code for consuming an input to live in qmp_input_get_object(),
rather than having it split according to whether we are visiting
a dict or a list. Making qmp_input_get_object() the common point
of consumption will make it easier for a later patch to refactor
visit_start_list() to cover the GenericList * head of a QAPI list,
and in turn will get rid of the 'first' flag (which lived in
qmp_input_next_list() pre-patch, and is hoisted to StackObject
by this patch).
This patch is therefore altering the post-condition use of 'entry',
while keeping what gets visited unchanged, from:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry NULL 1st elt 1st elt last elt last elt NULL gone
where type_ELT() returns (entry ? entry : 1st elt) and next_list() steps
entry
to this usage:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry 1st elt 1nd elt 2nd elt last elt NULL NULL gone
where type_ELT() steps entry and returns the old entry, and next_list()
leaves entry alone.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-12-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:19 +03:00
|
|
|
} else if (qobject_type(obj) == QTYPE_QLIST) {
|
|
|
|
tos->entry = qlist_first(qobject_to_qlist(obj));
|
2012-03-22 15:51:10 +04:00
|
|
|
}
|
|
|
|
|
2016-07-07 18:53:18 +03:00
|
|
|
QSLIST_INSERT_HEAD(&qiv->stack, tos, node);
|
qapi: Simplify semantics of visit_next_list()
The semantics of the list visit are somewhat baroque, with the
following pseudocode when FooList is used:
start()
for (prev = head; cur = next(prev); prev = &cur) {
visit(&cur->value)
}
Note that these semantics (advance before visit) requires that
the first call to next() return the list head, while all other
calls return the next element of the list; that is, every visitor
implementation is required to track extra state to decide whether
to return the input as-is, or to advance. It also requires an
argument of 'GenericList **' to next(), solely because the first
iteration might need to modify the caller's GenericList head, so
that all other calls have to do a layer of dereferencing.
Thankfully, we only have two uses of list visits in the entire
code base: one in spapr_drc (which completely avoids
visit_next_list(), feeding in integers from a different source
than uint8List), and one in qapi-visit.py. That is, all other
list visitors are generated in qapi-visit.c, and share the same
paradigm based on a qapi FooList type, so we can refactor how
lists are laid out with minimal churn among clients.
We can greatly simplify things by hoisting the special case
into the start() routine, and flipping the order in the loop
to visit before advance:
start(head)
for (tail = *head; tail; tail = next(tail)) {
visit(&tail->value)
}
With the simpler semantics, visitors have less state to track,
the argument to next() is reduced to 'GenericList *', and it
also becomes obvious whether an input visitor is allocating a
FooList during visit_start_list() (rather than the old way of
not knowing if an allocation happened until the first
visit_next_list()). As a minor drawback, we now allocate in
two functions instead of one, and have to pass the size to
both functions (unless we were to tweak the input visitors to
cache the size to start_list for reuse during next_list, but
that defeats the goal of less visitor state).
The signature of visit_start_list() is chosen to match
visit_start_struct(), with the new parameters after 'name'.
The spapr_drc case is a virtual visit, done by passing NULL for
list, similarly to how NULL is passed to visit_start_struct()
when a qapi type is not used in those visits. It was easy to
provide these semantics for qmp-output and dealloc visitors,
and a bit harder for qmp-input (several prerequisite patches
refactored things to make this patch straightforward). But it
turned out that the string and opts visitors munge enough other
state during visit_next_list() to make it easier to just
document and require a GenericList visit for now; an assertion
will remind us to adjust things if we need the semantics in the
future.
Several pre-requisite cleanup patches made the reshuffling of
the various visitors easier; particularly the qmp input visitor.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-24-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:31 +03:00
|
|
|
return tos->entry;
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2012-04-21 17:41:27 +04:00
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_check_struct(Visitor *v, Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
2016-07-07 18:53:18 +03:00
|
|
|
StackObject *tos = QSLIST_FIRST(&qiv->stack);
|
2012-03-22 15:51:10 +04:00
|
|
|
|
2016-07-07 18:53:18 +03:00
|
|
|
assert(tos && !tos->entry);
|
2012-04-21 17:41:27 +04:00
|
|
|
if (qiv->strict) {
|
qmp-input: Refactor when list is advanced
In the QMP input visitor, visiting a list traverses two objects:
the QAPI GenericList of the caller (which gets advanced in
visit_next_list() regardless of this patch), and the QList input
that we are converting to QAPI. For consistency with QDict
visits, we want to consume elements from the input QList during
the visit_type_FOO() for the list element; that is, we want ALL
the code for consuming an input to live in qmp_input_get_object(),
rather than having it split according to whether we are visiting
a dict or a list. Making qmp_input_get_object() the common point
of consumption will make it easier for a later patch to refactor
visit_start_list() to cover the GenericList * head of a QAPI list,
and in turn will get rid of the 'first' flag (which lived in
qmp_input_next_list() pre-patch, and is hoisted to StackObject
by this patch).
This patch is therefore altering the post-condition use of 'entry',
while keeping what gets visited unchanged, from:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry NULL 1st elt 1st elt last elt last elt NULL gone
where type_ELT() returns (entry ? entry : 1st elt) and next_list() steps
entry
to this usage:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry 1st elt 1nd elt 2nd elt last elt NULL NULL gone
where type_ELT() steps entry and returns the old entry, and next_list()
leaves entry alone.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-12-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:19 +03:00
|
|
|
GHashTable *const top_ht = tos->h;
|
2012-04-21 17:41:27 +04:00
|
|
|
if (top_ht) {
|
2016-02-18 09:48:15 +03:00
|
|
|
GHashTableIter iter;
|
|
|
|
const char *key;
|
|
|
|
|
|
|
|
g_hash_table_iter_init(&iter, top_ht);
|
|
|
|
if (g_hash_table_iter_next(&iter, (void **)&key, NULL)) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_QMP_EXTRA_MEMBER, key);
|
2012-04-21 17:41:27 +04:00
|
|
|
}
|
qapi: Split visit_end_struct() into pieces
As mentioned in previous patches, we want to call visit_end_struct()
functions unconditionally, so that visitors can release resources
tied up since the matching visit_start_struct() without also having
to worry about error priority if more than one error occurs.
Even though error_propagate() can be safely used to ignore a second
error during cleanup caused by a first error, it is simpler if the
cleanup cannot set an error. So, split out the error checking
portion (basically, input visitors checking for unvisited keys) into
a new function visit_check_struct(), which can be safely skipped if
any earlier errors are encountered, and leave the cleanup portion
(which never fails, but must be called unconditionally if
visit_start_struct() succeeded) in visit_end_struct().
Generated code in qapi-visit.c has diffs resembling:
|@@ -59,10 +59,12 @@ void visit_type_ACPIOSTInfo(Visitor *v,
| goto out_obj;
| }
| visit_type_ACPIOSTInfo_members(v, obj, &err);
|- error_propagate(errp, err);
|- err = NULL;
|+ if (err) {
|+ goto out_obj;
|+ }
|+ visit_check_struct(v, &err);
| out_obj:
|- visit_end_struct(v, &err);
|+ visit_end_struct(v);
| out:
and in qapi-event.c:
@@ -47,7 +47,10 @@ void qapi_event_send_acpi_device_ost(ACP
| goto out;
| }
| visit_type_q_obj_ACPI_DEVICE_OST_arg_members(v, ¶m, &err);
|- visit_end_struct(v, err ? NULL : &err);
|+ if (!err) {
|+ visit_check_struct(v, &err);
|+ }
|+ visit_end_struct(v);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-20-git-send-email-eblake@redhat.com>
[Conflict with a doc fixup resolved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_stack_object_free(StackObject *tos)
|
qapi: Split visit_end_struct() into pieces
As mentioned in previous patches, we want to call visit_end_struct()
functions unconditionally, so that visitors can release resources
tied up since the matching visit_start_struct() without also having
to worry about error priority if more than one error occurs.
Even though error_propagate() can be safely used to ignore a second
error during cleanup caused by a first error, it is simpler if the
cleanup cannot set an error. So, split out the error checking
portion (basically, input visitors checking for unvisited keys) into
a new function visit_check_struct(), which can be safely skipped if
any earlier errors are encountered, and leave the cleanup portion
(which never fails, but must be called unconditionally if
visit_start_struct() succeeded) in visit_end_struct().
Generated code in qapi-visit.c has diffs resembling:
|@@ -59,10 +59,12 @@ void visit_type_ACPIOSTInfo(Visitor *v,
| goto out_obj;
| }
| visit_type_ACPIOSTInfo_members(v, obj, &err);
|- error_propagate(errp, err);
|- err = NULL;
|+ if (err) {
|+ goto out_obj;
|+ }
|+ visit_check_struct(v, &err);
| out_obj:
|- visit_end_struct(v, &err);
|+ visit_end_struct(v);
| out:
and in qapi-event.c:
@@ -47,7 +47,10 @@ void qapi_event_send_acpi_device_ost(ACP
| goto out;
| }
| visit_type_q_obj_ACPI_DEVICE_OST_arg_members(v, ¶m, &err);
|- visit_end_struct(v, err ? NULL : &err);
|+ if (!err) {
|+ visit_check_struct(v, &err);
|+ }
|+ visit_end_struct(v);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-20-git-send-email-eblake@redhat.com>
[Conflict with a doc fixup resolved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:27 +03:00
|
|
|
{
|
2016-07-07 18:53:18 +03:00
|
|
|
if (tos->h) {
|
|
|
|
g_hash_table_unref(tos->h);
|
|
|
|
}
|
qapi: Split visit_end_struct() into pieces
As mentioned in previous patches, we want to call visit_end_struct()
functions unconditionally, so that visitors can release resources
tied up since the matching visit_start_struct() without also having
to worry about error priority if more than one error occurs.
Even though error_propagate() can be safely used to ignore a second
error during cleanup caused by a first error, it is simpler if the
cleanup cannot set an error. So, split out the error checking
portion (basically, input visitors checking for unvisited keys) into
a new function visit_check_struct(), which can be safely skipped if
any earlier errors are encountered, and leave the cleanup portion
(which never fails, but must be called unconditionally if
visit_start_struct() succeeded) in visit_end_struct().
Generated code in qapi-visit.c has diffs resembling:
|@@ -59,10 +59,12 @@ void visit_type_ACPIOSTInfo(Visitor *v,
| goto out_obj;
| }
| visit_type_ACPIOSTInfo_members(v, obj, &err);
|- error_propagate(errp, err);
|- err = NULL;
|+ if (err) {
|+ goto out_obj;
|+ }
|+ visit_check_struct(v, &err);
| out_obj:
|- visit_end_struct(v, &err);
|+ visit_end_struct(v);
| out:
and in qapi-event.c:
@@ -47,7 +47,10 @@ void qapi_event_send_acpi_device_ost(ACP
| goto out;
| }
| visit_type_q_obj_ACPI_DEVICE_OST_arg_members(v, ¶m, &err);
|- visit_end_struct(v, err ? NULL : &err);
|+ if (!err) {
|+ visit_check_struct(v, &err);
|+ }
|+ visit_end_struct(v);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-20-git-send-email-eblake@redhat.com>
[Conflict with a doc fixup resolved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:27 +03:00
|
|
|
|
2016-07-07 18:53:18 +03:00
|
|
|
g_free(tos);
|
|
|
|
}
|
qapi: Split visit_end_struct() into pieces
As mentioned in previous patches, we want to call visit_end_struct()
functions unconditionally, so that visitors can release resources
tied up since the matching visit_start_struct() without also having
to worry about error priority if more than one error occurs.
Even though error_propagate() can be safely used to ignore a second
error during cleanup caused by a first error, it is simpler if the
cleanup cannot set an error. So, split out the error checking
portion (basically, input visitors checking for unvisited keys) into
a new function visit_check_struct(), which can be safely skipped if
any earlier errors are encountered, and leave the cleanup portion
(which never fails, but must be called unconditionally if
visit_start_struct() succeeded) in visit_end_struct().
Generated code in qapi-visit.c has diffs resembling:
|@@ -59,10 +59,12 @@ void visit_type_ACPIOSTInfo(Visitor *v,
| goto out_obj;
| }
| visit_type_ACPIOSTInfo_members(v, obj, &err);
|- error_propagate(errp, err);
|- err = NULL;
|+ if (err) {
|+ goto out_obj;
|+ }
|+ visit_check_struct(v, &err);
| out_obj:
|- visit_end_struct(v, &err);
|+ visit_end_struct(v);
| out:
and in qapi-event.c:
@@ -47,7 +47,10 @@ void qapi_event_send_acpi_device_ost(ACP
| goto out;
| }
| visit_type_q_obj_ACPI_DEVICE_OST_arg_members(v, ¶m, &err);
|- visit_end_struct(v, err ? NULL : &err);
|+ if (!err) {
|+ visit_check_struct(v, &err);
|+ }
|+ visit_end_struct(v);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-20-git-send-email-eblake@redhat.com>
[Conflict with a doc fixup resolved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:27 +03:00
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_pop(Visitor *v, void **obj)
|
2016-07-07 18:53:18 +03:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
2016-07-07 18:53:18 +03:00
|
|
|
StackObject *tos = QSLIST_FIRST(&qiv->stack);
|
2012-03-22 15:51:10 +04:00
|
|
|
|
2016-07-07 18:53:18 +03:00
|
|
|
assert(tos && tos->qapi == obj);
|
|
|
|
QSLIST_REMOVE_HEAD(&qiv->stack, node);
|
2016-09-30 17:45:27 +03:00
|
|
|
qobject_input_stack_object_free(tos);
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_start_struct(Visitor *v, const char *name, void **obj,
|
|
|
|
size_t size, Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2012-03-22 15:51:05 +04:00
|
|
|
Error *err = NULL;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-04-29 00:45:10 +03:00
|
|
|
if (obj) {
|
|
|
|
*obj = NULL;
|
|
|
|
}
|
2016-09-30 12:59:48 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (qobject_type(qobj) != QTYPE_QDICT) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"QDict");
|
2011-07-19 23:50:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
qobject_input_push(qiv, qobj, obj, &err);
|
2012-03-22 15:51:05 +04:00
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2011-07-19 23:50:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj) {
|
2011-08-21 07:09:37 +04:00
|
|
|
*obj = g_malloc0(size);
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_start_list(Visitor *v, const char *name,
|
|
|
|
GenericList **list, size_t size,
|
|
|
|
Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
qapi: Simplify semantics of visit_next_list()
The semantics of the list visit are somewhat baroque, with the
following pseudocode when FooList is used:
start()
for (prev = head; cur = next(prev); prev = &cur) {
visit(&cur->value)
}
Note that these semantics (advance before visit) requires that
the first call to next() return the list head, while all other
calls return the next element of the list; that is, every visitor
implementation is required to track extra state to decide whether
to return the input as-is, or to advance. It also requires an
argument of 'GenericList **' to next(), solely because the first
iteration might need to modify the caller's GenericList head, so
that all other calls have to do a layer of dereferencing.
Thankfully, we only have two uses of list visits in the entire
code base: one in spapr_drc (which completely avoids
visit_next_list(), feeding in integers from a different source
than uint8List), and one in qapi-visit.py. That is, all other
list visitors are generated in qapi-visit.c, and share the same
paradigm based on a qapi FooList type, so we can refactor how
lists are laid out with minimal churn among clients.
We can greatly simplify things by hoisting the special case
into the start() routine, and flipping the order in the loop
to visit before advance:
start(head)
for (tail = *head; tail; tail = next(tail)) {
visit(&tail->value)
}
With the simpler semantics, visitors have less state to track,
the argument to next() is reduced to 'GenericList *', and it
also becomes obvious whether an input visitor is allocating a
FooList during visit_start_list() (rather than the old way of
not knowing if an allocation happened until the first
visit_next_list()). As a minor drawback, we now allocate in
two functions instead of one, and have to pass the size to
both functions (unless we were to tweak the input visitors to
cache the size to start_list for reuse during next_list, but
that defeats the goal of less visitor state).
The signature of visit_start_list() is chosen to match
visit_start_struct(), with the new parameters after 'name'.
The spapr_drc case is a virtual visit, done by passing NULL for
list, similarly to how NULL is passed to visit_start_struct()
when a qapi type is not used in those visits. It was easy to
provide these semantics for qmp-output and dealloc visitors,
and a bit harder for qmp-input (several prerequisite patches
refactored things to make this patch straightforward). But it
turned out that the string and opts visitors munge enough other
state during visit_next_list() to make it easier to just
document and require a GenericList visit for now; an assertion
will remind us to adjust things if we need the semantics in the
future.
Several pre-requisite cleanup patches made the reshuffling of
the various visitors easier; particularly the qmp input visitor.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-24-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:31 +03:00
|
|
|
const QListEntry *entry;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-09-30 12:59:48 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (qobject_type(qobj) != QTYPE_QLIST) {
|
qapi: Simplify semantics of visit_next_list()
The semantics of the list visit are somewhat baroque, with the
following pseudocode when FooList is used:
start()
for (prev = head; cur = next(prev); prev = &cur) {
visit(&cur->value)
}
Note that these semantics (advance before visit) requires that
the first call to next() return the list head, while all other
calls return the next element of the list; that is, every visitor
implementation is required to track extra state to decide whether
to return the input as-is, or to advance. It also requires an
argument of 'GenericList **' to next(), solely because the first
iteration might need to modify the caller's GenericList head, so
that all other calls have to do a layer of dereferencing.
Thankfully, we only have two uses of list visits in the entire
code base: one in spapr_drc (which completely avoids
visit_next_list(), feeding in integers from a different source
than uint8List), and one in qapi-visit.py. That is, all other
list visitors are generated in qapi-visit.c, and share the same
paradigm based on a qapi FooList type, so we can refactor how
lists are laid out with minimal churn among clients.
We can greatly simplify things by hoisting the special case
into the start() routine, and flipping the order in the loop
to visit before advance:
start(head)
for (tail = *head; tail; tail = next(tail)) {
visit(&tail->value)
}
With the simpler semantics, visitors have less state to track,
the argument to next() is reduced to 'GenericList *', and it
also becomes obvious whether an input visitor is allocating a
FooList during visit_start_list() (rather than the old way of
not knowing if an allocation happened until the first
visit_next_list()). As a minor drawback, we now allocate in
two functions instead of one, and have to pass the size to
both functions (unless we were to tweak the input visitors to
cache the size to start_list for reuse during next_list, but
that defeats the goal of less visitor state).
The signature of visit_start_list() is chosen to match
visit_start_struct(), with the new parameters after 'name'.
The spapr_drc case is a virtual visit, done by passing NULL for
list, similarly to how NULL is passed to visit_start_struct()
when a qapi type is not used in those visits. It was easy to
provide these semantics for qmp-output and dealloc visitors,
and a bit harder for qmp-input (several prerequisite patches
refactored things to make this patch straightforward). But it
turned out that the string and opts visitors munge enough other
state during visit_next_list() to make it easier to just
document and require a GenericList visit for now; an assertion
will remind us to adjust things if we need the semantics in the
future.
Several pre-requisite cleanup patches made the reshuffling of
the various visitors easier; particularly the qmp input visitor.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-24-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:31 +03:00
|
|
|
if (list) {
|
|
|
|
*list = NULL;
|
|
|
|
}
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"list");
|
2011-07-19 23:50:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
entry = qobject_input_push(qiv, qobj, list, errp);
|
qapi: Simplify semantics of visit_next_list()
The semantics of the list visit are somewhat baroque, with the
following pseudocode when FooList is used:
start()
for (prev = head; cur = next(prev); prev = &cur) {
visit(&cur->value)
}
Note that these semantics (advance before visit) requires that
the first call to next() return the list head, while all other
calls return the next element of the list; that is, every visitor
implementation is required to track extra state to decide whether
to return the input as-is, or to advance. It also requires an
argument of 'GenericList **' to next(), solely because the first
iteration might need to modify the caller's GenericList head, so
that all other calls have to do a layer of dereferencing.
Thankfully, we only have two uses of list visits in the entire
code base: one in spapr_drc (which completely avoids
visit_next_list(), feeding in integers from a different source
than uint8List), and one in qapi-visit.py. That is, all other
list visitors are generated in qapi-visit.c, and share the same
paradigm based on a qapi FooList type, so we can refactor how
lists are laid out with minimal churn among clients.
We can greatly simplify things by hoisting the special case
into the start() routine, and flipping the order in the loop
to visit before advance:
start(head)
for (tail = *head; tail; tail = next(tail)) {
visit(&tail->value)
}
With the simpler semantics, visitors have less state to track,
the argument to next() is reduced to 'GenericList *', and it
also becomes obvious whether an input visitor is allocating a
FooList during visit_start_list() (rather than the old way of
not knowing if an allocation happened until the first
visit_next_list()). As a minor drawback, we now allocate in
two functions instead of one, and have to pass the size to
both functions (unless we were to tweak the input visitors to
cache the size to start_list for reuse during next_list, but
that defeats the goal of less visitor state).
The signature of visit_start_list() is chosen to match
visit_start_struct(), with the new parameters after 'name'.
The spapr_drc case is a virtual visit, done by passing NULL for
list, similarly to how NULL is passed to visit_start_struct()
when a qapi type is not used in those visits. It was easy to
provide these semantics for qmp-output and dealloc visitors,
and a bit harder for qmp-input (several prerequisite patches
refactored things to make this patch straightforward). But it
turned out that the string and opts visitors munge enough other
state during visit_next_list() to make it easier to just
document and require a GenericList visit for now; an assertion
will remind us to adjust things if we need the semantics in the
future.
Several pre-requisite cleanup patches made the reshuffling of
the various visitors easier; particularly the qmp input visitor.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-24-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:31 +03:00
|
|
|
if (list) {
|
|
|
|
if (entry) {
|
|
|
|
*list = g_malloc0(size);
|
|
|
|
} else {
|
|
|
|
*list = NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static GenericList *qobject_input_next_list(Visitor *v, GenericList *tail,
|
|
|
|
size_t size)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
2016-07-07 18:53:18 +03:00
|
|
|
StackObject *so = QSLIST_FIRST(&qiv->stack);
|
2011-07-19 23:50:33 +04:00
|
|
|
|
qmp-input: Refactor when list is advanced
In the QMP input visitor, visiting a list traverses two objects:
the QAPI GenericList of the caller (which gets advanced in
visit_next_list() regardless of this patch), and the QList input
that we are converting to QAPI. For consistency with QDict
visits, we want to consume elements from the input QList during
the visit_type_FOO() for the list element; that is, we want ALL
the code for consuming an input to live in qmp_input_get_object(),
rather than having it split according to whether we are visiting
a dict or a list. Making qmp_input_get_object() the common point
of consumption will make it easier for a later patch to refactor
visit_start_list() to cover the GenericList * head of a QAPI list,
and in turn will get rid of the 'first' flag (which lived in
qmp_input_next_list() pre-patch, and is hoisted to StackObject
by this patch).
This patch is therefore altering the post-condition use of 'entry',
while keeping what gets visited unchanged, from:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry NULL 1st elt 1st elt last elt last elt NULL gone
where type_ELT() returns (entry ? entry : 1st elt) and next_list() steps
entry
to this usage:
start_list next_list type_ELT ... next_list type_ELT next_list end_list
visits 1st elt last elt
entry 1st elt 1nd elt 2nd elt last elt NULL NULL gone
where type_ELT() steps entry and returns the old entry, and next_list()
leaves entry alone.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-12-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:19 +03:00
|
|
|
if (!so->entry) {
|
2011-07-19 23:50:33 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
qapi: Simplify semantics of visit_next_list()
The semantics of the list visit are somewhat baroque, with the
following pseudocode when FooList is used:
start()
for (prev = head; cur = next(prev); prev = &cur) {
visit(&cur->value)
}
Note that these semantics (advance before visit) requires that
the first call to next() return the list head, while all other
calls return the next element of the list; that is, every visitor
implementation is required to track extra state to decide whether
to return the input as-is, or to advance. It also requires an
argument of 'GenericList **' to next(), solely because the first
iteration might need to modify the caller's GenericList head, so
that all other calls have to do a layer of dereferencing.
Thankfully, we only have two uses of list visits in the entire
code base: one in spapr_drc (which completely avoids
visit_next_list(), feeding in integers from a different source
than uint8List), and one in qapi-visit.py. That is, all other
list visitors are generated in qapi-visit.c, and share the same
paradigm based on a qapi FooList type, so we can refactor how
lists are laid out with minimal churn among clients.
We can greatly simplify things by hoisting the special case
into the start() routine, and flipping the order in the loop
to visit before advance:
start(head)
for (tail = *head; tail; tail = next(tail)) {
visit(&tail->value)
}
With the simpler semantics, visitors have less state to track,
the argument to next() is reduced to 'GenericList *', and it
also becomes obvious whether an input visitor is allocating a
FooList during visit_start_list() (rather than the old way of
not knowing if an allocation happened until the first
visit_next_list()). As a minor drawback, we now allocate in
two functions instead of one, and have to pass the size to
both functions (unless we were to tweak the input visitors to
cache the size to start_list for reuse during next_list, but
that defeats the goal of less visitor state).
The signature of visit_start_list() is chosen to match
visit_start_struct(), with the new parameters after 'name'.
The spapr_drc case is a virtual visit, done by passing NULL for
list, similarly to how NULL is passed to visit_start_struct()
when a qapi type is not used in those visits. It was easy to
provide these semantics for qmp-output and dealloc visitors,
and a bit harder for qmp-input (several prerequisite patches
refactored things to make this patch straightforward). But it
turned out that the string and opts visitors munge enough other
state during visit_next_list() to make it easier to just
document and require a GenericList visit for now; an assertion
will remind us to adjust things if we need the semantics in the
future.
Several pre-requisite cleanup patches made the reshuffling of
the various visitors easier; particularly the qmp input visitor.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-24-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:31 +03:00
|
|
|
tail->next = g_malloc0(size);
|
|
|
|
return tail->next;
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_start_alternate(Visitor *v, const char *name,
|
|
|
|
GenericAlternate **obj, size_t size,
|
|
|
|
bool promote_int, Error **errp)
|
2013-07-08 18:14:21 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, false, errp);
|
2013-07-08 18:14:21 +04:00
|
|
|
|
|
|
|
if (!qobj) {
|
qapi: Change visit_start_implicit_struct to visit_start_alternate
After recent changes, the only remaining use of
visit_start_implicit_struct() is for allocating the space needed
when visiting an alternate. Since the term 'implicit struct' is
hard to explain, rename the function to its current usage. While
at it, we can merge the functionality of visit_get_next_type()
into the same function, making it more like visit_start_struct().
Generated code is now slightly smaller:
| {
| Error *err = NULL;
|
|- visit_start_implicit_struct(v, (void**) obj, sizeof(BlockdevRef), &err);
|+ visit_start_alternate(v, name, (GenericAlternate **)obj, sizeof(**obj),
|+ true, &err);
| if (err) {
| goto out;
| }
|- visit_get_next_type(v, name, &(*obj)->type, true, &err);
|- if (err) {
|- goto out_obj;
|- }
| switch ((*obj)->type) {
| case QTYPE_QDICT:
| visit_start_struct(v, name, NULL, 0, &err);
...
| }
|-out_obj:
|- visit_end_implicit_struct(v);
|+ visit_end_alternate(v);
| out:
| error_propagate(errp, err);
| }
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1455778109-6278-16-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-02-18 09:48:29 +03:00
|
|
|
*obj = NULL;
|
2013-07-08 18:14:21 +04:00
|
|
|
return;
|
|
|
|
}
|
qapi: Change visit_start_implicit_struct to visit_start_alternate
After recent changes, the only remaining use of
visit_start_implicit_struct() is for allocating the space needed
when visiting an alternate. Since the term 'implicit struct' is
hard to explain, rename the function to its current usage. While
at it, we can merge the functionality of visit_get_next_type()
into the same function, making it more like visit_start_struct().
Generated code is now slightly smaller:
| {
| Error *err = NULL;
|
|- visit_start_implicit_struct(v, (void**) obj, sizeof(BlockdevRef), &err);
|+ visit_start_alternate(v, name, (GenericAlternate **)obj, sizeof(**obj),
|+ true, &err);
| if (err) {
| goto out;
| }
|- visit_get_next_type(v, name, &(*obj)->type, true, &err);
|- if (err) {
|- goto out_obj;
|- }
| switch ((*obj)->type) {
| case QTYPE_QDICT:
| visit_start_struct(v, name, NULL, 0, &err);
...
| }
|-out_obj:
|- visit_end_implicit_struct(v);
|+ visit_end_alternate(v);
| out:
| error_propagate(errp, err);
| }
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1455778109-6278-16-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-02-18 09:48:29 +03:00
|
|
|
*obj = g_malloc0(size);
|
|
|
|
(*obj)->type = qobject_type(qobj);
|
|
|
|
if (promote_int && (*obj)->type == QTYPE_QINT) {
|
|
|
|
(*obj)->type = QTYPE_QFLOAT;
|
2015-12-02 08:20:51 +03:00
|
|
|
}
|
2013-07-08 18:14:21 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_type_int64(Visitor *v, const char *name, int64_t *obj,
|
|
|
|
Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2016-09-30 12:59:48 +03:00
|
|
|
QInt *qint;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-09-30 12:59:48 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qint = qobject_to_qint(qobj);
|
2015-10-15 17:15:35 +03:00
|
|
|
if (!qint) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"integer");
|
2011-07-19 23:50:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-15 17:15:35 +03:00
|
|
|
*obj = qint_get_int(qint);
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_type_uint64(Visitor *v, const char *name,
|
|
|
|
uint64_t *obj, Error **errp)
|
qapi: Make all visitors supply uint64 callbacks
Our qapi visitor contract supports multiple integer visitors,
but left the type_uint64 visitor as optional (falling back on
type_int64); which in turn can lead to awkward behavior with
numbers larger than INT64_MAX (the user has to be aware of
twos complement, and deal with negatives).
This patch does not address the disparity in handling large
values as negatives. It merely moves the fallback from uint64
to int64 from the visitor core to the visitors, where the issue
can actually be fixed, by implementing the missing type_uint64()
callbacks on top of the respective type_int64() callbacks, and
with a FIXME comment explaining why that's wrong.
With that done, we now have a type_uint64() callback in every
driver, so we can make it mandatory from the core. And although
the type_int64() callback can cover the entire valid range of
type_uint{8,16,32} on valid user input, using type_uint64() to
avoid mixed signedness makes more sense.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1454075341-13658-15-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:50 +03:00
|
|
|
{
|
|
|
|
/* FIXME: qobject_to_qint mishandles values over INT64_MAX */
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2016-09-30 12:59:48 +03:00
|
|
|
QInt *qint;
|
qapi: Make all visitors supply uint64 callbacks
Our qapi visitor contract supports multiple integer visitors,
but left the type_uint64 visitor as optional (falling back on
type_int64); which in turn can lead to awkward behavior with
numbers larger than INT64_MAX (the user has to be aware of
twos complement, and deal with negatives).
This patch does not address the disparity in handling large
values as negatives. It merely moves the fallback from uint64
to int64 from the visitor core to the visitors, where the issue
can actually be fixed, by implementing the missing type_uint64()
callbacks on top of the respective type_int64() callbacks, and
with a FIXME comment explaining why that's wrong.
With that done, we now have a type_uint64() callback in every
driver, so we can make it mandatory from the core. And although
the type_int64() callback can cover the entire valid range of
type_uint{8,16,32} on valid user input, using type_uint64() to
avoid mixed signedness makes more sense.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1454075341-13658-15-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:50 +03:00
|
|
|
|
2016-09-30 12:59:48 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qint = qobject_to_qint(qobj);
|
qapi: Make all visitors supply uint64 callbacks
Our qapi visitor contract supports multiple integer visitors,
but left the type_uint64 visitor as optional (falling back on
type_int64); which in turn can lead to awkward behavior with
numbers larger than INT64_MAX (the user has to be aware of
twos complement, and deal with negatives).
This patch does not address the disparity in handling large
values as negatives. It merely moves the fallback from uint64
to int64 from the visitor core to the visitors, where the issue
can actually be fixed, by implementing the missing type_uint64()
callbacks on top of the respective type_int64() callbacks, and
with a FIXME comment explaining why that's wrong.
With that done, we now have a type_uint64() callback in every
driver, so we can make it mandatory from the core. And although
the type_int64() callback can cover the entire valid range of
type_uint{8,16,32} on valid user input, using type_uint64() to
avoid mixed signedness makes more sense.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1454075341-13658-15-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:50 +03:00
|
|
|
if (!qint) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"integer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = qint_get_int(qint);
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_type_bool(Visitor *v, const char *name, bool *obj,
|
|
|
|
Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2016-09-30 12:59:48 +03:00
|
|
|
QBool *qbool;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-09-30 12:59:48 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qbool = qobject_to_qbool(qobj);
|
2015-10-15 17:15:33 +03:00
|
|
|
if (!qbool) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"boolean");
|
2011-07-19 23:50:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-15 17:15:33 +03:00
|
|
|
*obj = qbool_get_bool(qbool);
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_type_str(Visitor *v, const char *name, char **obj,
|
|
|
|
Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2016-09-30 12:59:48 +03:00
|
|
|
QString *qstr;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-09-30 12:59:48 +03:00
|
|
|
*obj = NULL;
|
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qstr = qobject_to_qstring(qobj);
|
2015-10-15 17:15:37 +03:00
|
|
|
if (!qstr) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"string");
|
2011-07-19 23:50:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-15 17:15:37 +03:00
|
|
|
*obj = g_strdup(qstring_get_str(qstr));
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_type_number(Visitor *v, const char *name, double *obj,
|
|
|
|
Error **errp)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2015-10-15 17:15:35 +03:00
|
|
|
QInt *qint;
|
|
|
|
QFloat *qfloat;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-09-30 12:59:48 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-15 17:15:35 +03:00
|
|
|
qint = qobject_to_qint(qobj);
|
|
|
|
if (qint) {
|
|
|
|
*obj = qint_get_int(qobject_to_qint(qobj));
|
2011-07-19 23:50:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-15 17:15:35 +03:00
|
|
|
qfloat = qobject_to_qfloat(qobj);
|
|
|
|
if (qfloat) {
|
2012-05-11 21:43:24 +04:00
|
|
|
*obj = qfloat_get_double(qobject_to_qfloat(qobj));
|
2015-10-15 17:15:35 +03:00
|
|
|
return;
|
2012-05-11 21:43:24 +04:00
|
|
|
}
|
2015-10-15 17:15:35 +03:00
|
|
|
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"number");
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj,
|
|
|
|
Error **errp)
|
2015-09-16 14:06:24 +03:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2015-09-16 14:06:24 +03:00
|
|
|
|
2016-09-30 12:59:48 +03:00
|
|
|
*obj = NULL;
|
2016-09-22 23:39:26 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-16 14:06:24 +03:00
|
|
|
qobject_incref(qobj);
|
|
|
|
*obj = qobj;
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_type_null(Visitor *v, const char *name, Error **errp)
|
qapi: Add visit_type_null() visitor
Right now, qmp-output-visitor happens to produce a QNull result
if nothing is actually visited between the creation of the visitor
and the request for the resulting QObject. A stronger protocol
would require that a QMP output visit MUST visit something. But
to still be able to produce a JSON 'null' output, we need a new
visitor function that states our intentions. Yes, we could say
that such a visit must go through visit_type_any(), but that
feels clunky.
So this patch introduces the new visit_type_null() interface and
its no-op interface in the dealloc visitor, and stubs in the
qmp visitors (the next patch will finish the implementation).
For the visitors that will not implement the callback, document
the situation. The code in qapi-visit-core unconditionally
dereferences the callback pointer, so that a segfault will inform
a developer if they need to implement the callback for their
choice of visitor.
Note that JSON has a primitive null type, with the single value
null; likewise with the QNull type for QObject; but for QAPI,
we just have the 'null' value without a null type. We may
eventually want to add more support in QAPI for null (most likely,
we'd use it via an alternate type that permits 'null' or an
object); but we'll create that usage when we need it.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-15-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:22 +03:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
|
2016-04-29 00:45:23 +03:00
|
|
|
|
2016-09-22 23:39:26 +03:00
|
|
|
if (!qobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:45:23 +03:00
|
|
|
if (qobject_type(qobj) != QTYPE_QNULL) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
|
|
|
|
"null");
|
|
|
|
}
|
qapi: Add visit_type_null() visitor
Right now, qmp-output-visitor happens to produce a QNull result
if nothing is actually visited between the creation of the visitor
and the request for the resulting QObject. A stronger protocol
would require that a QMP output visit MUST visit something. But
to still be able to produce a JSON 'null' output, we need a new
visitor function that states our intentions. Yes, we could say
that such a visit must go through visit_type_any(), but that
feels clunky.
So this patch introduces the new visit_type_null() interface and
its no-op interface in the dealloc visitor, and stubs in the
qmp visitors (the next patch will finish the implementation).
For the visitors that will not implement the callback, document
the situation. The code in qapi-visit-core unconditionally
dereferences the callback pointer, so that a segfault will inform
a developer if they need to implement the callback for their
choice of visitor.
Note that JSON has a primitive null type, with the single value
null; likewise with the QNull type for QObject; but for QAPI,
we just have the 'null' value without a null type. We may
eventually want to add more support in QAPI for null (most likely,
we'd use it via an alternate type that permits 'null' or an
object); but we'll create that usage when we need it.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-15-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-29 00:45:22 +03:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_optional(Visitor *v, const char *name, bool *present)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
|
|
|
QObject *qobj = qobject_input_get_object(qiv, name, false, NULL);
|
2011-07-19 23:50:33 +04:00
|
|
|
|
|
|
|
if (!qobj) {
|
|
|
|
*present = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*present = true;
|
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
static void qobject_input_free(Visitor *v)
|
qapi: Add new visit_free() function
Making each visitor provide its own (awkwardly-named) FOO_cleanup()
is unusual, when we can instead have a polymorphic visit_free()
interface. Over the next few patches, we can use the polymorphic
functions to eliminate the need for a FOO_get_visitor() function
for accessing specific visitor functionality, once everything can
be accessed directly through the Visitor* interfaces.
The dealloc visitor is the first one converted to completely use
the new entry point, since qapi_dealloc_visitor_cleanup() was the
only reason that qapi_dealloc_get_visitor() existed, and only
generated and testsuite code was even using it. With the new
visit_free() entry point in place, we no longer need to expose
the QapiDeallocVisitor subtype through qapi_dealloc_visitor_new(),
and can get by with less generated code, with diffs that look like:
| void qapi_free_ACPIOSTInfo(ACPIOSTInfo *obj)
| {
|- QapiDeallocVisitor *qdv;
| Visitor *v;
|
| if (!obj) {
| return;
| }
|
|- qdv = qapi_dealloc_visitor_new();
|- v = qapi_dealloc_get_visitor(qdv);
|+ v = qapi_dealloc_visitor_new();
| visit_type_ACPIOSTInfo(v, NULL, &obj, NULL);
|- qapi_dealloc_visitor_cleanup(qdv);
|+ visit_free(v);
|}
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-5-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 19:48:35 +03:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *qiv = to_qiv(v);
|
2016-07-07 18:53:18 +03:00
|
|
|
while (!QSLIST_EMPTY(&qiv->stack)) {
|
|
|
|
StackObject *tos = QSLIST_FIRST(&qiv->stack);
|
|
|
|
|
|
|
|
QSLIST_REMOVE_HEAD(&qiv->stack, node);
|
2016-09-30 17:45:27 +03:00
|
|
|
qobject_input_stack_object_free(tos);
|
2016-07-07 18:53:18 +03:00
|
|
|
}
|
qapi: Add new visit_free() function
Making each visitor provide its own (awkwardly-named) FOO_cleanup()
is unusual, when we can instead have a polymorphic visit_free()
interface. Over the next few patches, we can use the polymorphic
functions to eliminate the need for a FOO_get_visitor() function
for accessing specific visitor functionality, once everything can
be accessed directly through the Visitor* interfaces.
The dealloc visitor is the first one converted to completely use
the new entry point, since qapi_dealloc_visitor_cleanup() was the
only reason that qapi_dealloc_get_visitor() existed, and only
generated and testsuite code was even using it. With the new
visit_free() entry point in place, we no longer need to expose
the QapiDeallocVisitor subtype through qapi_dealloc_visitor_new(),
and can get by with less generated code, with diffs that look like:
| void qapi_free_ACPIOSTInfo(ACPIOSTInfo *obj)
| {
|- QapiDeallocVisitor *qdv;
| Visitor *v;
|
| if (!obj) {
| return;
| }
|
|- qdv = qapi_dealloc_visitor_new();
|- v = qapi_dealloc_get_visitor(qdv);
|+ v = qapi_dealloc_visitor_new();
| visit_type_ACPIOSTInfo(v, NULL, &obj, NULL);
|- qapi_dealloc_visitor_cleanup(qdv);
|+ visit_free(v);
|}
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-5-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 19:48:35 +03:00
|
|
|
|
qmp-input-visitor: Favor new visit_free() function
Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.
Generated code changes to qmp-marshal.c look like:
|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 19:48:38 +03:00
|
|
|
qobject_decref(qiv->root);
|
|
|
|
g_free(qiv);
|
qapi: Add new visit_free() function
Making each visitor provide its own (awkwardly-named) FOO_cleanup()
is unusual, when we can instead have a polymorphic visit_free()
interface. Over the next few patches, we can use the polymorphic
functions to eliminate the need for a FOO_get_visitor() function
for accessing specific visitor functionality, once everything can
be accessed directly through the Visitor* interfaces.
The dealloc visitor is the first one converted to completely use
the new entry point, since qapi_dealloc_visitor_cleanup() was the
only reason that qapi_dealloc_get_visitor() existed, and only
generated and testsuite code was even using it. With the new
visit_free() entry point in place, we no longer need to expose
the QapiDeallocVisitor subtype through qapi_dealloc_visitor_new(),
and can get by with less generated code, with diffs that look like:
| void qapi_free_ACPIOSTInfo(ACPIOSTInfo *obj)
| {
|- QapiDeallocVisitor *qdv;
| Visitor *v;
|
| if (!obj) {
| return;
| }
|
|- qdv = qapi_dealloc_visitor_new();
|- v = qapi_dealloc_get_visitor(qdv);
|+ v = qapi_dealloc_visitor_new();
| visit_type_ACPIOSTInfo(v, NULL, &obj, NULL);
|- qapi_dealloc_visitor_cleanup(qdv);
|+ visit_free(v);
|}
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-5-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 19:48:35 +03:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:45:27 +03:00
|
|
|
Visitor *qobject_input_visitor_new(QObject *obj, bool strict)
|
2011-07-19 23:50:33 +04:00
|
|
|
{
|
2016-09-30 17:45:27 +03:00
|
|
|
QObjectInputVisitor *v;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-09-30 12:59:46 +03:00
|
|
|
assert(obj);
|
2011-08-21 07:09:37 +04:00
|
|
|
v = g_malloc0(sizeof(*v));
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-04-29 00:45:09 +03:00
|
|
|
v->visitor.type = VISITOR_INPUT;
|
2016-09-30 17:45:27 +03:00
|
|
|
v->visitor.start_struct = qobject_input_start_struct;
|
|
|
|
v->visitor.check_struct = qobject_input_check_struct;
|
|
|
|
v->visitor.end_struct = qobject_input_pop;
|
|
|
|
v->visitor.start_list = qobject_input_start_list;
|
|
|
|
v->visitor.next_list = qobject_input_next_list;
|
|
|
|
v->visitor.end_list = qobject_input_pop;
|
|
|
|
v->visitor.start_alternate = qobject_input_start_alternate;
|
|
|
|
v->visitor.type_int64 = qobject_input_type_int64;
|
|
|
|
v->visitor.type_uint64 = qobject_input_type_uint64;
|
|
|
|
v->visitor.type_bool = qobject_input_type_bool;
|
|
|
|
v->visitor.type_str = qobject_input_type_str;
|
|
|
|
v->visitor.type_number = qobject_input_type_number;
|
|
|
|
v->visitor.type_any = qobject_input_type_any;
|
|
|
|
v->visitor.type_null = qobject_input_type_null;
|
|
|
|
v->visitor.optional = qobject_input_optional;
|
|
|
|
v->visitor.free = qobject_input_free;
|
2016-04-29 00:45:13 +03:00
|
|
|
v->strict = strict;
|
2011-07-19 23:50:33 +04:00
|
|
|
|
2016-04-29 00:45:18 +03:00
|
|
|
v->root = obj;
|
2012-03-22 15:51:09 +04:00
|
|
|
qobject_incref(obj);
|
2011-07-19 23:50:33 +04:00
|
|
|
|
qmp-input-visitor: Favor new visit_free() function
Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.
Generated code changes to qmp-marshal.c look like:
|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 19:48:38 +03:00
|
|
|
return &v->visitor;
|
2011-07-19 23:50:33 +04:00
|
|
|
}
|