Skip to content

Commit e85f5ee

Browse files
authored
Merge pull request swiftlang#247 from apple/revert-242-sizeof
Revert "Use sizeof more pervasively"
2 parents d6eb245 + c717a44 commit e85f5ee

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/allocator.c

+5
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,10 @@ _dispatch_alloc_init(void)
601601
// Double-check our math. These are all compile time checks and don't
602602
// generate code.
603603

604+
dispatch_assert(sizeof(bitmap_t) == BYTES_PER_BITMAP);
604605
dispatch_assert(sizeof(bitmap_t) == BYTES_PER_SUPERMAP);
606+
dispatch_assert(sizeof(struct dispatch_magazine_header_s) ==
607+
SIZEOF_HEADER);
605608

606609
dispatch_assert(sizeof(struct dispatch_continuation_s) <=
607610
DISPATCH_CONTINUATION_SIZE);
@@ -611,6 +614,8 @@ _dispatch_alloc_init(void)
611614
dispatch_assert(sizeof(struct dispatch_magazine_s) == BYTES_PER_MAGAZINE);
612615

613616
// The header and maps sizes should match what we computed.
617+
dispatch_assert(SIZEOF_HEADER ==
618+
sizeof(((struct dispatch_magazine_s *)0x0)->header));
614619
dispatch_assert(SIZEOF_MAPS ==
615620
sizeof(((struct dispatch_magazine_s *)0x0)->maps));
616621

src/allocator_internal.h

+13-5
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,25 @@
9797
// Use the largest type your platform is comfortable doing atomic ops with.
9898
// TODO: rdar://11477843
9999
typedef unsigned long bitmap_t;
100-
#define BYTES_PER_BITMAP sizeof(bitmap_t)
100+
#if defined(__LP64__)
101+
#define BYTES_PER_BITMAP 8
102+
#else
103+
#define BYTES_PER_BITMAP 4
104+
#endif
101105

102106
#define BITMAP_C(v) ((bitmap_t)(v))
103107
#define BITMAP_ALL_ONES (~BITMAP_C(0))
104108

105109
// Stop configuring.
106110

107-
#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * CHAR_BIT)
108-
#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * CHAR_BIT)
111+
#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * 8)
112+
#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * 8)
109113

110114
#define BYTES_PER_MAGAZINE (PAGES_PER_MAGAZINE * DISPATCH_ALLOCATOR_PAGE_SIZE)
111115
#define CONSUMED_BYTES_PER_BITMAP (BYTES_PER_BITMAP + \
112116
(DISPATCH_CONTINUATION_SIZE * CONTINUATIONS_PER_BITMAP))
113117

114-
#define BYTES_PER_SUPERMAP sizeof(bitmap_t)
118+
#define BYTES_PER_SUPERMAP BYTES_PER_BITMAP
115119
#define CONSUMED_BYTES_PER_SUPERMAP (BYTES_PER_SUPERMAP + \
116120
(BITMAPS_PER_SUPERMAP * CONSUMED_BYTES_PER_BITMAP))
117121

@@ -143,7 +147,11 @@ typedef unsigned long bitmap_t;
143147

144148
#define PADDING_TO_CONTINUATION_SIZE(x) (ROUND_UP_TO_CONTINUATION_SIZE(x) - (x))
145149

146-
#define SIZEOF_HEADER (sizeof(struct dispatch_magazine_header_s))
150+
#if defined(__LP64__)
151+
#define SIZEOF_HEADER 16
152+
#else
153+
#define SIZEOF_HEADER 8
154+
#endif
147155

148156
#define SIZEOF_SUPERMAPS (BYTES_PER_SUPERMAP * SUPERMAPS_PER_MAGAZINE)
149157
#define SIZEOF_MAPS (BYTES_PER_BITMAP * BITMAPS_PER_SUPERMAP * \

0 commit comments

Comments
 (0)