[PATCH 1/6] reftable/system: provide `REFTABLE_INLINE()` macro
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Mar 31, 2026, 11:26 UTC
- Message-ID
- <20260331-pks-reftable-portability-fixes-v1-1-46bfae55c68c@pks.im>
- In-Reply-To
- <20260331-pks-reftable-portability-fixes-v1-0-46bfae55c68c@pks.im>
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> --- reftable/basics.h | 20 ++++++++++---------- reftable/pq.h | 4 ++-- reftable/record.h | 4 ++-- reftable/system.h | 2 ++ 4 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/reftable/basics.h b/reftable/basics.h index e4b83b2b03..ebbcec2ac3 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -75,14 +75,14 @@ char *reftable_buf_detach(struct reftable_buf *buf); /* Bigendian en/decoding of integers */ -static inline void reftable_put_be16(void *out, uint16_t i) +REFTABLE_INLINE(void) reftable_put_be16(void *out, uint16_t i) { unsigned char *p = out; p[0] = (uint8_t)((i >> 8) & 0xff); p[1] = (uint8_t)((i >> 0) & 0xff); } -static inline void reftable_put_be24(void *out, uint32_t i) +REFTABLE_INLINE(void) reftable_put_be24(void *out, uint32_t i) { unsigned char *p = out; p[0] = (uint8_t)((i >> 16) & 0xff); @@ -90,7 +90,7 @@ static inline void reftable_put_be24(void *out, uint32_t i) p[2] = (uint8_t)((i >> 0) & 0xff); } -static inline void reftable_put_be32(void *out, uint32_t i) +REFTABLE_INLINE(void) reftable_put_be32(void *out, uint32_t i) { unsigned char *p = out; p[0] = (uint8_t)((i >> 24) & 0xff); @@ -99,7 +99,7 @@ static inline void reftable_put_be32(void *out, uint32_t i) p[3] = (uint8_t)((i >> 0) & 0xff); } -static inline void reftable_put_be64(void *out, uint64_t i) +REFTABLE_INLINE(void) reftable_put_be64(void *out, uint64_t i) { unsigned char *p = out; p[0] = (uint8_t)((i >> 56) & 0xff); @@ -112,14 +112,14 @@ static inline void reftable_put_be64(void *out, uint64_t i) p[7] = (uint8_t)((i >> 0) & 0xff); } -static inline uint16_t reftable_get_be16(const void *in) +REFTABLE_INLINE(uint16_t) reftable_get_be16(const void *in) { const unsigned char *p = in; return (uint16_t)(p[0]) << 8 | (uint16_t)(p[1]) << 0; } -static inline uint32_t reftable_get_be24(const void *in) +REFTABLE_INLINE(uint32_t) reftable_get_be24(const void *in) { const unsigned char *p = in; return (uint32_t)(p[0]) << 16 | @@ -127,7 +127,7 @@ static inline uint32_t reftable_get_be24(const void *in) (uint32_t)(p[2]) << 0; } -static inline uint32_t reftable_get_be32(const void *in) +REFTABLE_INLINE(uint32_t) reftable_get_be32(const void *in) { const unsigned char *p = in; return (uint32_t)(p[0]) << 24 | @@ -136,7 +136,7 @@ static inline uint32_t reftable_get_be32(const void *in) (uint32_t)(p[3]) << 0; } -static inline uint64_t reftable_get_be64(const void *in) +REFTABLE_INLINE(uint64_t) reftable_get_be64(const void *in) { const unsigned char *p = in; return (uint64_t)(p[0]) << 56 | @@ -187,7 +187,7 @@ void reftable_free(void *p); void *reftable_calloc(size_t nelem, size_t elsize); char *reftable_strdup(const char *str); -static inline int reftable_alloc_size(size_t nelem, size_t elsize, size_t *out) +REFTABLE_INLINE(int) reftable_alloc_size(size_t nelem, size_t elsize, size_t *out) { if (nelem && elsize > SIZE_MAX / nelem) return -1; @@ -215,7 +215,7 @@ static inline int reftable_alloc_size(size_t nelem, size_t elsize, size_t *out) } \ } while (0) -static inline void *reftable_alloc_grow(void *p, size_t nelem, size_t elsize, +REFTABLE_INLINE(void) *reftable_alloc_grow(void *p, size_t nelem, size_t elsize, size_t *allocp) { void *new_p; diff --git a/reftable/pq.h b/reftable/pq.h index 42310670b0..9210ede273 100644 --- a/reftable/pq.h +++ b/reftable/pq.h @@ -27,12 +27,12 @@ int merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry void merged_iter_pqueue_release(struct merged_iter_pqueue *pq); int pq_less(struct pq_entry *a, struct pq_entry *b); -static inline struct pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq) +REFTABLE_INLINE(struct) pq_entry merged_iter_pqueue_top(struct merged_iter_pqueue pq) { return pq.heap[0]; } -static inline int merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq) +REFTABLE_INLINE(int) merged_iter_pqueue_is_empty(struct merged_iter_pqueue pq) { return pq.len == 0; } diff --git a/reftable/record.h b/reftable/record.h index 7953f352a3..20c9091371 100644 --- a/reftable/record.h +++ b/reftable/record.h @@ -26,7 +26,7 @@ struct string_view { }; /* Advance `s.buf` by `n`, and decrease length. */ -static inline void string_view_consume(struct string_view *s, int n) +REFTABLE_INLINE(void) string_view_consume(struct string_view *s, int n) { s->buf += n; s->len -= n; @@ -147,7 +147,7 @@ int reftable_record_decode(struct reftable_record *rec, struct reftable_buf key, uint32_t hash_size, struct reftable_buf *scratch); int reftable_record_is_deletion(struct reftable_record *rec); -static inline uint8_t reftable_record_type(struct reftable_record *rec) +REFTABLE_INLINE(uint8_t) reftable_record_type(struct reftable_record *rec) { return rec->type; } diff --git a/reftable/system.h b/reftable/system.h index c54ed4cad6..b15768dbdb 100644 --- a/reftable/system.h +++ b/reftable/system.h @@ -15,6 +15,8 @@ #include "compat/posix.h" #include "compat/zlib-compat.h" +#define REFTABLE_INLINE(type) static inline type + /* * Return a random 32 bit integer. This function is expected to return * pre-seeded data.
-- 2.53.0.1185.g05d4b7b318.dirty