]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: add explicit statement isomorphisms
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 26 Apr 2019 19:42:16 +0000 (21:42 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 27 Apr 2019 13:26:11 +0000 (15:26 +0200)
Coccinelle needs a custom isomorphism file with rules (isomorphisms) how
to correctly rewrite conditions with explicit NULL checks (i.e.
if (ptr == NULL)) to their shorter form (i.e. if (!ptr)). Coccinelle
already contains such isomorphisms in its default .iso file, however,
they're in the opposite direction, which results in useless output from
coccinelle/equals-null.cocci.

With this fix, `spatch` should no longer report patches like:

@@ -628,8 +628,9 @@ static int path_deserialize_item(Unit *u
                 f = path_result_from_string(value);
                 if (f < 0)
                         log_unit_debug(u, "Failed to parse result value: %s", value);
-                else if (f != PATH_SUCCESS)
-                        p->result = f;
+                else {if (f != PATH_SUCCESS)
+                                p->result = f;
+                }

         } else
                 log_unit_debug(u, "Unknown serialization key: %s", key);

coccinelle/run-coccinelle.sh
coccinelle/systemd-definitions.iso [new file with mode: 0644]

index 520de0ac4215f012f644cefc78687133621d4b2e..4d882112e639bc0d4db9b370d634d81351c48854 100755 (executable)
@@ -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 (file)
index 0000000..92db763
--- /dev/null
@@ -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