On Mon, 3 Sep 2012, Matt Turner wrote:

I'm trying to make a semantic patch which removes useless casts to
free(). ie, free(void *)tmp) -> free(tmp).

The semantic patch I have now is:

@@
type T;
expression E;
@@
- free ((T *) E);
+ free (E);

which works when T is char, void, or another recognizable C type.

I have some instances of free((GLvoid *) ...) which are not
recognized. I've tried using --all-includes -I ... and including the
file which provides the GLvoid typedef, but without success.

Is there a way to tell Coccinelle that GLvoid is typedef'd to void?

I'm a bit surprised that it doesn't recognize this as a type.  Check with
spatch -parse_c myfile.c to be sure that it is even parsing the function. Perhaps it is failing on the function for another reason.

If it does seem to be parsing the function, then it might help to define a macro. In your standard.h file, try #define GLvoid void. I suspect, though, that if you do that, it will not be willing to actually remove the type name. All you could do is use python to print out the line on which the problem occurs.

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

Reply via email to