coccinelle: simplify file exclusions
Use Coccinelle's "depends on" directive to exclude files from certain transformations. This should make them a bit simpler and possibly faster, since we don't have to shell out to Python. Unfortunately, this works only for file/directory exclusions. For function and other more complex exclusions we still need to use Python, at least for now. Also, completely drop the file exclusion for man/ in the xsprintf transformation, since we filter out everything under man/ before we even run Coccinelle (in run-coccinelle.sh).
This commit is contained in:
committed by
Luca Boccassi
parent
1bbf72d770
commit
6dcabd5f5e
@@ -1,8 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
@@
|
||||
/* We want to stick with dup() in test-fd-util.c */
|
||||
position p : script:python() { p[0].file != "src/test/test-fd-util.c" };
|
||||
@ depends on !(file in "src/test/test-fd-util.c") @
|
||||
expression fd;
|
||||
@@
|
||||
- dup@p(fd)
|
||||
- dup(fd)
|
||||
+ fcntl(fd, F_DUPFD, 3)
|
||||
|
||||
+33
-37
@@ -1,103 +1,99 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
@@
|
||||
/* Disable this transformation for the test-string-util.c */
|
||||
position p : script:python() { p[0].file != "src/test/test-string-util.c" };
|
||||
@ depends on !(file in "src/test/test-string-util.c") @
|
||||
expression s;
|
||||
@@
|
||||
(
|
||||
- strv_length@p(s) == 0
|
||||
- strv_length(s) == 0
|
||||
+ strv_isempty(s)
|
||||
|
|
||||
- strv_length@p(s) <= 0
|
||||
- strv_length(s) <= 0
|
||||
+ strv_isempty(s)
|
||||
|
|
||||
- strv_length@p(s) > 0
|
||||
- strv_length(s) > 0
|
||||
+ !strv_isempty(s)
|
||||
|
|
||||
- strv_length@p(s) != 0
|
||||
- strv_length(s) != 0
|
||||
+ !strv_isempty(s)
|
||||
|
|
||||
- strlen@p(s) == 0
|
||||
- strlen(s) == 0
|
||||
+ isempty(s)
|
||||
|
|
||||
- strlen@p(s) <= 0
|
||||
- strlen(s) <= 0
|
||||
+ isempty(s)
|
||||
|
|
||||
- strlen@p(s) > 0
|
||||
- strlen(s) > 0
|
||||
+ !isempty(s)
|
||||
|
|
||||
- strlen@p(s) != 0
|
||||
- strlen(s) != 0
|
||||
+ !isempty(s)
|
||||
|
|
||||
- strlen_ptr@p(s) == 0
|
||||
- strlen_ptr(s) == 0
|
||||
+ isempty(s)
|
||||
|
|
||||
- strlen_ptr@p(s) <= 0
|
||||
- strlen_ptr(s) <= 0
|
||||
+ isempty(s)
|
||||
|
|
||||
- strlen_ptr@p(s) > 0
|
||||
- strlen_ptr(s) > 0
|
||||
+ !isempty(s)
|
||||
|
|
||||
- strlen_ptr@p(s) != 0
|
||||
- strlen_ptr(s) != 0
|
||||
+ !isempty(s)
|
||||
)
|
||||
@@
|
||||
/* Disable this transformation for the hashmap.h, set.h, test-hashmap.c, test-hashmap-plain.c */
|
||||
position p : script:python() {
|
||||
p[0].file != "src/basic/hashmap.h" and
|
||||
p[0].file != "src/basic/set.h" and
|
||||
p[0].file != "src/test/test-hashmap.c" and
|
||||
p[0].file != "src/test/test-hashmap-plain.c"
|
||||
};
|
||||
@ depends on !(file in "src/basic/hashmap.h")
|
||||
&& !(file in "src/basic/set.h")
|
||||
&& !(file in "src/test/test-hashmap.c")
|
||||
&& !(file in "src/test/test-hashmap-plain.c") @
|
||||
expression s;
|
||||
@@
|
||||
(
|
||||
- hashmap_size@p(s) == 0
|
||||
- hashmap_size(s) == 0
|
||||
+ hashmap_isempty(s)
|
||||
|
|
||||
- hashmap_size@p(s) <= 0
|
||||
- hashmap_size(s) <= 0
|
||||
+ hashmap_isempty(s)
|
||||
|
|
||||
- hashmap_size@p(s) > 0
|
||||
- hashmap_size(s) > 0
|
||||
+ !hashmap_isempty(s)
|
||||
|
|
||||
- hashmap_size@p(s) != 0
|
||||
- hashmap_size(s) != 0
|
||||
+ !hashmap_isempty(s)
|
||||
|
|
||||
- ordered_hashmap_size@p(s) == 0
|
||||
- ordered_hashmap_size(s) == 0
|
||||
+ ordered_hashmap_isempty(s)
|
||||
|
|
||||
- ordered_hashmap_size@p(s) <= 0
|
||||
- ordered_hashmap_size(s) <= 0
|
||||
+ ordered_hashmap_isempty(s)
|
||||
|
|
||||
- ordered_hashmap_size@p(s) > 0
|
||||
- ordered_hashmap_size(s) > 0
|
||||
+ !ordered_hashmap_isempty(s)
|
||||
|
|
||||
- ordered_hashmap_size@p(s) != 0
|
||||
- ordered_hashmap_size(s) != 0
|
||||
+ !ordered_hashmap_isempty(s)
|
||||
|
|
||||
- set_size@p(s) == 0
|
||||
- set_size(s) == 0
|
||||
+ set_isempty(s)
|
||||
|
|
||||
- set_size@p(s) <= 0
|
||||
- set_size(s) <= 0
|
||||
+ set_isempty(s)
|
||||
|
|
||||
- set_size@p(s) > 0
|
||||
- set_size(s) > 0
|
||||
+ !set_isempty(s)
|
||||
|
|
||||
- set_size@p(s) != 0
|
||||
- set_size(s) != 0
|
||||
+ !set_isempty(s)
|
||||
|
|
||||
- ordered_set_size@p(s) == 0
|
||||
- ordered_set_size(s) == 0
|
||||
+ ordered_set_isempty(s)
|
||||
|
|
||||
- ordered_set_size@p(s) <= 0
|
||||
- ordered_set_size(s) <= 0
|
||||
+ ordered_set_isempty(s)
|
||||
|
|
||||
- ordered_set_size@p(s) > 0
|
||||
- ordered_set_size(s) > 0
|
||||
+ !ordered_set_isempty(s)
|
||||
|
|
||||
- ordered_set_size@p(s) != 0
|
||||
- ordered_set_size(s) != 0
|
||||
+ !ordered_set_isempty(s)
|
||||
)
|
||||
@@
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
@@
|
||||
/* Disable this transformation on test-json.c */
|
||||
position p : script:python() { p[0].file != "src/test/test-json.c" };
|
||||
@ depends on !(file in "src/test/test-json.c") @
|
||||
expression key, val;
|
||||
@@
|
||||
(
|
||||
- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_BOOLEAN(val))
|
||||
- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_BOOLEAN(val))
|
||||
+ SD_JSON_BUILD_PAIR_BOOLEAN(key, val)
|
||||
|
|
||||
- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_INTEGER(val))
|
||||
- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_INTEGER(val))
|
||||
+ SD_JSON_BUILD_PAIR_INTEGER(key, val)
|
||||
|
|
||||
- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_STRING(val))
|
||||
- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_STRING(val))
|
||||
+ SD_JSON_BUILD_PAIR_STRING(key, val)
|
||||
|
|
||||
- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_UNSIGNED(val))
|
||||
- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_UNSIGNED(val))
|
||||
+ SD_JSON_BUILD_PAIR_UNSIGNED(key, val)
|
||||
|
|
||||
- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_VARIANT(val))
|
||||
- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_VARIANT(val))
|
||||
+ SD_JSON_BUILD_PAIR_VARIANT(key, val)
|
||||
)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
@@
|
||||
/* We want to stick with the literal expression in the implementation of timestamp_is_set(), i.e. in time-util.h */
|
||||
@ depends on !(file in "src/basic/time-util.h") @
|
||||
expression x;
|
||||
constant USEC_INFINITY = USEC_INFINITY;
|
||||
/* We want to stick with the literal expression in the implementation of timestamp_is_set(), i.e. in time-util.c */
|
||||
position p : script:python() { p[0].file != "src/basic/time-util.h" };
|
||||
@@
|
||||
(
|
||||
- x > 0 && x < USEC_INFINITY
|
||||
@@ -12,7 +11,7 @@ position p : script:python() { p[0].file != "src/basic/time-util.h" };
|
||||
- x < USEC_INFINITY && x > 0
|
||||
+ timestamp_is_set(x)
|
||||
|
|
||||
- x@p > 0 && x != USEC_INFINITY
|
||||
- x > 0 && x != USEC_INFINITY
|
||||
+ timestamp_is_set(x)
|
||||
|
|
||||
- x != USEC_INFINITY && x > 0
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
@@
|
||||
position p : script:python() { not p[0].file.startswith("man/") };
|
||||
expression e, fmt;
|
||||
expression list vaargs;
|
||||
@@
|
||||
- snprintf@p(e, sizeof(e), fmt, vaargs);
|
||||
- snprintf(e, sizeof(e), fmt, vaargs);
|
||||
+ xsprintf(e, fmt, vaargs);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
@@
|
||||
position p : script:python() { p[0].file != "src/journal/lookup3.c" };
|
||||
expression e,e1;
|
||||
@ depends on !(file in "src/journal/lookup3.c") @
|
||||
expression e, e1;
|
||||
@@
|
||||
- if (e) {
|
||||
+ if (e)
|
||||
(
|
||||
e1@p;
|
||||
e1;
|
||||
|
|
||||
return e1@p;
|
||||
return e1;
|
||||
)
|
||||
- }
|
||||
|
||||
Reference in New Issue
Block a user