Skip to content

Commit e6030f1

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 602604c commit e6030f1

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
@@ -89,12 +89,12 @@ _dispatch_muxnote_bucket(int ident)
8989
return &_dispatch_sources[DSL_HASH((uint32_t)ident)];
9090
}
9191
#define _dispatch_unote_muxnote_bucket(du) \
92-
_dispatch_muxnote_bucket(du._du->du_ident)
92+
_dispatch_muxnote_bucket((int)du._du->du_ident)
9393

9494
DISPATCH_ALWAYS_INLINE
9595
static inline dispatch_muxnote_t
9696
_dispatch_muxnote_find(struct dispatch_muxnote_bucket_s *dmb,
97-
uint64_t ident, int16_t filter)
97+
int ident, int16_t filter)
9898
{
9999
dispatch_muxnote_t dmn;
100100
if (filter == EVFILT_WRITE) filter = EVFILT_READ;
@@ -106,7 +106,7 @@ _dispatch_muxnote_find(struct dispatch_muxnote_bucket_s *dmb,
106106
return dmn;
107107
}
108108
#define _dispatch_unote_muxnote_find(dmb, du) \
109-
_dispatch_muxnote_find(dmb, du._du->du_ident, du._du->du_filter)
109+
_dispatch_muxnote_find(dmb, (int)du._du->du_ident, du._du->du_filter)
110110

111111
static void
112112
_dispatch_muxnote_dispose(dispatch_muxnote_t dmn)
@@ -141,20 +141,20 @@ _dispatch_muxnote_create(dispatch_unote_t du, uint32_t events)
141141

142142
dispatch_muxnote_t dmn;
143143
struct stat sb;
144-
int fd = du._du->du_ident;
144+
int fd = (int)du._du->du_ident;
145145
int16_t filter = du._du->du_filter;
146146
bool socket_listener = false;
147147
sigset_t sigmask;
148148

149149
switch (filter) {
150150
case EVFILT_SIGNAL:
151-
if (!sigismember(&signals_with_unotes, du._du->du_ident)) {
151+
if (!sigismember(&signals_with_unotes, (int)du._du->du_ident)) {
152152
manager_thread = pthread_self();
153-
sigaddset(&signals_with_unotes, du._du->du_ident);
154-
sigaction(du._du->du_ident, &sa, NULL);
153+
sigaddset(&signals_with_unotes, (int)du._du->du_ident);
154+
sigaction((int)du._du->du_ident, &sa, NULL);
155155
}
156156
sigemptyset(&sigmask);
157-
sigaddset(&sigmask, du._du->du_ident);
157+
sigaddset(&sigmask, (int)du._du->du_ident);
158158
fd = signalfd(-1, &sigmask, SFD_NONBLOCK | SFD_CLOEXEC);
159159
if (fd < 0) {
160160
return NULL;
@@ -190,7 +190,7 @@ _dispatch_muxnote_create(dispatch_unote_t du, uint32_t events)
190190
TAILQ_INIT(&dmn->dmn_readers_head);
191191
TAILQ_INIT(&dmn->dmn_writers_head);
192192
dmn->dmn_fd = fd;
193-
dmn->dmn_ident = du._du->du_ident;
193+
dmn->dmn_ident = (int)du._du->du_ident;
194194
dmn->dmn_filter = filter;
195195
dmn->dmn_events = events;
196196
dmn->dmn_socket_listener = socket_listener;
@@ -284,7 +284,7 @@ _dispatch_unote_resume(dispatch_unote_t du)
284284
}
285285

286286
bool
287-
_dispatch_unote_unregister(dispatch_unote_t du, uint32_t flags)
287+
_dispatch_unote_unregister(dispatch_unote_t du, DISPATCH_UNUSED uint32_t flags)
288288
{
289289
switch (du._du->du_filter) {
290290
case DISPATCH_EVFILT_CUSTOM_ADD:
@@ -307,10 +307,10 @@ _dispatch_unote_unregister(dispatch_unote_t du, uint32_t flags)
307307
dul->du_muxnote = NULL;
308308

309309
if (TAILQ_EMPTY(&dmn->dmn_readers_head)) {
310-
events &= ~EPOLLIN;
310+
events &= (uint32_t)(~EPOLLIN);
311311
}
312312
if (TAILQ_EMPTY(&dmn->dmn_writers_head)) {
313-
events &= ~EPOLLOUT;
313+
events &= (uint32_t)(~EPOLLOUT);
314314
}
315315

316316
if (events == dmn->dmn_events) {
@@ -343,32 +343,32 @@ _dispatch_event_merge_timer(dispatch_clock_t clock)
343343
}
344344

345345
static void
346-
_dispatch_timeout_program(uint32_t tidx, uint64_t target, uint64_t leeway)
346+
_dispatch_timeout_program(uint32_t tidx, uint64_t target, DISPATCH_UNUSED uint64_t leeway)
347347
{
348348
dispatch_clock_t clock = DISPATCH_TIMER_CLOCK(tidx);
349349
dispatch_epoll_timeout_t timer = &_dispatch_epoll_timeout[clock];
350350
struct epoll_event ev = {
351351
.events = EPOLLONESHOT | EPOLLIN,
352352
.data = { .u32 = timer->det_ident },
353353
};
354-
unsigned long op;
354+
int op;
355355

356356
if (target >= INT64_MAX && !timer->det_registered) {
357357
return;
358358
}
359359

360360
if (unlikely(timer->det_fd < 0)) {
361-
clockid_t clock;
361+
clockid_t clockid;
362362
int fd;
363363
switch (DISPATCH_TIMER_CLOCK(tidx)) {
364364
case DISPATCH_CLOCK_MACH:
365-
clock = CLOCK_MONOTONIC;
365+
clockid = CLOCK_MONOTONIC;
366366
break;
367367
case DISPATCH_CLOCK_WALL:
368-
clock = CLOCK_REALTIME;
368+
clockid = CLOCK_REALTIME;
369369
break;
370370
}
371-
fd = timerfd_create(clock, TFD_NONBLOCK | TFD_CLOEXEC);
371+
fd = timerfd_create(clockid, TFD_NONBLOCK | TFD_CLOEXEC);
372372
if (!dispatch_assume(fd >= 0)) {
373373
return;
374374
}
@@ -444,7 +444,7 @@ _dispatch_epoll_init(void *context DISPATCH_UNUSED)
444444
.events = EPOLLIN | EPOLLFREE,
445445
.data = { .u32 = DISPATCH_EPOLL_EVENTFD, },
446446
};
447-
unsigned long op = EPOLL_CTL_ADD;
447+
int op = EPOLL_CTL_ADD;
448448
if (epoll_ctl(_dispatch_epfd, op, _dispatch_eventfd, &ev) < 0) {
449449
DISPATCH_INTERNAL_CRASH(errno, "epoll_ctl() failed");
450450
}

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)