Received: from eggs.gnu.org ([2001:4830:134:3::10]:48387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abB03-0001Tb-46 for qemu-devel@nongnu.org; Wed, 02 Mar 2016 12:55:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abAzy-0000Ob-4H for qemu-devel@nongnu.org; Wed, 02 Mar 2016 12:55:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41014) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abAzx-0000OQ-So for qemu-devel@nongnu.org; Wed, 02 Mar 2016 12:55:46 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 66B78C00F1E7 for ; Wed, 2 Mar 2016 17:55:45 +0000 (UTC) From: Markus Armbruster References: <1456443528-13901-1-git-send-email-eblake@redhat.com> <1456443528-13901-5-git-send-email-eblake@redhat.com> Date: Wed, 02 Mar 2016 18:55:43 +0100 In-Reply-To: <1456443528-13901-5-git-send-email-eblake@redhat.com> (Eric Blake's message of "Thu, 25 Feb 2016 16:38:33 -0700") Message-ID: <87fuw8hihs.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 04/19] chardev: Shorten references into ChardevBackend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Paolo Bonzini , qemu-devel@nongnu.org Eric Blake writes: > An upcoming patch will alter how simple unions, like ChardevBackend, > are laid out, which will impact all lines of the form 'backend->u.XXX'. > To minimize the impact of that patch, use a temporary variable to > reduce the number of lines needing modification when an internal > reference within ChardevBackend changes layout. > > Signed-off-by: Eric Blake > Reviewed-By: Daniel P. Berrange > > --- > v2: add R-b > --- > qemu-char.c | 122 ++++++++++++++++++++++++++++++++---------------------------- > 1 file changed, 66 insertions(+), 56 deletions(-) > > diff --git a/qemu-char.c b/qemu-char.c > index fc8ffda..5ea1d34 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -724,7 +724,7 @@ static CharDriverState *qemu_chr_open_mux(const char *id, > ChardevMux *mux = backend->u.mux; > CharDriverState *chr, *drv; > MuxDriver *d; > - ChardevCommon *common = qapi_ChardevMux_base(backend->u.mux); > + ChardevCommon *common = qapi_ChardevMux_base(mux); > > drv = qemu_chr_find(mux->chardev); > if (drv == NULL) { The commit message sounds like you *add* a temporary variable to reduce churn. You're using an existing one here. > @@ -1043,7 +1043,7 @@ static CharDriverState *qemu_chr_open_pipe(const char *id, > char *filename_in; > char *filename_out; > const char *filename = opts->device; > - ChardevCommon *common = qapi_ChardevHostdev_base(backend->u.pipe); > + ChardevCommon *common = qapi_ChardevHostdev_base(opts); > > > filename_in = g_strdup_printf("%s.in", filename); > @@ -1123,7 +1123,7 @@ static CharDriverState *qemu_chr_open_stdio(const char *id, > ChardevStdio *opts = backend->u.stdio; > CharDriverState *chr; > struct sigaction act; > - ChardevCommon *common = qapi_ChardevStdio_base(backend->u.stdio); > + ChardevCommon *common = qapi_ChardevStdio_base(opts); > > if (is_daemonized()) { > error_setg(errp, "cannot use stdio with -daemonize"); > @@ -2141,7 +2141,7 @@ static CharDriverState *qemu_chr_open_pipe(const char *id, > const char *filename = opts->device; > CharDriverState *chr; > WinCharState *s; > - ChardevCommon *common = qapi_ChardevHostdev_base(backend->u.pipe); > + ChardevCommon *common = qapi_ChardevHostdev_base(opts); > > chr = qemu_chr_alloc(common, errp); > if (!chr) { > @@ -3216,7 +3216,7 @@ static CharDriverState *qemu_chr_open_ringbuf(const char *id, > Error **errp) > { > ChardevRingbuf *opts = backend->u.ringbuf; > - ChardevCommon *common = qapi_ChardevRingbuf_base(backend->u.ringbuf); > + ChardevCommon *common = qapi_ChardevRingbuf_base(opts); > CharDriverState *chr; > RingBufCharDriver *d; > > @@ -3506,26 +3506,29 @@ static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend, > Error **errp) > { > const char *path = qemu_opt_get(opts, "path"); > + ChardevFile *file; Ah, you do add a temporary in some places. > > if (path == NULL) { > error_setg(errp, "chardev: file: no filename given"); > return; > } > - backend->u.file = g_new0(ChardevFile, 1); > - qemu_chr_parse_common(opts, qapi_ChardevFile_base(backend->u.file)); > - backend->u.file->out = g_strdup(path); > + file = backend->u.file = g_new0(ChardevFile, 1); > + qemu_chr_parse_common(opts, qapi_ChardevFile_base(file)); > + file->out = g_strdup(path); > > - backend->u.file->has_append = true; > - backend->u.file->append = qemu_opt_get_bool(opts, "append", false); > + file->has_append = true; > + file->append = qemu_opt_get_bool(opts, "append", false); > } Whether you touch every line now or later is a wash as far as churn is concerned. I'd be willing to accept an argument that this change is simpler than the one it avoids, or that it makes the code more consistent, or it makes the code easier to read. Preferably in the commit message. [More of the same snipped...]