[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] trace: Fix 'char **' compilation error in simpl
From: |
Fam Zheng |
Subject: |
Re: [Qemu-devel] [PATCH] trace: Fix 'char **' compilation error in simple backend |
Date: |
Wed, 26 Oct 2016 11:05:49 +0800 |
User-agent: |
Mutt/1.7.1 (2016-10-04) |
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
>