Received: from eggs.gnu.org ([2001:4830:134:3::10]:60805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axVje-0007TZ-5B for qemu-devel@nongnu.org; Tue, 03 May 2016 04:31:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axVjS-0002Rp-8r for qemu-devel@nongnu.org; Tue, 03 May 2016 04:31:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axVjS-0002PQ-1G for qemu-devel@nongnu.org; Tue, 03 May 2016 04:31:02 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4E81C01AA57 for ; Tue, 3 May 2016 08:30:50 +0000 (UTC) From: Markus Armbruster References: <1461903820-3092-1-git-send-email-eblake@redhat.com> <1461903820-3092-11-git-send-email-eblake@redhat.com> <87r3dkk2v9.fsf@dusky.pond.sub.org> <572762DA.4050107@redhat.com> Date: Tue, 03 May 2016 10:30:48 +0200 In-Reply-To: <572762DA.4050107@redhat.com> (Eric Blake's message of "Mon, 2 May 2016 08:23:22 -0600") Message-ID: <87lh3ra6h3.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3 10/18] vmstate: Use new JSON output visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Amit Shah , famz@redhat.com, qemu-devel@nongnu.org, Juan Quintela Eric Blake writes: > On 05/02/2016 07:26 AM, Markus Armbruster wrote: >> Eric Blake writes: >> >>> Rather than using a QJSON object and converting the QString result >>> to a char *, we can use the new JSON output visitor and get directly >>> to a char *. >>> >>> The conversions are a bit tricky in place (in places, we have to >>> copy an integer to an int64_t temporary to get the right pointer for >>> visit_type_int(); and for several strings, we have to copy to a >>> temporary variable so we can take an address (&char[] is not the >>> same as &char*) and cast away const), but overall still fairly >>> mechanical. >>> >>> Suggested-by: Paolo Bonzini >>> Signed-off-by: Eric Blake >>> > >>> -static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, QJSON *vmdesc) >>> +static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, >>> + Visitor *vmdesc) >>> { >>> int64_t old_offset, size; >>> + const char *tmp; >>> >>> old_offset = qemu_ftell_fast(f); >>> se->ops->save_state(f, se->opaque); >>> size = qemu_ftell_fast(f) - old_offset; >>> >>> if (vmdesc) { >> >> Conditionals could be avoided: use a null visitor. Not sure it's worth >> it, though. > > We could just teach qapi-visit-core.c to be a no-op for v==NULL (thus > hiding the conditionals in the core code, but that then slows down the > common case for more conditionals on every caller. Maybe a null visitor > is reasonable, after all? I'd prefer a null visitor to messing up the core with conditionals. Again: not sure avoiding the conditionals here is worth a null visitor. If you want to find out, cook up a patch and we'll see. >>> + tmp = "data"; >>> + visit_type_str(vmdesc, "name", (char **)&tmp, &error_abort); >> >> The Visitor interface is the same for input and for output. Convenient >> when the code is direction-agnostic. Inconvenient when it's output: you >> have to pass the value by reference even though it's only read. In >> particular, literals need a temporary, and types have to be adjusted via >> cast or temporary more frequently than for by-value. >> >> If that bothers us, we can add by-value wrappers to the interface. >> >> Are there other output-only visitor uses? > > qom-get is output-only, just as qom-set is input-only. Maybe it's worth > an experiment to see how difficult it would be. > > >> Well, it doesn't exactly make this code prettier, but having a stupid >> wrapper just to hide the ugliness isn't so hot, either. > > And now you see why I posted two alternatives, to see which way we want > to go. Having convenient wrappers for output-only visits may swing the > vote. Having read your first alternative, my immediate reaction was "why don't you do X instead?", where X turned out to be your second alternative. I really don't like this feature-limited wrapper that is used in just one place. I also don't like its confusing git-log, courtesy of its unwisely chosen filename. But having read the second alternative, I understand why you're offering the first one: both are ugly. So which of the uglies do I prefer? The experiment could indeed swing my vote.