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

[PATCH 2/2] grep: prefer UNUSED to MAYBE_UNUSED for pcre allocators

From
Jeff King <peff@peff.net>
Date
Aug 29, 2024, 20:09 UTC
Message-ID
<20240829200953.GB432235@coredump.intra.peff.net>
In-Reply-To
<20240829200807.GA430283@coredump.intra.peff.net>

We prove custom malloc/free callbacks for the pcre library to use. Those take an extra "data" parameter, but we don't use it. Back when these were added in 513f2b0bbd (grep: make PCRE2 aware of custom allocator, 2019-10-16), we only had MAYBE_UNUSED. But these days we have UNUSED, which we should prefer, as it will let the compiler inform us if the code changes to actually use the parameters.

I also moved the annotations to come after the variable name, which is how we typically spell it.

Signed-off-by: Jeff King <peff@peff.net>
---
Where "how we typically spell it" is "me", because I wrote 99% of the
annotations we have. ;) I'm open to debate, but only if it is
accompanied by a patch to change all of them to be consistent.
 grep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/grep.c b/grep.c
index 2f8b9553df..e5761426e4 100644
--- a/grep.c
+++ b/grep.c
@@ -245,7 +245,7 @@ static int is_fixed(const char *s, size_t len)
 #ifdef USE_LIBPCRE2
 #define GREP_PCRE2_DEBUG_MALLOC 0
 
-static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
+static void *pcre2_malloc(PCRE2_SIZE size, void *memory_data UNUSED)
 {
 	void *pointer = malloc(size);
 #if GREP_PCRE2_DEBUG_MALLOC
@@ -255,7 +255,7 @@ static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
 	return pointer;
 }
 
-static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
+static void pcre2_free(void *pointer, void *memory_data UNUSED)
 {
 #if GREP_PCRE2_DEBUG_MALLOC
 	static int count = 1;
-- 
2.46.0.761.g18aface1ae
Previous: Jeff KingNext: Eric Sunshine
Message 3 of 7 in “clean up some MAYBE_UNUSED cases”
  1. 0/2 clean up some MAYBE_UNUSED casesJeff King, Aug 29, 2024
  2. 1/2 gc: drop MAYBE_UNUSED annotation from used parameterJeff King, Aug 29, 2024
  3. 2/2 grep: prefer UNUSED to MAYBE_UNUSED for pcre allocatorsJeff King, Aug 29, 2024
  4. Eric SunshineAug 29, 2024
  5. Patrick SteinhardtAug 30, 2024
  6. Junio C HamanoAug 30, 2024
  7. Junio C HamanoAug 29, 2024

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.