From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzEXN-0002F0-Jz for qemu-devel@nongnu.org; Tue, 25 Oct 2016 23:05:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzEXI-0005gP-Li for qemu-devel@nongnu.org; Tue, 25 Oct 2016 23:05:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54490) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bzEXI-0005f7-C7 for qemu-devel@nongnu.org; Tue, 25 Oct 2016 23:05:52 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 7727081222 for ; Wed, 26 Oct 2016 03:05:51 +0000 (UTC) Date: Wed, 26 Oct 2016 11:05:49 +0800 From: Fam Zheng Message-ID: <20161026030549.GD14605@lemon> References: <1477447172-19677-1-git-send-email-famz@redhat.com> <0137c2f9-8e21-1269-8c60-f33dd8850ca9@redhat.com> <20161026024604.GC14605@lemon> <8ae892da-87b1-3fa5-2590-93f7c42175ac@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8ae892da-87b1-3fa5-2590-93f7c42175ac@redhat.com> Subject: Re: [Qemu-devel] [PATCH] trace: Fix 'char **' compilation error in simple backend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, Stefan Hajnoczi On Tue, 10/25 21:56, Eric Blake wrote: > On 10/25/2016 09:46 PM, Fam Zheng wrote: > > On Tue, 10/25 21:29, Eric Blake wrote: > >> On 10/25/2016 08:59 PM, Fam Zheng wrote: > >>> Currently, the generated function body will do "strlen(arg)" but the > >>> argument could be 'char **'. Avoid that by exclusding such cases in > >> > > >>> def is_string(arg): > >>> strtype = ('const char*', 'char*', 'const char *', 'char *') > >>> - if arg.lstrip().startswith(strtype): > >>> + non_strtype = ('const char**', 'char**', 'const char **', 'char **') > >>> + arg_strip = arg.lstrip() > >>> + if arg_strip.startswith(strtype) and not arg_strip.startswith(non_strtype): > >> > >> There may be a more compact way to write it, but I'm not enough of a > >> python expert to know offhand what else to suggest (it's not as simple > >> as string concatenation of strtype + '*', since strtype is a tuple > >> rather than a string). > > > > Did you mean > > > > non_strtype = tuple(x + '*' for x in strtype) > > Hmm, I guess that would work. > > Or, what about a different approach, something like: > if arg_strip.startswith(strtype) and no_multiple_star(arg_strip): > for some sane definition of no_multiple_star() that checks that there is > exactly one '*' in a string. In C, I'd check roughly: > p = strchr(str, '*'); > if (p && !strchr(p + 1, '*')) { > // treat str as string > } > but again, I'm not enough of an expert to pop that out late at night, > even if python has an easy one-liner way to express that. That's indeed a nicer approach: if arg_strip.startswith(strtype) and arg_strip.count("*") == 1: Do you want a respin with your suggested-by? :-) Fam > > > > But personally I'd stick to the flatten version in this specific case for > > a bit more readability. > > Indeed, and that's why I gave R-b as-is, even if it fails when there are > multiple 'const' qualifiers in a string with multiple '*' :) > > -- > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >