From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 1/5] qapi: Further enhance visitor virtual walk doc example
Date: Thu, 20 Jul 2017 11:05:48 +0200 [thread overview]
Message-ID: <87vamnmqab.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20170714190827.4083-2-eblake@redhat.com> (Eric Blake's message of "Fri, 14 Jul 2017 14:08:23 -0500")
Eric Blake <eblake@redhat.com> writes:
> Markus pointed out that the example given for virtual walks did
> not discuss how to do a virtual walk of an alternate type. It
> turns out that for output, we don't need to visit an alternate
> (just directly visit the type that we want); and for input,
> visit_start_alternate() is not currently wired up for alternates
> (it requires a QAPI type, rather than permitting NULL for a
> virtual walk). Also, the example was never updated in commit
> 3b098d5 about where visit_complete() would fit in. Improve the
> description and example to give more details along these lines.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
This clashes with some unfinished work I have on alternates. If I can
finish it quickly, we can compare and decide whether we still need this.
> ---
> include/qapi/visitor.h | 41 ++++++++++++++++++++++++++++-------------
> 1 file changed, 28 insertions(+), 13 deletions(-)
>
> diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
> index 74768aa..b0a048f 100644
> --- a/include/qapi/visitor.h
> +++ b/include/qapi/visitor.h
> @@ -183,19 +183,25 @@
> *
> * It is also possible to use the visitors to do a virtual walk, where
> * no actual QAPI struct is present. In this situation, decisions
> - * about what needs to be walked are made by the calling code, and
> - * structured visits are split between pairs of start and end methods
> - * (where the end method must be called if the start function
> - * succeeded, even if an intermediate visit encounters an error).
> - * Thus, a virtual walk corresponding to '{ "list": [1, 2] }' looks
> - * like:
> + * about what needs to be walked are made by the calling code (that
> + * is, there is no use for QAPI alternate types in a virtual walk,
> + * because the code can just directly visit the appropriate type
> + * within the alternate), and structured visits are split between
The parenthesis makes a long sentence even longer.
> + * pairs of start and end methods (where the end method must be called
> + * if the start function succeeded, even if an intermediate visit
> + * encounters an error). Thus, a virtual output walk of an object
> + * containing a list of alternates between an integer or nested
> + * object, corresponding to '{ "list": [1, { "value": "2" } ] }',
> + * would look like:
Covering alternates as well makes the example rather complicated. In
the unfinished work I mentioned above, I explain them separately.
> *
> * <example>
> * Visitor *v;
> * Error *err = NULL;
> - * int value;
> + * int i = 1;
> + * const char *s = "2";
> + * FOO output;
> *
> - * v = FOO_visitor_new(...);
> + * v = FOO_visitor_new(..., &output);
> * visit_start_struct(v, NULL, NULL, 0, &err);
> * if (err) {
> * goto out;
> @@ -204,16 +210,21 @@
> * if (err) {
> * goto outobj;
> * }
> - * value = 1;
> - * visit_type_int(v, NULL, &value, &err);
> + * visit_type_int(v, NULL, &i, &err);
> * if (err) {
> * goto outlist;
> * }
> - * value = 2;
> - * visit_type_int(v, NULL, &value, &err);
> + * visit_type_start(v, NULL, NULL, 0, &err);
> * if (err) {
> - * goto outlist;
> + * goto outnest;
> + * }
> + * visit_type_str(v, "value", (char **)&s, &err);
> + * if (err) {
> + * goto outnest;
> * }
> + * visit_check_struct(v, &err);
> + * outnest:
> + * visit_end_struct(v, NULL);
> * outlist:
> * visit_end_list(v, NULL);
> * if (!err) {
> @@ -221,6 +232,10 @@
> * }
> * outobj:
> * visit_end_struct(v, NULL);
> + * if (!err) {
> + * visit_complete(v, &output);
> + * ...use output...
> + * }
> * out:
> * error_propagate(errp, err);
> * visit_free(v);
next prev parent reply other threads:[~2017-07-20 9:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-14 19:08 [Qemu-devel] [PATCH 0/5] random qapi cleanups Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 1/5] qapi: Further enhance visitor virtual walk doc example Eric Blake
2017-07-20 9:05 ` Markus Armbruster [this message]
2017-07-20 20:21 ` Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 2/5] tests: Enhance qobject output to cover partial visit Eric Blake
2017-07-20 9:52 ` Markus Armbruster
2017-07-20 20:27 ` Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 3/5] qapi: Visitor documentation tweak Eric Blake
2017-07-20 10:00 ` Markus Armbruster
2017-07-20 20:28 ` Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 4/5] qtest: Avoid passing raw strings through hmp() Eric Blake
2017-07-20 10:03 ` Markus Armbruster
2017-07-14 19:08 ` [Qemu-devel] [PATCH 5/5] qtest: Document calling conventions Eric Blake
2017-07-20 10:10 ` Markus Armbruster
2017-07-20 20:37 ` Eric Blake
2017-07-20 20:53 ` Eric Blake
2017-07-21 6:42 ` Markus Armbruster
2017-07-21 12:08 ` Eric Blake
2017-07-21 14:13 ` Markus Armbruster
2017-07-18 16:09 ` [Qemu-devel] [PATCH 0/5] random qapi cleanups Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vamnmqab.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.