qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v1 4/6] qapi: add a text output visitor for pretty printing types
Date: Tue, 7 Jun 2016 10:40:36 -0600	[thread overview]
Message-ID: <5756F904.1090804@redhat.com> (raw)
In-Reply-To: <20160607162042.GU20196@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4439 bytes --]

On 06/07/2016 10:20 AM, Daniel P. Berrange wrote:
> On Tue, Jun 07, 2016 at 10:09:48AM -0600, Eric Blake wrote:
>> On 06/07/2016 04:11 AM, Daniel P. Berrange wrote:
>>> The current approach for pretty-printing QAPI types is to
>>> convert them to JSON using the QMP output visitor and then
>>> pretty-print the JSON document. This has an unfixable problem
>>> that structs get their keys printed out in random order, since
>>> JSON dicts do not contain any key ordering information.
>>>
>>> To address this, introduce a text output visitor that can
>>> directly pretty print a QAPI type into a string.
>>>
>>> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
>>> ---
>>>  include/qapi/text-output-visitor.h |  73 ++++++++++++
>>>  include/qapi/visitor-impl.h        |   5 +-
>>>  include/qapi/visitor.h             |   5 +-
>>>  qapi/Makefile.objs                 |   1 +
>>>  qapi/opts-visitor.c                |   5 +-
>>>  qapi/qapi-dealloc-visitor.c        |   4 +-
>>>  qapi/qapi-visit-core.c             |   9 +-
>>>  qapi/qmp-input-visitor.c           |   5 +-
>>>  qapi/qmp-output-visitor.c          |   4 +-
>>>  qapi/string-input-visitor.c        |   5 +-
>>>  qapi/string-output-visitor.c       |   5 +-
>>
>> Why can't we enhance the existing string-output-visitor to handle structs?
> 
> string-output-visitor seems to be doing something very
> different from this. In particular it only ever seems
> to output the values, never the field names. So if we
> did enhance string-output-visitor, we'd basically have
> to make all of its code conditional to output in one
> style or the other style, at which point I didn't think
> it was really buying us anything vs a new visitor.

That is, it was always doing a top-level visit of a scalar or array of
scalars, and nothing else. It may still be something that can be merged.
Maybe I should take a rough shot at it, since I have ideas on how to use
a common handler for name/list index (and do nothing at the top level),
then the rest of each callback is independent from what name prefix, if
any, was output.  On the other hand, I guess the way intList is handled
(compacting it into a single list, instead of each element of the list),
may indeed be a reason to keep it as two visitors.


>> Why do we need to list the element size twice?  Or is one the size of
>> the GenericList object wrapping the element?  I'm still not convinced we
>> need the size of an element at this point in the visit.
> 
> 'size_t element' isn't the size of an element, it is the really
> the list index - eg 1, 2, 3, 4, etc. I didn't call it 'index'
> because that causes a clashing symbol, but I guess I could
> have used 'idx' instead.

The perils of replying to email text in the order I read it. I think I
figured that out later on.  And it is indeed annoying that older gcc
warns about conflicts with shadowing 'index'.


>> Don't we already have a util/ function for pretty-printing a size?  In
>> fact, doesn't the existing StringOutputVisitor have code for doing it?
> 
> Guess where this code was copied from - StringOutputVisitor :-) If this
> idea is amenable in general, I'll go back and cleanup this patch be better.

A common helper may be nice, if we have two visitors both wanting to use it.


>>
>> Oooooh, I see.  You're using 'element' as the index within the array,
>> not as a size.  I think naming it 'idx' (or 'index', if that doesn't
>> cause older compilers to barf for shadowing a function name), would make
>> more sense, but it definitely highlights the need for documentation.
>> Also, why does element 0 have to be special-cased?
> 
> The pattern of calling means 'next_list' is invoked /after/
> each element is visited, but we want to print out the header
> /before/ each element. So I had to special case 0, and also
> use the 'if(ret)' check to skip printing a header after the
> last element.

But if we have a common helper function (see json_output_name() in my
JSON series), then that helper will be called before every element, and
can easily tell whether we are in struct context (name is non-null,
print it) or list context (name is NULL, print our current counter then
increment it), rather than having to special case the code around the
elements.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2016-06-07 16:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-07 10:11 [Qemu-devel] [PATCH v1 0/6] Report format specific info for LUKS block driver Daniel P. Berrange
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 1/6] crypto: add support for querying parameters for block encryption Daniel P. Berrange
2016-06-07 14:17   ` Eric Blake
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 2/6] block: export LUKS specific data to qemu-img info Daniel P. Berrange
2016-06-07 15:36   ` Eric Blake
2016-06-07 15:51     ` Daniel P. Berrange
2016-06-07 16:11       ` Eric Blake
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 3/6] qapi: assert that visitor impls have required callbacks Daniel P. Berrange
2016-06-07 15:40   ` Eric Blake
2016-06-07 15:46     ` Daniel P. Berrange
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 4/6] qapi: add a text output visitor for pretty printing types Daniel P. Berrange
2016-06-07 16:09   ` Eric Blake
2016-06-07 16:20     ` Daniel P. Berrange
2016-06-07 16:40       ` Eric Blake [this message]
2016-06-07 16:45         ` Daniel P. Berrange
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 5/6] qapi: generate a qapi_stringify_TYPENAME method for all types Daniel P. Berrange
2016-06-07 16:23   ` Eric Blake
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 6/6] block: convert to use qapi_stringify_ImageInfoSpecific Daniel P. Berrange
2016-06-07 16:59   ` Eric Blake
2016-06-07 12:04 ` [Qemu-devel] [PATCH v1 0/6] Report format specific info for LUKS block driver Eric Blake
2016-06-07 14:35   ` Daniel P. Berrange
2016-06-14 13:56 ` Max Reitz
2016-06-14 14:05   ` Daniel P. Berrange

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=5756F904.1090804@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).