Merge pull request #247 from apple/revert-242-sizeof
Revert "Use sizeof more pervasively"
diff --git a/src/allocator.c b/src/allocator.c
index 8616789..e6ea772 100644
--- a/src/allocator.c
+++ b/src/allocator.c
@@ -601,7 +601,10 @@
// 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_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 fc34b95..abe4a1d 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 @@
#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 * \