[Cocci] Problem when using a macro for mangling function names
julia at diku.dk
Fri Mar 20 19:26:41 CET 2009
> So if my understanding is good, spatch doesn't really expand the macros, it
> only extends the parsing rules to take them into account. Am I right ?
This is correct.
> > I will try to find a way to solve the problem. Is this pattern very common
> > in the code you are working with?
> Unfortunately yes. This is something that we cannot get rid of.
> Moreover, another pattern which is very common is
> #define METHOD(foo, bar) componentName_##foo##_##bar
> I think this may raise other problems since
> 1. void METHOD(foor,bar)(params) is not valid C code as opposed to void
> METH(foo)(params) - as highlighted by Yoann.
It doesn't matter. This is fine as long as there is no metavariable that
matches the call to METHOD.
> 2. if the macro expansion semantics is not took into account (hypothesis that
> might be wrong depending on the answer of my above question), then the
> metavariable could be bound to something wrong. Indeed, I believe that the
> metavariable should be bound to 'foo' (in the above case) and not to METH(foo)
> because a direct reference to 'foo' may appear later in the code without the
> use of the METH macro.
But since METH(foo) converts foo into something else, I guess you would
not want a match on foo? That would cause dropping the first argument of
any random call to foo.
More information about the Cocci