On Sat, 2013-03-16 at 11:57 -0400, Steven Rostedt wrote:
> My macro nastiness is contagious ;-)

True.

> On Sat, 2013-03-16 at 06:50 -0700, Joe Perches wrote:

> > +int (seq_printf)(struct seq_file *m, const char *f, ...)
> 
> That's rather ugly. Why not just #undef seq_printf before defining it?

The whole thing is ugly, nasty and hackish.
I kinda like it.

But I don't like unnecessary undefs.
The preprocessor doesn't expand (funcname).

> Anyway, not making va_args a whacky name is dangerous. This is why I add
> those crazy underscores. If someone does:
> 
>       var = 1;
>       va_args[] = "abc";
>       seq_printf(m, "%d %s", var, va_args);

The same could be true of fmt and it's
used in lots of macros no?

> What will be printed is:
> 
>       1 var, va_args
> 
> That will be very confusing to people.

And so be fixed very quickly.

> > +   if (sizeof(va_args) > 1)                                \
> > +           seq_printf(seq, fmt, ##__VA_ARGS__);            \
> > +   else                                                    \
> > +           seq_puts(seq, fmt);                             \
> > +} while (0)
> 
> BTW, you need to return a value.

Oh, yeah, thanks.

>  #define seq_printf(seq, fmt, ...)                            \
> -do {                                                         \
> +({                                                           \
>       char va_args[] = __stringify(__VA_ARGS__);              \
> +     int _____ret;                                           \
>       if (sizeof(va_args) > 1)                                \
> -             seq_printf(seq, fmt, ##__VA_ARGS__);            \
> +             _____ret = seq_printf(seq, fmt, ##__VA_ARGS__); \
>       else                                                    \
> -             seq_puts(seq, fmt);                             \
> -} while (0)
> +             _____ret = seq_puts(seq, fmt);                  \
> +     _____ret;                                               \
> +})

It's certainly better as a statement expression,
but I think the underscores are really ugly and
not necessary as ret is locally scoped.

Checkpatch doesn't generally parse strings.
checking strings for % could be done though
I suppose.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to