diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-10-16 08:19:47 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-10-16 08:19:47 +0200 |
commit | f3178067bb6963aa913dfd9a024e960729056760 (patch) | |
tree | bb2d0ca04035cb497748ba17364a10c48788f844 | |
parent | 1781e5937a6e200e3627d482bee6ccb919444568 (diff) |
Take a pointer to a pointer
-rw-r--r-- | include/array.h | 16 | ||||
-rw-r--r-- | test/_brk-test.h | 4 | ||||
-rw-r--r-- | test/_norm-test.h | 4 | ||||
-rw-r--r-- | test/array-test.c | 2 | ||||
-rw-r--r-- | test/wbrk-human-test.c | 4 |
5 files changed, 15 insertions, 15 deletions
diff --git a/include/array.h b/include/array.h index 0853c2d..ba7fa8d 100644 --- a/include/array.h +++ b/include/array.h @@ -34,22 +34,22 @@ _mlib_array_hdr(void *p, ptrdiff_t align) #define array_push(p, x) \ do { \ - _mlib_arr_hdr_t *hdr = _mlib_array_hdr((p), alignof(typeof(*(p)))); \ + _mlib_arr_hdr_t *hdr = _mlib_array_hdr(*(p), alignof(typeof(**(p)))); \ if (hdr->len == hdr->cap) { \ - (p) = array_resz((p), hdr->len * 2); \ - hdr = _mlib_array_hdr((p), alignof(typeof(*(p)))); \ + *(p) = array_resz(*(p), hdr->len * 2); \ + hdr = _mlib_array_hdr(*(p), alignof(typeof(**(p)))); \ } \ - (p)[hdr->len++] = (x); \ + (*(p))[hdr->len++] = (x); \ } while (false) #define array_extend(p, xs, n) \ do { \ - _mlib_arr_hdr_t *hdr = _mlib_array_hdr((p), alignof(typeof(*(p)))); \ + _mlib_arr_hdr_t *hdr = _mlib_array_hdr(*(p), alignof(typeof(**(p)))); \ if (hdr->len + (n) >= hdr->cap) { \ - (p) = array_resz((p), stdc_bit_ceil((size_t)hdr->len + (n))); \ - hdr = _mlib_array_hdr((p), alignof(typeof(*(p)))); \ + *(p) = array_resz(*(p), stdc_bit_ceil((size_t)hdr->len + (n))); \ + hdr = _mlib_array_hdr(*(p), alignof(typeof(**(p)))); \ } \ - memcpy(&(p)[hdr->len], (xs), (n) * sizeof(*xs)); \ + memcpy(&(*(p))[hdr->len], (xs), (n) * sizeof(*xs)); \ hdr->len += (n); \ } while (false) diff --git a/test/_brk-test.h b/test/_brk-test.h index 6e0c502..572697a 100644 --- a/test/_brk-test.h +++ b/test/_brk-test.h @@ -73,8 +73,8 @@ test(u8view_t sv, int id) total += w; if (op == U'÷') - array_push(items, array_new(mem, char8_t, 64)); - array_extend(items[array_len(items) - 1], buf, w); + array_push(&items, array_new(mem, char8_t, 64)); + array_extend(&items[array_len(items) - 1], buf, w); } size_t off = 0; diff --git a/test/_norm-test.h b/test/_norm-test.h index 4083e1a..ef51aa9 100644 --- a/test/_norm-test.h +++ b/test/_norm-test.h @@ -70,10 +70,10 @@ test(u8view_t sv, int id) sscanf(cp.p, "%" SCNxRUNE, &ch); char8_t buf[U8_LEN_MAX]; int w = rtoucs(buf, sizeof(buf), ch); - array_extend(s, buf, w); + array_extend(&s, buf, w); } while (_ != MBEND); - array_push(columns, ((u8view_t){s, array_len(s)})); + array_push(&columns, ((u8view_t){s, array_len(s)})); } for (size_t i = 0; i < 5; i++) { diff --git a/test/array-test.c b/test/array-test.c index 307dd9a..3eb955a 100644 --- a/test/array-test.c +++ b/test/array-test.c @@ -37,7 +37,7 @@ main(int, char **argv) array_hdr(xs)->len = 4; for (int i = 4; i < 69; i++) { - array_push(xs, i + 1); + array_push(&xs, i + 1); if (stdc_count_ones((unsigned)i) == 1) { /* Integers don’t need padding. It simplifies the test */ if ((size_t)ctx.last_alloc_size diff --git a/test/wbrk-human-test.c b/test/wbrk-human-test.c index 4536afa..45dcaef 100644 --- a/test/wbrk-human-test.c +++ b/test/wbrk-human-test.c @@ -56,9 +56,9 @@ test(u8view_t sv, int id) u8view_t *ws = array_new(mem, typeof(*ws), 64); while (ucscut(&w, &sv, U"|", 1) != MBEND) - array_push(ws, w); + array_push(&ws, w); if (w.len > 0) - array_push(ws, w); + array_push(&ws, w); /* Assert the word count is correct */ size_t n; |