diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 69709f88502..93291a174da 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -179,6 +179,7 @@ #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif +#define GPR_MSG_IOVLEN_TYPE int #if TARGET_OS_IPHONE #define GPR_PLATFORM_STRING "ios" #define GPR_CPU_IPHONE 1 diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index f1bc60ba4e9..cae260cab0b 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -101,7 +101,8 @@ static void multipoll_with_poll_pollset_maybe_work( gpr_timespec now, int allow_synchronous_callback) { int timeout; int r; - size_t i, j, pfd_count, fd_count; + size_t i, j, fd_count; + nfds_t pfd_count; pollset_hdr *h; /* TODO(ctiller): inline some elements to avoid an allocation */ grpc_fd_watcher *watchers; diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index 81f04494eb5..68f469c3681 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -61,6 +61,12 @@ #define SENDMSG_FLAGS 0 #endif +#ifdef GPR_MSG_IOVLEN_TYPE +typedef GPR_MSG_IOVLEN_TYPE msg_iovlen_type; +#else +typedef size_t msg_iovlen_type; +#endif + int grpc_tcp_trace = 0; typedef struct { @@ -68,7 +74,7 @@ typedef struct { grpc_fd *em_fd; int fd; int finished_edge; - size_t iov_size; /* Number of slices to allocate per read attempt */ + msg_iovlen_type iov_size; /* Number of slices to allocate per read attempt */ size_t slice_size; gpr_refcount refcount; @@ -265,7 +271,7 @@ static grpc_endpoint_op_status tcp_read(grpc_endpoint *ep, static grpc_endpoint_op_status tcp_flush(grpc_tcp *tcp) { struct msghdr msg; struct iovec iov[MAX_WRITE_IOVEC]; - size_t iov_size; + msg_iovlen_type iov_size; ssize_t sent_length; size_t sending_length; size_t trailing; diff --git a/src/core/support/cpu_posix.c b/src/core/support/cpu_posix.c index 99484e37fbc..55d92c0555f 100644 --- a/src/core/support/cpu_posix.c +++ b/src/core/support/cpu_posix.c @@ -44,11 +44,11 @@ static __thread char magic_thread_local; -static int ncpus = 0; +static long ncpus = 0; static void init_ncpus() { ncpus = sysconf(_SC_NPROCESSORS_ONLN); - if (ncpus < 1) { + if (ncpus < 1 || ncpus > GPR_UINT32_MAX) { gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1"); ncpus = 1; } @@ -57,7 +57,7 @@ static void init_ncpus() { unsigned gpr_cpu_num_cores(void) { static gpr_once once = GPR_ONCE_INIT; gpr_once_init(&once, init_ncpus); - return ncpus; + return (unsigned)ncpus; } /* This is a cheap, but good enough, pointer hash for sharding things: */ @@ -71,7 +71,7 @@ unsigned gpr_cpu_current_cpu(void) { most code that's using this is using it to shard across work queues though, so here we use thread identity instead to achieve a similar though not identical effect */ - return shard_ptr(&magic_thread_local); + return (unsigned)shard_ptr(&magic_thread_local); } #endif /* GPR_CPU_POSIX */ diff --git a/src/core/support/log_posix.c b/src/core/support/log_posix.c index 940ee20f151..021c4666d41 100644 --- a/src/core/support/log_posix.c +++ b/src/core/support/log_posix.c @@ -62,7 +62,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity, } else if ((size_t)ret <= sizeof(buf) - 1) { message = buf; } else { - message = allocated = gpr_malloc(ret + 1); + message = allocated = gpr_malloc((size_t)ret + 1); va_start(args, format); vsnprintf(message, ret + 1, format, args); va_end(args); diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index a2744002437..dcecff0d05d 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -108,8 +108,8 @@ gpr_timespec gpr_now(gpr_clock_type clock) { break; case GPR_CLOCK_MONOTONIC: now_dbl = (mach_absolute_time() - g_time_start) * g_time_scale; - now.tv_sec = now_dbl * 1e-9; - now.tv_nsec = now_dbl - now.tv_sec * 1e9; + now.tv_sec = (time_t)(now_dbl * 1e-9); + now.tv_nsec = (int)(now_dbl - ((double)now.tv_sec) * 1e9); break; case GPR_CLOCK_PRECISE: gpr_precise_clock_now(&now);