git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 4/6] coccinelle: add a rule to make "expression" code use FREE_AND_NULL()

From
René Scharfe <l.s.r@web.de>
Date
Jun 25, 2017, 08:01 UTC
Message-ID
<2122b01f-7627-cd1b-c7df-751c076f90ff@web.de>
In-Reply-To
<xmqq7f0byayu.fsf@gitster.mtv.corp.google.com>
Am 16.06.2017 um 21:43 schrieb Junio C Hamano:
Show 12 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
> 
>> A follow-up to the existing "type" rule added in an earlier
>> change. This catches some occurrences that are missed by the previous
>> rule.
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
> 
> Hmph, I wonder if the "type" thing is really needed.  Over there,
> "ptr" is an expression and we can find "free(ptr); ptr = NULL" with
> the rule in this patch already, no?
Indeed.  How about this on top of master?
-- >8 --
Subject: [PATCH] coccinelle: polish FREE_AND_NULL rules

There are two rules for using FREE_AND_NULL in free.cocci, one for pointer types and one for expressions. Both cause coccinelle to remove empty lines and even newline characters between replacements for some reason; consecutive "free(x);/x=NULL;" sequences end up as multiple FREE_AND_NULL calls on the same time.

Remove the type rule, as the expression rule already covers it, and rearrange the lines of the latter to place the addition of FREE_AND_NULL between the removals, which causes coccinelle to leave surrounding whitespace untouched.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 contrib/coccinelle/free.cocci | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
index f2d97e755b..4490069df9 100644
--- a/contrib/coccinelle/free.cocci
+++ b/contrib/coccinelle/free.cocci
@@ -11,16 +11,8 @@ expression E;
   free(E);
 
 @@
-type T;
-T *ptr;
-@@
-- free(ptr);
-- ptr = NULL;
-+ FREE_AND_NULL(ptr);
-
-@@
 expression E;
 @@
 - free(E);
-- E = NULL;
 + FREE_AND_NULL(E);
+- E = NULL;
-- 
2.13.2
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 7 of 18 in “Add a FREE_AND_NULL() wrapper macro”
  1. 0/6 Add a FREE_AND_NULL() wrapper macroÆvar Arnfjörð Bjarmason, Jun 15, 2017
  2. 6/6 *.[ch] refactoring: make use of the FREE_AND_NULL() macroÆvar Arnfjörð Bjarmason, Jun 15, 2017
  3. 2/6 coccinelle: add a rule to make "type" code use FREE_AND_NULL()Ævar Arnfjörð Bjarmason, Jun 15, 2017
  4. 1/6 git-compat-util: add a FREE_AND_NULL() wrapper around free(ptr); ptr = NULLÆvar Arnfjörð Bjarmason, Jun 15, 2017
  5. 4/6 coccinelle: add a rule to make "expression" code use FREE_AND_NULL()Ævar Arnfjörð Bjarmason, Jun 15, 2017
  6. Junio C HamanoJun 16, 2017
  7. René ScharfeJun 25, 2017
  8. Ævar Arnfjörð BjarmasonJun 28, 2017
  9. Junio C HamanoJun 28, 2017
  10. Ævar Arnfjörð BjarmasonJun 28, 2017
  11. René ScharfeJun 28, 2017
  12. Ævar Arnfjörð BjarmasonJun 28, 2017
  13. Junio C HamanoJun 28, 2017
  14. René ScharfeJun 28, 2017
  15. Ævar Arnfjörð BjarmasonJun 28, 2017
  16. René ScharfeJun 28, 2017
  17. 5/6 coccinelle: make use of the "expression" FREE_AND_NULL() ruleÆvar Arnfjörð Bjarmason, Jun 15, 2017
  18. 3/6 coccinelle: make use of the "type" FREE_AND_NULL() ruleÆvar Arnfjörð Bjarmason, Jun 15, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.