[Cocci] Whole-directory handling not functional?

Julia Lawall julia at diku.dk
Sat Mar 7 07:26:01 CET 2009


> There are two small speedbumps I encountered when trying the patch above:
> 
> This command processes all files, but does nothing:
> spatch -noif0_passing -inplace -cocci_file
> cocci/renamechipaccessors.cocci -dir .
> 
> These command processes all files, but it converts only .c files and
> leaves the function defined in the header file unchanged:
> spatch -noif0_passing -inplace -cocci_file
> cocci/renamechipaccessors.cocci *.[ch]
> spatch -noif0_passing -inplace -include_headers -cocci_file
> cocci/renamechipaccessors.cocci *.[ch]
> spatch -noif0_passing -inplace -include_headers -I . -cocci_file
> cocci/renamechipaccessors.cocci *.[ch]
> spatch -noif0_passing -inplace -include_headers -I . -all_includes
> -cocci_file cocci/renamechipaccessors.cocci *.[ch]

Actually, I never use -inplace; I would rather check the patch and then 
apply it.  But I tried it on a small directory and it worked fine.  At the 
end of the run does it say eg:

One file modified. Result is here: /tmp/foo.c
One file modified. Result is here: /tmp/foo.h

In your directory, do you get .cocci_orig files?

With -dir, you should use -include_headers if you want the header files to 
be modified.  If you give a bunch of file names as arguments, that 
shouldn't be necessary (and in any case it will be ignored).  But I don't 
know why in your case it is doing nothing at all.

Actually, giving a set of files as arguments probably doesn't do what you 
think.  Instead of processing the files one by one, it processes them 
breadth first - the first rule to all files, then the second rule to all 
files, etc.  This can allow interactions between the files, in that you 
can find something that the first rule is looking for in one file, and 
then use that information to modify another file.  I have the impression, 
though that it should be slower, or at least incur more memory usage, 
since data structures for many files are live at the same time.

-all_includes controls which files are actually included when it comes to 
an #include directive.  It doesn't have any effect on the set of files 
that are modified by -inplace.  -all_includes is useful when you are 
missing type information, that would be in a header file.  The unfortunate 
point is that when you are not doing a -inplace and just generating a 
patch and the header file is modified, it will generate a patch for each 
modified instance.  By default, if the semantic patch doesn't require type 
information, then no #include directives are followed.  -include_headers 
then causes the header files to be processed independently.

Perhaps just try without -inplace and see what you get results for?  Maybe 
that will show where the problem is.

julia


More information about the Cocci mailing list