git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 2 of 28 in “reftable: some more portability improvements”
  1. 0/6 reftable: some more portability improvementsPatrick Steinhardt, Mar 31, 2026
  2. 1/6 reftable/system: provide `REFTABLE_INLINE()` macroPatrick Steinhardt, Mar 31, 2026
  3. Junio C HamanoMar 31, 2026
  4. René ScharfeMar 31, 2026
  5. Junio C HamanoMar 31, 2026
  6. René ScharfeMar 31, 2026
  7. brian m. carlsonMar 31, 2026
  8. Patrick SteinhardtApr 1, 2026
  9. 2/6 reftable/stack: don't call fsync(3p) unless providedPatrick Steinhardt, Mar 31, 2026
  10. Junio C HamanoMar 31, 2026
  11. Patrick SteinhardtApr 1, 2026
  12. 3/6 reftable/fsck: use REFTABLE_UNUSED instead of UNUSEDPatrick Steinhardt, Mar 31, 2026
  13. Junio C HamanoMar 31, 2026
  14. 4/6 reftable/system: add abstraction to retrieve time in millisecondsPatrick Steinhardt, Mar 31, 2026
  15. 5/6 reftable/system: add abstraction to mmap filesPatrick Steinhardt, Mar 31, 2026
  16. 6/6 reftable: introduce "reftable-system.h" headerPatrick Steinhardt, Mar 31, 2026
  17. Junio C HamanoMar 31, 2026
  18. Patrick SteinhardtApr 1, 2026
  19. Junio C HamanoApr 1, 2026
  20. Patrick SteinhardtApr 2, 2026
  21. 0/5 reftable: some more portability improvementsPatrick Steinhardt, Apr 2, 2026
  22. 1/5 reftable: introduce "reftable-system.h" headerPatrick Steinhardt, Apr 2, 2026
  23. 2/5 reftable/stack: provide fsync(3p) via system headerPatrick Steinhardt, Apr 2, 2026
  24. Junio C HamanoApr 2, 2026
  25. 3/5 reftable/fsck: use REFTABLE_UNUSED instead of UNUSEDPatrick Steinhardt, Apr 2, 2026
  26. 4/5 reftable/system: add abstraction to retrieve time in millisecondsPatrick Steinhardt, Apr 2, 2026
  27. Junio C HamanoApr 2, 2026
  28. 5/5 reftable/system: add abstraction to mmap filesPatrick Steinhardt, Apr 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.