Skip to content

Commit 50b247e

Browse files
committed
Handle dispatch_unote_ident_t typedefs properly.
Different platforms need to typedef dispatch_unote_ident differently, and subsequently may have different bit widths and proper handling thereof. Mostly this involves debug printing, which needs proper format handling. One special case for consideration is `_dispatch_timer_unote_disarm`; this gets the `du_ident` and converts that into a `uint32_t` timer index. When `dispatch_unote_ident` is a `uint32_t` this is of course fine, but needs consideration for when it isn't. Here, we just cast down. This is somewhat reasonable since this is initialized from `_dispatch_timer_unote_idx` which returns an `unsigned int`. (Of course, we are not actually bounds checking that index, but that's outside the scope of this commit).
1 parent 12601ad commit 50b247e

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

src/event/event.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ _dispatch_timer_heap_update(dispatch_timer_heap_t dth,
766766
#pragma mark timer unote
767767

768768
#define _dispatch_timer_du_debug(what, du) \
769-
_dispatch_debug("kevent-source[%p]: %s kevent[%p] { ident = 0x%x }", \
769+
_dispatch_debug("kevent-source[%p]: %s kevent[%p] { ident = 0x%" PRI_DUI " }", \
770770
_dispatch_wref2ptr((du)->du_owner_wref), what, \
771771
(du), (du)->du_ident)
772772

@@ -792,7 +792,7 @@ static void
792792
_dispatch_timer_unote_disarm(dispatch_timer_source_refs_t dt,
793793
dispatch_timer_heap_t dth)
794794
{
795-
uint32_t tidx = dt->du_ident;
795+
uint32_t tidx = (uint32_t)dt->du_ident;
796796

797797
dispatch_assert(_dispatch_unote_armed(dt));
798798
_dispatch_timer_heap_remove(&dth[tidx], dt);

src/event/event_internal.h

+5
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,13 @@ _dispatch_timer_flags_from_clock(dispatch_clock_t clock)
125125

126126
#if defined(_WIN32)
127127
typedef uintptr_t dispatch_unote_ident_t;
128+
#define PRI_DUI PRIuPTR
129+
#elif defined(__OpenBSD__)
130+
typedef uintptr_t dispatch_unote_ident_t;
131+
#define PRI_DUI PRIuPTR
128132
#else
129133
typedef uint32_t dispatch_unote_ident_t;
134+
#define PRI_DUI PRIu32
130135
#endif
131136

132137
#define DISPATCH_UNOTE_CLASS_HEADER() \

src/event/event_kevent.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ dispatch_kevent_debug(const char *verb, const dispatch_kevent_s *kev,
195195
}
196196
}
197197
#if DISPATCH_USE_KEVENT_QOS
198-
_dispatch_debug("%s kevent[%p] %s= { ident = 0x%llx, filter = %s, "
198+
_dispatch_debug("%s kevent[%p] %s= { ident = 0x%" PRI_DUI ", filter = %s, "
199199
"flags = %s (0x%x), fflags = 0x%x, data = 0x%llx, udata = 0x%llx, "
200200
"qos = 0x%x, ext[0] = 0x%llx, ext[1] = 0x%llx, ext[2] = 0x%llx, "
201201
"ext[3] = 0x%llx }: %s #%u", verb, kev, i_n,
@@ -205,7 +205,7 @@ dispatch_kevent_debug(const char *verb, const dispatch_kevent_s *kev,
205205
kev->ext[0], kev->ext[1], kev->ext[2], kev->ext[3],
206206
function, line);
207207
#else
208-
_dispatch_debug("%s kevent[%p] %s= { ident = 0x%llx, filter = %s, "
208+
_dispatch_debug("%s kevent[%p] %s= { ident = 0x%" PRI_DUI ", filter = %s, "
209209
"flags = %s (0x%x), fflags = 0x%x, data = 0x%llx, udata = 0x%llx}: "
210210
"%s #%u", verb, kev, i_n,
211211
(unsigned long long)kev->ident, _evfiltstr(kev->filter),
@@ -240,7 +240,7 @@ dispatch_kevent_debug(const char *verb, const dispatch_kevent_s *kev,
240240

241241
#define _dispatch_du_debug(what, du) \
242242
_dispatch_debug("kevent-source[%p]: %s kevent[%p] " \
243-
"{ filter = %s, ident = 0x%x }", \
243+
"{ filter = %s, ident = 0x%" PRI_DUI " }", \
244244
_dispatch_wref2ptr((du)->du_owner_wref), what, \
245245
(du), _evfiltstr((du)->du_filter), (du)->du_ident)
246246

src/init.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1043,10 +1043,10 @@ _dispatch_bug_kevent_vanished(dispatch_unote_t du)
10431043
_dispatch_log_fault("LIBDISPATCH_STRICT: _dispatch_bug_kevent_vanished",
10441044
"BUG in libdispatch client: %s, monitored resource vanished before "
10451045
"the source cancel handler was invoked "
1046-
"{ %p[%s], ident: %" PRIdPTR " / 0x%" PRIxPTR ", handler: %p }",
1046+
"{ %p[%s], ident: %" PRI_DUI " / 0x%" PRIxMAX ", handler: %p }",
10471047
dux_type(du._du)->dst_kind, dou._dq,
10481048
dou._dq->dq_label ? dou._dq->dq_label : "<unknown>",
1049-
du._du->du_ident, du._du->du_ident, func);
1049+
du._du->du_ident, (uintmax_t)du._du->du_ident, func);
10501050
}
10511051

10521052
#endif // RDAR_49023449
@@ -1151,8 +1151,8 @@ _dispatch_logv_init(void *context DISPATCH_UNUSED)
11511151
}
11521152
#else
11531153
dprintf(dispatch_logfile, "=== log file opened for %s[%u] at "
1154-
"%ld.%06u ===\n", getprogname() ?: "", getpid(),
1155-
tv.tv_sec, (int)tv.tv_usec);
1154+
"%lld.%06u ===\n", getprogname() ?: "", getpid(),
1155+
(time_t)tv.tv_sec, (int)tv.tv_usec);
11561156
#endif
11571157
}
11581158
}

src/source.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ _dispatch_source_debug_attr(dispatch_source_t ds, char* buf, size_t bufsiz)
13981398
dispatch_source_refs_t dr = ds->ds_refs;
13991399
dispatch_queue_flags_t dqf = _dispatch_queue_atomic_flags(ds);
14001400
dispatch_unote_state_t du_state = _dispatch_unote_state(dr);
1401-
return dsnprintf(buf, bufsiz, "target = %s[%p], ident = 0x%x, "
1401+
return dsnprintf(buf, bufsiz, "target = %s[%p], ident = 0x%" PRI_DUI ", "
14021402
"mask = 0x%x, pending_data = 0x%llx, registered = %d, "
14031403
"armed = %d, %s%s%s",
14041404
target && target->dq_label ? target->dq_label : "", target,

0 commit comments

Comments
 (0)