Skip to content

Commit 38d35b3

Browse files
committed
resolve all compiler warnings
Resolve all compiler warnings when building libdispatch and the test suite on linux. It now compiles cleanly. Many of the warnings were due to platform-specific sized integers being used in printf-like contexts. In libdispatch itself, I took the approach of adding casts to the values to match the size/type specified in the printf format string (under the assumption that the expected output format should not be changed and needs to be the same on all platforms).
1 parent a650657 commit 38d35b3

File tree

9 files changed

+47
-26
lines changed

9 files changed

+47
-26
lines changed

src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ _dispatch_logv_init(void *context DISPATCH_UNUSED)
531531
#endif
532532
dprintf(dispatch_logfile, "=== log file opened for %s[%u] at "
533533
"%ld.%06u ===\n", getprogname() ?: "", getpid(),
534-
tv.tv_sec, tv.tv_usec);
534+
tv.tv_sec, (int)tv.tv_usec);
535535
}
536536
}
537537
}

src/io.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ _dispatch_disk_init(dispatch_fd_entry_t fd_entry, dev_t dev)
16011601
TAILQ_INIT(&disk->operations);
16021602
disk->cur_rq = TAILQ_FIRST(&disk->operations);
16031603
char label[45];
1604-
snprintf(label, sizeof(label), "com.apple.libdispatch-io.deviceq.%d", dev);
1604+
snprintf(label, sizeof(label), "com.apple.libdispatch-io.deviceq.%d", (int)dev);
16051605
disk->pick_queue = dispatch_queue_create(label, NULL);
16061606
TAILQ_INSERT_TAIL(&_dispatch_io_devs[hash], disk, disk_list);
16071607
out:
@@ -2367,7 +2367,7 @@ _dispatch_io_debug_attr(dispatch_io_t channel, char* buf, size_t bufsiz)
23672367
channel->barrier_group, channel->err, channel->params.low,
23682368
channel->params.high, channel->params.interval_flags &
23692369
DISPATCH_IO_STRICT_INTERVAL ? "(strict)" : "",
2370-
channel->params.interval);
2370+
(unsigned long long) channel->params.interval);
23712371
}
23722372

23732373
size_t
@@ -2398,10 +2398,10 @@ _dispatch_operation_debug_attr(dispatch_operation_t op, char* buf,
23982398
"write", op->fd_entry ? op->fd_entry->fd : -1, op->fd_entry,
23992399
op->channel, op->op_q, oqtarget && oqtarget->dq_label ?
24002400
oqtarget->dq_label : "", oqtarget, target && target->dq_label ?
2401-
target->dq_label : "", target, op->offset, op->length, op->total,
2401+
target->dq_label : "", target, (long long)op->offset, op->length, op->total,
24022402
op->undelivered + op->buf_len, op->flags, op->err, op->params.low,
24032403
op->params.high, op->params.interval_flags &
2404-
DISPATCH_IO_STRICT_INTERVAL ? "(strict)" : "", op->params.interval);
2404+
DISPATCH_IO_STRICT_INTERVAL ? "(strict)" : "", (unsigned long long)op->params.interval);
24052405
}
24062406

24072407
size_t

src/semaphore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ static bool _dispatch_futex_wait_slow(dispatch_futex_t dfx,
895895
const struct timespec* timeout);
896896

