Received: from eggs.gnu.org ([2001:4830:134:3::10]:49813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMBO0-00011r-Pg for qemu-devel@nongnu.org; Thu, 21 Jan 2016 04:18:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMBNz-0006iH-8h for qemu-devel@nongnu.org; Thu, 21 Jan 2016 04:18:36 -0500 From: Markus Armbruster References: <1453219845-30939-1-git-send-email-eblake@redhat.com> <1453219845-30939-16-git-send-email-eblake@redhat.com> <874me8m6h0.fsf@blackfin.pond.sub.org> <569FF411.3080005@redhat.com> Date: Thu, 21 Jan 2016 10:18:25 +0100 In-Reply-To: <569FF411.3080005@redhat.com> (Eric Blake's message of "Wed, 20 Jan 2016 13:54:41 -0700") Message-ID: <87twm7mgta.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 15/37] qom: Swap 'name' next to visitor in ObjectPropertyAccessor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , Paolo Bonzini , Eduardo Habkost , "open list:nvme" , "Michael S. Tsirkin" , Jiri Slaby , Jason Wang , qemu-devel@nongnu.org, Alexander Graf , Keith Busch , Gonglei , "open list:sPAPR" , Gerd Hoffmann , Igor Mammedov , marcandre.lureau@redhat.com, David Gibson , John Snow , Andreas =?utf-8?Q?F=C3=A4rber?= , Richard Henderson Eric Blake writes: > On 01/20/2016 11:49 AM, Markus Armbruster wrote: >> Eric Blake writes: >>=20 >>> Similar to the previous patch, it's nice to have all functions >>> in the tree that involve a visitor and a name for conversion to >>> or from QAPI to consistently stick the 'name' parameter next >>> to the Visitor parameter. >>> >>> Done by manually changing include/qom/object.h and qom/object.c, >>> then running this Coccinelle script and touching up the fallout >>> (Coccinelle insisted on adding some trailing whitespace). >>> >>> @ rule1 @ >>> identifier fn; >>> type Object, Visitor, Error; >>> identifier obj, v, opaque, name, errp; >>> @@ >>> void fn >>> - (Object *obj, Visitor *v, void *opaque, const char *name, >>> + (Object *obj, Visitor *v, const char *name, void *opaque, >>> Error **errp) { ... } >>=20 >> I think we want to match void functions with exactly these parameter >> types. The parameter names don't matter. > > The parameter names shouldn't matter; the 'identifier obj' should have > been enough to make 'obj' a metavariable matching any actual parameter na= me. > >>=20 >> However, the actual match is looser! For instance, it also matches >>=20 >> void foo(int *pi, unsigned *pu, void *vp, const char *cp, double **d= pp) >> { >> } > > Uggh. My intent was to match exactly 'Object *' and 'Visitor *' as the > first two types, where 'int *' and 'unsigned *' are NOT matches. But I > don't know Coccinelle well enough to make that blatantly obvious (is my > declaration of 'type Object' not correct?). 'type Object' makes 'Object' a metavariable matching any C type. >> This could mess up unrelated function. I could double-check it doesn't, >> but I'd rather have a narrower match instead. Can't give one offhand, >> though. Ideas? > > Is 'typedef' better than 'type' for constraining the type of the first > two arguments? Matches any C typedef name. Less wrong, but still wrong :) > Or does Coccinelle do literal matches on anything you > don't pre-declare, as in: Yes, but... > @ rule1 @ > identifier fn; > identifier obj, v, opaque, name, errp; > @@ > void fn > - (Object *obj, Visitor *v, void *opaque, const char *name, > + (Object *obj, Visitor *v, const char *name, void *opaque, > Error **errp) { ... } ... when I try that, spatch throws a parse error. > Fortunately, a manual inspection of the results (which I had to do > anyways due to spacing issues) didn't spot any incorrect swaps. > > At this point, I don't know that re-writing Coccinelle will be worth the > hassle (nothing else needs to be rewritten). I'd normally take up the challenge to wrestle Coccinelle, but I think our time is better spent elsewhere right now. Let's amend the commit message instead: describe the semantic patch's shortcomings, and your manual checking: This semantic patch is actually far too lose: it matches *any* type, not just Object, Visitor, Error. However, I can't figure out how to make Coccinelle match Object, Visitor, Error exactly. Simply deleting the 'type Object, Visitor, Error;' line results in a parse error. I reviewed the resulting patch carefully to verify there are no unwanted matches. >>> @@ >>> identifier rule1.fn; >>> expression obj, v, opaque, name, errp; >>> @@ >>> fn(obj, v, >>> - opaque, name, >>> + name, opaque, >>> errp) >>=20 >> The rule1.fn restricts the match to functions changed by the previous >> rule. Good. >>=20 >>> >>> Signed-off-by: Eric Blake >>> Reviewed-by: Marc-Andr=C3=A9 Lureau >>=20