diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-10-29 14:37:19 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-11-02 11:25:10 -0400 |
commit | c90d4af8750bef77ce9abe91df80d5d98ba297d7 (patch) | |
tree | 2e3213be7021b2be425954e33b34ea228f0d9f85 /tests/alloc.c | |
parent | b00341a45238d383fa27289a53798eef856092bb (diff) | |
download | bfs-c90d4af8750bef77ce9abe91df80d5d98ba297d7.tar.xz |
alloc: Don't require size % align == 0
Allowing unaligned sizes will allow us to allocate aligned slabs with
additional metadata in the tail without ballooning the allocation size
for large alignments.
Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2244.htm#dr_460
Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2072.htm
Diffstat (limited to 'tests/alloc.c')
-rw-r--r-- | tests/alloc.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/alloc.c b/tests/alloc.c index f91b428..046613a 100644 --- a/tests/alloc.c +++ b/tests/alloc.c @@ -11,6 +11,14 @@ #include <stdint.h> void check_alloc(void) { + // Check aligned allocation + void *ptr; + bfs_everify((ptr = zalloc(64, 129))); + bfs_check((uintptr_t)ptr % 64 == 0); + bfs_echeck((ptr = xrealloc(ptr, 64, 129, 65))); + bfs_check((uintptr_t)ptr % 64 == 0); + free(ptr); + // Check sizeof_flex() struct flexible { alignas(64) int foo[8]; |