Semantic patches with spatch(1) from Coccinelle

Dridi Boukelmoune dridi.boukelmoune at zenika.com
Fri Apr 18 11:49:19 CEST 2014


Hi all,

Last September I was introduced to Coccinelle [1,2] at a conference
and since then I kept wondering how I could ever try it. Last week I
was randomly reading parts of Varnish code (which I haven't done since
last August I think) and found a piece of code that felt odd to me. Since
Coccinelle's semantic patches are meant for C code (for the Linux kernel
initially) my brain eventually connected the right neurons and here I was
making my Coccinelle helloworld with Varnish.

The two patches only pick the right macros from miniobj.h and vas.h
throughout the code base, and fortunately spatch even outputs
git-friendly patches.

For instance, to fix the "mistake" I found in stevedore.c, I've
written this spatch:
   @@
   expression x, y;
   @@

   -if (x != NULL)
   - CHECK_OBJ_NOTNULL(x, y);
   +CHECK_OBJ_ORNULL(x, y);

Pretty simple :)

My patch set doesn't bring any value, only consistency to some extent.
I think spatch(1) might prove useful for refactoring too (vmod3to4.cocci?).
Coccinelle's semantic patches are rather expressive in my opinion, the
documentation could include some for vmod developers for instance (eg.
prefer this approach instead of that one).

Happy Easter,
Dridi

[1] http://coccinelle.lip6.fr/
[2] http://coccinellery.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: miniobj.cocci
Type: application/octet-stream
Size: 319 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20140418/6cfd0ffb/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vas.cocci
Type: application/octet-stream
Size: 207 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20140418/6cfd0ffb/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: miniobj.patch
Type: text/x-patch
Size: 592 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20140418/6cfd0ffb/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vas.patch
Type: text/x-patch
Size: 26074 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20140418/6cfd0ffb/attachment-0003.bin>


More information about the varnish-dev mailing list