Received: from eggs.gnu.org ([2001:4830:134:3::10]:45872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzEOW-0007CP-NE for qemu-devel@nongnu.org; Tue, 25 Oct 2016 22:56:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzEOT-0003MP-KK for qemu-devel@nongnu.org; Tue, 25 Oct 2016 22:56:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bzEOT-0003MA-CY for qemu-devel@nongnu.org; Tue, 25 Oct 2016 22:56:45 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 6ED7B6540A for ; Wed, 26 Oct 2016 02:56:44 +0000 (UTC) References: <1477447172-19677-1-git-send-email-famz@redhat.com> <0137c2f9-8e21-1269-8c60-f33dd8850ca9@redhat.com> <20161026024604.GC14605@lemon> From: Eric Blake Message-ID: <8ae892da-87b1-3fa5-2590-93f7c42175ac@redhat.com> Date: Tue, 25 Oct 2016 21:56:43 -0500 MIME-Version: 1.0 In-Reply-To: <20161026024604.GC14605@lemon> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1Na1TqOr6oWFjKdOffdskT9xVF7gcmmlc" 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: Fam Zheng Cc: qemu-devel@nongnu.org, Stefan Hajnoczi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1Na1TqOr6oWFjKdOffdskT9xVF7gcmmlc From: Eric Blake To: Fam Zheng Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Message-ID: <8ae892da-87b1-3fa5-2590-93f7c42175ac@redhat.com> Subject: Re: [Qemu-devel] [PATCH] trace: Fix 'char **' compilation error in simple backend References: <1477447172-19677-1-git-send-email-famz@redhat.com> <0137c2f9-8e21-1269-8c60-f33dd8850ca9@redhat.com> <20161026024604.GC14605@lemon> In-Reply-To: <20161026024604.GC14605@lemon> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 =3D ('const char*', 'char*', 'const char *', 'char *') >>> - if arg.lstrip().startswith(strtype): >>> + non_strtype =3D ('const char**', 'char**', 'const char **', 'cha= r **') >>> + arg_strip =3D arg.lstrip() >>> + if arg_strip.startswith(strtype) and not arg_strip.startswith(no= n_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). >=20 > Did you mean >=20 > non_strtype =3D 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 =3D 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. > But personally I'd stick to the flatten version in this specific case f= or > 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 '*' :) --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --1Na1TqOr6oWFjKdOffdskT9xVF7gcmmlc Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYEBtrAAoJEKeha0olJ0NqFigH/2npv9f60DYNAgcP/bjd11jX H5bu5KNvUhf8uygkYt2QioQbU0hbWlfTrVAq3Wbe5RMr9gsx+LdZQ7YwotHkWMH2 AV2UsLDpWRFsb/l/F3cWhL3iJp1v5KbT7qFzR+lpIz+jm5pDeimIz6d+iDhKGrgV MbNPgzDd19eUW1osHfTAfUle4YUAh+t8J6JqM2cTt+mEEEN9U8w76JSvbTAIvaK0 ga5RqvzhAf/UV5CT/hIuhXcl9Q7y8nz+7Eo/uOLVScUicH+QChWpUKYblwb4fVIW BMKHT9GFz8d0tFE2W5NRw7OUHmAQ5mcqSWFDjWBpdwUtscgEY2Tqvdg22weVtXc= =94hn -----END PGP SIGNATURE----- --1Na1TqOr6oWFjKdOffdskT9xVF7gcmmlc--