897897
DISPATCH_INLINE
898-
static int
898+
int
899899
_dispatch_futex_syscall(int *futex_addr,
900900
int op, int val, const struct timespec *timeout)
901901
{

src/source.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ dispatch_source_create(dispatch_source_type_t type,
148148
dk->dk_kevent.ident = handle;
149149
dk->dk_kevent.flags |= EV_ADD|EV_ENABLE;
150150
dk->dk_kevent.fflags |= (uint32_t)mask;
151-
dk->dk_kevent.udata = (uintptr_t)dk;
151+
dk->dk_kevent.udata = (typeof(dk->dk_kevent.udata))dk;
152152
TAILQ_INIT(&dk->dk_sources);
153153

154154
ds->ds_dkev = dk;
@@ -917,9 +917,9 @@ _dispatch_kevent_init()
917917
TAILQ_INSERT_TAIL(&_dispatch_sources[0],
918918
&_dispatch_kevent_data_add, dk_list);
919919
_dispatch_kevent_data_or.dk_kevent.udata =
920-
(uintptr_t)&_dispatch_kevent_data_or;
920+
(typeof(_dispatch_kevent_data_or.dk_kevent.udata))&_dispatch_kevent_data_or;
921921
_dispatch_kevent_data_add.dk_kevent.udata =
922-
(uintptr_t)&_dispatch_kevent_data_add;
922+
(typeof(_dispatch_kevent_data_or.dk_kevent.udata))&_dispatch_kevent_data_add;
923923
#endif // !DISPATCH_USE_EV_UDATA_SPECIFIC
924924
}
925925

@@ -1168,11 +1168,11 @@ _dispatch_kevent_drain(_dispatch_kevent_qos_s *ke)
11681168
ke->data = 0; // don't return error from caller
11691169
if (ke->flags & EV_DELETE) {
11701170
_dispatch_debug("kevent[0x%llx]: ignoring ESRCH from "
1171-
"EVFILT_PROC EV_DELETE", ke->udata);
1171+
"EVFILT_PROC EV_DELETE", (unsigned long long)ke->udata);
11721172
return;
11731173
}
11741174
_dispatch_debug("kevent[0x%llx]: ESRCH from EVFILT_PROC: "
1175-
"generating fake NOTE_EXIT", ke->udata);
1175+
"generating fake NOTE_EXIT", (unsigned long long)ke->udata);
11761176
return _dispatch_kevent_proc_exit(ke);
11771177
}
11781178
return _dispatch_kevent_error(ke);
@@ -1532,8 +1532,13 @@ struct dispatch_timer_s _dispatch_timer[] = {
15321532
#define DISPATCH_TIMER_COUNT \
15331533
((sizeof(_dispatch_timer) / sizeof(_dispatch_timer[0])))
15341534

1535+
#if __linux__
15351536
#define DISPATCH_KEVENT_TIMER_UDATA(tidx) \
1537+
(void*)&_dispatch_kevent_timer[tidx]
1538+
#else
1539+
#define DISPATCH_KEVENT_TIMER_UDATA(tidx) \
15361540
(uintptr_t)&_dispatch_kevent_timer[tidx]
1541+
#endif
15371542
#ifdef __LP64__
15381543
#define DISPATCH_KEVENT_TIMER_UDATA_INITIALIZER(tidx) \
15391544
.udata = DISPATCH_KEVENT_TIMER_UDATA(tidx)
@@ -1962,13 +1967,16 @@ _dispatch_timers_configure(void)
19621967
return _dispatch_timers_check(_dispatch_kevent_timer, _dispatch_timer);
19631968
}
19641969

1970+
1971+
#if HAVE_MACH
19651972
static void
19661973
_dispatch_timers_calendar_change(void)
19671974
{
19681975
// calendar change may have gone past the wallclock deadline
19691976
_dispatch_timer_expired = true;
19701977
_dispatch_timers_qos_mask = ~0u;
19711978
}
1979+
#endif
19721980

