Received: from eggs.gnu.org ([2001:4830:134:3::10]:59112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLpci-00054Q-Sd for qemu-devel@nongnu.org; Wed, 20 Jan 2016 05:04:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLpcf-0006Yf-MF for qemu-devel@nongnu.org; Wed, 20 Jan 2016 05:04:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42495) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLpcf-0006YF-HR for qemu-devel@nongnu.org; Wed, 20 Jan 2016 05:04:17 -0500 From: Markus Armbruster References: <1453219845-30939-1-git-send-email-eblake@redhat.com> <1453219845-30939-3-git-send-email-eblake@redhat.com> Date: Wed, 20 Jan 2016 11:04:14 +0100 In-Reply-To: <1453219845-30939-3-git-send-email-eblake@redhat.com> (Eric Blake's message of "Tue, 19 Jan 2016 09:10:10 -0700") Message-ID: <87egdczhwh.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v9 02/37] qapi: Avoid use of misnamed DO_UPCAST() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: marcandre.lureau@redhat.com, qemu-devel@nongnu.org, Michael Roth Eric Blake writes: > The macro DO_UPCAST() is incorrectly named: it converts from a > parent class to a derived class (which is a downcast). Better, > and more consistent with some of the other qapi visitors, is > to use the container_of() macro through a to_FOO() helper. > > Our current definition of container_of() is weaker than > DO_UPCAST(), in that it does not require the derived class to > have Visitor as its first member, but this does not hurt our > usage patterns in qapi visitors. > > Signed-off-by: Eric Blake > Reviewed-by: Marc-Andr=C3=A9 Lureau > > --- > v9: no change > v8: no change > v7: new patch > --- > qapi/opts-visitor.c | 28 +++++++++++++++++----------- > qapi/string-input-visitor.c | 23 ++++++++++++++--------- > qapi/string-output-visitor.c | 21 +++++++++++++-------- > 3 files changed, 44 insertions(+), 28 deletions(-) > > diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c > index ef5fb8b..dd4094c 100644 > --- a/qapi/opts-visitor.c > +++ b/qapi/opts-visitor.c > @@ -89,6 +89,12 @@ struct OptsVisitor > }; > > > +static OptsVisitor *to_ov(Visitor *v) > +{ > + return container_of(v, OptsVisitor, visitor); > +} > + > + The name to_ov() is rather laconic even for my taste. Tolerable, since it's static. > static void > destroy_list(gpointer list) > { > @@ -121,7 +127,7 @@ static void > opts_start_struct(Visitor *v, void **obj, const char *kind, > const char *name, size_t size, Error **errp) > { > - OptsVisitor *ov =3D DO_UPCAST(OptsVisitor, visitor, v); > + OptsVisitor *ov =3D to_ov(v); > const QemuOpt *opt; > > if (obj) { Much clearer! [...] Patch gets rid of all DO_UPCAST() in qapi/. PATCH 33 brings one back; it should use to_ov() instead.