On Thu, 21 Jun 2012, yafo lee wrote:

hi guys,

In order to convert spin_lock_init(&adpt->tx_lock);
to mtx_init(&adpt->tx_lock, "adpt->tx_lock", "adpt->tx_lock", MTX_DEF);

I wrote the rule:
@@
struct mtx e;
@@
- spin_lock_init(&e)
+ mtx_init(&e, "e", "e", MTX_DEF)

But I got "e" instead of  "adpt->tx_lock", how to fix that?

Coccinelle doesn't really support creating strings. But it is possible by passing through a scripting language.

In the demos subdirectory you can find the demo pythontococci.cocci that shows how to declare a metavariable in python code and then import it into a SmPL rule as an identifier metavariable. Of course, you don't want an identifier metavariable, you want a string, but it suffices to initialize the metavariable in the python code to a string that contains the string, including the extra ", that you want.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to