Skip to content

Commit 7c1b3c0

Browse files
pks-tgitster
authored andcommitted
reftable/basics: stop using UNUSED annotation
Stop using the `UNUSED` annotation and replace it with a new `REFTABLE_UNUSED` macro. The latter is a weaker guarantee compared to `UNUSED` as it only suppresses unused parameters without generating a warning in case a parameter marked as unused is in fact used. But it's good enough, and by relaxing the behaviour a bit we avoid having to wire up compiler-specific logic. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6350077 commit 7c1b3c0

File tree

5 files changed

+61
-23
lines changed

5 files changed

+61
-23
lines changed

reftable/basics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ license that can be found in the LICENSE file or at
1616
#include "system.h"
1717
#include "reftable-basics.h"
1818

19+
#define REFTABLE_UNUSED(x) (void)(x)
20+
1921
struct reftable_buf {
2022
size_t alloc;
2123
size_t len;

reftable/blocksource.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ license that can be found in the LICENSE file or at
1313
#include "reftable-blocksource.h"
1414
#include "reftable-error.h"
1515

16-
static void reftable_buf_return_block(void *b UNUSED, struct reftable_block *dest)
16+
static void reftable_buf_return_block(void *b, struct reftable_block *dest)
1717
{
18+
REFTABLE_UNUSED(b);
1819
if (dest->len)
1920
memset(dest->data, 0xff, dest->len);
2021
reftable_free(dest->data);
2122
}
2223

23-
static void reftable_buf_close(void *b UNUSED)
24+
static void reftable_buf_close(void *b)
2425
{
26+
REFTABLE_UNUSED(b);
2527
}
2628

2729
static ssize_t reftable_buf_read_block(void *v, struct reftable_block *dest,
@@ -67,8 +69,10 @@ static uint64_t file_size(void *b)
6769
return ((struct file_block_source *)b)->size;
6870
}
6971

70-
static void file_return_block(void *b UNUSED, struct reftable_block *dest UNUSED)
72+
static void file_return_block(void *b, struct reftable_block *dest)
7173
{
74+
REFTABLE_UNUSED(b);
75+
REFTABLE_UNUSED(dest);
7276
}
7377

7478
static void file_close(void *v)

reftable/iter.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ int iterator_next(struct reftable_iterator *it, struct reftable_record *rec)
2525
return it->ops->next(it->iter_arg, rec);
2626
}
2727

28-
static int empty_iterator_seek(void *arg UNUSED, struct reftable_record *want UNUSED)
28+
static int empty_iterator_seek(void *arg, struct reftable_record *want)
2929
{
30+
REFTABLE_UNUSED(arg);
31+
REFTABLE_UNUSED(want);
3032
return 0;
3133
}
3234

33-
static int empty_iterator_next(void *arg UNUSED, struct reftable_record *rec UNUSED)
35+
static int empty_iterator_next(void *arg, struct reftable_record *rec)
3436
{
37+
REFTABLE_UNUSED(arg);
38+
REFTABLE_UNUSED(rec);
3539
return 1;
3640
}
3741

38-
static void empty_iterator_close(void *arg UNUSED)
42+
static void empty_iterator_close(void *arg)
3943
{
44+
REFTABLE_UNUSED(arg);
4045
}
4146

4247
static struct reftable_iterator_vtable empty_vtable = {
@@ -143,9 +148,11 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
143148
return 0;
144149
}
145150

146-
static int indexed_table_ref_iter_seek(void *p UNUSED,
147-
struct reftable_record *want UNUSED)
151+
static int indexed_table_ref_iter_seek(void *p,
152+
struct reftable_record *want)
148153
{
154+
REFTABLE_UNUSED(p);
155+
REFTABLE_UNUSED(want);
149156
return REFTABLE_API_ERROR;
150157
}
151158

reftable/record.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,13 @@ static void reftable_obj_record_release(void *rec)
490490
}
491491

492492
static int reftable_obj_record_copy_from(void *rec, const void *src_rec,
493-
uint32_t hash_size UNUSED)
493+
uint32_t hash_size)
494494
{
495495
struct reftable_obj_record *obj = rec;
496496
const struct reftable_obj_record *src = src_rec;
497497

498+
REFTABLE_UNUSED(hash_size);
499+
498500
reftable_obj_record_release(obj);
499501

500502
REFTABLE_ALLOC_ARRAY(obj->hash_prefix, src->hash_prefix_len);
@@ -523,13 +525,16 @@ static uint8_t reftable_obj_record_val_type(const void *rec)
523525
}
524526

