Skip to content

Commit bdb3648

Browse files
compnerdrokhinip
authored andcommitted
dispatch: make public interfaces LLP64 friendly
This attempts to replace the public uses of `unsigned long` with `uintptr_t` and `long` with `intptr_t`. The use of `long` and `unsigned long` here was as a type suitable for matching pointer width. However, on LLP64 targets, this does not hold. Replace them with `intptr_t` which gives a proper pointer sized type. This is done only for the argument types and not for named types to ensure that the ABI is not modified for C++ (where a template may be specialized on the named type). Signed-off-by: Kim Topley <[email protected]>
1 parent 0ba34b4 commit bdb3648

File tree

14 files changed

+47
-47
lines changed

14 files changed

+47
-47
lines changed

dispatch/block.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ dispatch_block_perform(dispatch_block_flags_t flags,
323323
*/
324324
API_AVAILABLE(macos(10.10), ios(8.0))
325325
DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
326-
long
326+
intptr_t
327327
dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout);
328328

329329
/*!
@@ -416,7 +416,7 @@ dispatch_block_cancel(dispatch_block_t block);
416416
API_AVAILABLE(macos(10.10), ios(8.0))
417417
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
418418
DISPATCH_NOTHROW
419-
long
419+
intptr_t
420420
dispatch_block_testcancel(dispatch_block_t block);
421421

422422
__END_DECLS

dispatch/group.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ dispatch_group_async_f(dispatch_group_t group,
160160
*/
161161
API_AVAILABLE(macos(10.6), ios(4.0))
162162
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
163-
long
163+
intptr_t
164164
dispatch_group_wait(dispatch_group_t group, dispatch_time_t timeout);
165165

166166
/*!

dispatch/object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ dispatch_set_qos_class_floor(dispatch_object_t object,
458458
*/
459459
DISPATCH_UNAVAILABLE
460460
DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
461-
long
461+
intptr_t
462462
dispatch_wait(void *object, dispatch_time_t timeout);
463463
#if __has_extension(c_generic_selections)
464464
#define dispatch_wait(object, timeout) \
@@ -556,7 +556,7 @@ dispatch_cancel(void *object);
556556
DISPATCH_UNAVAILABLE
557557
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
558558
DISPATCH_NOTHROW
559-
long
559+
intptr_t
560560
dispatch_testcancel(void *object);
561561
#if __has_extension(c_generic_selections)
562562
#define dispatch_testcancel(object) \

dispatch/queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ typedef long dispatch_queue_priority_t;
681681
API_AVAILABLE(macos(10.6), ios(4.0))
682682
DISPATCH_EXPORT DISPATCH_CONST DISPATCH_WARN_RESULT DISPATCH_NOTHROW
683683
dispatch_queue_global_t
684-
dispatch_get_global_queue(long identifier, unsigned long flags);
684+
dispatch_get_global_queue(intptr_t identifier, uintptr_t flags);
685685

686686
/*!
687687
* @typedef dispatch_queue_attr_t

dispatch/semaphore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ API_AVAILABLE(macos(10.6), ios(4.0))
6161
DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
6262
DISPATCH_NOTHROW
6363
dispatch_semaphore_t
64-
dispatch_semaphore_create(long value);
64+
dispatch_semaphore_create(intptr_t value);
6565

6666
/*!
6767
* @function dispatch_semaphore_wait
@@ -85,7 +85,7 @@ dispatch_semaphore_create(long value);
8585
*/
8686
API_AVAILABLE(macos(10.6), ios(4.0))
8787
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
88-
long
88+
intptr_t
8989
dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout);
9090

9191
/*!
@@ -107,7 +107,7 @@ dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout);
107107
*/
108108
API_AVAILABLE(macos(10.6), ios(4.0))
109109
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
110-
long
110+
intptr_t
111111
dispatch_semaphore_signal(dispatch_semaphore_t dsema);
112112

113113
__END_DECLS

dispatch/source.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ DISPATCH_NOTHROW
389389
dispatch_source_t
390390
dispatch_source_create(dispatch_source_type_t type,
391391
uintptr_t handle,
392-
unsigned long mask,
392+
uintptr_t mask,
393393
dispatch_queue_t _Nullable queue);
394394

