I've got a couple of questions about python interface.
Let us suppose that I want to suppress a couple of matches because they are
false-positives.
However, I still want to check they exists in finalize block and print a
warning otherwise.
This is some kind of self-check for a rule.
For example, there is "test.c" file with:
extern int function1(void);
extern int function2(void);
int test(void)
{
return function1();
}
And the rule test.cocci with:
virtual context
virtual org
virtual patch
virtual report
@initialize:python@
@@
matches = [] # global list of all positions to check in finalize
blacklist = frozenset(['test'])
# Always prints []. Is it normal?
#print(cocci.files())
def relevant(p): # suppress functions from blacklist
matches.extend(p) # It doesn't work in position script, so I do it here
return False if blacklist & { el.current_element for el in p } else
True # intersection
@r depends on !patch@
// It doesn't work. Is it normal?
//position p: script:python() { matches.extend(p); relevant(p) };
position p: script:python() { relevant(p) };
@@
* function1@p();
@rp depends on patch@
position p: script:python() { relevant(p) };
@@
- function1@p();
+ function2();
// Self-check for the rule
@finalize:python depends on !patch@
@@
# Always prints []. Is it normal?
#print(cocci.files())
if 'test.c' in cocci.files(): # I know that we should match test definition in
test.c
not_matched = blacklist - { el.current_element for el in matches }; #
set difference
if not_matched:
print('SELF-CHECK: patterns no longer match definitions for: '
+ ','.join(not_matched))
I want to implement this kind of self-check for memdup_user function. I need
check that the patterns
match the function definition, but suppress these diagnostics. And print a
warning about changed
implementation if there is no matches for the patterns in mm/util.c
Thanks,
Denis
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci