Skip to content

Commit 445d2fa

Browse files
committed
fixes for compiler warnings
work in progress on cleaning up code so it can be compiled with the same set of warning flags used on Darwin. This is an inital pass through the C files in src to resolve warnings. Most warnings are related to implicit size/sign conversions between integral types and missing explicit prototypes for non-static functions.
1 parent 5ad9208 commit 445d2fa

File tree

13 files changed

+87
-45
lines changed

13 files changed

+87
-45
lines changed

src/BlocksRuntime/runtime.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ GC support stub routines
148148

149149

150150
static void *_Block_alloc_default(const unsigned long size, const bool initialCountIsOne, const bool isObject) {
151+
(void)initialCountIsOne;
152+
(void)isObject;
151153
return malloc(size);
152154
}
153155

@@ -156,16 +158,20 @@ static void _Block_assign_default(void *value, void **destptr) {
156158
}
157159

158160
static void _Block_setHasRefcount_default(const void *ptr, const bool hasRefcount) {
161+
(void)ptr;
162+
(void)hasRefcount;
159163
}
160164

161165
#if HAVE_OBJC
162166
static void _Block_do_nothing(const void *aBlock) { }
163167
#endif
164168

165169
static void _Block_retain_object_default(const void *ptr) {
170+
(void)ptr;
166171
}
167172

168173
static void _Block_release_object_default(const void *ptr) {
174+
(void)ptr;
169175
}
170176

171177
static void _Block_assign_weak_default(const void *ptr, void *dest) {
@@ -193,7 +199,9 @@ static void _Block_memmove_gc_broken(void *dest, void *src, unsigned long size)
193199
}
194200
#endif
195201

196-
static void _Block_destructInstance_default(const void *aBlock) {}
202+
static void _Block_destructInstance_default(const void *aBlock) {
203+
(void)aBlock;
204+
}
197205

198206
/**************************************************************************
199207
GC support callout functions - initially set to stub routines

src/data.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ static void
129129
_dispatch_data_destroy_buffer(const void* buffer, size_t size,
130130
dispatch_queue_t queue, dispatch_block_t destructor)
131131
{
132+
#if !HAVE_MACH
133+
(void)size;
134+
#endif
132135
if (destructor == DISPATCH_DATA_DESTRUCTOR_FREE) {
133136
free((void*)buffer);
134137
} else if (destructor == DISPATCH_DATA_DESTRUCTOR_NONE) {

src/event/event_epoll.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ _dispatch_muxnote_bucket(int ident)
9090
return &_dispatch_sources[DSL_HASH((uint32_t)ident)];
9191
}
9292
#define _dispatch_unote_muxnote_bucket(du) \
93-
_dispatch_muxnote_bucket(du._du->du_ident)
93+
_dispatch_muxnote_bucket((int)du._du->du_ident)
9494

9595
DISPATCH_ALWAYS_INLINE
9696
static inline dispatch_muxnote_t
9797
_dispatch_muxnote_find(struct dispatch_muxnote_bucket_s *dmb,
98-
uint64_t ident, int16_t filter)
98+
int ident, int16_t filter)
9999
{
100100
dispatch_muxnote_t dmn;
101101
if (filter == EVFILT_WRITE) filter = EVFILT_READ;
@@ -107,7 +107,7 @@ _dispatch_muxnote_find(struct dispatch_muxnote_bucket_s *dmb,
107107
return dmn;
108108
}
109109
#define _dispatch_unote_muxnote_find(dmb, du) \
110-
_dispatch_muxnote_find(dmb, du._du->du_ident, du._du->du_filter)
110+
_dispatch_muxnote_find(dmb, (int)du._du->du_ident, du._du->du_filter)
111111

112112
static void
113113
_dispatch_muxnote_dispose(dispatch_muxnote_t dmn)
@@ -142,20 +142,20 @@ _dispatch_muxnote_create(dispatch_unote_t du, uint32_t events)
142142

143143
dispatch_muxnote_t dmn;
144144
struct stat sb;
145-
int fd = du._du->du_ident;
145+
int fd = (int)du._du->du_ident;
146146
int16_t filter = du._du->du_filter;
147147
bool skip_outq_ioctl = false, skip_inq_ioctl = false;
148148
sigset_t sigmask;
149149

150150
switch (filter) {
151151
case EVFILT_SIGNAL:
152-
if (!sigismember(&signals_with_unotes, du._du->du_ident)) {
152+
if (!sigismember(&signals_with_unotes, (int)du._du->du_ident)) {
153153
manager_thread = pthread_self();
154-
sigaddset(&signals_with_unotes, du._du->du_ident);
155-
sigaction(du._du->du_ident, &sa, NULL);
154+
sigaddset(&signals_with_unotes, (int)du._du->du_ident);
155+
sigaction((int)du._du->du_ident, &sa, NULL);
156156
}
157157
sigemptyset(&sigmask);
158-
sigaddset(&sigmask, du._du->du_ident);
158+
sigaddset(&sigmask, (int)du._du->du_ident);
159159
fd = signalfd(-1, &sigmask, SFD_NONBLOCK | SFD_CLOEXEC);
160160
if (fd < 0) {
161161
return NULL;
@@ -195,7 +195,7 @@ _dispatch_muxnote_create(dispatch_unote_t du, uint32_t events)
195195
TAILQ_INIT(&dmn->dmn_readers_head);
196196
TAILQ_INIT(&dmn->dmn_writers_head);
197197
dmn->dmn_fd = fd;
198-
dmn->dmn_ident = du._du->du_ident;
198+
dmn->dmn_ident = (int)du._du->du_ident;
199199
dmn->dmn_filter = filter;
200200
dmn->dmn_events = events;
201201
dmn->dmn_skip_outq_ioctl = skip_outq_ioctl;
@@ -290,7 +290,7 @@ _dispatch_unote_resume(dispatch_unote_t du)
290290
}
291291

292292
bool
293-
_dispatch_unote_unregister(dispatch_unote_t du, uint32_t flags)
293+
_dispatch_unote_unregister(dispatch_unote_t du, DISPATCH_UNUSED uint32_t flags)
294294
{
295295
switch (du._du->du_filter) {
296296
case DISPATCH_EVFILT_CUSTOM_ADD:
@@ -313,10 +313,10 @@ _dispatch_unote_unregister(dispatch_unote_t du, uint32_t flags)
313313
dul->du_muxnote = NULL;
314314

315315
if (TAILQ_EMPTY(&dmn->dmn_readers_head)) {
316-
events &= ~EPOLLIN;
316+
events &= (uint32_t)(~EPOLLIN);
317317
}
318318
if (TAILQ_EMPTY(&dmn->dmn_writers_head)) {
319-
events &= ~EPOLLOUT;
319+
events &= (uint32_t)(~EPOLLOUT);
320320
}
321321

322322
if (events == dmn->dmn_events) {
@@ -350,32 +350,32 @@ _dispatch_event_merge_timer(dispatch_clock_t clock)
350350
}
351351

352352
static void
353-
_dispatch_timeout_program(uint32_t tidx, uint64_t target, uint64_t leeway)
353+
_dispatch_timeout_program(uint32_t tidx, uint64_t target, DISPATCH_UNUSED uint64_t leeway)
354354
{
355355
dispatch_clock_t clock = DISPATCH_TIMER_CLOCK(tidx);
356356
dispatch_epoll_timeout_t timer = &_dispatch_epoll_timeout[clock];
357357
struct epoll_event ev = {
358358
.events = EPOLLONESHOT | EPOLLIN,
359359
.data = { .u32 = timer->det_ident },
360360
};
361-
unsigned long op;
361+
int op;
362362

363363
if (target >= INT64_MAX && !timer->det_registered) {
364364
return;
365365
}
366366

367367
if (unlikely(timer->det_fd < 0)) {
368-
clockid_t clock;
368+
clockid_t clockid;
369369
int fd;
370370
switch (DISPATCH_TIMER_CLOCK(tidx)) {
371371
case DISPATCH_CLOCK_MACH:
372-
clock = CLOCK_MONOTONIC;
372+
clockid = CLOCK_MONOTONIC;
373373
break;
374374
case DISPATCH_CLOCK_WALL:
375-
clock = CLOCK_REALTIME;
375+
clockid = CLOCK_REALTIME;
376376
break;
377377
}
378-
fd = timerfd_create(clock, TFD_NONBLOCK | TFD_CLOEXEC);
378+
fd = timerfd_create(clockid, TFD_NONBLOCK | TFD_CLOEXEC);
379379
if (!dispatch_assume(fd >= 0)) {
380380
return;
381381
}
@@ -451,7 +451,7 @@ _dispatch_epoll_init(void *context DISPATCH_UNUSED)
451451
.events = EPOLLIN | EPOLLFREE,
452452
.data = { .u32 = DISPATCH_EPOLL_EVENTFD, },
453453
};
454-
unsigned long op = EPOLL_CTL_ADD;
454+
int op = EPOLL_CTL_ADD;
455455
if (epoll_ctl(_dispatch_epfd, op, _dispatch_eventfd, &ev) < 0) {
456456
DISPATCH_INTERNAL_CRASH(errno, "epoll_ctl() failed");
457457
}

src/event/workqueue.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222

2323
#if DISPATCH_USE_INTERNAL_WORKQUEUE
2424

25-
// forward looking typedef; not yet defined in dispatch
26-
typedef pid_t dispatch_tid;
27-
2825
/*
2926
* dispatch_workq monitors the thread pool that is
3027
* executing the work enqueued on libdispatch's pthread
@@ -88,7 +85,7 @@ _dispatch_workq_worker_register(dispatch_queue_t root_q, qos_class_t cls)
8885
dispatch_qos_t qos = _dispatch_qos_from_qos_class(cls);
8986
dispatch_workq_monitor_t mon = &_dispatch_workq_monitors[qos-1];
9087
dispatch_assert(mon->dq == root_q);
91-
dispatch_tid tid = _dispatch_thread_getspecific(tid);
88+
dispatch_tid tid = _dispatch_tid_self();
9289
_dispatch_unfair_lock_lock(&mon->registered_tid_lock);
9390
dispatch_assert(mon->num_registered_tids < WORKQ_MAX_TRACKED_TIDS-1);
9491
int worker_id = mon->num_registered_tids++;
@@ -103,7 +100,8 @@ _dispatch_workq_worker_unregister(dispatch_queue_t root_q, qos_class_t cls)
103100
#if HAVE_DISPATCH_WORKQ_MONITORING
104101
dispatch_qos_t qos = _dispatch_qos_from_qos_class(cls);
105102
dispatch_workq_monitor_t mon = &_dispatch_workq_monitors[qos-1];
106-
dispatch_tid tid = _dispatch_thread_getspecific(tid);
103+
dispatch_assert(mon->dq == root_q);
104+
dispatch_tid tid = _dispatch_tid_self();
107105
_dispatch_unfair_lock_lock(&mon->registered_tid_lock);
108106
for (int i = 0; i < mon->num_registered_tids; i++) {
109107
if (mon->registered_tids[i] == tid) {
@@ -138,10 +136,10 @@ _dispatch_workq_count_runnable_workers(dispatch_workq_monitor_t mon)
138136
for (int i = 0; i < mon->num_registered_tids; i++) {
139137
dispatch_tid tid = mon->registered_tids[i];
140138
int fd;
141-
size_t bytes_read = -1;
139+
ssize_t bytes_read = -1;
142140

143141
int r = snprintf(path, sizeof(path), "/proc/%d/stat", tid);
144-
dispatch_assert(r > 0 && r < sizeof(path));
142+
dispatch_assert(r > 0 && r < (int)sizeof(path));
145143

146144
fd = open(path, O_RDONLY | O_NONBLOCK);
147145
if (unlikely(fd == -1)) {
@@ -179,7 +177,7 @@ _dispatch_workq_count_runnable_workers(dispatch_workq_monitor_t mon)
179177
static void
180178
_dispatch_workq_monitor_pools(void *context DISPATCH_UNUSED)
181179
{
182-
int global_soft_max = WORKQ_OVERSUBSCRIBE_FACTOR * dispatch_hw_config(active_cpus);
180+
int global_soft_max = WORKQ_OVERSUBSCRIBE_FACTOR * (int)dispatch_hw_config(active_cpus);
183181
int global_runnable = 0;
184182
for (dispatch_qos_t i = DISPATCH_QOS_MAX; i > DISPATCH_QOS_UNSPECIFIED; i--) {
185183
dispatch_workq_monitor_t mon = &_dispatch_workq_monitors[i-1];
@@ -228,7 +226,7 @@ static void
228226
_dispatch_workq_init_once(void *context DISPATCH_UNUSED)
229227
{
230228
#if HAVE_DISPATCH_WORKQ_MONITORING
231-
int target_runnable = dispatch_hw_config(active_cpus);
229+
int target_runnable = (int)dispatch_hw_config(active_cpus);
232230
for (dispatch_qos_t i = DISPATCH_QOS_MAX; i > DISPATCH_QOS_UNSPECIFIED; i--) {
233231
dispatch_workq_monitor_t mon = &_dispatch_workq_monitors[i-1];
234232
mon->dq = _dispatch_get_root_queue(i, false);

src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,13 @@ _dispatch_bug(size_t line, long val)
614614
_dispatch_build, (unsigned long)line, val);
615615
}
616616

617+
#if HAVE_MACH
617618
void
618619
_dispatch_bug_client(const char* msg)
619620
{
620621
_dispatch_bug_log("BUG in libdispatch client: %s", msg);
621622
}
622623

623-
#if HAVE_MACH
624624
void
625625
_dispatch_bug_mach_client(const char* msg, mach_msg_return_t kr)
626626
{

src/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ void _dispatch_log(const char *msg, ...);
466466
} \
467467
} while (0)
468468
#else
469-
static inline void _dispatch_assert(long e, long line) {
469+
static inline void _dispatch_assert(long e, size_t line) {
470470
if (DISPATCH_DEBUG && !e) _dispatch_abort(line, e);
471471
}
472472
#define dispatch_assert(e) _dispatch_assert((long)(e), __LINE__)
@@ -488,7 +488,7 @@ static inline void _dispatch_assert(long e, long line) {
488488
} \
489489
} while (0)
490490
#else
491-
static inline void _dispatch_assert_zero(long e, long line) {
491+
static inline void _dispatch_assert_zero(long e, size_t line) {
492492
if (DISPATCH_DEBUG && e) _dispatch_abort(line, e);
493493
}
494494
#define dispatch_assert_zero(e) _dispatch_assert_zero((long)(e), __LINE__)

src/io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#endif
2626

2727
#ifndef PAGE_SIZE
28-
#define PAGE_SIZE getpagesize()
28+
#define PAGE_SIZE ((size_t)getpagesize())
2929
#endif
3030

3131
#if DISPATCH_DATA_IS_BRIDGED_TO_NSDATA
@@ -1372,7 +1372,7 @@ _dispatch_fd_entry_create_with_fd(dispatch_fd_t fd, uintptr_t hash)
13721372
break;
13731373
);
13741374
}
1375-
int32_t dev = major(st.st_dev);
1375+
dev_t dev = major(st.st_dev);
13761376
// We have to get the disk on the global dev queue. The
13771377
// barrier queue cannot continue until that is complete
13781378
dispatch_suspend(fd_entry->barrier_queue);
@@ -2167,7 +2167,7 @@ _dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
21672167
op->advise_offset += advise.ra_count;
21682168
#ifdef __linux__
21692169
_dispatch_io_syscall_switch(err,
2170-
readahead(op->fd_entry->fd, advise.ra_offset, advise.ra_count),
2170+
readahead(op->fd_entry->fd, advise.ra_offset, (size_t)advise.ra_count),
21712171
case EINVAL: break; // fd does refer to a non-supported filetype
21722172
default: (void)dispatch_assume_zero(err); break;
21732173
);

src/queue.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,7 @@ _dispatch_root_queue_push(dispatch_queue_t rq, dispatch_object_t dou,
53305330
return _dispatch_root_queue_push_override(rq, dou, qos);
53315331
}
53325332
#endif
5333+
(void)qos;
53335334
_dispatch_root_queue_push_inline(rq, dou, dou, 1);
53345335
}
53355336

@@ -5870,7 +5871,7 @@ _dispatch_worker_thread(void *context)
58705871

58715872
#if DISPATCH_USE_INTERNAL_WORKQUEUE
58725873
if (monitored) {
5873-
_dispatch_workq_worker_unregister(dq, qc->dgq_qos);
5874+
_dispatch_workq_worker_unregister(dq, qc->dgq_qos);
58745875
}
58755876
#endif
58765877
(void)os_atomic_inc2o(qc, dgq_thread_pool_size, release);
@@ -5962,6 +5963,7 @@ _dispatch_runloop_root_queue_wakeup_4CF(dispatch_queue_t dq)
59625963
_dispatch_runloop_queue_wakeup(dq, 0, false);
59635964
}
59645965

5966+
#if TARGET_OS_MAC
59655967
dispatch_runloop_handle_t
59665968
_dispatch_runloop_root_queue_get_port_4CF(dispatch_queue_t dq)
59675969
{
@@ -5970,6 +5972,7 @@ _dispatch_runloop_root_queue_get_port_4CF(dispatch_queue_t dq)
59705972
}
59715973
return _dispatch_runloop_queue_get_handle(dq);
59725974
}
5975+
#endif
59735976

59745977
static void
59755978
_dispatch_runloop_queue_handle_init(void *ctxt)
@@ -6218,6 +6221,7 @@ DISPATCH_NORETURN
62186221
static void
62196222
_dispatch_deferred_items_cleanup(void *ctxt)
62206223
{
6224+
(void)ctxt;
62216225
// POSIX defines that destructors are only called if 'ctxt' is non-null
62226226
DISPATCH_INTERNAL_CRASH(ctxt,
62236227
"Premature thread exit with unhandled deferred items");
@@ -6227,6 +6231,7 @@ DISPATCH_NORETURN
62276231
static void
62286232
_dispatch_frame_cleanup(void *ctxt)
62296233
{
6234+
(void)ctxt;
62306235
// POSIX defines that destructors are only called if 'ctxt' is non-null
62316236
DISPATCH_INTERNAL_CRASH(ctxt,
62326237
"Premature thread exit while a dispatch frame is active");
@@ -6236,6 +6241,7 @@ DISPATCH_NORETURN
62366241
static void
62376242
_dispatch_context_cleanup(void *ctxt)
62386243
{
6244+
(void)ctxt;
62396245
// POSIX defines that destructors are only called if 'ctxt' is non-null
62406246
DISPATCH_INTERNAL_CRASH(ctxt,
62416247
"Premature thread exit while a dispatch context is set");

src/shims/hw_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
101101
switch (c) {
102102
case _dispatch_hw_config_logical_cpus:
103103
case _dispatch_hw_config_physical_cpus:
104-
return sysconf(_SC_NPROCESSORS_CONF);
104+
return (uint32_t)sysconf(_SC_NPROCESSORS_CONF);
105105
case _dispatch_hw_config_active_cpus:
106106
{
107107
#ifdef __USE_GNU
@@ -110,9 +110,9 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
110110
// is restricted to a subset of the online cpus (eg via numactl).
111111
cpu_set_t cpuset;
112112
if (pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) == 0)
113-
return CPU_COUNT(&cpuset);
113+
return (uint32_t)CPU_COUNT(&cpuset);
114114
#endif
115-
return sysconf(_SC_NPROCESSORS_ONLN);
115+
return (uint32_t)sysconf(_SC_NPROCESSORS_ONLN);
116116
}
117117
}
118118
#else

0 commit comments

Comments
 (0)