Skip to content

Commit eedb747

Browse files
committed
Cast when printing dispatch_unote_ident_t.
Different platforms may define dispatch_unote_ident_t differently and subsequently this type may have different bit widths. Therefore, when printing du_ident, cast explicitly to deal with format mismatch errors. The alternative is to specify explicit format string macros, but this is a little complex and casting is already being used in swiftlang#584. 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 08ec7fd commit eedb747

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

src/event/event.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ _dispatch_timer_heap_update(dispatch_timer_heap_t dth,
768768
#define _dispatch_timer_du_debug(what, du) \
769769
_dispatch_debug("kevent-source[%p]: %s kevent[%p] { ident = 0x%llx }", \
770770
_dispatch_wref2ptr((du)->du_owner_wref), what, \
771-
(du), (unsigned long long)((du)->du_ident))
771+
(du), (unsigned long long)(du)->du_ident)
772772

773773
DISPATCH_ALWAYS_INLINE
774774
static inline unsigned int
@@ -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

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

126126
#if defined(_WIN32)
127127
typedef uintptr_t dispatch_unote_ident_t;
128+
#elif defined(__OpenBSD__)
129+
typedef uintptr_t dispatch_unote_ident_t;
128130
#else
129131
typedef uint32_t dispatch_unote_ident_t;
130132
#endif

src/event/event_kevent.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ 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%llx }", \
244244
_dispatch_wref2ptr((du)->du_owner_wref), what, \
245-
(du), _evfiltstr((du)->du_filter), (du)->du_ident)
245+
(du), _evfiltstr((du)->du_filter), (unsigned long long)(du)->du_ident)
246246

247247
#if DISPATCH_MACHPORT_DEBUG
248248
#ifndef MACH_PORT_TYPE_SPREQUEST

src/init.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ _dispatch_bug_kevent_vanished(dispatch_unote_t du)
10491049
"{ %p[%s], ident: %" PRIdPTR " / 0x%" PRIxPTR ", handler: %p }",
10501050
dux_type(du._du)->dst_kind, dou._dq,
10511051
dou._dq->dq_label ? dou._dq->dq_label : "<unknown>",
1052-
du._du->du_ident, du._du->du_ident, func);
1052+
(intptr_t)du._du->du_ident, (uintptr_t)du._du->du_ident, func);
10531053
}
10541054

10551055
#endif // RDAR_49023449
@@ -1154,8 +1154,8 @@ _dispatch_logv_init(void *context DISPATCH_UNUSED)
11541154
}
11551155
#else
11561156
dprintf(dispatch_logfile, "=== log file opened for %s[%u] at "
1157-
"%ld.%06u ===\n", getprogname() ?: "", getpid(),
1158-
tv.tv_sec, (int)tv.tv_usec);
1157+
"%lld.%06u ===\n", getprogname() ?: "", getpid(),
1158+
(time_t)tv.tv_sec, (int)tv.tv_usec);
11591159
#endif
11601160
}
11611161
}

src/source.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,7 @@ _dispatch_source_debug_attr(dispatch_source_t ds, char* buf, size_t bufsiz)
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,
1405-
(unsigned long long)dr->du_ident, dr->du_fflags,
1406-
(unsigned long long)dr->ds_pending_data,
1405+
(unsigned long long)dr->du_ident, dr->du_fflags, (unsigned long long)dr->ds_pending_data,
14071406
_du_state_registered(du_state), _du_state_armed(du_state),
14081407
(dqf & DSF_CANCELED) ? "cancelled, " : "",
14091408
(dqf & DSF_NEEDS_EVENT) ? "needs-event, " : "",

0 commit comments

Comments
 (0)