Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
On Fri, 14 Oct 2016, SF Markus Elfring wrote: > > You can look at patches people have previously submitted and see to what > > extent there is interest in this issue. > > I see another software development challenge here. > > The discussed source code search pattern builds on a "general function" > like "seq_printf" as an update candidate from which each instance > (probably with a different prefix) is connected with a few replacement > possibilities. > Did any other software developer fiddle with corresponding combinations > of function names? No idea. Look at the code and see what is available. julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
> You can look at patches people have previously submitted and see to what > extent there is interest in this issue. I see another software development challenge here. The discussed source code search pattern builds on a "general function" like "seq_printf" as an update candidate from which each instance (probably with a different prefix) is connected with a few replacement possibilities. Did any other software developer fiddle with corresponding combinations of function names? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
On Fri, 14 Oct 2016, SF Markus Elfring wrote: > > But that should be fine for detecting eg if a string has only one character. > > Did you come along similar change possibilities at other places already? > > http://lxr.free-electrons.com/source/include/linux/seq_file.h?v=4.8#L114 > > ╔══╤╤╗ > ║ update candidate │ 1. replacement │ 2. replacement ║ > ╠══╪╪╣ > ║ seq_printf │ seq_puts │ seq_putc ║ > ╚══╧╧╝ > > > Would it make sense to consider any more source code search patterns here? I'm not familiar with the details of this issue. julia___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: misc: Improve the script for more accurate results
On Friday 14 October 2016 02:21 PM, Lars-Peter Clausen wrote: > On 10/13/2016 07:01 PM, Vaishali Thakkar wrote: >> >> >> On Thursday 13 October 2016 09:45 PM, Julia Lawall wrote: >>> >>> >>> On Thu, 13 Oct 2016, Vaishali Thakkar wrote: >>> Currently because of the left associativity of the operators, pattern IRQF_ONESHOT | flags does not match with the pattern when we have more than one flag after the disjunction. This eventually results in giving false positives by the script. The patch eliminates these FPs by improving the rule. Also, add a new rule to eliminate the false positives given by the new line issue. Misc: 1. Add support for the context, org and report mode in the case of devm_request_threaded_irq 2. To be consistent with other scripts, change the confidence level to 'Moderate' >>> >>> I'm getting a lot more reports for context mode than for patch mode, eg >>> for sound/pcmcia/vx/vxpocket.c. Is this normal? >> >> This seems to be because of the ... in '*request_threaded_irq@p(...)'. >> Usually I think we should have same rules for the patch and context mode. >> But the original code does not do that. So, I was not sure if that was >> intentional or not. >> [just in case, person wants to check all cases of these functions using >> context mode] > > To be honest, I don't remember if it was intentional or not. But looking at > it now, I'd say context mode should use the same pattern as the report mode. > The way it is right now context mode certainly generates a fair amount of > false positives. > > As for your patch I'd say split this into multiple patches, one patch to add > the missing devm_ variants to the context and report mode and one patch to > improve the matching, since these are two independent changes. Sure. I'll send the revised version with 3 patches. One more with changing the rule of context mode. > -- Vaishali ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
> * But I will also need a way to construct a source code change ("plus code" in > the semantic patch) with OCaml or Python scripting, won't I? If you need to do this, you can follow the examples in demos/camltococci.cocci and demos/pythontococci.cocci julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
> You can inherit and test properties of anything you like in python or > ocaml code. If you inherit some kind of metavariable other than a > position variable, the term will be represented as a string. But that > should be fine for detecting eg if a string has only one character. Your explanation sounds promising. > If it has multiple characters, you can do the include match false call, so > that > in the last rule when yu inherit again the metavariable containing th > string, it won't be seen. I see another software development challenge then. * I imagine that this "false call" will work for the exclusion of unwanted source code fragments. * But I will also need a way to construct a source code change ("plus code" in the semantic patch) with OCaml or Python scripting, won't I? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: misc: Improve the script for more accurate results
On 10/13/2016 07:01 PM, Vaishali Thakkar wrote: > > > On Thursday 13 October 2016 09:45 PM, Julia Lawall wrote: >> >> >> On Thu, 13 Oct 2016, Vaishali Thakkar wrote: >> >>> Currently because of the left associativity of the operators, >>> pattern IRQF_ONESHOT | flags does not match with the pattern >>> when we have more than one flag after the disjunction. This >>> eventually results in giving false positives by the script. >>> The patch eliminates these FPs by improving the rule. >>> >>> Also, add a new rule to eliminate the false positives given by >>> the new line issue. >>> >>> Misc: >>> >>> 1. Add support for the context, org and report mode in the case >>>of devm_request_threaded_irq >>> 2. To be consistent with other scripts, change the confidence >>>level to 'Moderate' >> >> I'm getting a lot more reports for context mode than for patch mode, eg >> for sound/pcmcia/vx/vxpocket.c. Is this normal? > > This seems to be because of the ... in '*request_threaded_irq@p(...)'. > Usually I think we should have same rules for the patch and context mode. > But the original code does not do that. So, I was not sure if that was > intentional or not. > [just in case, person wants to check all cases of these functions using > context mode] To be honest, I don't remember if it was intentional or not. But looking at it now, I'd say context mode should use the same pattern as the report mode. The way it is right now context mode certainly generates a fair amount of false positives. As for your patch I'd say split this into multiple patches, one patch to add the missing devm_ variants to the context and report mode and one patch to improve the matching, since these are two independent changes. ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
> > coccinelle/demos/first.cocci may be helpful. > > I have got the impression that this small SmPL script demonstrates the usage > of the mentioned function from your software library only for a simple > position variable. > I do not see the way so far how desired data could be extracted from a > function > (or expression?) parameter. Would you like to make the introspection options > a bit > clearer for the SmPL interface? You can inherit and test properties of anything you like in python or ocaml code. If you inherit some kind of metavariable other than a position variable, the term will be represented as a string. But that should be fine for detecting eg if a string has only one character. If it has multiple characters, you can do the include match false call, so that in the last rule when yu inherit again the metavariable containing th string, it won't be seen. julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
>> With which metavariables and corresponding programming interfaces can >> strings that >> are passed to such functions be checked in more detail by the Coccinelle >> software? > > The simplest would be to use python or ocaml code to make the checks that > are needed. You can use cocci.include_match(False) in python or > Coccilib.include_match false in ocaml when your test detects that > something is not suitable. Thanks for your suggestion. > coccinelle/demos/first.cocci may be helpful. I have got the impression that this small SmPL script demonstrates the usage of the mentioned function from your software library only for a simple position variable. I do not see the way so far how desired data could be extracted from a function (or expression?) parameter. Would you like to make the introspection options a bit clearer for the SmPL interface? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Replacing calls of general functions by more specific ones with SmPL
On Fri, 14 Oct 2016, SF Markus Elfring wrote: > Hello, > > I came during my software development activities along a few Linux source > files > where I got an advice by the script "checkpatch.pl" like the following. > > WARNING: Prefer seq_puts to seq_printf > > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl?id=29fbff8698fc0ac1a1d74584b258e0bf18b469f9#n5610 > > > Joe Perches pointed out that the function "seq_putc" would be more appropriate > at a specific source code place. > https://patchwork.kernel.org/patch/9364455/ > https://lkml.kernel.org/r/<1475771699.1914.10.ca...@perches.com> > > > Now I am curious on how good the semantic patch language is applicable > for advanced source code transformations in similar use cases. > With which metavariables and corresponding programming interfaces can strings > that > are passed to such functions be checked in more detail by the Coccinelle > software? The simplest would be to use python or ocaml code to make the checks that are needed. You can use cocci.include_match(False) in python or Coccilib.include_match false in ocaml when your test detects that something is not suitable. coccinelle/demos/first.cocci may be helpful. julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] Replacing calls of general functions by more specific ones with SmPL
Hello, I came during my software development activities along a few Linux source files where I got an advice by the script "checkpatch.pl" like the following. WARNING: Prefer seq_puts to seq_printf https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl?id=29fbff8698fc0ac1a1d74584b258e0bf18b469f9#n5610 Joe Perches pointed out that the function "seq_putc" would be more appropriate at a specific source code place. https://patchwork.kernel.org/patch/9364455/ https://lkml.kernel.org/r/<1475771699.1914.10.ca...@perches.com> Now I am curious on how good the semantic patch language is applicable for advanced source code transformations in similar use cases. With which metavariables and corresponding programming interfaces can strings that are passed to such functions be checked in more detail by the Coccinelle software? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci