diff mbox series

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

Message ID 20240829200953.GB432235@coredump.intra.peff.net (mailing list archive)
State Accepted
Commit 516a9ec3d5874aad41757e573f7b841bb45cb098
Headers show
Series clean up some MAYBE_UNUSED cases | expand

Commit Message

Jeff King Aug. 29, 2024, 8:09 p.m. UTC
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(-)

Comments

Eric Sunshine Aug. 29, 2024, 8:27 p.m. UTC | #1
On Thu, Aug 29, 2024 at 4:10 PM Jeff King <peff@peff.net> wrote:
> We prove custom malloc/free callbacks for the pcre library to use. Those

s/prove/provide/

> 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>
Patrick Steinhardt Aug. 30, 2024, 6:39 a.m. UTC | #2
On Thu, Aug 29, 2024 at 04:09:53PM -0400, Jeff King wrote:
> 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.

I don't care about the order, but if we settle on one I think we should
also document this accordingly in our code style guide.

In any case, the patch series looks obviously good, except for the one
typo that Eric already pointed out.

Thanks!

Patrick
Junio C Hamano Aug. 30, 2024, 4:30 p.m. UTC | #3
Patrick Steinhardt <ps@pks.im> writes:

> On Thu, Aug 29, 2024 at 04:09:53PM -0400, Jeff King wrote:
>> 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.
>
> I don't care about the order, but if we settle on one I think we should
> also document this accordingly in our code style guide.

Very true.  I think Peff's [PATCH 7/6] was sufficient by ending the
new instruction with

	... like "int foo UNUSED".

when it talked about the -Werror=unused-parameter.

Thanks.
diff mbox series

Patch

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;