On Mon, 8 Nov 2010, Michael Stefaniuc wrote:
> Hello,
>
> somehow I cannot find the for adding stuff around a function call.
> Finding a function call that is called with a lock held is trivial:
> wined3d_mutex_lock();
> <... iwine...@p( ... ) ...>
> wined3d_mutex_unlock();
>
> But if I want to add the locks around the IWineD3D() calls that don't have
> them I fail:
> + wined3d_mutex_lock();
> <... iwine...@p( ... ) ...>
> + wined3d_mutex_unlock();
> gives
> Fatal error: exception Failure("13: no available token to attach to")
>
> Basically I would need something like
> @@ statement S; @@
> + wined3d_mutex_lock();
> S
> + wined3d_mutex_unlock();
> where S is the smallest possible statement that contains the function call
> IWineD3D(). But how do I specify that? I have grepped through the examples but
> didn't find anything that looks similar to this problem.
There is unfortunately no drect way to do this. I'm not even sure it
would be desirable. For example, what if the call to IWineD3D is in an if
test and the then branch does a return. You could introduce a deadlock,
because there would be no unlock before the return.
Currently the only solution is to enumerate the various kinds of
statements you are interested in. A small problem here is that do ...
while never got added to SmPL, so there is no way to specify that. You
can use position variables to mark all of the calls that get treated and
then make another rule that searches for any call that is not marked by
the position variable, eg:
@r@
expression e;
position p;
@@
+lock()
e = <+...c...@p()...+>;
+unlock()
@@
position p != r.p;
@@
- c...@p()
+ BAD(call())
You can also say position p != {r.p,s.p,x.p,...}; if there are multiple
position variables you want to compare with.
You can of course also make another rule afterwards to print out an error
message rather than introducing an artificial call to BAD.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)