On Friday 18 June 2010 13:38:35 Eric Noulard wrote:
> Hi all,
> 
> I do have a problem for writing a python scripts in  a cocci semantic patch.
> I don't really know if it's a "feature" or a bug, the context is the 
> following.
> 
> A cocci file (rule1and2.cocci) contains several rules (say 2 for the example),
> and a single python script (at the end).
> 
> The python script is using matches of the rules:
> 
> @script:python@
> rule1_matches << rule_1.p;
> rule2_matches << rule_2.p;
> 
> @@
> if (len(rule1_matches)>0):
>    for m in rule1_matches:
>        print "File <%s>, line %s" % (m.file,m.line)
> if (len(rule2_matches)>0):
>    for m in rule1_matches:
>        print "File <%s>, line %s" % (m.file,m.line)
> 
> 
> it looks like the script is executed iff both rules (1 & 2) matches.
> 
> Find attached  the files to reproduce the "problem":
> 
> Commands giving no output
> spatch -sp rule1and2.cocci -no_show_diff 1-1-2.c
> spatch -sp rule1and2.cocci -no_show_diff 1-1-1.c
> 
> Command giving output
> spatch -sp rule1and2.cocci -no_show_diff 1-1-1.c 1-1-2.c
> 
> Is this an expected behavior?

Yes. The python code depends on rule_1.p AND rule_2.p. Thus, the python code
is only invoked if both rule have matched.

> 
> Should I write a python script for EACH rules?

In this case, you should.

> 
> 
> 

-- 
Nicolas Palix
Tel: (+33) 1 44 27 87 25
Tel: (+33) 6 81 07 91 72
Web: http://www.diku.dk/~npalix/
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to