reftable/basics: introduce `REFTABLE_UNUSED` annotation

Introduce the `REFTABLE_UNUSED` annotation and replace all existing users of `UNUSED` in the reftable library to use the new macro instead. Note that we unconditionally define `MAYBE_UNUSED` in the exact same way, so doing so unconditionally for `REFTABLE_UNUSED` should be fine, too. Suggested-by: Toon Claes <toon@iotcl.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 18, 2025 at 10:20 UTC f93b2a04243ee1a95920ae02a9423accbe1c3719
5 files changed +24 -22
reftable/basics.h
+2
@@ -16,6 +16,8 @@ https://developers.google.com/open-source/licenses/bsd
16 #include "system.h"
17 #include "reftable-basics.h"
18
19 +#define REFTABLE_UNUSED __attribute__((__unused__))
20 +
21 struct reftable_buf {
22 size_t alloc;
23 size_t len;
reftable/blocksource.c
+3 -3
@@ -13,14 +13,14 @@ https://developers.google.com/open-source/licenses/bsd
13 #include "reftable-blocksource.h"
14 #include "reftable-error.h"
15
16 -static void reftable_buf_return_block(void *b UNUSED, struct reftable_block *dest)
16 +static void reftable_buf_return_block(void *b REFTABLE_UNUSED, struct reftable_block *dest)
17 {
18 if (dest->len)
19 memset(dest->data, 0xff, dest->len);
20 reftable_free(dest->data);
21 }
22
23 -static void reftable_buf_close(void *b UNUSED)
23 +static void reftable_buf_close(void *b REFTABLE_UNUSED)
24 {
25 }
26
@@ -67,7 +67,7 @@ static uint64_t file_size(void *b)
67 return ((struct file_block_source *)b)->size;
68 }
69
70 -static void file_return_block(void *b UNUSED, struct reftable_block *dest UNUSED)
70 +static void file_return_block(void *b REFTABLE_UNUSED, struct reftable_block *dest REFTABLE_UNUSED)
71 {
72 }
73
reftable/iter.c
+5 -5
@@ -25,17 +25,17 @@ int iterator_next(struct reftable_iterator *it, struct reftable_record *rec)
25 return it->ops->next(it->iter_arg, rec);
26 }
27
28 -static int empty_iterator_seek(void *arg UNUSED, struct reftable_record *want UNUSED)
28 +static int empty_iterator_seek(void *arg REFTABLE_UNUSED, struct reftable_record *want REFTABLE_UNUSED)
29 {
30 return 0;
31 }
32
33 -static int empty_iterator_next(void *arg UNUSED, struct reftable_record *rec UNUSED)
33 +static int empty_iterator_next(void *arg REFTABLE_UNUSED, struct reftable_record *rec REFTABLE_UNUSED)
34 {
35 return 1;
36 }
37
38 -static void empty_iterator_close(void *arg UNUSED)
38 +static void empty_iterator_close(void *arg REFTABLE_UNUSED)
39 {
40 }
41
@@ -143,8 +143,8 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
143 return 0;
144 }
145
146 -static int indexed_table_ref_iter_seek(void *p UNUSED,
147 - struct reftable_record *want UNUSED)
146 +static int indexed_table_ref_iter_seek(void *p REFTABLE_UNUSED,
147 + struct reftable_record *want REFTABLE_UNUSED)
148 {
149 return REFTABLE_API_ERROR;
150 }
reftable/record.c
+13 -13
@@ -490,7 +490,7 @@ static void reftable_obj_record_release(void *rec)
490 }
491
492 static int reftable_obj_record_copy_from(void *rec, const void *src_rec,
493 - uint32_t hash_size UNUSED)
493 + uint32_t hash_size REFTABLE_UNUSED)
494 {
495 struct reftable_obj_record *obj = rec;
496 const struct reftable_obj_record *src = src_rec;
@@ -528,7 +528,7 @@ static uint8_t reftable_obj_record_val_type(const void *rec)
528 }
529
530 static int reftable_obj_record_encode(const void *rec, struct string_view s,
531 - uint32_t hash_size UNUSED)
531 + uint32_t hash_size REFTABLE_UNUSED)
532 {
533 const struct reftable_obj_record *r = rec;
534 struct string_view start = s;
@@ -563,8 +563,8 @@ static int reftable_obj_record_encode(const void *rec, struct string_view s,
563
564 static int reftable_obj_record_decode(void *rec, struct reftable_buf key,
565 uint8_t val_type, struct string_view in,
566 - uint32_t hash_size UNUSED,
567 - struct reftable_buf *scratch UNUSED)
566 + uint32_t hash_size REFTABLE_UNUSED,
567 + struct reftable_buf *scratch REFTABLE_UNUSED)
568 {
569 struct string_view start = in;
570 struct reftable_obj_record *r = rec;
@@ -618,13 +618,13 @@ static int reftable_obj_record_decode(void *rec, struct reftable_buf key,
618 return start.len - in.len;
619 }
620
621 -static int not_a_deletion(const void *p UNUSED)
621 +static int not_a_deletion(const void *p REFTABLE_UNUSED)
622 {
623 return 0;
624 }
625
626 static int reftable_obj_record_equal_void(const void *a, const void *b,
627 - uint32_t hash_size UNUSED)
627 + uint32_t hash_size REFTABLE_UNUSED)
628 {
629 struct reftable_obj_record *ra = (struct reftable_obj_record *) a;
630 struct reftable_obj_record *rb = (struct reftable_obj_record *) b;
@@ -1054,7 +1054,7 @@ static int reftable_index_record_key(const void *r, struct reftable_buf *dest)
1054 }
1055
1056 static int reftable_index_record_copy_from(void *rec, const void *src_rec,
1057 - uint32_t hash_size UNUSED)
1057 + uint32_t hash_size REFTABLE_UNUSED)
1058 {
1059 struct reftable_index_record *dst = rec;
1060 const struct reftable_index_record *src = src_rec;
@@ -1075,13 +1075,13 @@ static void reftable_index_record_release(void *rec)
1075 reftable_buf_release(&idx->last_key);
1076 }
1077
1078 -static uint8_t reftable_index_record_val_type(const void *rec UNUSED)
1078 +static uint8_t reftable_index_record_val_type(const void *rec REFTABLE_UNUSED)
1079 {
1080 return 0;
1081 }
1082
1083 static int reftable_index_record_encode(const void *rec, struct string_view out,
1084 - uint32_t hash_size UNUSED)
1084 + uint32_t hash_size REFTABLE_UNUSED)
1085 {
1086 const struct reftable_index_record *r =
1087 (const struct reftable_index_record *)rec;
@@ -1097,10 +1097,10 @@ static int reftable_index_record_encode(const void *rec, struct string_view out,
1097 }
1098
1099 static int reftable_index_record_decode(void *rec, struct reftable_buf key,
1100 - uint8_t val_type UNUSED,
1100 + uint8_t val_type REFTABLE_UNUSED,
1101 struct string_view in,
1102 - uint32_t hash_size UNUSED,
1103 - struct reftable_buf *scratch UNUSED)
1102 + uint32_t hash_size REFTABLE_UNUSED,
1103 + struct reftable_buf *scratch REFTABLE_UNUSED)
1104 {
1105 struct string_view start = in;
1106 struct reftable_index_record *r = rec;
@@ -1120,7 +1120,7 @@ static int reftable_index_record_decode(void *rec, struct reftable_buf key,
1120 }
1121
1122 static int reftable_index_record_equal(const void *a, const void *b,
1123 - uint32_t hash_size UNUSED)
1123 + uint32_t hash_size REFTABLE_UNUSED)
1124 {
1125 struct reftable_index_record *ia = (struct reftable_index_record *) a;
1126 struct reftable_index_record *ib = (struct reftable_index_record *) b;
reftable/writer.c
+1 -1
@@ -649,7 +649,7 @@ static void write_object_record(void *void_arg, void *key)
649 done:;
650 }
651
652 -static void object_record_free(void *void_arg UNUSED, void *key)
652 +static void object_record_free(void *void_arg REFTABLE_UNUSED, void *key)
653 {
654 struct obj_index_tree_node *entry = key;
655