All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
	"Alexander Graf" <agraf@suse.de>,
	famz@redhat.com,
	"open list:Block layer core" <qemu-block@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Michael Roth" <mdroth@linux.vnet.ibm.com>,
	"open list:sPAPR" <qemu-ppc@nongnu.org>,
	"Amit Shah" <amit.shah@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [PATCH v3 18/18] qapi: Add parameter to visit_end_*
Date: Mon, 2 May 2016 13:31:36 -0600	[thread overview]
Message-ID: <5727AB18.2010809@redhat.com> (raw)
In-Reply-To: <87y47se2yy.fsf@dusky.pond.sub.org>

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

On 05/02/2016 12:20 PM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
> 
>> 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.
>>
>> The clone visitor also gets a minor simplification of not having
>> to track quite as much depth.
> 
> Do this before adding the clone visitor, to reduce churn?

I could. I first thought of it after, and kept it there as a
justification for keeping it (multiple visitors benefit), but even if
rebased earlier, the commit message can still mention that it will make
the clone visitor easier.

>> @@ -59,7 +59,7 @@ struct Visitor
>>      GenericList *(*next_list)(Visitor *v, GenericList *tail, size_t size);
>>
>>      /* Must be set */
>> -    void (*end_list)(Visitor *v);
>> +    void (*end_list)(Visitor *v, void **list);
> 
> Sure you want void ** and not GenericList **?

Yes. There are only two callers: dtc code passes NULL (where the type
doesn't matter), and generated visit_type_FOOList() has to already cast
to GenericList() during visit_start_list(); accepting void** here
instead of GenericList** removes the need for a second instance of that
cast.

> 
>>
>>      /* Must be set by input and dealloc visitors to visit alternates;
>>       * optional for output visitors. */
>> @@ -68,7 +68,7 @@ struct Visitor
>>                              bool promote_int, Error **errp);
>>
>>      /* Optional, needed for dealloc visitor */
>> -    void (*end_alternate)(Visitor *v);
>> +    void (*end_alternate)(Visitor *v, void **obj);
> 
> Sure you want void ** and not GenericAlternate **?

Only one caller: generated code. Same story that we already have to cast
during visit_start_alternate(), so using void** here avoids the need for
a second cast.

Oh, and the clone visitor was easier to write with a single function
that takes void** for all three visit_end() implementations (whereas I'd
have to write three functions identical except for signature otherwise).