525527
static int reftable_obj_record_encode(const void *rec, struct string_view s,
526-
uint32_t hash_size UNUSED)
528+
uint32_t hash_size)
527529
{
528530
const struct reftable_obj_record *r = rec;
529531
struct string_view start = s;
530532
int i = 0;
531533
int n = 0;
532534
uint64_t last = 0;
535+
536+
REFTABLE_UNUSED(hash_size);
537+
533538
if (r->offset_len == 0 || r->offset_len >= 8) {
534539
n = put_var_int(&s, r->offset_len);
535540
if (n < 0) {
@@ -558,15 +563,18 @@ static int reftable_obj_record_encode(const void *rec, struct string_view s,
558563

559564
static int reftable_obj_record_decode(void *rec, struct reftable_buf key,
560565
uint8_t val_type, struct string_view in,
561-
uint32_t hash_size UNUSED,
562-
struct reftable_buf *scratch UNUSED)
566+
uint32_t hash_size,
567+
struct reftable_buf *scratch)
563568
{
564569
struct string_view start = in;
565570
struct reftable_obj_record *r = rec;
566571
uint64_t count = val_type;
567572
int n = 0;
568573
uint64_t last;
569574

575+
REFTABLE_UNUSED(hash_size);
576+
REFTABLE_UNUSED(scratch);
577+
570578
reftable_obj_record_release(r);
571579

572580
REFTABLE_ALLOC_ARRAY(r->hash_prefix, key.len);
@@ -613,17 +621,20 @@ static int reftable_obj_record_decode(void *rec, struct reftable_buf key,
613621
return start.len - in.len;
614622
}
615623

616-
static int not_a_deletion(const void *p UNUSED)
624+
static int not_a_deletion(const void *p)
617625
{
626+
REFTABLE_UNUSED(p);
618627
return 0;
619628
}
620629

621630
static int reftable_obj_record_equal_void(const void *a, const void *b,
622-
uint32_t hash_size UNUSED)
631+
uint32_t hash_size)
623632
{
624633
struct reftable_obj_record *ra = (struct reftable_obj_record *) a;
625634
struct reftable_obj_record *rb = (struct reftable_obj_record *) b;
626635

636+
REFTABLE_UNUSED(hash_size);
637+
627638
if (ra->hash_prefix_len != rb->hash_prefix_len
628639
|| ra->offset_len != rb->offset_len)
629640
return 0;
@@ -1049,12 +1060,14 @@ static int reftable_index_record_key(const void *r, struct reftable_buf *dest)
10491060
}
10501061

10511062
static int reftable_index_record_copy_from(void *rec, const void *src_rec,
1052-
uint32_t hash_size UNUSED)
1063+
uint32_t hash_size)
10531064
{
10541065
struct reftable_index_record *dst = rec;
10551066
const struct reftable_index_record *src = src_rec;
10561067
int err;
10571068

1069+
REFTABLE_UNUSED(hash_size);
1070+
10581071
reftable_buf_reset(&dst->last_key);
10591072
err = reftable_buf_add(&dst->last_key, src->last_key.buf, src->last_key.len);
10601073
if (err < 0)
@@ -1070,19 +1083,23 @@ static void reftable_index_record_release(void *rec)
10701083
reftable_buf_release(&idx->last_key);
10711084
}
10721085

1073-
static uint8_t reftable_index_record_val_type(const void *rec UNUSED)
1086+
static uint8_t reftable_index_record_val_type(const void *rec)
10741087
{
1088+
REFTABLE_UNUSED(rec);
10751089
return 0;
10761090
}
10771091

10781092
static int reftable_index_record_encode(const void *rec, struct string_view out,
1079-
uint32_t hash_size UNUSED)
1093+
uint32_t hash_size)
10801094
{
10811095
const struct reftable_index_record *r =
10821096
(const struct reftable_index_record *)rec;
10831097
struct string_view start = out;
1098+
int n;
10841099

1085-
int n = put_var_int(&out, r->offset);
1100+
REFTABLE_UNUSED(hash_size);
1101+
1102+
n = put_var_int(&out, r->offset);
10861103
if (n < 0)
10871104
return n;
10881105

@@ -1092,15 +1109,19 @@ static int reftable_index_record_encode(const void *rec, struct string_view out,
10921109
}
10931110

10941111
static int reftable_index_record_decode(void *rec, struct reftable_buf key,
1095-
uint8_t val_type UNUSED,
1112+
uint8_t val_type,
10961113
struct string_view in,
1097-
uint32_t hash_size UNUSED,
1098-
struct reftable_buf *scratch UNUSED)
1114+
uint32_t hash_size,
1115+
struct reftable_buf *scratch)
10991116
{
11001117
struct string_view start = in;
11011118
struct reftable_index_record *r = rec;
11021119
int err, n = 0;
11031120

1121+
REFTABLE_UNUSED(val_type);
1122+
REFTABLE_UNUSED(hash_size);
1123+
REFTABLE_UNUSED(scratch);
1124+
11041125
reftable_buf_reset(&r->last_key);
11051126
err = reftable_buf_add(&r->last_key, key.buf, key.len);
11061127
if (err < 0)
@@ -1115,11 +1136,13 @@ static int reftable_index_record_decode(void *rec, struct reftable_buf key,
11151136
}
11161137

11171138
static int reftable_index_record_equal(const void *a, const void *b,
1118-
uint32_t hash_size UNUSED)
1139+
uint32_t hash_size)
11191140
{
11201141
struct reftable_index_record *ia = (struct reftable_index_record *) a;
11211142
struct reftable_index_record *ib = (struct reftable_index_record *) b;
11221143

1144+
REFTABLE_UNUSED(hash_size);
1145+
11231146
return ia->offset == ib->offset && !reftable_buf_cmp(&ia->last_key, &ib->last_key);
11241147
}
11251148

reftable/writer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,12 @@ static void write_object_record(void *void_arg, void *key)
636636
done:;
637637
}
638638

639-
static void object_record_free(void *void_arg UNUSED, void *key)
639+
static void object_record_free(void *void_arg, void *key)
640640
{
641641
struct obj_index_tree_node *entry = key;
642642

643+
REFTABLE_UNUSED(void_arg);
644+
643645
REFTABLE_FREE_AND_NULL(entry->offsets);
644646
reftable_buf_release(&entry->hash);
645647
reftable_free(entry);

0 commit comments

Comments
 (0)