Skip to content

Commit d52b0d7

Browse files
committed
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).
1 parent f6376cb commit d52b0d7

File tree

12 files changed

+39
-39
lines changed

12 files changed

+39
-39
lines changed

dispatch/block.h

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

328328
/*!
@@ -415,7 +415,7 @@ dispatch_block_cancel(dispatch_block_t block);
415415
API_AVAILABLE(macos(10.10), ios(8.0))
416416
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
417417
DISPATCH_NOTHROW
418-
long
418+
intptr_t
419419
dispatch_block_testcancel(dispatch_block_t block);
420420

421421
__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
@@ -402,7 +402,7 @@ dispatch_resume(dispatch_object_t object);
402402
*/
403403
DISPATCH_UNAVAILABLE
404404
DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
405-
long
405+
intptr_t
406406
dispatch_wait(void *object, dispatch_time_t timeout);
407407
#if __has_extension(c_generic_selections)
408408
#define dispatch_wait(object, timeout) \
@@ -500,7 +500,7 @@ dispatch_cancel(void *object);
500500
DISPATCH_UNAVAILABLE
501501
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
502502
DISPATCH_NOTHROW
503-
long
503+
intptr_t
504504
dispatch_testcancel(void *object);
505505
#if __has_extension(c_generic_selections)
506506
#define dispatch_testcancel(object) \

dispatch/queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ typedef unsigned int dispatch_qos_class_t;
454454
API_AVAILABLE(macos(10.6), ios(4.0))
455455
DISPATCH_EXPORT DISPATCH_CONST DISPATCH_WARN_RESULT DISPATCH_NOTHROW
456456
dispatch_queue_t
457-
dispatch_get_global_queue(long identifier, unsigned long flags);
457+
dispatch_get_global_queue(intptr_t identifier, uintptr_t flags);
458458

