Messages in this thread | | | Subject | Re: [RFC PATCH] seq_file: Use seq_puts when seq_printf has only a format with no args | From | Joe Perches <> | Date | Sat, 16 Mar 2013 09:15:40 -0700 |
| |
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.
| |