Skip to content

Commit d38683d

Browse files
pks-tgitster
authored andcommitted
reftable/system: provide REFTABLE_INLINE() macro
Not every compiler knows about the `inline` annotation for functions. Consequently, Git knows to define `inline` as an empty macro in case it's not available. In the reftable library though we cannot assume the macro to be available as it is usable as a standalone library. Fix this by introducing a `REFTABLE_INLINE()` macro via "reftable/system.h" that allows the project to use their own definition. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 270e10a commit d38683d

4 files changed

Lines changed: 16 additions & 14 deletions

File tree

reftable/basics.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,22 @@ char *reftable_buf_detach(struct reftable_buf *buf);
7575

7676
/* Bigendian en/decoding of integers */
7777

78-
static inline void reftable_put_be16(void *out, uint16_t i)
78+
REFTABLE_INLINE(void) reftable_put_be16(void *out, uint16_t i)
7979
{
8080
unsigned char *p = out;
8181
p[0] = (uint8_t)((i >> 8) & 0xff);
8282
p[1] = (uint8_t)((i >> 0) & 0xff);
8383
}
8484

85-
static inline void reftable_put_be24(void *out, uint32_t i)
85+
REFTABLE_INLINE(void) reftable_put_be24(void *out, uint32_t i)
8686
{
8787
unsigned char *p = out;
8888
p[0] = (uint8_t)((i >> 16) & 0xff);
8989
p[1] = (uint8_t)((i >> 8) & 0xff);
9090
p[2] = (uint8_t)((i >> 0) & 0xff);
9191
}
9292

93-
static inline void reftable_put_be32(void *out, uint32_t i)
93+
REFTABLE_INLINE(void) reftable_put_be32(void *out, uint32_t i)
9494
{
9595
unsigned char *p = out;
9696
p[0] = (uint8_t)((i >> 24) & 0xff);
@@ -99,7 +99,7 @@ static inline void reftable_put_be32(void *out, uint32_t i)
9999
p[3] = (uint8_t)((i >> 0) & 0xff);
100100
}
101101

102-
static inline void reftable_put_be64(void *out, uint64_t i)
102+
REFTABLE_INLINE(void) reftable_put_be64(void *out, uint64_t i)
103103
{
104104
unsigned char *p = out;
105105
p[0] = (uint8_t)((i >> 56) & 0xff);
@@ -112,22 +112,22 @@ static inline void reftable_put_be64(void *out, uint64_t i)
112112
p[7] = (uint8_t)((i >> 0) & 0xff);
113113
}
114114

115-
static inline uint16_t reftable_get_be16(const void *in)
115+
REFTABLE_INLINE(uint16_t) reftable_get_be16(const void *in)
116116
{
117117
const unsigned char *p = in;
118118
return (uint16_t)(p[0]) << 8 |
119119
(uint16_t)(p[1]) << 0;
120120
}
121121

122-
static inline uint32_t reftable_get_be24(const void *in)
122+
REFTABLE_INLINE(uint32_t) reftable_get_be24(const void *in)
123123
{
124124
const unsigned char *p = in;
125125
return (uint32_t)(p[0]) << 16 |
126126
(uint32_t)(p[1]) << 8 |
127127
(uint32_t)(p[2]) << 0;
128128
}
129129

130-
static inline uint32_t reftable_get_be32(const void *in)
130+
REFTABLE_INLINE(uint32_t) reftable_get_be32(const void *in)
131131
{
132132
const unsigned char *p = in;
133133
return (uint32_t)(p[0]) << 24 |
@@ -136,7 +136,7 @@ static inline uint32_t reftable_get_be32(const void *in)
136136
(uint32_t)(p[3]) << 0;
137137
}
138138

139-
static inline uint64_t reftable_get_be64(const void *in)
139+
REFTABLE_INLINE(uint64_t) reftable_get_be64(const void *in)
140140
{
141141
const unsigned char *p = in;
142142
return (uint64_t)(p[0]) << 56 |
@@ -187,7 +187,7 @@ void reftable_free(void *p);
187187
void *reftable_calloc(size_t nelem, size_t elsize);
188188
char *reftable_strdup(const char *str);
189189

190-
static inline int reftable_alloc_size(size_t nelem, size_t elsize, size_t *out)
190+
REFTABLE_INLINE(int) reftable_alloc_size(size_t nelem, size_t elsize, size_t *out)
191191
{
192192
if (nelem && elsize > SIZE_MAX / nelem)
193193
return -1;
@@ -215,7 +215,7 @@ static inline int reftable_alloc_size(size_t nelem, size_t elsize, size_t *out)
215215
} \
216216
} while (0)
217217

218-
static inline void *reftable_alloc_grow(void *p, size_t nelem, size_t elsize,
218+
REFTABLE_INLINE(void) *reftable_alloc_grow(void *p, size_t nelem, size_t elsize,
219219
size_t *allocp)
220220
{
221221
void *new_p;

reftable/pq.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ int merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry
2727
void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);
2828
int pq_less(struct pq_entry *a, struct pq_entry *b);
2929

30-
static inline struct pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq)
30+
REFTABLE_INLINE(struct) pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq)
3131
{
3232
return pq.heap[0];
3333
}
3434

35-
static inline int merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq)
35+
REFTABLE_INLINE(int) merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq)
3636
{
3737
return pq.len == 0;
3838
}

reftable/record.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct string_view {
2626
};
2727

2828
/* Advance `s.buf` by `n`, and decrease length. */
29-
static inline void string_view_consume(struct string_view *s, int n)
29+
REFTABLE_INLINE(void) string_view_consume(struct string_view *s, int n)
3030
{
3131
s->buf += n;
3232
s->len -= n;
@@ -147,7 +147,7 @@ int reftable_record_decode(struct reftable_record *rec, struct reftable_buf key,
147147
uint32_t hash_size, struct reftable_buf *scratch);
148148
int reftable_record_is_deletion(struct reftable_record *rec);
149149

150-
static inline uint8_t reftable_record_type(struct reftable_record *rec)
150+
REFTABLE_INLINE(uint8_t) reftable_record_type(struct reftable_record *rec)
151151
{
152152
return rec->type;
153153
}

reftable/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "compat/posix.h"
1616
#include "compat/zlib-compat.h"
1717

18+
#define REFTABLE_INLINE(type) static inline type
19+
1820
/*
1921
* Return a random 32 bit integer. This function is expected to return
2022
* pre-seeded data.

0 commit comments

Comments
 (0)