From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avot5-0003qS-PB for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:34:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avot2-0000yL-I8 for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:33:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avot2-0000yC-Cw for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:33:56 -0400 From: Markus Armbruster References: <1460131992-32278-1-git-send-email-eblake@redhat.com> <1460131992-32278-9-git-send-email-eblake@redhat.com> <87inzk43ml.fsf@dusky.pond.sub.org> <571FE295.30102@redhat.com> Date: Thu, 28 Apr 2016 18:33:53 +0200 In-Reply-To: <571FE295.30102@redhat.com> (Eric Blake's message of "Tue, 26 Apr 2016 15:50:13 -0600") Message-ID: <87oa8thevi.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v14 08/19] qapi: Document visitor interfaces, add assertions 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 04/14/2016 09:22 AM, Markus Armbruster wrote: >> Eric Blake writes: [...] >>> +++ b/qapi/qapi-visit-core.c >>> @@ -23,6 +23,10 @@ >>> void visit_start_struct(Visitor *v, const char *name, void **obj, >>> size_t size, Error **errp) >>> { >>> + if (obj) { >>> + assert(size); >> >> Yes, because the generator puts a dummy member into empty structs. >> >>> + assert(v->type != VISITOR_OUTPUT || *obj); >> >> Can you point me to the spot in the contract that requires this? > > Translation of the assert: If you are using an output visitor, and not > doing a virtual walk (obj is non-NULL), then the object must be > completely built (*obj is non-NULL). For an input visitor, *obj is NULL > on entry (we're allocating it, after all); Actually, it may be anything, including uninitialized, and it'll be overwritten. > for the dealloc visitor, *obj > may or may not be NULL (since we handle cleanup of partial allocation). Got the assertion now, thanks! > In the text, "output visitors (QMP and string) take a completed QAPI > graph", but maybe I can further clarify that a completed object means > that *obj is non-NULL and all 'has_member' and 'member' members are > complete. [...]