cocci: matching (multiple) identifiers
PATCH 1/1 cocci: matching (multiple) identifiers
"make coccicheck" seems to work OK at GitHub CI using
$ spatch --version
spatch version 1.1.1 compiled with OCaml version 4.13.1
OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCREbut not with
$ spatch --version
spatch version 1.3 compiled with OCaml version 5.3.0
OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: StrJudging from https://ocaml.org/manual/5.3/api/Str.html, I suspect that this probably is caused by the distinction between BRE vs PCRE. As there is no reasonably clean way to write the multiple choice matches portably between these two pattern languages, let's stop using regexp_constraint and use compare_constraint instead when listing the function names to exclude.
There are other uses of "!~" but they all want to match a single simple token, that should work fine either with BRE or PCRE.
--- contrib/coccinelle/commit.cocci | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/coccinelle/commit.cocci +2 -1
@@ -25,7 +25,8 @@ expression s; // functions, then the recommended transformation will be bogus with // repo_get_commit_tree() on the LHS. @@ -identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$"; +identifier f != { repo_get_commit_tree, get_commit_tree_in_graph_one, + load_tree_for_commit, set_commit_tree }; expression c; @@ f(...) {<...
PATCH 1/1 cocci: do not directly access the .d_type member in struct dirent
In "struct dirent", the presence of the .d_type member should not be assumed and the code should instead use DTYPE() macro, with possibly a fallback check to determine the type of the file.
Add a rule to catch direct access to the .d_type member and use DTYPE() macro instead, except in the emulation code paths that work on platforms that do have the member. This is probably not sufficient to notice the lack of necessary fallback code.
--- contrib/coccinelle/dtype.cocci | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 contrib/coccinelle/dtype.cocci
contrib/coccinelle/dtype.cocci new file +8 -0
@@ -0,0 +1,8 @@ +@@ +identifier f != { finddata2dirent, precompose_utf8_readdir }; +struct dirent *E; +@@ + f(...) {<... +- E->d_type ++ DTYPE(E) + ...>}
Signature · 1 line
2.50.0-228-g6e205fdad9
Re: [PATCH] cocci: do not directly access the .d_type member in struct dirent
Quoted 10 lines · Junio C Hamano
In "struct dirent", the presence of the .d_type member should not be assumed and the code should instead use
DTYPE()macro, with possibly a fallback check to determine the type of the file.Add a rule to catch direct access to the .d_type member and use
DTYPE()macro instead, except in the emulation code paths that work on platforms that do have the member. This is probably not sufficient to notice the lack of necessary fallback code.Signed-off-by Junio C Hamano <[email protected]>
This change looks good to me. Atleast it will catch code that fails to build on niche platforms, even if it cannot validate existing backup code.
Your fix for the 'git diff --no-index' looks correct [1]. I'll build libcurl on an AIX machine I have access to in order to test (not an administrator on it).
Collin
[1] https://lore.kernel.org/git/[email protected]/T/#m4fc1f0ddf1730ffb025e37d523035bd9f6cddfae
Re: [PATCH] cocci: do not directly access the .d_type member in struct dirent
Quoted 11 lines · Collin Funk
Quoted 9 lines · Junio C Hamano
In "struct dirent", the presence of the .d_type member should not be assumed and the code should instead use
DTYPE()macro, with possibly a fallback check to determine the type of the file.Add a rule to catch direct access to the .d_type member and use
DTYPE()macro instead, except in the emulation code paths that work on platforms that do have the member. This is probably not sufficient to notice the lack of necessary fallback code.
Quoted 5 lines
Quoted 1 line
Signed-off-by Junio C Hamano <[email protected]>This change looks good to me. Atleast it will catch code that fails to build on niche platforms, even if it cannot validate existing backup code.
I do not think it is necessarily a good idea to allow building a binary that is known to silently misbehave, though.
Quoted 5 lines
Reviewed-by Collin Funk <[email protected]>Your fix for the 'git diff --no-index' looks correct [1]. I'll build libcurl on an AIX machine I have access to in order to test (not an administrator on it).
I do not think you need libcurl if you only want to test the diff --no-index change, but anyway, thanks.
Re: [PATCH] cocci: do not directly access the .d_type member in struct dirent
Quoted 6 lines · Junio C Hamano
Quoted 3 lines
This change looks good to me. Atleast it will catch code that fails to build on niche platforms, even if it cannot validate existing backup code.
I do not think it is necessarily a good idea to allow building a binary that is known to silently misbehave, though.
Yes, but off the top of my head I cannot think of a great way to check that DTYPE has backup code for systems that do not have d_type.
At least in the case of 'git diff --no-index' the tests will fail if we do not properly detect a file is a directory. So at least we will likely know upon running 'make test'. Still that requires manual investigation, so not perfect, though...
Quoted 6 lines
Quoted 3 lines
Your fix for the 'git diff --no-index' looks correct [1]. I'll build libcurl on an AIX machine I have access to in order to test (not an administrator on it).
I do not think you need libcurl if you only want to test the diff --no-index change, but anyway, thanks.
I assumed that it was a hard dependency and could not be disabled. Am I wrong?
Anyways, it was quick so no worries. I posted my findings [1].
Collin
[1] https://lore.kernel.org/git/[email protected]/T/#me995c8f49943f0606c236e8e5e9ea8163602e65b