From c717a44e1657b687b0434951559ddd85d11a1b12 Mon Sep 17 00:00:00 2001 From: "Daniel A. Steffen" Date: Thu, 18 May 2017 20:26:38 -0700 Subject: [PATCH] Revert "Use sizeof more pervasively" --- src/allocator.c | 5 +++++ src/allocator_internal.h | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/allocator.c b/src/allocator.c index 861678973..e6ea77217 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -601,7 +601,10 @@ _dispatch_alloc_init(void) // Double-check our math. These are all compile time checks and don't // generate code. + dispatch_assert(sizeof(bitmap_t) == BYTES_PER_BITMAP); dispatch_assert(sizeof(bitmap_t) == BYTES_PER_SUPERMAP); + dispatch_assert(sizeof(struct dispatch_magazine_header_s) == + SIZEOF_HEADER); dispatch_assert(sizeof(struct dispatch_continuation_s) <= DISPATCH_CONTINUATION_SIZE); @@ -611,6 +614,8 @@ _dispatch_alloc_init(void) dispatch_assert(sizeof(struct dispatch_magazine_s) == BYTES_PER_MAGAZINE); // The header and maps sizes should match what we computed. + dispatch_assert(SIZEOF_HEADER == + sizeof(((struct dispatch_magazine_s *)0x0)->header)); dispatch_assert(SIZEOF_MAPS == sizeof(((struct dispatch_magazine_s *)0x0)->maps)); diff --git a/src/allocator_internal.h b/src/allocator_internal.h index fc34b955f..abe4a1d43 100644 --- a/src/allocator_internal.h +++ b/src/allocator_internal.h @@ -97,21 +97,25 @@ // Use the largest type your platform is comfortable doing atomic ops with. // TODO: rdar://11477843 typedef unsigned long bitmap_t; -#define BYTES_PER_BITMAP sizeof(bitmap_t) +#if defined(__LP64__) +#define BYTES_PER_BITMAP 8 +#else +#define BYTES_PER_BITMAP 4 +#endif #define BITMAP_C(v) ((bitmap_t)(v)) #define BITMAP_ALL_ONES (~BITMAP_C(0)) // Stop configuring. -#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * CHAR_BIT) -#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * CHAR_BIT) +#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * 8) +#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * 8) #define BYTES_PER_MAGAZINE (PAGES_PER_MAGAZINE * DISPATCH_ALLOCATOR_PAGE_SIZE) #define CONSUMED_BYTES_PER_BITMAP (BYTES_PER_BITMAP + \ (DISPATCH_CONTINUATION_SIZE * CONTINUATIONS_PER_BITMAP)) -#define BYTES_PER_SUPERMAP sizeof(bitmap_t) +#define BYTES_PER_SUPERMAP BYTES_PER_BITMAP #define CONSUMED_BYTES_PER_SUPERMAP (BYTES_PER_SUPERMAP + \ (BITMAPS_PER_SUPERMAP * CONSUMED_BYTES_PER_BITMAP)) @@ -143,7 +147,11 @@ typedef unsigned long bitmap_t; #define PADDING_TO_CONTINUATION_SIZE(x) (ROUND_UP_TO_CONTINUATION_SIZE(x) - (x)) -#define SIZEOF_HEADER (sizeof(struct dispatch_magazine_header_s)) +#if defined(__LP64__) +#define SIZEOF_HEADER 16 +#else +#define SIZEOF_HEADER 8 +#endif #define SIZEOF_SUPERMAPS (BYTES_PER_SUPERMAP * SUPERMAPS_PER_MAGAZINE) #define SIZEOF_MAPS (BYTES_PER_BITMAP * BITMAPS_PER_SUPERMAP * \