Received: from eggs.gnu.org ([2001:4830:134:3::10]:49696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWTlB-0004gN-5M for qemu-devel@nongnu.org; Thu, 18 Feb 2016 13:57:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWTl7-0006rA-Uu for qemu-devel@nongnu.org; Thu, 18 Feb 2016 13:57:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWTl7-0006r5-PF for qemu-devel@nongnu.org; Thu, 18 Feb 2016 13:57:01 -0500 From: Markus Armbruster References: <1455778109-6278-1-git-send-email-eblake@redhat.com> <1455778109-6278-13-git-send-email-eblake@redhat.com> <874md69dfi.fsf@blackfin.pond.sub.org> <56C5F7D6.4060801@redhat.com> Date: Thu, 18 Feb 2016 19:56:58 +0100 In-Reply-To: <56C5F7D6.4060801@redhat.com> (Eric Blake's message of "Thu, 18 Feb 2016 09:56:54 -0700") Message-ID: <87fuwp26f9.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v11 12/15] qapi: Don't box struct branch of alternate List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, Michael Roth Eric Blake writes: > On 02/18/2016 09:43 AM, Markus Armbruster wrote: >> Eric Blake writes: >> >>> There's no reason to do two malloc's for an alternate type visiting >>> a QAPI struct; let's just inline the struct directly as the C union >>> branch of the struct. >>> >>> >>> meanwhile, in qapi-visit.h, we trade the previous visit_type_FOO(obj) >> >> Meanwhile >> >>> (which allocates a pointer, handles a layer of {} from the JSON stream, >>> and visits the fields) > > Maybe: > > (which first calls visit_start_struct(v, name, obj, size, &err) to > allocate a pointer and handle a layer of {} from the JSON stream, then > visits the fields) > >>> with an inline call to visit_type_FOO(NULL) (to >>> consume the {} without allocation) and a direct visit of the fields: >> >> I don't see a call to visit_type_FOO(NULL). > > Whoops, wrong function name. I meant: > > visit_start_struct(v, name, NULL, 0, &err). > ^^^^ > Especially useful if you take my earlier text suggestion to point out > the difference in the visit_start_struct() calls as being the > intentional so that we continue to consume {} but now opt out of a > second allocation. Better, but the sentence is long enough to confuse even a German. What about: The corresponding spot in qapi-visit.c calls visit_type_FOO(), which first calls visit_start_struct() to allocate or deallocate the member and handle a layer of {} from the JSON stream, then visits the members. To peel off the indirection and the memory management that comes with it, we inline this call, then suppress allocation / deallocation by passing NULL to visit_start_struct(), and adjust the member visit: >> >> Suggest not to abbreviate argument lists, it's mildly confusing. > > Sure. Are we still at a point that you could touch up the commit message > without a patch respin? Looks like it so far. >> >> Patch looks good. >>