util/ralloc: add HEADER_ALIGN macro
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 8 Sep 2021 15:13:01 +0000 (16:13 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 30 Aug 2022 18:21:44 +0000 (18:21 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12910>

src/util/ralloc.c

index 3574065..0d57a60 100644 (file)
 
 #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
  */
 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 */