diff options
| author | Patrick Steinhardt <ps@pks.im> | 2025-02-18 10:20:49 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-02-18 10:55:38 -0800 |
| commit | f8ed12dec459df9ea0d43ccacc93cb2c32702c0e (patch) | |
| tree | ec137e7fe9e2b59db153b0498fd264186db16ba6 /reftable/basics.h | |
| parent | reftable/stack: stop using `sleep_millisec()` (diff) | |
| download | git-f8ed12dec459df9ea0d43ccacc93cb2c32702c0e.tar.gz git-f8ed12dec459df9ea0d43ccacc93cb2c32702c0e.zip | |
reftable/basics: stop using `SWAP()` macro
Stop using `SWAP()` macro in favor of an open-coded variant of it. Note
that this also requires us to open-code the build assert that `SWAP()`
itself uses to verify that the size of both variables matches.
This is done to reduce our dependency on the Git codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/basics.h')
| -rw-r--r-- | reftable/basics.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/reftable/basics.h b/reftable/basics.h index c1ddbaec3f..59000798f0 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -266,6 +266,15 @@ static inline void *reftable_alloc_grow(void *p, size_t nelem, size_t elsize, # define strdup(str) REFTABLE_BANNED(strdup) #endif +#define REFTABLE_SWAP(a, b) do { \ + void *_swap_a_ptr = &(a); \ + void *_swap_b_ptr = &(b); \ + unsigned char _swap_buffer[sizeof(a) - 2 * sizeof(a) * (sizeof(a) != sizeof(b))]; \ + memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \ + memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a)); \ + memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \ +} while (0) + /* Find the longest shared prefix size of `a` and `b` */ size_t common_prefix_size(struct reftable_buf *a, struct reftable_buf *b); |