19731981
static void
19741982
_dispatch_timers_kevent(_dispatch_kevent_qos_s *ke)
@@ -2194,7 +2202,7 @@ _dispatch_select_register(const _dispatch_kevent_qos_s *kev)
21942202
sizeof(*_dispatch_rfd_ptrs));
21952203
}
21962204
if (!_dispatch_rfd_ptrs[kev->ident]) {
2197-
_dispatch_rfd_ptrs[kev->ident] = kev->udata;
2205+
_dispatch_rfd_ptrs[kev->ident] = (uint64_t)kev->udata;
21982206
_dispatch_select_workaround++;
21992207
_dispatch_debug("select workaround used to read fd %d: 0x%lx",
22002208
(int)kev->ident, (long)kev->data);
@@ -2211,7 +2219,7 @@ _dispatch_select_register(const _dispatch_kevent_qos_s *kev)
22112219
sizeof(*_dispatch_wfd_ptrs));
22122220
}
22132221
if (!_dispatch_wfd_ptrs[kev->ident]) {
2214-
_dispatch_wfd_ptrs[kev->ident] = kev->udata;
2222+
_dispatch_wfd_ptrs[kev->ident] = (uint64_t)kev->udata;
22152223
_dispatch_select_workaround++;
22162224
_dispatch_debug("select workaround used to write fd %d: 0x%lx",
22172225
(int)kev->ident, (long)kev->data);
@@ -2313,7 +2321,7 @@ _dispatch_mgr_select(bool poll)
23132321
.filter = EVFILT_READ,
23142322
.flags = EV_ADD|EV_ENABLE|EV_DISPATCH,
23152323
.data = 1,
2316-
.udata = _dispatch_rfd_ptrs[i],
2324+
.udata = (typeof(kev.udata))_dispatch_rfd_ptrs[i],
23172325
};
23182326
_dispatch_kevent_drain(&kev);
23192327
}
@@ -2324,7 +2332,7 @@ _dispatch_mgr_select(bool poll)
23242332
.filter = EVFILT_WRITE,
23252333
.flags = EV_ADD|EV_ENABLE|EV_DISPATCH,
23262334
.data = 1,
2327-
.udata = _dispatch_wfd_ptrs[i],
2335+
.udata = (typeof(kev.udata))_dispatch_wfd_ptrs[i],
23282336
};
23292337
_dispatch_kevent_drain(&kev);
23302338
}
@@ -2482,12 +2490,14 @@ _dispatch_kq_update(const _dispatch_kevent_qos_s *kev)
24822490

24832491
static _dispatch_kevent_qos_s *_dispatch_kevent_enable;
24842492

2493+
#if HAVE_MACH
24852494
static void inline
24862495
_dispatch_mgr_kevent_reenable(_dispatch_kevent_qos_s *ke)
24872496
{
24882497
dispatch_assert(!_dispatch_kevent_enable || _dispatch_kevent_enable == ke);
24892498
_dispatch_kevent_enable = ke;
24902499
}
2500+
#endif
24912501

24922502
unsigned long
24932503
_dispatch_mgr_wakeup(dispatch_queue_t dq DISPATCH_UNUSED)
@@ -4755,8 +4765,9 @@ _dispatch_timer_debug_attr(dispatch_source_t ds, char* buf, size_t bufsiz)
47554765
dispatch_source_refs_t dr = ds->ds_refs;
47564766
return dsnprintf(buf, bufsiz, "timer = { target = 0x%llx, deadline = 0x%llx,"
47574767
" last_fire = 0x%llx, interval = 0x%llx, flags = 0x%lx }, ",
4758-
ds_timer(dr).target, ds_timer(dr).deadline, ds_timer(dr).last_fire,
4759-
ds_timer(dr).interval, ds_timer(dr).flags);
4768+
(unsigned long long)ds_timer(dr).target, (unsigned long long)ds_timer(dr).deadline,
4769+
(unsigned long long)ds_timer(dr).last_fire, (unsigned long long)ds_timer(dr).interval,
4770+
ds_timer(dr).flags);
47604771
}
47614772

47624773
size_t

tests/bsdtestharness.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#endif
3232
#include <sys/resource.h>
3333
#include <sys/time.h>
34+
#ifdef __linux__
35+
#include <sys/wait.h>
36+
#endif
3437

3538
#include <bsdtests.h>
3639

