Skip to content

fixes to src to prep for enabling additional compiler warnings #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2017

Conversation

dgrove-oss
Copy link
Contributor

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.

@dgrove-oss
Copy link
Contributor Author

happy to adjust based on feedback. I've mainly gone with local fixes/casts to resolve the warnings and tried to avoid changing very much cross-platform code. This might not always have been the right thing to do...

@dgrove-oss dgrove-oss force-pushed the match-darwin-cflags-round1 branch from 2cd7124 to e6030f1 Compare July 6, 2017 13:11
@dgrove-oss dgrove-oss changed the title fixes for compiler warnings fixes to src to prep for enabling additional compiler warnings Jul 6, 2017
@@ -89,12 +89,12 @@ _dispatch_muxnote_bucket(int ident)
return &_dispatch_sources[DSL_HASH((uint32_t)ident)];
}
#define _dispatch_unote_muxnote_bucket(du) \
_dispatch_muxnote_bucket(du._du->du_ident)
_dispatch_muxnote_bucket((int)du._du->du_ident)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think _dispatch_muxnote_bucket() argument type should take a uint32_t instead.


DISPATCH_ALWAYS_INLINE
static inline dispatch_muxnote_t
_dispatch_muxnote_find(struct dispatch_muxnote_bucket_s *dmb,
uint64_t ident, int16_t filter)
int ident, int16_t filter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int seems the wrong type since it forces a cast at the call site, why int?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a cast somewhere on this call path because dmn_ident is an int (makes since since file descriptors are ints), but du_ident is an uint32_t.

I can push the cast down to the == compare instead of bubbling it up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my worry is that signed stuff for a hash table is a bad idea. Moving to uint32_t would be fine fWIW. and the reason for uint32_t for du_identis because it's unsigned on Darwin because of kevent and it'll be hell if we change signedness of this field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I changed dmn_ident to be a uint32_t for the epoll backend.

int16_t filter = du._du->du_filter;
bool socket_listener = false;
sigset_t sigmask;

switch (filter) {
case EVFILT_SIGNAL:
if (!sigismember(&signals_with_unotes, du._du->du_ident)) {
if (!sigismember(&signals_with_unotes, (int)du._du->du_ident)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would take a temporary int signo = (int)du._du->du_ident which would make it clearer in the first place and avoid that many ugly casts

@@ -343,32 +343,32 @@ _dispatch_event_merge_timer(dispatch_clock_t clock)
}

static void
_dispatch_timeout_program(uint32_t tidx, uint64_t target, uint64_t leeway)
_dispatch_timeout_program(uint32_t tidx, uint64_t target, DISPATCH_UNUSED uint64_t leeway)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80 columns (?) you need to wrap

src/init.c Outdated
@@ -614,13 +614,13 @@ _dispatch_bug(size_t line, long val)
_dispatch_build, (unsigned long)line, val);
}

#if HAVE_MACH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems wrong, are you sure it's never used on linux ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prototype in internal.h is already guarded this way, but agree that that seems wrong. This is currently only used in event_kevent.c (so could be guarded by DISPATCH_EVENT_BACKEND_KEVENT) but it is really intended to be a generic facility that can be used anywhere, so the better fix is probably to remove the ifdef of the prototype in internal.h

src/internal.h Outdated
@@ -466,7 +466,7 @@ void _dispatch_log(const char *msg, ...);
} \
} while (0)
#else
static inline void _dispatch_assert(long e, long line) {
static inline void _dispatch_assert(long e, size_t line) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you fix the style while at it, it's unlike the rest of dispatch, it should be:

static inline void
_dispatch_assert(long e, size_t line)
{

thanks

src/internal.h Outdated
@@ -488,7 +488,7 @@ static inline void _dispatch_assert(long e, long line) {
} \
} while (0)
#else
static inline void _dispatch_assert_zero(long e, long line) {
static inline void _dispatch_assert_zero(long e, size_t line) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/io.c Outdated
@@ -2167,7 +2167,7 @@ _dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
op->advise_offset += advise.ra_count;
#ifdef __linux__
_dispatch_io_syscall_switch(err,
readahead(op->fd_entry->fd, advise.ra_offset, advise.ra_count),
readahead(op->fd_entry->fd, advise.ra_offset, (size_t)advise.ra_count),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that indent seems wrong :)

src/queue.c Outdated
@@ -5330,6 +5330,7 @@ _dispatch_root_queue_push(dispatch_queue_t rq, dispatch_object_t dou,
return _dispatch_root_queue_push_override(rq, dou, qos);
}
#endif
(void)qos;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please inside a #else instead

src/queue.c Outdated
@@ -6218,6 +6221,7 @@ DISPATCH_NORETURN
static void
_dispatch_deferred_items_cleanup(void *ctxt)
{
(void)ctxt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think DISPATCH_INTERNAL_CRASH should ((void)(ac)) instead to avoid this

src/voucher.c Outdated
@@ -1550,12 +1550,14 @@ _voucher_create_accounting_voucher(voucher_t voucher)
return NULL;
}

#if __has_include(<mach/mach.h>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be HAVE_MACH, that matches the guards of this type

src/data.c Outdated
@@ -129,6 +129,9 @@ static void
_dispatch_data_destroy_buffer(const void* buffer, size_t size,
dispatch_queue_t queue, dispatch_block_t destructor)
{
#if !HAVE_MACH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nicer as an #else to the #if HAVE_MACH below

src/init.c Outdated
@@ -614,13 +614,13 @@ _dispatch_bug(size_t line, long val)
_dispatch_build, (unsigned long)line, val);
}

#if HAVE_MACH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prototype in internal.h is already guarded this way, but agree that that seems wrong. This is currently only used in event_kevent.c (so could be guarded by DISPATCH_EVENT_BACKEND_KEVENT) but it is really intended to be a generic facility that can be used anywhere, so the better fix is probably to remove the ifdef of the prototype in internal.h

@dgrove-oss
Copy link
Contributor Author

Thanks for the comments; I will revise/rebase and let you know when it is ready for second review (was out on vacation last week...)

@dgrove-oss dgrove-oss force-pushed the match-darwin-cflags-round1 branch 2 times, most recently from 9d64682 to 6a3f928 Compare July 18, 2017 20:12
@dgrove-oss
Copy link
Contributor Author

updated to address comments, rebased to tip of master, & squashed. Ready for you to look at again.

}
sigemptyset(&sigmask);
sigaddset(&sigmask, du._du->du_ident);
sigaddset(&sigmask, (int)du._du->du_ident);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signo ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, missed that one. fixed.

Copy link
Contributor

@das das left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

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 initial
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.
@dgrove-oss dgrove-oss force-pushed the match-darwin-cflags-round1 branch from 6a3f928 to 03cd694 Compare July 21, 2017 00:06
@das
Copy link
Contributor

das commented Jul 24, 2017

@swift-ci please test

@das das merged commit 698d085 into swiftlang:master Jul 24, 2017
@dgrove-oss dgrove-oss deleted the match-darwin-cflags-round1 branch July 25, 2017 12:40
das added a commit that referenced this pull request Jul 31, 2017
fixes to src to prep for enabling additional compiler warnings

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
@das das removed the darwin pending label Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants