From 9bd7b0b305f9075ed2fc491edec73a2a6dfa15e5 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 8 Sep 2021 16:13:01 +0100 Subject: [PATCH] util/ralloc: add HEADER_ALIGN macro Signed-off-by: Rhys Perry Reviewed-by: Jason Ekstrand Reviewed-by: Emma Anholt Part-of: --- src/util/ralloc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 3574065..0d57a60 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -36,6 +36,12 @@ #define CANARY 0x5A1106 +#if defined(__LP64__) || defined(_WIN64) +#define HEADER_ALIGN alignas(16) +#else +#define HEADER_ALIGN alignas(8) +#endif + /* Align the header's size so that ralloc() allocations will return with the * same alignment as a libc malloc would have (8 on 32-bit GLIBC, 16 on * 64-bit), avoiding performance penalities on x86 and alignment faults on @@ -43,11 +49,7 @@ */ struct ralloc_header { -#if defined(__LP64__) || defined(_WIN64) - alignas(16) -#else - alignas(8) -#endif + HEADER_ALIGN #ifndef NDEBUG /* A canary value used to determine whether a pointer is ralloc'd. */ @@ -550,12 +552,7 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, struct linear_header { - /* align first member to align struct */ -#if defined(__LP64__) || defined(_WIN64) - alignas(16) -#else - alignas(8) -#endif + HEADER_ALIGN #ifndef NDEBUG unsigned magic; /* for debugging */ -- 2.7.4