>> +++ b/qapi/qapi-clone-visitor.c
>> @@ -29,11 +29,8 @@ static void qapi_clone_start_struct(Visitor *v, const char *name, void **obj,
>>      QapiCloneVisitor *qcv = to_qcv(v);
>>
>>      if (!obj) {
>> -        /* Nothing to allocate on the virtual walk during an
>> -         * alternate, but we still have to push depth.
>> -         * FIXME: passing obj to visit_end_struct would make this easier */
>> +        /* Nothing to allocate on the virtual walk */
>>          assert(qcv->depth);
>> -        qcv->depth++;
>>          return;
>>      }
>>
> 
> Why can we elide qcv->depth++?  Do the assert(qcv->qdepth) still hold?

Yes, the assertion still holds: we can only reach this code underneath
visit_start_alternate(), ...

> 
>> @@ -41,11 +38,13 @@ static void qapi_clone_start_struct(Visitor *v, const char *name, void **obj,
>>      qcv->depth++;
>>  }
>>
>> -static void qapi_clone_end(Visitor *v)
>> +static void qapi_clone_end(Visitor *v, void **obj)
>>  {
>>      QapiCloneVisitor *qcv = to_qcv(v);
>>      assert(qcv->depth);
>> -    qcv->depth--;
>> +    if (obj) {
>> +        qcv->depth--;
>> +    }

...and this is the matching elision of the depth manipulations.

>> +++ b/qapi/qmp-input-visitor.c
>> @@ -145,7 +145,7 @@ static void qmp_input_check_struct(Visitor *v, Error **errp)
>>      }
>>  }
>>
>> -static void qmp_input_pop(Visitor *v)
>> +static void qmp_input_pop(Visitor *v, void **obj)
>>  {
>>      QmpInputVisitor *qiv = to_qiv(v);
>>      StackObject *tos = &qiv->stack[qiv->nb_stack - 1];
> 
> You could assert @obj matches tos->obj.  Same for the other visitors
> that still need a stack.

And brings me back to my question of whether qapi-visit-core.c should
maintain its own stack for asserting these types of sanity checks for
ALL callers, even when the visitor itself doesn't need a stack.

-- 
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-05-02 19:32 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29  4:23 [Qemu-devel] [PATCH v3 00/18] Add qapi-to-JSON and clone visitors Eric Blake
2016-04-29  4:23 ` [PATCH v3 01/18] qapi: Rename (one) qjson.h to qobject-json.h Eric Blake
2016-04-29  4:23   ` [Qemu-devel] " Eric Blake
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 02/18] qapi: Improve use of qmp/types.h Eric Blake
2016-04-29 11:46   ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 03/18] qapi: Factor out JSON string escaping Eric Blake
2016-04-29 12:09   ` Markus Armbruster
2016-04-29 17:57     ` Eric Blake
2016-05-03  7:36       ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 04/18] qapi: Factor out JSON number formatting Eric Blake
2016-04-29 13:22   ` Markus Armbruster
2016-04-29 13:43     ` Eric Blake
2016-05-03  8:02       ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 05/18] qapi: Use qstring_append_chr() where appropriate Eric Blake
2016-04-29 13:25   ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 06/18] qapi: Add qstring_append_format() Eric Blake
2016-04-29 13:40   ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 07/18] qapi: Add json output visitor Eric Blake
2016-05-02  9:15   ` Markus Armbruster
2016-05-02 15:11     ` Eric Blake
2016-05-03  8:22       ` Markus Armbruster
2016-05-04 15:45         ` Markus Armbruster
2016-05-06  4:16           ` Eric Blake
2016-05-06 12:31             ` Markus Armbruster
2016-05-06 14:08               ` Eric Blake
2016-05-10  4:22                 ` Eric Blake
2016-05-18 15:16     ` Eric Blake
2016-05-18 15:24       ` Eric Blake
2016-05-02 15:00   ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 08/18] qjson: Simplify by using json-output-visitor Eric Blake
2016-05-02 12:45   ` Markus Armbruster
2016-05-02 12:49     ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 09/18] Revert "qjson: Simplify by using json-output-visitor" Eric Blake
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 10/18] vmstate: Use new JSON output visitor Eric Blake
2016-05-02 13:26   ` Markus Armbruster
2016-05-02 14:23     ` Eric Blake
2016-05-03  8:30       ` Markus Armbruster
2016-05-03  9:44   ` Dr. David Alan Gilbert
2016-05-03 12:26     ` Markus Armbruster
2016-05-03 12:34       ` Eric Blake
2016-05-03 13:27         ` Dr. David Alan Gilbert
2016-05-04  8:39           ` Markus Armbruster
2016-05-04  8:54             ` Dr. David Alan Gilbert
2016-05-24  7:15               ` Paolo Bonzini
2016-05-03 13:23       ` Dr. David Alan Gilbert
2016-05-04  9:11         ` Markus Armbruster
2016-05-04  9:22           ` Dr. David Alan Gilbert
2016-05-04 11:37             ` Markus Armbruster
2016-05-04 11:56               ` Dr. David Alan Gilbert
2016-05-04 13:00                 ` Markus Armbruster
2016-05-04 13:19                   ` Dr. David Alan Gilbert
2016-05-04 14:10                     ` Markus Armbruster
2016-05-04 14:53                       ` Dr. David Alan Gilbert
2016-05-04 15:17                         ` Eric Blake
2016-05-04 15:42                         ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 11/18] qjson: Remove unused file Eric Blake
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 12/18] qapi: Add qobject_to_json_pretty_prefix() Eric Blake
2016-05-02 13:56   ` Markus Armbruster
2016-05-02 15:14     ` Eric Blake
2016-05-03  8:32       ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 13/18] qapi: Support pretty printing in JSON output visitor Eric Blake
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 14/18] qemu-img: Use new JSON output formatter Eric Blake
2016-05-02 14:04   ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 15/18] qapi: Add new clone visitor Eric Blake
2016-05-02 17:54   ` Markus Armbruster
2016-05-02 19:25     ` Eric Blake
2016-05-03 11:36       ` Markus Armbruster
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 16/18] sockets: Use new QAPI cloning Eric Blake
2016-04-29  8:30   ` Daniel P. Berrange
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 17/18] replay: " Eric Blake
2016-04-29  4:23 ` [Qemu-devel] [PATCH v3 18/18] qapi: Add parameter to visit_end_* Eric Blake
2016-05-02 18:20   ` Markus Armbruster
2016-05-02 19:31     ` Eric Blake [this message]
2016-05-03 11:53       ` Markus Armbruster
2016-05-03 12:41         ` Eric Blake
2016-05-09  8:50 ` [Qemu-devel] [PATCH v3 00/18] Add qapi-to-JSON and clone visitors Paolo Bonzini
2016-05-09  9:29   ` Paolo Bonzini
2016-05-09 14:52     ` Eric Blake

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=5727AB18.2010809@redhat.com \
    --to=eblake@redhat.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=amit.shah@redhat.com \
    --cc=armbru@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=quintela@redhat.com \
    /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.