aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-06-23 16:26:18 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-06-23 16:26:18 -0700
commit009886cf79bd4bf53049633ef7797eb63be30b68 (patch)
treeacf2de7539d7b49cb35f174c25100a4d6b644d23 /src/core
parentaf691804781f4e546c806b98ca8b05e2370e61f8 (diff)
parent6b4fc31f08b9a61a90262379072cffea0bc39795 (diff)
Merge github.com:grpc/grpc into that-which-we-call-a-rose
Conflicts: gRPC.podspec tools/doxygen/Doxyfile.core.internal
Diffstat (limited to 'src/core')
-rw-r--r--src/core/iomgr/pollset.h5
-rw-r--r--src/core/iomgr/pollset_multipoller_with_epoll.c3
-rw-r--r--src/core/iomgr/pollset_multipoller_with_poll_posix.c8
-rw-r--r--src/core/iomgr/pollset_posix.c16
-rw-r--r--src/core/iomgr/pollset_posix.h4
-rw-r--r--src/core/iomgr/pollset_windows.c13
-rw-r--r--src/core/iomgr/pollset_windows.h8
-rw-r--r--src/core/json/json_reader.c12
-rw-r--r--src/core/json/json_string.c22
-rw-r--r--src/core/json/json_writer.c14
-rw-r--r--src/core/security/base64.c10
-rw-r--r--src/core/security/secure_endpoint.c14
-rw-r--r--src/core/security/secure_transport_setup.c2
-rw-r--r--src/core/security/security_connector.c41
-rw-r--r--src/core/security/security_connector.h3
-rw-r--r--src/core/security/server_secure_chttp2.c4
-rw-r--r--src/core/support/cmdline.c6
-rw-r--r--src/core/support/cpu_linux.c8
-rw-r--r--src/core/support/file.c3
-rw-r--r--src/core/support/histogram.c6
-rw-r--r--src/core/support/host_port.c4
-rw-r--r--src/core/support/murmur_hash.c14
-rw-r--r--src/core/support/slice.c28
-rw-r--r--src/core/support/slice_buffer.c8
-rw-r--r--src/core/support/string.c6
-rw-r--r--src/core/support/subprocess_posix.c4
-rw-r--r--src/core/support/time.c16
-rw-r--r--src/core/support/time_posix.c2
-rw-r--r--src/core/surface/call.c11
-rw-r--r--src/core/transport/stream_op.c58
-rw-r--r--src/core/transport/stream_op.h47
31 files changed, 222 insertions, 178 deletions
diff --git a/src/core/iomgr/pollset.h b/src/core/iomgr/pollset.h
index 7472b6144f..c40188b3c9 100644
--- a/src/core/iomgr/pollset.h
+++ b/src/core/iomgr/pollset.h
@@ -62,7 +62,10 @@ void grpc_pollset_destroy(grpc_pollset *pollset);
May involve invoking asynchronous callbacks, or actually polling file
descriptors.
Requires GRPC_POLLSET_MU(pollset) locked.
- May unlock GRPC_POLLSET_MU(pollset) during its execution. */
+ May unlock GRPC_POLLSET_MU(pollset) during its execution.
+
+ Returns true if some work has been done, and false if the deadline
+ got attained. */
int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline);
/* Break one polling thread out of polling work for this pollset.
diff --git a/src/core/iomgr/pollset_multipoller_with_epoll.c b/src/core/iomgr/pollset_multipoller_with_epoll.c
index b4a526b9e7..dcf08d379c 100644
--- a/src/core/iomgr/pollset_multipoller_with_epoll.c
+++ b/src/core/iomgr/pollset_multipoller_with_epoll.c
@@ -83,7 +83,7 @@ static void multipoll_with_epoll_pollset_del_fd(grpc_pollset *pollset,
/* TODO(klempner): We probably want to turn this down a bit */
#define GRPC_EPOLL_MAX_EVENTS 1000
-static int multipoll_with_epoll_pollset_maybe_work(
+static void multipoll_with_epoll_pollset_maybe_work(
grpc_pollset *pollset, gpr_timespec deadline, gpr_timespec now,
int allow_synchronous_callback) {
struct epoll_event ep_ev[GRPC_EPOLL_MAX_EVENTS];
@@ -133,7 +133,6 @@ static int multipoll_with_epoll_pollset_maybe_work(
gpr_mu_lock(&pollset->mu);
pollset->counter -= 1;
- return 1;
}
static void multipoll_with_epoll_pollset_finish_shutdown(
diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c
index 2f108da66a..cc062693a9 100644
--- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c
+++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c
@@ -103,7 +103,7 @@ static void end_polling(grpc_pollset *pollset) {
}
}
-static int multipoll_with_poll_pollset_maybe_work(
+static void multipoll_with_poll_pollset_maybe_work(
grpc_pollset *pollset, gpr_timespec deadline, gpr_timespec now,
int allow_synchronous_callback) {
int timeout;
@@ -126,7 +126,7 @@ static int multipoll_with_poll_pollset_maybe_work(
kfd = grpc_pollset_kick_pre_poll(&pollset->kick_state);
if (kfd == NULL) {
/* Already kicked */
- return 1;
+ return;
}
h->pfds[0].fd = GRPC_POLLSET_KICK_GET_FD(kfd);
h->pfds[0].events = POLLIN;
@@ -154,7 +154,7 @@ static int multipoll_with_poll_pollset_maybe_work(
h->del_count = 0;
if (h->pfd_count == 0) {
end_polling(pollset);
- return 0;
+ return;
}
pollset->counter++;
gpr_mu_unlock(&pollset->mu);
@@ -191,8 +191,6 @@ static int multipoll_with_poll_pollset_maybe_work(
gpr_mu_lock(&pollset->mu);
pollset->counter--;
-
- return 1;
}
static void multipoll_with_poll_pollset_kick(grpc_pollset *p) {
diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c
index 46d3d132ce..15ed8e75e6 100644
--- a/src/core/iomgr/pollset_posix.c
+++ b/src/core/iomgr/pollset_posix.c
@@ -123,7 +123,6 @@ static void finish_shutdown(grpc_pollset *pollset) {
int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
/* pollset->mu already held */
gpr_timespec now = gpr_now();
- int r;
if (gpr_time_cmp(now, deadline) > 0) {
return 0;
}
@@ -137,7 +136,7 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
return 1;
}
gpr_tls_set(&g_current_thread_poller, (gpr_intptr)pollset);
- r = pollset->vtable->maybe_work(pollset, deadline, now, 1);
+ pollset->vtable->maybe_work(pollset, deadline, now, 1);
gpr_tls_set(&g_current_thread_poller, 0);
if (pollset->shutting_down) {
if (pollset->counter > 0) {
@@ -153,7 +152,7 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
gpr_mu_lock(&pollset->mu);
}
}
- return r;
+ return 1;
}
void grpc_pollset_shutdown(grpc_pollset *pollset,
@@ -338,9 +337,9 @@ static void basic_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) {
}
}
-static int basic_pollset_maybe_work(grpc_pollset *pollset,
- gpr_timespec deadline, gpr_timespec now,
- int allow_synchronous_callback) {
+static void basic_pollset_maybe_work(grpc_pollset *pollset,
+ gpr_timespec deadline, gpr_timespec now,
+ int allow_synchronous_callback) {
struct pollfd pfd[2];
grpc_fd *fd;
grpc_fd_watcher fd_watcher;
@@ -353,7 +352,7 @@ static int basic_pollset_maybe_work(grpc_pollset *pollset,
/* Give do_promote priority so we don't starve it out */
gpr_mu_unlock(&pollset->mu);
gpr_mu_lock(&pollset->mu);
- return 1;
+ return;
}
fd = pollset->data.ptr;
if (fd && grpc_fd_is_orphaned(fd)) {
@@ -364,7 +363,7 @@ static int basic_pollset_maybe_work(grpc_pollset *pollset,
kfd = grpc_pollset_kick_pre_poll(&pollset->kick_state);
if (kfd == NULL) {
/* Already kicked */
- return 1;
+ return;
}
pfd[0].fd = GRPC_POLLSET_KICK_GET_FD(kfd);
pfd[0].events = POLLIN;
@@ -418,7 +417,6 @@ static int basic_pollset_maybe_work(grpc_pollset *pollset,
gpr_mu_lock(&pollset->mu);
pollset->counter--;
- return 1;
}
static void basic_pollset_destroy(grpc_pollset *pollset) {
diff --git a/src/core/iomgr/pollset_posix.h b/src/core/iomgr/pollset_posix.h
index ba3d638d41..53585a2886 100644
--- a/src/core/iomgr/pollset_posix.h
+++ b/src/core/iomgr/pollset_posix.h
@@ -68,8 +68,8 @@ typedef struct grpc_pollset {
struct grpc_pollset_vtable {
void (*add_fd)(grpc_pollset *pollset, struct grpc_fd *fd);
void (*del_fd)(grpc_pollset *pollset, struct grpc_fd *fd);
- int (*maybe_work)(grpc_pollset *pollset, gpr_timespec deadline,
- gpr_timespec now, int allow_synchronous_callback);
+ void (*maybe_work)(grpc_pollset *pollset, gpr_timespec deadline,
+ gpr_timespec now, int allow_synchronous_callback);
void (*kick)(grpc_pollset *pollset);
void (*finish_shutdown)(grpc_pollset *pollset);
void (*destroy)(grpc_pollset *pollset);
diff --git a/src/core/iomgr/pollset_windows.c b/src/core/iomgr/pollset_windows.c
index 9deb0fa8fa..d0507af960 100644
--- a/src/core/iomgr/pollset_windows.c
+++ b/src/core/iomgr/pollset_windows.c
@@ -46,7 +46,10 @@
set of features for the sake of the rest of grpc. But grpc_pollset_work
won't actually do any polling, and return as quickly as possible. */
-void grpc_pollset_init(grpc_pollset *pollset) { gpr_mu_init(&pollset->mu); }
+void grpc_pollset_init(grpc_pollset *pollset) {
+ gpr_mu_init(&pollset->mu);
+ gpr_cv_init(&pollset->cv);
+}
void grpc_pollset_shutdown(grpc_pollset *pollset,
void (*shutdown_done)(void *arg),
@@ -56,6 +59,7 @@ void grpc_pollset_shutdown(grpc_pollset *pollset,
void grpc_pollset_destroy(grpc_pollset *pollset) {
gpr_mu_destroy(&pollset->mu);
+ gpr_cv_destroy(&pollset->cv);
}
int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
@@ -70,9 +74,12 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
if (grpc_alarm_check(NULL, now, &deadline)) {
return 1 /* GPR_TRUE */;
}
- return 0 /* GPR_FALSE */;
+ gpr_cv_wait(&pollset->cv, &pollset->mu, deadline);
+ return 1 /* GPR_TRUE */;
}
-void grpc_pollset_kick(grpc_pollset *p) {}
+void grpc_pollset_kick(grpc_pollset *p) {
+ gpr_cv_signal(&p->cv);
+}
#endif /* GPR_WINSOCK_SOCKET */
diff --git a/src/core/iomgr/pollset_windows.h b/src/core/iomgr/pollset_windows.h
index cbbd9efdd1..b4aec1b809 100644
--- a/src/core/iomgr/pollset_windows.h
+++ b/src/core/iomgr/pollset_windows.h
@@ -41,10 +41,12 @@
/* There isn't really any such thing as a pollset under Windows, due to the
nature of the IO completion ports. A Windows "pollset" is merely a mutex
- and a condition variable, as this is the minimal set of features we need
- implemented for the rest of grpc. But we won't use them directly. */
+ and a condition variable, used to synchronize with the IOCP. */
-typedef struct grpc_pollset { gpr_mu mu; } grpc_pollset;
+typedef struct grpc_pollset {
+ gpr_mu mu;
+ gpr_cv cv;
+} grpc_pollset;
#define GRPC_POLLSET_MU(pollset) (&(pollset)->mu)
diff --git a/src/core/json/json_reader.c b/src/core/json/json_reader.c
index 5ea4e9569c..c14094c290 100644
--- a/src/core/json/json_reader.c
+++ b/src/core/json/json_reader.c
@@ -151,7 +151,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
case GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL:
case GRPC_JSON_STATE_VALUE_NUMBER_ZERO:
case GRPC_JSON_STATE_VALUE_NUMBER_EPM:
- success = json_reader_set_number(reader);
+ success = (gpr_uint32)json_reader_set_number(reader);
if (!success) return GRPC_JSON_PARSE_ERROR;
json_reader_string_clear(reader);
reader->state = GRPC_JSON_STATE_VALUE_END;
@@ -177,7 +177,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
case GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL:
case GRPC_JSON_STATE_VALUE_NUMBER_ZERO:
case GRPC_JSON_STATE_VALUE_NUMBER_EPM:
- success = json_reader_set_number(reader);
+ success = (gpr_uint32)json_reader_set_number(reader);
if (!success) return GRPC_JSON_PARSE_ERROR;
json_reader_string_clear(reader);
reader->state = GRPC_JSON_STATE_VALUE_END;
@@ -410,8 +410,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
} else {
return GRPC_JSON_PARSE_ERROR;
}
- reader->unicode_char <<= 4;
- reader->unicode_char |= c;
+ reader->unicode_char = (gpr_uint16)(reader->unicode_char << 4);
+ reader->unicode_char = (gpr_uint16)(reader->unicode_char | c);
switch (reader->state) {
case GRPC_JSON_STATE_STRING_ESCAPE_U1:
@@ -438,8 +438,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
if (reader->unicode_high_surrogate == 0)
return GRPC_JSON_PARSE_ERROR;
utf32 = 0x10000;
- utf32 += (reader->unicode_high_surrogate - 0xd800) * 0x400;
- utf32 += reader->unicode_char - 0xdc00;
+ utf32 += (gpr_uint32)((reader->unicode_high_surrogate - 0xd800) * 0x400);
+ utf32 += (gpr_uint32)(reader->unicode_char - 0xdc00);
json_reader_string_add_utf32(reader, utf32);
reader->unicode_high_surrogate = 0;
} else {
diff --git a/src/core/json/json_string.c b/src/core/json/json_string.c
index 13f816995b..03c1099167 100644
--- a/src/core/json/json_string.c
+++ b/src/core/json/json_string.c
@@ -83,7 +83,7 @@ static void json_writer_output_check(void* userdata, size_t needed) {
if (state->free_space >= needed) return;
needed -= state->free_space;
/* Round up by 256 bytes. */
- needed = (needed + 0xff) & ~0xff;
+ needed = (needed + 0xff) & ~0xffU;
state->output = gpr_realloc(state->output, state->allocated + needed);
state->free_space += needed;
state->allocated += needed;
@@ -128,7 +128,7 @@ static void json_reader_string_add_char(void* userdata, gpr_uint32 c) {
json_reader_userdata* state = userdata;
GPR_ASSERT(state->string_ptr < state->input);
GPR_ASSERT(c <= 0xff);
- *state->string_ptr++ = (char)c;
+ *state->string_ptr++ = (gpr_uint8)c;
}
/* We are converting a UTF-32 character into UTF-8 here,
@@ -138,22 +138,22 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {
if (c <= 0x7f) {
json_reader_string_add_char(userdata, c);
} else if (c <= 0x7ff) {
- int b1 = 0xc0 | ((c >> 6) & 0x1f);
- int b2 = 0x80 | (c & 0x3f);
+ gpr_uint32 b1 = 0xc0 | ((c >> 6) & 0x1f);
+ gpr_uint32 b2 = 0x80 | (c & 0x3f);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
} else if (c <= 0xffff) {
- int b1 = 0xe0 | ((c >> 12) & 0x0f);
- int b2 = 0x80 | ((c >> 6) & 0x3f);
- int b3 = 0x80 | (c & 0x3f);
+ gpr_uint32 b1 = 0xe0 | ((c >> 12) & 0x0f);
+ gpr_uint32 b2 = 0x80 | ((c >> 6) & 0x3f);
+ gpr_uint32 b3 = 0x80 | (c & 0x3f);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
json_reader_string_add_char(userdata, b3);
} else if (c <= 0x1fffff) {
- int b1 = 0xf0 | ((c >> 18) & 0x07);
- int b2 = 0x80 | ((c >> 12) & 0x3f);
- int b3 = 0x80 | ((c >> 6) & 0x3f);
- int b4 = 0x80 | (c & 0x3f);
+ gpr_uint32 b1 = 0xf0 | ((c >> 18) & 0x07);
+ gpr_uint32 b2 = 0x80 | ((c >> 12) & 0x3f);
+ gpr_uint32 b3 = 0x80 | ((c >> 6) & 0x3f);
+ gpr_uint32 b4 = 0x80 | (c & 0x3f);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
json_reader_string_add_char(userdata, b3);
diff --git a/src/core/json/json_writer.c b/src/core/json/json_writer.c
index a40bf1733e..bed9a9bfa5 100644
--- a/src/core/json/json_writer.c
+++ b/src/core/json/json_writer.c
@@ -66,7 +66,7 @@ static void json_writer_output_indent(
" "
" ";
- unsigned spaces = writer->depth * writer->indent;
+ unsigned spaces = (unsigned)(writer->depth * writer->indent);
if (writer->indent == 0) return;
@@ -78,7 +78,7 @@ static void json_writer_output_indent(
while (spaces >= (sizeof(spacesstr) - 1)) {
json_writer_output_string_with_len(writer, spacesstr,
sizeof(spacesstr) - 1);
- spaces -= (sizeof(spacesstr) - 1);
+ spaces -= (unsigned)(sizeof(spacesstr) - 1);
}
if (spaces == 0) return;
@@ -119,7 +119,7 @@ static void json_writer_escape_string(grpc_json_writer* writer,
break;
} else if ((c >= 32) && (c <= 126)) {
if ((c == '\\') || (c == '"')) json_writer_output_char(writer, '\\');
- json_writer_output_char(writer, c);
+ json_writer_output_char(writer, (char)c);
} else if ((c < 32) || (c == 127)) {
switch (c) {
case '\b':
@@ -160,7 +160,7 @@ static void json_writer_escape_string(grpc_json_writer* writer,
}
for (i = 0; i < extra; i++) {
utf32 <<= 6;
- c = *string++;
+ c = (gpr_uint8)(*string++);
/* Breaks out and bail on any invalid UTF-8 sequence, including \0. */
if ((c & 0xc0) != 0x80) {
valid = 0;
@@ -193,10 +193,10 @@ static void json_writer_escape_string(grpc_json_writer* writer,
* That range is exactly 20 bits.
*/
utf32 -= 0x10000;
- json_writer_escape_utf16(writer, 0xd800 | (utf32 >> 10));
- json_writer_escape_utf16(writer, 0xdc00 | (utf32 & 0x3ff));
+ json_writer_escape_utf16(writer, (gpr_uint16)(0xd800 | (utf32 >> 10)));
+ json_writer_escape_utf16(writer, (gpr_uint16)(0xdc00 | (utf32 & 0x3ff)));
} else {
- json_writer_escape_utf16(writer, utf32);
+ json_writer_escape_utf16(writer, (gpr_uint16)utf32);
}
}
}
diff --git a/src/core/security/base64.c b/src/core/security/base64.c
index 3b8fea8f73..3f28c09611 100644
--- a/src/core/security/base64.c
+++ b/src/core/security/base64.c
@@ -128,7 +128,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) {
size_t num_codes = 0;
while (b64_len--) {
- unsigned char c = *b64++;
+ unsigned char c = (unsigned char)(*b64++);
signed char code;
if (c >= GPR_ARRAY_SIZE(base64_bytes)) continue;
if (url_safe) {
@@ -149,7 +149,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) {
goto fail;
}
} else {
- codes[num_codes++] = code;
+ codes[num_codes++] = (unsigned char)code;
if (num_codes == 4) {
if (codes[0] == GRPC_BASE64_PAD_BYTE ||
codes[1] == GRPC_BASE64_PAD_BYTE) {
@@ -159,7 +159,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) {
if (codes[2] == GRPC_BASE64_PAD_BYTE) {
if (codes[3] == GRPC_BASE64_PAD_BYTE) {
/* Double padding. */
- gpr_uint32 packed = (codes[0] << 2) | (codes[1] >> 4);
+ gpr_uint32 packed = (gpr_uint32)((codes[0] << 2) | (codes[1] >> 4));
current[result_size++] = (unsigned char)packed;
} else {
gpr_log(GPR_ERROR, "Invalid padding detected.");
@@ -168,13 +168,13 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) {
} else if (codes[3] == GRPC_BASE64_PAD_BYTE) {
/* Single padding. */
gpr_uint32 packed =
- (codes[0] << 10) | (codes[1] << 4) | (codes[2] >> 2);
+ (gpr_uint32)((codes[0] << 10) | (codes[1] << 4) | (codes[2] >> 2));
current[result_size++] = (unsigned char)(packed >> 8);
current[result_size++] = (unsigned char)(packed);
} else {
/* No padding. */
gpr_uint32 packed =
- (codes[0] << 18) | (codes[1] << 12) | (codes[2] << 6) | codes[3];
+ (gpr_uint32)((codes[0] << 18) | (codes[1] << 12) | (codes[2] << 6) | codes[3]);
current[result_size++] = (unsigned char)(packed >> 16);
current[result_size++] = (unsigned char)(packed >> 8);
current[result_size++] = (unsigned char)(packed);
diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c
index 7bb1de4413..73496d1153 100644
--- a/src/core/security/secure_endpoint.c
+++ b/src/core/security/secure_endpoint.c
@@ -116,7 +116,7 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status error) {
unsigned i;
gpr_uint8 keep_looping = 0;
- int input_buffer_count = 0;
+ size_t input_buffer_count = 0;
tsi_result result = TSI_OK;
secure_endpoint *ep = (secure_endpoint *)user_data;
gpr_uint8 *cur = GPR_SLICE_START_PTR(ep->read_staging_buffer);
@@ -129,7 +129,7 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices,
size_t message_size = GPR_SLICE_LENGTH(encrypted);
while (message_size > 0 || keep_looping) {
- size_t unprotected_buffer_size_written = end - cur;
+ size_t unprotected_buffer_size_written = (size_t)(end - cur);
size_t processed_message_size = message_size;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_unprotect(ep->protector, message_bytes,
@@ -166,7 +166,7 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices,
&ep->input_buffer,
gpr_slice_split_head(
&ep->read_staging_buffer,
- cur - GPR_SLICE_START_PTR(ep->read_staging_buffer)));
+ (size_t)(cur - GPR_SLICE_START_PTR(ep->read_staging_buffer))));
}
/* TODO(yangg) experiment with moving this block after read_cb to see if it
@@ -225,7 +225,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
grpc_endpoint_write_cb cb,
void *user_data) {
unsigned i;
- int output_buffer_count = 0;
+ size_t output_buffer_count = 0;
tsi_result result = TSI_OK;
secure_endpoint *ep = (secure_endpoint *)secure_ep;
gpr_uint8 *cur = GPR_SLICE_START_PTR(ep->write_staging_buffer);
@@ -248,7 +248,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
gpr_uint8 *message_bytes = GPR_SLICE_START_PTR(plain);
size_t message_size = GPR_SLICE_LENGTH(plain);
while (message_size > 0) {
- size_t protected_buffer_size_to_send = end - cur;
+ size_t protected_buffer_size_to_send = (size_t)(end - cur);
size_t processed_message_size = message_size;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_protect(ep->protector, message_bytes,
@@ -273,7 +273,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
if (result == TSI_OK) {
size_t still_pending_size;
do {
- size_t protected_buffer_size_to_send = end - cur;
+ size_t protected_buffer_size_to_send = (size_t)(end - cur);
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_protect_flush(ep->protector, cur,
&protected_buffer_size_to_send,
@@ -290,7 +290,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
&ep->output_buffer,
gpr_slice_split_head(
&ep->write_staging_buffer,
- cur - GPR_SLICE_START_PTR(ep->write_staging_buffer)));
+ (size_t)(cur - GPR_SLICE_START_PTR(ep->write_staging_buffer))));
}
}
diff --git a/src/core/security/secure_transport_setup.c b/src/core/security/secure_transport_setup.c
index 3e1db9a12d..1b39ab141e 100644
--- a/src/core/security/secure_transport_setup.c
+++ b/src/core/security/secure_transport_setup.c
@@ -235,7 +235,7 @@ static void on_handshake_data_received_from_peer(
gpr_slice_unref(slices[i]); /* split_tail above increments refcount. */
}
gpr_slice_buffer_addn(&s->left_overs, &slices[i + 1],
- num_left_overs - has_left_overs_in_current_slice);
+ num_left_overs - (size_t)has_left_overs_in_current_slice);
check_peer(s);
}
diff --git a/src/core/security/security_connector.c b/src/core/security/security_connector.c
index 4098636a2e..5512bb177a 100644
--- a/src/core/security/security_connector.c
+++ b/src/core/security/security_connector.c
@@ -386,29 +386,13 @@ static int ssl_host_matches_name(const tsi_peer *peer, const char *peer_name) {
return r;
}
-static grpc_auth_context *tsi_ssl_peer_to_auth_context(const tsi_peer *peer) {
- /* We bet that iterating over a handful of properties twice will be faster
- than having to realloc on average . */
- size_t auth_prop_count = 1; /* for transport_security_type. */
+grpc_auth_context *tsi_ssl_peer_to_auth_context(const tsi_peer *peer) {
size_t i;
- const char *peer_identity_property_name = NULL;
grpc_auth_context *ctx = NULL;
- for (i = 0; i < peer->property_count; i++) {
- const tsi_peer_property *prop = &peer->properties[i];
- if (prop->name == NULL) continue;
- if (strcmp(prop->name, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY) == 0) {
- auth_prop_count++;
- /* If there is no subject alt name, have the CN as the identity. */
- if (peer_identity_property_name == NULL) {
- peer_identity_property_name = prop->name;
- }
- } else if (strcmp(prop->name,
- TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == 0) {
- auth_prop_count++;
- peer_identity_property_name = prop->name;
- }
- }
- ctx = grpc_auth_context_create(NULL, auth_prop_count);
+
+ /* The caller has checked the certificate type property. */
+ GPR_ASSERT(peer->property_count >= 1);
+ ctx = grpc_auth_context_create(NULL, peer->property_count);
ctx->properties[0] = grpc_auth_property_init_from_cstring(
GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
GRPC_SSL_TRANSPORT_SECURITY_TYPE);
@@ -417,15 +401,19 @@ static grpc_auth_context *tsi_ssl_peer_to_auth_context(const tsi_peer *peer) {
const tsi_peer_property *prop = &peer->properties[i];
if (prop->name == NULL) continue;
if (strcmp(prop->name, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY) == 0) {
+ /* If there is no subject alt name, have the CN as the identity. */
+ if (ctx->peer_identity_property_name == NULL) {
+ ctx->peer_identity_property_name = GRPC_X509_CN_PROPERTY_NAME;
+ }
ctx->properties[ctx->property_count++] = grpc_auth_property_init(
GRPC_X509_CN_PROPERTY_NAME, prop->value.data, prop->value.length);
} else if (strcmp(prop->name,
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == 0) {
+ ctx->peer_identity_property_name = GRPC_X509_SAN_PROPERTY_NAME;
ctx->properties[ctx->property_count++] = grpc_auth_property_init(
GRPC_X509_SAN_PROPERTY_NAME, prop->value.data, prop->value.length);
}
}
- GPR_ASSERT(auth_prop_count == ctx->property_count);
return ctx;
}
@@ -550,7 +538,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
alpn_protocol_strings[i] =
(const unsigned char *)grpc_chttp2_get_alpn_version_index(i);
alpn_protocol_string_lengths[i] =
- strlen(grpc_chttp2_get_alpn_version_index(i));
+ (unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i));
}
if (config == NULL || target_name == NULL) {
@@ -589,7 +577,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
config->pem_private_key, config->pem_private_key_size,
config->pem_cert_chain, config->pem_cert_chain_size, pem_root_certs,
pem_root_certs_size, ssl_cipher_suites(), alpn_protocol_strings,
- alpn_protocol_string_lengths, num_alpn_protocols, &c->handshaker_factory);
+ alpn_protocol_string_lengths, (uint16_t)num_alpn_protocols, &c->handshaker_factory);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
tsi_result_to_string(result));
@@ -623,7 +611,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
alpn_protocol_strings[i] =
(const unsigned char *)grpc_chttp2_get_alpn_version_index(i);
alpn_protocol_string_lengths[i] =
- strlen(grpc_chttp2_get_alpn_version_index(i));
+ (unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i));
}
if (config == NULL || config->num_key_cert_pairs == 0) {
@@ -642,7 +630,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
(const unsigned char **)config->pem_cert_chains,
config->pem_cert_chains_sizes, config->num_key_cert_pairs,
config->pem_root_certs, config->pem_root_certs_size, ssl_cipher_suites(),
- alpn_protocol_strings, alpn_protocol_string_lengths, num_alpn_protocols,
+ alpn_protocol_strings, alpn_protocol_string_lengths, (uint16_t)num_alpn_protocols,
&c->handshaker_factory);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
@@ -661,4 +649,3 @@ error:
gpr_free(alpn_protocol_string_lengths);
return GRPC_SECURITY_ERROR;
}
-
diff --git a/src/core/security/security_connector.h b/src/core/security/security_connector.h
index 0617041448..ee3057b43b 100644
--- a/src/core/security/security_connector.h
+++ b/src/core/security/security_connector.h
@@ -203,4 +203,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
const tsi_peer_property *tsi_peer_get_property_by_name(
const tsi_peer *peer, const char *name);
+/* Exposed for testing only. */
+grpc_auth_context *tsi_ssl_peer_to_auth_context(const tsi_peer *peer);
+
#endif /* GRPC_INTERNAL_CORE_SECURITY_SECURITY_CONNECTOR_H */
diff --git a/src/core/security/server_secure_chttp2.c b/src/core/security/server_secure_chttp2.c
index b312bdd0b6..53afa1caad 100644
--- a/src/core/security/server_secure_chttp2.c
+++ b/src/core/security/server_secure_chttp2.c
@@ -138,10 +138,12 @@ static void destroy_done(void *statep) {
callbacks) */
static void destroy(grpc_server *server, void *statep) {
grpc_server_secure_state *state = statep;
+ grpc_tcp_server *tcp;
gpr_mu_lock(&state->mu);
state->is_shutdown = 1;
- grpc_tcp_server_destroy(state->tcp, destroy_done, state);
+ tcp = state->tcp;
gpr_mu_unlock(&state->mu);
+ grpc_tcp_server_destroy(tcp, destroy_done, state);
}
int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
diff --git a/src/core/support/cmdline.c b/src/core/support/cmdline.c
index 4baad85040..45a3182f73 100644
--- a/src/core/support/cmdline.c
+++ b/src/core/support/cmdline.c
@@ -228,7 +228,7 @@ static void value_state(gpr_cmdline *cl, char *arg) {
cl->cur_arg->name);
print_usage_and_die(cl);
}
- *(int *)cl->cur_arg->value = intval;
+ *(int *)cl->cur_arg->value = (int)intval;
break;
case ARGTYPE_BOOL:
if (0 == strcmp(arg, "1") || 0 == strcmp(arg, "true")) {
@@ -287,8 +287,8 @@ static void normal_state(gpr_cmdline *cl, char *arg) {
eq = strchr(arg, '=');
if (eq != NULL) {
/* copy the string into a temp buffer and extract the name */
- tmp = arg_name = gpr_malloc(eq - arg + 1);
- memcpy(arg_name, arg, eq - arg);
+ tmp = arg_name = gpr_malloc((size_t)(eq - arg + 1));
+ memcpy(arg_name, arg, (size_t)(eq - arg));
arg_name[eq - arg] = 0;
} else {
arg_name = arg;
diff --git a/src/core/support/cpu_linux.c b/src/core/support/cpu_linux.c
index 37e840d4cf..282d4daab1 100644
--- a/src/core/support/cpu_linux.c
+++ b/src/core/support/cpu_linux.c
@@ -51,7 +51,9 @@
static int ncpus = 0;
static void init_num_cpus() {
- ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+ /* This must be signed. sysconf returns -1 when the number cannot be
+ determined */
+ ncpus = (int)sysconf(_SC_NPROCESSORS_ONLN);
if (ncpus < 1) {
gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1");
ncpus = 1;
@@ -61,7 +63,7 @@ static void init_num_cpus() {
unsigned gpr_cpu_num_cores(void) {
static gpr_once once = GPR_ONCE_INIT;
gpr_once_init(&once, init_num_cpus);
- return ncpus;
+ return (unsigned)ncpus;
}
unsigned gpr_cpu_current_cpu(void) {
@@ -70,7 +72,7 @@ unsigned gpr_cpu_current_cpu(void) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
return 0;
}
- return cpu;
+ return (unsigned)cpu;
}
#endif /* GPR_CPU_LINUX */
diff --git a/src/core/support/file.c b/src/core/support/file.c
index 8ce7a67fb1..c1361d8a9e 100644
--- a/src/core/support/file.c
+++ b/src/core/support/file.c
@@ -58,7 +58,8 @@ gpr_slice gpr_load_file(const char *filename, int add_null_terminator,
goto end;
}
fseek(file, 0, SEEK_END);
- contents_size = ftell(file);
+ /* Converting to size_t on the assumption that it will not fail */
+ contents_size = (size_t)ftell(file);
fseek(file, 0, SEEK_SET);
contents = gpr_malloc(contents_size + (add_null_terminator ? 1 : 0));
bytes_read = fread(contents, 1, contents_size, file);
diff --git a/src/core/support/histogram.c b/src/core/support/histogram.c
index 673affde71..2f1adcf511 100644
--- a/src/core/support/histogram.c
+++ b/src/core/support/histogram.c
@@ -189,12 +189,12 @@ static double threshold_for_count_below(gpr_histogram *h, double count_below) {
break;
}
}
- return (bucket_start(h, lower_idx) + bucket_start(h, upper_idx)) / 2.0;
+ return (bucket_start(h, (double)lower_idx) + bucket_start(h, (double)upper_idx)) / 2.0;
} else {
/* treat values as uniform throughout the bucket, and find where this value
should lie */
- lower_bound = bucket_start(h, lower_idx);
- upper_bound = bucket_start(h, lower_idx + 1);
+ lower_bound = bucket_start(h, (double)lower_idx);
+ upper_bound = bucket_start(h, (double)(lower_idx + 1));
return GPR_CLAMP(upper_bound - (upper_bound - lower_bound) *
(count_so_far - count_below) /
h->buckets[lower_idx],
diff --git a/src/core/support/host_port.c b/src/core/support/host_port.c
index 53669f063b..0906ebc2a3 100644
--- a/src/core/support/host_port.c
+++ b/src/core/support/host_port.c
@@ -76,7 +76,7 @@ void gpr_split_host_port(const char *name, char **host, char **port) {
return;
}
host_start = name + 1;
- host_len = rbracket - host_start;
+ host_len = (size_t)(rbracket - host_start);
if (memchr(host_start, ':', host_len) == NULL) {
/* Require all bracketed hosts to contain a colon, because a hostname or
IPv4 address should never use brackets. */
@@ -87,7 +87,7 @@ void gpr_split_host_port(const char *name, char **host, char **port) {
if (colon != NULL && strchr(colon + 1, ':') == NULL) {
/* Exactly 1 colon. Split into host:port. */
host_start = name;
- host_len = colon - name;
+ host_len = (size_t)(colon - name);
port_start = colon + 1;
} else {
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
diff --git a/src/core/support/murmur_hash.c b/src/core/support/murmur_hash.c
index cc84691508..37fdca82ba 100644
--- a/src/core/support/murmur_hash.c
+++ b/src/core/support/murmur_hash.c
@@ -48,7 +48,7 @@
gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed) {
const gpr_uint8 *data = (const gpr_uint8 *)key;
- const int nblocks = len / 4;
+ const size_t nblocks = len / 4;
int i;
gpr_uint32 h1 = seed;
@@ -57,11 +57,11 @@ gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed) {
const gpr_uint32 c1 = 0xcc9e2d51;
const gpr_uint32 c2 = 0x1b873593;
- const gpr_uint32 *blocks = (const uint32_t *)(data + nblocks * 4);
- const uint8_t *tail = (const uint8_t *)(data + nblocks * 4);
+ const gpr_uint32 *blocks = ((const gpr_uint32 *)key) + nblocks;
+ const gpr_uint8 *tail = (const gpr_uint8 *)(data + nblocks * 4);
/* body */
- for (i = -nblocks; i; i++) {
+ for (i = -(int)nblocks; i; i++) {
k1 = GETBLOCK32(blocks, i);
k1 *= c1;
@@ -78,9 +78,9 @@ gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed) {
/* tail */
switch (len & 3) {
case 3:
- k1 ^= tail[2] << 16;
+ k1 ^= ((gpr_uint32)tail[2]) << 16;
case 2:
- k1 ^= tail[1] << 8;
+ k1 ^= ((gpr_uint32)tail[1]) << 8;
case 1:
k1 ^= tail[0];
k1 *= c1;
@@ -90,7 +90,7 @@ gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed) {
};
/* finalization */
- h1 ^= len;
+ h1 ^= (gpr_uint32)len;
FMIX32(h1);
return h1;
}
diff --git a/src/core/support/slice.c b/src/core/support/slice.c
index 4cff029286..a2d62fc1e5 100644
--- a/src/core/support/slice.c
+++ b/src/core/support/slice.c
@@ -194,7 +194,7 @@ gpr_slice gpr_slice_malloc(size_t length) {
} else {
/* small slice: just inline the data */
slice.refcount = NULL;
- slice.data.inlined.length = length;
+ slice.data.inlined.length = (gpr_uint8)length;
}
return slice;
}
@@ -202,11 +202,11 @@ gpr_slice gpr_slice_malloc(size_t length) {
gpr_slice gpr_slice_sub_no_ref(gpr_slice source, size_t begin, size_t end) {
gpr_slice subset;
+ GPR_ASSERT(end >= begin);
+
if (source.refcount) {
/* Enforce preconditions */
- GPR_ASSERT(source.data.refcounted.length >= begin);
GPR_ASSERT(source.data.refcounted.length >= end);
- GPR_ASSERT(end >= begin);
/* Build the result */
subset.refcount = source.refcount;
@@ -214,8 +214,10 @@ gpr_slice gpr_slice_sub_no_ref(gpr_slice source, size_t begin, size_t end) {
subset.data.refcounted.bytes = source.data.refcounted.bytes + begin;
subset.data.refcounted.length = end - begin;
} else {
+ /* Enforce preconditions */
+ GPR_ASSERT(source.data.inlined.length >= end);
subset.refcount = NULL;
- subset.data.inlined.length = end - begin;
+ subset.data.inlined.length = (gpr_uint8)(end - begin);
memcpy(subset.data.inlined.bytes, source.data.inlined.bytes + begin,
end - begin);
}
@@ -227,7 +229,7 @@ gpr_slice gpr_slice_sub(gpr_slice source, size_t begin, size_t end) {
if (end - begin <= sizeof(subset.data.inlined.bytes)) {
subset.refcount = NULL;
- subset.data.inlined.length = end - begin;
+ subset.data.inlined.length = (gpr_uint8)(end - begin);
memcpy(subset.data.inlined.bytes, GPR_SLICE_START_PTR(source) + begin,
end - begin);
} else {
@@ -245,17 +247,17 @@ gpr_slice gpr_slice_split_tail(gpr_slice *source, size_t split) {
/* inlined data, copy it out */
GPR_ASSERT(source->data.inlined.length >= split);
tail.refcount = NULL;
- tail.data.inlined.length = source->data.inlined.length - split;
+ tail.data.inlined.length = (gpr_uint8)(source->data.inlined.length - split);
memcpy(tail.data.inlined.bytes, source->data.inlined.bytes + split,
tail.data.inlined.length);
- source->data.inlined.length = split;
+ source->data.inlined.length = (gpr_uint8)split;
} else {
size_t tail_length = source->data.refcounted.length - split;
GPR_ASSERT(source->data.refcounted.length >= split);
if (tail_length < sizeof(tail.data.inlined.bytes)) {
/* Copy out the bytes - it'll be cheaper than refcounting */
tail.refcount = NULL;
- tail.data.inlined.length = tail_length;
+ tail.data.inlined.length = (gpr_uint8)tail_length;
memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split,
tail_length);
} else {
@@ -280,16 +282,16 @@ gpr_slice gpr_slice_split_head(gpr_slice *source, size_t split) {
GPR_ASSERT(source->data.inlined.length >= split);
head.refcount = NULL;
- head.data.inlined.length = split;
+ head.data.inlined.length = (gpr_uint8)split;
memcpy(head.data.inlined.bytes, source->data.inlined.bytes, split);
- source->data.inlined.length -= split;
+ source->data.inlined.length = (gpr_uint8)(source->data.inlined.length - split);
memmove(source->data.inlined.bytes, source->data.inlined.bytes + split,
source->data.inlined.length);
} else if (split < sizeof(head.data.inlined.bytes)) {
GPR_ASSERT(source->data.refcounted.length >= split);
head.refcount = NULL;
- head.data.inlined.length = split;
+ head.data.inlined.length = (gpr_uint8)split;
memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split);
source->data.refcounted.bytes += split;
source->data.refcounted.length -= split;
@@ -311,7 +313,7 @@ gpr_slice gpr_slice_split_head(gpr_slice *source, size_t split) {
}
int gpr_slice_cmp(gpr_slice a, gpr_slice b) {
- int d = GPR_SLICE_LENGTH(a) - GPR_SLICE_LENGTH(b);
+ int d = (int)(GPR_SLICE_LENGTH(a) - GPR_SLICE_LENGTH(b));
if (d != 0) return d;
return memcmp(GPR_SLICE_START_PTR(a), GPR_SLICE_START_PTR(b),
GPR_SLICE_LENGTH(a));
@@ -319,7 +321,7 @@ int gpr_slice_cmp(gpr_slice a, gpr_slice b) {
int gpr_slice_str_cmp(gpr_slice a, const char *b) {
size_t b_length = strlen(b);
- int d = GPR_SLICE_LENGTH(a) - b_length;
+ int d = (int)(GPR_SLICE_LENGTH(a) - b_length);
if (d != 0) return d;
return memcmp(GPR_SLICE_START_PTR(a), b, b_length);
}
diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c
index 91b5d8c98b..7e25d99774 100644
--- a/src/core/support/slice_buffer.c
+++ b/src/core/support/slice_buffer.c
@@ -81,7 +81,7 @@ gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned n) {
if ((back->data.inlined.length + n) > sizeof(back->data.inlined.bytes))
goto add_new;
out = back->data.inlined.bytes + back->data.inlined.length;
- back->data.inlined.length += n;
+ back->data.inlined.length = (gpr_uint8)(back->data.inlined.length + n);
return out;
add_new:
@@ -89,7 +89,7 @@ add_new:
back = &sb->slices[sb->count];
sb->count++;
back->refcount = NULL;
- back->data.inlined.length = n;
+ back->data.inlined.length = (gpr_uint8)n;
return back->data.inlined.bytes;
}
@@ -116,7 +116,7 @@ void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice s) {
GPR_SLICE_INLINED_SIZE) {
memcpy(back->data.inlined.bytes + back->data.inlined.length,
s.data.inlined.bytes, s.data.inlined.length);
- back->data.inlined.length += s.data.inlined.length;
+ back->data.inlined.length = (gpr_uint8)(back->data.inlined.length + s.data.inlined.length);
} else {
size_t cp1 = GPR_SLICE_INLINED_SIZE - back->data.inlined.length;
memcpy(back->data.inlined.bytes + back->data.inlined.length,
@@ -126,7 +126,7 @@ void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice s) {
back = &sb->slices[n];
sb->count = n + 1;
back->refcount = NULL;
- back->data.inlined.length = s.data.inlined.length - cp1;
+ back->data.inlined.length = (gpr_uint8)(s.data.inlined.length - cp1);
memcpy(back->data.inlined.bytes, s.data.inlined.bytes + cp1,
s.data.inlined.length - cp1);
}
diff --git a/src/core/support/string.c b/src/core/support/string.c
index bfd7ce1590..6a80ccc841 100644
--- a/src/core/support/string.c
+++ b/src/core/support/string.c
@@ -94,7 +94,7 @@ char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags) {
if (len) hexout_append(&out, ' ');
hexout_append(&out, '\'');
for (cur = beg; cur != end; ++cur) {
- hexout_append(&out, isprint(*cur) ? *cur : '.');
+ hexout_append(&out, isprint(*cur) ? *(char*)cur : '.');
}
hexout_append(&out, '\'');
}
@@ -113,7 +113,7 @@ int gpr_parse_bytes_to_uint32(const char *buf, size_t len, gpr_uint32 *result) {
for (i = 0; i < len; i++) {
if (buf[i] < '0' || buf[i] > '9') return 0; /* bad char */
- new = 10 * out + (buf[i] - '0');
+ new = 10 * out + (gpr_uint32)(buf[i] - '0');
if (new < out) return 0; /* overflow */
out = new;
}
@@ -143,7 +143,7 @@ int gpr_ltoa(long value, char *string) {
if (neg) value = -value;
while (value) {
- string[i++] = '0' + value % 10;
+ string[i++] = (char)('0' + value % 10);
value /= 10;
}
if (neg) string[i++] = '-';
diff --git a/src/core/support/subprocess_posix.c b/src/core/support/subprocess_posix.c
index b4631fa0ed..171054e4da 100644
--- a/src/core/support/subprocess_posix.c
+++ b/src/core/support/subprocess_posix.c
@@ -66,8 +66,8 @@ gpr_subprocess *gpr_subprocess_create(int argc, const char **argv) {
if (pid == -1) {
return NULL;
} else if (pid == 0) {
- exec_args = gpr_malloc((argc + 1) * sizeof(char *));
- memcpy(exec_args, argv, argc * sizeof(char *));
+ exec_args = gpr_malloc(((size_t)argc + 1) * sizeof(char *));
+ memcpy(exec_args, argv, (size_t)argc * sizeof(char *));
exec_args[argc] = NULL;
execv(exec_args[0], exec_args);
/* if we reach here, an error has occurred */
diff --git a/src/core/support/time.c b/src/core/support/time.c
index 7dbf95059f..d47b08b266 100644
--- a/src/core/support/time.c
+++ b/src/core/support/time.c
@@ -86,11 +86,11 @@ gpr_timespec gpr_time_from_nanos(long ns) {
result = gpr_inf_past;
} else if (ns >= 0) {
result.tv_sec = ns / GPR_NS_PER_SEC;
- result.tv_nsec = ns - result.tv_sec * GPR_NS_PER_SEC;
+ result.tv_nsec = (int)(ns - result.tv_sec * GPR_NS_PER_SEC);
} else {
/* Calculation carefully formulated to avoid any possible under/overflow. */
result.tv_sec = (-(999999999 - (ns + GPR_NS_PER_SEC)) / GPR_NS_PER_SEC) - 1;
- result.tv_nsec = ns - result.tv_sec * GPR_NS_PER_SEC;
+ result.tv_nsec = (int)(ns - result.tv_sec * GPR_NS_PER_SEC);
}
return result;
}
@@ -103,11 +103,11 @@ gpr_timespec gpr_time_from_micros(long us) {
result = gpr_inf_past;
} else if (us >= 0) {
result.tv_sec = us / 1000000;
- result.tv_nsec = (us - result.tv_sec * 1000000) * 1000;
+ result.tv_nsec = (int)((us - result.tv_sec * 1000000) * 1000);
} else {
/* Calculation carefully formulated to avoid any possible under/overflow. */
result.tv_sec = (-(999999 - (us + 1000000)) / 1000000) - 1;
- result.tv_nsec = (us - result.tv_sec * 1000000) * 1000;
+ result.tv_nsec = (int)((us - result.tv_sec * 1000000) * 1000);
}
return result;
}
@@ -120,11 +120,11 @@ gpr_timespec gpr_time_from_millis(long ms) {
result = gpr_inf_past;
} else if (ms >= 0) {
result.tv_sec = ms / 1000;
- result.tv_nsec = (ms - result.tv_sec * 1000) * 1000000;
+ result.tv_nsec = (int)((ms - result.tv_sec * 1000) * 1000000);
} else {
/* Calculation carefully formulated to avoid any possible under/overflow. */
result.tv_sec = (-(999 - (ms + 1000)) / 1000) - 1;
- result.tv_nsec = (ms - result.tv_sec * 1000) * 1000000;
+ result.tv_nsec = (int)((ms - result.tv_sec * 1000) * 1000000);
}
return result;
}
@@ -245,10 +245,10 @@ gpr_int32 gpr_time_to_millis(gpr_timespec t) {
care?) */
return -2147483647;
} else {
- return t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS;
+ return (gpr_int32)(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS);
}
}
double gpr_timespec_to_micros(gpr_timespec t) {
- return t.tv_sec * GPR_US_PER_SEC + t.tv_nsec * 1e-3;
+ return (double)t.tv_sec * GPR_US_PER_SEC + t.tv_nsec * 1e-3;
}
diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c
index 3675f1eb22..afb58ef231 100644
--- a/src/core/support/time_posix.c
+++ b/src/core/support/time_posix.c
@@ -51,7 +51,7 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) {
static gpr_timespec gpr_from_timespec(struct timespec ts) {
gpr_timespec rv;
rv.tv_sec = ts.tv_sec;
- rv.tv_nsec = ts.tv_nsec;
+ rv.tv_nsec = (int)ts.tv_nsec;
return rv;
}
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index ad55ef6601..dd8eaa943e 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -405,6 +405,8 @@ void grpc_call_internal_unref(grpc_call *c, int allow_immediate_deletion) {
static void set_status_code(grpc_call *call, status_source source,
gpr_uint32 status) {
+ if (call->status[source].is_set) return;
+
call->status[source].is_set = 1;
call->status[source].code = status;
@@ -1188,9 +1190,14 @@ static gpr_uint32 decode_compression(grpc_mdelem *md) {
if (user_data) {
clevel = ((grpc_compression_level)(gpr_intptr)user_data) - COMPRESS_OFFSET;
} else {
- if (!gpr_parse_bytes_to_uint32(grpc_mdstr_as_c_string(md->value),
+ gpr_uint32 parsed_clevel_bytes;
+ if (gpr_parse_bytes_to_uint32(grpc_mdstr_as_c_string(md->value),
GPR_SLICE_LENGTH(md->value->slice),
- &clevel)) {
+ &parsed_clevel_bytes)) {
+ /* the following cast is safe, as a gpr_uint32 should be able to hold all
+ * possible values of the grpc_compression_level enum */
+ clevel = (grpc_compression_level) parsed_clevel_bytes;
+ } else {
clevel = GRPC_COMPRESS_LEVEL_NONE; /* could not parse, no compression */
}
grpc_mdelem_set_user_data(md, destroy_compression,
diff --git a/src/core/transport/stream_op.c b/src/core/transport/stream_op.c
index 8996ecac35..0a01598bd9 100644
--- a/src/core/transport/stream_op.c
+++ b/src/core/transport/stream_op.c
@@ -184,34 +184,34 @@ static void assert_valid_list(grpc_mdelem_list *list) {
}
#ifndef NDEBUG
-void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd) {
- assert_valid_list(&comd->list);
- assert_valid_list(&comd->garbage);
+void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) {
+ assert_valid_list(&batch->list);
+ assert_valid_list(&batch->garbage);
}
#endif /* NDEBUG */
-void grpc_metadata_batch_init(grpc_metadata_batch *comd) {
- comd->list.head = comd->list.tail = comd->garbage.head = comd->garbage.tail =
+void grpc_metadata_batch_init(grpc_metadata_batch *batch) {
+ batch->list.head = batch->list.tail = batch->garbage.head = batch->garbage.tail =
NULL;
- comd->deadline = gpr_inf_future;
+ batch->deadline = gpr_inf_future;
}
-void grpc_metadata_batch_destroy(grpc_metadata_batch *comd) {
+void grpc_metadata_batch_destroy(grpc_metadata_batch *batch) {
grpc_linked_mdelem *l;
- for (l = comd->list.head; l; l = l->next) {
+ for (l = batch->list.head; l; l = l->next) {
grpc_mdelem_unref(l->md);
}
- for (l = comd->garbage.head; l; l = l->next) {
+ for (l = batch->garbage.head; l; l = l->next) {
grpc_mdelem_unref(l->md);
}
}
-void grpc_metadata_batch_add_head(grpc_metadata_batch *comd,
+void grpc_metadata_batch_add_head(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage,
grpc_mdelem *elem_to_add) {
GPR_ASSERT(elem_to_add);
storage->md = elem_to_add;
- grpc_metadata_batch_link_head(comd, storage);
+ grpc_metadata_batch_link_head(batch, storage);
}
static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) {
@@ -228,17 +228,17 @@ static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) {
assert_valid_list(list);
}
-void grpc_metadata_batch_link_head(grpc_metadata_batch *comd,
+void grpc_metadata_batch_link_head(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage) {
- link_head(&comd->list, storage);
+ link_head(&batch->list, storage);
}
-void grpc_metadata_batch_add_tail(grpc_metadata_batch *comd,
+void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage,
grpc_mdelem *elem_to_add) {
GPR_ASSERT(elem_to_add);
storage->md = elem_to_add;
- grpc_metadata_batch_link_tail(comd, storage);
+ grpc_metadata_batch_link_tail(batch, storage);
}
static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) {
@@ -255,9 +255,9 @@ static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) {
assert_valid_list(list);
}
-void grpc_metadata_batch_link_tail(grpc_metadata_batch *comd,
+void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage) {
- link_tail(&comd->list, storage);
+ link_tail(&batch->list, storage);
}
void grpc_metadata_batch_merge(grpc_metadata_batch *target,
@@ -274,16 +274,16 @@ void grpc_metadata_batch_merge(grpc_metadata_batch *target,
}
}
-void grpc_metadata_batch_filter(grpc_metadata_batch *comd,
+void grpc_metadata_batch_filter(grpc_metadata_batch *batch,
grpc_mdelem *(*filter)(void *user_data,
grpc_mdelem *elem),
void *user_data) {
grpc_linked_mdelem *l;
grpc_linked_mdelem *next;
- assert_valid_list(&comd->list);
- assert_valid_list(&comd->garbage);
- for (l = comd->list.head; l; l = next) {
+ assert_valid_list(&batch->list);
+ assert_valid_list(&batch->garbage);
+ for (l = batch->list.head; l; l = next) {
grpc_mdelem *orig = l->md;
grpc_mdelem *filt = filter(user_data, orig);
next = l->next;
@@ -294,19 +294,19 @@ void grpc_metadata_batch_filter(grpc_metadata_batch *comd,
if (l->next) {
l->next->prev = l->prev;
}
- if (comd->list.head == l) {
- comd->list.head = l->next;
+ if (batch->list.head == l) {
+ batch->list.head = l->next;
}
- if (comd->list.tail == l) {
- comd->list.tail = l->prev;
+ if (batch->list.tail == l) {
+ batch->list.tail = l->prev;
}
- assert_valid_list(&comd->list);
- link_head(&comd->garbage, l);
+ assert_valid_list(&batch->list);
+ link_head(&batch->garbage, l);
} else if (filt != orig) {
grpc_mdelem_unref(orig);
l->md = filt;
}
}
- assert_valid_list(&comd->list);
- assert_valid_list(&comd->garbage);
+ assert_valid_list(&batch->list);
+ assert_valid_list(&batch->garbage);
}
diff --git a/src/core/transport/stream_op.h b/src/core/transport/stream_op.h
index e080701e2d..ac7af1f2b0 100644
--- a/src/core/transport/stream_op.h
+++ b/src/core/transport/stream_op.h
@@ -85,29 +85,62 @@ typedef struct grpc_mdelem_list {
} grpc_mdelem_list;
typedef struct grpc_metadata_batch {
+ /** Metadata elements in this batch */
grpc_mdelem_list list;
+ /** Elements that have been removed from the batch, but have
+ not yet been unreffed - used to allow collecting garbage
+ under a single metadata context lock */
grpc_mdelem_list garbage;
+ /** Used to calculate grpc-timeout at the point of sending,
+ or gpr_inf_future if this batch does not need to send a
+ grpc-timeout */
gpr_timespec deadline;
} grpc_metadata_batch;
-void grpc_metadata_batch_init(grpc_metadata_batch *comd);
-void grpc_metadata_batch_destroy(grpc_metadata_batch *comd);
+void grpc_metadata_batch_init(grpc_metadata_batch *batch);
+void grpc_metadata_batch_destroy(grpc_metadata_batch *batch);
void grpc_metadata_batch_merge(grpc_metadata_batch *target,
grpc_metadata_batch *add);
-void grpc_metadata_batch_link_head(grpc_metadata_batch *comd,
+/** Add \a storage to the beginning of \a batch. storage->md is
+ assumed to be valid.
+ \a storage is owned by the caller and must survive for the
+ lifetime of batch. This usually means it should be around
+ for the lifetime of the call. */
+void grpc_metadata_batch_link_head(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage);
-void grpc_metadata_batch_link_tail(grpc_metadata_batch *comd,
+/** Add \a storage to the end of \a batch. storage->md is
+ assumed to be valid.
+ \a storage is owned by the caller and must survive for the
+ lifetime of batch. This usually means it should be around
+ for the lifetime of the call. */
+void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage);
-void grpc_metadata_batch_add_head(grpc_metadata_batch *comd,
+/** Add \a elem_to_add as the first element in \a batch, using
+ \a storage as backing storage for the linked list element.
+ \a storage is owned by the caller and must survive for the
+ lifetime of batch. This usually means it should be around
+ for the lifetime of the call.
+ Takes ownership of \a elem_to_add */
+void grpc_metadata_batch_add_head(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage,
grpc_mdelem *elem_to_add);
-void grpc_metadata_batch_add_tail(grpc_metadata_batch *comd,
+/** Add \a elem_to_add as the last element in \a batch, using
+ \a storage as backing storage for the linked list element.
+ \a storage is owned by the caller and must survive for the
+ lifetime of batch. This usually means it should be around
+ for the lifetime of the call.
+ Takes ownership of \a elem_to_add */
+void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch,
grpc_linked_mdelem *storage,
grpc_mdelem *elem_to_add);
-void grpc_metadata_batch_filter(grpc_metadata_batch *comd,
+/** For each element in \a batch, execute \a filter.
+ The return value from \a filter will be substituted for the
+ grpc_mdelem passed to \a filter. If \a filter returns NULL,
+ the element will be moved to the garbage list. */
+void grpc_metadata_batch_filter(grpc_metadata_batch *batch,
grpc_mdelem *(*filter)(void *user_data,
grpc_mdelem *elem),
void *user_data);