diff --git a/coccinelle/run-coccinelle.sh b/coccinelle/run-coccinelle.sh index 520de0ac42..4d882112e6 100755 --- a/coccinelle/run-coccinelle.sh +++ b/coccinelle/run-coccinelle.sh @@ -2,6 +2,7 @@ top="$(git rev-parse --show-toplevel)" files="$(git ls-files ':/*.[ch]')" +iso_defs="$top/coccinelle/systemd-definitions.iso" args= case "$1" in @@ -21,7 +22,7 @@ for SCRIPT in ${@-$top/coccinelle/*.cocci} ; do TMPFILE=`mktemp` echo "+ spatch --sp-file $SCRIPT $args ..." parallel --halt now,fail=1 --keep-order --noswap --max-args=20 \ - spatch --sp-file $SCRIPT $args ::: $files \ + spatch --iso-file $iso_defs --sp-file $SCRIPT $args ::: $files \ 2>"$TMPFILE" || cat "$TMPFILE" echo -e "--x-- Processed $SCRIPT --x--\n" done diff --git a/coccinelle/systemd-definitions.iso b/coccinelle/systemd-definitions.iso new file mode 100644 index 0000000000..92db763a29 --- /dev/null +++ b/coccinelle/systemd-definitions.iso @@ -0,0 +1,20 @@ +/* Statement isomorphisms - replace explicit checks against NULL with a + * shorter variant, which relies on C's downgrade-to-bool feature. + * The expression metavariables should be declared as pointers, however, + * that doesn't work well with complex expressions like: + * if (UNIT(p)->default_dependencies != NULL) + */ + +Statement +@@ +expression X; +statement S; +@@ +if (X == NULL) S => if (!X) S + +Statement +@@ +expression X; +statement S; +@@ +if (X != NULL) S => if (X) S