@@ -47,7 +50,6 @@ extern char **environ;
4750
int
4851
main(int argc, char *argv[])
4952
{
50-
dispatch_source_t tmp_ds;
5153
int res;
5254
pid_t pid = 0;
5355

@@ -73,13 +75,13 @@ main(int argc, char *argv[])
7375
assert(res == 0);
7476

7577
uint64_t to = 0;
76-
#ifdef __APPLE__
7778
char *tos = getenv("BSDTEST_TIMEOUT");
7879
if (tos) {
7980
to = strtoul(tos, NULL, 0);
8081
to *= NSEC_PER_SEC;
8182
}
8283

84+
#ifdef __APPLE__
8385
char *arch = getenv("BSDTEST_ARCH");
8486
if (arch) {
8587
const NXArchInfo *ai = NXGetArchInfoFromName(arch);
@@ -123,14 +125,14 @@ main(int argc, char *argv[])
123125
gettimeofday(&tv_stop, NULL);
124126
tv_wall.tv_sec = tv_stop.tv_sec - tv_start.tv_sec;
125127
tv_wall.tv_sec -= (tv_stop.tv_usec < tv_start.tv_usec);
126-
tv_wall.tv_usec = abs(tv_stop.tv_usec - tv_start.tv_usec);
128+
tv_wall.tv_usec = labs(tv_stop.tv_usec - tv_start.tv_usec);
127129

128130
int res2 = wait4(pid, &status, 0, &usage);
129131
assert(res2 != -1);
130132
test_long("Process exited", (WIFEXITED(status) && WEXITSTATUS(status) && WEXITSTATUS(status) != 0xff) || WIFSIGNALED(status), 0);
131-
printf("[PERF]\twall time: %ld.%06d\n", tv_wall.tv_sec, tv_wall.tv_usec);
132-
printf("[PERF]\tuser time: %ld.%06d\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
133-
printf("[PERF]\tsystem time: %ld.%06d\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
133+
printf("[PERF]\twall time: %ld.%06ld\n", tv_wall.tv_sec, tv_wall.tv_usec);
134+
printf("[PERF]\tuser time: %ld.%06ld\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
135+
printf("[PERF]\tsystem time: %ld.%06ld\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
134136
printf("[PERF]\tmax resident set size: %ld\n", usage.ru_maxrss);
135137
printf("[PERF]\tpage faults: %ld\n", usage.ru_majflt);
136138
printf("[PERF]\tswaps: %ld\n", usage.ru_nswap);
@@ -140,7 +142,7 @@ main(int argc, char *argv[])
140142
#else
141143
dispatch_queue_t main_q = dispatch_get_main_queue();
142144

143-
tmp_ds = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, pid, DISPATCH_PROC_EXIT, main_q);
145+
dispatch_source_t tmp_ds = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, pid, DISPATCH_PROC_EXIT, main_q);
144146
assert(tmp_ds);
145147
dispatch_source_set_event_handler(tmp_ds, ^{
146148
int status;

tests/bsdtests.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
* @APPLE_APACHE_LICENSE_HEADER_END@
1919
*/
2020

21+
#ifdef __linux__
22+
// for asprintf
23+
#define _GNU_SOURCE 1
24+
#endif
2125
#include <stdarg.h>
2226
#include <stdio.h>
2327
#include <stdlib.h>

tests/dispatch_overcommit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
* @APPLE_APACHE_LICENSE_HEADER_END@
1919
*/
2020

21+
#ifdef __linux__
22+
// for asprintf
23+
#define _GNU_SOURCE 1
24+
#endif
2125
#include <dispatch/dispatch.h>
2226
#include <dispatch/private.h>
2327
#include <stdio.h>

tests/dispatch_starfish.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ collect(void *context __attribute__((unused)))
7070

7171
printf("lap: %ld\n", lap_count_down);
7272
printf("count: %lu\n", COUNT);
73-
printf("delta: %llu ns\n", delta);
73+
printf("delta: %lu ns\n", delta);
7474
printf("math: %Lf ns / lap\n", math);
7575

7676
for (i = 0; i < COUNT; i++) {

tests/dispatch_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_timer(void)
6363
dispatch_source_set_event_handler(s, ^{
6464
if (!finalized) {
6565
test_long_less_than("timer number", j, stop_at);
66-
fprintf(stderr, "timer[%lld]\n", j);
66+
fprintf(stderr, "timer[%lu]\n", j);
6767
}
6868
dispatch_release(s);
6969
});

0 commit comments

Comments
 (0)