459459
/*!
460460
* @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
@@ -382,7 +382,7 @@ DISPATCH_NOTHROW
382382
dispatch_source_t
383383
dispatch_source_create(dispatch_source_type_t type,
384384
uintptr_t handle,
385-
unsigned long mask,
385+
uintptr_t mask,
386386
dispatch_queue_t _Nullable queue);
387387

388388
/*!
@@ -530,7 +530,7 @@ dispatch_source_cancel(dispatch_source_t source);
530530
API_AVAILABLE(macos(10.6), ios(4.0))
531531
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
532532
DISPATCH_NOTHROW
533-
long
533+
intptr_t
534534
dispatch_source_testcancel(dispatch_source_t source);
535535

536536
/*!
@@ -592,7 +592,7 @@ dispatch_source_get_handle(dispatch_source_t source);
592592
API_AVAILABLE(macos(10.6), ios(4.0))
593593
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
594594
DISPATCH_NOTHROW
595-
unsigned long
595+
uintptr_t
596596
dispatch_source_get_mask(dispatch_source_t source);
597597

598598
/*!
@@ -630,7 +630,7 @@ dispatch_source_get_mask(dispatch_source_t source);
630630
API_AVAILABLE(macos(10.6), ios(4.0))
631631
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
632632
DISPATCH_NOTHROW
633-
unsigned long
633+
uintptr_t
634634
dispatch_source_get_data(dispatch_source_t source);
635635

636636
/*!
@@ -652,7 +652,7 @@ dispatch_source_get_data(dispatch_source_t source);
652652
API_AVAILABLE(macos(10.6), ios(4.0))
653653
DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
654654
void
655-
dispatch_source_merge_data(dispatch_source_t source, unsigned long value);
655+
dispatch_source_merge_data(dispatch_source_t source, uintptr_t value);
656656

657657
/*!
658658
* @function dispatch_source_set_timer

src/event/event_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ typedef struct dispatch_source_type_s {
241241
#endif
242242

243243
dispatch_unote_t (*dst_create)(dispatch_source_type_t dst,
244-
uintptr_t handle, unsigned long mask);
244+
uintptr_t handle, uintptr_t mask);
245245
#if DISPATCH_EVENT_BACKEND_KEVENT
246246
bool (*dst_update_mux)(struct dispatch_muxnote_s *dmn);
247247
#endif

src/queue.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,9 @@ struct dispatch_queue_s _dispatch_mgr_q = {
511511
};
512512

513513
dispatch_queue_t
514-
dispatch_get_global_queue(long priority, unsigned long flags)
514+
dispatch_get_global_queue(intptr_t priority, uintptr_t flags)
515515
{
516-
if (flags & ~(unsigned long)DISPATCH_QUEUE_OVERCOMMIT) {
516+
if (flags & ~(uintptr_t)DISPATCH_QUEUE_OVERCOMMIT) {
517517
return DISPATCH_BAD_INPUT;
518518
}
519519
dispatch_qos_t qos = _dispatch_qos_from_queue_priority(priority);
@@ -3267,7 +3267,7 @@ dispatch_block_cancel(dispatch_block_t db)
32673267
(void)os_atomic_or2o(dbpd, dbpd_atomic_flags, DBF_CANCELED, relaxed);
32683268
}
32693269

3270-
long
3270+
intptr_t
32713271
dispatch_block_testcancel(dispatch_block_t db)
32723272
{
32733273
dispatch_block_private_data_t dbpd = _dispatch_block_get_data(db);
@@ -3278,7 +3278,7 @@ dispatch_block_testcancel(dispatch_block_t db)
32783278
return (bool)(dbpd->dbpd_atomic_flags & DBF_CANCELED);
32793279
}
32803280

3281-
long
3281+
intptr_t
32823282
dispatch_block_wait(dispatch_block_t db, dispatch_time_t timeout)
32833283
{
32843284
dispatch_block_private_data_t dbpd = _dispatch_block_get_data(db);
@@ -3324,7 +3324,7 @@ dispatch_block_wait(dispatch_block_t db, dispatch_time_t timeout)
33243324
"run more than once and waited for");
33253325
}
33263326

3327-
long ret = dispatch_group_wait(_dbpd_group(dbpd), timeout);
3327+
intptr_t ret = dispatch_group_wait(_dbpd_group(dbpd), timeout);
33283328

33293329
if (boost_th) {
33303330
_dispatch_thread_override_end(boost_th, dbpd);

src/semaphore.c

Lines changed: 9 additions & 9 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_class_t
2828

2929
static void
30-
_dispatch_semaphore_class_init(long value, dispatch_semaphore_class_t dsemau)
30+
_dispatch_semaphore_class_init(intptr_t value, dispatch_semaphore_class_t dsemau)
3131
{
3232
struct dispatch_semaphore_header_s *dsema = dsemau._dsema_hdr;
3333

@@ -41,7 +41,7 @@ _dispatch_semaphore_class_init(long value, dispatch_semaphore_class_t dsemau)
4141
#pragma mark dispatch_semaphore_t
4242

4343
dispatch_semaphore_t
44-
dispatch_semaphore_create(long value)
44+
dispatch_semaphore_create(intptr_t value)
4545
{
4646
dispatch_semaphore_t dsema;
4747

@@ -92,15 +92,15 @@ _dispatch_semaphore_debug(dispatch_object_t dou, char *buf, size_t bufsiz)
9292
}
9393

9494
DISPATCH_NOINLINE
95-
long
95+
intptr_t
9696
_dispatch_semaphore_signal_slow(dispatch_semaphore_t dsema)
9797
{
9898
_dispatch_sema4_create(&dsema->dsema_sema, _DSEMA4_POLICY_FIFO);
9999
_dispatch_sema4_signal(&dsema->dsema_sema, 1);
100100
return 1;
101101
}
102102

103-
long
103+
intptr_t
104104
dispatch_semaphore_signal(dispatch_semaphore_t dsema)
105105
{
106106
long value = os_atomic_inc2o(dsema, dsema_value, release);
@@ -115,7 +115,7 @@ dispatch_semaphore_signal(dispatch_semaphore_t dsema)
115115
}
116116

117117
DISPATCH_NOINLINE
118-
static long
118+
static intptr_t
119119
_dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
120120
dispatch_time_t timeout)
121121
{
@@ -146,7 +146,7 @@ _dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
146146
return 0;
147147
}
148148

149-
long
149+
intptr_t
150150
dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout)
151151
{
152152
long value = os_atomic_dec2o(dsema, dsema_value, acquire);
@@ -198,7 +198,7 @@ dispatch_group_enter(dispatch_group_t dg)
198198
}
199199

200200
DISPATCH_NOINLINE
201-
static long
201+
static intptr_t
202202
_dispatch_group_wake(dispatch_group_t dg, bool needs_release)
203203
{
204204
dispatch_continuation_t next, head, tail = NULL;
@@ -277,7 +277,7 @@ _dispatch_group_debug(dispatch_object_t dou, char *buf, size_t bufsiz)
277277
}
278278

279279
DISPATCH_NOINLINE
280-
static long
280+
static intptr_t
281281
_dispatch_group_wait_slow(dispatch_group_t dg, dispatch_time_t timeout)
282282
{
283283
long value;
@@ -325,7 +325,7 @@ _dispatch_group_wait_slow(dispatch_group_t dg, dispatch_time_t timeout)
325325
return 0;
326326
}
327327

328-
long
328+
intptr_t
329329
dispatch_group_wait(dispatch_group_t dg, dispatch_time_t timeout)
330330
{
331331
if (dg->dg_value == 0) {

src/semaphore_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct dispatch_queue_s;
3131

3232
#define DISPATCH_SEMAPHORE_HEADER(cls, ns) \
3333
DISPATCH_OBJECT_HEADER(cls); \
34-
long volatile ns##_value; \
34+
intptr_t volatile ns##_value; \
3535
_dispatch_sema4_t ns##_sema
3636

3737
struct dispatch_semaphore_header_s {
@@ -41,7 +41,7 @@ struct dispatch_semaphore_header_s {
4141
DISPATCH_CLASS_DECL(semaphore);
4242
struct dispatch_semaphore_s {
4343
DISPATCH_SEMAPHORE_HEADER(semaphore, dsema);
44-
long dsema_orig;
44+
intptr_t dsema_orig;
4545
};
4646

4747
DISPATCH_CLASS_DECL(group);

src/shims/priority.h

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

143143
DISPATCH_ALWAYS_INLINE
144144
static inline dispatch_qos_t
145-
_dispatch_qos_from_queue_priority(long priority)
145+
_dispatch_qos_from_queue_priority(intptr_t priority)
146146
{
147147
switch (priority) {
148148
case DISPATCH_QUEUE_PRIORITY_BACKGROUND: return DISPATCH_QOS_BACKGROUND;

src/source.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static inline unsigned long _dispatch_source_timer_data(
3737

3838
dispatch_source_t
3939
dispatch_source_create(dispatch_source_type_t dst, uintptr_t handle,
40-
unsigned long mask, dispatch_queue_t dq)
40+
uintptr_t mask, dispatch_queue_t dq)
4141
{
4242
dispatch_source_refs_t dr;
4343
dispatch_source_t ds;
@@ -93,13 +93,13 @@ _dispatch_source_xref_dispose(dispatch_source_t ds)
9393
dx_wakeup(ds, 0, DISPATCH_WAKEUP_MAKE_DIRTY);
9494
}
9595

96-
long
96+
intptr_t
9797
dispatch_source_testcancel(dispatch_source_t ds)
9898
{
9999
return (bool)(ds->dq_atomic_flags & DSF_CANCELED);
100100
}
101101

102-
unsigned long
102+
uintptr_t
103103
dispatch_source_get_mask(dispatch_source_t ds)
104104
{
105105
dispatch_source_refs_t dr = ds->ds_refs;
@@ -131,7 +131,7 @@ dispatch_source_get_handle(dispatch_source_t ds)
131131
return dr->du_ident;
132132
}
133133

134-
unsigned long
134+
uintptr_t
135135
dispatch_source_get_data(dispatch_source_t ds)
136136
{
137137
#if DISPATCH_USE_MEMORYSTATUS
@@ -146,7 +146,7 @@ dispatch_source_get_data(dispatch_source_t ds)
146146
#endif
147147
#endif // DISPATCH_USE_MEMORYSTATUS
148148
uint64_t value = os_atomic_load2o(ds, ds_data, relaxed);
149-
return (unsigned long)(
149+
return (uintptr_t)(
150150
ds->ds_refs->du_data_action == DISPATCH_UNOTE_ACTION_DATA_OR_STATUS_SET
151151
? DISPATCH_SOURCE_GET_DATA(value) : value);
152152
}
@@ -187,7 +187,7 @@ dispatch_source_get_extended_data(dispatch_source_t ds,
187187
DISPATCH_NOINLINE
188188
void
189189
_dispatch_source_merge_data(dispatch_source_t ds, pthread_priority_t pp,
190-
unsigned long val)
190+
uintptr_t val)
191191
{
192192
dispatch_queue_flags_t dqf = _dispatch_queue_atomic_flags(ds->_as_dq);
193193
int filter = ds->ds_refs->du_filter;
@@ -214,7 +214,7 @@ _dispatch_source_merge_data(dispatch_source_t ds, pthread_priority_t pp,
214214
}
215215

216216
void
217-
dispatch_source_merge_data(dispatch_source_t ds, unsigned long val)
217+
dispatch_source_merge_data(dispatch_source_t ds, uintptr_t val)
218218
{
219219
_dispatch_source_merge_data(ds, 0, val);
220220
}

0 commit comments

Comments
 (0)