395395
/*!
@@ -537,7 +537,7 @@ dispatch_source_cancel(dispatch_source_t source);
537537
API_AVAILABLE(macos(10.6), ios(4.0))
538538
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
539539
DISPATCH_NOTHROW
540-
long
540+
intptr_t
541541
dispatch_source_testcancel(dispatch_source_t source);
542542

543543
/*!
@@ -601,7 +601,7 @@ dispatch_source_get_handle(dispatch_source_t source);
601601
API_AVAILABLE(macos(10.6), ios(4.0))
602602
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
603603
DISPATCH_NOTHROW
604-
unsigned long
604+
uintptr_t
605605
dispatch_source_get_mask(dispatch_source_t source);
606606

607607
/*!
@@ -640,7 +640,7 @@ dispatch_source_get_mask(dispatch_source_t source);
640640
API_AVAILABLE(macos(10.6), ios(4.0))
641641
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
642642
DISPATCH_NOTHROW
643-
unsigned long
643+
uintptr_t
644644
dispatch_source_get_data(dispatch_source_t source);
645645

646646
/*!
@@ -662,7 +662,7 @@ dispatch_source_get_data(dispatch_source_t source);
662662
API_AVAILABLE(macos(10.6), ios(4.0))
663663
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
664664
void
665-
dispatch_source_merge_data(dispatch_source_t source, unsigned long value);
665+
dispatch_source_merge_data(dispatch_source_t source, uintptr_t value);
666666

667667
/*!
668668
* @function dispatch_source_set_timer

src/event/event.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void _dispatch_timer_unote_unregister(dispatch_timer_source_refs_t dt);
3030
DISPATCH_NOINLINE
3131
static dispatch_unote_t
3232
_dispatch_unote_create(dispatch_source_type_t dst,
33-
uintptr_t handle, unsigned long mask)
33+
uintptr_t handle, uintptr_t mask)
3434
{
3535
dispatch_unote_linkage_t dul;
3636
dispatch_unote_class_t du;
@@ -63,7 +63,7 @@ _dispatch_unote_create(dispatch_source_type_t dst,
6363
DISPATCH_NOINLINE
6464
dispatch_unote_t
6565
_dispatch_unote_create_with_handle(dispatch_source_type_t dst,
66-
uintptr_t handle, unsigned long mask)
66+
uintptr_t handle, uintptr_t mask)
6767
{
6868
if (!handle) {
6969
return DISPATCH_UNOTE_NULL;
@@ -74,7 +74,7 @@ _dispatch_unote_create_with_handle(dispatch_source_type_t dst,
7474
DISPATCH_NOINLINE
7575
dispatch_unote_t
7676
_dispatch_unote_create_with_fd(dispatch_source_type_t dst,
77-
uintptr_t handle, unsigned long mask)
77+
uintptr_t handle, uintptr_t mask)
7878
{
7979
#if !TARGET_OS_MAC // <rdar://problem/27756657>
8080
if (handle > INT_MAX) {
@@ -87,7 +87,7 @@ _dispatch_unote_create_with_fd(dispatch_source_type_t dst,
8787
DISPATCH_NOINLINE
8888
dispatch_unote_t
8989
_dispatch_unote_create_without_handle(dispatch_source_type_t dst,
90-
uintptr_t handle, unsigned long mask)
90+
uintptr_t handle, uintptr_t mask)
9191
{
9292
if (handle) {
9393
return DISPATCH_UNOTE_NULL;
@@ -206,7 +206,7 @@ _dispatch_unote_unregister(dispatch_unote_t du, uint32_t flags)
206206

207207
static dispatch_unote_t
208208
_dispatch_source_data_create(dispatch_source_type_t dst, uintptr_t handle,
209-
unsigned long mask)
209+
uintptr_t mask)
210210
{
211211
if (handle || mask) {
212212
return DISPATCH_UNOTE_NULL;
@@ -294,7 +294,7 @@ const dispatch_source_type_s _dispatch_source_type_write = {
294294

295295
static dispatch_unote_t
296296
_dispatch_source_signal_create(dispatch_source_type_t dst, uintptr_t handle,
297-
unsigned long mask)
297+
uintptr_t mask)
298298
{
299299
if (handle >= NSIG) {
300300
return DISPATCH_UNOTE_NULL;
@@ -927,13 +927,13 @@ _dispatch_timer_unote_unregister(dispatch_timer_source_refs_t dt)
927927

928928
static dispatch_unote_t
929929
_dispatch_source_timer_create(dispatch_source_type_t dst,
930-
uintptr_t handle, unsigned long mask)
930+
uintptr_t handle, uintptr_t mask)
931931
{
932932
dispatch_timer_source_refs_t dt;
933933

934934
// normalize flags
935935
if (mask & DISPATCH_TIMER_STRICT) {
936-
mask &= ~(unsigned long)DISPATCH_TIMER_BACKGROUND;
936+
mask &= ~(uintptr_t)DISPATCH_TIMER_BACKGROUND;
937937
}
938938
if (mask & ~dst->dst_mask) {
939939
return DISPATCH_UNOTE_NULL;

src/event/event_internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ typedef struct dispatch_source_type_s {
355355
uint32_t dst_size;
356356

357357
dispatch_unote_t (*dst_create)(dispatch_source_type_t dst,
358-
uintptr_t handle, unsigned long mask);
358+
uintptr_t handle, uintptr_t mask);
359359
#if DISPATCH_EVENT_BACKEND_KEVENT
360360
bool (*dst_update_mux)(struct dispatch_muxnote_s *dmn);
361361
#endif
@@ -614,11 +614,11 @@ _dispatch_timer_unote_compute_missed(dispatch_timer_source_refs_t dt,
614614
extern struct dispatch_timer_heap_s _dispatch_timers_heap[DISPATCH_TIMER_COUNT];
615615

616616
dispatch_unote_t _dispatch_unote_create_with_handle(dispatch_source_type_t dst,
617-
uintptr_t handle, unsigned long mask);
617+
uintptr_t handle, uintptr_t mask);
618618
dispatch_unote_t _dispatch_unote_create_with_fd(dispatch_source_type_t dst,
619-
uintptr_t handle, unsigned long mask);
619+
uintptr_t handle, uintptr_t mask);
620620
dispatch_unote_t _dispatch_unote_create_without_handle(
621-
dispatch_source_type_t dst, uintptr_t handle, unsigned long mask);
621+
dispatch_source_type_t dst, uintptr_t handle, uintptr_t mask);
622622
void _dispatch_unote_dispose(dispatch_unote_t du);
623623

624624
/*

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,12 @@ unsigned long volatile _dispatch_queue_serial_numbers =
361361

362362

363363
dispatch_queue_global_t
364-
dispatch_get_global_queue(long priority, unsigned long flags)
364+
dispatch_get_global_queue(intptr_t priority, uintptr_t flags)
365365
{
366366
dispatch_assert(countof(_dispatch_root_queues) ==
367367
DISPATCH_ROOT_QUEUE_COUNT);
368368

369-
if (flags & ~(unsigned long)DISPATCH_QUEUE_OVERCOMMIT) {
369+
if (flags & ~(uintptr_t)DISPATCH_QUEUE_OVERCOMMIT) {
370370
return DISPATCH_BAD_INPUT;
371371
}
372372
dispatch_qos_t qos = _dispatch_qos_from_queue_priority(priority);

src/queue.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ dispatch_block_cancel(dispatch_block_t db)
561561
(void)os_atomic_or2o(dbpd, dbpd_atomic_flags, DBF_CANCELED, relaxed);
562562
}
563563

564-
long
564+
intptr_t
565565
dispatch_block_testcancel(dispatch_block_t db)
566566
{
567567
dispatch_block_private_data_t dbpd = _dispatch_block_get_data(db);
@@ -572,7 +572,7 @@ dispatch_block_testcancel(dispatch_block_t db)
572572
return (bool)(dbpd->dbpd_atomic_flags & DBF_CANCELED);
573573
}
574574

575-
long
575+
intptr_t
576576
dispatch_block_wait(dispatch_block_t db, dispatch_time_t timeout)
577577
{
578578
dispatch_block_private_data_t dbpd = _dispatch_block_get_data(db);
@@ -618,7 +618,7 @@ dispatch_block_wait(dispatch_block_t db, dispatch_time_t timeout)
618618
"run more than once and waited for");
619619
}
620620

621-
long ret = dispatch_group_wait(dbpd->dbpd_group, timeout);
621+
intptr_t ret = dispatch_group_wait(dbpd->dbpd_group, timeout);
622622

623623
if (boost_th) {
624624
_dispatch_thread_override_end(boost_th, dbpd);

src/semaphore.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ long _dispatch_semaphore_signal_slow(dispatch_semaphore_t dsema);
2727
#pragma mark dispatch_semaphore_t
2828

2929
dispatch_semaphore_t
30-
dispatch_semaphore_create(long value)
30+
dispatch_semaphore_create(intptr_t value)
3131
{
3232
dispatch_semaphore_t dsema;
3333

@@ -81,15 +81,15 @@ _dispatch_semaphore_debug(dispatch_object_t dou, char *buf, size_t bufsiz)
8181
}
8282

8383
DISPATCH_NOINLINE
84-
long
84+
intptr_t
8585
_dispatch_semaphore_signal_slow(dispatch_semaphore_t dsema)
8686
{
8787
_dispatch_sema4_create(&dsema->dsema_sema, _DSEMA4_POLICY_FIFO);
8888
_dispatch_sema4_signal(&dsema->dsema_sema, 1);
8989
return 1;
9090
}
9191

92-
long
92+
intptr_t
9393
dispatch_semaphore_signal(dispatch_semaphore_t dsema)
9494
{
9595
long value = os_atomic_inc2o(dsema, dsema_value, release);
@@ -104,7 +104,7 @@ dispatch_semaphore_signal(dispatch_semaphore_t dsema)
104104
}
105105

106106
DISPATCH_NOINLINE
107-
static long
107+
static intptr_t
108108
_dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
109109
dispatch_time_t timeout)
110110
{
@@ -135,7 +135,7 @@ _dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
135135
return 0;
136136
}
137137

138-
long
138+
intptr_t
139139
dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout)
140140
{
141141
long value = os_atomic_dec2o(dsema, dsema_value, acquire);
@@ -206,7 +206,7 @@ _dispatch_group_debug(dispatch_object_t dou, char *buf, size_t bufsiz)
206206
}
207207

208208
DISPATCH_NOINLINE
209-
static long
209+
static intptr_t
210210
_dispatch_group_wait_slow(dispatch_group_t dg, uint32_t gen,
211211
dispatch_time_t timeout)
212212
{
@@ -221,7 +221,7 @@ _dispatch_group_wait_slow(dispatch_group_t dg, uint32_t gen,
221221
}
222222
}
223223

224-
long
224+
intptr_t
225225
dispatch_group_wait(dispatch_group_t dg, dispatch_time_t timeout)
226226
{
227227
uint64_t old_state, new_state;

src/semaphore_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct dispatch_queue_s;
3232
DISPATCH_CLASS_DECL(semaphore, OBJECT);
3333
struct dispatch_semaphore_s {
3434
DISPATCH_OBJECT_HEADER(semaphore);
35-
long volatile dsema_value;
36-
long dsema_orig;
35+
intptr_t volatile dsema_value;
36+
intptr_t dsema_orig;
3737
_dispatch_sema4_t dsema_sema;
3838
};
3939

src/shims/priority.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ _dispatch_qos_to_qos_class(dispatch_qos_t qos)
165165

166166
DISPATCH_ALWAYS_INLINE
167167
static inline dispatch_qos_t
168-
_dispatch_qos_from_queue_priority(long priority)
168+
_dispatch_qos_from_queue_priority(intptr_t priority)
169169
{
170170
switch (priority) {
171171
case DISPATCH_QUEUE_PRIORITY_BACKGROUND: return DISPATCH_QOS_BACKGROUND;

src/source.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _dispatch_source_get_handler(dispatch_source_refs_t dr, long kind)
4040

4141
dispatch_source_t
4242
dispatch_source_create(dispatch_source_type_t dst, uintptr_t handle,
43-
unsigned long mask, dispatch_queue_t dq)
43+
uintptr_t mask, dispatch_queue_t dq)
4444
{
4545
dispatch_source_refs_t dr;
4646
dispatch_source_t ds;
@@ -96,13 +96,13 @@ _dispatch_source_xref_dispose(dispatch_source_t ds)
9696
dx_wakeup(ds, 0, DISPATCH_WAKEUP_MAKE_DIRTY);
9797
}
9898

99-
long
99+
intptr_t
100100
dispatch_source_testcancel(dispatch_source_t ds)
101101
{
102102
return (bool)(ds->dq_atomic_flags & DSF_CANCELED);
103103
}
104104

105-
unsigned long
105+
uintptr_t
106106
dispatch_source_get_mask(dispatch_source_t ds)
107107
{
108108
dispatch_source_refs_t dr = ds->ds_refs;
@@ -144,7 +144,7 @@ dispatch_source_get_handle(dispatch_source_t ds)
144144
return dr->du_ident;
145145
}
146146

147-
unsigned long
147+
uintptr_t
148148
dispatch_source_get_data(dispatch_source_t ds)
149149
{
150150
#if DISPATCH_USE_MEMORYSTATUS
@@ -159,7 +159,7 @@ dispatch_source_get_data(dispatch_source_t ds)
159159
#endif
160160
#endif // DISPATCH_USE_MEMORYSTATUS
161161
uint64_t value = os_atomic_load2o(dr, ds_data, relaxed);
162-
return (unsigned long)(dr->du_has_extended_status ?
162+
return (uintptr_t)(dr->du_has_extended_status ?
163163
DISPATCH_SOURCE_GET_DATA(value) : value);
164164
}
165165

@@ -197,7 +197,7 @@ dispatch_source_get_extended_data(dispatch_source_t ds,
197197
}
198198

199199
void
200-
dispatch_source_merge_data(dispatch_source_t ds, unsigned long val)
200+
dispatch_source_merge_data(dispatch_source_t ds, uintptr_t val)
201201
{
202202
dispatch_queue_flags_t dqf = _dispatch_queue_atomic_flags(ds);
203203
dispatch_source_refs_t dr = ds->ds_refs;

0 commit comments

Comments
 (0)