aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
authorGravatar Noah Eisen <ncteisen@google.com>2018-02-09 09:16:55 -0800
committerGravatar Noah Eisen <ncteisen@google.com>2018-02-09 09:16:55 -0800
commitbe82e64b3debcdb1d9ec6a149fc85af0d46bfb7e (patch)
treecc5e1234073eb250a2c319b5a4db2919fce060ea /src/core/lib
parent194436342137924b4fb7429bede037a4b5ec7edb (diff)
Autofix c casts to c++ casts
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/avl/avl.cc2
-rw-r--r--src/core/lib/backoff/backoff.cc6
-rw-r--r--src/core/lib/channel/channel_args.cc20
-rw-r--r--src/core/lib/channel/channel_stack.cc10
-rw-r--r--src/core/lib/channel/channel_stack_builder.cc12
-rw-r--r--src/core/lib/channel/connected_channel.cc34
-rw-r--r--src/core/lib/channel/handshaker.cc12
-rw-r--r--src/core/lib/channel/handshaker_registry.cc4
-rw-r--r--src/core/lib/compression/compression_internal.cc2
-rw-r--r--src/core/lib/compression/message_compress.cc8
-rw-r--r--src/core/lib/compression/stream_compression_gzip.cc16
-rw-r--r--src/core/lib/compression/stream_compression_identity.cc2
-rw-r--r--src/core/lib/debug/stats.cc12
-rw-r--r--src/core/lib/debug/trace.cc6
-rw-r--r--src/core/lib/gpr/alloc.cc2
-rw-r--r--src/core/lib/gpr/arena.cc20
-rw-r--r--src/core/lib/gpr/cpu_linux.cc6
-rw-r--r--src/core/lib/gpr/host_port.cc6
-rw-r--r--src/core/lib/gpr/log.cc8
-rw-r--r--src/core/lib/gpr/log_linux.cc2
-rw-r--r--src/core/lib/gpr/murmur_hash.cc8
-rw-r--r--src/core/lib/gpr/string.cc30
-rw-r--r--src/core/lib/gpr/string_posix.cc6
-rw-r--r--src/core/lib/gpr/sync_posix.cc2
-rw-r--r--src/core/lib/gpr/thd_posix.cc10
-rw-r--r--src/core/lib/gpr/time.cc6
-rw-r--r--src/core/lib/gpr/time_posix.cc4
-rw-r--r--src/core/lib/http/format_request.cc4
-rw-r--r--src/core/lib/http/httpcli.cc12
-rw-r--r--src/core/lib/http/httpcli_security_connector.cc20
-rw-r--r--src/core/lib/http/parser.cc22
-rw-r--r--src/core/lib/iomgr/call_combiner.cc14
-rw-r--r--src/core/lib/iomgr/closure.h4
-rw-r--r--src/core/lib/iomgr/combiner.cc8
-rw-r--r--src/core/lib/iomgr/error.cc66
-rw-r--r--src/core/lib/iomgr/ev_epoll1_linux.cc20
-rw-r--r--src/core/lib/iomgr/ev_epollex_linux.cc34
-rw-r--r--src/core/lib/iomgr/ev_epollsig_linux.cc22
-rw-r--r--src/core/lib/iomgr/ev_poll_posix.cc52
-rw-r--r--src/core/lib/iomgr/ev_posix.cc6
-rw-r--r--src/core/lib/iomgr/exec_ctx.cc12
-rw-r--r--src/core/lib/iomgr/executor.cc18
-rw-r--r--src/core/lib/iomgr/gethostname_host_name_max.cc2
-rw-r--r--src/core/lib/iomgr/is_epollexclusive_available.cc2
-rw-r--r--src/core/lib/iomgr/load_file.cc4
-rw-r--r--src/core/lib/iomgr/resolve_address_posix.cc10
-rw-r--r--src/core/lib/iomgr/resource_quota.cc64
-rw-r--r--src/core/lib/iomgr/sockaddr_utils.cc44
-rw-r--r--src/core/lib/iomgr/socket_factory_posix.cc8
-rw-r--r--src/core/lib/iomgr/socket_mutator.cc8
-rw-r--r--src/core/lib/iomgr/socket_utils_common_posix.cc6
-rw-r--r--src/core/lib/iomgr/socket_utils_linux.cc4
-rw-r--r--src/core/lib/iomgr/tcp_client_posix.cc10
-rw-r--r--src/core/lib/iomgr/tcp_posix.cc74
-rw-r--r--src/core/lib/iomgr/tcp_server_posix.cc18
-rw-r--r--src/core/lib/iomgr/tcp_server_utils_posix_common.cc10
-rw-r--r--src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc4
-rw-r--r--src/core/lib/iomgr/timer_generic.cc20
-rw-r--r--src/core/lib/iomgr/timer_heap.cc12
-rw-r--r--src/core/lib/iomgr/timer_manager.cc4
-rw-r--r--src/core/lib/iomgr/udp_server.cc30
-rw-r--r--src/core/lib/iomgr/unix_sockets_posix.cc14
-rw-r--r--src/core/lib/iomgr/wakeup_fd_cv.cc6
-rw-r--r--src/core/lib/json/json.cc2
-rw-r--r--src/core/lib/json/json_reader.cc12
-rw-r--r--src/core/lib/json/json_string.cc36
-rw-r--r--src/core/lib/json/json_writer.cc16
-rw-r--r--src/core/lib/security/context/security_context.cc26
-rw-r--r--src/core/lib/security/credentials/composite/composite_credentials.cc28
-rw-r--r--src/core/lib/security/credentials/credentials.cc16
-rw-r--r--src/core/lib/security/credentials/credentials_metadata.cc2
-rw-r--r--src/core/lib/security/credentials/fake/fake_credentials.cc12
-rw-r--r--src/core/lib/security/credentials/google_default/google_default_credentials.cc8
-rw-r--r--src/core/lib/security/credentials/iam/iam_credentials.cc6
-rw-r--r--src/core/lib/security/credentials/jwt/json_token.cc6
-rw-r--r--src/core/lib/security/credentials/jwt/jwt_credentials.cc14
-rw-r--r--src/core/lib/security/credentials/jwt/jwt_verifier.cc32
-rw-r--r--src/core/lib/security/credentials/oauth2/oauth2_credentials.cc36
-rw-r--r--src/core/lib/security/credentials/plugin/plugin_credentials.cc14
-rw-r--r--src/core/lib/security/credentials/ssl/ssl_credentials.cc40
-rw-r--r--src/core/lib/security/transport/client_auth_filter.cc56
-rw-r--r--src/core/lib/security/transport/lb_targets_info.cc10
-rw-r--r--src/core/lib/security/transport/secure_endpoint.cc34
-rw-r--r--src/core/lib/security/transport/security_connector.cc76
-rw-r--r--src/core/lib/security/transport/security_handshaker.cc32
-rw-r--r--src/core/lib/security/transport/server_auth_filter.cc42
-rw-r--r--src/core/lib/slice/b64.cc30
-rw-r--r--src/core/lib/slice/percent_encoding.cc10
-rw-r--r--src/core/lib/slice/slice.cc64
-rw-r--r--src/core/lib/slice/slice_buffer.cc22
-rw-r--r--src/core/lib/slice/slice_hash_table.cc4
-rw-r--r--src/core/lib/slice/slice_intern.cc30
-rw-r--r--src/core/lib/slice/slice_string_helpers.cc4
-rw-r--r--src/core/lib/surface/byte_buffer.cc4
-rw-r--r--src/core/lib/surface/call.cc78
-rw-r--r--src/core/lib/surface/channel.cc24
-rw-r--r--src/core/lib/surface/channel_init.cc10
-rw-r--r--src/core/lib/surface/channel_ping.cc4
-rw-r--r--src/core/lib/surface/completion_queue.cc92
-rw-r--r--src/core/lib/surface/init.cc4
-rw-r--r--src/core/lib/surface/server.cc104
-rw-r--r--src/core/lib/transport/bdp_estimator.cc6
-rw-r--r--src/core/lib/transport/byte_stream.cc18
-rw-r--r--src/core/lib/transport/connectivity_state.cc10
-rw-r--r--src/core/lib/transport/error_utils.cc12
-rw-r--r--src/core/lib/transport/metadata.cc26
-rw-r--r--src/core/lib/transport/service_config.cc10
-rw-r--r--src/core/lib/transport/static_metadata.cc4
-rw-r--r--src/core/lib/transport/timeout_encoding.cc4
-rw-r--r--src/core/lib/transport/transport.cc10
110 files changed, 1032 insertions, 1032 deletions
diff --git a/src/core/lib/avl/avl.cc b/src/core/lib/avl/avl.cc
index acc0432af7..c674d9be28 100644
--- a/src/core/lib/avl/avl.cc
+++ b/src/core/lib/avl/avl.cc
@@ -79,7 +79,7 @@ static grpc_avl_node* assert_invariants(grpc_avl_node* n) { return n; }
grpc_avl_node* new_node(void* key, void* value, grpc_avl_node* left,
grpc_avl_node* right) {
- grpc_avl_node* node = (grpc_avl_node*)gpr_malloc(sizeof(*node));
+ grpc_avl_node* node = static_cast<grpc_avl_node*>(gpr_malloc(sizeof(*node)));
gpr_ref_init(&node->refs, 1);
node->key = key;
node->value = value;
diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc
index 9275fc2894..81ea429a6a 100644
--- a/src/core/lib/backoff/backoff.cc
+++ b/src/core/lib/backoff/backoff.cc
@@ -56,12 +56,12 @@ grpc_millis BackOff::NextAttemptTime() {
return current_backoff_ + grpc_core::ExecCtx::Get()->Now();
}
current_backoff_ =
- (grpc_millis)(std::min(current_backoff_ * options_.multiplier(),
- (double)options_.max_backoff()));
+ static_cast<grpc_millis>(std::min(current_backoff_ * options_.multiplier(),
+ static_cast<double>(options_.max_backoff())));
const double jitter = generate_uniform_random_number_between(
&rng_state_, -options_.jitter() * current_backoff_,
options_.jitter() * current_backoff_);
- const grpc_millis next_timeout = (grpc_millis)(current_backoff_ + jitter);
+ const grpc_millis next_timeout = static_cast<grpc_millis>(current_backoff_ + jitter);
return next_timeout + grpc_core::ExecCtx::Get()->Now();
}
diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc
index 5cd158aff2..8f448bfd91 100644
--- a/src/core/lib/channel/channel_args.cc
+++ b/src/core/lib/channel/channel_args.cc
@@ -87,13 +87,13 @@ grpc_channel_args* grpc_channel_args_copy_and_add_and_remove(
}
// Create result.
grpc_channel_args* dst =
- (grpc_channel_args*)gpr_malloc(sizeof(grpc_channel_args));
+ static_cast<grpc_channel_args*>(gpr_malloc(sizeof(grpc_channel_args)));
dst->num_args = num_args_to_copy + num_to_add;
if (dst->num_args == 0) {
dst->args = nullptr;
return dst;
}
- dst->args = (grpc_arg*)gpr_malloc(sizeof(grpc_arg) * dst->num_args);
+ dst->args = static_cast<grpc_arg*>(gpr_malloc(sizeof(grpc_arg) * dst->num_args));
// Copy args from src that are not being removed.
size_t dst_idx = 0;
if (src != nullptr) {
@@ -118,7 +118,7 @@ grpc_channel_args* grpc_channel_args_copy(const grpc_channel_args* src) {
grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a,
const grpc_channel_args* b) {
const size_t max_out = (a->num_args + b->num_args);
- grpc_arg* uniques = (grpc_arg*)gpr_malloc(sizeof(*uniques) * max_out);
+ grpc_arg* uniques = static_cast<grpc_arg*>(gpr_malloc(sizeof(*uniques) * max_out));
for (size_t i = 0; i < a->num_args; ++i) uniques[i] = a->args[i];
size_t uniques_idx = a->num_args;
@@ -161,15 +161,15 @@ static int cmp_arg(const grpc_arg* a, const grpc_arg* b) {
/* stabilizing comparison function: since channel_args ordering matters for
* keys with the same name, we need to preserve that ordering */
static int cmp_key_stable(const void* ap, const void* bp) {
- const grpc_arg* const* a = (const grpc_arg* const*)ap;
- const grpc_arg* const* b = (const grpc_arg* const*)bp;
+ const grpc_arg* const* a = static_cast<const grpc_arg* const*>(ap);
+ const grpc_arg* const* b = static_cast<const grpc_arg* const*>(bp);
int c = strcmp((*a)->key, (*b)->key);
if (c == 0) c = GPR_ICMP(*a, *b);
return c;
}
grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) {
- grpc_arg** args = (grpc_arg**)gpr_malloc(sizeof(grpc_arg*) * a->num_args);
+ grpc_arg** args = static_cast<grpc_arg**>(gpr_malloc(sizeof(grpc_arg*) * a->num_args));
for (size_t i = 0; i < a->num_args; i++) {
args[i] = &a->args[i];
}
@@ -177,9 +177,9 @@ grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) {
qsort(args, a->num_args, sizeof(grpc_arg*), cmp_key_stable);
grpc_channel_args* b =
- (grpc_channel_args*)gpr_malloc(sizeof(grpc_channel_args));
+ static_cast<grpc_channel_args*>(gpr_malloc(sizeof(grpc_channel_args)));
b->num_args = a->num_args;
- b->args = (grpc_arg*)gpr_malloc(sizeof(grpc_arg) * b->num_args);
+ b->args = static_cast<grpc_arg*>(gpr_malloc(sizeof(grpc_arg) * b->num_args));
for (size_t i = 0; i < a->num_args; i++) {
b->args[i] = copy_arg(args[i]);
}
@@ -215,7 +215,7 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
for (i = 0; i < a->num_args; ++i) {
if (a->args[i].type == GRPC_ARG_INTEGER &&
!strcmp(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, a->args[i].key)) {
- return (grpc_compression_algorithm)a->args[i].value.integer;
+ return static_cast<grpc_compression_algorithm>(a->args[i].value.integer);
break;
}
}
@@ -296,7 +296,7 @@ uint32_t grpc_channel_args_compression_algorithm_get_states(
const grpc_channel_args* a) {
int* states_arg;
if (find_compression_algorithm_states_bitset(a, &states_arg)) {
- return (uint32_t)*states_arg;
+ return static_cast<uint32_t>(*states_arg);
} else {
return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */
}
diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc
index 195fe0b195..c311c73b85 100644
--- a/src/core/lib/channel/channel_stack.cc
+++ b/src/core/lib/channel/channel_stack.cc
@@ -104,7 +104,7 @@ grpc_error* grpc_channel_stack_init(
GRPC_STREAM_REF_INIT(&stack->refcount, initial_refs, destroy, destroy_arg,
name);
elems = CHANNEL_ELEMS_FROM_STACK(stack);
- user_data = ((char*)elems) + ROUND_UP_TO_ALIGNMENT_SIZE(
+ user_data = (reinterpret_cast<char*>(elems)) + ROUND_UP_TO_ALIGNMENT_SIZE(
filter_count * sizeof(grpc_channel_element));
/* init per-filter data */
@@ -162,7 +162,7 @@ grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack,
GRPC_STREAM_REF_INIT(&elem_args->call_stack->refcount, initial_refs, destroy,
destroy_arg, "CALL_STACK");
call_elems = CALL_ELEMS_FROM_STACK(elem_args->call_stack);
- user_data = ((char*)call_elems) +
+ user_data = (reinterpret_cast<char*>(call_elems)) +
ROUND_UP_TO_ALIGNMENT_SIZE(count * sizeof(grpc_call_element));
/* init per-filter data */
@@ -194,7 +194,7 @@ void grpc_call_stack_set_pollset_or_pollset_set(grpc_call_stack* call_stack,
size_t i;
call_elems = CALL_ELEMS_FROM_STACK(call_stack);
- user_data = ((char*)call_elems) +
+ user_data = (reinterpret_cast<char*>(call_elems)) +
ROUND_UP_TO_ALIGNMENT_SIZE(count * sizeof(grpc_call_element));
/* init per-filter data */
@@ -243,11 +243,11 @@ void grpc_channel_next_op(grpc_channel_element* elem, grpc_transport_op* op) {
grpc_channel_stack* grpc_channel_stack_from_top_element(
grpc_channel_element* elem) {
- return (grpc_channel_stack*)((char*)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE(
+ return reinterpret_cast<grpc_channel_stack*>(reinterpret_cast<char*>(elem)-ROUND_UP_TO_ALIGNMENT_SIZE(
sizeof(grpc_channel_stack)));
}
grpc_call_stack* grpc_call_stack_from_top_element(grpc_call_element* elem) {
- return (grpc_call_stack*)((char*)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE(
+ return reinterpret_cast<grpc_call_stack*>(reinterpret_cast<char*>(elem)-ROUND_UP_TO_ALIGNMENT_SIZE(
sizeof(grpc_call_stack)));
}
diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc
index fcba826644..c04f4c603a 100644
--- a/src/core/lib/channel/channel_stack_builder.cc
+++ b/src/core/lib/channel/channel_stack_builder.cc
@@ -52,7 +52,7 @@ struct grpc_channel_stack_builder_iterator {
grpc_channel_stack_builder* grpc_channel_stack_builder_create(void) {
grpc_channel_stack_builder* b =
- (grpc_channel_stack_builder*)gpr_zalloc(sizeof(*b));
+ static_cast<grpc_channel_stack_builder*>(gpr_zalloc(sizeof(*b)));
b->begin.filter = nullptr;
b->end.filter = nullptr;
@@ -78,7 +78,7 @@ const char* grpc_channel_stack_builder_get_target(
static grpc_channel_stack_builder_iterator* create_iterator_at_filter_node(
grpc_channel_stack_builder* builder, filter_node* node) {
grpc_channel_stack_builder_iterator* it =
- (grpc_channel_stack_builder_iterator*)gpr_malloc(sizeof(*it));
+ static_cast<grpc_channel_stack_builder_iterator*>(gpr_malloc(sizeof(*it)));
it->builder = builder;
it->node = node;
return it;
@@ -213,7 +213,7 @@ bool grpc_channel_stack_builder_prepend_filter(
static void add_after(filter_node* before, const grpc_channel_filter* filter,
grpc_post_filter_create_init_func post_init_func,
void* user_data) {
- filter_node* new_node = (filter_node*)gpr_malloc(sizeof(*new_node));
+ filter_node* new_node = static_cast<filter_node*>(gpr_malloc(sizeof(*new_node)));
new_node->next = before->next;
new_node->prev = before;
new_node->next->prev = new_node->prev->next = new_node;
@@ -265,7 +265,7 @@ grpc_error* grpc_channel_stack_builder_finish(
// create an array of filters
const grpc_channel_filter** filters =
- (const grpc_channel_filter**)gpr_malloc(sizeof(*filters) * num_filters);
+ static_cast<const grpc_channel_filter**>(gpr_malloc(sizeof(*filters) * num_filters));
size_t i = 0;
for (filter_node* p = builder->begin.next; p != &builder->end; p = p->next) {
filters[i++] = p->filter;
@@ -278,7 +278,7 @@ grpc_error* grpc_channel_stack_builder_finish(
*result = gpr_zalloc(prefix_bytes + channel_stack_size);
// fetch a pointer to the channel stack
grpc_channel_stack* channel_stack =
- (grpc_channel_stack*)((char*)(*result) + prefix_bytes);
+ reinterpret_cast<grpc_channel_stack*>(static_cast<char*>(*result) + prefix_bytes);
// and initialize it
grpc_error* error = grpc_channel_stack_init(
initial_refs, destroy, destroy_arg == nullptr ? *result : destroy_arg,
@@ -303,7 +303,7 @@ grpc_error* grpc_channel_stack_builder_finish(
}
grpc_channel_stack_builder_destroy(builder);
- gpr_free((grpc_channel_filter**)filters);
+ gpr_free(const_cast<grpc_channel_filter**>(filters));
return error;
}
diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc
index fb26bdf586..516d49e4d3 100644
--- a/src/core/lib/channel/connected_channel.cc
+++ b/src/core/lib/channel/connected_channel.cc
@@ -52,7 +52,7 @@ typedef struct connected_channel_call_data {
} call_data;
static void run_in_call_combiner(void* arg, grpc_error* error) {
- callback_state* state = (callback_state*)arg;
+ callback_state* state = static_cast<callback_state*>(arg);
GRPC_CALL_COMBINER_START(state->call_combiner, state->original_closure,
GRPC_ERROR_REF(error), state->reason);
}
@@ -96,8 +96,8 @@ static callback_state* get_state_for_batch(
into transport stream operations */
static void con_start_transport_stream_op_batch(
grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (batch->recv_initial_metadata) {
callback_state* state = &calld->recv_initial_metadata_ready;
intercept_callback(
@@ -115,7 +115,7 @@ static void con_start_transport_stream_op_batch(
// calld->on_complete like we can for the other ops. However,
// cancellation isn't in the fast path, so we just allocate a new
// closure for each one.
- callback_state* state = (callback_state*)gpr_malloc(sizeof(*state));
+ callback_state* state = static_cast<callback_state*>(gpr_malloc(sizeof(*state)));
intercept_callback(calld, state, true, "on_complete (cancel_stream)",
&batch->on_complete);
} else {
@@ -129,15 +129,15 @@ static void con_start_transport_stream_op_batch(
static void con_start_transport_op(grpc_channel_element* elem,
grpc_transport_op* op) {
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_transport_perform_op(chand->transport, op);
}
/* Constructor for call_data */
static grpc_error* init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
calld->call_combiner = args->call_combiner;
int r = grpc_transport_init_stream(
chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld),
@@ -149,8 +149,8 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
static void set_pollset_or_pollset_set(grpc_call_element* elem,
grpc_polling_entity* pollent) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_transport_set_pops(chand->transport,
TRANSPORT_STREAM_FROM_CALL_DATA(calld), pollent);
}
@@ -159,8 +159,8 @@ static void set_pollset_or_pollset_set(grpc_call_element* elem,
static void destroy_call_elem(grpc_call_element* elem,
const grpc_call_final_info* final_info,
grpc_closure* then_schedule_closure) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_transport_destroy_stream(chand->transport,
TRANSPORT_STREAM_FROM_CALL_DATA(calld),
then_schedule_closure);
@@ -169,7 +169,7 @@ static void destroy_call_elem(grpc_call_element* elem,
/* Constructor for channel_data */
static grpc_error* init_channel_elem(grpc_channel_element* elem,
grpc_channel_element_args* args) {
- channel_data* cd = (channel_data*)elem->channel_data;
+ channel_data* cd = static_cast<channel_data*>(elem->channel_data);
GPR_ASSERT(args->is_last);
cd->transport = nullptr;
return GRPC_ERROR_NONE;
@@ -177,7 +177,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
/* Destructor for channel_data */
static void destroy_channel_elem(grpc_channel_element* elem) {
- channel_data* cd = (channel_data*)elem->channel_data;
+ channel_data* cd = static_cast<channel_data*>(elem->channel_data);
if (cd->transport) {
grpc_transport_destroy(cd->transport);
}
@@ -203,10 +203,10 @@ const grpc_channel_filter grpc_connected_filter = {
static void bind_transport(grpc_channel_stack* channel_stack,
grpc_channel_element* elem, void* t) {
- channel_data* cd = (channel_data*)elem->channel_data;
+ channel_data* cd = static_cast<channel_data*>(elem->channel_data);
GPR_ASSERT(elem->filter == &grpc_connected_filter);
GPR_ASSERT(cd->transport == nullptr);
- cd->transport = (grpc_transport*)t;
+ cd->transport = static_cast<grpc_transport*>(t);
/* HACK(ctiller): increase call stack size for the channel to make space
for channel data. We need a cleaner (but performant) way to do this,
@@ -215,7 +215,7 @@ static void bind_transport(grpc_channel_stack* channel_stack,
the last call element, and the last call element MUST be the connected
channel. */
channel_stack->call_stack_size +=
- grpc_transport_stream_size((grpc_transport*)t);
+ grpc_transport_stream_size(static_cast<grpc_transport*>(t));
}
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder,
@@ -228,6 +228,6 @@ bool grpc_add_connected_filter(grpc_channel_stack_builder* builder,
}
grpc_stream* grpc_connected_channel_get_stream(grpc_call_element* elem) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
return TRANSPORT_STREAM_FROM_CALL_DATA(calld);
}
diff --git a/src/core/lib/channel/handshaker.cc b/src/core/lib/channel/handshaker.cc
index dcb149c03e..daacbdebd3 100644
--- a/src/core/lib/channel/handshaker.cc
+++ b/src/core/lib/channel/handshaker.cc
@@ -82,7 +82,7 @@ struct grpc_handshake_manager {
grpc_handshake_manager* grpc_handshake_manager_create() {
grpc_handshake_manager* mgr =
- (grpc_handshake_manager*)gpr_zalloc(sizeof(grpc_handshake_manager));
+ static_cast<grpc_handshake_manager*>(gpr_zalloc(sizeof(grpc_handshake_manager)));
gpr_mu_init(&mgr->mu);
gpr_ref_init(&mgr->refs, 1);
return mgr;
@@ -135,8 +135,8 @@ void grpc_handshake_manager_add(grpc_handshake_manager* mgr,
realloc_count = mgr->count * 2;
}
if (realloc_count > 0) {
- mgr->handshakers = (grpc_handshaker**)gpr_realloc(
- mgr->handshakers, realloc_count * sizeof(grpc_handshaker*));
+ mgr->handshakers = static_cast<grpc_handshaker**>(gpr_realloc(
+ mgr->handshakers, realloc_count * sizeof(grpc_handshaker*)));
}
mgr->handshakers[mgr->count++] = handshaker;
gpr_mu_unlock(&mgr->mu);
@@ -197,7 +197,7 @@ static bool call_next_handshaker_locked(grpc_handshake_manager* mgr,
// A function used as the handshaker-done callback when chaining
// handshakers together.
static void call_next_handshaker(void* arg, grpc_error* error) {
- grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg;
+ grpc_handshake_manager* mgr = static_cast<grpc_handshake_manager*>(arg);
gpr_mu_lock(&mgr->mu);
bool done = call_next_handshaker_locked(mgr, GRPC_ERROR_REF(error));
gpr_mu_unlock(&mgr->mu);
@@ -211,7 +211,7 @@ static void call_next_handshaker(void* arg, grpc_error* error) {
// Callback invoked when deadline is exceeded.
static void on_timeout(void* arg, grpc_error* error) {
- grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg;
+ grpc_handshake_manager* mgr = static_cast<grpc_handshake_manager*>(arg);
if (error == GRPC_ERROR_NONE) { // Timer fired, rather than being cancelled.
grpc_handshake_manager_shutdown(
mgr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out"));
@@ -234,7 +234,7 @@ void grpc_handshake_manager_do_handshake(
mgr->args.args = grpc_channel_args_copy(channel_args);
mgr->args.user_data = user_data;
mgr->args.read_buffer =
- (grpc_slice_buffer*)gpr_malloc(sizeof(*mgr->args.read_buffer));
+ static_cast<grpc_slice_buffer*>(gpr_malloc(sizeof(*mgr->args.read_buffer)));
grpc_slice_buffer_init(mgr->args.read_buffer);
// Initialize state needed for calling handshakers.
mgr->acceptor = acceptor;
diff --git a/src/core/lib/channel/handshaker_registry.cc b/src/core/lib/channel/handshaker_registry.cc
index 098eabf084..f23f009275 100644
--- a/src/core/lib/channel/handshaker_registry.cc
+++ b/src/core/lib/channel/handshaker_registry.cc
@@ -34,8 +34,8 @@ typedef struct {
static void grpc_handshaker_factory_list_register(
grpc_handshaker_factory_list* list, bool at_start,
grpc_handshaker_factory* factory) {
- list->list = (grpc_handshaker_factory**)gpr_realloc(
- list->list, (list->num_factories + 1) * sizeof(grpc_handshaker_factory*));
+ list->list = static_cast<grpc_handshaker_factory**>(gpr_realloc(
+ list->list, (list->num_factories + 1) * sizeof(grpc_handshaker_factory*)));
if (at_start) {
memmove(list->list + 1, list->list,
sizeof(grpc_handshaker_factory*) * list->num_factories);
diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc
index 4bbaca2f98..e49c67f784 100644
--- a/src/core/lib/compression/compression_internal.cc
+++ b/src/core/lib/compression/compression_internal.cc
@@ -190,7 +190,7 @@ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level(
GRPC_API_TRACE("grpc_message_compression_algorithm_for_level(level=%d)", 1,
((int)level));
if (level > GRPC_COMPRESS_LEVEL_HIGH) {
- gpr_log(GPR_ERROR, "Unknown message compression level %d.", (int)level);
+ gpr_log(GPR_ERROR, "Unknown message compression level %d.", static_cast<int>(level));
abort();
}
diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc
index 1e9b0f10ee..238eff780c 100644
--- a/src/core/lib/compression/message_compress.cc
+++ b/src/core/lib/compression/message_compress.cc
@@ -36,23 +36,23 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input,
int flush;
size_t i;
grpc_slice outbuf = GRPC_SLICE_MALLOC(OUTPUT_BLOCK_SIZE);
- const uInt uint_max = ~(uInt)0;
+ const uInt uint_max = ~static_cast<uInt>(0);
GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max);
- zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf);
+ zs->avail_out = static_cast<uInt>GRPC_SLICE_LENGTH(outbuf);
zs->next_out = GRPC_SLICE_START_PTR(outbuf);
flush = Z_NO_FLUSH;
for (i = 0; i < input->count; i++) {
if (i == input->count - 1) flush = Z_FINISH;
GPR_ASSERT(GRPC_SLICE_LENGTH(input->slices[i]) <= uint_max);
- zs->avail_in = (uInt)GRPC_SLICE_LENGTH(input->slices[i]);
+ zs->avail_in = static_cast<uInt>GRPC_SLICE_LENGTH(input->slices[i]);
zs->next_in = GRPC_SLICE_START_PTR(input->slices[i]);
do {
if (zs->avail_out == 0) {
grpc_slice_buffer_add_indexed(output, outbuf);
outbuf = GRPC_SLICE_MALLOC(OUTPUT_BLOCK_SIZE);
GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max);
- zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf);
+ zs->avail_out = static_cast<uInt>GRPC_SLICE_LENGTH(outbuf);
zs->next_out = GRPC_SLICE_START_PTR(outbuf);
}
r = flate(zs, flush);
diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc
index 897f3918a7..c48fe9305d 100644
--- a/src/core/lib/compression/stream_compression_gzip.cc
+++ b/src/core/lib/compression/stream_compression_gzip.cc
@@ -48,11 +48,11 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx,
size_t slice_size = max_output_size < OUTPUT_BLOCK_SIZE ? max_output_size
: OUTPUT_BLOCK_SIZE;
grpc_slice slice_out = GRPC_SLICE_MALLOC(slice_size);
- ctx->zs.avail_out = (uInt)slice_size;
+ ctx->zs.avail_out = static_cast<uInt>(slice_size);
ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out);
while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) {
grpc_slice slice = grpc_slice_buffer_take_first(in);
- ctx->zs.avail_in = (uInt)GRPC_SLICE_LENGTH(slice);
+ ctx->zs.avail_in = static_cast<uInt>GRPC_SLICE_LENGTH(slice);
ctx->zs.next_in = GRPC_SLICE_START_PTR(slice);
r = ctx->flate(&ctx->zs, Z_NO_FLUSH);
if (r < 0 && r != Z_BUF_ERROR) {
@@ -142,7 +142,7 @@ static bool grpc_stream_compress_gzip(grpc_stream_compression_context* ctx,
return false;
}
grpc_stream_compression_context_gzip* gzip_ctx =
- (grpc_stream_compression_context_gzip*)ctx;
+ reinterpret_cast<grpc_stream_compression_context_gzip*>(ctx);
GPR_ASSERT(gzip_ctx->flate == deflate);
int gzip_flush;
switch (flush) {
@@ -172,7 +172,7 @@ static bool grpc_stream_decompress_gzip(grpc_stream_compression_context* ctx,
return false;
}
grpc_stream_compression_context_gzip* gzip_ctx =
- (grpc_stream_compression_context_gzip*)ctx;
+ reinterpret_cast<grpc_stream_compression_context_gzip*>(ctx);
GPR_ASSERT(gzip_ctx->flate == inflate);
return gzip_flate(gzip_ctx, in, out, output_size, max_output_size,
Z_SYNC_FLUSH, end_of_context);
@@ -184,8 +184,8 @@ grpc_stream_compression_context_create_gzip(
GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_GZIP_COMPRESS ||
method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
grpc_stream_compression_context_gzip* gzip_ctx =
- (grpc_stream_compression_context_gzip*)gpr_zalloc(
- sizeof(grpc_stream_compression_context_gzip));
+ static_cast<grpc_stream_compression_context_gzip*>(gpr_zalloc(
+ sizeof(grpc_stream_compression_context_gzip)));
int r;
if (gzip_ctx == nullptr) {
return nullptr;
@@ -204,7 +204,7 @@ grpc_stream_compression_context_create_gzip(
}
gzip_ctx->base.vtable = &grpc_stream_compression_gzip_vtable;
- return (grpc_stream_compression_context*)gzip_ctx;
+ return reinterpret_cast<grpc_stream_compression_context*>(gzip_ctx);
}
static void grpc_stream_compression_context_destroy_gzip(
@@ -213,7 +213,7 @@ static void grpc_stream_compression_context_destroy_gzip(
return;
}
grpc_stream_compression_context_gzip* gzip_ctx =
- (grpc_stream_compression_context_gzip*)ctx;
+ reinterpret_cast<grpc_stream_compression_context_gzip*>(ctx);
if (gzip_ctx->flate == inflate) {
inflateEnd(&gzip_ctx->zs);
} else {
diff --git a/src/core/lib/compression/stream_compression_identity.cc b/src/core/lib/compression/stream_compression_identity.cc
index af4051144c..933d24b3a1 100644
--- a/src/core/lib/compression/stream_compression_identity.cc
+++ b/src/core/lib/compression/stream_compression_identity.cc
@@ -79,7 +79,7 @@ grpc_stream_compression_context_create_identity(
GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ||
method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS);
/* No context needed in this case. Use fake context instead. */
- return (grpc_stream_compression_context*)&identity_ctx;
+ return &identity_ctx;
}
static void grpc_stream_compression_context_destroy_identity(
diff --git a/src/core/lib/debug/stats.cc b/src/core/lib/debug/stats.cc
index 40355c2d45..f4de6a82a9 100644
--- a/src/core/lib/debug/stats.cc
+++ b/src/core/lib/debug/stats.cc
@@ -33,7 +33,7 @@ static size_t g_num_cores;
void grpc_stats_init(void) {
g_num_cores = GPR_MAX(1, gpr_cpu_num_cores());
grpc_stats_per_cpu_storage =
- (grpc_stats_data*)gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores);
+ static_cast<grpc_stats_data*>(gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores));
}
void grpc_stats_shutdown(void) { gpr_free(grpc_stats_per_cpu_storage); }
@@ -76,14 +76,14 @@ int grpc_stats_histo_find_bucket_slow(int value, const int* table,
table_size = step;
}
}
- return (int)(table - start) - 1;
+ return static_cast<int>(table - start) - 1;
}
size_t grpc_stats_histo_count(const grpc_stats_data* stats,
grpc_stats_histograms histogram) {
size_t sum = 0;
for (int i = 0; i < grpc_stats_histo_buckets[histogram]; i++) {
- sum += (size_t)stats->histograms[grpc_stats_histo_start[histogram] + i];
+ sum += static_cast<size_t>(stats->histograms[grpc_stats_histo_start[histogram] + i]);
}
return sum;
}
@@ -100,7 +100,7 @@ static double threshold_for_count_below(const gpr_atm* bucket_counts,
/* find the lowest bucket that gets us above count_below */
count_so_far = 0.0;
for (lower_idx = 0; lower_idx < num_buckets; lower_idx++) {
- count_so_far += (double)bucket_counts[lower_idx];
+ count_so_far += static_cast<double>(bucket_counts[lower_idx]);
if (count_so_far >= count_below) {
break;
}
@@ -121,7 +121,7 @@ static double threshold_for_count_below(const gpr_atm* bucket_counts,
upper_bound = bucket_boundaries[lower_idx + 1];
return upper_bound - (upper_bound - lower_bound) *
(count_so_far - count_below) /
- (double)bucket_counts[lower_idx];
+ static_cast<double>(bucket_counts[lower_idx]);
}
}
@@ -133,7 +133,7 @@ double grpc_stats_histo_percentile(const grpc_stats_data* stats,
return threshold_for_count_below(
stats->histograms + grpc_stats_histo_start[histogram],
grpc_stats_histo_bucket_boundaries[histogram],
- grpc_stats_histo_buckets[histogram], (double)count * percentile / 100.0);
+ grpc_stats_histo_buckets[histogram], static_cast<double>(count) * percentile / 100.0);
}
char* grpc_stats_data_as_json(const grpc_stats_data* data) {
diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc
index d870bbc5e7..c0cefd0639 100644
--- a/src/core/lib/debug/trace.cc
+++ b/src/core/lib/debug/trace.cc
@@ -88,11 +88,11 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) {
char* s;
size_t len;
GPR_ASSERT(end >= beg);
- len = (size_t)(end - beg);
- s = (char*)gpr_malloc(len + 1);
+ len = static_cast<size_t>(end - beg);
+ s = static_cast<char*>(gpr_malloc(len + 1));
memcpy(s, beg, len);
s[len] = 0;
- *ss = (char**)gpr_realloc(*ss, sizeof(char**) * np);
+ *ss = static_cast<char**>(gpr_realloc(*ss, sizeof(char**) * np));
(*ss)[n] = s;
*ns = np;
}
diff --git a/src/core/lib/gpr/alloc.cc b/src/core/lib/gpr/alloc.cc
index b1d1550630..e0d25963ed 100644
--- a/src/core/lib/gpr/alloc.cc
+++ b/src/core/lib/gpr/alloc.cc
@@ -95,4 +95,4 @@ void* gpr_malloc_aligned(size_t size, size_t alignment) {
return (void*)ret;
}
-void gpr_free_aligned(void* ptr) { gpr_free(((void**)ptr)[-1]); }
+void gpr_free_aligned(void* ptr) { gpr_free((static_cast<void**>(ptr))[-1]); }
diff --git a/src/core/lib/gpr/arena.cc b/src/core/lib/gpr/arena.cc
index 5a8d7ff6ec..a1eefa56bc 100644
--- a/src/core/lib/gpr/arena.cc
+++ b/src/core/lib/gpr/arena.cc
@@ -51,8 +51,8 @@ static void* zalloc_aligned(size_t size) {
gpr_arena* gpr_arena_create(size_t initial_size) {
initial_size = ROUND_UP_TO_ALIGNMENT_SIZE(initial_size);
- gpr_arena* a = (gpr_arena*)zalloc_aligned(
- ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + initial_size);
+ gpr_arena* a = static_cast<gpr_arena*>(zalloc_aligned(
+ ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + initial_size));
a->initial_zone.size_end = initial_size;
return a;
}
@@ -66,23 +66,23 @@ size_t gpr_arena_destroy(gpr_arena* arena) {
gpr_free_aligned(z);
z = next_z;
}
- return (size_t)size;
+ return static_cast<size_t>(size);
}
void* gpr_arena_alloc(gpr_arena* arena, size_t size) {
size = ROUND_UP_TO_ALIGNMENT_SIZE(size);
size_t start =
- (size_t)gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size);
+ static_cast<size_t>(gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size));
zone* z = &arena->initial_zone;
while (start > z->size_end) {
zone* next_z = (zone*)gpr_atm_acq_load(&z->next_atm);
if (next_z == nullptr) {
- size_t next_z_size = (size_t)gpr_atm_no_barrier_load(&arena->size_so_far);
- next_z = (zone*)zalloc_aligned(ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) +
- next_z_size);
+ size_t next_z_size = static_cast<size_t>gpr_atm_no_barrier_load(&arena->size_so_far);
+ next_z = static_cast<zone*>(zalloc_aligned(ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) +
+ next_z_size));
next_z->size_begin = z->size_end;
next_z->size_end = z->size_end + next_z_size;
- if (!gpr_atm_rel_cas(&z->next_atm, (gpr_atm)NULL, (gpr_atm)next_z)) {
+ if (!gpr_atm_rel_cas(&z->next_atm, static_cast<gpr_atm>(NULL), (gpr_atm)next_z)) {
gpr_free_aligned(next_z);
next_z = (zone*)gpr_atm_acq_load(&z->next_atm);
}
@@ -95,7 +95,7 @@ void* gpr_arena_alloc(gpr_arena* arena, size_t size) {
GPR_ASSERT(start >= z->size_begin);
GPR_ASSERT(start + size <= z->size_end);
char* ptr = (z == &arena->initial_zone)
- ? (char*)arena + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena))
- : (char*)z + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone));
+ ? reinterpret_cast<char*>(arena) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena))
+ : reinterpret_cast<char*>(z) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone));
return ptr + start - z->size_begin;
}
diff --git a/src/core/lib/gpr/cpu_linux.cc b/src/core/lib/gpr/cpu_linux.cc
index 21b1a71dc9..4782f9f742 100644
--- a/src/core/lib/gpr/cpu_linux.cc
+++ b/src/core/lib/gpr/cpu_linux.cc
@@ -45,7 +45,7 @@ static void init_num_cpus() {
#endif
/* This must be signed. sysconf returns -1 when the number cannot be
determined */
- ncpus = (int)sysconf(_SC_NPROCESSORS_ONLN);
+ ncpus = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
if (ncpus < 1) {
gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1");
ncpus = 1;
@@ -55,7 +55,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 (unsigned)ncpus;
+ return static_cast<unsigned>(ncpus);
}
unsigned gpr_cpu_current_cpu(void) {
@@ -71,7 +71,7 @@ unsigned gpr_cpu_current_cpu(void) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
return 0;
}
- return (unsigned)cpu;
+ return static_cast<unsigned>(cpu);
#endif
}
diff --git a/src/core/lib/gpr/host_port.cc b/src/core/lib/gpr/host_port.cc
index 0776727906..5a03a16296 100644
--- a/src/core/lib/gpr/host_port.cc
+++ b/src/core/lib/gpr/host_port.cc
@@ -62,7 +62,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) {
return 0;
}
host_start = name + 1;
- host_len = (size_t)(rbracket - host_start);
+ host_len = static_cast<size_t>(rbracket - host_start);
if (memchr(host_start, ':', host_len) == nullptr) {
/* Require all bracketed hosts to contain a colon, because a hostname or
IPv4 address should never use brackets. */
@@ -73,7 +73,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) {
if (colon != nullptr && strchr(colon + 1, ':') == nullptr) {
/* Exactly 1 colon. Split into host:port. */
host_start = name;
- host_len = (size_t)(colon - name);
+ host_len = static_cast<size_t>(colon - name);
port_start = colon + 1;
} else {
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
@@ -84,7 +84,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) {
}
/* Allocate return values. */
- *host = (char*)gpr_malloc(host_len + 1);
+ *host = static_cast<char*>(gpr_malloc(host_len + 1));
memcpy(*host, host_start, host_len);
(*host)[host_len] = '\0';
diff --git a/src/core/lib/gpr/log.cc b/src/core/lib/gpr/log.cc
index 19c0f6c34d..9211a00a69 100644
--- a/src/core/lib/gpr/log.cc
+++ b/src/core/lib/gpr/log.cc
@@ -45,7 +45,7 @@ const char* gpr_log_severity_string(gpr_log_severity severity) {
void gpr_log_message(const char* file, int line, gpr_log_severity severity,
const char* message) {
- if ((gpr_atm)severity < gpr_atm_no_barrier_load(&g_min_severity_to_print)) {
+ if (static_cast<gpr_atm>(severity) < gpr_atm_no_barrier_load(&g_min_severity_to_print)) {
return;
}
@@ -70,11 +70,11 @@ void gpr_log_verbosity_init() {
gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR;
if (verbosity != nullptr) {
if (gpr_stricmp(verbosity, "DEBUG") == 0) {
- min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_DEBUG;
+ min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_DEBUG);
} else if (gpr_stricmp(verbosity, "INFO") == 0) {
- min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_INFO;
+ min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_INFO);
} else if (gpr_stricmp(verbosity, "ERROR") == 0) {
- min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_ERROR;
+ min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_ERROR);
}
gpr_free(verbosity);
}
diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc
index 6b1f1c71e4..d743eedf38 100644
--- a/src/core/lib/gpr/log_linux.cc
+++ b/src/core/lib/gpr/log_linux.cc
@@ -67,7 +67,7 @@ void gpr_default_log(gpr_log_func_args* args) {
static __thread long tid = 0;
if (tid == 0) tid = gettid();
- timer = (time_t)now.tv_sec;
+ timer = static_cast<time_t>(now.tv_sec);
final_slash = strrchr(args->file, '/');
if (final_slash == nullptr)
display_file = args->file;
diff --git a/src/core/lib/gpr/murmur_hash.cc b/src/core/lib/gpr/murmur_hash.cc
index 3f5e04d211..01a7290c67 100644
--- a/src/core/lib/gpr/murmur_hash.cc
+++ b/src/core/lib/gpr/murmur_hash.cc
@@ -36,7 +36,7 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) {
const uint32_t c1 = 0xcc9e2d51;
const uint32_t c2 = 0x1b873593;
- const uint8_t* keyptr = (const uint8_t*)key;
+ const uint8_t* keyptr = static_cast<const uint8_t*>(key);
const size_t bsize = sizeof(k1);
const size_t nblocks = len / bsize;
@@ -58,10 +58,10 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) {
/* tail */
switch (len & 3) {
case 3:
- k1 ^= ((uint32_t)keyptr[2]) << 16;
+ k1 ^= (static_cast<uint32_t>(keyptr[2])) << 16;
/* fallthrough */
case 2:
- k1 ^= ((uint32_t)keyptr[1]) << 8;
+ k1 ^= (static_cast<uint32_t>(keyptr[1])) << 8;
/* fallthrough */
case 1:
k1 ^= keyptr[0];
@@ -72,7 +72,7 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) {
};
/* finalization */
- h1 ^= (uint32_t)len;
+ h1 ^= static_cast<uint32_t>(len);
FMIX32(h1);
return h1;
}
diff --git a/src/core/lib/gpr/string.cc b/src/core/lib/gpr/string.cc
index 6b360e4013..9c07f43cae 100644
--- a/src/core/lib/gpr/string.cc
+++ b/src/core/lib/gpr/string.cc
@@ -40,7 +40,7 @@ char* gpr_strdup(const char* src) {
}
len = strlen(src) + 1;
- dst = (char*)gpr_malloc(len);
+ dst = static_cast<char*>(gpr_malloc(len));
memcpy(dst, src, len);
@@ -61,7 +61,7 @@ static dump_out dump_out_create(void) {
static void dump_out_append(dump_out* out, char c) {
if (out->length == out->capacity) {
out->capacity = GPR_MAX(8, 2 * out->capacity);
- out->data = (char*)gpr_realloc(out->data, out->capacity);
+ out->data = static_cast<char*>(gpr_realloc(out->data, out->capacity));
}
out->data[out->length++] = c;
}
@@ -69,7 +69,7 @@ static void dump_out_append(dump_out* out, char c) {
static void hexdump(dump_out* out, const char* buf, size_t len) {
static const char* hex = "0123456789abcdef";
- const uint8_t* const beg = (const uint8_t*)buf;
+ const uint8_t* const beg = reinterpret_cast<const uint8_t*>(buf);
const uint8_t* const end = beg + len;
const uint8_t* cur;
@@ -81,7 +81,7 @@ static void hexdump(dump_out* out, const char* buf, size_t len) {
}
static void asciidump(dump_out* out, const char* buf, size_t len) {
- const uint8_t* const beg = (const uint8_t*)buf;
+ const uint8_t* const beg = reinterpret_cast<const uint8_t*>(buf);
const uint8_t* const end = beg + len;
const uint8_t* cur;
int out_was_empty = (out->length == 0);
@@ -90,7 +90,7 @@ static void asciidump(dump_out* out, const char* buf, size_t len) {
dump_out_append(out, '\'');
}
for (cur = beg; cur != end; ++cur) {
- dump_out_append(out, (char)(isprint(*cur) ? *(char*)cur : '.'));
+ dump_out_append(out, (isprint(*cur) ? *(char*)cur : '.'));
}
if (!out_was_empty) {
dump_out_append(out, '\'');
@@ -118,7 +118,7 @@ int gpr_parse_bytes_to_uint32(const char* buf, size_t len, uint32_t* result) {
for (i = 0; i < len; i++) {
if (buf[i] < '0' || buf[i] > '9') return 0; /* bad char */
- new_val = 10 * out + (uint32_t)(buf[i] - '0');
+ new_val = 10 * out + static_cast<uint32_t>(buf[i] - '0');
if (new_val < out) return 0; /* overflow */
out = new_val;
}
@@ -148,7 +148,7 @@ int gpr_ltoa(long value, char* string) {
sign = value < 0 ? -1 : 1;
while (value) {
- string[i++] = (char)('0' + sign * (value % 10));
+ string[i++] = static_cast<char>('0' + sign * (value % 10));
value /= 10;
}
if (sign < 0) string[i++] = '-';
@@ -169,7 +169,7 @@ int int64_ttoa(int64_t value, char* string) {
sign = value < 0 ? -1 : 1;
while (value) {
- string[i++] = (char)('0' + sign * (value % 10));
+ string[i++] = static_cast<char>('0' + sign * (value % 10));
value /= 10;
}
if (sign < 0) string[i++] = '-';
@@ -182,13 +182,13 @@ int gpr_parse_nonnegative_int(const char* value) {
char* end;
long result = strtol(value, &end, 0);
if (*end != '\0' || result < 0 || result > INT_MAX) return -1;
- return (int)result;
+ return static_cast<int>(result);
}
char* gpr_leftpad(const char* str, char flag, size_t length) {
const size_t str_length = strlen(str);
const size_t out_length = str_length > length ? str_length : length;
- char* out = (char*)gpr_malloc(out_length + 1);
+ char* out = static_cast<char*>(gpr_malloc(out_length + 1));
memset(out, flag, out_length - str_length);
memcpy(out + out_length - str_length, str, str_length);
out[out_length] = 0;
@@ -212,7 +212,7 @@ char* gpr_strjoin_sep(const char** strs, size_t nstrs, const char* sep,
if (nstrs > 0) {
out_length += sep_len * (nstrs - 1); /* separators */
}
- out = (char*)gpr_malloc(out_length);
+ out = static_cast<char*>(gpr_malloc(out_length));
out_length = 0;
for (i = 0; i < nstrs; i++) {
const size_t slen = strlen(strs[i]);
@@ -243,7 +243,7 @@ void gpr_strvec_destroy(gpr_strvec* sv) {
void gpr_strvec_add(gpr_strvec* sv, char* str) {
if (sv->count == sv->capacity) {
sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2);
- sv->strs = (char**)gpr_realloc(sv->strs, sizeof(char*) * sv->capacity);
+ sv->strs = static_cast<char**>(gpr_realloc(sv->strs, sizeof(char*) * sv->capacity));
}
sv->strs[sv->count++] = str;
}
@@ -265,12 +265,12 @@ int gpr_stricmp(const char* a, const char* b) {
static void add_string_to_split(const char* beg, const char* end, char*** strs,
size_t* nstrs, size_t* capstrs) {
- char* out = (char*)gpr_malloc((size_t)(end - beg) + 1);
- memcpy(out, beg, (size_t)(end - beg));
+ char* out = static_cast<char*>(gpr_malloc(static_cast<size_t>(end - beg) + 1));
+ memcpy(out, beg, static_cast<size_t>(end - beg));
out[end - beg] = 0;
if (*nstrs == *capstrs) {
*capstrs = GPR_MAX(8, 2 * *capstrs);
- *strs = (char**)gpr_realloc(*strs, sizeof(*strs) * *capstrs);
+ *strs = static_cast<char**>(gpr_realloc(*strs, sizeof(*strs) * *capstrs));
}
(*strs)[*nstrs] = out;
++*nstrs;
diff --git a/src/core/lib/gpr/string_posix.cc b/src/core/lib/gpr/string_posix.cc
index 8b818e39b9..d32775fb3b 100644
--- a/src/core/lib/gpr/string_posix.cc
+++ b/src/core/lib/gpr/string_posix.cc
@@ -43,8 +43,8 @@ int gpr_asprintf(char** strp, const char* format, ...) {
}
/* Allocate a new buffer, with space for the NUL terminator. */
- strp_buflen = (size_t)ret + 1;
- if ((*strp = (char*)gpr_malloc(strp_buflen)) == nullptr) {
+ strp_buflen = static_cast<size_t>(ret) + 1;
+ if ((*strp = static_cast<char*>(gpr_malloc(strp_buflen))) == nullptr) {
/* This shouldn't happen, because gpr_malloc() calls abort(). */
return -1;
}
@@ -59,7 +59,7 @@ int gpr_asprintf(char** strp, const char* format, ...) {
va_start(args, format);
ret = vsnprintf(*strp, strp_buflen, format, args);
va_end(args);
- if ((size_t)ret == strp_buflen - 1) {
+ if (static_cast<size_t>(ret) == strp_buflen - 1) {
return ret;
}
diff --git a/src/core/lib/gpr/sync_posix.cc b/src/core/lib/gpr/sync_posix.cc
index f23a8b2486..848d23730c 100644
--- a/src/core/lib/gpr/sync_posix.cc
+++ b/src/core/lib/gpr/sync_posix.cc
@@ -84,7 +84,7 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
#else
abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME);
#endif // GPR_LINUX
- abs_deadline_ts.tv_sec = (time_t)abs_deadline.tv_sec;
+ abs_deadline_ts.tv_sec = static_cast<time_t>(abs_deadline.tv_sec);
abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec;
err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts);
}
diff --git a/src/core/lib/gpr/thd_posix.cc b/src/core/lib/gpr/thd_posix.cc
index 683fd4575e..e8e61ca396 100644
--- a/src/core/lib/gpr/thd_posix.cc
+++ b/src/core/lib/gpr/thd_posix.cc
@@ -49,7 +49,7 @@ static void dec_thd_count();
/* Body of every thread started via gpr_thd_new. */
static void* thread_body(void* v) {
- struct thd_arg a = *(struct thd_arg*)v;
+ struct thd_arg a = *static_cast<struct thd_arg*>(v);
free(v);
if (a.name != nullptr) {
#if GPR_APPLE_PTHREAD_NAME
@@ -77,7 +77,7 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name,
pthread_t p;
/* don't use gpr_malloc as we may cause an infinite recursion with
* the profiling code */
- struct thd_arg* a = (struct thd_arg*)malloc(sizeof(*a));
+ struct thd_arg* a = static_cast<struct thd_arg*>(malloc(sizeof(*a)));
GPR_ASSERT(a != nullptr);
a->body = thd_body;
a->arg = arg;
@@ -99,13 +99,13 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name,
free(a);
dec_thd_count();
}
- *t = (gpr_thd_id)p;
+ *t = static_cast<gpr_thd_id>(p);
return thread_started;
}
-gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)pthread_self(); }
+gpr_thd_id gpr_thd_currentid(void) { return static_cast<gpr_thd_id>(pthread_self()); }
-void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, nullptr); }
+void gpr_thd_join(gpr_thd_id t) { pthread_join(static_cast<pthread_t>(t), nullptr); }
/*****************************************
* Only used when fork support is enabled
diff --git a/src/core/lib/gpr/time.cc b/src/core/lib/gpr/time.cc
index 6903674d75..9ebfaa7525 100644
--- a/src/core/lib/gpr/time.cc
+++ b/src/core/lib/gpr/time.cc
@@ -81,7 +81,7 @@ static gpr_timespec to_seconds_from_sub_second_time(int64_t time_in_units,
units_per_sec) -
1;
}
- out.tv_nsec = (int32_t)((time_in_units - out.tv_sec * units_per_sec) *
+ out.tv_nsec = static_cast<int32_t>((time_in_units - out.tv_sec * units_per_sec) *
GPR_NS_PER_SEC / units_per_sec);
out.clock_type = type;
}
@@ -216,12 +216,12 @@ int32_t gpr_time_to_millis(gpr_timespec t) {
care?) */
return -2147483647;
} else {
- return (int32_t)(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS);
+ return static_cast<int32_t>(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS);
}
}
double gpr_timespec_to_micros(gpr_timespec t) {
- return (double)t.tv_sec * GPR_US_PER_SEC + t.tv_nsec * 1e-3;
+ return static_cast<double>(t.tv_sec) * GPR_US_PER_SEC + t.tv_nsec * 1e-3;
}
gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type) {
diff --git a/src/core/lib/gpr/time_posix.cc b/src/core/lib/gpr/time_posix.cc
index 9c7e86b080..09171c9c48 100644
--- a/src/core/lib/gpr/time_posix.cc
+++ b/src/core/lib/gpr/time_posix.cc
@@ -37,7 +37,7 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) {
/* fine to assert, as this is only used in gpr_sleep_until */
GPR_ASSERT(gts.tv_sec <= INT32_MAX && gts.tv_sec >= INT32_MIN);
}
- rv.tv_sec = (time_t)gts.tv_sec;
+ rv.tv_sec = static_cast<time_t>(gts.tv_sec);
rv.tv_nsec = gts.tv_nsec;
return rv;
}
@@ -52,7 +52,7 @@ static gpr_timespec gpr_from_timespec(struct timespec ts,
*/
gpr_timespec rv;
rv.tv_sec = ts.tv_sec;
- rv.tv_nsec = (int32_t)ts.tv_nsec;
+ rv.tv_nsec = static_cast<int32_t>(ts.tv_nsec);
rv.clock_type = clock_type;
return rv;
}
diff --git a/src/core/lib/http/format_request.cc b/src/core/lib/http/format_request.cc
index 884a70e550..ff273ffc1a 100644
--- a/src/core/lib/http/format_request.cc
+++ b/src/core/lib/http/format_request.cc
@@ -89,7 +89,7 @@ grpc_slice grpc_httpcli_format_post_request(const grpc_httpcli_request* request,
if (!has_content_type) {
gpr_strvec_add(&out, gpr_strdup("Content-Type: text/plain\r\n"));
}
- gpr_asprintf(&tmp, "Content-Length: %lu\r\n", (unsigned long)body_size);
+ gpr_asprintf(&tmp, "Content-Length: %lu\r\n", static_cast<unsigned long>(body_size));
gpr_strvec_add(&out, tmp);
}
gpr_strvec_add(&out, gpr_strdup("\r\n"));
@@ -97,7 +97,7 @@ grpc_slice grpc_httpcli_format_post_request(const grpc_httpcli_request* request,
gpr_strvec_destroy(&out);
if (body_bytes) {
- tmp = (char*)gpr_realloc(tmp, out_len + body_size);
+ tmp = static_cast<char*>(gpr_realloc(tmp, out_len + body_size));
memcpy(tmp + out_len, body_bytes, body_size);
out_len += body_size;
}
diff --git a/src/core/lib/http/httpcli.cc b/src/core/lib/http/httpcli.cc
index 9775ed08ad..2cdca48487 100644
--- a/src/core/lib/http/httpcli.cc
+++ b/src/core/lib/http/httpcli.cc
@@ -123,7 +123,7 @@ static void do_read(internal_request* req) {
}
static void on_read(void* user_data, grpc_error* error) {
- internal_request* req = (internal_request*)user_data;
+ internal_request* req = static_cast<internal_request*>(user_data);
size_t i;
for (i = 0; i < req->incoming.count; i++) {
@@ -150,7 +150,7 @@ static void on_read(void* user_data, grpc_error* error) {
static void on_written(internal_request* req) { do_read(req); }
static void done_write(void* arg, grpc_error* error) {
- internal_request* req = (internal_request*)arg;
+ internal_request* req = static_cast<internal_request*>(arg);
if (error == GRPC_ERROR_NONE) {
on_written(req);
} else {
@@ -165,7 +165,7 @@ static void start_write(internal_request* req) {
}
static void on_handshake_done(void* arg, grpc_endpoint* ep) {
- internal_request* req = (internal_request*)arg;
+ internal_request* req = static_cast<internal_request*>(arg);
if (!ep) {
next_address(req, GRPC_ERROR_CREATE_FROM_STATIC_STRING(
@@ -178,7 +178,7 @@ static void on_handshake_done(void* arg, grpc_endpoint* ep) {
}
static void on_connected(void* arg, grpc_error* error) {
- internal_request* req = (internal_request*)arg;
+ internal_request* req = static_cast<internal_request*>(arg);
if (!req->ep) {
next_address(req, GRPC_ERROR_REF(error));
@@ -212,7 +212,7 @@ static void next_address(internal_request* req, grpc_error* error) {
}
static void on_resolved(void* arg, grpc_error* error) {
- internal_request* req = (internal_request*)arg;
+ internal_request* req = static_cast<internal_request*>(arg);
if (error != GRPC_ERROR_NONE) {
finish(req, GRPC_ERROR_REF(error));
return;
@@ -229,7 +229,7 @@ static void internal_request_begin(grpc_httpcli_context* context,
grpc_httpcli_response* response,
const char* name, grpc_slice request_text) {
internal_request* req =
- (internal_request*)gpr_malloc(sizeof(internal_request));
+ static_cast<internal_request*>(gpr_malloc(sizeof(internal_request)));
memset(req, 0, sizeof(*req));
req->request_text = request_text;
grpc_http_parser_init(&req->parser, GRPC_HTTP_RESPONSE, response);
diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc
index 8664418144..ab684f6093 100644
--- a/src/core/lib/http/httpcli_security_connector.cc
+++ b/src/core/lib/http/httpcli_security_connector.cc
@@ -40,7 +40,7 @@ typedef struct {
static void httpcli_ssl_destroy(grpc_security_connector* sc) {
grpc_httpcli_ssl_channel_security_connector* c =
- (grpc_httpcli_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc);
if (c->handshaker_factory != nullptr) {
tsi_ssl_client_handshaker_factory_unref(c->handshaker_factory);
c->handshaker_factory = nullptr;
@@ -52,7 +52,7 @@ static void httpcli_ssl_destroy(grpc_security_connector* sc) {
static void httpcli_ssl_add_handshakers(grpc_channel_security_connector* sc,
grpc_handshake_manager* handshake_mgr) {
grpc_httpcli_ssl_channel_security_connector* c =
- (grpc_httpcli_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc);
tsi_handshaker* handshaker = nullptr;
if (c->handshaker_factory != nullptr) {
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
@@ -71,7 +71,7 @@ static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_auth_context** auth_context,
grpc_closure* on_peer_checked) {
grpc_httpcli_ssl_channel_security_connector* c =
- (grpc_httpcli_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc);
grpc_error* error = GRPC_ERROR_NONE;
/* Check the peer name. */
@@ -90,9 +90,9 @@ static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer,
static int httpcli_ssl_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
grpc_httpcli_ssl_channel_security_connector* c1 =
- (grpc_httpcli_ssl_channel_security_connector*)sc1;
+ reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc1);
grpc_httpcli_ssl_channel_security_connector* c2 =
- (grpc_httpcli_ssl_channel_security_connector*)sc2;
+ reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc2);
return strcmp(c1->secure_peer_name, c2->secure_peer_name);
}
@@ -111,8 +111,8 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create(
return GRPC_SECURITY_ERROR;
}
- c = (grpc_httpcli_ssl_channel_security_connector*)gpr_zalloc(
- sizeof(grpc_httpcli_ssl_channel_security_connector));
+ c = static_cast<grpc_httpcli_ssl_channel_security_connector*>(gpr_zalloc(
+ sizeof(grpc_httpcli_ssl_channel_security_connector)));
gpr_ref_init(&c->base.base.refcount, 1);
c->base.base.vtable = &httpcli_ssl_vtable;
@@ -146,8 +146,8 @@ typedef struct {
} on_done_closure;
static void on_handshake_done(void* arg, grpc_error* error) {
- grpc_handshaker_args* args = (grpc_handshaker_args*)arg;
- on_done_closure* c = (on_done_closure*)args->user_data;
+ grpc_handshaker_args* args = static_cast<grpc_handshaker_args*>(arg);
+ on_done_closure* c = static_cast<on_done_closure*>(args->user_data);
if (error != GRPC_ERROR_NONE) {
const char* msg = grpc_error_string(error);
gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg);
@@ -166,7 +166,7 @@ static void on_handshake_done(void* arg, grpc_error* error) {
static void ssl_handshake(void* arg, grpc_endpoint* tcp, const char* host,
grpc_millis deadline,
void (*on_done)(void* arg, grpc_endpoint* endpoint)) {
- on_done_closure* c = (on_done_closure*)gpr_malloc(sizeof(*c));
+ on_done_closure* c = static_cast<on_done_closure*>(gpr_malloc(sizeof(*c)));
const char* pem_root_certs = grpc_get_default_ssl_roots();
if (pem_root_certs == nullptr) {
gpr_log(GPR_ERROR, "Could not get default pem root certs.");
diff --git a/src/core/lib/http/parser.cc b/src/core/lib/http/parser.cc
index ee6941fde3..74689a6671 100644
--- a/src/core/lib/http/parser.cc
+++ b/src/core/lib/http/parser.cc
@@ -29,7 +29,7 @@
grpc_core::TraceFlag grpc_http1_trace(false, "http1");
static char* buf2str(void* buffer, size_t length) {
- char* out = (char*)gpr_malloc(length + 1);
+ char* out = static_cast<char*>(gpr_malloc(length + 1));
memcpy(out, buffer, length);
out[length] = 0;
return out;
@@ -88,14 +88,14 @@ static grpc_error* handle_request_line(grpc_http_parser* parser) {
if (cur == end)
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"No method on HTTP request line");
- parser->http.request->method = buf2str(beg, (size_t)(cur - beg - 1));
+ parser->http.request->method = buf2str(beg, static_cast<size_t>(cur - beg - 1));
beg = cur;
while (cur != end && *cur++ != ' ')
;
if (cur == end)
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No path on HTTP request line");
- parser->http.request->path = buf2str(beg, (size_t)(cur - beg - 1));
+ parser->http.request->path = buf2str(beg, static_cast<size_t>(cur - beg - 1));
if (cur == end || *cur++ != 'H')
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'H'");
@@ -107,12 +107,12 @@ static grpc_error* handle_request_line(grpc_http_parser* parser) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'P'");
if (cur == end || *cur++ != '/')
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected '/'");
- vers_major = (uint8_t)(*cur++ - '1' + 1);
+ vers_major = static_cast<uint8_t>(*cur++ - '1' + 1);
++cur;
if (cur == end)
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"End of line in HTTP version string");
- vers_minor = (uint8_t)(*cur++ - '1' + 1);
+ vers_minor = static_cast<uint8_t>(*cur++ - '1' + 1);
if (vers_major == 1) {
if (vers_minor == 0) {
@@ -175,14 +175,14 @@ static grpc_error* add_header(grpc_http_parser* parser) {
goto done;
}
GPR_ASSERT(cur >= beg);
- hdr.key = buf2str(beg, (size_t)(cur - beg));
+ hdr.key = buf2str(beg, static_cast<size_t>(cur - beg));
cur++; /* skip : */
while (cur != end && (*cur == ' ' || *cur == '\t')) {
cur++;
}
GPR_ASSERT((size_t)(end - cur) >= parser->cur_line_end_length);
- hdr.value = buf2str(cur, (size_t)(end - cur) - parser->cur_line_end_length);
+ hdr.value = buf2str(cur, static_cast<size_t>(end - cur) - parser->cur_line_end_length);
switch (parser->type) {
case GRPC_HTTP_RESPONSE:
@@ -198,8 +198,8 @@ static grpc_error* add_header(grpc_http_parser* parser) {
if (*hdr_count == parser->hdr_capacity) {
parser->hdr_capacity =
GPR_MAX(parser->hdr_capacity + 1, parser->hdr_capacity * 3 / 2);
- *hdrs = (grpc_http_header*)gpr_realloc(
- *hdrs, parser->hdr_capacity * sizeof(**hdrs));
+ *hdrs = static_cast<grpc_http_header*>(gpr_realloc(
+ *hdrs, parser->hdr_capacity * sizeof(**hdrs)));
}
(*hdrs)[(*hdr_count)++] = hdr;
@@ -257,9 +257,9 @@ static grpc_error* addbyte_body(grpc_http_parser* parser, uint8_t byte) {
if (*body_length == parser->body_capacity) {
parser->body_capacity = GPR_MAX(8, parser->body_capacity * 3 / 2);
- *body = (char*)gpr_realloc((void*)*body, parser->body_capacity);
+ *body = static_cast<char*>(gpr_realloc((void*)*body, parser->body_capacity));
}
- (*body)[*body_length] = (char)byte;
+ (*body)[*body_length] = static_cast<char>(byte);
(*body_length)++;
return GRPC_ERROR_NONE;
diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc
index 0e4c9cb3b3..f180594545 100644
--- a/src/core/lib/iomgr/call_combiner.cc
+++ b/src/core/lib/iomgr/call_combiner.cc
@@ -28,13 +28,13 @@ grpc_core::TraceFlag grpc_call_combiner_trace(false, "call_combiner");
static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) {
if (cancel_state & 1) {
- return (grpc_error*)(cancel_state & ~(gpr_atm)1);
+ return (grpc_error*)(cancel_state & ~static_cast<gpr_atm>(1));
}
return GRPC_ERROR_NONE;
}
static gpr_atm encode_cancel_state_error(grpc_error* error) {
- return (gpr_atm)1 | (gpr_atm)error;
+ return static_cast<gpr_atm>(1) | (gpr_atm)error;
}
void grpc_call_combiner_init(grpc_call_combiner* call_combiner) {
@@ -69,7 +69,7 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner,
grpc_error_string(error));
}
size_t prev_size =
- (size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1);
+ static_cast<size_t>(gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1));
if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
prev_size + 1);
@@ -90,7 +90,7 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner,
}
// Queue was not empty, so add closure to queue.
closure->error_data.error = error;
- gpr_mpscq_push(&call_combiner->queue, (gpr_mpscq_node*)closure);
+ gpr_mpscq_push(&call_combiner->queue, reinterpret_cast<gpr_mpscq_node*>(closure));
}
}
@@ -103,7 +103,7 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS,
call_combiner DEBUG_FMT_ARGS, reason);
}
size_t prev_size =
- (size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1);
+ static_cast<size_t>(gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1));
if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
prev_size - 1);
@@ -115,8 +115,8 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS,
gpr_log(GPR_DEBUG, " checking queue");
}
bool empty;
- grpc_closure* closure = (grpc_closure*)gpr_mpscq_pop_and_check_end(
- &call_combiner->queue, &empty);
+ grpc_closure* closure = reinterpret_cast<grpc_closure*>(gpr_mpscq_pop_and_check_end(
+ &call_combiner->queue, &empty));
if (closure == nullptr) {
// This can happen either due to a race condition within the mpscq
// code or because of a race with grpc_call_combiner_start().
diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h
index 2bf2578c63..64527d6bb1 100644
--- a/src/core/lib/iomgr/closure.h
+++ b/src/core/lib/iomgr/closure.h
@@ -143,7 +143,7 @@ typedef struct {
} wrapped_closure;
inline void closure_wrapper(void* arg, grpc_error* error) {
- wrapped_closure* wc = (wrapped_closure*)arg;
+ wrapped_closure* wc = static_cast<wrapped_closure*>(arg);
grpc_iomgr_cb_func cb = wc->cb;
void* cb_arg = wc->cb_arg;
gpr_free(wc);
@@ -161,7 +161,7 @@ inline grpc_closure* grpc_closure_create(grpc_iomgr_cb_func cb, void* cb_arg,
grpc_closure_scheduler* scheduler) {
#endif
closure_impl::wrapped_closure* wc =
- (closure_impl::wrapped_closure*)gpr_malloc(sizeof(*wc));
+ static_cast<closure_impl::wrapped_closure*>(gpr_malloc(sizeof(*wc)));
wc->cb = cb;
wc->cb_arg = cb_arg;
#ifndef NDEBUG
diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc
index 2965d807c1..6ff6fccf03 100644
--- a/src/core/lib/iomgr/combiner.cc
+++ b/src/core/lib/iomgr/combiner.cc
@@ -72,7 +72,7 @@ static const grpc_closure_scheduler_vtable finally_scheduler = {
static void offload(void* arg, grpc_error* error);
grpc_combiner* grpc_combiner_create(void) {
- grpc_combiner* lock = (grpc_combiner*)gpr_zalloc(sizeof(*lock));
+ grpc_combiner* lock = static_cast<grpc_combiner*>(gpr_zalloc(sizeof(*lock)));
gpr_ref_init(&lock->refs, 1);
lock->scheduler.vtable = &scheduler;
lock->finally_scheduler.vtable = &finally_scheduler;
@@ -194,7 +194,7 @@ static void move_next() {
}
static void offload(void* arg, grpc_error* error) {
- grpc_combiner* lock = (grpc_combiner*)arg;
+ grpc_combiner* lock = static_cast<grpc_combiner*>(arg);
push_last_on_exec_ctx(lock);
}
@@ -249,7 +249,7 @@ bool grpc_combiner_continue_exec_ctx() {
return true;
}
GPR_TIMER_SCOPE("combiner.exec1", 0);
- grpc_closure* cl = (grpc_closure*)n;
+ grpc_closure* cl = reinterpret_cast<grpc_closure*>(n);
grpc_error* cl_err = cl->error_data.error;
#ifndef NDEBUG
cl->scheduled = false;
@@ -342,7 +342,7 @@ static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) {
}
static void enqueue_finally(void* closure, grpc_error* error) {
- combiner_finally_exec((grpc_closure*)closure, GRPC_ERROR_REF(error));
+ combiner_finally_exec(static_cast<grpc_closure*>(closure), GRPC_ERROR_REF(error));
}
grpc_closure_scheduler* grpc_combiner_scheduler(grpc_combiner* combiner) {
diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc
index d5b5013269..0ba0617f75 100644
--- a/src/core/lib/iomgr/error.cc
+++ b/src/core/lib/iomgr/error.cc
@@ -148,7 +148,7 @@ grpc_error* grpc_error_ref(grpc_error* err) {
static void unref_errs(grpc_error* err) {
uint8_t slot = err->first_err;
while (slot != UINT8_MAX) {
- grpc_linked_error* lerr = (grpc_linked_error*)(err->arena + slot);
+ grpc_linked_error* lerr = reinterpret_cast<grpc_linked_error*>(err->arena + slot);
GRPC_ERROR_UNREF(lerr->err);
GPR_ASSERT(err->last_err == slot ? lerr->next == UINT8_MAX
: lerr->next != UINT8_MAX);
@@ -162,7 +162,7 @@ static void unref_strs(grpc_error* err) {
for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) {
uint8_t slot = err->strs[which];
if (slot != UINT8_MAX) {
- unref_slice(*(grpc_slice*)(err->arena + slot));
+ unref_slice(*reinterpret_cast<grpc_slice*>(err->arena + slot));
}
}
}
@@ -198,18 +198,18 @@ void grpc_error_unref(grpc_error* err) {
static uint8_t get_placement(grpc_error** err, size_t size) {
GPR_ASSERT(*err);
- uint8_t slots = (uint8_t)(size / sizeof(intptr_t));
+ uint8_t slots = static_cast<uint8_t>(size / sizeof(intptr_t));
if ((*err)->arena_size + slots > (*err)->arena_capacity) {
(*err)->arena_capacity =
- (uint8_t)GPR_MIN(UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2));
+ static_cast<uint8_t>GPR_MIN(UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2));
if ((*err)->arena_size + slots > (*err)->arena_capacity) {
return UINT8_MAX;
}
#ifndef NDEBUG
grpc_error* orig = *err;
#endif
- *err = (grpc_error*)gpr_realloc(
- *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t));
+ *err = static_cast<grpc_error*>(gpr_realloc(
+ *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t)));
#ifndef NDEBUG
if (grpc_trace_error_refcount.enabled()) {
if (*err != orig) {
@@ -219,7 +219,7 @@ static uint8_t get_placement(grpc_error** err, size_t size) {
#endif
}
uint8_t placement = (*err)->arena_size;
- (*err)->arena_size = (uint8_t)((*err)->arena_size + slots);
+ (*err)->arena_size = static_cast<uint8_t>((*err)->arena_size + slots);
return placement;
}
@@ -251,7 +251,7 @@ static void internal_set_str(grpc_error** err, grpc_error_strs which,
return;
}
} else {
- unref_slice(*(grpc_slice*)((*err)->arena + slot));
+ unref_slice(*reinterpret_cast<grpc_slice*>((*err)->arena + slot));
}
(*err)->strs[which] = slot;
memcpy((*err)->arena + slot, &value, sizeof(value));
@@ -291,7 +291,7 @@ static void internal_add_error(grpc_error** err, grpc_error* new_err) {
} else {
GPR_ASSERT((*err)->last_err != UINT8_MAX);
grpc_linked_error* old_last =
- (grpc_linked_error*)((*err)->arena + (*err)->last_err);
+ reinterpret_cast<grpc_linked_error*>((*err)->arena + (*err)->last_err);
old_last->next = slot;
(*err)->last_err = slot;
}
@@ -315,11 +315,11 @@ grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc,
grpc_error** referencing,
size_t num_referencing) {
GPR_TIMER_SCOPE("grpc_error_create", 0);
- uint8_t initial_arena_capacity = (uint8_t)(
+ uint8_t initial_arena_capacity = static_cast<uint8_t>(
DEFAULT_ERROR_CAPACITY +
- (uint8_t)(num_referencing * SLOTS_PER_LINKED_ERROR) + SURPLUS_CAPACITY);
- grpc_error* err = (grpc_error*)gpr_malloc(
- sizeof(*err) + initial_arena_capacity * sizeof(intptr_t));
+ static_cast<uint8_t>(num_referencing * SLOTS_PER_LINKED_ERROR) + SURPLUS_CAPACITY);
+ grpc_error* err = static_cast<grpc_error*>(gpr_malloc(
+ sizeof(*err) + initial_arena_capacity * sizeof(intptr_t)));
if (err == nullptr) { // TODO(ctiller): make gpr_malloc return NULL
return GRPC_ERROR_OOM;
}
@@ -362,7 +362,7 @@ static void ref_strs(grpc_error* err) {
for (size_t i = 0; i < GRPC_ERROR_STR_MAX; ++i) {
uint8_t slot = err->strs[i];
if (slot != UINT8_MAX) {
- grpc_slice_ref_internal(*(grpc_slice*)(err->arena + slot));
+ grpc_slice_ref_internal(*reinterpret_cast<grpc_slice*>(err->arena + slot));
}
}
}
@@ -370,7 +370,7 @@ static void ref_strs(grpc_error* err) {
static void ref_errs(grpc_error* err) {
uint8_t slot = err->first_err;
while (slot != UINT8_MAX) {
- grpc_linked_error* lerr = (grpc_linked_error*)(err->arena + slot);
+ grpc_linked_error* lerr = reinterpret_cast<grpc_linked_error*>(err->arena + slot);
GRPC_ERROR_REF(lerr->err);
slot = lerr->next;
}
@@ -399,11 +399,11 @@ static grpc_error* copy_error_and_unref(grpc_error* in) {
uint8_t new_arena_capacity = in->arena_capacity;
// the returned err will be added to, so we ensure this is room to avoid
// unneeded allocations.
- if (in->arena_capacity - in->arena_size < (uint8_t)SLOTS_PER_STR) {
- new_arena_capacity = (uint8_t)(3 * new_arena_capacity / 2);
+ if (in->arena_capacity - in->arena_size < static_cast<uint8_t>SLOTS_PER_STR) {
+ new_arena_capacity = static_cast<uint8_t>(3 * new_arena_capacity / 2);
}
- out = (grpc_error*)gpr_malloc(sizeof(*in) +
- new_arena_capacity * sizeof(intptr_t));
+ out = static_cast<grpc_error*>(gpr_malloc(sizeof(*in) +
+ new_arena_capacity * sizeof(intptr_t)));
#ifndef NDEBUG
if (grpc_trace_error_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%p create copying %p", out, in);
@@ -487,7 +487,7 @@ bool grpc_error_get_str(grpc_error* err, grpc_error_strs which,
}
uint8_t slot = err->strs[which];
if (slot != UINT8_MAX) {
- *str = *(grpc_slice*)(err->arena + slot);
+ *str = *reinterpret_cast<grpc_slice*>(err->arena + slot);
return true;
} else {
return false;
@@ -519,7 +519,7 @@ typedef struct {
static void append_chr(char c, char** s, size_t* sz, size_t* cap) {
if (*sz == *cap) {
*cap = GPR_MAX(8, 3 * *cap / 2);
- *s = (char*)gpr_realloc(*s, *cap);
+ *s = static_cast<char*>(gpr_realloc(*s, *cap));
}
(*s)[(*sz)++] = c;
}
@@ -562,7 +562,7 @@ static void append_esc_str(const uint8_t* str, size_t len, char** s, size_t* sz,
break;
}
} else {
- append_chr((char)*str, s, sz, cap);
+ append_chr(static_cast<char>(*str), s, sz, cap);
}
}
append_chr('"', s, sz, cap);
@@ -572,7 +572,7 @@ static void append_kv(kv_pairs* kvs, char* key, char* value) {
if (kvs->num_kvs == kvs->cap_kvs) {
kvs->cap_kvs = GPR_MAX(3 * kvs->cap_kvs / 2, 4);
kvs->kvs =
- (kv_pair*)gpr_realloc(kvs->kvs, sizeof(*kvs->kvs) * kvs->cap_kvs);
+ static_cast<kv_pair*>(gpr_realloc(kvs->kvs, sizeof(*kvs->kvs) * kvs->cap_kvs));
}
kvs->kvs[kvs->num_kvs].key = key;
kvs->kvs[kvs->num_kvs].value = value;
@@ -593,7 +593,7 @@ static void collect_ints_kvs(grpc_error* err, kv_pairs* kvs) {
for (size_t which = 0; which < GRPC_ERROR_INT_MAX; ++which) {
uint8_t slot = err->ints[which];
if (slot != UINT8_MAX) {
- append_kv(kvs, key_int((grpc_error_ints)which),
+ append_kv(kvs, key_int(static_cast<grpc_error_ints>(which)),
fmt_int(err->arena[slot]));
}
}
@@ -617,8 +617,8 @@ static void collect_strs_kvs(grpc_error* err, kv_pairs* kvs) {
for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) {
uint8_t slot = err->strs[which];
if (slot != UINT8_MAX) {
- append_kv(kvs, key_str((grpc_error_strs)which),
- fmt_str(*(grpc_slice*)(err->arena + slot)));
+ append_kv(kvs, key_str(static_cast<grpc_error_strs>(which)),
+ fmt_str(*reinterpret_cast<grpc_slice*>(err->arena + slot)));
}
}
}
@@ -652,8 +652,8 @@ static void collect_times_kvs(grpc_error* err, kv_pairs* kvs) {
for (size_t which = 0; which < GRPC_ERROR_TIME_MAX; ++which) {
uint8_t slot = err->times[which];
if (slot != UINT8_MAX) {
- append_kv(kvs, key_time((grpc_error_times)which),
- fmt_time(*(gpr_timespec*)(err->arena + slot)));
+ append_kv(kvs, key_time(static_cast<grpc_error_times>(which)),
+ fmt_time(*reinterpret_cast<gpr_timespec*>(err->arena + slot)));
}
}
}
@@ -662,7 +662,7 @@ static void add_errs(grpc_error* err, char** s, size_t* sz, size_t* cap) {
uint8_t slot = err->first_err;
bool first = true;
while (slot != UINT8_MAX) {
- grpc_linked_error* lerr = (grpc_linked_error*)(err->arena + slot);
+ grpc_linked_error* lerr = reinterpret_cast<grpc_linked_error*>(err->arena + slot);
if (!first) append_chr(',', s, sz, cap);
first = false;
const char* e = grpc_error_string(lerr->err);
@@ -685,8 +685,8 @@ static char* errs_string(grpc_error* err) {
}
static int cmp_kvs(const void* a, const void* b) {
- const kv_pair* ka = (const kv_pair*)a;
- const kv_pair* kb = (const kv_pair*)b;
+ const kv_pair* ka = static_cast<const kv_pair*>(a);
+ const kv_pair* kb = static_cast<const kv_pair*>(b);
return strcmp(ka->key, kb->key);
}
@@ -698,7 +698,7 @@ static char* finish_kvs(kv_pairs* kvs) {
append_chr('{', &s, &sz, &cap);
for (size_t i = 0; i < kvs->num_kvs; i++) {
if (i != 0) append_chr(',', &s, &sz, &cap);
- append_esc_str((const uint8_t*)kvs->kvs[i].key, strlen(kvs->kvs[i].key), &s,
+ append_esc_str(reinterpret_cast<const uint8_t*>(kvs->kvs[i].key), strlen(kvs->kvs[i].key), &s,
&sz, &cap);
gpr_free(kvs->kvs[i].key);
append_chr(':', &s, &sz, &cap);
@@ -720,7 +720,7 @@ const char* grpc_error_string(grpc_error* err) {
void* p = (void*)gpr_atm_acq_load(&err->atomics.error_string);
if (p != nullptr) {
- return (const char*)p;
+ return static_cast<const char*>(p);
}
kv_pairs kvs;
diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc
index a05d74c50a..ad013c01b6 100644
--- a/src/core/lib/iomgr/ev_epoll1_linux.cc
+++ b/src/core/lib/iomgr/ev_epoll1_linux.cc
@@ -281,7 +281,7 @@ static grpc_fd* fd_create(int fd, const char* name) {
gpr_mu_unlock(&fd_freelist_mu);
if (new_fd == nullptr) {
- new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd));
+ new_fd = static_cast<grpc_fd*>(gpr_malloc(sizeof(grpc_fd)));
new_fd->read_closure.Init();
new_fd->write_closure.Init();
}
@@ -304,7 +304,7 @@ static grpc_fd* fd_create(int fd, const char* name) {
gpr_free(fd_name);
struct epoll_event ev;
- ev.events = (uint32_t)(EPOLLIN | EPOLLOUT | EPOLLET);
+ ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLOUT | EPOLLET);
ev.data.ptr = new_fd;
if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_ADD, fd, &ev) != 0) {
gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno));
@@ -440,7 +440,7 @@ static worker_remove_result worker_remove(grpc_pollset* pollset,
}
static size_t choose_neighborhood(void) {
- return (size_t)gpr_cpu_current_cpu() % g_num_neighborhoods;
+ return static_cast<size_t>(gpr_cpu_current_cpu()) % g_num_neighborhoods;
}
static grpc_error* pollset_global_init(void) {
@@ -451,15 +451,15 @@ static grpc_error* pollset_global_init(void) {
grpc_error* err = grpc_wakeup_fd_init(&global_wakeup_fd);
if (err != GRPC_ERROR_NONE) return err;
struct epoll_event ev;
- ev.events = (uint32_t)(EPOLLIN | EPOLLET);
+ ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLET);
ev.data.ptr = &global_wakeup_fd;
if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_ADD, global_wakeup_fd.read_fd,
&ev) != 0) {
return GRPC_OS_ERROR(errno, "epoll_ctl");
}
g_num_neighborhoods = GPR_CLAMP(gpr_cpu_num_cores(), 1, MAX_NEIGHBORHOODS);
- g_neighborhoods = (pollset_neighborhood*)gpr_zalloc(sizeof(*g_neighborhoods) *
- g_num_neighborhoods);
+ g_neighborhoods = static_cast<pollset_neighborhood*>(gpr_zalloc(sizeof(*g_neighborhoods) *
+ g_num_neighborhoods));
for (size_t i = 0; i < g_num_neighborhoods; i++) {
gpr_mu_init(&g_neighborhoods[i].mu);
}
@@ -579,7 +579,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) {
} else if (delta < 0) {
return 0;
} else {
- return (int)delta;
+ return static_cast<int>(delta);
}
}
@@ -609,7 +609,7 @@ static grpc_error* process_epoll_events(grpc_pollset* pollset) {
append_error(&error, grpc_wakeup_fd_consume_wakeup(&global_wakeup_fd),
err_desc);
} else {
- grpc_fd* fd = (grpc_fd*)(data_ptr);
+ grpc_fd* fd = static_cast<grpc_fd*>(data_ptr);
bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0;
bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0;
bool write_ev = (ev->events & EPOLLOUT) != 0;
@@ -881,7 +881,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
} else {
gpr_atm_no_barrier_store(&g_active_poller, 0);
size_t poller_neighborhood_idx =
- (size_t)(pollset->neighborhood - g_neighborhoods);
+ static_cast<size_t>(pollset->neighborhood - g_neighborhoods);
gpr_mu_unlock(&pollset->mu);
bool found_worker = false;
bool scan_state[MAX_NEIGHBORHOODS];
@@ -1150,7 +1150,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {}
*/
static grpc_pollset_set* pollset_set_create(void) {
- return (grpc_pollset_set*)((intptr_t)0xdeafbeef);
+ return (grpc_pollset_set*)(static_cast<intptr_t>(0xdeafbeef));
}
static void pollset_set_destroy(grpc_pollset_set* pss) {}
diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc
index 000faed1d9..e201845cd2 100644
--- a/src/core/lib/iomgr/ev_epollex_linux.cc
+++ b/src/core/lib/iomgr/ev_epollex_linux.cc
@@ -276,7 +276,7 @@ static void ref_by(grpc_fd* fd, int n) {
}
static void fd_destroy(void* arg, grpc_error* error) {
- grpc_fd* fd = (grpc_fd*)arg;
+ grpc_fd* fd = static_cast<grpc_fd*>(arg);
/* Add the fd to the freelist */
grpc_iomgr_unregister_object(&fd->iomgr_object);
POLLABLE_UNREF(fd->pollable_obj, "fd_pollable");
@@ -338,7 +338,7 @@ static grpc_fd* fd_create(int fd, const char* name) {
gpr_mu_unlock(&fd_freelist_mu);
if (new_fd == nullptr) {
- new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd));
+ new_fd = static_cast<grpc_fd*>(gpr_malloc(sizeof(grpc_fd)));
new_fd->read_closure.Init();
new_fd->write_closure.Init();
}
@@ -441,7 +441,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) {
if (epfd == -1) {
return GRPC_OS_ERROR(errno, "epoll_create1");
}
- *p = (pollable*)gpr_malloc(sizeof(**p));
+ *p = static_cast<pollable*>(gpr_malloc(sizeof(**p)));
grpc_error* err = grpc_wakeup_fd_init(&(*p)->wakeup);
if (err != GRPC_ERROR_NONE) {
close(epfd);
@@ -450,7 +450,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) {
return err;
}
struct epoll_event ev;
- ev.events = (uint32_t)(EPOLLIN | EPOLLET);
+ ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLET);
ev.data.ptr = (void*)(1 | (intptr_t) & (*p)->wakeup);
if (epoll_ctl(epfd, EPOLL_CTL_ADD, (*p)->wakeup.read_fd, &ev) != 0) {
err = GRPC_OS_ERROR(errno, "epoll_ctl");
@@ -479,7 +479,7 @@ static pollable* pollable_ref(pollable* p) {
#else
static pollable* pollable_ref(pollable* p, int line, const char* reason) {
if (grpc_trace_pollable_refcount.enabled()) {
- int r = (int)gpr_atm_no_barrier_load(&p->refs.count);
+ int r = static_cast<int>gpr_atm_no_barrier_load(&p->refs.count);
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
"POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason);
}
@@ -494,7 +494,7 @@ static void pollable_unref(pollable* p) {
static void pollable_unref(pollable* p, int line, const char* reason) {
if (p == nullptr) return;
if (grpc_trace_pollable_refcount.enabled()) {
- int r = (int)gpr_atm_no_barrier_load(&p->refs.count);
+ int r = static_cast<int>gpr_atm_no_barrier_load(&p->refs.count);
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
"POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason);
}
@@ -516,7 +516,7 @@ static grpc_error* pollable_add_fd(pollable* p, grpc_fd* fd) {
}
struct epoll_event ev_fd;
- ev_fd.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE);
+ ev_fd.events = static_cast<uint32_t>(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE);
ev_fd.data.ptr = fd;
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd->fd, &ev_fd) != 0) {
switch (errno) {
@@ -699,7 +699,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) {
else if (delta < 0)
return 0;
else
- return (int)delta;
+ return static_cast<int>(delta);
}
static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) {
@@ -768,10 +768,10 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset,
}
append_error(&error,
grpc_wakeup_fd_consume_wakeup(
- (grpc_wakeup_fd*)((~(intptr_t)1) & (intptr_t)data_ptr)),
+ (grpc_wakeup_fd*)((~static_cast<intptr_t>(1)) & (intptr_t)data_ptr)),
err_desc);
} else {
- grpc_fd* fd = (grpc_fd*)data_ptr;
+ grpc_fd* fd = static_cast<grpc_fd*>(data_ptr);
bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0;
bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0;
bool write_ev = (ev->events & EPOLLOUT) != 0;
@@ -1170,7 +1170,7 @@ static grpc_pollset_set* pss_lock_adam(grpc_pollset_set* pss) {
}
static grpc_pollset_set* pollset_set_create(void) {
- grpc_pollset_set* pss = (grpc_pollset_set*)gpr_zalloc(sizeof(*pss));
+ grpc_pollset_set* pss = static_cast<grpc_pollset_set*>(gpr_zalloc(sizeof(*pss)));
gpr_mu_init(&pss->mu);
gpr_ref_init(&pss->refs, 1);
return pss;
@@ -1211,7 +1211,7 @@ static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {
if (pss->fd_count == pss->fd_capacity) {
pss->fd_capacity = GPR_MAX(pss->fd_capacity * 2, 8);
pss->fds =
- (grpc_fd**)gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds));
+ static_cast<grpc_fd**>(gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds)));
}
REF_BY(fd, 2, "pollset_set");
pss->fds[pss->fd_count++] = fd;
@@ -1319,8 +1319,8 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
err_desc);
if (pss->pollset_count == pss->pollset_capacity) {
pss->pollset_capacity = GPR_MAX(pss->pollset_capacity * 2, 8);
- pss->pollsets = (grpc_pollset**)gpr_realloc(
- pss->pollsets, pss->pollset_capacity * sizeof(*pss->pollsets));
+ pss->pollsets = static_cast<grpc_pollset**>(gpr_realloc(
+ pss->pollsets, pss->pollset_capacity * sizeof(*pss->pollsets)));
}
pss->pollsets[pss->pollset_count++] = ps;
gpr_mu_unlock(&pss->mu);
@@ -1373,7 +1373,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
b->parent = a;
if (a->fd_capacity < a->fd_count + b->fd_count) {
a->fd_capacity = GPR_MAX(2 * a->fd_capacity, a->fd_count + b->fd_count);
- a->fds = (grpc_fd**)gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds));
+ a->fds = static_cast<grpc_fd**>(gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds)));
}
size_t initial_a_fd_count = a->fd_count;
a->fd_count = 0;
@@ -1390,8 +1390,8 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
if (a->pollset_capacity < a->pollset_count + b->pollset_count) {
a->pollset_capacity =
GPR_MAX(2 * a->pollset_capacity, a->pollset_count + b->pollset_count);
- a->pollsets = (grpc_pollset**)gpr_realloc(
- a->pollsets, a->pollset_capacity * sizeof(*a->pollsets));
+ a->pollsets = static_cast<grpc_pollset**>(gpr_realloc(
+ a->pollsets, a->pollset_capacity * sizeof(*a->pollsets)));
}
if (b->pollset_count > 0) {
memcpy(a->pollsets + a->pollset_count, b->pollsets,
diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc
index 4c26bbd2c6..438b4c8c09 100644
--- a/src/core/lib/iomgr/ev_epollsig_linux.cc
+++ b/src/core/lib/iomgr/ev_epollsig_linux.cc
@@ -349,7 +349,7 @@ static void polling_island_add_fds_locked(polling_island* pi, grpc_fd** fds,
#endif /* defined(GRPC_TSAN) */
for (i = 0; i < fd_count; i++) {
- ev.events = (uint32_t)(EPOLLIN | EPOLLOUT | EPOLLET);
+ ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLOUT | EPOLLET);
ev.data.ptr = fds[i];
err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_ADD, fds[i]->fd, &ev);
@@ -369,7 +369,7 @@ static void polling_island_add_fds_locked(polling_island* pi, grpc_fd** fds,
if (pi->fd_cnt == pi->fd_capacity) {
pi->fd_capacity = GPR_MAX(pi->fd_capacity + 8, pi->fd_cnt * 3 / 2);
pi->fds =
- (grpc_fd**)gpr_realloc(pi->fds, sizeof(grpc_fd*) * pi->fd_capacity);
+ static_cast<grpc_fd**>(gpr_realloc(pi->fds, sizeof(grpc_fd*) * pi->fd_capacity));
}
pi->fds[pi->fd_cnt++] = fds[i];
@@ -388,7 +388,7 @@ static void polling_island_add_wakeup_fd_locked(polling_island* pi,
char* err_msg;
const char* err_desc = "polling_island_add_wakeup_fd";
- ev.events = (uint32_t)(EPOLLIN | EPOLLET);
+ ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLET);
ev.data.ptr = wakeup_fd;
err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_ADD,
GRPC_WAKEUP_FD_GET_READ_FD(wakeup_fd), &ev);
@@ -471,7 +471,7 @@ static polling_island* polling_island_create(grpc_fd* initial_fd,
*error = GRPC_ERROR_NONE;
- pi = (polling_island*)gpr_malloc(sizeof(*pi));
+ pi = static_cast<polling_island*>(gpr_malloc(sizeof(*pi)));
gpr_mu_init(&pi->mu);
pi->fd_cnt = 0;
pi->fd_capacity = 0;
@@ -815,7 +815,7 @@ static grpc_fd* fd_create(int fd, const char* name) {
gpr_mu_unlock(&fd_freelist_mu);
if (new_fd == nullptr) {
- new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd));
+ new_fd = static_cast<grpc_fd*>(gpr_malloc(sizeof(grpc_fd)));
gpr_mu_init(&new_fd->po.mu);
new_fd->read_closure.Init();
new_fd->write_closure.Init();
@@ -976,7 +976,7 @@ static grpc_error* pollset_worker_kick(grpc_pollset_worker* worker) {
grpc_error* err = GRPC_ERROR_NONE;
/* Kick the worker only if it was not already kicked */
- if (gpr_atm_no_barrier_cas(&worker->is_kicked, (gpr_atm)0, (gpr_atm)1)) {
+ if (gpr_atm_no_barrier_cas(&worker->is_kicked, static_cast<gpr_atm>(0), static_cast<gpr_atm>(1))) {
GRPC_POLLING_TRACE(
"pollset_worker_kick: Kicking worker: %p (thread id: %ld)",
(void*)worker, (long int)worker->pt_id);
@@ -1096,7 +1096,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) {
else if (delta < 0)
return 0;
else
- return (int)delta;
+ return static_cast<int>(delta);
}
static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) {
@@ -1251,7 +1251,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset,
to the function pollset_work_and_unlock() will pick up the correct
epoll_fd */
} else {
- grpc_fd* fd = (grpc_fd*)data_ptr;
+ grpc_fd* fd = static_cast<grpc_fd*>(data_ptr);
int cancel = ep_ev[i].events & (EPOLLERR | EPOLLHUP);
int read_ev = ep_ev[i].events & (EPOLLIN | EPOLLPRI);
int write_ev = ep_ev[i].events & EPOLLOUT;
@@ -1538,7 +1538,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
*/
static grpc_pollset_set* pollset_set_create(void) {
- grpc_pollset_set* pss = (grpc_pollset_set*)gpr_malloc(sizeof(*pss));
+ grpc_pollset_set* pss = static_cast<grpc_pollset_set*>(gpr_malloc(sizeof(*pss)));
gpr_mu_init(&pss->po.mu);
pss->po.pi = nullptr;
#ifndef NDEBUG
@@ -1607,8 +1607,8 @@ void* grpc_pollset_get_polling_island(grpc_pollset* ps) {
}
bool grpc_are_polling_islands_equal(void* p, void* q) {
- polling_island* p1 = (polling_island*)p;
- polling_island* p2 = (polling_island*)q;
+ polling_island* p1 = static_cast<polling_island*>(p);
+ polling_island* p2 = static_cast<polling_island*>(q);
/* Note: polling_island_lock_pair() may change p1 and p2 to point to the
latest polling islands in their respective linked lists */
diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc
index 9833b47bd3..769fdbc299 100644
--- a/src/core/lib/iomgr/ev_poll_posix.cc
+++ b/src/core/lib/iomgr/ev_poll_posix.cc
@@ -323,7 +323,7 @@ static void unref_by(grpc_fd* fd, int n) {
}
static grpc_fd* fd_create(int fd, const char* name) {
- grpc_fd* r = (grpc_fd*)gpr_malloc(sizeof(*r));
+ grpc_fd* r = static_cast<grpc_fd*>(gpr_malloc(sizeof(*r)));
gpr_mu_init(&r->mu);
gpr_atm_rel_store(&r->refst, 1);
r->shutdown = 0;
@@ -835,8 +835,8 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
if (pollset->fd_count == pollset->fd_capacity) {
pollset->fd_capacity =
GPR_MAX(pollset->fd_capacity + 8, pollset->fd_count * 3 / 2);
- pollset->fds = (grpc_fd**)gpr_realloc(
- pollset->fds, sizeof(grpc_fd*) * pollset->fd_capacity);
+ pollset->fds = static_cast<grpc_fd**>(gpr_realloc(
+ pollset->fds, sizeof(grpc_fd*) * pollset->fd_capacity));
}
pollset->fds[pollset->fd_count++] = fd;
GRPC_FD_REF(fd, "multipoller");
@@ -890,7 +890,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
pollset->local_wakeup_cache = worker.wakeup_fd->next;
} else {
worker.wakeup_fd =
- (grpc_cached_wakeup_fd*)gpr_malloc(sizeof(*worker.wakeup_fd));
+ static_cast<grpc_cached_wakeup_fd*>(gpr_malloc(sizeof(*worker.wakeup_fd)));
error = grpc_wakeup_fd_init(&worker.wakeup_fd->fd);
if (error != GRPC_ERROR_NONE) {
GRPC_LOG_IF_ERROR("pollset_work", GRPC_ERROR_REF(error));
@@ -945,8 +945,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
const size_t pfd_size = sizeof(*pfds) * (pollset->fd_count + 2);
const size_t watch_size = sizeof(*watchers) * (pollset->fd_count + 2);
void* buf = gpr_malloc(pfd_size + watch_size);
- pfds = (struct pollfd*)buf;
- watchers = (grpc_fd_watcher*)(void*)((char*)buf + pfd_size);
+ pfds = static_cast<struct pollfd*>(buf);
+ watchers = static_cast<grpc_fd_watcher*>((void*)(static_cast<char*>(buf) + pfd_size));
}
fd_count = 0;
@@ -972,8 +972,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
for (i = 1; i < pfd_count; i++) {
grpc_fd* fd = watchers[i].fd;
- pfds[i].events = (short)fd_begin_poll(fd, pollset, &worker, POLLIN,
- POLLOUT, &watchers[i]);
+ pfds[i].events = static_cast<short>(fd_begin_poll(fd, pollset, &worker, POLLIN,
+ POLLOUT, &watchers[i]));
GRPC_FD_UNREF(fd, "multipoller_start");
}
@@ -1123,7 +1123,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis deadline) {
grpc_millis n = deadline - grpc_core::ExecCtx::Get()->Now();
if (n < 0) return 0;
if (n > INT_MAX) return -1;
- return (int)n;
+ return static_cast<int>(n);
}
/*******************************************************************************
@@ -1132,7 +1132,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis deadline) {
static grpc_pollset_set* pollset_set_create(void) {
grpc_pollset_set* pollset_set =
- (grpc_pollset_set*)gpr_zalloc(sizeof(*pollset_set));
+ static_cast<grpc_pollset_set*>(gpr_zalloc(sizeof(*pollset_set)));
gpr_mu_init(&pollset_set->mu);
return pollset_set;
}
@@ -1173,9 +1173,9 @@ static void pollset_set_add_pollset(grpc_pollset_set* pollset_set,
if (pollset_set->pollset_count == pollset_set->pollset_capacity) {
pollset_set->pollset_capacity =
GPR_MAX(8, 2 * pollset_set->pollset_capacity);
- pollset_set->pollsets = (grpc_pollset**)gpr_realloc(
+ pollset_set->pollsets = static_cast<grpc_pollset**>(gpr_realloc(
pollset_set->pollsets,
- pollset_set->pollset_capacity * sizeof(*pollset_set->pollsets));
+ pollset_set->pollset_capacity * sizeof(*pollset_set->pollsets)));
}
pollset_set->pollsets[pollset_set->pollset_count++] = pollset;
for (i = 0, j = 0; i < pollset_set->fd_count; i++) {
@@ -1222,9 +1222,9 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* bag,
gpr_mu_lock(&bag->mu);
if (bag->pollset_set_count == bag->pollset_set_capacity) {
bag->pollset_set_capacity = GPR_MAX(8, 2 * bag->pollset_set_capacity);
- bag->pollset_sets = (grpc_pollset_set**)gpr_realloc(
+ bag->pollset_sets = static_cast<grpc_pollset_set**>(gpr_realloc(
bag->pollset_sets,
- bag->pollset_set_capacity * sizeof(*bag->pollset_sets));
+ bag->pollset_set_capacity * sizeof(*bag->pollset_sets)));
}
bag->pollset_sets[bag->pollset_set_count++] = item;
for (i = 0, j = 0; i < bag->fd_count; i++) {
@@ -1259,8 +1259,8 @@ static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) {
gpr_mu_lock(&pollset_set->mu);
if (pollset_set->fd_count == pollset_set->fd_capacity) {
pollset_set->fd_capacity = GPR_MAX(8, 2 * pollset_set->fd_capacity);
- pollset_set->fds = (grpc_fd**)gpr_realloc(
- pollset_set->fds, pollset_set->fd_capacity * sizeof(*pollset_set->fds));
+ pollset_set->fds = static_cast<grpc_fd**>(gpr_realloc(
+ pollset_set->fds, pollset_set->fd_capacity * sizeof(*pollset_set->fds)));
}
GRPC_FD_REF(fd, "pollset_set");
pollset_set->fds[pollset_set->fd_count++] = fd;
@@ -1312,12 +1312,12 @@ static void cache_insert_locked(poll_args* args) {
}
static void init_result(poll_args* pargs) {
- pargs->result = (poll_result*)gpr_malloc(sizeof(poll_result));
+ pargs->result = static_cast<poll_result*>(gpr_malloc(sizeof(poll_result)));
gpr_ref_init(&pargs->result->refcount, 1);
pargs->result->watchers = nullptr;
pargs->result->watchcount = 0;
pargs->result->fds =
- (struct pollfd*)gpr_malloc(sizeof(struct pollfd) * pargs->nfds);
+ static_cast<struct pollfd*>(gpr_malloc(sizeof(struct pollfd) * pargs->nfds));
memcpy(pargs->result->fds, pargs->fds, sizeof(struct pollfd) * pargs->nfds);
pargs->result->nfds = pargs->nfds;
pargs->result->retval = 0;
@@ -1356,7 +1356,7 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) {
return pargs;
}
- poll_args* pargs = (poll_args*)gpr_malloc(sizeof(struct poll_args));
+ poll_args* pargs = static_cast<poll_args*>(gpr_malloc(sizeof(struct poll_args)));
gpr_cv_init(&pargs->trigger);
pargs->fds = fds;
pargs->nfds = count;
@@ -1404,7 +1404,7 @@ static void cache_poller_locked(poll_args* args) {
poll_cache.size = poll_cache.size * 2;
poll_cache.count = 0;
poll_cache.active_pollers =
- (poll_args**)gpr_malloc(sizeof(void*) * poll_cache.size);
+ static_cast<poll_args**>(gpr_malloc(sizeof(void*) * poll_cache.size));
for (unsigned int i = 0; i < poll_cache.size; i++) {
poll_cache.active_pollers[i] = nullptr;
}
@@ -1461,7 +1461,7 @@ gpr_timespec thread_grace;
// Poll in a background thread
static void run_poll(void* args) {
- poll_args* pargs = (poll_args*)args;
+ poll_args* pargs = static_cast<poll_args*>(args);
while (1) {
poll_result* result = pargs->result;
int retval = g_cvfds.poll(result->fds, result->nfds, CV_POLL_PERIOD_MS);
@@ -1509,12 +1509,12 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) {
nfds_t nsockfds = 0;
poll_result* result = nullptr;
gpr_mu_lock(&g_cvfds.mu);
- pollcv = (grpc_cv_node*)gpr_malloc(sizeof(grpc_cv_node));
+ pollcv = static_cast<grpc_cv_node*>(gpr_malloc(sizeof(grpc_cv_node)));
pollcv->next = nullptr;
gpr_cv pollcv_cv;
gpr_cv_init(&pollcv_cv);
pollcv->cv = &pollcv_cv;
- grpc_cv_node* fd_cvs = (grpc_cv_node*)gpr_malloc(nfds * sizeof(grpc_cv_node));
+ grpc_cv_node* fd_cvs = static_cast<grpc_cv_node*>(gpr_malloc(nfds * sizeof(grpc_cv_node)));
for (i = 0; i < nfds; i++) {
fds[i].revents = 0;
@@ -1547,7 +1547,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) {
res = 0;
if (!skip_poll && nsockfds > 0) {
struct pollfd* pollfds =
- (struct pollfd*)gpr_malloc(sizeof(struct pollfd) * nsockfds);
+ static_cast<struct pollfd*>(gpr_malloc(sizeof(struct pollfd) * nsockfds));
idx = 0;
for (i = 0; i < nfds; i++) {
if (fds[i].fd >= 0) {
@@ -1611,7 +1611,7 @@ static void global_cv_fd_table_init() {
gpr_ref_init(&g_cvfds.pollcount, 1);
g_cvfds.size = CV_DEFAULT_TABLE_SIZE;
g_cvfds.cvfds =
- (grpc_fd_node*)gpr_malloc(sizeof(grpc_fd_node) * CV_DEFAULT_TABLE_SIZE);
+ static_cast<grpc_fd_node*>(gpr_malloc(sizeof(grpc_fd_node) * CV_DEFAULT_TABLE_SIZE));
g_cvfds.free_fds = nullptr;
thread_grace = gpr_time_from_millis(POLLCV_THREAD_GRACE_MS, GPR_TIMESPAN);
for (int i = 0; i < CV_DEFAULT_TABLE_SIZE; i++) {
@@ -1628,7 +1628,7 @@ static void global_cv_fd_table_init() {
poll_cache.size = 32;
poll_cache.count = 0;
poll_cache.free_pollers = nullptr;
- poll_cache.active_pollers = (poll_args**)gpr_malloc(sizeof(void*) * 32);
+ poll_cache.active_pollers = static_cast<poll_args**>(gpr_malloc(sizeof(void*) * 32));
for (unsigned int i = 0; i < poll_cache.size; i++) {
poll_cache.active_pollers[i] = nullptr;
}
diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc
index af5dfe5bf3..4280794428 100644
--- a/src/core/lib/iomgr/ev_posix.cc
+++ b/src/core/lib/iomgr/ev_posix.cc
@@ -108,11 +108,11 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) {
char* s;
size_t len;
GPR_ASSERT(end >= beg);
- len = (size_t)(end - beg);
- s = (char*)gpr_malloc(len + 1);
+ len = static_cast<size_t>(end - beg);
+ s = static_cast<char*>(gpr_malloc(len + 1));
memcpy(s, beg, len);
s[len] = 0;
- *ss = (char**)gpr_realloc(*ss, sizeof(char**) * np);
+ *ss = static_cast<char**>(gpr_realloc(*ss, sizeof(char**) * np));
(*ss)[n] = s;
*ns = np;
}
diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc
index 03c833ff07..89c6a873e6 100644
--- a/src/core/lib/iomgr/exec_ctx.cc
+++ b/src/core/lib/iomgr/exec_ctx.cc
@@ -54,20 +54,20 @@ static gpr_timespec g_start_time;
static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) {
ts = gpr_time_sub(ts, g_start_time);
double x =
- GPR_MS_PER_SEC * (double)ts.tv_sec + (double)ts.tv_nsec / GPR_NS_PER_MS;
+ GPR_MS_PER_SEC * static_cast<double>(ts.tv_sec) + static_cast<double>(ts.tv_nsec) / GPR_NS_PER_MS;
if (x < 0) return 0;
if (x > GPR_ATM_MAX) return GPR_ATM_MAX;
- return (gpr_atm)x;
+ return static_cast<gpr_atm>(x);
}
static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) {
ts = gpr_time_sub(ts, g_start_time);
- double x = GPR_MS_PER_SEC * (double)ts.tv_sec +
- (double)ts.tv_nsec / GPR_NS_PER_MS +
- (double)(GPR_NS_PER_SEC - 1) / (double)GPR_NS_PER_SEC;
+ double x = GPR_MS_PER_SEC * static_cast<double>(ts.tv_sec) +
+ static_cast<double>(ts.tv_nsec) / GPR_NS_PER_MS +
+ static_cast<double>(GPR_NS_PER_SEC - 1) / static_cast<double>(GPR_NS_PER_SEC);
if (x < 0) return 0;
if (x > GPR_ATM_MAX) return GPR_ATM_MAX;
- return (gpr_atm)x;
+ return static_cast<gpr_atm>(x);
}
gpr_timespec grpc_millis_to_timespec(grpc_millis millis,
diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc
index 3288ea3de5..901bbdd4df 100644
--- a/src/core/lib/iomgr/executor.cc
+++ b/src/core/lib/iomgr/executor.cc
@@ -95,7 +95,7 @@ void grpc_executor_set_threading(bool threading) {
gpr_atm_no_barrier_store(&g_cur_threads, 1);
gpr_tls_init(&g_this_thread_state);
g_thread_state =
- (thread_state*)gpr_zalloc(sizeof(thread_state) * g_max_threads);
+ static_cast<thread_state*>(gpr_zalloc(sizeof(thread_state) * g_max_threads));
for (size_t i = 0; i < g_max_threads; i++) {
gpr_mu_init(&g_thread_state[i].mu);
gpr_cv_init(&g_thread_state[i].cv);
@@ -140,7 +140,7 @@ void grpc_executor_init() {
void grpc_executor_shutdown() { grpc_executor_set_threading(false); }
static void executor_thread(void* arg) {
- thread_state* ts = (thread_state*)arg;
+ thread_state* ts = static_cast<thread_state*>(arg);
gpr_tls_set(&g_this_thread_state, (intptr_t)ts);
grpc_core::ExecCtx exec_ctx(0);
@@ -149,7 +149,7 @@ static void executor_thread(void* arg) {
for (;;) {
if (executor_trace.enabled()) {
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: step (sub_depth=%" PRIdPTR ")",
- (int)(ts - g_thread_state), subtract_depth);
+ static_cast<int>(ts - g_thread_state), subtract_depth);
}
gpr_mu_lock(&ts->mu);
ts->depth -= subtract_depth;
@@ -160,7 +160,7 @@ static void executor_thread(void* arg) {
if (ts->shutdown) {
if (executor_trace.enabled()) {
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: shutdown",
- (int)(ts - g_thread_state));
+ static_cast<int>(ts - g_thread_state));
}
gpr_mu_unlock(&ts->mu);
break;
@@ -170,7 +170,7 @@ static void executor_thread(void* arg) {
ts->elems = GRPC_CLOSURE_LIST_INIT;
gpr_mu_unlock(&ts->mu);
if (executor_trace.enabled()) {
- gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state));
+ gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", static_cast<int>(ts - g_thread_state));
}
grpc_core::ExecCtx::Get()->InvalidateNow();
@@ -188,7 +188,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error,
}
do {
retry_push = false;
- size_t cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads);
+ size_t cur_thread_count = static_cast<size_t>gpr_atm_no_barrier_load(&g_cur_threads);
if (cur_thread_count == 0) {
if (executor_trace.enabled()) {
#ifndef NDEBUG
@@ -219,7 +219,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error,
GPR_DEBUG,
"EXECUTOR: try to schedule %p (%s) (created %s:%d) to thread %d",
closure, is_short ? "short" : "long", closure->file_created,
- closure->line_created, (int)(ts - g_thread_state));
+ closure->line_created, static_cast<int>(ts - g_thread_state));
#else
gpr_log(GPR_DEBUG, "EXECUTOR: try to schedule %p (%s) to thread %d",
closure, is_short ? "short" : "long",
@@ -233,7 +233,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error,
// guarantee no starvation)
// ... spin through queues and try again
gpr_mu_unlock(&ts->mu);
- size_t idx = (size_t)(ts - g_thread_state);
+ size_t idx = static_cast<size_t>(ts - g_thread_state);
ts = &g_thread_state[(idx + 1) % cur_thread_count];
if (ts == orig_ts) {
retry_push = true;
@@ -255,7 +255,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error,
break;
}
if (try_new_thread && gpr_spinlock_trylock(&g_adding_thread_lock)) {
- cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads);
+ cur_thread_count = static_cast<size_t>gpr_atm_no_barrier_load(&g_cur_threads);
if (cur_thread_count < g_max_threads) {
gpr_atm_no_barrier_store(&g_cur_threads, cur_thread_count + 1);
diff --git a/src/core/lib/iomgr/gethostname_host_name_max.cc b/src/core/lib/iomgr/gethostname_host_name_max.cc
index 2487160916..ae95788a1e 100644
--- a/src/core/lib/iomgr/gethostname_host_name_max.cc
+++ b/src/core/lib/iomgr/gethostname_host_name_max.cc
@@ -27,7 +27,7 @@
#include <grpc/support/alloc.h>
char* grpc_gethostname() {
- char* hostname = (char*)gpr_malloc(HOST_NAME_MAX);
+ char* hostname = static_cast<char*>(gpr_malloc(HOST_NAME_MAX));
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
gpr_free(hostname);
return nullptr;
diff --git a/src/core/lib/iomgr/is_epollexclusive_available.cc b/src/core/lib/iomgr/is_epollexclusive_available.cc
index 08f9cf2b69..a58a5775d3 100644
--- a/src/core/lib/iomgr/is_epollexclusive_available.cc
+++ b/src/core/lib/iomgr/is_epollexclusive_available.cc
@@ -61,7 +61,7 @@ bool grpc_is_epollexclusive_available(void) {
/* choose events that should cause an error on
EPOLLEXCLUSIVE enabled kernels - specifically the combination of
EPOLLONESHOT and EPOLLEXCLUSIVE */
- ev.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT);
+ ev.events = static_cast<uint32_t>(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT);
ev.data.ptr = nullptr;
if (epoll_ctl(fd, EPOLL_CTL_ADD, evfd, &ev) != 0) {
if (errno != EINVAL) {
diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc
index b6586fbc73..5e637ff8b5 100644
--- a/src/core/lib/iomgr/load_file.cc
+++ b/src/core/lib/iomgr/load_file.cc
@@ -45,10 +45,10 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator,
}
fseek(file, 0, SEEK_END);
/* Converting to size_t on the assumption that it will not fail */
- contents_size = (size_t)ftell(file);
+ contents_size = static_cast<size_t>(ftell(file));
fseek(file, 0, SEEK_SET);
contents =
- (unsigned char*)gpr_malloc(contents_size + (add_null_terminator ? 1 : 0));
+ static_cast<unsigned char*>(gpr_malloc(contents_size + (add_null_terminator ? 1 : 0)));
bytes_read = fread(contents, 1, contents_size, file);
if (bytes_read < contents_size) {
error = GRPC_OS_ERROR(errno, "fread");
diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc
index 3eea709ce4..b49b080c12 100644
--- a/src/core/lib/iomgr/resolve_address_posix.cc
+++ b/src/core/lib/iomgr/resolve_address_posix.cc
@@ -115,13 +115,13 @@ static grpc_error* blocking_resolve_address_impl(
/* Success path: set addrs non-NULL, fill it in */
*addresses =
- (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses));
+ static_cast<grpc_resolved_addresses*>(gpr_malloc(sizeof(grpc_resolved_addresses)));
(*addresses)->naddrs = 0;
for (resp = result; resp != nullptr; resp = resp->ai_next) {
(*addresses)->naddrs++;
}
- (*addresses)->addrs = (grpc_resolved_address*)gpr_malloc(
- sizeof(grpc_resolved_address) * (*addresses)->naddrs);
+ (*addresses)->addrs = static_cast<grpc_resolved_address*>(gpr_malloc(
+ sizeof(grpc_resolved_address) * (*addresses)->naddrs));
i = 0;
for (resp = result; resp != nullptr; resp = resp->ai_next) {
memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen);
@@ -155,7 +155,7 @@ typedef struct {
/* Callback to be passed to grpc_executor to asynch-ify
* grpc_blocking_resolve_address */
static void do_request_thread(void* rp, grpc_error* error) {
- request* r = (request*)rp;
+ request* r = static_cast<request*>(rp);
GRPC_CLOSURE_SCHED(r->on_done, grpc_blocking_resolve_address(
r->name, r->default_port, r->addrs_out));
gpr_free(r->name);
@@ -174,7 +174,7 @@ static void resolve_address_impl(const char* name, const char* default_port,
grpc_pollset_set* interested_parties,
grpc_closure* on_done,
grpc_resolved_addresses** addrs) {
- request* r = (request*)gpr_malloc(sizeof(request));
+ request* r = static_cast<request*>(gpr_malloc(sizeof(request)));
GRPC_CLOSURE_INIT(&r->request_closure, do_request_thread, r,
grpc_executor_scheduler(GRPC_EXECUTOR_SHORT));
r->name = gpr_strdup(name);
diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc
index e64d772a7d..40dd29b6a4 100644
--- a/src/core/lib/iomgr/resource_quota.cc
+++ b/src/core/lib/iomgr/resource_quota.cc
@@ -244,7 +244,7 @@ static bool rq_reclaim_from_per_user_free_pool(
static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive);
static void rq_step(void* rq, grpc_error* error) {
- grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq;
+ grpc_resource_quota* resource_quota = static_cast<grpc_resource_quota*>(rq);
resource_quota->step_scheduled = false;
do {
if (rq_alloc(resource_quota)) goto done;
@@ -303,7 +303,7 @@ static bool rq_alloc(grpc_resource_quota* resource_quota) {
resource_user->free_pool += aborted_allocations;
GRPC_CLOSURE_LIST_SCHED(&resource_user->on_allocated);
gpr_mu_unlock(&resource_user->mu);
- ru_unref_by(resource_user, (gpr_atm)aborted_allocations);
+ ru_unref_by(resource_user, static_cast<gpr_atm>(aborted_allocations));
continue;
}
if (resource_user->free_pool < 0 &&
@@ -401,12 +401,12 @@ typedef struct {
} ru_slice_refcount;
static void ru_slice_ref(void* p) {
- ru_slice_refcount* rc = (ru_slice_refcount*)p;
+ ru_slice_refcount* rc = static_cast<ru_slice_refcount*>(p);
gpr_ref(&rc->refs);
}
static void ru_slice_unref(void* p) {
- ru_slice_refcount* rc = (ru_slice_refcount*)p;
+ ru_slice_refcount* rc = static_cast<ru_slice_refcount*>(p);
if (gpr_unref(&rc->refs)) {
grpc_resource_user_free(rc->resource_user, rc->size);
gpr_free(rc);
@@ -420,7 +420,7 @@ static const grpc_slice_refcount_vtable ru_slice_vtable = {
static grpc_slice ru_slice_create(grpc_resource_user* resource_user,
size_t size) {
ru_slice_refcount* rc =
- (ru_slice_refcount*)gpr_malloc(sizeof(ru_slice_refcount) + size);
+ static_cast<ru_slice_refcount*>(gpr_malloc(sizeof(ru_slice_refcount) + size));
rc->base.vtable = &ru_slice_vtable;
rc->base.sub_refcount = &rc->base;
gpr_ref_init(&rc->refs, 1);
@@ -428,7 +428,7 @@ static grpc_slice ru_slice_create(grpc_resource_user* resource_user,
rc->size = size;
grpc_slice slice;
slice.refcount = &rc->base;
- slice.data.refcounted.bytes = (uint8_t*)(rc + 1);
+ slice.data.refcounted.bytes = reinterpret_cast<uint8_t*>(rc + 1);
slice.data.refcounted.length = size;
return slice;
}
@@ -439,7 +439,7 @@ static grpc_slice ru_slice_create(grpc_resource_user* resource_user,
*/
static void ru_allocate(void* ru, grpc_error* error) {
- grpc_resource_user* resource_user = (grpc_resource_user*)ru;
+ grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru);
if (rulist_empty(resource_user->resource_quota,
GRPC_RULIST_AWAITING_ALLOCATION)) {
rq_step_sched(resource_user->resource_quota);
@@ -448,7 +448,7 @@ static void ru_allocate(void* ru, grpc_error* error) {
}
static void ru_add_to_free_pool(void* ru, grpc_error* error) {
- grpc_resource_user* resource_user = (grpc_resource_user*)ru;
+ grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru);
if (!rulist_empty(resource_user->resource_quota,
GRPC_RULIST_AWAITING_ALLOCATION) &&
rulist_empty(resource_user->resource_quota,
@@ -473,7 +473,7 @@ static bool ru_post_reclaimer(grpc_resource_user* resource_user,
}
static void ru_post_benign_reclaimer(void* ru, grpc_error* error) {
- grpc_resource_user* resource_user = (grpc_resource_user*)ru;
+ grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru);
if (!ru_post_reclaimer(resource_user, false)) return;
if (!rulist_empty(resource_user->resource_quota,
GRPC_RULIST_AWAITING_ALLOCATION) &&
@@ -487,7 +487,7 @@ static void ru_post_benign_reclaimer(void* ru, grpc_error* error) {
}
static void ru_post_destructive_reclaimer(void* ru, grpc_error* error) {
- grpc_resource_user* resource_user = (grpc_resource_user*)ru;
+ grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru);
if (!ru_post_reclaimer(resource_user, true)) return;
if (!rulist_empty(resource_user->resource_quota,
GRPC_RULIST_AWAITING_ALLOCATION) &&
@@ -506,7 +506,7 @@ static void ru_shutdown(void* ru, grpc_error* error) {
if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RU shutdown %p", ru);
}
- grpc_resource_user* resource_user = (grpc_resource_user*)ru;
+ grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru);
gpr_mu_lock(&resource_user->mu);
GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED);
GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED);
@@ -521,10 +521,10 @@ static void ru_shutdown(void* ru, grpc_error* error) {
}
static void ru_destroy(void* ru, grpc_error* error) {
- grpc_resource_user* resource_user = (grpc_resource_user*)ru;
+ grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru);
GPR_ASSERT(gpr_atm_no_barrier_load(&resource_user->refs) == 0);
for (int i = 0; i < GRPC_RULIST_COUNT; i++) {
- rulist_remove(resource_user, (grpc_rulist)i);
+ rulist_remove(resource_user, static_cast<grpc_rulist>(i));
}
GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED);
GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED);
@@ -540,7 +540,7 @@ static void ru_destroy(void* ru, grpc_error* error) {
static void ru_allocated_slices(void* arg, grpc_error* error) {
grpc_resource_user_slice_allocator* slice_allocator =
- (grpc_resource_user_slice_allocator*)arg;
+ static_cast<grpc_resource_user_slice_allocator*>(arg);
if (error == GRPC_ERROR_NONE) {
for (size_t i = 0; i < slice_allocator->count; i++) {
grpc_slice_buffer_add_indexed(
@@ -563,7 +563,7 @@ typedef struct {
} rq_resize_args;
static void rq_resize(void* args, grpc_error* error) {
- rq_resize_args* a = (rq_resize_args*)args;
+ rq_resize_args* a = static_cast<rq_resize_args*>(args);
int64_t delta = a->size - a->resource_quota->size;
a->resource_quota->size += delta;
a->resource_quota->free_pool += delta;
@@ -574,7 +574,7 @@ static void rq_resize(void* args, grpc_error* error) {
}
static void rq_reclamation_done(void* rq, grpc_error* error) {
- grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq;
+ grpc_resource_quota* resource_quota = static_cast<grpc_resource_quota*>(rq);
resource_quota->reclaiming = false;
rq_step_sched(resource_quota);
grpc_resource_quota_unref_internal(resource_quota);
@@ -587,7 +587,7 @@ static void rq_reclamation_done(void* rq, grpc_error* error) {
/* Public API */
grpc_resource_quota* grpc_resource_quota_create(const char* name) {
grpc_resource_quota* resource_quota =
- (grpc_resource_quota*)gpr_malloc(sizeof(*resource_quota));
+ static_cast<grpc_resource_quota*>(gpr_malloc(sizeof(*resource_quota)));
gpr_ref_init(&resource_quota->refs, 1);
resource_quota->combiner = grpc_combiner_create();
resource_quota->free_pool = INT64_MAX;
@@ -640,18 +640,18 @@ void grpc_resource_quota_ref(grpc_resource_quota* resource_quota) {
double grpc_resource_quota_get_memory_pressure(
grpc_resource_quota* resource_quota) {
- return ((double)(gpr_atm_no_barrier_load(
+ return (static_cast<double>(gpr_atm_no_barrier_load(
&resource_quota->memory_usage_estimation))) /
- ((double)MEMORY_USAGE_ESTIMATION_MAX);
+ (static_cast<double>(MEMORY_USAGE_ESTIMATION_MAX));
}
/* Public API */
void grpc_resource_quota_resize(grpc_resource_quota* resource_quota,
size_t size) {
grpc_core::ExecCtx exec_ctx;
- rq_resize_args* a = (rq_resize_args*)gpr_malloc(sizeof(*a));
+ rq_resize_args* a = static_cast<rq_resize_args*>(gpr_malloc(sizeof(*a)));
a->resource_quota = grpc_resource_quota_ref_internal(resource_quota);
- a->size = (int64_t)size;
+ a->size = static_cast<int64_t>(size);
gpr_atm_no_barrier_store(&resource_quota->last_size,
(gpr_atm)GPR_MIN((size_t)GPR_ATM_MAX, size));
GRPC_CLOSURE_INIT(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx);
@@ -659,7 +659,7 @@ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota,
}
size_t grpc_resource_quota_peek_size(grpc_resource_quota* resource_quota) {
- return (size_t)gpr_atm_no_barrier_load(&resource_quota->last_size);
+ return static_cast<size_t>gpr_atm_no_barrier_load(&resource_quota->last_size);
}
/*******************************************************************************
@@ -672,7 +672,7 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args(
if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
if (channel_args->args[i].type == GRPC_ARG_POINTER) {
return grpc_resource_quota_ref_internal(
- (grpc_resource_quota*)channel_args->args[i].value.pointer.p);
+ static_cast<grpc_resource_quota*>(channel_args->args[i].value.pointer.p));
} else {
gpr_log(GPR_DEBUG, GRPC_ARG_RESOURCE_QUOTA " should be a pointer");
}
@@ -682,12 +682,12 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args(
}
static void* rq_copy(void* rq) {
- grpc_resource_quota_ref((grpc_resource_quota*)rq);
+ grpc_resource_quota_ref(static_cast<grpc_resource_quota*>(rq));
return rq;
}
static void rq_destroy(void* rq) {
- grpc_resource_quota_unref_internal((grpc_resource_quota*)rq);
+ grpc_resource_quota_unref_internal(static_cast<grpc_resource_quota*>(rq));
}
static int rq_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
@@ -704,7 +704,7 @@ const grpc_arg_pointer_vtable* grpc_resource_quota_arg_vtable(void) {
grpc_resource_user* grpc_resource_user_create(
grpc_resource_quota* resource_quota, const char* name) {
grpc_resource_user* resource_user =
- (grpc_resource_user*)gpr_malloc(sizeof(*resource_user));
+ static_cast<grpc_resource_user*>(gpr_malloc(sizeof(*resource_user)));
resource_user->resource_quota =
grpc_resource_quota_ref_internal(resource_quota);
GRPC_CLOSURE_INIT(&resource_user->allocate_closure, &ru_allocate,
@@ -785,9 +785,9 @@ void grpc_resource_user_shutdown(grpc_resource_user* resource_user) {
void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size,
grpc_closure* optional_on_done) {
gpr_mu_lock(&resource_user->mu);
- ru_ref_by(resource_user, (gpr_atm)size);
- resource_user->free_pool -= (int64_t)size;
- resource_user->outstanding_allocations += (int64_t)size;
+ ru_ref_by(resource_user, static_cast<gpr_atm>(size));
+ resource_user->free_pool -= static_cast<int64_t>(size);
+ resource_user->outstanding_allocations += static_cast<int64_t>(size);
if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: alloc %" PRIdPTR "; free_pool -> %" PRId64,
resource_user->resource_quota->name, resource_user->name, size,
@@ -801,7 +801,7 @@ void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size,
GRPC_CLOSURE_SCHED(&resource_user->allocate_closure, GRPC_ERROR_NONE);
}
} else {
- resource_user->outstanding_allocations -= (int64_t)size;
+ resource_user->outstanding_allocations -= static_cast<int64_t>(size);
GRPC_CLOSURE_SCHED(optional_on_done, GRPC_ERROR_NONE);
}
gpr_mu_unlock(&resource_user->mu);
@@ -810,7 +810,7 @@ void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size,
void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) {
gpr_mu_lock(&resource_user->mu);
bool was_zero_or_negative = resource_user->free_pool <= 0;
- resource_user->free_pool += (int64_t)size;
+ resource_user->free_pool += static_cast<int64_t>(size);
if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: free %" PRIdPTR "; free_pool -> %" PRId64,
resource_user->resource_quota->name, resource_user->name, size,
@@ -824,7 +824,7 @@ void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) {
GRPC_ERROR_NONE);
}
gpr_mu_unlock(&resource_user->mu);
- ru_unref_by(resource_user, (gpr_atm)size);
+ ru_unref_by(resource_user, static_cast<gpr_atm>(size));
}
void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user,
diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc
index ac97af4dee..06f080376a 100644
--- a/src/core/lib/iomgr/sockaddr_utils.cc
+++ b/src/core/lib/iomgr/sockaddr_utils.cc
@@ -39,13 +39,13 @@ static const uint8_t kV4MappedPrefix[] = {0, 0, 0, 0, 0, 0,
int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr,
grpc_resolved_address* resolved_addr4_out) {
GPR_ASSERT(resolved_addr != resolved_addr4_out);
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
struct sockaddr_in* addr4_out =
resolved_addr4_out == nullptr
? nullptr
- : (struct sockaddr_in*)resolved_addr4_out->addr;
+ : reinterpret_cast<struct sockaddr_in*>(resolved_addr4_out->addr);
if (addr->sa_family == AF_INET6) {
- const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr;
+ const struct sockaddr_in6* addr6 = reinterpret_cast<const struct sockaddr_in6*>(addr);
if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix,
sizeof(kV4MappedPrefix)) == 0) {
if (resolved_addr4_out != nullptr) {
@@ -66,11 +66,11 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr,
int grpc_sockaddr_to_v4mapped(const grpc_resolved_address* resolved_addr,
grpc_resolved_address* resolved_addr6_out) {
GPR_ASSERT(resolved_addr != resolved_addr6_out);
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
struct sockaddr_in6* addr6_out =
- (struct sockaddr_in6*)resolved_addr6_out->addr;
+ reinterpret_cast<struct sockaddr_in6*>(resolved_addr6_out->addr);
if (addr->sa_family == AF_INET) {
- const struct sockaddr_in* addr4 = (const struct sockaddr_in*)addr;
+ const struct sockaddr_in* addr4 = reinterpret_cast<const struct sockaddr_in*>(addr);
memset(resolved_addr6_out, 0, sizeof(*resolved_addr6_out));
addr6_out->sin6_family = AF_INET6;
memcpy(&addr6_out->sin6_addr.s6_addr[0], kV4MappedPrefix, 12);
@@ -89,10 +89,10 @@ int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr,
if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr4_normalized)) {
resolved_addr = &addr4_normalized;
}
- addr = (const struct sockaddr*)resolved_addr->addr;
+ addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
if (addr->sa_family == AF_INET) {
/* Check for 0.0.0.0 */
- const struct sockaddr_in* addr4 = (const struct sockaddr_in*)addr;
+ const struct sockaddr_in* addr4 = reinterpret_cast<const struct sockaddr_in*>(addr);
if (addr4->sin_addr.s_addr != 0) {
return 0;
}
@@ -100,7 +100,7 @@ int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr,
return 1;
} else if (addr->sa_family == AF_INET6) {
/* Check for :: */
- const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr;
+ const struct sockaddr_in6* addr6 = reinterpret_cast<const struct sockaddr_in6*>(addr);
int i;
for (i = 0; i < 16; i++) {
if (addr6->sin6_addr.s6_addr[i] != 0) {
@@ -122,21 +122,21 @@ void grpc_sockaddr_make_wildcards(int port, grpc_resolved_address* wild4_out,
void grpc_sockaddr_make_wildcard4(int port,
grpc_resolved_address* resolved_wild_out) {
- struct sockaddr_in* wild_out = (struct sockaddr_in*)resolved_wild_out->addr;
+ struct sockaddr_in* wild_out = reinterpret_cast<struct sockaddr_in*>(resolved_wild_out->addr);
GPR_ASSERT(port >= 0 && port < 65536);
memset(resolved_wild_out, 0, sizeof(*resolved_wild_out));
wild_out->sin_family = AF_INET;
- wild_out->sin_port = htons((uint16_t)port);
+ wild_out->sin_port = htons(static_cast<uint16_t>(port));
resolved_wild_out->len = sizeof(struct sockaddr_in);
}
void grpc_sockaddr_make_wildcard6(int port,
grpc_resolved_address* resolved_wild_out) {
- struct sockaddr_in6* wild_out = (struct sockaddr_in6*)resolved_wild_out->addr;
+ struct sockaddr_in6* wild_out = reinterpret_cast<struct sockaddr_in6*>(resolved_wild_out->addr);
GPR_ASSERT(port >= 0 && port < 65536);
memset(resolved_wild_out, 0, sizeof(*resolved_wild_out));
wild_out->sin6_family = AF_INET6;
- wild_out->sin6_port = htons((uint16_t)port);
+ wild_out->sin6_port = htons(static_cast<uint16_t>(port));
resolved_wild_out->len = sizeof(struct sockaddr_in6);
}
@@ -156,13 +156,13 @@ int grpc_sockaddr_to_string(char** out,
if (normalize && grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) {
resolved_addr = &addr_normalized;
}
- addr = (const struct sockaddr*)resolved_addr->addr;
+ addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
if (addr->sa_family == AF_INET) {
- const struct sockaddr_in* addr4 = (const struct sockaddr_in*)addr;
+ const struct sockaddr_in* addr4 = reinterpret_cast<const struct sockaddr_in*>(addr);
ip = &addr4->sin_addr;
port = ntohs(addr4->sin_port);
} else if (addr->sa_family == AF_INET6) {
- const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr;
+ const struct sockaddr_in6* addr6 = reinterpret_cast<const struct sockaddr_in6*>(addr);
ip = &addr6->sin6_addr;
port = ntohs(addr6->sin6_port);
sin6_scope_id = addr6->sin6_scope_id;
@@ -208,7 +208,7 @@ char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) {
const char* grpc_sockaddr_get_uri_scheme(
const grpc_resolved_address* resolved_addr) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
switch (addr->sa_family) {
case AF_INET:
return "ipv4";
@@ -221,12 +221,12 @@ const char* grpc_sockaddr_get_uri_scheme(
}
int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
return addr->sa_family;
}
int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
switch (addr->sa_family) {
case AF_INET:
return ntohs(((struct sockaddr_in*)addr)->sin_port);
@@ -244,15 +244,15 @@ int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) {
int grpc_sockaddr_set_port(const grpc_resolved_address* resolved_addr,
int port) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
switch (addr->sa_family) {
case AF_INET:
GPR_ASSERT(port >= 0 && port < 65536);
- ((struct sockaddr_in*)addr)->sin_port = htons((uint16_t)port);
+ ((struct sockaddr_in*)addr)->sin_port = htons(static_cast<uint16_t>(port));
return 1;
case AF_INET6:
GPR_ASSERT(port >= 0 && port < 65536);
- ((struct sockaddr_in6*)addr)->sin6_port = htons((uint16_t)port);
+ ((struct sockaddr_in6*)addr)->sin6_port = htons(static_cast<uint16_t>(port));
return 1;
default:
gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port",
diff --git a/src/core/lib/iomgr/socket_factory_posix.cc b/src/core/lib/iomgr/socket_factory_posix.cc
index 1c1b2fb270..3e696c2e10 100644
--- a/src/core/lib/iomgr/socket_factory_posix.cc
+++ b/src/core/lib/iomgr/socket_factory_posix.cc
@@ -69,16 +69,16 @@ void grpc_socket_factory_unref(grpc_socket_factory* factory) {
}
static void* socket_factory_arg_copy(void* p) {
- return grpc_socket_factory_ref((grpc_socket_factory*)p);
+ return grpc_socket_factory_ref(static_cast<grpc_socket_factory*>(p));
}
static void socket_factory_arg_destroy(void* p) {
- grpc_socket_factory_unref((grpc_socket_factory*)p);
+ grpc_socket_factory_unref(static_cast<grpc_socket_factory*>(p));
}
static int socket_factory_cmp(void* a, void* b) {
- return grpc_socket_factory_compare((grpc_socket_factory*)a,
- (grpc_socket_factory*)b);
+ return grpc_socket_factory_compare(static_cast<grpc_socket_factory*>(a),
+ static_cast<grpc_socket_factory*>(b));
}
static const grpc_arg_pointer_vtable socket_factory_arg_vtable = {
diff --git a/src/core/lib/iomgr/socket_mutator.cc b/src/core/lib/iomgr/socket_mutator.cc
index 8c8f0e56e1..eb219d7cb3 100644
--- a/src/core/lib/iomgr/socket_mutator.cc
+++ b/src/core/lib/iomgr/socket_mutator.cc
@@ -60,16 +60,16 @@ void grpc_socket_mutator_unref(grpc_socket_mutator* mutator) {
}
static void* socket_mutator_arg_copy(void* p) {
- return grpc_socket_mutator_ref((grpc_socket_mutator*)p);
+ return grpc_socket_mutator_ref(static_cast<grpc_socket_mutator*>(p));
}
static void socket_mutator_arg_destroy(void* p) {
- grpc_socket_mutator_unref((grpc_socket_mutator*)p);
+ grpc_socket_mutator_unref(static_cast<grpc_socket_mutator*>(p));
}
static int socket_mutator_cmp(void* a, void* b) {
- return grpc_socket_mutator_compare((grpc_socket_mutator*)a,
- (grpc_socket_mutator*)b);
+ return grpc_socket_mutator_compare(static_cast<grpc_socket_mutator*>(a),
+ static_cast<grpc_socket_mutator*>(b));
}
static const grpc_arg_pointer_vtable socket_mutator_arg_vtable = {
diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc
index d02d77eb02..2668aa6d10 100644
--- a/src/core/lib/iomgr/socket_utils_common_posix.cc
+++ b/src/core/lib/iomgr/socket_utils_common_posix.cc
@@ -218,7 +218,7 @@ static void probe_ipv6_once(void) {
memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
addr.sin6_addr.s6_addr[15] = 1; /* [::1]:0 */
- if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) {
+ if (bind(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) == 0) {
g_ipv6_loopback_available = 1;
} else {
gpr_log(GPR_INFO,
@@ -278,7 +278,7 @@ static int create_socket(grpc_socket_factory* factory, int domain, int type,
grpc_error* grpc_create_dualstack_socket_using_factory(
grpc_socket_factory* factory, const grpc_resolved_address* resolved_addr,
int type, int protocol, grpc_dualstack_mode* dsmode, int* newfd) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
int family = addr->sa_family;
if (family == AF_INET6) {
if (grpc_ipv6_loopback_available()) {
@@ -310,7 +310,7 @@ grpc_error* grpc_create_dualstack_socket_using_factory(
const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) {
GPR_ASSERT(size <= (socklen_t)-1);
- return inet_ntop(af, src, dst, (socklen_t)size);
+ return inet_ntop(af, src, dst, static_cast<socklen_t>(size));
}
#endif
diff --git a/src/core/lib/iomgr/socket_utils_linux.cc b/src/core/lib/iomgr/socket_utils_linux.cc
index 12199c5c89..edb5274e0e 100644
--- a/src/core/lib/iomgr/socket_utils_linux.cc
+++ b/src/core/lib/iomgr/socket_utils_linux.cc
@@ -35,8 +35,8 @@ int grpc_accept4(int sockfd, grpc_resolved_address* resolved_addr, int nonblock,
GPR_ASSERT(resolved_addr->len <= (socklen_t)-1);
flags |= nonblock ? SOCK_NONBLOCK : 0;
flags |= cloexec ? SOCK_CLOEXEC : 0;
- return accept4(sockfd, (struct sockaddr*)resolved_addr->addr,
- (socklen_t*)&resolved_addr->len, flags);
+ return accept4(sockfd, reinterpret_cast<struct sockaddr*>(resolved_addr->addr),
+ reinterpret_cast<socklen_t*>(&resolved_addr->len), flags);
}
#endif
diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc
index 3dff624065..8d08127915 100644
--- a/src/core/lib/iomgr/tcp_client_posix.cc
+++ b/src/core/lib/iomgr/tcp_client_posix.cc
@@ -80,7 +80,7 @@ static grpc_error* prepare_socket(const grpc_resolved_address* addr, int fd,
if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_SOCKET_MUTATOR)) {
GPR_ASSERT(channel_args->args[i].type == GRPC_ARG_POINTER);
grpc_socket_mutator* mutator =
- (grpc_socket_mutator*)channel_args->args[i].value.pointer.p;
+ static_cast<grpc_socket_mutator*>(channel_args->args[i].value.pointer.p);
err = grpc_set_socket_with_mutator(fd, mutator);
if (err != GRPC_ERROR_NONE) goto error;
}
@@ -98,7 +98,7 @@ done:
static void tc_on_alarm(void* acp, grpc_error* error) {
int done;
- async_connect* ac = (async_connect*)acp;
+ async_connect* ac = static_cast<async_connect*>(acp);
if (grpc_tcp_trace.enabled()) {
const char* str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str,
@@ -125,7 +125,7 @@ grpc_endpoint* grpc_tcp_client_create_from_fd(
}
static void on_writable(void* acp, grpc_error* error) {
- async_connect* ac = (async_connect*)acp;
+ async_connect* ac = static_cast<async_connect*>(acp);
int so_error = 0;
socklen_t so_error_size;
int err;
@@ -291,7 +291,7 @@ void grpc_tcp_client_create_from_prepared_fd(
async_connect* ac;
do {
GPR_ASSERT(addr->len < ~(socklen_t)0);
- err = connect(fd, (const struct sockaddr*)addr->addr, (socklen_t)addr->len);
+ err = connect(fd, reinterpret_cast<const struct sockaddr*>(addr->addr), static_cast<socklen_t>(addr->len));
} while (err < 0 && errno == EINTR);
if (err >= 0) {
char* addr_str = grpc_sockaddr_to_uri(addr);
@@ -309,7 +309,7 @@ void grpc_tcp_client_create_from_prepared_fd(
grpc_pollset_set_add_fd(interested_parties, fdobj);
- ac = (async_connect*)gpr_malloc(sizeof(async_connect));
+ ac = static_cast<async_connect*>(gpr_malloc(sizeof(async_connect)));
ac->closure = closure;
ac->ep = ep;
ac->fd = fdobj;
diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc
index e78e19761a..71819adaba 100644
--- a/src/core/lib/iomgr/tcp_posix.cc
+++ b/src/core/lib/iomgr/tcp_posix.cc
@@ -116,7 +116,7 @@ static void tcp_drop_uncovered_then_handle_write(void* arg /* grpc_tcp */,
grpc_error* error);
static void done_poller(void* bp, grpc_error* error_ignored) {
- backup_poller* p = (backup_poller*)bp;
+ backup_poller* p = static_cast<backup_poller*>(bp);
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p);
}
@@ -125,7 +125,7 @@ static void done_poller(void* bp, grpc_error* error_ignored) {
}
static void run_poller(void* bp, grpc_error* error_ignored) {
- backup_poller* p = (backup_poller*)bp;
+ backup_poller* p = static_cast<backup_poller*>(bp);
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p);
}
@@ -165,8 +165,8 @@ static void drop_uncovered(grpc_tcp* tcp) {
gpr_atm old_count =
gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1);
if (grpc_tcp_trace.enabled()) {
- gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, (int)old_count,
- (int)old_count - 1);
+ gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, static_cast<int>(old_count),
+ static_cast<int>(old_count) - 1);
}
GPR_ASSERT(old_count != 1);
}
@@ -176,12 +176,12 @@ static void cover_self(grpc_tcp* tcp) {
gpr_atm old_count =
gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2);
if (grpc_tcp_trace.enabled()) {
- gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", (int)old_count,
- 2 + (int)old_count);
+ gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", static_cast<int>(old_count),
+ 2 + static_cast<int>(old_count));
}
if (old_count == 0) {
GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED();
- p = (backup_poller*)gpr_zalloc(sizeof(*p) + grpc_pollset_size());
+ p = static_cast<backup_poller*>(gpr_zalloc(sizeof(*p) + grpc_pollset_size()));
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p);
}
@@ -230,12 +230,12 @@ static void tcp_drop_uncovered_then_handle_write(void* arg, grpc_error* error) {
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error));
}
- drop_uncovered((grpc_tcp*)arg);
+ drop_uncovered(static_cast<grpc_tcp*>(arg));
tcp_handle_write(arg, error);
}
static void add_to_estimate(grpc_tcp* tcp, size_t bytes) {
- tcp->bytes_read_this_round += (double)bytes;
+ tcp->bytes_read_this_round += static_cast<double>(bytes);
}
static void finish_estimate(grpc_tcp* tcp) {
@@ -257,10 +257,10 @@ static size_t get_target_read_size(grpc_tcp* tcp) {
double pressure = grpc_resource_quota_get_memory_pressure(rq);
double target =
tcp->target_length * (pressure > 0.8 ? (1.0 - pressure) / 0.2 : 1.0);
- size_t sz = (((size_t)GPR_CLAMP(target, tcp->min_read_chunk_size,
+ size_t sz = ((static_cast<size_t>GPR_CLAMP(target, tcp->min_read_chunk_size,
tcp->max_read_chunk_size)) +
255) &
- ~(size_t)255;
+ ~static_cast<size_t>(255);
/* don't use more than 1/16th of the overall resource quota for a single read
* alloc */
size_t rqmax = grpc_resource_quota_peek_size(rq);
@@ -285,7 +285,7 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error);
static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error);
static void tcp_shutdown(grpc_endpoint* ep, grpc_error* why) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
grpc_fd_shutdown(tcp->em_fd, why);
grpc_resource_user_shutdown(tcp->resource_user);
}
@@ -339,7 +339,7 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); }
static void tcp_destroy(grpc_endpoint* ep) {
grpc_network_status_unregister_endpoint(ep);
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer);
TCP_UNREF(tcp, "destroy");
}
@@ -385,7 +385,7 @@ static void tcp_do_read(grpc_tcp* tcp) {
msg.msg_name = nullptr;
msg.msg_namelen = 0;
msg.msg_iov = iov;
- msg.msg_iovlen = (msg_iovlen_type)tcp->incoming_buffer->count;
+ msg.msg_iovlen = static_cast<msg_iovlen_type>(tcp->incoming_buffer->count);
msg.msg_control = nullptr;
msg.msg_controllen = 0;
msg.msg_flags = 0;
@@ -421,12 +421,12 @@ static void tcp_do_read(grpc_tcp* tcp) {
TCP_UNREF(tcp, "read");
} else {
GRPC_STATS_INC_TCP_READ_SIZE(read_bytes);
- add_to_estimate(tcp, (size_t)read_bytes);
+ add_to_estimate(tcp, static_cast<size_t>(read_bytes));
GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length);
- if ((size_t)read_bytes < tcp->incoming_buffer->length) {
+ if (static_cast<size_t>(read_bytes) < tcp->incoming_buffer->length) {
grpc_slice_buffer_trim_end(
tcp->incoming_buffer,
- tcp->incoming_buffer->length - (size_t)read_bytes,
+ tcp->incoming_buffer->length - static_cast<size_t>(read_bytes),
&tcp->last_read_buffer);
}
GPR_ASSERT((size_t)read_bytes == tcp->incoming_buffer->length);
@@ -436,7 +436,7 @@ static void tcp_do_read(grpc_tcp* tcp) {
}
static void tcp_read_allocation_done(void* tcpp, grpc_error* error) {
- grpc_tcp* tcp = (grpc_tcp*)tcpp;
+ grpc_tcp* tcp = static_cast<grpc_tcp*>(tcpp);
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp,
grpc_error_string(error));
@@ -469,7 +469,7 @@ static void tcp_continue_read(grpc_tcp* tcp) {
}
static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) {
- grpc_tcp* tcp = (grpc_tcp*)arg;
+ grpc_tcp* tcp = static_cast<grpc_tcp*>(arg);
GPR_ASSERT(!tcp->finished_edge);
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p got_read: %s", tcp, grpc_error_string(error));
@@ -487,7 +487,7 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) {
static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer,
grpc_closure* cb) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
GPR_ASSERT(tcp->read_cb == nullptr);
tcp->read_cb = cb;
tcp->incoming_buffer = incoming_buffer;
@@ -578,7 +578,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
}
GPR_ASSERT(tcp->outgoing_byte_idx == 0);
- trailing = sending_length - (size_t)sent_length;
+ trailing = sending_length - static_cast<size_t>(sent_length);
while (trailing > 0) {
size_t slice_length;
@@ -602,7 +602,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
}
static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) {
- grpc_tcp* tcp = (grpc_tcp*)arg;
+ grpc_tcp* tcp = static_cast<grpc_tcp*>(arg);
grpc_closure* cb;
if (error != GRPC_ERROR_NONE) {
@@ -634,7 +634,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) {
static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
grpc_closure* cb) {
GPR_TIMER_SCOPE("tcp_write", 0);
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
grpc_error* error = GRPC_ERROR_NONE;
if (grpc_tcp_trace.enabled()) {
@@ -678,34 +678,34 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
}
static void tcp_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
grpc_pollset_add_fd(pollset, tcp->em_fd);
}
static void tcp_add_to_pollset_set(grpc_endpoint* ep,
grpc_pollset_set* pollset_set) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
grpc_pollset_set_add_fd(pollset_set, tcp->em_fd);
}
static void tcp_delete_from_pollset_set(grpc_endpoint* ep,
grpc_pollset_set* pollset_set) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
grpc_pollset_set_del_fd(pollset_set, tcp->em_fd);
}
static char* tcp_get_peer(grpc_endpoint* ep) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
return gpr_strdup(tcp->peer_string);
}
static int tcp_get_fd(grpc_endpoint* ep) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
return tcp->fd;
}
static grpc_resource_user* tcp_get_resource_user(grpc_endpoint* ep) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
return tcp->resource_user;
}
@@ -733,19 +733,19 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
for (size_t i = 0; i < channel_args->num_args; i++) {
if (0 ==
strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) {
- grpc_integer_options options = {(int)tcp_read_chunk_size, 1,
+ grpc_integer_options options = {tcp_read_chunk_size, 1,
MAX_CHUNK_SIZE};
tcp_read_chunk_size =
grpc_channel_arg_get_integer(&channel_args->args[i], options);
} else if (0 == strcmp(channel_args->args[i].key,
GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE)) {
- grpc_integer_options options = {(int)tcp_read_chunk_size, 1,
+ grpc_integer_options options = {tcp_read_chunk_size, 1,
MAX_CHUNK_SIZE};
tcp_min_read_chunk_size =
grpc_channel_arg_get_integer(&channel_args->args[i], options);
} else if (0 == strcmp(channel_args->args[i].key,
GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE)) {
- grpc_integer_options options = {(int)tcp_read_chunk_size, 1,
+ grpc_integer_options options = {tcp_read_chunk_size, 1,
MAX_CHUNK_SIZE};
tcp_max_read_chunk_size =
grpc_channel_arg_get_integer(&channel_args->args[i], options);
@@ -753,7 +753,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
grpc_resource_quota_unref_internal(resource_quota);
resource_quota = grpc_resource_quota_ref_internal(
- (grpc_resource_quota*)channel_args->args[i].value.pointer.p);
+ static_cast<grpc_resource_quota*>(channel_args->args[i].value.pointer.p));
}
}
}
@@ -764,7 +764,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
tcp_read_chunk_size = GPR_CLAMP(tcp_read_chunk_size, tcp_min_read_chunk_size,
tcp_max_read_chunk_size);
- grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp));
+ grpc_tcp* tcp = static_cast<grpc_tcp*>(gpr_malloc(sizeof(grpc_tcp)));
tcp->base.vtable = &vtable;
tcp->peer_string = gpr_strdup(peer_string);
tcp->fd = grpc_fd_wrapped_fd(em_fd);
@@ -773,7 +773,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
tcp->release_fd_cb = nullptr;
tcp->release_fd = nullptr;
tcp->incoming_buffer = nullptr;
- tcp->target_length = (double)tcp_read_chunk_size;
+ tcp->target_length = static_cast<double>(tcp_read_chunk_size);
tcp->min_read_chunk_size = tcp_min_read_chunk_size;
tcp->max_read_chunk_size = tcp_max_read_chunk_size;
tcp->bytes_read_this_round = 0;
@@ -794,7 +794,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
}
int grpc_tcp_fd(grpc_endpoint* ep) {
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
GPR_ASSERT(ep->vtable == &vtable);
return grpc_fd_wrapped_fd(tcp->em_fd);
}
@@ -802,7 +802,7 @@ int grpc_tcp_fd(grpc_endpoint* ep) {
void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd,
grpc_closure* done) {
grpc_network_status_unregister_endpoint(ep);
- grpc_tcp* tcp = (grpc_tcp*)ep;
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
GPR_ASSERT(ep->vtable == &vtable);
tcp->release_fd = fd;
tcp->release_fd_cb = done;
diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc
index 89d9160e02..f8f94e3fbb 100644
--- a/src/core/lib/iomgr/tcp_server_posix.cc
+++ b/src/core/lib/iomgr/tcp_server_posix.cc
@@ -72,7 +72,7 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete,
grpc_tcp_server** server) {
gpr_once_init(&check_init, init);
- grpc_tcp_server* s = (grpc_tcp_server*)gpr_zalloc(sizeof(grpc_tcp_server));
+ grpc_tcp_server* s = static_cast<grpc_tcp_server*>(gpr_zalloc(sizeof(grpc_tcp_server)));
s->so_reuseport = has_so_reuseport;
s->expand_wildcard_addrs = false;
for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) {
@@ -135,7 +135,7 @@ static void finish_shutdown(grpc_tcp_server* s) {
}
static void destroyed_port(void* server, grpc_error* error) {
- grpc_tcp_server* s = (grpc_tcp_server*)server;
+ grpc_tcp_server* s = static_cast<grpc_tcp_server*>(server);
gpr_mu_lock(&s->mu);
s->destroyed_ports++;
if (s->destroyed_ports == s->nports) {
@@ -194,15 +194,15 @@ static void tcp_server_destroy(grpc_tcp_server* s) {
/* event manager callback when reads are ready */
static void on_read(void* arg, grpc_error* err) {
- grpc_tcp_listener* sp = (grpc_tcp_listener*)arg;
+ grpc_tcp_listener* sp = static_cast<grpc_tcp_listener*>(arg);
grpc_pollset* read_notifier_pollset;
if (err != GRPC_ERROR_NONE) {
goto error;
}
read_notifier_pollset =
- sp->server->pollsets[(size_t)gpr_atm_no_barrier_fetch_add(
- &sp->server->next_pollset_to_assign, 1) %
+ sp->server->pollsets[static_cast<size_t>(gpr_atm_no_barrier_fetch_add(
+ &sp->server->next_pollset_to_assign, 1)) %
sp->server->pollset_count];
/* loop until accept4 returns EAGAIN, and then re-arm notification */
@@ -249,7 +249,7 @@ static void on_read(void* arg, grpc_error* err) {
// Create acceptor.
grpc_tcp_server_acceptor* acceptor =
- (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor));
+ static_cast<grpc_tcp_server_acceptor*>(gpr_malloc(sizeof(*acceptor)));
acceptor->from_server = sp->server;
acceptor->port_index = sp->port_index;
acceptor->fd_index = sp->fd_index;
@@ -363,7 +363,7 @@ static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) {
listener->server->nports++;
grpc_sockaddr_to_string(&addr_str, &listener->addr, 1);
gpr_asprintf(&name, "tcp-server-listener:%s/clone-%d", addr_str, i);
- sp = (grpc_tcp_listener*)gpr_malloc(sizeof(grpc_tcp_listener));
+ sp = static_cast<grpc_tcp_listener*>(gpr_malloc(sizeof(grpc_tcp_listener)));
sp->next = listener->next;
listener->next = sp;
/* sp (the new listener) is a sibling of 'listener' (the original
@@ -410,8 +410,8 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s,
if (requested_port == 0) {
for (sp = s->head; sp; sp = sp->next) {
sockname_temp.len = sizeof(struct sockaddr_storage);
- if (0 == getsockname(sp->fd, (struct sockaddr*)&sockname_temp.addr,
- (socklen_t*)&sockname_temp.len)) {
+ if (0 == getsockname(sp->fd, reinterpret_cast<struct sockaddr*>(&sockname_temp.addr),
+ reinterpret_cast<socklen_t*>(&sockname_temp.len))) {
int used_port = grpc_sockaddr_get_port(&sockname_temp);
if (used_port > 0) {
memcpy(&sockname_temp, addr, sizeof(grpc_resolved_address));
diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc
index 5139760634..db8ccf02eb 100644
--- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc
+++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc
@@ -56,7 +56,7 @@ static void init_max_accept_queue_size(void) {
char* end;
long i = strtol(buf, &end, 10);
if (i > 0 && i <= INT_MAX && end && *end == '\n') {
- n = (int)i;
+ n = static_cast<int>(i);
}
}
fclose(fp);
@@ -93,7 +93,7 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd,
gpr_mu_lock(&s->mu);
s->nports++;
GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server");
- sp = (grpc_tcp_listener*)gpr_malloc(sizeof(grpc_tcp_listener));
+ sp = static_cast<grpc_tcp_listener*>(gpr_malloc(sizeof(grpc_tcp_listener)));
sp->next = nullptr;
if (s->head == nullptr) {
s->head = sp;
@@ -169,7 +169,7 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd,
if (err != GRPC_ERROR_NONE) goto error;
GPR_ASSERT(addr->len < ~(socklen_t)0);
- if (bind(fd, (struct sockaddr*)addr->addr, (socklen_t)addr->len) < 0) {
+ if (bind(fd, reinterpret_cast<struct sockaddr*>(addr->addr), static_cast<socklen_t>(addr->len)) < 0) {
err = GRPC_OS_ERROR(errno, "bind");
goto error;
}
@@ -181,8 +181,8 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd,
sockname_temp.len = sizeof(struct sockaddr_storage);
- if (getsockname(fd, (struct sockaddr*)sockname_temp.addr,
- (socklen_t*)&sockname_temp.len) < 0) {
+ if (getsockname(fd, reinterpret_cast<struct sockaddr*>(sockname_temp.addr),
+ reinterpret_cast<socklen_t*>(&sockname_temp.len)) < 0) {
err = GRPC_OS_ERROR(errno, "getsockname");
goto error;
}
diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
index 227bf94aa7..5470dbcff7 100644
--- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
+++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
@@ -66,12 +66,12 @@ static grpc_error* get_unused_port(int* port) {
if (dsmode == GRPC_DSMODE_IPV4) {
grpc_sockaddr_make_wildcard4(0, &wild);
}
- if (bind(fd, (const struct sockaddr*)wild.addr, (socklen_t)wild.len) != 0) {
+ if (bind(fd, reinterpret_cast<const struct sockaddr*>(wild.addr), static_cast<socklen_t>(wild.len)) != 0) {
err = GRPC_OS_ERROR(errno, "bind");
close(fd);
return err;
}
- if (getsockname(fd, (struct sockaddr*)wild.addr, (socklen_t*)&wild.len) !=
+ if (getsockname(fd, reinterpret_cast<struct sockaddr*>(wild.addr), reinterpret_cast<socklen_t*>(&wild.len)) !=
0) {
err = GRPC_OS_ERROR(errno, "getsockname");
close(fd);
diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc
index ef86d237d3..b47c12b689 100644
--- a/src/core/lib/iomgr/timer_generic.cc
+++ b/src/core/lib/iomgr/timer_generic.cc
@@ -240,9 +240,9 @@ void grpc_timer_list_init() {
uint32_t i;
g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores());
- g_shards = (timer_shard*)gpr_zalloc(g_num_shards * sizeof(*g_shards));
+ g_shards = static_cast<timer_shard*>(gpr_zalloc(g_num_shards * sizeof(*g_shards)));
g_shard_queue =
- (timer_shard**)gpr_zalloc(g_num_shards * sizeof(*g_shard_queue));
+ static_cast<timer_shard**>(gpr_zalloc(g_num_shards * sizeof(*g_shard_queue)));
g_shared_mutables.initialized = true;
g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER;
@@ -360,7 +360,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline,
}
grpc_time_averaged_stats_add_sample(&shard->stats,
- (double)(deadline - now) / 1000.0);
+ static_cast<double>(deadline - now) / 1000.0);
ADD_TO_HASH_TABLE(timer);
@@ -374,7 +374,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline,
gpr_log(GPR_DEBUG,
" .. add to shard %d with queue_deadline_cap=%" PRIdPTR
" => is_first_timer=%s",
- (int)(shard - g_shards), shard->queue_deadline_cap,
+ static_cast<int>(shard - g_shards), shard->queue_deadline_cap,
is_first_timer ? "true" : "false");
}
gpr_mu_unlock(&shard->mu);
@@ -461,11 +461,11 @@ static int refill_heap(timer_shard* shard, gpr_atm now) {
/* Compute the new cap and put all timers under it into the queue: */
shard->queue_deadline_cap =
saturating_add(GPR_MAX(now, shard->queue_deadline_cap),
- (gpr_atm)(deadline_delta * 1000.0));
+ static_cast<gpr_atm>(deadline_delta * 1000.0));
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d]->queue_deadline_cap --> %" PRIdPTR,
- (int)(shard - g_shards), shard->queue_deadline_cap);
+ static_cast<int>(shard - g_shards), shard->queue_deadline_cap);
}
for (timer = shard->list.next; timer != &shard->list; timer = next) {
next = timer->next;
@@ -490,7 +490,7 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) {
for (;;) {
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d]: heap_empty=%s",
- (int)(shard - g_shards),
+ static_cast<int>(shard - g_shards),
grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false");
}
if (grpc_timer_heap_is_empty(&shard->heap)) {
@@ -530,7 +530,7 @@ static size_t pop_timers(timer_shard* shard, gpr_atm now,
gpr_mu_unlock(&shard->mu);
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d] popped %" PRIdPTR,
- (int)(shard - g_shards), n);
+ static_cast<int>(shard - g_shards), n);
}
return n;
}
@@ -553,7 +553,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now,
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d]->min_deadline = %" PRIdPTR,
- (int)(g_shard_queue[0] - g_shards),
+ static_cast<int>(g_shard_queue[0] - g_shards),
g_shard_queue[0]->min_deadline);
}
@@ -573,7 +573,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now,
" .. result --> %d"
", shard[%d]->min_deadline %" PRIdPTR " --> %" PRIdPTR
", now=%" PRIdPTR,
- result, (int)(g_shard_queue[0] - g_shards),
+ result, static_cast<int>(g_shard_queue[0] - g_shards),
g_shard_queue[0]->min_deadline, new_min_deadline, now);
}
diff --git a/src/core/lib/iomgr/timer_heap.cc b/src/core/lib/iomgr/timer_heap.cc
index 632928fafa..9aedfd3755 100644
--- a/src/core/lib/iomgr/timer_heap.cc
+++ b/src/core/lib/iomgr/timer_heap.cc
@@ -35,7 +35,7 @@
its argument. */
static void adjust_upwards(grpc_timer** first, uint32_t i, grpc_timer* t) {
while (i > 0) {
- uint32_t parent = (uint32_t)(((int)i - 1) / 2);
+ uint32_t parent = static_cast<uint32_t>((static_cast<int>(i) - 1) / 2);
if (first[parent]->deadline <= t->deadline) break;
first[i] = first[parent];
first[i]->heap_index = i;
@@ -74,14 +74,14 @@ static void maybe_shrink(grpc_timer_heap* heap) {
if (heap->timer_count >= 8 &&
heap->timer_count <= heap->timer_capacity / SHRINK_FULLNESS_FACTOR / 2) {
heap->timer_capacity = heap->timer_count * SHRINK_FULLNESS_FACTOR;
- heap->timers = (grpc_timer**)gpr_realloc(
- heap->timers, heap->timer_capacity * sizeof(grpc_timer*));
+ heap->timers = static_cast<grpc_timer**>(gpr_realloc(
+ heap->timers, heap->timer_capacity * sizeof(grpc_timer*)));
}
}
static void note_changed_priority(grpc_timer_heap* heap, grpc_timer* timer) {
uint32_t i = timer->heap_index;
- uint32_t parent = (uint32_t)(((int)i - 1) / 2);
+ uint32_t parent = static_cast<uint32_t>((static_cast<int>(i) - 1) / 2);
if (heap->timers[parent]->deadline > timer->deadline) {
adjust_upwards(heap->timers, i, timer);
} else {
@@ -99,8 +99,8 @@ int grpc_timer_heap_add(grpc_timer_heap* heap, grpc_timer* timer) {
if (heap->timer_count == heap->timer_capacity) {
heap->timer_capacity =
GPR_MAX(heap->timer_capacity + 1, heap->timer_capacity * 3 / 2);
- heap->timers = (grpc_timer**)gpr_realloc(
- heap->timers, heap->timer_capacity * sizeof(grpc_timer*));
+ heap->timers = static_cast<grpc_timer**>(gpr_realloc(
+ heap->timers, heap->timer_capacity * sizeof(grpc_timer*)));
}
timer->heap_index = heap->timer_count;
adjust_upwards(heap->timers, heap->timer_count, timer);
diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc
index 7fb068f10f..4cefb7fc9f 100644
--- a/src/core/lib/iomgr/timer_manager.cc
+++ b/src/core/lib/iomgr/timer_manager.cc
@@ -86,7 +86,7 @@ static void start_timer_thread_and_unlock(void) {
}
gpr_thd_options opt = gpr_thd_options_default();
gpr_thd_options_set_joinable(&opt);
- completed_thread* ct = (completed_thread*)gpr_malloc(sizeof(*ct));
+ completed_thread* ct = static_cast<completed_thread*>(gpr_malloc(sizeof(*ct)));
// The call to gpr_thd_new() has to be under the same lock used by
// gc_completed_threads(), particularly due to ct->t, which is written here
// (internally by gpr_thd_new) and read there. Otherwise it's possible for ct
@@ -276,7 +276,7 @@ static void timer_thread(void* completed_thread_ptr) {
grpc_core::ExecCtx exec_ctx(0);
timer_main_loop();
- timer_thread_cleanup((completed_thread*)completed_thread_ptr);
+ timer_thread_cleanup(static_cast<completed_thread*>(completed_thread_ptr));
}
static void start_threads(void) {
diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc
index 27d32c59ae..0d052dc166 100644
--- a/src/core/lib/iomgr/udp_server.cc
+++ b/src/core/lib/iomgr/udp_server.cc
@@ -132,14 +132,14 @@ static grpc_socket_factory* get_socket_factory(const grpc_channel_args* args) {
const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_SOCKET_FACTORY);
if (arg) {
GPR_ASSERT(arg->type == GRPC_ARG_POINTER);
- return (grpc_socket_factory*)arg->value.pointer.p;
+ return static_cast<grpc_socket_factory*>(arg->value.pointer.p);
}
}
return nullptr;
}
grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) {
- grpc_udp_server* s = (grpc_udp_server*)gpr_malloc(sizeof(grpc_udp_server));
+ grpc_udp_server* s = static_cast<grpc_udp_server*>(gpr_malloc(sizeof(grpc_udp_server)));
gpr_mu_init(&s->mu);
s->socket_factory = get_socket_factory(args);
if (s->socket_factory) {
@@ -156,7 +156,7 @@ grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) {
}
static void shutdown_fd(void* args, grpc_error* error) {
- struct shutdown_fd_args* shutdown_args = (struct shutdown_fd_args*)args;
+ struct shutdown_fd_args* shutdown_args = static_cast<struct shutdown_fd_args*>(args);
grpc_udp_listener* sp = shutdown_args->sp;
gpr_log(GPR_DEBUG, "shutdown fd %d", sp->fd);
gpr_mu_lock(shutdown_args->server_mu);
@@ -198,7 +198,7 @@ static void finish_shutdown(grpc_udp_server* s) {
}
static void destroyed_port(void* server, grpc_error* error) {
- grpc_udp_server* s = (grpc_udp_server*)server;
+ grpc_udp_server* s = static_cast<grpc_udp_server*>(server);
gpr_mu_lock(&s->mu);
s->destroyed_ports++;
if (s->destroyed_ports == s->nports) {
@@ -260,7 +260,7 @@ void grpc_udp_server_destroy(grpc_udp_server* s, grpc_closure* on_done) {
for (sp = s->head; sp; sp = sp->next) {
GPR_ASSERT(sp->orphan_cb);
struct shutdown_fd_args* args =
- (struct shutdown_fd_args*)gpr_malloc(sizeof(*args));
+ static_cast<struct shutdown_fd_args*>(gpr_malloc(sizeof(*args)));
args->sp = sp;
args->server_mu = &s->mu;
GRPC_CLOSURE_INIT(&sp->orphan_fd_closure, shutdown_fd, args,
@@ -279,7 +279,7 @@ static int bind_socket(grpc_socket_factory* socket_factory, int sockfd,
const grpc_resolved_address* addr) {
return (socket_factory != nullptr)
? grpc_socket_factory_bind(socket_factory, sockfd, addr)
- : bind(sockfd, (struct sockaddr*)addr->addr, (socklen_t)addr->len);
+ : bind(sockfd, reinterpret_cast<struct sockaddr*>(addr->addr), static_cast<socklen_t>(addr->len));
}
/* Prepare a recently-created socket for listening. */
@@ -287,7 +287,7 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd,
const grpc_resolved_address* addr, int rcv_buf_size,
int snd_buf_size) {
grpc_resolved_address sockname_temp;
- struct sockaddr* addr_ptr = (struct sockaddr*)addr->addr;
+ struct sockaddr* addr_ptr = reinterpret_cast<struct sockaddr*>(addr->addr);
if (fd < 0) {
goto error;
@@ -323,8 +323,8 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd,
sockname_temp.len = sizeof(struct sockaddr_storage);
- if (getsockname(fd, (struct sockaddr*)sockname_temp.addr,
- (socklen_t*)&sockname_temp.len) < 0) {
+ if (getsockname(fd, reinterpret_cast<struct sockaddr*>(sockname_temp.addr),
+ reinterpret_cast<socklen_t*>(&sockname_temp.len)) < 0) {
goto error;
}
@@ -379,7 +379,7 @@ static void do_read(void* arg, grpc_error* error) {
/* event manager callback when reads are ready */
static void on_read(void* arg, grpc_error* error) {
- grpc_udp_listener* sp = (grpc_udp_listener*)arg;
+ grpc_udp_listener* sp = static_cast<grpc_udp_listener*>(arg);
gpr_mu_lock(&sp->server->mu);
if (error != GRPC_ERROR_NONE) {
@@ -438,7 +438,7 @@ static void do_write(void* arg, grpc_error* error) {
}
static void on_write(void* arg, grpc_error* error) {
- grpc_udp_listener* sp = (grpc_udp_listener*)arg;
+ grpc_udp_listener* sp = static_cast<grpc_udp_listener*>(arg);
gpr_mu_lock(&sp->server->mu);
if (error != GRPC_ERROR_NONE) {
@@ -479,7 +479,7 @@ static int add_socket_to_server(grpc_udp_server* s, int fd,
gpr_free(addr_str);
gpr_mu_lock(&s->mu);
s->nports++;
- sp = (grpc_udp_listener*)gpr_malloc(sizeof(grpc_udp_listener));
+ sp = static_cast<grpc_udp_listener*>(gpr_malloc(sizeof(grpc_udp_listener)));
sp->next = nullptr;
if (s->head == nullptr) {
s->head = sp;
@@ -530,12 +530,12 @@ int grpc_udp_server_add_port(grpc_udp_server* s,
if (grpc_sockaddr_get_port(addr) == 0) {
for (sp = s->head; sp; sp = sp->next) {
sockname_temp.len = sizeof(struct sockaddr_storage);
- if (0 == getsockname(sp->fd, (struct sockaddr*)sockname_temp.addr,
- (socklen_t*)&sockname_temp.len)) {
+ if (0 == getsockname(sp->fd, reinterpret_cast<struct sockaddr*>(sockname_temp.addr),
+ reinterpret_cast<socklen_t*>(&sockname_temp.len))) {
port = grpc_sockaddr_get_port(&sockname_temp);
if (port > 0) {
allocated_addr =
- (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address));
+ static_cast<grpc_resolved_address*>(gpr_malloc(sizeof(grpc_resolved_address)));
memcpy(allocated_addr, addr, sizeof(grpc_resolved_address));
grpc_sockaddr_set_port(allocated_addr, port);
addr = allocated_addr;
diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc
index 91b7cb1e59..7365787c71 100644
--- a/src/core/lib/iomgr/unix_sockets_posix.cc
+++ b/src/core/lib/iomgr/unix_sockets_posix.cc
@@ -52,11 +52,11 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name,
return err;
}
*addrs =
- (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses));
+ static_cast<grpc_resolved_addresses*>(gpr_malloc(sizeof(grpc_resolved_addresses)));
(*addrs)->naddrs = 1;
(*addrs)->addrs =
- (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address));
- un = (struct sockaddr_un*)(*addrs)->addrs->addr;
+ static_cast<grpc_resolved_address*>(gpr_malloc(sizeof(grpc_resolved_address)));
+ un = reinterpret_cast<struct sockaddr_un*>((*addrs)->addrs->addr);
un->sun_family = AF_UNIX;
strncpy(un->sun_path, name, sizeof(un->sun_path));
(*addrs)->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
@@ -64,17 +64,17 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name,
}
int grpc_is_unix_socket(const grpc_resolved_address* resolved_addr) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
return addr->sa_family == AF_UNIX;
}
void grpc_unlink_if_unix_domain_socket(
const grpc_resolved_address* resolved_addr) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
if (addr->sa_family != AF_UNIX) {
return;
}
- struct sockaddr_un* un = (struct sockaddr_un*)resolved_addr->addr;
+ struct sockaddr_un* un = reinterpret_cast<struct sockaddr_un*>(resolved_addr->addr);
struct stat st;
if (stat(un->sun_path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) {
@@ -84,7 +84,7 @@ void grpc_unlink_if_unix_domain_socket(
char* grpc_sockaddr_to_uri_unix_if_possible(
const grpc_resolved_address* resolved_addr) {
- const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
+ const struct sockaddr* addr = reinterpret_cast<const struct sockaddr*>(resolved_addr->addr);
if (addr->sa_family != AF_UNIX) {
return nullptr;
}
diff --git a/src/core/lib/iomgr/wakeup_fd_cv.cc b/src/core/lib/iomgr/wakeup_fd_cv.cc
index 4818cafe3d..80f07ccf23 100644
--- a/src/core/lib/iomgr/wakeup_fd_cv.cc
+++ b/src/core/lib/iomgr/wakeup_fd_cv.cc
@@ -43,8 +43,8 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) {
gpr_mu_lock(&g_cvfds.mu);
if (!g_cvfds.free_fds) {
newsize = GPR_MIN(g_cvfds.size * 2, g_cvfds.size + MAX_TABLE_RESIZE);
- g_cvfds.cvfds = (grpc_fd_node*)gpr_realloc(g_cvfds.cvfds,
- sizeof(grpc_fd_node) * newsize);
+ g_cvfds.cvfds = static_cast<grpc_fd_node*>(gpr_realloc(g_cvfds.cvfds,
+ sizeof(grpc_fd_node) * newsize));
for (i = g_cvfds.size; i < newsize; i++) {
g_cvfds.cvfds[i].is_set = 0;
g_cvfds.cvfds[i].cvs = nullptr;
@@ -54,7 +54,7 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) {
g_cvfds.size = newsize;
}
- idx = (int)(g_cvfds.free_fds - g_cvfds.cvfds);
+ idx = static_cast<int>(g_cvfds.free_fds - g_cvfds.cvfds);
g_cvfds.free_fds = g_cvfds.free_fds->next_free;
g_cvfds.cvfds[idx].cvs = nullptr;
g_cvfds.cvfds[idx].is_set = 0;
diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc
index 4ad51f662a..adf35b9088 100644
--- a/src/core/lib/json/json.cc
+++ b/src/core/lib/json/json.cc
@@ -23,7 +23,7 @@
#include "src/core/lib/json/json.h"
grpc_json* grpc_json_create(grpc_json_type type) {
- grpc_json* json = (grpc_json*)gpr_zalloc(sizeof(*json));
+ grpc_json* json = static_cast<grpc_json*>(gpr_zalloc(sizeof(*json)));
json->type = type;
return json;
diff --git a/src/core/lib/json/json_reader.cc b/src/core/lib/json/json_reader.cc
index 30039419b1..019214a167 100644
--- a/src/core/lib/json/json_reader.cc
+++ b/src/core/lib/json/json_reader.cc
@@ -138,7 +138,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 = (uint32_t)json_reader_set_number(reader);
+ success = static_cast<uint32_t>(json_reader_set_number(reader));
if (!success) return GRPC_JSON_PARSE_ERROR;
json_reader_string_clear(reader);
reader->state = GRPC_JSON_STATE_VALUE_END;
@@ -173,7 +173,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
} else if ((c == ']') && !reader->in_array) {
return GRPC_JSON_PARSE_ERROR;
}
- success = (uint32_t)json_reader_set_number(reader);
+ success = static_cast<uint32_t>(json_reader_set_number(reader));
if (!success) return GRPC_JSON_PARSE_ERROR;
json_reader_string_clear(reader);
reader->state = GRPC_JSON_STATE_VALUE_END;
@@ -417,8 +417,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
} else {
return GRPC_JSON_PARSE_ERROR;
}
- reader->unicode_char = (uint16_t)(reader->unicode_char << 4);
- reader->unicode_char = (uint16_t)(reader->unicode_char | c);
+ reader->unicode_char = static_cast<uint16_t>(reader->unicode_char << 4);
+ reader->unicode_char = static_cast<uint16_t>(reader->unicode_char | c);
switch (reader->state) {
case GRPC_JSON_STATE_STRING_ESCAPE_U1:
@@ -445,9 +445,9 @@ 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 += (uint32_t)(
+ utf32 += static_cast<uint32_t>(
(reader->unicode_high_surrogate - 0xd800) * 0x400);
- utf32 += (uint32_t)(reader->unicode_char - 0xdc00);
+ utf32 += static_cast<uint32_t>(reader->unicode_char - 0xdc00);
json_reader_string_add_utf32(reader, utf32);
reader->unicode_high_surrogate = 0;
} else {
diff --git a/src/core/lib/json/json_string.cc b/src/core/lib/json/json_string.cc
index a339eec81b..dcaf11d0c9 100644
--- a/src/core/lib/json/json_string.cc
+++ b/src/core/lib/json/json_string.cc
@@ -63,19 +63,19 @@ typedef struct {
* bytes at a time (or multiples thereof).
*/
static void json_writer_output_check(void* userdata, size_t needed) {
- json_writer_userdata* state = (json_writer_userdata*)userdata;
+ json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
if (state->free_space >= needed) return;
needed -= state->free_space;
/* Round up by 256 bytes. */
needed = (needed + 0xff) & ~0xffU;
- state->output = (char*)gpr_realloc(state->output, state->allocated + needed);
+ state->output = static_cast<char*>(gpr_realloc(state->output, state->allocated + needed));
state->free_space += needed;
state->allocated += needed;
}
/* These are needed by the writer's implementation. */
static void json_writer_output_char(void* userdata, char c) {
- json_writer_userdata* state = (json_writer_userdata*)userdata;
+ json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
json_writer_output_check(userdata, 1);
state->output[state->string_len++] = c;
state->free_space--;
@@ -83,7 +83,7 @@ static void json_writer_output_char(void* userdata, char c) {
static void json_writer_output_string_with_len(void* userdata, const char* str,
size_t len) {
- json_writer_userdata* state = (json_writer_userdata*)userdata;
+ json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
json_writer_output_check(userdata, len);
memcpy(state->output + state->string_len, str, len);
state->string_len += len;
@@ -99,7 +99,7 @@ static void json_writer_output_string(void* userdata, const char* str) {
* the end of the current string, and advance our output pointer.
*/
static void json_reader_string_clear(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
if (state->string) {
GPR_ASSERT(state->string_ptr < state->input);
*state->string_ptr++ = 0;
@@ -108,10 +108,10 @@ static void json_reader_string_clear(void* userdata) {
}
static void json_reader_string_add_char(void* userdata, uint32_t c) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
GPR_ASSERT(state->string_ptr < state->input);
GPR_ASSERT(c <= 0xff);
- *state->string_ptr++ = (uint8_t)c;
+ *state->string_ptr++ = static_cast<uint8_t>(c);
}
/* We are converting a UTF-32 character into UTF-8 here,
@@ -149,7 +149,7 @@ static void json_reader_string_add_utf32(void* userdata, uint32_t c) {
*/
static uint32_t json_reader_read_char(void* userdata) {
uint32_t r;
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
if (state->remaining_input == 0) return GRPC_JSON_READ_CHAR_EOF;
@@ -168,7 +168,7 @@ static uint32_t json_reader_read_char(void* userdata) {
* our tree-in-progress inside our opaque structure.
*/
static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* json = grpc_json_create(type);
json->parent = state->current_container;
@@ -183,7 +183,7 @@ static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) {
json->parent->child = json;
}
if (json->parent->type == GRPC_JSON_OBJECT) {
- json->key = (char*)state->key;
+ json->key = reinterpret_cast<char*>(state->key);
}
}
if (!state->top) {
@@ -194,7 +194,7 @@ static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) {
}
static void json_reader_container_begins(void* userdata, grpc_json_type type) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* container;
GPR_ASSERT(type == GRPC_JSON_ARRAY || type == GRPC_JSON_OBJECT);
@@ -215,7 +215,7 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) {
*/
static grpc_json_type json_reader_container_ends(void* userdata) {
grpc_json_type container_type = GRPC_JSON_TOP_LEVEL;
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
GPR_ASSERT(state->current_container);
@@ -236,20 +236,20 @@ static grpc_json_type json_reader_container_ends(void* userdata) {
* We'll keep it as a string, and leave it to the caller to evaluate it.
*/
static void json_reader_set_key(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
state->key = state->string;
}
static void json_reader_set_string(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* json = json_create_and_link(userdata, GRPC_JSON_STRING);
- json->value = (char*)state->string;
+ json->value = reinterpret_cast<char*>(state->string);
}
static int json_reader_set_number(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* json = json_create_and_link(userdata, GRPC_JSON_NUMBER);
- json->value = (char*)state->string;
+ json->value = reinterpret_cast<char*>(state->string);
return 1;
}
@@ -287,7 +287,7 @@ grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) {
state.top = state.current_container = state.current_value = nullptr;
state.string = state.key = nullptr;
- state.string_ptr = state.input = (uint8_t*)input;
+ state.string_ptr = state.input = reinterpret_cast<uint8_t*>(input);
state.remaining_input = size;
grpc_json_reader_init(&reader, &reader_vtable, &state);
diff --git a/src/core/lib/json/json_writer.cc b/src/core/lib/json/json_writer.cc
index 0b9c7c30ea..df49cbe4dc 100644
--- a/src/core/lib/json/json_writer.cc
+++ b/src/core/lib/json/json_writer.cc
@@ -52,7 +52,7 @@ static void json_writer_output_indent(grpc_json_writer* writer) {
" "
" ";
- unsigned spaces = (unsigned)(writer->depth * writer->indent);
+ unsigned spaces = static_cast<unsigned>(writer->depth * writer->indent);
if (writer->indent == 0) return;
@@ -64,7 +64,7 @@ static void json_writer_output_indent(grpc_json_writer* writer) {
while (spaces >= (sizeof(spacesstr) - 1)) {
json_writer_output_string_with_len(writer, spacesstr,
sizeof(spacesstr) - 1);
- spaces -= (unsigned)(sizeof(spacesstr) - 1);
+ spaces -= static_cast<unsigned>(sizeof(spacesstr) - 1);
}
if (spaces == 0) return;
@@ -100,12 +100,12 @@ static void json_writer_escape_string(grpc_json_writer* writer,
json_writer_output_char(writer, '"');
for (;;) {
- uint8_t c = (uint8_t)*string++;
+ uint8_t c = static_cast<uint8_t>(*string++);
if (c == 0) {
break;
} else if ((c >= 32) && (c <= 126)) {
if ((c == '\\') || (c == '"')) json_writer_output_char(writer, '\\');
- json_writer_output_char(writer, (char)c);
+ json_writer_output_char(writer, static_cast<char>(c));
} else if ((c < 32) || (c == 127)) {
switch (c) {
case '\b':
@@ -146,7 +146,7 @@ static void json_writer_escape_string(grpc_json_writer* writer,
}
for (i = 0; i < extra; i++) {
utf32 <<= 6;
- c = (uint8_t)(*string++);
+ c = static_cast<uint8_t>(*string++);
/* Breaks out and bail on any invalid UTF-8 sequence, including \0. */
if ((c & 0xc0) != 0x80) {
valid = 0;
@@ -179,10 +179,10 @@ static void json_writer_escape_string(grpc_json_writer* writer,
* That range is exactly 20 bits.
*/
utf32 -= 0x10000;
- json_writer_escape_utf16(writer, (uint16_t)(0xd800 | (utf32 >> 10)));
- json_writer_escape_utf16(writer, (uint16_t)(0xdc00 | (utf32 & 0x3ff)));
+ json_writer_escape_utf16(writer, static_cast<uint16_t>(0xd800 | (utf32 >> 10)));
+ json_writer_escape_utf16(writer, static_cast<uint16_t>(0xdc00 | (utf32 & 0x3ff)));
} else {
- json_writer_escape_utf16(writer, (uint16_t)utf32);
+ json_writer_escape_utf16(writer, static_cast<uint16_t>(utf32));
}
}
}
diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc
index 63ec42cf86..cd8fabea28 100644
--- a/src/core/lib/security/context/security_context.cc
+++ b/src/core/lib/security/context/security_context.cc
@@ -44,8 +44,8 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call,
gpr_log(GPR_ERROR, "Method is client-side only.");
return GRPC_CALL_ERROR_NOT_ON_SERVER;
}
- ctx = (grpc_client_security_context*)grpc_call_context_get(
- call, GRPC_CONTEXT_SECURITY);
+ ctx = static_cast<grpc_client_security_context*>(grpc_call_context_get(
+ call, GRPC_CONTEXT_SECURITY));
if (ctx == nullptr) {
ctx = grpc_client_security_context_create();
ctx->creds = grpc_call_credentials_ref(creds);
@@ -80,13 +80,13 @@ void grpc_auth_context_release(grpc_auth_context* context) {
/* --- grpc_client_security_context --- */
grpc_client_security_context* grpc_client_security_context_create(void) {
- return (grpc_client_security_context*)gpr_zalloc(
- sizeof(grpc_client_security_context));
+ return static_cast<grpc_client_security_context*>(gpr_zalloc(
+ sizeof(grpc_client_security_context)));
}
void grpc_client_security_context_destroy(void* ctx) {
grpc_core::ExecCtx exec_ctx;
- grpc_client_security_context* c = (grpc_client_security_context*)ctx;
+ grpc_client_security_context* c = static_cast<grpc_client_security_context*>(ctx);
grpc_call_credentials_unref(c->creds);
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context");
if (c->extension.instance != nullptr && c->extension.destroy != nullptr) {
@@ -98,12 +98,12 @@ void grpc_client_security_context_destroy(void* ctx) {
/* --- grpc_server_security_context --- */
grpc_server_security_context* grpc_server_security_context_create(void) {
- return (grpc_server_security_context*)gpr_zalloc(
- sizeof(grpc_server_security_context));
+ return static_cast<grpc_server_security_context*>(gpr_zalloc(
+ sizeof(grpc_server_security_context)));
}
void grpc_server_security_context_destroy(void* ctx) {
- grpc_server_security_context* c = (grpc_server_security_context*)ctx;
+ grpc_server_security_context* c = static_cast<grpc_server_security_context*>(ctx);
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context");
if (c->extension.instance != nullptr && c->extension.destroy != nullptr) {
c->extension.destroy(c->extension.instance);
@@ -117,7 +117,7 @@ static grpc_auth_property_iterator empty_iterator = {nullptr, 0, nullptr};
grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) {
grpc_auth_context* ctx =
- (grpc_auth_context*)gpr_zalloc(sizeof(grpc_auth_context));
+ static_cast<grpc_auth_context*>(gpr_zalloc(sizeof(grpc_auth_context)));
gpr_ref_init(&ctx->refcount, 1);
if (chained != nullptr) {
ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained");
@@ -258,9 +258,9 @@ static void ensure_auth_context_capacity(grpc_auth_context* ctx) {
if (ctx->properties.count == ctx->properties.capacity) {
ctx->properties.capacity =
GPR_MAX(ctx->properties.capacity + 8, ctx->properties.capacity * 2);
- ctx->properties.array = (grpc_auth_property*)gpr_realloc(
+ ctx->properties.array = static_cast<grpc_auth_property*>(gpr_realloc(
ctx->properties.array,
- ctx->properties.capacity * sizeof(grpc_auth_property));
+ ctx->properties.capacity * sizeof(grpc_auth_property)));
}
}
@@ -276,7 +276,7 @@ void grpc_auth_context_add_property(grpc_auth_context* ctx, const char* name,
ensure_auth_context_capacity(ctx);
prop = &ctx->properties.array[ctx->properties.count++];
prop->name = gpr_strdup(name);
- prop->value = (char*)gpr_malloc(value_length + 1);
+ prop->value = static_cast<char*>(gpr_malloc(value_length + 1));
memcpy(prop->value, value, value_length);
prop->value[value_length] = '\0';
prop->value_length = value_length;
@@ -329,7 +329,7 @@ grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) {
GRPC_AUTH_CONTEXT_ARG);
return nullptr;
}
- return (grpc_auth_context*)arg->value.pointer.p;
+ return static_cast<grpc_auth_context*>(arg->value.pointer.p);
}
grpc_auth_context* grpc_find_auth_context_in_args(
diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc
index e4c1604795..248177a178 100644
--- a/src/core/lib/security/credentials/composite/composite_credentials.cc
+++ b/src/core/lib/security/credentials/composite/composite_credentials.cc
@@ -40,7 +40,7 @@ typedef struct {
} grpc_composite_call_credentials_metadata_context;
static void composite_call_destruct(grpc_call_credentials* creds) {
- grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds;
+ grpc_composite_call_credentials* c = reinterpret_cast<grpc_composite_call_credentials*>(creds);
for (size_t i = 0; i < c->inner.num_creds; i++) {
grpc_call_credentials_unref(c->inner.creds_array[i]);
}
@@ -49,7 +49,7 @@ static void composite_call_destruct(grpc_call_credentials* creds) {
static void composite_call_metadata_cb(void* arg, grpc_error* error) {
grpc_composite_call_credentials_metadata_context* ctx =
- (grpc_composite_call_credentials_metadata_context*)arg;
+ static_cast<grpc_composite_call_credentials_metadata_context*>(arg);
if (error == GRPC_ERROR_NONE) {
/* See if we need to get some more metadata. */
if (ctx->creds_index < ctx->composite_creds->inner.num_creds) {
@@ -75,10 +75,10 @@ static bool composite_call_get_request_metadata(
grpc_auth_metadata_context auth_md_context,
grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
grpc_error** error) {
- grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds;
+ grpc_composite_call_credentials* c = reinterpret_cast<grpc_composite_call_credentials*>(creds);
grpc_composite_call_credentials_metadata_context* ctx;
- ctx = (grpc_composite_call_credentials_metadata_context*)gpr_zalloc(
- sizeof(grpc_composite_call_credentials_metadata_context));
+ ctx = static_cast<grpc_composite_call_credentials_metadata_context*>(gpr_zalloc(
+ sizeof(grpc_composite_call_credentials_metadata_context)));
ctx->composite_creds = c;
ctx->pollent = pollent;
ctx->auth_md_context = auth_md_context;
@@ -106,7 +106,7 @@ static bool composite_call_get_request_metadata(
static void composite_call_cancel_get_request_metadata(
grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
grpc_error* error) {
- grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds;
+ grpc_composite_call_credentials* c = reinterpret_cast<grpc_composite_call_credentials*>(creds);
for (size_t i = 0; i < c->inner.num_creds; ++i) {
grpc_call_credentials_cancel_get_request_metadata(
c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error));
@@ -145,8 +145,8 @@ grpc_call_credentials* grpc_composite_call_credentials_create(
GPR_ASSERT(reserved == nullptr);
GPR_ASSERT(creds1 != nullptr);
GPR_ASSERT(creds2 != nullptr);
- c = (grpc_composite_call_credentials*)gpr_zalloc(
- sizeof(grpc_composite_call_credentials));
+ c = static_cast<grpc_composite_call_credentials*>(gpr_zalloc(
+ sizeof(grpc_composite_call_credentials)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE;
c->base.vtable = &composite_call_credentials_vtable;
gpr_ref_init(&c->base.refcount, 1);
@@ -155,7 +155,7 @@ grpc_call_credentials* grpc_composite_call_credentials_create(
c->inner.num_creds = creds1_array.num_creds + creds2_array.num_creds;
creds_array_byte_size = c->inner.num_creds * sizeof(grpc_call_credentials*);
c->inner.creds_array =
- (grpc_call_credentials**)gpr_zalloc(creds_array_byte_size);
+ static_cast<grpc_call_credentials**>(gpr_zalloc(creds_array_byte_size));
for (i = 0; i < creds1_array.num_creds; i++) {
grpc_call_credentials* cur_creds = creds1_array.creds_array[i];
c->inner.creds_array[i] = grpc_call_credentials_ref(cur_creds);
@@ -171,7 +171,7 @@ grpc_call_credentials* grpc_composite_call_credentials_create(
const grpc_call_credentials_array*
grpc_composite_call_credentials_get_credentials(grpc_call_credentials* creds) {
const grpc_composite_call_credentials* c =
- (const grpc_composite_call_credentials*)creds;
+ reinterpret_cast<const grpc_composite_call_credentials*>(creds);
GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0);
return &c->inner;
}
@@ -200,7 +200,7 @@ grpc_call_credentials* grpc_credentials_contains_type(
static void composite_channel_destruct(grpc_channel_credentials* creds) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)creds;
+ reinterpret_cast<grpc_composite_channel_credentials*>(creds);
grpc_channel_credentials_unref(c->inner_creds);
grpc_call_credentials_unref(c->call_creds);
}
@@ -210,7 +210,7 @@ static grpc_security_status composite_channel_create_security_connector(
const char* target, const grpc_channel_args* args,
grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)creds;
+ reinterpret_cast<grpc_composite_channel_credentials*>(creds);
grpc_security_status status = GRPC_SECURITY_ERROR;
GPR_ASSERT(c->inner_creds != nullptr && c->call_creds != nullptr &&
@@ -236,7 +236,7 @@ static grpc_channel_credentials*
composite_channel_duplicate_without_call_credentials(
grpc_channel_credentials* creds) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)creds;
+ reinterpret_cast<grpc_composite_channel_credentials*>(creds);
return grpc_channel_credentials_ref(c->inner_creds);
}
@@ -248,7 +248,7 @@ grpc_channel_credentials* grpc_composite_channel_credentials_create(
grpc_channel_credentials* channel_creds, grpc_call_credentials* call_creds,
void* reserved) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)gpr_zalloc(sizeof(*c));
+ static_cast<grpc_composite_channel_credentials*>(gpr_zalloc(sizeof(*c)));
GPR_ASSERT(channel_creds != nullptr && call_creds != nullptr &&
reserved == nullptr);
GRPC_API_TRACE(
diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc
index 009a5ce4ec..c1ca881292 100644
--- a/src/core/lib/security/credentials/credentials.cc
+++ b/src/core/lib/security/credentials/credentials.cc
@@ -40,8 +40,8 @@
grpc_credentials_metadata_request* grpc_credentials_metadata_request_create(
grpc_call_credentials* creds) {
grpc_credentials_metadata_request* r =
- (grpc_credentials_metadata_request*)gpr_zalloc(
- sizeof(grpc_credentials_metadata_request));
+ static_cast<grpc_credentials_metadata_request*>(gpr_zalloc(
+ sizeof(grpc_credentials_metadata_request)));
r->creds = grpc_call_credentials_ref(creds);
return r;
}
@@ -145,11 +145,11 @@ grpc_channel_credentials_duplicate_without_call_credentials(
}
static void credentials_pointer_arg_destroy(void* p) {
- grpc_channel_credentials_unref((grpc_channel_credentials*)p);
+ grpc_channel_credentials_unref(static_cast<grpc_channel_credentials*>(p));
}
static void* credentials_pointer_arg_copy(void* p) {
- return grpc_channel_credentials_ref((grpc_channel_credentials*)p);
+ return grpc_channel_credentials_ref(static_cast<grpc_channel_credentials*>(p));
}
static int credentials_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
@@ -173,7 +173,7 @@ grpc_channel_credentials* grpc_channel_credentials_from_arg(
GRPC_ARG_CHANNEL_CREDENTIALS);
return nullptr;
}
- return (grpc_channel_credentials*)arg->value.pointer.p;
+ return static_cast<grpc_channel_credentials*>(arg->value.pointer.p);
}
grpc_channel_credentials* grpc_channel_credentials_find_in_args(
@@ -240,11 +240,11 @@ void grpc_server_credentials_set_auth_metadata_processor(
}
static void server_credentials_pointer_arg_destroy(void* p) {
- grpc_server_credentials_unref((grpc_server_credentials*)p);
+ grpc_server_credentials_unref(static_cast<grpc_server_credentials*>(p));
}
static void* server_credentials_pointer_arg_copy(void* p) {
- return grpc_server_credentials_ref((grpc_server_credentials*)p);
+ return grpc_server_credentials_ref(static_cast<grpc_server_credentials*>(p));
}
static int server_credentials_pointer_cmp(void* a, void* b) {
@@ -267,7 +267,7 @@ grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) {
GRPC_SERVER_CREDENTIALS_ARG);
return nullptr;
}
- return (grpc_server_credentials*)arg->value.pointer.p;
+ return static_cast<grpc_server_credentials*>(arg->value.pointer.p);
}
grpc_server_credentials* grpc_find_server_credentials_in_args(
diff --git a/src/core/lib/security/credentials/credentials_metadata.cc b/src/core/lib/security/credentials/credentials_metadata.cc
index 9ceaf21139..76e856f48e 100644
--- a/src/core/lib/security/credentials/credentials_metadata.cc
+++ b/src/core/lib/security/credentials/credentials_metadata.cc
@@ -34,7 +34,7 @@ static void mdelem_list_ensure_capacity(grpc_credentials_mdelem_array* list,
new_size *= 2;
}
list->md =
- (grpc_mdelem*)gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size);
+ static_cast<grpc_mdelem*>(gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size));
}
void grpc_credentials_mdelem_array_add(grpc_credentials_mdelem_array* list,
diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc
index 9065325cdd..b4f0dfdbdc 100644
--- a/src/core/lib/security/credentials/fake/fake_credentials.cc
+++ b/src/core/lib/security/credentials/fake/fake_credentials.cc
@@ -60,7 +60,7 @@ static grpc_server_credentials_vtable
grpc_channel_credentials* grpc_fake_transport_security_credentials_create(
void) {
grpc_channel_credentials* c =
- (grpc_channel_credentials*)gpr_zalloc(sizeof(grpc_channel_credentials));
+ static_cast<grpc_channel_credentials*>(gpr_zalloc(sizeof(grpc_channel_credentials)));
c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY;
c->vtable = &fake_transport_security_credentials_vtable;
gpr_ref_init(&c->refcount, 1);
@@ -70,7 +70,7 @@ grpc_channel_credentials* grpc_fake_transport_security_credentials_create(
grpc_server_credentials* grpc_fake_transport_security_server_credentials_create(
void) {
grpc_server_credentials* c =
- (grpc_server_credentials*)gpr_malloc(sizeof(grpc_server_credentials));
+ static_cast<grpc_server_credentials*>(gpr_malloc(sizeof(grpc_server_credentials)));
memset(c, 0, sizeof(grpc_server_credentials));
c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY;
gpr_ref_init(&c->refcount, 1);
@@ -97,7 +97,7 @@ const char* grpc_fake_transport_get_expected_targets(
/* -- Metadata-only test credentials. -- */
static void md_only_test_destruct(grpc_call_credentials* creds) {
- grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds;
+ grpc_md_only_test_credentials* c = reinterpret_cast<grpc_md_only_test_credentials*>(creds);
GRPC_MDELEM_UNREF(c->md);
}
@@ -105,7 +105,7 @@ static bool md_only_test_get_request_metadata(
grpc_call_credentials* creds, grpc_polling_entity* pollent,
grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata, grpc_error** error) {
- grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds;
+ grpc_md_only_test_credentials* c = reinterpret_cast<grpc_md_only_test_credentials*>(creds);
grpc_credentials_mdelem_array_add(md_array, c->md);
if (c->is_async) {
GRPC_CLOSURE_SCHED(on_request_metadata, GRPC_ERROR_NONE);
@@ -126,8 +126,8 @@ static grpc_call_credentials_vtable md_only_test_vtable = {
grpc_call_credentials* grpc_md_only_test_credentials_create(
const char* md_key, const char* md_value, bool is_async) {
- grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)gpr_zalloc(
- sizeof(grpc_md_only_test_credentials));
+ grpc_md_only_test_credentials* c = static_cast<grpc_md_only_test_credentials*>(gpr_zalloc(
+ sizeof(grpc_md_only_test_credentials)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2;
c->base.vtable = &md_only_test_vtable;
gpr_ref_init(&c->base.refcount, 1);
diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc
index dc19202033..dd7d52d750 100644
--- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc
+++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc
@@ -60,7 +60,7 @@ typedef struct {
static void on_compute_engine_detection_http_response(void* user_data,
grpc_error* error) {
- compute_engine_detector* detector = (compute_engine_detector*)user_data;
+ compute_engine_detector* detector = static_cast<compute_engine_detector*>(user_data);
if (error == GRPC_ERROR_NONE && detector->response.status == 200 &&
detector->response.hdr_count > 0) {
/* Internet providers can return a generic response to all requests, so
@@ -85,7 +85,7 @@ static void on_compute_engine_detection_http_response(void* user_data,
}
static void destroy_pollset(void* p, grpc_error* e) {
- grpc_pollset_destroy((grpc_pollset*)p);
+ grpc_pollset_destroy(static_cast<grpc_pollset*>(p));
}
static int is_stack_running_on_compute_engine() {
@@ -98,7 +98,7 @@ static int is_stack_running_on_compute_engine() {
on compute engine. */
grpc_millis max_detection_delay = GPR_MS_PER_SEC;
- grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
+ grpc_pollset* pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(pollset, &g_polling_mu);
detector.pollent = grpc_polling_entity_create_from_pollset(pollset);
detector.is_done = 0;
@@ -171,7 +171,7 @@ static grpc_error* create_default_creds_from_path(
goto end;
}
json = grpc_json_parse_string_with_len(
- (char*)GRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data));
+ reinterpret_cast<char*>GRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data));
if (json == nullptr) {
error = grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"),
diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc
index 75acb2a58e..20f4ff95f5 100644
--- a/src/core/lib/security/credentials/iam/iam_credentials.cc
+++ b/src/core/lib/security/credentials/iam/iam_credentials.cc
@@ -28,7 +28,7 @@
#include <grpc/support/sync.h>
static void iam_destruct(grpc_call_credentials* creds) {
- grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds;
+ grpc_google_iam_credentials* c = reinterpret_cast<grpc_google_iam_credentials*>(creds);
grpc_credentials_mdelem_array_destroy(&c->md_array);
}
@@ -38,7 +38,7 @@ static bool iam_get_request_metadata(grpc_call_credentials* creds,
grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata,
grpc_error** error) {
- grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds;
+ grpc_google_iam_credentials* c = reinterpret_cast<grpc_google_iam_credentials*>(creds);
grpc_credentials_mdelem_array_append(md_array, &c->md_array);
return true;
}
@@ -63,7 +63,7 @@ grpc_call_credentials* grpc_google_iam_credentials_create(
GPR_ASSERT(token != nullptr);
GPR_ASSERT(authority_selector != nullptr);
grpc_google_iam_credentials* c =
- (grpc_google_iam_credentials*)gpr_zalloc(sizeof(*c));
+ static_cast<grpc_google_iam_credentials*>(gpr_zalloc(sizeof(*c)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_IAM;
c->base.vtable = &iam_vtable;
gpr_ref_init(&c->base.refcount, 1);
diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc
index 078f04ed11..eae1be17fd 100644
--- a/src/core/lib/security/credentials/jwt/json_token.cc
+++ b/src/core/lib/security/credentials/jwt/json_token.cc
@@ -96,7 +96,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) {
}
bio = BIO_new(BIO_s_mem());
success = BIO_puts(bio, prop_value);
- if ((success < 0) || ((size_t)success != strlen(prop_value))) {
+ if ((success < 0) || (static_cast<size_t>(success) != strlen(prop_value))) {
gpr_log(GPR_ERROR, "Could not write into openssl BIO.");
goto end;
}
@@ -219,7 +219,7 @@ static char* dot_concat_and_free_strings(char* str1, char* str2) {
size_t str1_len = strlen(str1);
size_t str2_len = strlen(str2);
size_t result_len = str1_len + 1 /* dot */ + str2_len;
- char* result = (char*)gpr_malloc(result_len + 1 /* NULL terminated */);
+ char* result = static_cast<char*>(gpr_malloc(result_len + 1 /* NULL terminated */));
char* current = result;
memcpy(current, str1, str1_len);
current += str1_len;
@@ -271,7 +271,7 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key,
gpr_log(GPR_ERROR, "DigestFinal (get signature length) failed.");
goto end;
}
- sig = (unsigned char*)gpr_malloc(sig_len);
+ sig = static_cast<unsigned char*>(gpr_malloc(sig_len));
if (EVP_DigestSignFinal(md_ctx, sig, &sig_len) != 1) {
gpr_log(GPR_ERROR, "DigestFinal (signature compute) failed.");
goto end;
diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc
index 2404e860e4..44101acd78 100644
--- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc
+++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc
@@ -42,7 +42,7 @@ static void jwt_reset_cache(grpc_service_account_jwt_access_credentials* c) {
static void jwt_destruct(grpc_call_credentials* creds) {
grpc_service_account_jwt_access_credentials* c =
- (grpc_service_account_jwt_access_credentials*)creds;
+ reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
grpc_auth_json_key_destruct(&c->key);
jwt_reset_cache(c);
gpr_mu_destroy(&c->cache_mu);
@@ -55,7 +55,7 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds,
grpc_closure* on_request_metadata,
grpc_error** error) {
grpc_service_account_jwt_access_credentials* c =
- (grpc_service_account_jwt_access_credentials*)creds;
+ reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
gpr_timespec refresh_threshold = gpr_time_from_seconds(
GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN);
@@ -123,8 +123,8 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
return nullptr;
}
- c = (grpc_service_account_jwt_access_credentials*)gpr_zalloc(
- sizeof(grpc_service_account_jwt_access_credentials));
+ c = static_cast<grpc_service_account_jwt_access_credentials*>(gpr_zalloc(
+ sizeof(grpc_service_account_jwt_access_credentials)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_JWT;
gpr_ref_init(&c->base.refcount, 1);
c->base.vtable = &jwt_vtable;
@@ -133,7 +133,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
if (gpr_time_cmp(token_lifetime, max_token_lifetime) > 0) {
gpr_log(GPR_INFO,
"Cropping token lifetime to maximum allowed value (%d secs).",
- (int)max_token_lifetime.tv_sec);
+ static_cast<int>(max_token_lifetime.tv_sec));
token_lifetime = grpc_max_auth_token_lifetime();
}
c->jwt_lifetime = token_lifetime;
@@ -154,7 +154,7 @@ static char* redact_private_key(const char* json_key) {
while (current) {
if (current->type == GRPC_JSON_STRING &&
strcmp(current->key, "private_key") == 0) {
- current->value = (char*)redacted;
+ current->value = const_cast<char*>(redacted);
break;
}
current = current->next;
@@ -177,7 +177,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create(
", tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
clean_json, token_lifetime.tv_sec, token_lifetime.tv_nsec,
- (int)token_lifetime.clock_type, reserved);
+ static_cast<int>(token_lifetime.clock_type), reserved);
gpr_free(clean_json);
}
GPR_ASSERT(reserved == nullptr);
diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc
index 8b22307944..3d7541f4c9 100644
--- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc
+++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc
@@ -82,7 +82,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len,
gpr_log(GPR_ERROR, "Invalid base64.");
return nullptr;
}
- json = grpc_json_parse_string_with_len((char*)GRPC_SLICE_START_PTR(*buffer),
+ json = grpc_json_parse_string_with_len(reinterpret_cast<char*>GRPC_SLICE_START_PTR(*buffer),
GRPC_SLICE_LENGTH(*buffer));
if (json == nullptr) {
grpc_slice_unref_internal(*buffer);
@@ -129,7 +129,7 @@ static void jose_header_destroy(jose_header* h) {
/* Takes ownership of json and buffer. */
static jose_header* jose_header_from_json(grpc_json* json, grpc_slice buffer) {
grpc_json* cur;
- jose_header* h = (jose_header*)gpr_zalloc(sizeof(jose_header));
+ jose_header* h = static_cast<jose_header*>(gpr_zalloc(sizeof(jose_header)));
h->buffer = buffer;
for (cur = json->child; cur != nullptr; cur = cur->next) {
if (strcmp(cur->key, "alg") == 0) {
@@ -231,7 +231,7 @@ gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) {
grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer) {
grpc_json* cur;
grpc_jwt_claims* claims =
- (grpc_jwt_claims*)gpr_malloc(sizeof(grpc_jwt_claims));
+ static_cast<grpc_jwt_claims*>(gpr_malloc(sizeof(grpc_jwt_claims)));
memset(claims, 0, sizeof(grpc_jwt_claims));
claims->json = json;
claims->buffer = buffer;
@@ -347,7 +347,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create(
const char* signed_jwt, size_t signed_jwt_len, void* user_data,
grpc_jwt_verification_done_cb cb) {
grpc_core::ExecCtx exec_ctx;
- verifier_cb_ctx* ctx = (verifier_cb_ctx*)gpr_zalloc(sizeof(verifier_cb_ctx));
+ verifier_cb_ctx* ctx = static_cast<verifier_cb_ctx*>(gpr_zalloc(sizeof(verifier_cb_ctx)));
ctx->verifier = verifier;
ctx->pollent = grpc_polling_entity_create_from_pollset(pollset);
ctx->header = header;
@@ -429,7 +429,7 @@ static EVP_PKEY* extract_pkey_from_x509(const char* x509_str) {
BIO* bio = BIO_new(BIO_s_mem());
size_t len = strlen(x509_str);
GPR_ASSERT(len < INT_MAX);
- BIO_write(bio, x509_str, (int)len);
+ BIO_write(bio, x509_str, static_cast<int>(len));
x509 = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr);
if (x509 == nullptr) {
gpr_log(GPR_ERROR, "Unable to parse x509 cert.");
@@ -625,7 +625,7 @@ end:
}
static void on_keys_retrieved(void* user_data, grpc_error* error) {
- verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data;
+ verifier_cb_ctx* ctx = static_cast<verifier_cb_ctx*>(user_data);
grpc_json* json = json_from_http(&ctx->responses[HTTP_RESPONSE_KEYS]);
EVP_PKEY* verification_key = nullptr;
grpc_jwt_verifier_status status = GRPC_JWT_VERIFIER_GENERIC_ERROR;
@@ -666,7 +666,7 @@ end:
static void on_openid_config_retrieved(void* user_data, grpc_error* error) {
const grpc_json* cur;
- verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data;
+ verifier_cb_ctx* ctx = static_cast<verifier_cb_ctx*>(user_data);
const grpc_http_response* response = &ctx->responses[HTTP_RESPONSE_OPENID];
grpc_json* json = json_from_http(response);
grpc_httpcli_request req;
@@ -689,7 +689,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) {
jwks_uri += 8;
req.handshaker = &grpc_httpcli_ssl;
req.host = gpr_strdup(jwks_uri);
- req.http.path = (char*)strchr(jwks_uri, '/');
+ req.http.path = const_cast<char*>(strchr(jwks_uri, '/'));
if (req.http.path == nullptr) {
req.http.path = (char*)"";
} else {
@@ -754,8 +754,8 @@ const char* grpc_jwt_issuer_email_domain(const char* issuer) {
if (dot == nullptr || dot == email_domain) return email_domain;
GPR_ASSERT(dot > email_domain);
/* There may be a subdomain, we just want the domain. */
- dot = (const char*)gpr_memrchr((void*)email_domain, '.',
- (size_t)(dot - email_domain));
+ dot = static_cast<const char*>(gpr_memrchr((void*)email_domain, '.',
+ static_cast<size_t>(dot - email_domain)));
if (dot == nullptr) return email_domain;
return dot + 1;
}
@@ -861,7 +861,7 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier,
cb != nullptr);
dot = strchr(cur, '.');
if (dot == nullptr) goto error;
- json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &header_buffer);
+ json = parse_json_part_from_jwt(cur, static_cast<size_t>(dot - cur), &header_buffer);
if (json == nullptr) goto error;
header = jose_header_from_json(json, header_buffer);
if (header == nullptr) goto error;
@@ -869,12 +869,12 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier,
cur = dot + 1;
dot = strchr(cur, '.');
if (dot == nullptr) goto error;
- json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &claims_buffer);
+ json = parse_json_part_from_jwt(cur, static_cast<size_t>(dot - cur), &claims_buffer);
if (json == nullptr) goto error;
claims = grpc_jwt_claims_from_json(json, claims_buffer);
if (claims == nullptr) goto error;
- signed_jwt_len = (size_t)(dot - jwt);
+ signed_jwt_len = static_cast<size_t>(dot - jwt);
cur = dot + 1;
signature = grpc_base64_decode(cur, 1);
if (GRPC_SLICE_IS_EMPTY(signature)) goto error;
@@ -893,13 +893,13 @@ grpc_jwt_verifier* grpc_jwt_verifier_create(
const grpc_jwt_verifier_email_domain_key_url_mapping* mappings,
size_t num_mappings) {
grpc_jwt_verifier* v =
- (grpc_jwt_verifier*)gpr_zalloc(sizeof(grpc_jwt_verifier));
+ static_cast<grpc_jwt_verifier*>(gpr_zalloc(sizeof(grpc_jwt_verifier)));
grpc_httpcli_context_init(&v->http_ctx);
/* We know at least of one mapping. */
v->allocated_mappings = 1 + num_mappings;
- v->mappings = (email_key_mapping*)gpr_malloc(v->allocated_mappings *
- sizeof(email_key_mapping));
+ v->mappings = static_cast<email_key_mapping*>(gpr_malloc(v->allocated_mappings *
+ sizeof(email_key_mapping)));
verifier_put_mapping(v, GRPC_GOOGLE_SERVICE_ACCOUNTS_EMAIL_DOMAIN,
GRPC_GOOGLE_SERVICE_ACCOUNTS_KEY_URL_PREFIX);
/* User-Provided mappings. */
diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
index e243ea52c6..b4fb9a43e7 100644
--- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
+++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
@@ -105,7 +105,7 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) {
static void oauth2_token_fetcher_destruct(grpc_call_credentials* creds) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
GRPC_MDELEM_UNREF(c->access_token_md);
gpr_mu_destroy(&c->mu);
grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&c->pollent));
@@ -128,7 +128,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
}
if (response->body_length > 0) {
- null_terminated_body = (char*)gpr_malloc(response->body_length + 1);
+ null_terminated_body = static_cast<char*>(gpr_malloc(response->body_length + 1));
null_terminated_body[response->body_length] = '\0';
memcpy(null_terminated_body, response->body, response->body_length);
}
@@ -204,9 +204,9 @@ static void on_oauth2_token_fetcher_http_response(void* user_data,
grpc_error* error) {
GRPC_LOG_IF_ERROR("oauth_fetch", GRPC_ERROR_REF(error));
grpc_credentials_metadata_request* r =
- (grpc_credentials_metadata_request*)user_data;
+ static_cast<grpc_credentials_metadata_request*>(user_data);
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)r->creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(r->creds);
grpc_mdelem access_token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_credentials_status status =
@@ -249,7 +249,7 @@ static bool oauth2_token_fetcher_get_request_metadata(
grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata, grpc_error** error) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
// Check if we can use the cached token.
grpc_millis refresh_threshold =
GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS * GPR_MS_PER_SEC;
@@ -269,8 +269,8 @@ static bool oauth2_token_fetcher_get_request_metadata(
// Couldn't get the token from the cache.
// Add request to c->pending_requests and start a new fetch if needed.
grpc_oauth2_pending_get_request_metadata* pending_request =
- (grpc_oauth2_pending_get_request_metadata*)gpr_malloc(
- sizeof(*pending_request));
+ static_cast<grpc_oauth2_pending_get_request_metadata*>(gpr_malloc(
+ sizeof(*pending_request)));
pending_request->md_array = md_array;
pending_request->on_request_metadata = on_request_metadata;
pending_request->pollent = pollent;
@@ -298,7 +298,7 @@ static void oauth2_token_fetcher_cancel_get_request_metadata(
grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
grpc_error* error) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
gpr_mu_lock(&c->mu);
grpc_oauth2_pending_get_request_metadata* prev = nullptr;
grpc_oauth2_pending_get_request_metadata* pending_request =
@@ -371,8 +371,8 @@ static void compute_engine_fetch_oauth2(
grpc_call_credentials* grpc_google_compute_engine_credentials_create(
void* reserved) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)gpr_malloc(
- sizeof(grpc_oauth2_token_fetcher_credentials));
+ static_cast<grpc_oauth2_token_fetcher_credentials*>(gpr_malloc(
+ sizeof(grpc_oauth2_token_fetcher_credentials)));
GRPC_API_TRACE("grpc_compute_engine_credentials_create(reserved=%p)", 1,
(reserved));
GPR_ASSERT(reserved == nullptr);
@@ -387,7 +387,7 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create(
static void refresh_token_destruct(grpc_call_credentials* creds) {
grpc_google_refresh_token_credentials* c =
- (grpc_google_refresh_token_credentials*)creds;
+ reinterpret_cast<grpc_google_refresh_token_credentials*>(creds);
grpc_auth_refresh_token_destruct(&c->refresh_token);
oauth2_token_fetcher_destruct(&c->base.base);
}
@@ -401,7 +401,7 @@ static void refresh_token_fetch_oauth2(
grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent,
grpc_iomgr_cb_func response_cb, grpc_millis deadline) {
grpc_google_refresh_token_credentials* c =
- (grpc_google_refresh_token_credentials*)metadata_req->creds;
+ reinterpret_cast<grpc_google_refresh_token_credentials*>(metadata_req->creds);
grpc_http_header header = {(char*)"Content-Type",
(char*)"application/x-www-form-urlencoded"};
grpc_httpcli_request request;
@@ -437,8 +437,8 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token(
gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation");
return nullptr;
}
- c = (grpc_google_refresh_token_credentials*)gpr_zalloc(
- sizeof(grpc_google_refresh_token_credentials));
+ c = static_cast<grpc_google_refresh_token_credentials*>(gpr_zalloc(
+ sizeof(grpc_google_refresh_token_credentials)));
init_oauth2_token_fetcher(&c->base, refresh_token_fetch_oauth2);
c->base.base.vtable = &refresh_token_vtable;
c->refresh_token = refresh_token;
@@ -478,7 +478,7 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create(
//
static void access_token_destruct(grpc_call_credentials* creds) {
- grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds;
+ grpc_access_token_credentials* c = reinterpret_cast<grpc_access_token_credentials*>(creds);
GRPC_MDELEM_UNREF(c->access_token_md);
}
@@ -486,7 +486,7 @@ static bool access_token_get_request_metadata(
grpc_call_credentials* creds, grpc_polling_entity* pollent,
grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata, grpc_error** error) {
- grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds;
+ grpc_access_token_credentials* c = reinterpret_cast<grpc_access_token_credentials*>(creds);
grpc_credentials_mdelem_array_add(md_array, c->access_token_md);
return true;
}
@@ -503,8 +503,8 @@ static grpc_call_credentials_vtable access_token_vtable = {
grpc_call_credentials* grpc_access_token_credentials_create(
const char* access_token, void* reserved) {
- grpc_access_token_credentials* c = (grpc_access_token_credentials*)gpr_zalloc(
- sizeof(grpc_access_token_credentials));
+ grpc_access_token_credentials* c = static_cast<grpc_access_token_credentials*>(gpr_zalloc(
+ sizeof(grpc_access_token_credentials)));
GRPC_API_TRACE(
"grpc_access_token_credentials_create(access_token=<redacted>, "
"reserved=%p)",
diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc
index 203ba58c67..89f94f9e6d 100644
--- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc
+++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc
@@ -34,7 +34,7 @@
grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials");
static void plugin_destruct(grpc_call_credentials* creds) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds;
+ grpc_plugin_credentials* c = reinterpret_cast<grpc_plugin_credentials*>(creds);
gpr_mu_destroy(&c->mu);
if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) {
c->plugin.destroy(c->plugin.state);
@@ -118,7 +118,7 @@ static void plugin_md_request_metadata_ready(void* request,
grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED |
GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP);
grpc_plugin_credentials_pending_request* r =
- (grpc_plugin_credentials_pending_request*)request;
+ static_cast<grpc_plugin_credentials_pending_request*>(request);
if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned "
@@ -147,13 +147,13 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata,
grpc_error** error) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds;
+ grpc_plugin_credentials* c = reinterpret_cast<grpc_plugin_credentials*>(creds);
bool retval = true; // Synchronous return.
if (c->plugin.get_metadata != nullptr) {
// Create pending_request object.
grpc_plugin_credentials_pending_request* pending_request =
- (grpc_plugin_credentials_pending_request*)gpr_zalloc(
- sizeof(*pending_request));
+ static_cast<grpc_plugin_credentials_pending_request*>(gpr_zalloc(
+ sizeof(*pending_request)));
pending_request->creds = c;
pending_request->md_array = md_array;
pending_request->on_request_metadata = on_request_metadata;
@@ -225,7 +225,7 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
static void plugin_cancel_get_request_metadata(
grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
grpc_error* error) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds;
+ grpc_plugin_credentials* c = reinterpret_cast<grpc_plugin_credentials*>(creds);
gpr_mu_lock(&c->mu);
for (grpc_plugin_credentials_pending_request* pending_request =
c->pending_requests;
@@ -252,7 +252,7 @@ static grpc_call_credentials_vtable plugin_vtable = {
grpc_call_credentials* grpc_metadata_credentials_create_from_plugin(
grpc_metadata_credentials_plugin plugin, void* reserved) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)gpr_zalloc(sizeof(*c));
+ grpc_plugin_credentials* c = static_cast<grpc_plugin_credentials*>(gpr_zalloc(sizeof(*c)));
GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1,
(reserved));
GPR_ASSERT(reserved == nullptr);
diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc
index d8546441c9..4237039274 100644
--- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc
+++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc
@@ -42,7 +42,7 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp,
}
static void ssl_destruct(grpc_channel_credentials* creds) {
- grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds;
+ grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
gpr_free(c->config.pem_root_certs);
grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pair, 1);
}
@@ -51,7 +51,7 @@ static grpc_security_status ssl_create_security_connector(
grpc_channel_credentials* creds, grpc_call_credentials* call_creds,
const char* target, const grpc_channel_args* args,
grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
- grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds;
+ grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
grpc_security_status status = GRPC_SECURITY_OK;
const char* overridden_target_name = nullptr;
for (size_t i = 0; args && i < args->num_args; i++) {
@@ -85,8 +85,8 @@ static void ssl_build_config(const char* pem_root_certs,
if (pem_key_cert_pair != nullptr) {
GPR_ASSERT(pem_key_cert_pair->private_key != nullptr);
GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr);
- config->pem_key_cert_pair = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc(
- sizeof(tsi_ssl_pem_key_cert_pair));
+ config->pem_key_cert_pair = static_cast<tsi_ssl_pem_key_cert_pair*>(gpr_zalloc(
+ sizeof(tsi_ssl_pem_key_cert_pair)));
config->pem_key_cert_pair->cert_chain =
gpr_strdup(pem_key_cert_pair->cert_chain);
config->pem_key_cert_pair->private_key =
@@ -98,7 +98,7 @@ grpc_channel_credentials* grpc_ssl_credentials_create(
const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
void* reserved) {
grpc_ssl_credentials* c =
- (grpc_ssl_credentials*)gpr_zalloc(sizeof(grpc_ssl_credentials));
+ static_cast<grpc_ssl_credentials*>(gpr_zalloc(sizeof(grpc_ssl_credentials)));
GRPC_API_TRACE(
"grpc_ssl_credentials_create(pem_root_certs=%s, "
"pem_key_cert_pair=%p, "
@@ -123,7 +123,7 @@ struct grpc_ssl_server_credentials_options {
};
static void ssl_server_destruct(grpc_server_credentials* creds) {
- grpc_ssl_server_credentials* c = (grpc_ssl_server_credentials*)creds;
+ grpc_ssl_server_credentials* c = reinterpret_cast<grpc_ssl_server_credentials*>(creds);
grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pairs,
c->config.num_key_cert_pairs);
gpr_free(c->config.pem_root_certs);
@@ -143,8 +143,8 @@ tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs(
tsi_ssl_pem_key_cert_pair* tsi_pairs = nullptr;
if (num_key_cert_pairs > 0) {
GPR_ASSERT(pem_key_cert_pairs != nullptr);
- tsi_pairs = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc(
- num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair));
+ tsi_pairs = static_cast<tsi_ssl_pem_key_cert_pair*>(gpr_zalloc(
+ num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair)));
}
for (size_t i = 0; i < num_key_cert_pairs; i++) {
GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr);
@@ -174,15 +174,15 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create(
const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs,
size_t num_key_cert_pairs) {
grpc_ssl_server_certificate_config* config =
- (grpc_ssl_server_certificate_config*)gpr_zalloc(
- sizeof(grpc_ssl_server_certificate_config));
+ static_cast<grpc_ssl_server_certificate_config*>(gpr_zalloc(
+ sizeof(grpc_ssl_server_certificate_config)));
if (pem_root_certs != nullptr) {
config->pem_root_certs = gpr_strdup(pem_root_certs);
}
if (num_key_cert_pairs > 0) {
GPR_ASSERT(pem_key_cert_pairs != nullptr);
- config->pem_key_cert_pairs = (grpc_ssl_pem_key_cert_pair*)gpr_zalloc(
- num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair));
+ config->pem_key_cert_pairs = static_cast<grpc_ssl_pem_key_cert_pair*>(gpr_zalloc(
+ num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair)));
}
config->num_key_cert_pairs = num_key_cert_pairs;
for (size_t i = 0; i < num_key_cert_pairs; i++) {
@@ -217,8 +217,8 @@ grpc_ssl_server_credentials_create_options_using_config(
gpr_log(GPR_ERROR, "Certificate config must not be NULL.");
goto done;
}
- options = (grpc_ssl_server_credentials_options*)gpr_zalloc(
- sizeof(grpc_ssl_server_credentials_options));
+ options = static_cast<grpc_ssl_server_credentials_options*>(gpr_zalloc(
+ sizeof(grpc_ssl_server_credentials_options)));
options->client_certificate_request = client_certificate_request;
options->certificate_config = config;
done:
@@ -235,14 +235,14 @@ grpc_ssl_server_credentials_create_options_using_config_fetcher(
}
grpc_ssl_server_certificate_config_fetcher* fetcher =
- (grpc_ssl_server_certificate_config_fetcher*)gpr_zalloc(
- sizeof(grpc_ssl_server_certificate_config_fetcher));
+ static_cast<grpc_ssl_server_certificate_config_fetcher*>(gpr_zalloc(
+ sizeof(grpc_ssl_server_certificate_config_fetcher)));
fetcher->cb = cb;
fetcher->user_data = user_data;
grpc_ssl_server_credentials_options* options =
- (grpc_ssl_server_credentials_options*)gpr_zalloc(
- sizeof(grpc_ssl_server_credentials_options));
+ static_cast<grpc_ssl_server_credentials_options*>(gpr_zalloc(
+ sizeof(grpc_ssl_server_credentials_options)));
options->client_certificate_request = client_certificate_request;
options->certificate_config_fetcher = fetcher;
@@ -307,8 +307,8 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options(
goto done;
}
- c = (grpc_ssl_server_credentials*)gpr_zalloc(
- sizeof(grpc_ssl_server_credentials));
+ c = static_cast<grpc_ssl_server_credentials*>(gpr_zalloc(
+ sizeof(grpc_ssl_server_credentials)));
c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL;
gpr_ref_init(&c->base.refcount, 1);
c->base.vtable = &ssl_server_vtable;
diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc
index 802503c868..b5171acc87 100644
--- a/src/core/lib/security/transport/client_auth_filter.cc
+++ b/src/core/lib/security/transport/client_auth_filter.cc
@@ -70,11 +70,11 @@ struct channel_data {
void grpc_auth_metadata_context_reset(
grpc_auth_metadata_context* auth_md_context) {
if (auth_md_context->service_url != nullptr) {
- gpr_free((char*)auth_md_context->service_url);
+ gpr_free(const_cast<char*>(auth_md_context->service_url));
auth_md_context->service_url = nullptr;
}
if (auth_md_context->method_name != nullptr) {
- gpr_free((char*)auth_md_context->method_name);
+ gpr_free(const_cast<char*>(auth_md_context->method_name));
auth_md_context->method_name = nullptr;
}
GRPC_AUTH_CONTEXT_UNREF(
@@ -93,10 +93,10 @@ static void add_error(grpc_error** combined, grpc_error* error) {
}
static void on_credentials_metadata(void* arg, grpc_error* input_error) {
- grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg;
+ grpc_transport_stream_op_batch* batch = static_cast<grpc_transport_stream_op_batch*>(arg);
grpc_call_element* elem =
- (grpc_call_element*)batch->handler_private.extra_arg;
- call_data* calld = (call_data*)elem->call_data;
+ static_cast<grpc_call_element*>(batch->handler_private.extra_arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_auth_metadata_context_reset(&calld->auth_md_context);
grpc_error* error = GRPC_ERROR_REF(input_error);
if (error == GRPC_ERROR_NONE) {
@@ -159,8 +159,8 @@ void grpc_auth_metadata_context_build(
}
static void cancel_get_request_metadata(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (error != GRPC_ERROR_NONE) {
grpc_call_credentials_cancel_get_request_metadata(
calld->creds, &calld->md_array, GRPC_ERROR_REF(error));
@@ -170,12 +170,12 @@ static void cancel_get_request_metadata(void* arg, grpc_error* error) {
static void send_security_metadata(grpc_call_element* elem,
grpc_transport_stream_op_batch* batch) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_client_security_context* ctx =
- (grpc_client_security_context*)batch->payload
+ static_cast<grpc_client_security_context*>(batch->payload
->context[GRPC_CONTEXT_SECURITY]
- .value;
+ .value);
grpc_call_credentials* channel_call_creds =
chand->security_connector->request_metadata_creds;
int call_creds_has_md = (ctx != nullptr) && (ctx->creds != nullptr);
@@ -231,10 +231,10 @@ static void send_security_metadata(grpc_call_element* elem,
}
static void on_host_checked(void* arg, grpc_error* error) {
- grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg;
+ grpc_transport_stream_op_batch* batch = static_cast<grpc_transport_stream_op_batch*>(arg);
grpc_call_element* elem =
- (grpc_call_element*)batch->handler_private.extra_arg;
- call_data* calld = (call_data*)elem->call_data;
+ static_cast<grpc_call_element*>(batch->handler_private.extra_arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (error == GRPC_ERROR_NONE) {
send_security_metadata(elem, batch);
} else {
@@ -255,9 +255,9 @@ static void on_host_checked(void* arg, grpc_error* error) {
}
static void cancel_check_call_host(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (error != GRPC_ERROR_NONE) {
grpc_channel_security_connector_cancel_check_call_host(
chand->security_connector, &calld->async_result_closure,
@@ -271,8 +271,8 @@ static void auth_start_transport_stream_op_batch(
GPR_TIMER_SCOPE("auth_start_transport_stream_op_batch", 0);
/* grab pointers to our data from the call element */
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (!batch->cancel_stream) {
GPR_ASSERT(batch->payload->context != nullptr);
@@ -283,9 +283,9 @@ static void auth_start_transport_stream_op_batch(
grpc_client_security_context_destroy;
}
grpc_client_security_context* sec_ctx =
- (grpc_client_security_context*)batch->payload
+ static_cast<grpc_client_security_context*>(batch->payload
->context[GRPC_CONTEXT_SECURITY]
- .value;
+ .value);
GRPC_AUTH_CONTEXT_UNREF(sec_ctx->auth_context, "client auth filter");
sec_ctx->auth_context =
GRPC_AUTH_CONTEXT_REF(chand->auth_context, "client_auth_filter");
@@ -346,7 +346,7 @@ static void auth_start_transport_stream_op_batch(
/* Constructor for call_data */
static grpc_error* init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
calld->owning_call = args->call_stack;
calld->call_combiner = args->call_combiner;
return GRPC_ERROR_NONE;
@@ -354,7 +354,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
static void set_pollset_or_pollset_set(grpc_call_element* elem,
grpc_polling_entity* pollent) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
calld->pollent = pollent;
}
@@ -362,7 +362,7 @@ static void set_pollset_or_pollset_set(grpc_call_element* elem,
static void destroy_call_elem(grpc_call_element* elem,
const grpc_call_final_info* final_info,
grpc_closure* ignored) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_credentials_mdelem_array_destroy(&calld->md_array);
grpc_call_credentials_unref(calld->creds);
if (calld->have_host) {
@@ -391,7 +391,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
}
/* grab pointers to our data from the channel element */
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
/* The first and the last filters tend to be implemented differently to
handle the case that there's no 'next' filter to call on the up or down
@@ -400,8 +400,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
/* initialize members */
chand->security_connector =
- (grpc_channel_security_connector*)GRPC_SECURITY_CONNECTOR_REF(
- sc, "client_auth_filter");
+ reinterpret_cast<grpc_channel_security_connector*>(GRPC_SECURITY_CONNECTOR_REF(
+ sc, "client_auth_filter"));
chand->auth_context =
GRPC_AUTH_CONTEXT_REF(auth_context, "client_auth_filter");
return GRPC_ERROR_NONE;
@@ -410,7 +410,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
/* Destructor for channel data */
static void destroy_channel_elem(grpc_channel_element* elem) {
/* grab pointers to our data from the channel element */
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_channel_security_connector* sc = chand->security_connector;
if (sc != nullptr) {
GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "client_auth_filter");
diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc
index 183b1ebf35..84a72731c9 100644
--- a/src/core/lib/security/transport/lb_targets_info.cc
+++ b/src/core/lib/security/transport/lb_targets_info.cc
@@ -26,14 +26,14 @@
#define GRPC_ARG_LB_SECURE_NAMING_MAP "grpc.lb_secure_naming_map"
static void* targets_info_copy(void* p) {
- return grpc_slice_hash_table_ref((grpc_slice_hash_table*)p);
+ return grpc_slice_hash_table_ref(static_cast<grpc_slice_hash_table*>(p));
}
static void targets_info_destroy(void* p) {
- grpc_slice_hash_table_unref((grpc_slice_hash_table*)p);
+ grpc_slice_hash_table_unref(static_cast<grpc_slice_hash_table*>(p));
}
static int targets_info_cmp(void* a, void* b) {
- return grpc_slice_hash_table_cmp((const grpc_slice_hash_table*)a,
- (const grpc_slice_hash_table*)b);
+ return grpc_slice_hash_table_cmp(static_cast<const grpc_slice_hash_table*>(a),
+ static_cast<const grpc_slice_hash_table*>(b));
}
static const grpc_arg_pointer_vtable server_to_balancer_names_vtable = {
targets_info_copy, targets_info_destroy, targets_info_cmp};
@@ -51,7 +51,7 @@ grpc_slice_hash_table* grpc_lb_targets_info_find_in_args(
grpc_channel_args_find(args, GRPC_ARG_LB_SECURE_NAMING_MAP);
if (targets_info_arg != nullptr) {
GPR_ASSERT(targets_info_arg->type == GRPC_ARG_POINTER);
- return (grpc_slice_hash_table*)targets_info_arg->value.pointer.p;
+ return static_cast<grpc_slice_hash_table*>(targets_info_arg->value.pointer.p);
}
return nullptr;
}
diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc
index 9eaa299897..a63dbc07c8 100644
--- a/src/core/lib/security/transport/secure_endpoint.cc
+++ b/src/core/lib/security/transport/secure_endpoint.cc
@@ -144,7 +144,7 @@ static void on_read(void* user_data, grpc_error* error) {
unsigned i;
uint8_t keep_looping = 0;
tsi_result result = TSI_OK;
- secure_endpoint* ep = (secure_endpoint*)user_data;
+ secure_endpoint* ep = static_cast<secure_endpoint*>(user_data);
uint8_t* cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer);
uint8_t* end = GRPC_SLICE_END_PTR(ep->read_staging_buffer);
@@ -168,7 +168,7 @@ static void on_read(void* user_data, grpc_error* error) {
size_t message_size = GRPC_SLICE_LENGTH(encrypted);
while (message_size > 0 || keep_looping) {
- size_t unprotected_buffer_size_written = (size_t)(end - cur);
+ size_t unprotected_buffer_size_written = static_cast<size_t>(end - cur);
size_t processed_message_size = message_size;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_unprotect(
@@ -205,7 +205,7 @@ static void on_read(void* user_data, grpc_error* error) {
ep->read_buffer,
grpc_slice_split_head(
&ep->read_staging_buffer,
- (size_t)(cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer))));
+ static_cast<size_t>(cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer))));
}
}
@@ -226,7 +226,7 @@ static void on_read(void* user_data, grpc_error* error) {
static void endpoint_read(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
grpc_closure* cb) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
ep->read_cb = cb;
ep->read_buffer = slices;
grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer);
@@ -256,7 +256,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
unsigned i;
tsi_result result = TSI_OK;
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
uint8_t* cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer);
uint8_t* end = GRPC_SLICE_END_PTR(ep->write_staging_buffer);
@@ -282,7 +282,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
uint8_t* message_bytes = GRPC_SLICE_START_PTR(plain);
size_t message_size = GRPC_SLICE_LENGTH(plain);
while (message_size > 0) {
- size_t protected_buffer_size_to_send = (size_t)(end - cur);
+ size_t protected_buffer_size_to_send = static_cast<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,
@@ -307,7 +307,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
if (result == TSI_OK) {
size_t still_pending_size;
do {
- size_t protected_buffer_size_to_send = (size_t)(end - cur);
+ size_t protected_buffer_size_to_send = static_cast<size_t>(end - cur);
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_protect_flush(
ep->protector, cur, &protected_buffer_size_to_send,
@@ -324,7 +324,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
&ep->output_buffer,
grpc_slice_split_head(
&ep->write_staging_buffer,
- (size_t)(cur -
+ static_cast<size_t>(cur -
GRPC_SLICE_START_PTR(ep->write_staging_buffer))));
}
}
@@ -343,46 +343,46 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
}
static void endpoint_shutdown(grpc_endpoint* secure_ep, grpc_error* why) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_shutdown(ep->wrapped_ep, why);
}
static void endpoint_destroy(grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
SECURE_ENDPOINT_UNREF(ep, "destroy");
}
static void endpoint_add_to_pollset(grpc_endpoint* secure_ep,
grpc_pollset* pollset) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_add_to_pollset(ep->wrapped_ep, pollset);
}
static void endpoint_add_to_pollset_set(grpc_endpoint* secure_ep,
grpc_pollset_set* pollset_set) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_add_to_pollset_set(ep->wrapped_ep, pollset_set);
}
static void endpoint_delete_from_pollset_set(grpc_endpoint* secure_ep,
grpc_pollset_set* pollset_set) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_delete_from_pollset_set(ep->wrapped_ep, pollset_set);
}
static char* endpoint_get_peer(grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_peer(ep->wrapped_ep);
}
static int endpoint_get_fd(grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_fd(ep->wrapped_ep);
}
static grpc_resource_user* endpoint_get_resource_user(
grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_resource_user(ep->wrapped_ep);
}
@@ -403,7 +403,7 @@ grpc_endpoint* grpc_secure_endpoint_create(
grpc_endpoint* transport, grpc_slice* leftover_slices,
size_t leftover_nslices) {
size_t i;
- secure_endpoint* ep = (secure_endpoint*)gpr_malloc(sizeof(secure_endpoint));
+ secure_endpoint* ep = static_cast<secure_endpoint*>(gpr_malloc(sizeof(secure_endpoint)));
ep->base.vtable = &vtable;
ep->wrapped_ep = transport;
ep->protector = protector;
diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc
index fd632bdbab..e9a2d23535 100644
--- a/src/core/lib/security/transport/security_connector.cc
+++ b/src/core/lib/security/transport/security_connector.cc
@@ -239,8 +239,8 @@ static void* connector_arg_copy(void* p) {
}
static int connector_cmp(void* a, void* b) {
- return grpc_security_connector_cmp((grpc_security_connector*)a,
- (grpc_security_connector*)b);
+ return grpc_security_connector_cmp(static_cast<grpc_security_connector*>(a),
+ static_cast<grpc_security_connector*>(b));
}
static const grpc_arg_pointer_vtable connector_arg_vtable = {
@@ -258,7 +258,7 @@ grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) {
GRPC_ARG_SECURITY_CONNECTOR);
return nullptr;
}
- return (grpc_security_connector*)arg->value.pointer.p;
+ return static_cast<grpc_security_connector*>(arg->value.pointer.p);
}
grpc_security_connector* grpc_security_connector_find_in_args(
@@ -308,7 +308,7 @@ typedef struct {
static void fake_channel_destroy(grpc_security_connector* sc) {
grpc_fake_channel_security_connector* c =
- (grpc_fake_channel_security_connector*)sc;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
grpc_call_credentials_unref(c->base.request_metadata_creds);
gpr_free(c->target);
gpr_free(c->expected_targets);
@@ -420,7 +420,7 @@ static void fake_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_closure* on_peer_checked) {
fake_check_peer(sc, peer, auth_context, on_peer_checked);
grpc_fake_channel_security_connector* c =
- (grpc_fake_channel_security_connector*)sc;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
fake_secure_name_check(c->target, c->expected_targets, c->is_lb_channel);
}
@@ -433,9 +433,9 @@ static void fake_server_check_peer(grpc_security_connector* sc, tsi_peer peer,
static int fake_channel_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
grpc_fake_channel_security_connector* c1 =
- (grpc_fake_channel_security_connector*)sc1;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc1);
grpc_fake_channel_security_connector* c2 =
- (grpc_fake_channel_security_connector*)sc2;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc2);
int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base);
if (c != 0) return c;
c = strcmp(c1->target, c2->target);
@@ -452,8 +452,8 @@ static int fake_channel_cmp(grpc_security_connector* sc1,
static int fake_server_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
return grpc_server_security_connector_cmp(
- (grpc_server_security_connector*)sc1,
- (grpc_server_security_connector*)sc2);
+ reinterpret_cast<grpc_server_security_connector*>(sc1),
+ reinterpret_cast<grpc_server_security_connector*>(sc2));
}
static bool fake_channel_check_call_host(grpc_channel_security_connector* sc,
@@ -498,7 +498,7 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create(
grpc_call_credentials* request_metadata_creds, const char* target,
const grpc_channel_args* args) {
grpc_fake_channel_security_connector* c =
- (grpc_fake_channel_security_connector*)gpr_zalloc(sizeof(*c));
+ static_cast<grpc_fake_channel_security_connector*>(gpr_zalloc(sizeof(*c)));
gpr_ref_init(&c->base.base.refcount, 1);
c->base.base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
c->base.base.vtable = &fake_channel_vtable;
@@ -518,8 +518,8 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create(
grpc_server_security_connector* grpc_fake_server_security_connector_create(
grpc_server_credentials* server_creds) {
grpc_server_security_connector* c =
- (grpc_server_security_connector*)gpr_zalloc(
- sizeof(grpc_server_security_connector));
+ static_cast<grpc_server_security_connector*>(gpr_zalloc(
+ sizeof(grpc_server_security_connector)));
gpr_ref_init(&c->base.refcount, 1);
c->base.vtable = &fake_server_vtable;
c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
@@ -546,14 +546,14 @@ static bool server_connector_has_cert_config_fetcher(
grpc_ssl_server_security_connector* c) {
GPR_ASSERT(c != nullptr);
grpc_ssl_server_credentials* server_creds =
- (grpc_ssl_server_credentials*)c->base.server_creds;
+ reinterpret_cast<grpc_ssl_server_credentials*>(c->base.server_creds);
GPR_ASSERT(server_creds != nullptr);
return server_creds->certificate_config_fetcher.cb != nullptr;
}
static void ssl_channel_destroy(grpc_security_connector* sc) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
grpc_channel_credentials_unref(c->base.channel_creds);
grpc_call_credentials_unref(c->base.request_metadata_creds);
tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory);
@@ -565,7 +565,7 @@ static void ssl_channel_destroy(grpc_security_connector* sc) {
static void ssl_server_destroy(grpc_security_connector* sc) {
grpc_ssl_server_security_connector* c =
- (grpc_ssl_server_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_server_security_connector*>(sc);
grpc_server_credentials_unref(c->base.server_creds);
tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory);
c->server_handshaker_factory = nullptr;
@@ -575,7 +575,7 @@ static void ssl_server_destroy(grpc_security_connector* sc) {
static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc,
grpc_handshake_manager* handshake_mgr) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
// Instantiate TSI handshaker.
tsi_handshaker* tsi_hs = nullptr;
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
@@ -598,7 +598,7 @@ static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) {
GPR_ASSERT(num_alpn_protocols != nullptr);
*num_alpn_protocols = grpc_chttp2_num_alpn_versions();
const char** alpn_protocol_strings =
- (const char**)gpr_malloc(sizeof(const char*) * (*num_alpn_protocols));
+ static_cast<const char**>(gpr_malloc(sizeof(const char*) * (*num_alpn_protocols)));
for (size_t i = 0; i < *num_alpn_protocols; i++) {
alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i);
}
@@ -627,12 +627,12 @@ static bool try_replace_server_handshaker_factory(
config->pem_key_cert_pairs, config->num_key_cert_pairs);
tsi_ssl_server_handshaker_factory* new_handshaker_factory = nullptr;
grpc_ssl_server_credentials* server_creds =
- (grpc_ssl_server_credentials*)sc->base.server_creds;
+ reinterpret_cast<grpc_ssl_server_credentials*>(sc->base.server_creds);
tsi_result result = tsi_create_ssl_server_handshaker_factory_ex(
cert_pairs, config->num_key_cert_pairs, config->pem_root_certs,
get_tsi_client_certificate_request_type(
server_creds->config.client_certificate_request),
- ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
+ ssl_cipher_suites(), alpn_protocol_strings, static_cast<uint16_t>(num_alpn_protocols),
&new_handshaker_factory);
gpr_free(cert_pairs);
gpr_free((void*)alpn_protocol_strings);
@@ -659,7 +659,7 @@ static bool try_fetch_ssl_server_credentials(
if (!server_connector_has_cert_config_fetcher(sc)) return false;
grpc_ssl_server_credentials* server_creds =
- (grpc_ssl_server_credentials*)sc->base.server_creds;
+ reinterpret_cast<grpc_ssl_server_credentials*>(sc->base.server_creds);
grpc_ssl_certificate_config_reload_status cb_result =
server_creds->certificate_config_fetcher.cb(
server_creds->certificate_config_fetcher.user_data,
@@ -686,7 +686,7 @@ static bool try_fetch_ssl_server_credentials(
static void ssl_server_add_handshakers(grpc_server_security_connector* sc,
grpc_handshake_manager* handshake_mgr) {
grpc_ssl_server_security_connector* c =
- (grpc_ssl_server_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_server_security_connector*>(sc);
// Instantiate TSI handshaker.
try_fetch_ssl_server_credentials(c);
tsi_handshaker* tsi_hs = nullptr;
@@ -788,7 +788,7 @@ static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_auth_context** auth_context,
grpc_closure* on_peer_checked) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
grpc_error* error = ssl_check_peer(sc,
c->overridden_target_name != nullptr
? c->overridden_target_name
@@ -809,9 +809,9 @@ static void ssl_server_check_peer(grpc_security_connector* sc, tsi_peer peer,
static int ssl_channel_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
grpc_ssl_channel_security_connector* c1 =
- (grpc_ssl_channel_security_connector*)sc1;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc1);
grpc_ssl_channel_security_connector* c2 =
- (grpc_ssl_channel_security_connector*)sc2;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc2);
int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base);
if (c != 0) return c;
c = strcmp(c1->target_name, c2->target_name);
@@ -825,15 +825,15 @@ static int ssl_channel_cmp(grpc_security_connector* sc1,
static int ssl_server_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
return grpc_server_security_connector_cmp(
- (grpc_server_security_connector*)sc1,
- (grpc_server_security_connector*)sc2);
+ reinterpret_cast<grpc_server_security_connector*>(sc1),
+ reinterpret_cast<grpc_server_security_connector*>(sc2));
}
static void add_shallow_auth_property_to_peer(tsi_peer* peer,
const grpc_auth_property* prop,
const char* tsi_prop_name) {
tsi_peer_property* tsi_prop = &peer->properties[peer->property_count++];
- tsi_prop->name = (char*)tsi_prop_name;
+ tsi_prop->name = const_cast<char*>(tsi_prop_name);
tsi_prop->value.data = prop->value;
tsi_prop->value.length = prop->value_length;
}
@@ -850,8 +850,8 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context(
while (grpc_auth_property_iterator_next(&it) != nullptr) max_num_props++;
if (max_num_props > 0) {
- peer.properties = (tsi_peer_property*)gpr_malloc(max_num_props *
- sizeof(tsi_peer_property));
+ peer.properties = static_cast<tsi_peer_property*>(gpr_malloc(max_num_props *
+ sizeof(tsi_peer_property)));
it = grpc_auth_context_property_iterator(auth_context);
while ((prop = grpc_auth_property_iterator_next(&it)) != nullptr) {
if (strcmp(prop->name, GRPC_X509_SAN_PROPERTY_NAME) == 0) {
@@ -879,7 +879,7 @@ static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc,
grpc_closure* on_call_host_checked,
grpc_error** error) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
grpc_security_status status = GRPC_SECURITY_ERROR;
tsi_peer peer = tsi_shallow_peer_from_ssl_auth_context(auth_context);
if (ssl_host_matches_name(&peer, host)) status = GRPC_SECURITY_OK;
@@ -963,7 +963,7 @@ const char* grpc_get_default_ssl_roots(void) {
gpr_once_init(&once, init_default_pem_root_certs);
return GRPC_SLICE_IS_EMPTY(default_pem_root_certs)
? nullptr
- : (const char*)GRPC_SLICE_START_PTR(default_pem_root_certs);
+ : reinterpret_cast<const char*>GRPC_SLICE_START_PTR(default_pem_root_certs);
}
grpc_security_status grpc_ssl_channel_security_connector_create(
@@ -994,8 +994,8 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
pem_root_certs = config->pem_root_certs;
}
- c = (grpc_ssl_channel_security_connector*)gpr_zalloc(
- sizeof(grpc_ssl_channel_security_connector));
+ c = static_cast<grpc_ssl_channel_security_connector*>(gpr_zalloc(
+ sizeof(grpc_ssl_channel_security_connector)));
gpr_ref_init(&c->base.base.refcount, 1);
c->base.base.vtable = &ssl_channel_vtable;
@@ -1017,7 +1017,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
config->pem_key_cert_pair->cert_chain != nullptr;
result = tsi_create_ssl_client_handshaker_factory(
has_key_cert_pair ? config->pem_key_cert_pair : nullptr, pem_root_certs,
- ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
+ ssl_cipher_suites(), alpn_protocol_strings, static_cast<uint16_t>(num_alpn_protocols),
&c->client_handshaker_factory);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
@@ -1039,8 +1039,8 @@ static grpc_ssl_server_security_connector*
grpc_ssl_server_security_connector_initialize(
grpc_server_credentials* server_creds) {
grpc_ssl_server_security_connector* c =
- (grpc_ssl_server_security_connector*)gpr_zalloc(
- sizeof(grpc_ssl_server_security_connector));
+ static_cast<grpc_ssl_server_security_connector*>(gpr_zalloc(
+ sizeof(grpc_ssl_server_security_connector)));
gpr_ref_init(&c->base.base.refcount, 1);
c->base.base.url_scheme = GRPC_SSL_URL_SCHEME;
c->base.base.vtable = &ssl_server_vtable;
@@ -1053,7 +1053,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
grpc_server_credentials* gsc, grpc_server_security_connector** sc) {
tsi_result result = TSI_OK;
grpc_ssl_server_credentials* server_credentials =
- (grpc_ssl_server_credentials*)gsc;
+ reinterpret_cast<grpc_ssl_server_credentials*>(gsc);
grpc_security_status retval = GRPC_SECURITY_OK;
GPR_ASSERT(server_credentials != nullptr);
@@ -1078,7 +1078,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
get_tsi_client_certificate_request_type(
server_credentials->config.client_certificate_request),
ssl_cipher_suites(), alpn_protocol_strings,
- (uint16_t)num_alpn_protocols, &c->server_handshaker_factory);
+ static_cast<uint16_t>(num_alpn_protocols), &c->server_handshaker_factory);
gpr_free((void*)alpn_protocol_strings);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc
index 7623fbfd5b..2e7c3570b6 100644
--- a/src/core/lib/security/transport/security_handshaker.cc
+++ b/src/core/lib/security/transport/security_handshaker.cc
@@ -69,7 +69,7 @@ static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) {
size_t bytes_in_read_buffer = h->args->read_buffer->length;
if (h->handshake_buffer_size < bytes_in_read_buffer) {
h->handshake_buffer =
- (uint8_t*)gpr_realloc(h->handshake_buffer, bytes_in_read_buffer);
+ static_cast<uint8_t*>(gpr_realloc(h->handshake_buffer, bytes_in_read_buffer));
h->handshake_buffer_size = bytes_in_read_buffer;
}
size_t offset = 0;
@@ -205,7 +205,7 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) {
}
static void on_peer_checked(void* arg, grpc_error* error) {
- security_handshaker* h = (security_handshaker*)arg;
+ security_handshaker* h = static_cast<security_handshaker*>(arg);
gpr_mu_lock(&h->mu);
on_peer_checked_inner(h, error);
gpr_mu_unlock(&h->mu);
@@ -249,7 +249,7 @@ static grpc_error* on_handshake_next_done_locked(
if (bytes_to_send_size > 0) {
// Send data to peer, if needed.
grpc_slice to_send = grpc_slice_from_copied_buffer(
- (const char*)bytes_to_send, bytes_to_send_size);
+ reinterpret_cast<const char*>(bytes_to_send), bytes_to_send_size);
grpc_slice_buffer_reset_and_unref_internal(&h->outgoing);
grpc_slice_buffer_add(&h->outgoing, to_send);
grpc_endpoint_write(h->args->endpoint, &h->outgoing,
@@ -268,7 +268,7 @@ static grpc_error* on_handshake_next_done_locked(
static void on_handshake_next_done_grpc_wrapper(
tsi_result result, void* user_data, const unsigned char* bytes_to_send,
size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) {
- security_handshaker* h = (security_handshaker*)user_data;
+ security_handshaker* h = static_cast<security_handshaker*>(user_data);
// This callback will be invoked by TSI in a non-grpc thread, so it's
// safe to create our own exec_ctx here.
grpc_core::ExecCtx exec_ctx;
@@ -307,7 +307,7 @@ static grpc_error* do_handshaker_next_locked(
}
static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) {
- security_handshaker* h = (security_handshaker*)arg;
+ security_handshaker* h = static_cast<security_handshaker*>(arg);
gpr_mu_lock(&h->mu);
if (error != GRPC_ERROR_NONE || h->shutdown) {
security_handshake_failed_locked(
@@ -333,7 +333,7 @@ static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) {
}
static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) {
- security_handshaker* h = (security_handshaker*)arg;
+ security_handshaker* h = static_cast<security_handshaker*>(arg);
gpr_mu_lock(&h->mu);
if (error != GRPC_ERROR_NONE || h->shutdown) {
security_handshake_failed_locked(
@@ -364,13 +364,13 @@ static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) {
//
static void security_handshaker_destroy(grpc_handshaker* handshaker) {
- security_handshaker* h = (security_handshaker*)handshaker;
+ security_handshaker* h = reinterpret_cast<security_handshaker*>(handshaker);
security_handshaker_unref(h);
}
static void security_handshaker_shutdown(grpc_handshaker* handshaker,
grpc_error* why) {
- security_handshaker* h = (security_handshaker*)handshaker;
+ security_handshaker* h = reinterpret_cast<security_handshaker*>(handshaker);
gpr_mu_lock(&h->mu);
if (!h->shutdown) {
h->shutdown = true;
@@ -385,7 +385,7 @@ static void security_handshaker_do_handshake(grpc_handshaker* handshaker,
grpc_tcp_server_acceptor* acceptor,
grpc_closure* on_handshake_done,
grpc_handshaker_args* args) {
- security_handshaker* h = (security_handshaker*)handshaker;
+ security_handshaker* h = reinterpret_cast<security_handshaker*>(handshaker);
gpr_mu_lock(&h->mu);
h->args = args;
h->on_handshake_done = on_handshake_done;
@@ -409,14 +409,14 @@ static const grpc_handshaker_vtable security_handshaker_vtable = {
static grpc_handshaker* security_handshaker_create(
tsi_handshaker* handshaker, grpc_security_connector* connector) {
security_handshaker* h =
- (security_handshaker*)gpr_zalloc(sizeof(security_handshaker));
+ static_cast<security_handshaker*>(gpr_zalloc(sizeof(security_handshaker)));
grpc_handshaker_init(&security_handshaker_vtable, &h->base);
h->handshaker = handshaker;
h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake");
gpr_mu_init(&h->mu);
gpr_ref_init(&h->refs, 1);
h->handshake_buffer_size = GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE;
- h->handshake_buffer = (uint8_t*)gpr_malloc(h->handshake_buffer_size);
+ h->handshake_buffer = static_cast<uint8_t*>(gpr_malloc(h->handshake_buffer_size));
GRPC_CLOSURE_INIT(&h->on_handshake_data_sent_to_peer,
on_handshake_data_sent_to_peer, h,
grpc_schedule_on_exec_ctx);
@@ -456,7 +456,7 @@ static const grpc_handshaker_vtable fail_handshaker_vtable = {
fail_handshaker_do_handshake};
static grpc_handshaker* fail_handshaker_create() {
- grpc_handshaker* h = (grpc_handshaker*)gpr_malloc(sizeof(*h));
+ grpc_handshaker* h = static_cast<grpc_handshaker*>(gpr_malloc(sizeof(*h)));
grpc_handshaker_init(&fail_handshaker_vtable, h);
return h;
}
@@ -469,8 +469,8 @@ static void client_handshaker_factory_add_handshakers(
grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args,
grpc_handshake_manager* handshake_mgr) {
grpc_channel_security_connector* security_connector =
- (grpc_channel_security_connector*)grpc_security_connector_find_in_args(
- args);
+ reinterpret_cast<grpc_channel_security_connector*>(grpc_security_connector_find_in_args(
+ args));
grpc_channel_security_connector_add_handshakers(security_connector,
handshake_mgr);
}
@@ -479,8 +479,8 @@ static void server_handshaker_factory_add_handshakers(
grpc_handshaker_factory* hf, const grpc_channel_args* args,
grpc_handshake_manager* handshake_mgr) {
grpc_server_security_connector* security_connector =
- (grpc_server_security_connector*)grpc_security_connector_find_in_args(
- args);
+ reinterpret_cast<grpc_server_security_connector*>(grpc_security_connector_find_in_args(
+ args));
grpc_server_security_connector_add_handshakers(security_connector,
handshake_mgr);
}
diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc
index f82971dc56..409aded650 100644
--- a/src/core/lib/security/transport/server_auth_filter.cc
+++ b/src/core/lib/security/transport/server_auth_filter.cc
@@ -65,8 +65,8 @@ static grpc_metadata_array metadata_batch_to_md_array(
grpc_slice value = GRPC_MDVALUE(md);
if (result.count == result.capacity) {
result.capacity = GPR_MAX(result.capacity + 8, result.capacity * 2);
- result.metadata = (grpc_metadata*)gpr_realloc(
- result.metadata, result.capacity * sizeof(grpc_metadata));
+ result.metadata = static_cast<grpc_metadata*>(gpr_realloc(
+ result.metadata, result.capacity * sizeof(grpc_metadata)));
}
usr_md = &result.metadata[result.count++];
usr_md->key = grpc_slice_ref_internal(key);
@@ -77,8 +77,8 @@ static grpc_metadata_array metadata_batch_to_md_array(
static grpc_filtered_mdelem remove_consumed_md(void* user_data,
grpc_mdelem md) {
- grpc_call_element* elem = (grpc_call_element*)user_data;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(user_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
size_t i;
for (i = 0; i < calld->num_consumed_md; i++) {
const grpc_metadata* consumed_md = &calld->consumed_md[i];
@@ -95,7 +95,7 @@ static void on_md_processing_done_inner(grpc_call_element* elem,
const grpc_metadata* response_md,
size_t num_response_md,
grpc_error* error) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch;
/* TODO(jboeuf): Implement support for response_md. */
if (response_md != nullptr && num_response_md > 0) {
@@ -118,12 +118,12 @@ static void on_md_processing_done(
void* user_data, const grpc_metadata* consumed_md, size_t num_consumed_md,
const grpc_metadata* response_md, size_t num_response_md,
grpc_status_code status, const char* error_details) {
- grpc_call_element* elem = (grpc_call_element*)user_data;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(user_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_core::ExecCtx exec_ctx;
// If the call was not cancelled while we were in flight, process the result.
- if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT,
- (gpr_atm)STATE_DONE)) {
+ if (gpr_atm_full_cas(&calld->state, static_cast<gpr_atm>(STATE_INIT),
+ static_cast<gpr_atm>(STATE_DONE))) {
grpc_error* error = GRPC_ERROR_NONE;
if (status != GRPC_STATUS_OK) {
if (error_details == nullptr) {
@@ -146,12 +146,12 @@ static void on_md_processing_done(
}
static void cancel_call(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
// If the result was not already processed, invoke the callback now.
if (error != GRPC_ERROR_NONE &&
- gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT,
- (gpr_atm)STATE_CANCELLED)) {
+ gpr_atm_full_cas(&calld->state, static_cast<gpr_atm>(STATE_INIT),
+ static_cast<gpr_atm>(STATE_CANCELLED))) {
on_md_processing_done_inner(elem, nullptr, 0, nullptr, 0,
GRPC_ERROR_REF(error));
}
@@ -159,9 +159,9 @@ static void cancel_call(void* arg, grpc_error* error) {
}
static void recv_initial_metadata_ready(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- channel_data* chand = (channel_data*)elem->channel_data;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch;
if (error == GRPC_ERROR_NONE) {
if (chand->creds != nullptr && chand->creds->processor.process != nullptr) {
@@ -187,7 +187,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) {
static void auth_start_transport_stream_op_batch(
grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (batch->recv_initial_metadata) {
// Inject our callback.
calld->recv_initial_metadata_batch = batch;
@@ -202,8 +202,8 @@ static void auth_start_transport_stream_op_batch(
/* Constructor for call_data */
static grpc_error* init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
calld->call_combiner = args->call_combiner;
calld->owning_call = args->call_stack;
GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready,
@@ -234,7 +234,7 @@ static void destroy_call_elem(grpc_call_element* elem,
static grpc_error* init_channel_elem(grpc_channel_element* elem,
grpc_channel_element_args* args) {
GPR_ASSERT(!args->is_last);
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_auth_context* auth_context =
grpc_find_auth_context_in_args(args->channel_args);
GPR_ASSERT(auth_context != nullptr);
@@ -248,7 +248,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
/* Destructor for channel data */
static void destroy_channel_elem(grpc_channel_element* elem) {
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "server_auth_filter");
grpc_server_credentials_unref(chand->creds);
}
diff --git a/src/core/lib/slice/b64.cc b/src/core/lib/slice/b64.cc
index 5c6610c372..1d938be11c 100644
--- a/src/core/lib/slice/b64.cc
+++ b/src/core/lib/slice/b64.cc
@@ -58,7 +58,7 @@ char* grpc_base64_encode(const void* vdata, size_t data_size, int url_safe,
int multiline) {
size_t result_projected_size =
grpc_base64_estimate_encoded_size(data_size, url_safe, multiline);
- char* result = (char*)gpr_malloc(result_projected_size);
+ char* result = static_cast<char*>(gpr_malloc(result_projected_size));
grpc_base64_encode_core(result, vdata, data_size, url_safe, multiline);
return result;
}
@@ -75,7 +75,7 @@ size_t grpc_base64_estimate_encoded_size(size_t data_size, int url_safe,
void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size,
int url_safe, int multiline) {
- const unsigned char* data = (const unsigned char*)vdata;
+ const unsigned char* data = static_cast<const unsigned char*>(vdata);
const char* base64_chars =
url_safe ? base64_url_safe_chars : base64_url_unsafe_chars;
const size_t result_projected_size =
@@ -128,16 +128,16 @@ grpc_slice grpc_base64_decode(const char* b64, int url_safe) {
static void decode_one_char(const unsigned char* codes, unsigned char* result,
size_t* result_offset) {
- uint32_t packed = ((uint32_t)codes[0] << 2) | ((uint32_t)codes[1] >> 4);
- result[(*result_offset)++] = (unsigned char)packed;
+ uint32_t packed = (static_cast<uint32_t>(codes[0]) << 2) | (static_cast<uint32_t>(codes[1]) >> 4);
+ result[(*result_offset)++] = static_cast<unsigned char>(packed);
}
static void decode_two_chars(const unsigned char* codes, unsigned char* result,
size_t* result_offset) {
- uint32_t packed = ((uint32_t)codes[0] << 10) | ((uint32_t)codes[1] << 4) |
- ((uint32_t)codes[2] >> 2);
- result[(*result_offset)++] = (unsigned char)(packed >> 8);
- result[(*result_offset)++] = (unsigned char)(packed);
+ uint32_t packed = (static_cast<uint32_t>(codes[0]) << 10) | (static_cast<uint32_t>(codes[1]) << 4) |
+ (static_cast<uint32_t>(codes[2]) >> 2);
+ result[(*result_offset)++] = static_cast<unsigned char>(packed >> 8);
+ result[(*result_offset)++] = static_cast<unsigned char>(packed);
}
static int decode_group(const unsigned char* codes, size_t num_codes,
@@ -175,11 +175,11 @@ static int decode_group(const unsigned char* codes, size_t num_codes,
decode_two_chars(codes, result, result_offset);
} else {
/* No padding. */
- uint32_t packed = ((uint32_t)codes[0] << 18) | ((uint32_t)codes[1] << 12) |
- ((uint32_t)codes[2] << 6) | codes[3];
- result[(*result_offset)++] = (unsigned char)(packed >> 16);
- result[(*result_offset)++] = (unsigned char)(packed >> 8);
- result[(*result_offset)++] = (unsigned char)(packed);
+ uint32_t packed = (static_cast<uint32_t>(codes[0]) << 18) | (static_cast<uint32_t>(codes[1]) << 12) |
+ (static_cast<uint32_t>(codes[2]) << 6) | codes[3];
+ result[(*result_offset)++] = static_cast<unsigned char>(packed >> 16);
+ result[(*result_offset)++] = static_cast<unsigned char>(packed >> 8);
+ result[(*result_offset)++] = static_cast<unsigned char>(packed);
}
return 1;
}
@@ -193,7 +193,7 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len,
size_t num_codes = 0;
while (b64_len--) {
- unsigned char c = (unsigned char)(*b64++);
+ unsigned char c = static_cast<unsigned char>(*b64++);
signed char code;
if (c >= GPR_ARRAY_SIZE(base64_bytes)) continue;
if (url_safe) {
@@ -214,7 +214,7 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len,
goto fail;
}
} else {
- codes[num_codes++] = (unsigned char)code;
+ codes[num_codes++] = static_cast<unsigned char>(code);
if (num_codes == 4) {
if (!decode_group(codes, num_codes, current, &result_size)) goto fail;
num_codes = 0;
diff --git a/src/core/lib/slice/percent_encoding.cc b/src/core/lib/slice/percent_encoding.cc
index 894e43b191..84fb554454 100644
--- a/src/core/lib/slice/percent_encoding.cc
+++ b/src/core/lib/slice/percent_encoding.cc
@@ -78,9 +78,9 @@ static bool valid_hex(const uint8_t* p, const uint8_t* end) {
}
static uint8_t dehex(uint8_t c) {
- if (c >= '0' && c <= '9') return (uint8_t)(c - '0');
- if (c >= 'A' && c <= 'F') return (uint8_t)(c - 'A' + 10);
- if (c >= 'a' && c <= 'f') return (uint8_t)(c - 'a' + 10);
+ if (c >= '0' && c <= '9') return static_cast<uint8_t>(c - '0');
+ if (c >= 'A' && c <= 'F') return static_cast<uint8_t>(c - 'A' + 10);
+ if (c >= 'a' && c <= 'f') return static_cast<uint8_t>(c - 'a' + 10);
GPR_UNREACHABLE_CODE(return 255);
}
@@ -114,7 +114,7 @@ bool grpc_strict_percent_decode_slice(grpc_slice slice_in,
uint8_t* q = GRPC_SLICE_START_PTR(*slice_out);
while (p != in_end) {
if (*p == '%') {
- *q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2]));
+ *q++ = static_cast<uint8_t>(dehex(p[1]) << 4) | (dehex(p[2]));
p += 3;
} else {
*q++ = *p++;
@@ -155,7 +155,7 @@ grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in) {
if (!valid_hex(p + 1, in_end) || !valid_hex(p + 2, in_end)) {
*q++ = *p++;
} else {
- *q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2]));
+ *q++ = static_cast<uint8_t>(dehex(p[1]) << 4) | (dehex(p[2]));
p += 3;
}
} else {
diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc
index 1eb15290eb..136cce1d1e 100644
--- a/src/core/lib/slice/slice.cc
+++ b/src/core/lib/slice/slice.cc
@@ -27,7 +27,7 @@
#include "src/core/lib/iomgr/exec_ctx.h"
char* grpc_slice_to_c_string(grpc_slice slice) {
- char* out = (char*)gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1);
+ char* out = static_cast<char*>(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1));
memcpy(out, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice));
out[GRPC_SLICE_LENGTH(slice)] = 0;
return out;
@@ -104,12 +104,12 @@ typedef struct new_slice_refcount {
} new_slice_refcount;
static void new_slice_ref(void* p) {
- new_slice_refcount* r = (new_slice_refcount*)p;
+ new_slice_refcount* r = static_cast<new_slice_refcount*>(p);
gpr_ref(&r->refs);
}
static void new_slice_unref(void* p) {
- new_slice_refcount* r = (new_slice_refcount*)p;
+ new_slice_refcount* r = static_cast<new_slice_refcount*>(p);
if (gpr_unref(&r->refs)) {
r->user_destroy(r->user_data);
gpr_free(r);
@@ -125,7 +125,7 @@ grpc_slice grpc_slice_new_with_user_data(void* p, size_t len,
void* user_data) {
grpc_slice slice;
new_slice_refcount* rc =
- (new_slice_refcount*)gpr_malloc(sizeof(new_slice_refcount));
+ static_cast<new_slice_refcount*>(gpr_malloc(sizeof(new_slice_refcount)));
gpr_ref_init(&rc->refs, 1);
rc->rc.vtable = &new_slice_vtable;
rc->rc.sub_refcount = &rc->rc;
@@ -133,7 +133,7 @@ grpc_slice grpc_slice_new_with_user_data(void* p, size_t len,
rc->user_data = user_data;
slice.refcount = &rc->rc;
- slice.data.refcounted.bytes = (uint8_t*)p;
+ slice.data.refcounted.bytes = static_cast<uint8_t*>(p);
slice.data.refcounted.length = len;
return slice;
}
@@ -154,12 +154,12 @@ typedef struct new_with_len_slice_refcount {
} new_with_len_slice_refcount;
static void new_with_len_ref(void* p) {
- new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p;
+ new_with_len_slice_refcount* r = static_cast<new_with_len_slice_refcount*>(p);
gpr_ref(&r->refs);
}
static void new_with_len_unref(void* p) {
- new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p;
+ new_with_len_slice_refcount* r = static_cast<new_with_len_slice_refcount*>(p);
if (gpr_unref(&r->refs)) {
r->user_destroy(r->user_data, r->user_length);
gpr_free(r);
@@ -173,8 +173,8 @@ static const grpc_slice_refcount_vtable new_with_len_vtable = {
grpc_slice grpc_slice_new_with_len(void* p, size_t len,
void (*destroy)(void*, size_t)) {
grpc_slice slice;
- new_with_len_slice_refcount* rc = (new_with_len_slice_refcount*)gpr_malloc(
- sizeof(new_with_len_slice_refcount));
+ new_with_len_slice_refcount* rc = static_cast<new_with_len_slice_refcount*>(gpr_malloc(
+ sizeof(new_with_len_slice_refcount)));
gpr_ref_init(&rc->refs, 1);
rc->rc.vtable = &new_with_len_vtable;
rc->rc.sub_refcount = &rc->rc;
@@ -183,7 +183,7 @@ grpc_slice grpc_slice_new_with_len(void* p, size_t len,
rc->user_length = len;
slice.refcount = &rc->rc;
- slice.data.refcounted.bytes = (uint8_t*)p;
+ slice.data.refcounted.bytes = static_cast<uint8_t*>(p);
slice.data.refcounted.length = len;
return slice;
}
@@ -205,12 +205,12 @@ typedef struct {
} malloc_refcount;
static void malloc_ref(void* p) {
- malloc_refcount* r = (malloc_refcount*)p;
+ malloc_refcount* r = static_cast<malloc_refcount*>(p);
gpr_ref(&r->refs);
}
static void malloc_unref(void* p) {
- malloc_refcount* r = (malloc_refcount*)p;
+ malloc_refcount* r = static_cast<malloc_refcount*>(p);
if (gpr_unref(&r->refs)) {
gpr_free(r);
}
@@ -233,7 +233,7 @@ grpc_slice grpc_slice_malloc_large(size_t length) {
bytes is an array of bytes of the requested length
Both parts are placed in the same allocation returned from gpr_malloc */
malloc_refcount* rc =
- (malloc_refcount*)gpr_malloc(sizeof(malloc_refcount) + length);
+ static_cast<malloc_refcount*>(gpr_malloc(sizeof(malloc_refcount) + length));
/* Initial refcount on rc is 1 - and it's up to the caller to release
this reference. */
@@ -246,7 +246,7 @@ grpc_slice grpc_slice_malloc_large(size_t length) {
/* The slices refcount points back to the allocated block. */
slice.refcount = &rc->base;
/* The data bytes are placed immediately after the refcount struct */
- slice.data.refcounted.bytes = (uint8_t*)(rc + 1);
+ slice.data.refcounted.bytes = reinterpret_cast<uint8_t*>(rc + 1);
/* And the length of the block is set to the requested length */
slice.data.refcounted.length = length;
return slice;
@@ -260,7 +260,7 @@ grpc_slice grpc_slice_malloc(size_t length) {
} else {
/* small slice: just inline the data */
slice.refcount = nullptr;
- slice.data.inlined.length = (uint8_t)length;
+ slice.data.inlined.length = static_cast<uint8_t>(length);
}
return slice;
}
@@ -283,7 +283,7 @@ grpc_slice grpc_slice_sub_no_ref(grpc_slice source, size_t begin, size_t end) {
/* Enforce preconditions */
GPR_ASSERT(source.data.inlined.length >= end);
subset.refcount = nullptr;
- subset.data.inlined.length = (uint8_t)(end - begin);
+ subset.data.inlined.length = static_cast<uint8_t>(end - begin);
memcpy(subset.data.inlined.bytes, source.data.inlined.bytes + begin,
end - begin);
}
@@ -295,7 +295,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) {
if (end - begin <= sizeof(subset.data.inlined.bytes)) {
subset.refcount = nullptr;
- subset.data.inlined.length = (uint8_t)(end - begin);
+ subset.data.inlined.length = static_cast<uint8_t>(end - begin);
memcpy(subset.data.inlined.bytes, GRPC_SLICE_START_PTR(source) + begin,
end - begin);
} else {
@@ -314,10 +314,10 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split,
/* inlined data, copy it out */
GPR_ASSERT(source->data.inlined.length >= split);
tail.refcount = nullptr;
- tail.data.inlined.length = (uint8_t)(source->data.inlined.length - split);
+ tail.data.inlined.length = static_cast<uint8_t>(source->data.inlined.length - split);
memcpy(tail.data.inlined.bytes, source->data.inlined.bytes + split,
tail.data.inlined.length);
- source->data.inlined.length = (uint8_t)split;
+ source->data.inlined.length = static_cast<uint8_t>(split);
} else {
size_t tail_length = source->data.refcounted.length - split;
GPR_ASSERT(source->data.refcounted.length >= split);
@@ -325,7 +325,7 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split,
ref_whom != GRPC_SLICE_REF_TAIL) {
/* Copy out the bytes - it'll be cheaper than refcounting */
tail.refcount = nullptr;
- tail.data.inlined.length = (uint8_t)tail_length;
+ tail.data.inlined.length = static_cast<uint8_t>(tail_length);
memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split,
tail_length);
source->refcount = source->refcount->sub_refcount;
@@ -368,17 +368,17 @@ grpc_slice grpc_slice_split_head(grpc_slice* source, size_t split) {
GPR_ASSERT(source->data.inlined.length >= split);
head.refcount = nullptr;
- head.data.inlined.length = (uint8_t)split;
+ head.data.inlined.length = static_cast<uint8_t>(split);
memcpy(head.data.inlined.bytes, source->data.inlined.bytes, split);
source->data.inlined.length =
- (uint8_t)(source->data.inlined.length - split);
+ static_cast<uint8_t>(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 = nullptr;
- head.data.inlined.length = (uint8_t)split;
+ head.data.inlined.length = static_cast<uint8_t>(split);
memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split);
source->refcount = source->refcount->sub_refcount;
source->data.refcounted.bytes += split;
@@ -416,7 +416,7 @@ int grpc_slice_eq(grpc_slice a, grpc_slice b) {
}
int grpc_slice_cmp(grpc_slice a, grpc_slice b) {
- int d = (int)(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b));
+ int d = static_cast<int>(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b));
if (d != 0) return d;
return memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b),
GRPC_SLICE_LENGTH(a));
@@ -424,7 +424,7 @@ int grpc_slice_cmp(grpc_slice a, grpc_slice b) {
int grpc_slice_str_cmp(grpc_slice a, const char* b) {
size_t b_length = strlen(b);
- int d = (int)(GRPC_SLICE_LENGTH(a) - b_length);
+ int d = static_cast<int>(GRPC_SLICE_LENGTH(a) - b_length);
if (d != 0) return d;
return memcmp(GRPC_SLICE_START_PTR(a), b, b_length);
}
@@ -443,17 +443,17 @@ int grpc_slice_buf_start_eq(grpc_slice a, const void* b, size_t len) {
}
int grpc_slice_rchr(grpc_slice s, char c) {
- const char* b = (const char*)GRPC_SLICE_START_PTR(s);
+ const char* b = reinterpret_cast<const char*>GRPC_SLICE_START_PTR(s);
int i;
- for (i = (int)GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--)
+ for (i = static_cast<int>GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--)
;
return i;
}
int grpc_slice_chr(grpc_slice s, char c) {
- const char* b = (const char*)GRPC_SLICE_START_PTR(s);
- const char* p = (const char*)memchr(b, c, GRPC_SLICE_LENGTH(s));
- return p == nullptr ? -1 : (int)(p - b);
+ const char* b = reinterpret_cast<const char*>GRPC_SLICE_START_PTR(s);
+ const char* p = static_cast<const char*>(memchr(b, c, GRPC_SLICE_LENGTH(s)));
+ return p == nullptr ? -1 : static_cast<int>(p - b);
}
int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) {
@@ -466,12 +466,12 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) {
if (haystack_len < needle_len) return -1;
if (haystack_len == needle_len)
return grpc_slice_eq(haystack, needle) ? 0 : -1;
- if (needle_len == 1) return grpc_slice_chr(haystack, (char)*needle_bytes);
+ if (needle_len == 1) return grpc_slice_chr(haystack, static_cast<char>(*needle_bytes));
const uint8_t* last = haystack_bytes + haystack_len - needle_len;
for (const uint8_t* cur = haystack_bytes; cur != last; ++cur) {
if (0 == memcmp(cur, needle_bytes, needle_len)) {
- return (int)(cur - haystack_bytes);
+ return static_cast<int>(cur - haystack_bytes);
}
}
return -1;
diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc
index 178c7f9e94..84a2b5f6d9 100644
--- a/src/core/lib/slice/slice_buffer.cc
+++ b/src/core/lib/slice/slice_buffer.cc
@@ -32,7 +32,7 @@
static void maybe_embiggen(grpc_slice_buffer* sb) {
/* How far away from sb->base_slices is sb->slices pointer */
- size_t slice_offset = (size_t)(sb->slices - sb->base_slices);
+ size_t slice_offset = static_cast<size_t>(sb->slices - sb->base_slices);
size_t slice_count = sb->count + slice_offset;
if (slice_count == sb->capacity) {
@@ -46,11 +46,11 @@ static void maybe_embiggen(grpc_slice_buffer* sb) {
GPR_ASSERT(sb->capacity > slice_count);
if (sb->base_slices == sb->inlined) {
sb->base_slices =
- (grpc_slice*)gpr_malloc(sb->capacity * sizeof(grpc_slice));
+ static_cast<grpc_slice*>(gpr_malloc(sb->capacity * sizeof(grpc_slice)));
memcpy(sb->base_slices, sb->inlined, slice_count * sizeof(grpc_slice));
} else {
- sb->base_slices = (grpc_slice*)gpr_realloc(
- sb->base_slices, sb->capacity * sizeof(grpc_slice));
+ sb->base_slices = static_cast<grpc_slice*>(gpr_realloc(
+ sb->base_slices, sb->capacity * sizeof(grpc_slice)));
}
sb->slices = sb->base_slices + slice_offset;
@@ -89,7 +89,7 @@ uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t 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 = (uint8_t)(back->data.inlined.length + n);
+ back->data.inlined.length = static_cast<uint8_t>(back->data.inlined.length + n);
return out;
add_new:
@@ -97,7 +97,7 @@ add_new:
back = &sb->slices[sb->count];
sb->count++;
back->refcount = nullptr;
- back->data.inlined.length = (uint8_t)n;
+ back->data.inlined.length = static_cast<uint8_t>(n);
return back->data.inlined.bytes;
}
@@ -126,7 +126,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) {
memcpy(back->data.inlined.bytes + back->data.inlined.length,
s.data.inlined.bytes, s.data.inlined.length);
back->data.inlined.length =
- (uint8_t)(back->data.inlined.length + s.data.inlined.length);
+ static_cast<uint8_t>(back->data.inlined.length + s.data.inlined.length);
} else {
size_t cp1 = GRPC_SLICE_INLINED_SIZE - back->data.inlined.length;
memcpy(back->data.inlined.bytes + back->data.inlined.length,
@@ -136,7 +136,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) {
back = &sb->slices[n];
sb->count = n + 1;
back->refcount = nullptr;
- back->data.inlined.length = (uint8_t)(s.data.inlined.length - cp1);
+ back->data.inlined.length = static_cast<uint8_t>(s.data.inlined.length - cp1);
memcpy(back->data.inlined.bytes, s.data.inlined.bytes + cp1,
s.data.inlined.length - cp1);
}
@@ -177,8 +177,8 @@ void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) {
}
void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) {
- size_t a_offset = (size_t)(a->slices - a->base_slices);
- size_t b_offset = (size_t)(b->slices - b->base_slices);
+ size_t a_offset = static_cast<size_t>(a->slices - a->base_slices);
+ size_t b_offset = static_cast<size_t>(b->slices - b->base_slices);
size_t a_count = a->count + a_offset;
size_t b_count = b->count + b_offset;
@@ -287,7 +287,7 @@ void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n,
void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n,
void* dst) {
- char* dstp = (char*)dst;
+ char* dstp = static_cast<char*>(dst);
GPR_ASSERT(src->length >= n);
while (n > 0) {
diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc
index 89340eff84..1818b126ca 100644
--- a/src/core/lib/slice/slice_hash_table.cc
+++ b/src/core/lib/slice/slice_hash_table.cc
@@ -60,14 +60,14 @@ grpc_slice_hash_table* grpc_slice_hash_table_create(
size_t num_entries, grpc_slice_hash_table_entry* entries,
void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)) {
grpc_slice_hash_table* table =
- (grpc_slice_hash_table*)gpr_zalloc(sizeof(*table));
+ static_cast<grpc_slice_hash_table*>(gpr_zalloc(sizeof(*table)));
gpr_ref_init(&table->refs, 1);
table->destroy_value = destroy_value;
table->value_cmp = value_cmp;
// Keep load factor low to improve performance of lookups.
table->size = num_entries * 2;
const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size;
- table->entries = (grpc_slice_hash_table_entry*)gpr_zalloc(entry_size);
+ table->entries = static_cast<grpc_slice_hash_table_entry*>(gpr_zalloc(entry_size));
for (size_t i = 0; i < num_entries; ++i) {
grpc_slice_hash_table_entry* entry = &entries[i];
grpc_slice_hash_table_add(table, entry->key, entry->value);
diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc
index cf471f30f8..f4aad73e0f 100644
--- a/src/core/lib/slice/slice_intern.cc
+++ b/src/core/lib/slice/slice_intern.cc
@@ -70,7 +70,7 @@ static uint32_t max_static_metadata_hash_probe;
static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT];
static void interned_slice_ref(void* p) {
- interned_slice_refcount* s = (interned_slice_refcount*)p;
+ interned_slice_refcount* s = static_cast<interned_slice_refcount*>(p);
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0);
}
@@ -91,22 +91,22 @@ static void interned_slice_destroy(interned_slice_refcount* s) {
}
static void interned_slice_unref(void* p) {
- interned_slice_refcount* s = (interned_slice_refcount*)p;
+ interned_slice_refcount* s = static_cast<interned_slice_refcount*>(p);
if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) {
interned_slice_destroy(s);
}
}
static void interned_slice_sub_ref(void* p) {
- interned_slice_ref(((char*)p) - offsetof(interned_slice_refcount, sub));
+ interned_slice_ref((static_cast<char*>(p)) - offsetof(interned_slice_refcount, sub));
}
static void interned_slice_sub_unref(void* p) {
- interned_slice_unref(((char*)p) - offsetof(interned_slice_refcount, sub));
+ interned_slice_unref((static_cast<char*>(p)) - offsetof(interned_slice_refcount, sub));
}
static uint32_t interned_slice_hash(grpc_slice slice) {
- interned_slice_refcount* s = (interned_slice_refcount*)slice.refcount;
+ interned_slice_refcount* s = reinterpret_cast<interned_slice_refcount*>(slice.refcount);
return s->hash;
}
@@ -129,8 +129,8 @@ static void grow_shard(slice_shard* shard) {
interned_slice_refcount** strtab;
interned_slice_refcount *s, *next;
- strtab = (interned_slice_refcount**)gpr_zalloc(
- sizeof(interned_slice_refcount*) * capacity);
+ strtab = static_cast<interned_slice_refcount**>(gpr_zalloc(
+ sizeof(interned_slice_refcount*) * capacity));
for (i = 0; i < shard->capacity; i++) {
for (s = shard->strs[i]; s; s = next) {
@@ -148,7 +148,7 @@ static void grow_shard(slice_shard* shard) {
static grpc_slice materialize(interned_slice_refcount* s) {
grpc_slice slice;
slice.refcount = &s->base;
- slice.data.refcounted.bytes = (uint8_t*)(s + 1);
+ slice.data.refcounted.bytes = reinterpret_cast<uint8_t*>(s + 1);
slice.data.refcounted.length = s->length;
return slice;
}
@@ -237,8 +237,8 @@ grpc_slice grpc_slice_intern(grpc_slice slice) {
/* not found: create a new string */
/* string data goes after the internal_string header */
- s = (interned_slice_refcount*)gpr_malloc(sizeof(*s) +
- GRPC_SLICE_LENGTH(slice));
+ s = static_cast<interned_slice_refcount*>(gpr_malloc(sizeof(*s) +
+ GRPC_SLICE_LENGTH(slice)));
gpr_atm_rel_store(&s->refcnt, 1);
s->length = GRPC_SLICE_LENGTH(slice);
s->hash = hash;
@@ -268,15 +268,15 @@ void grpc_test_only_set_slice_hash_seed(uint32_t seed) {
void grpc_slice_intern_init(void) {
if (!g_forced_hash_seed) {
- g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec;
+ g_hash_seed = static_cast<uint32_t>(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
}
for (size_t i = 0; i < SHARD_COUNT; i++) {
slice_shard* shard = &g_shards[i];
gpr_mu_init(&shard->mu);
shard->count = 0;
shard->capacity = INITIAL_SHARD_CAPACITY;
- shard->strs = (interned_slice_refcount**)gpr_zalloc(sizeof(*shard->strs) *
- shard->capacity);
+ shard->strs = static_cast<interned_slice_refcount**>(gpr_zalloc(sizeof(*shard->strs) *
+ shard->capacity));
}
for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) {
static_metadata_hash[i].hash = 0;
@@ -291,9 +291,9 @@ void grpc_slice_intern_init(void) {
GPR_ARRAY_SIZE(static_metadata_hash);
if (static_metadata_hash[slot].idx == GRPC_STATIC_MDSTR_COUNT) {
static_metadata_hash[slot].hash = static_metadata_hash_values[i];
- static_metadata_hash[slot].idx = (uint32_t)i;
+ static_metadata_hash[slot].idx = static_cast<uint32_t>(i);
if (j > max_static_metadata_hash_probe) {
- max_static_metadata_hash_probe = (uint32_t)j;
+ max_static_metadata_hash_probe = static_cast<uint32_t>(j);
}
break;
}
diff --git a/src/core/lib/slice/slice_string_helpers.cc b/src/core/lib/slice/slice_string_helpers.cc
index 4441a26d8e..2015040c12 100644
--- a/src/core/lib/slice/slice_string_helpers.cc
+++ b/src/core/lib/slice/slice_string_helpers.cc
@@ -26,7 +26,7 @@
#include "src/core/lib/slice/slice_internal.h"
char* grpc_dump_slice(grpc_slice s, uint32_t flags) {
- return gpr_dump((const char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s),
+ return gpr_dump(reinterpret_cast<const char*>GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s),
flags);
}
@@ -110,6 +110,6 @@ void grpc_slice_split_without_space(grpc_slice str, const char* sep,
}
bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t* result) {
- return gpr_parse_bytes_to_uint32((const char*)GRPC_SLICE_START_PTR(str),
+ return gpr_parse_bytes_to_uint32(reinterpret_cast<const char*>GRPC_SLICE_START_PTR(str),
GRPC_SLICE_LENGTH(str), result) != 0;
}
diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc
index e4c2a4a4c2..01cbf7354a 100644
--- a/src/core/lib/surface/byte_buffer.cc
+++ b/src/core/lib/surface/byte_buffer.cc
@@ -33,7 +33,7 @@ grpc_byte_buffer* grpc_raw_compressed_byte_buffer_create(
grpc_compression_algorithm compression) {
size_t i;
grpc_byte_buffer* bb =
- (grpc_byte_buffer*)gpr_malloc(sizeof(grpc_byte_buffer));
+ static_cast<grpc_byte_buffer*>(gpr_malloc(sizeof(grpc_byte_buffer)));
bb->type = GRPC_BB_RAW;
bb->data.raw.compression = compression;
grpc_slice_buffer_init(&bb->data.raw.slice_buffer);
@@ -47,7 +47,7 @@ grpc_byte_buffer* grpc_raw_compressed_byte_buffer_create(
grpc_byte_buffer* grpc_raw_byte_buffer_from_reader(
grpc_byte_buffer_reader* reader) {
grpc_byte_buffer* bb =
- (grpc_byte_buffer*)gpr_malloc(sizeof(grpc_byte_buffer));
+ static_cast<grpc_byte_buffer*>(gpr_malloc(sizeof(grpc_byte_buffer)));
grpc_slice slice;
bb->type = GRPC_BB_RAW;
bb->data.raw.compression = GRPC_COMPRESS_NONE;
diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc
index a7b932b46d..d6949103c7 100644
--- a/src/core/lib/surface/call.cc
+++ b/src/core/lib/surface/call.cc
@@ -97,7 +97,7 @@ static received_status unpack_received_status(gpr_atm atm) {
if ((atm & 1) == 0) {
return {false, GRPC_ERROR_NONE};
} else {
- return {true, (grpc_error*)(atm & ~(gpr_atm)1)};
+ return {true, (grpc_error*)(atm & ~static_cast<gpr_atm>(1))};
}
}
@@ -304,7 +304,7 @@ void* grpc_call_arena_alloc(grpc_call* call, size_t size) {
static parent_call* get_or_create_parent_call(grpc_call* call) {
parent_call* p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm);
if (p == nullptr) {
- p = (parent_call*)gpr_arena_alloc(call->arena, sizeof(*p));
+ p = static_cast<parent_call*>(gpr_arena_alloc(call->arena, sizeof(*p)));
gpr_mu_init(&p->child_list_mu);
if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm) nullptr,
(gpr_atm)p)) {
@@ -330,8 +330,8 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
size_t initial_size = grpc_channel_get_call_size_estimate(args->channel);
GRPC_STATS_INC_CALL_INITIAL_SIZE(initial_size);
gpr_arena* arena = gpr_arena_create(initial_size);
- call = (grpc_call*)gpr_arena_alloc(
- arena, sizeof(grpc_call) + channel_stack->call_stack_size);
+ call = static_cast<grpc_call*>(gpr_arena_alloc(
+ arena, sizeof(grpc_call) + channel_stack->call_stack_size));
gpr_ref_init(&call->ext_ref, 1);
call->arena = arena;
grpc_call_combiner_init(&call->call_combiner);
@@ -360,7 +360,7 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
GRPC_MDVALUE(args->add_initial_metadata[i]));
}
}
- call->send_extra_metadata_count = (int)args->add_initial_metadata_count;
+ call->send_extra_metadata_count = static_cast<int>(args->add_initial_metadata_count);
} else {
GPR_ASSERT(args->add_initial_metadata_count == 0);
call->send_extra_metadata_count = 0;
@@ -376,7 +376,7 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
if (args->parent != nullptr) {
child_call* cc = call->child =
- (child_call*)gpr_arena_alloc(arena, sizeof(child_call));
+ static_cast<child_call*>(gpr_arena_alloc(arena, sizeof(child_call)));
call->child->parent = args->parent;
GRPC_CALL_INTERNAL_REF(args->parent, "child");
@@ -500,7 +500,7 @@ void grpc_call_internal_unref(grpc_call* c REF_ARG) {
}
static void release_call(void* call, grpc_error* error) {
- grpc_call* c = (grpc_call*)call;
+ grpc_call* c = static_cast<grpc_call*>(call);
grpc_channel* channel = c->channel;
grpc_call_combiner_destroy(&c->call_combiner);
gpr_free((char*)c->peer_string);
@@ -513,7 +513,7 @@ static void destroy_call(void* call, grpc_error* error) {
GPR_TIMER_SCOPE("destroy_call", 0);
size_t i;
int ii;
- grpc_call* c = (grpc_call*)call;
+ grpc_call* c = static_cast<grpc_call*>(call);
for (i = 0; i < 2; i++) {
grpc_metadata_batch_destroy(
&c->metadata_batch[1 /* is_receiving */][i /* is_initial */]);
@@ -608,8 +608,8 @@ grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) {
// the filter stack.
static void execute_batch_in_call_combiner(void* arg, grpc_error* ignored) {
GPR_TIMER_SCOPE("execute_batch", 0);
- grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg;
- grpc_call* call = (grpc_call*)batch->handler_private.extra_arg;
+ grpc_transport_stream_op_batch* batch = static_cast<grpc_transport_stream_op_batch*>(arg);
+ grpc_call* call = static_cast<grpc_call*>(batch->handler_private.extra_arg);
grpc_call_element* elem = CALL_ELEM_FROM_CALL(call, 0);
GRPC_CALL_LOG_OP(GPR_INFO, elem, batch);
elem->filter->start_transport_stream_op_batch(elem, batch);
@@ -667,7 +667,7 @@ typedef struct {
// The on_complete callback used when sending a cancel_stream batch down
// the filter stack. Yields the call combiner when the batch is done.
static void done_termination(void* arg, grpc_error* error) {
- cancel_state* state = (cancel_state*)arg;
+ cancel_state* state = static_cast<cancel_state*>(arg);
GRPC_CALL_COMBINER_STOP(&state->call->call_combiner,
"on_complete for cancel_stream op");
GRPC_CALL_INTERNAL_UNREF(state->call, "termination");
@@ -683,7 +683,7 @@ static void cancel_with_error(grpc_call* c, status_source source,
// down the filter stack in a timely manner.
grpc_call_combiner_cancel(&c->call_combiner, GRPC_ERROR_REF(error));
set_status_from_error(c, source, GRPC_ERROR_REF(error));
- cancel_state* state = (cancel_state*)gpr_malloc(sizeof(*state));
+ cancel_state* state = static_cast<cancel_state*>(gpr_malloc(sizeof(*state)));
state->call = c;
GRPC_CLOSURE_INIT(&state->finish_batch, done_termination, state,
grpc_schedule_on_exec_ctx);
@@ -845,7 +845,7 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel,
grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer);
if (accepted_user_data != nullptr) {
*encodings_accepted_by_peer =
- (uint32_t)(((uintptr_t)accepted_user_data) - 1);
+ static_cast<uint32_t>(((uintptr_t)accepted_user_data) - 1);
return;
}
@@ -863,11 +863,11 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel,
if (!stream_encoding) {
r = grpc_message_compression_algorithm_parse(
accept_encoding_entry_slice,
- (grpc_message_compression_algorithm*)&algorithm);
+ reinterpret_cast<grpc_message_compression_algorithm*>(&algorithm));
} else {
r = grpc_stream_compression_algorithm_parse(
accept_encoding_entry_slice,
- (grpc_stream_compression_algorithm*)&algorithm);
+ reinterpret_cast<grpc_stream_compression_algorithm*>(&algorithm));
}
if (r) {
GPR_BITSET(encodings_accepted_by_peer, algorithm);
@@ -885,7 +885,7 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel,
grpc_mdelem_set_user_data(
mdel, destroy_encodings_accepted_by_peer,
- (void*)(((uintptr_t)(*encodings_accepted_by_peer)) + 1));
+ (void*)((static_cast<uintptr_t>(*encodings_accepted_by_peer)) + 1));
}
uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call* call) {
@@ -936,7 +936,7 @@ static int prepare_application_metadata(grpc_call* call, int count,
grpc_validate_header_nonbin_value_is_legal(md->value))) {
break;
}
- l->md = grpc_mdelem_from_grpc_metadata((grpc_metadata*)md);
+ l->md = grpc_mdelem_from_grpc_metadata(const_cast<grpc_metadata*>(md));
}
if (i != total_count) {
for (int j = 0; j < i; j++) {
@@ -986,13 +986,13 @@ static uint32_t decode_status(grpc_mdelem md) {
if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_2)) return 2;
user_data = grpc_mdelem_get_user_data(md, destroy_status);
if (user_data != nullptr) {
- status = ((uint32_t)(intptr_t)user_data) - STATUS_OFFSET;
+ status = (static_cast<uint32_t>((intptr_t)user_data)) - STATUS_OFFSET;
} else {
if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(md), &status)) {
status = GRPC_STATUS_UNKNOWN; /* could not parse status code */
}
grpc_mdelem_set_user_data(md, destroy_status,
- (void*)(intptr_t)(status + STATUS_OFFSET));
+ (void*)static_cast<intptr_t>(status + STATUS_OFFSET));
}
return status;
}
@@ -1040,8 +1040,8 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b,
if (dest->count + b->list.count > dest->capacity) {
dest->capacity =
GPR_MAX(dest->capacity + b->list.count, dest->capacity * 3 / 2);
- dest->metadata = (grpc_metadata*)gpr_realloc(
- dest->metadata, sizeof(grpc_metadata) * dest->capacity);
+ dest->metadata = static_cast<grpc_metadata*>(gpr_realloc(
+ dest->metadata, sizeof(grpc_metadata) * dest->capacity));
}
for (grpc_linked_mdelem* l = b->list.head; l != nullptr; l = l->next) {
mdusr = &dest->metadata[dest->count++];
@@ -1086,7 +1086,7 @@ static void recv_initial_filter(grpc_call* call, grpc_metadata_batch* b) {
}
static void recv_trailing_filter(void* args, grpc_metadata_batch* b) {
- grpc_call* call = (grpc_call*)args;
+ grpc_call* call = static_cast<grpc_call*>(args);
if (b->idx.named.grpc_status != nullptr) {
uint32_t status_code = decode_status(b->idx.named.grpc_status->md);
grpc_error* error =
@@ -1095,7 +1095,7 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b) {
: grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Error received from peer"),
GRPC_ERROR_INT_GRPC_STATUS,
- (intptr_t)status_code);
+ static_cast<intptr_t>(status_code));
if (b->idx.named.grpc_message != nullptr) {
error = grpc_error_set_str(
error, GRPC_ERROR_STR_GRPC_MESSAGE,
@@ -1120,11 +1120,11 @@ grpc_call_stack* grpc_call_get_call_stack(grpc_call* call) {
*/
static void set_status_value_directly(grpc_status_code status, void* dest) {
- *(grpc_status_code*)dest = status;
+ *static_cast<grpc_status_code*>(dest) = status;
}
static void set_cancelled_value(grpc_status_code status, void* dest) {
- *(int*)dest = (status != GRPC_STATUS_OK);
+ *static_cast<int*>(dest) = (status != GRPC_STATUS_OK);
}
static bool are_write_flags_valid(uint32_t flags) {
@@ -1171,7 +1171,7 @@ static batch_control* allocate_batch_control(grpc_call* call,
batch_control** pslot = &call->active_batches[slot];
if (*pslot == nullptr) {
*pslot =
- (batch_control*)gpr_arena_alloc(call->arena, sizeof(batch_control));
+ static_cast<batch_control*>(gpr_arena_alloc(call->arena, sizeof(batch_control)));
}
batch_control* bctl = *pslot;
if (bctl->call != nullptr) {
@@ -1185,14 +1185,14 @@ static batch_control* allocate_batch_control(grpc_call* call,
static void finish_batch_completion(void* user_data,
grpc_cq_completion* storage) {
- batch_control* bctl = (batch_control*)user_data;
+ batch_control* bctl = static_cast<batch_control*>(user_data);
grpc_call* call = bctl->call;
bctl->call = nullptr;
GRPC_CALL_INTERNAL_UNREF(call, "completion");
}
static grpc_error* consolidate_batch_errors(batch_control* bctl) {
- size_t n = (size_t)gpr_atm_acq_load(&bctl->num_errors);
+ size_t n = static_cast<size_t>gpr_atm_acq_load(&bctl->num_errors);
if (n == 0) {
return GRPC_ERROR_NONE;
} else if (n == 1) {
@@ -1332,7 +1332,7 @@ static void continue_receiving_slices(batch_control* bctl) {
}
static void receiving_slice_ready(void* bctlp, grpc_error* error) {
- batch_control* bctl = (batch_control*)bctlp;
+ batch_control* bctl = static_cast<batch_control*>(bctlp);
grpc_call* call = bctl->call;
grpc_byte_stream* bs = call->receiving_stream;
bool release_error = false;
@@ -1395,7 +1395,7 @@ static void process_data_after_md(batch_control* bctl) {
}
static void receiving_stream_ready(void* bctlp, grpc_error* error) {
- batch_control* bctl = (batch_control*)bctlp;
+ batch_control* bctl = static_cast<batch_control*>(bctlp);
grpc_call* call = bctl->call;
if (error != GRPC_ERROR_NONE) {
if (call->receiving_stream != nullptr) {
@@ -1419,7 +1419,7 @@ static void receiving_stream_ready(void* bctlp, grpc_error* error) {
// before processing the received message.
static void receiving_stream_ready_in_call_combiner(void* bctlp,
grpc_error* error) {
- batch_control* bctl = (batch_control*)bctlp;
+ batch_control* bctl = static_cast<batch_control*>(bctlp);
grpc_call* call = bctl->call;
GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_message_ready");
receiving_stream_ready(bctlp, error);
@@ -1495,7 +1495,7 @@ static void validate_filtered_metadata(batch_control* bctl) {
static void add_batch_error(batch_control* bctl, grpc_error* error,
bool has_cancelled) {
if (error == GRPC_ERROR_NONE) return;
- int idx = (int)gpr_atm_full_fetch_add(&bctl->num_errors, 1);
+ int idx = static_cast<int>(gpr_atm_full_fetch_add(&bctl->num_errors, 1));
if (idx == 0 && !has_cancelled) {
cancel_with_error(bctl->call, STATUS_FROM_CORE, GRPC_ERROR_REF(error));
}
@@ -1503,7 +1503,7 @@ static void add_batch_error(batch_control* bctl, grpc_error* error,
}
static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) {
- batch_control* bctl = (batch_control*)bctlp;
+ batch_control* bctl = static_cast<batch_control*>(bctlp);
grpc_call* call = bctl->call;
GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_initial_metadata_ready");
@@ -1555,7 +1555,7 @@ static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) {
}
static void finish_batch(void* bctlp, grpc_error* error) {
- batch_control* bctl = (batch_control*)bctlp;
+ batch_control* bctl = static_cast<batch_control*>(bctlp);
grpc_call* call = bctl->call;
GRPC_CALL_COMBINER_STOP(&call->call_combiner, "on_complete");
add_batch_error(bctl, GRPC_ERROR_REF(error), false);
@@ -1586,7 +1586,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag));
grpc_cq_end_op(
call->cq, notify_tag, GRPC_ERROR_NONE, free_no_op_completion, nullptr,
- (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion)));
+ static_cast<grpc_cq_completion*>(gpr_malloc(sizeof(grpc_cq_completion))));
} else {
GRPC_CLOSURE_SCHED((grpc_closure*)notify_tag, GRPC_ERROR_NONE);
}
@@ -1600,7 +1600,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
}
bctl->completion_data.notify_tag.tag = notify_tag;
bctl->completion_data.notify_tag.is_closure =
- (uint8_t)(is_notify_tag_closure != 0);
+ static_cast<uint8_t>(is_notify_tag_closure != 0);
stream_op = &bctl->op;
stream_op_payload = &call->stream_op_payload;
@@ -1660,9 +1660,9 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
stream_op->send_initial_metadata = true;
call->sent_initial_metadata = true;
if (!prepare_application_metadata(
- call, (int)op->data.send_initial_metadata.count,
+ call, static_cast<int>(op->data.send_initial_metadata.count),
op->data.send_initial_metadata.metadata, 0, call->is_client,
- &call->compression_md, (int)additional_metadata_count)) {
+ &call->compression_md, static_cast<int>(additional_metadata_count))) {
error = GRPC_CALL_ERROR_INVALID_METADATA;
goto done_with_error;
}
@@ -1779,7 +1779,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
}
if (!prepare_application_metadata(
call,
- (int)op->data.send_status_from_server.trailing_metadata_count,
+ static_cast<int>(op->data.send_status_from_server.trailing_metadata_count),
op->data.send_status_from_server.trailing_metadata, 1, 1,
nullptr, 0)) {
for (int n = 0; n < call->send_extra_metadata_count; n++) {
diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc
index 679666bc5f..06dbfdcb49 100644
--- a/src/core/lib/surface/channel.cc
+++ b/src/core/lib/surface/channel.cc
@@ -85,7 +85,7 @@ grpc_channel* grpc_channel_create_with_builder(
}
grpc_error* error = grpc_channel_stack_builder_finish(
builder, sizeof(grpc_channel), 1, destroy_channel, nullptr,
- (void**)&channel);
+ reinterpret_cast<void**>(&channel));
if (error != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "channel stack builder failed: %s",
grpc_error_string(error));
@@ -157,7 +157,7 @@ grpc_channel* grpc_channel_create_with_builder(
strcmp(args->args[i].key,
GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET)) {
channel->compression_options.enabled_algorithms_bitset =
- (uint32_t)args->args[i].value.integer |
+ static_cast<uint32_t>(args->args[i].value.integer) |
0x1; /* always support no compression */
}
}
@@ -190,26 +190,26 @@ size_t grpc_channel_get_call_size_estimate(grpc_channel* channel) {
(which is common) - which tends to help most allocators reuse memory
2. a small amount of allowed growth over the estimate without hitting
the arena size doubling case, reducing overall memory usage */
- return ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) +
+ return (static_cast<size_t>gpr_atm_no_barrier_load(&channel->call_size_estimate) +
2 * ROUND_UP_SIZE) &
- ~(size_t)(ROUND_UP_SIZE - 1);
+ ~static_cast<size_t>(ROUND_UP_SIZE - 1);
}
void grpc_channel_update_call_size_estimate(grpc_channel* channel,
size_t size) {
- size_t cur = (size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate);
+ size_t cur = static_cast<size_t>gpr_atm_no_barrier_load(&channel->call_size_estimate);
if (cur < size) {
/* size grew: update estimate */
- gpr_atm_no_barrier_cas(&channel->call_size_estimate, (gpr_atm)cur,
- (gpr_atm)size);
+ gpr_atm_no_barrier_cas(&channel->call_size_estimate, static_cast<gpr_atm>(cur),
+ static_cast<gpr_atm>(size));
/* if we lose: never mind, something else will likely update soon enough */
} else if (cur == size) {
/* no change: holding pattern */
} else if (cur > 0) {
/* size shrank: decrease estimate */
gpr_atm_no_barrier_cas(
- &channel->call_size_estimate, (gpr_atm)cur,
- (gpr_atm)(GPR_MIN(cur - 1, (255 * cur + size) / 256)));
+ &channel->call_size_estimate, static_cast<gpr_atm>(cur),
+ static_cast<gpr_atm>(GPR_MIN(cur - 1, (255 * cur + size) / 256)));
/* if we lose: never mind, something else will likely update soon enough */
}
}
@@ -297,7 +297,7 @@ grpc_call* grpc_channel_create_pollset_set_call(
void* grpc_channel_register_call(grpc_channel* channel, const char* method,
const char* host, void* reserved) {
- registered_call* rc = (registered_call*)gpr_malloc(sizeof(registered_call));
+ registered_call* rc = static_cast<registered_call*>(gpr_malloc(sizeof(registered_call)));
GRPC_API_TRACE(
"grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)",
4, (channel, method, host, reserved));
@@ -324,7 +324,7 @@ grpc_call* grpc_channel_create_registered_call(
grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask,
grpc_completion_queue* completion_queue, void* registered_call_handle,
gpr_timespec deadline, void* reserved) {
- registered_call* rc = (registered_call*)registered_call_handle;
+ registered_call* rc = static_cast<registered_call*>(registered_call_handle);
GRPC_API_TRACE(
"grpc_channel_create_registered_call("
"channel=%p, parent_call=%p, propagation_mask=%x, completion_queue=%p, "
@@ -362,7 +362,7 @@ void grpc_channel_internal_unref(grpc_channel* c REF_ARG) {
}
static void destroy_channel(void* arg, grpc_error* error) {
- grpc_channel* channel = (grpc_channel*)arg;
+ grpc_channel* channel = static_cast<grpc_channel*>(arg);
grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel));
while (channel->registered_calls) {
registered_call* rc = channel->registered_calls;
diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc
index 99690e63b4..6b63195272 100644
--- a/src/core/lib/surface/channel_init.cc
+++ b/src/core/lib/surface/channel_init.cc
@@ -52,9 +52,9 @@ void grpc_channel_init_register_stage(grpc_channel_stack_type type,
GPR_ASSERT(!g_finalized);
if (g_slots[type].cap_slots == g_slots[type].num_slots) {
g_slots[type].cap_slots = GPR_MAX(8, 3 * g_slots[type].cap_slots / 2);
- g_slots[type].slots = (stage_slot*)gpr_realloc(
+ g_slots[type].slots = static_cast<stage_slot*>(gpr_realloc(
g_slots[type].slots,
- g_slots[type].cap_slots * sizeof(*g_slots[type].slots));
+ g_slots[type].cap_slots * sizeof(*g_slots[type].slots)));
}
stage_slot* s = &g_slots[type].slots[g_slots[type].num_slots++];
s->insertion_order = g_slots[type].num_slots;
@@ -64,8 +64,8 @@ void grpc_channel_init_register_stage(grpc_channel_stack_type type,
}
static int compare_slots(const void* a, const void* b) {
- const stage_slot* sa = (const stage_slot*)a;
- const stage_slot* sb = (const stage_slot*)b;
+ const stage_slot* sa = static_cast<const stage_slot*>(a);
+ const stage_slot* sb = static_cast<const stage_slot*>(b);
int c = GPR_ICMP(sa->priority, sb->priority);
if (c != 0) return c;
@@ -84,7 +84,7 @@ void grpc_channel_init_finalize(void) {
void grpc_channel_init_shutdown(void) {
for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) {
gpr_free(g_slots[i].slots);
- g_slots[i].slots = (stage_slot*)(void*)(uintptr_t)0xdeadbeef;
+ g_slots[i].slots = static_cast<stage_slot*>((void*)static_cast<uintptr_t>(0xdeadbeef));
}
}
diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc
index a030d8d0f0..513519d991 100644
--- a/src/core/lib/surface/channel_ping.cc
+++ b/src/core/lib/surface/channel_ping.cc
@@ -38,7 +38,7 @@ static void ping_destroy(void* arg, grpc_cq_completion* storage) {
}
static void ping_done(void* arg, grpc_error* error) {
- ping_result* pr = (ping_result*)arg;
+ ping_result* pr = static_cast<ping_result*>(arg);
grpc_cq_end_op(pr->cq, pr->tag, GRPC_ERROR_REF(error), ping_destroy, pr,
&pr->completion_storage);
}
@@ -48,7 +48,7 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq,
GRPC_API_TRACE("grpc_channel_ping(channel=%p, cq=%p, tag=%p, reserved=%p)", 4,
(channel, cq, tag, reserved));
grpc_transport_op* op = grpc_make_transport_op(nullptr);
- ping_result* pr = (ping_result*)gpr_malloc(sizeof(*pr));
+ ping_result* pr = static_cast<ping_result*>(gpr_malloc(sizeof(*pr)));
grpc_channel_element* top_elem =
grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
grpc_core::ExecCtx exec_ctx;
diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc
index a2c52082c2..2f4bcc357c 100644
--- a/src/core/lib/surface/completion_queue.cc
+++ b/src/core/lib/surface/completion_queue.cc
@@ -88,24 +88,24 @@ static size_t non_polling_poller_size(void) {
}
static void non_polling_poller_init(grpc_pollset* pollset, gpr_mu** mu) {
- non_polling_poller* npp = (non_polling_poller*)pollset;
+ non_polling_poller* npp = reinterpret_cast<non_polling_poller*>(pollset);
gpr_mu_init(&npp->mu);
*mu = &npp->mu;
}
static void non_polling_poller_destroy(grpc_pollset* pollset) {
- non_polling_poller* npp = (non_polling_poller*)pollset;
+ non_polling_poller* npp = reinterpret_cast<non_polling_poller*>(pollset);
gpr_mu_destroy(&npp->mu);
}
static grpc_error* non_polling_poller_work(grpc_pollset* pollset,
grpc_pollset_worker** worker,
grpc_millis deadline) {
- non_polling_poller* npp = (non_polling_poller*)pollset;
+ non_polling_poller* npp = reinterpret_cast<non_polling_poller*>(pollset);
if (npp->shutdown) return GRPC_ERROR_NONE;
non_polling_worker w;
gpr_cv_init(&w.cv);
- if (worker != nullptr) *worker = (grpc_pollset_worker*)&w;
+ if (worker != nullptr) *worker = reinterpret_cast<grpc_pollset_worker*>(&w);
if (npp->root == nullptr) {
npp->root = w.next = w.prev = &w;
} else {
@@ -138,11 +138,11 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset,
static grpc_error* non_polling_poller_kick(
grpc_pollset* pollset, grpc_pollset_worker* specific_worker) {
- non_polling_poller* p = (non_polling_poller*)pollset;
+ non_polling_poller* p = reinterpret_cast<non_polling_poller*>(pollset);
if (specific_worker == nullptr)
- specific_worker = (grpc_pollset_worker*)p->root;
+ specific_worker = reinterpret_cast<grpc_pollset_worker*>(p->root);
if (specific_worker != nullptr) {
- non_polling_worker* w = (non_polling_worker*)specific_worker;
+ non_polling_worker* w = reinterpret_cast<non_polling_worker*>(specific_worker);
if (!w->kicked) {
w->kicked = true;
gpr_cv_signal(&w->cv);
@@ -153,7 +153,7 @@ static grpc_error* non_polling_poller_kick(
static void non_polling_poller_shutdown(grpc_pollset* pollset,
grpc_closure* closure) {
- non_polling_poller* p = (non_polling_poller*)pollset;
+ non_polling_poller* p = reinterpret_cast<non_polling_poller*>(pollset);
GPR_ASSERT(closure != nullptr);
p->shutdown = closure;
if (p->root == nullptr) {
@@ -354,10 +354,10 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq,
(grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) {
*tag = storage->tag;
grpc_core::ExecCtx exec_ctx;
- *ok = (storage->next & (uintptr_t)(1)) == 1;
+ *ok = (storage->next & static_cast<uintptr_t>(1)) == 1;
storage->done(storage->done_arg, storage);
ret = 1;
- cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq);
+ cq_next_data* cqd = static_cast<cq_next_data*>DATA_FROM_CQ(cq);
if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) {
GRPC_CQ_INTERNAL_REF(cq, "shutting_down");
gpr_mu_lock(cq->mu);
@@ -383,7 +383,7 @@ static void cq_event_queue_destroy(grpc_cq_event_queue* q) {
}
static bool cq_event_queue_push(grpc_cq_event_queue* q, grpc_cq_completion* c) {
- gpr_mpscq_push(&q->queue, (gpr_mpscq_node*)c);
+ gpr_mpscq_push(&q->queue, reinterpret_cast<gpr_mpscq_node*>(c));
return gpr_atm_no_barrier_fetch_add(&q->num_queue_items, 1) == 0;
}
@@ -395,7 +395,7 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) {
GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES();
bool is_empty = false;
- c = (grpc_cq_completion*)gpr_mpscq_pop_and_check_end(&q->queue, &is_empty);
+ c = reinterpret_cast<grpc_cq_completion*>(gpr_mpscq_pop_and_check_end(&q->queue, &is_empty));
gpr_spinlock_unlock(&q->queue_lock);
if (c == nullptr && !is_empty) {
@@ -415,7 +415,7 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) {
/* Note: The counter is not incremented/decremented atomically with push/pop.
* The count is only eventually consistent */
static long cq_event_queue_num_items(grpc_cq_event_queue* q) {
- return (long)gpr_atm_no_barrier_load(&q->num_queue_items);
+ return static_cast<long>gpr_atm_no_barrier_load(&q->num_queue_items);
}
grpc_completion_queue* grpc_completion_queue_create_internal(
@@ -437,9 +437,9 @@ grpc_completion_queue* grpc_completion_queue_create_internal(
grpc_core::ExecCtx exec_ctx;
GRPC_STATS_INC_CQS_CREATED();
- cq = (grpc_completion_queue*)gpr_zalloc(sizeof(grpc_completion_queue) +
+ cq = static_cast<grpc_completion_queue*>(gpr_zalloc(sizeof(grpc_completion_queue) +
vtable->data_size +
- poller_vtable->size());
+ poller_vtable->size()));
cq->vtable = vtable;
cq->poller_vtable = poller_vtable;
@@ -456,7 +456,7 @@ grpc_completion_queue* grpc_completion_queue_create_internal(
}
static void cq_init_next(void* ptr) {
- cq_next_data* cqd = (cq_next_data*)ptr;
+ cq_next_data* cqd = static_cast<cq_next_data*>(ptr);
/* Initial count is dropped by grpc_completion_queue_shutdown */
gpr_atm_no_barrier_store(&cqd->pending_events, 1);
cqd->shutdown_called = false;
@@ -465,13 +465,13 @@ static void cq_init_next(void* ptr) {
}
static void cq_destroy_next(void* ptr) {
- cq_next_data* cqd = (cq_next_data*)ptr;
+ cq_next_data* cqd = static_cast<cq_next_data*>(ptr);
GPR_ASSERT(cq_event_queue_num_items(&cqd->queue) == 0);
cq_event_queue_destroy(&cqd->queue);
}
static void cq_init_pluck(void* ptr) {
- cq_pluck_data* cqd = (cq_pluck_data*)ptr;
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>(ptr);
/* Initial count is dropped by grpc_completion_queue_shutdown */
gpr_atm_no_barrier_store(&cqd->pending_events, 1);
cqd->completed_tail = &cqd->completed_head;
@@ -483,7 +483,7 @@ static void cq_init_pluck(void* ptr) {
}
static void cq_destroy_pluck(void* ptr) {
- cq_pluck_data* cqd = (cq_pluck_data*)ptr;
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>(ptr);
GPR_ASSERT(cqd->completed_head.next == (uintptr_t)&cqd->completed_head);
}
@@ -515,7 +515,7 @@ void grpc_cq_internal_ref(grpc_completion_queue* cq) {
}
static void on_pollset_shutdown_done(void* arg, grpc_error* error) {
- grpc_completion_queue* cq = (grpc_completion_queue*)arg;
+ grpc_completion_queue* cq = static_cast<grpc_completion_queue*>(arg);
GRPC_CQ_INTERNAL_UNREF(cq, "pollset_destroy");
}
@@ -548,7 +548,7 @@ static void cq_check_tag(grpc_completion_queue* cq, void* tag, bool lock_cq) {
gpr_mu_lock(cq->mu);
}
- for (int i = 0; i < (int)cq->outstanding_tag_count; i++) {
+ for (int i = 0; i < static_cast<int>(cq->outstanding_tag_count); i++) {
if (cq->outstanding_tags[i] == tag) {
cq->outstanding_tag_count--;
GPR_SWAP(void*, cq->outstanding_tags[i],
@@ -587,12 +587,12 @@ static bool atm_inc_if_nonzero(gpr_atm* counter) {
}
static bool cq_begin_op_for_next(grpc_completion_queue* cq, void* tag) {
- cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq);
+ cq_next_data* cqd = static_cast<cq_next_data*>DATA_FROM_CQ(cq);
return atm_inc_if_nonzero(&cqd->pending_events);
}
static bool cq_begin_op_for_pluck(grpc_completion_queue* cq, void* tag) {
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
return atm_inc_if_nonzero(&cqd->pending_events);
}
@@ -601,9 +601,9 @@ bool grpc_cq_begin_op(grpc_completion_queue* cq, void* tag) {
gpr_mu_lock(cq->mu);
if (cq->outstanding_tag_count == cq->outstanding_tag_capacity) {
cq->outstanding_tag_capacity = GPR_MAX(4, 2 * cq->outstanding_tag_capacity);
- cq->outstanding_tags = (void**)gpr_realloc(
+ cq->outstanding_tags = static_cast<void**>(gpr_realloc(
cq->outstanding_tags,
- sizeof(*cq->outstanding_tags) * cq->outstanding_tag_capacity);
+ sizeof(*cq->outstanding_tags) * cq->outstanding_tag_capacity));
}
cq->outstanding_tags[cq->outstanding_tag_count++] = tag;
gpr_mu_unlock(cq->mu);
@@ -632,13 +632,13 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag,
gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg);
}
}
- cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq);
+ cq_next_data* cqd = static_cast<cq_next_data*>DATA_FROM_CQ(cq);
int is_success = (error == GRPC_ERROR_NONE);
storage->tag = tag;
storage->done = done;
storage->done_arg = done_arg;
- storage->next = (uintptr_t)(is_success);
+ storage->next = static_cast<uintptr_t>(is_success);
cq_check_tag(cq, tag, true); /* Used in debug builds only */
@@ -701,7 +701,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag,
void* done_arg, grpc_cq_completion* storage) {
GPR_TIMER_SCOPE("cq_end_op_for_pluck", 0);
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
int is_success = (error == GRPC_ERROR_NONE);
if (grpc_api_trace.enabled() ||
@@ -719,7 +719,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag,
storage->tag = tag;
storage->done = done;
storage->done_arg = done_arg;
- storage->next = ((uintptr_t)&cqd->completed_head) | ((uintptr_t)(is_success));
+ storage->next = ((uintptr_t)&cqd->completed_head) | (static_cast<uintptr_t>(is_success));
gpr_mu_lock(cq->mu);
cq_check_tag(cq, tag, false); /* Used in debug builds only */
@@ -727,7 +727,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag,
/* Add to the list of completions */
gpr_atm_no_barrier_fetch_add(&cqd->things_queued_ever, 1);
cqd->completed_tail->next =
- ((uintptr_t)storage) | (1u & (uintptr_t)cqd->completed_tail->next);
+ ((uintptr_t)storage) | (1u & cqd->completed_tail->next);
cqd->completed_tail = storage;
if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) {
@@ -778,9 +778,9 @@ class ExecCtxNext : public grpc_core::ExecCtx {
ExecCtxNext(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {}
bool CheckReadyToFinish() override {
- cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_;
+ cq_is_finished_arg* a = static_cast<cq_is_finished_arg*>(check_ready_to_finish_arg_);
grpc_completion_queue* cq = a->cq;
- cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq);
+ cq_next_data* cqd = static_cast<cq_next_data*>DATA_FROM_CQ(cq);
GPR_ASSERT(a->stolen_completion == nullptr);
gpr_atm current_last_seen_things_queued_ever =
@@ -836,7 +836,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline,
GPR_TIMER_SCOPE("grpc_completion_queue_next", 0);
grpc_event ret;
- cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq);
+ cq_next_data* cqd = static_cast<cq_next_data*>DATA_FROM_CQ(cq);
GRPC_API_TRACE(
"grpc_completion_queue_next("
@@ -961,7 +961,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline,
- grpc_completion_queue_shutdown() MUST have been called before calling
this function */
static void cq_finish_shutdown_next(grpc_completion_queue* cq) {
- cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq);
+ cq_next_data* cqd = static_cast<cq_next_data*>DATA_FROM_CQ(cq);
GPR_ASSERT(cqd->shutdown_called);
GPR_ASSERT(gpr_atm_no_barrier_load(&cqd->pending_events) == 0);
@@ -970,7 +970,7 @@ static void cq_finish_shutdown_next(grpc_completion_queue* cq) {
}
static void cq_shutdown_next(grpc_completion_queue* cq) {
- cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq);
+ cq_next_data* cqd = static_cast<cq_next_data*>DATA_FROM_CQ(cq);
/* Need an extra ref for cq here because:
* We call cq_finish_shutdown_next() below, that would call pollset shutdown.
@@ -1003,7 +1003,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue* cq,
static int add_plucker(grpc_completion_queue* cq, void* tag,
grpc_pollset_worker** worker) {
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
if (cqd->num_pluckers == GRPC_MAX_COMPLETION_QUEUE_PLUCKERS) {
return 0;
}
@@ -1015,7 +1015,7 @@ static int add_plucker(grpc_completion_queue* cq, void* tag,
static void del_plucker(grpc_completion_queue* cq, void* tag,
grpc_pollset_worker** worker) {
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
for (int i = 0; i < cqd->num_pluckers; i++) {
if (cqd->pluckers[i].tag == tag && cqd->pluckers[i].worker == worker) {
cqd->num_pluckers--;
@@ -1031,9 +1031,9 @@ class ExecCtxPluck : public grpc_core::ExecCtx {
ExecCtxPluck(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {}
bool CheckReadyToFinish() override {
- cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_;
+ cq_is_finished_arg* a = static_cast<cq_is_finished_arg*>(check_ready_to_finish_arg_);
grpc_completion_queue* cq = a->cq;
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
GPR_ASSERT(a->stolen_completion == nullptr);
gpr_atm current_last_seen_things_queued_ever =
@@ -1045,10 +1045,10 @@ class ExecCtxPluck : public grpc_core::ExecCtx {
gpr_atm_no_barrier_load(&cqd->things_queued_ever);
grpc_cq_completion* c;
grpc_cq_completion* prev = &cqd->completed_head;
- while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) !=
+ while ((c = (grpc_cq_completion*)(prev->next & ~static_cast<uintptr_t>(1))) !=
&cqd->completed_head) {
if (c->tag == a->tag) {
- prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1);
+ prev->next = (prev->next & static_cast<uintptr_t>(1)) | (c->next & ~static_cast<uintptr_t>(1));
if (c == cqd->completed_tail) {
cqd->completed_tail = prev;
}
@@ -1075,7 +1075,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag,
grpc_cq_completion* c;
grpc_cq_completion* prev;
grpc_pollset_worker* worker = nullptr;
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
if (grpc_cq_pluck_trace.enabled()) {
GRPC_API_TRACE(
@@ -1115,10 +1115,10 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag,
break;
}
prev = &cqd->completed_head;
- while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) !=
+ while ((c = (grpc_cq_completion*)(prev->next & ~static_cast<uintptr_t>(1))) !=
&cqd->completed_head) {
if (c->tag == tag) {
- prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1);
+ prev->next = (prev->next & static_cast<uintptr_t>(1)) | (c->next & ~static_cast<uintptr_t>(1));
if (c == cqd->completed_tail) {
cqd->completed_tail = prev;
}
@@ -1191,7 +1191,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag,
}
static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) {
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
GPR_ASSERT(cqd->shutdown_called);
GPR_ASSERT(!gpr_atm_no_barrier_load(&cqd->shutdown));
@@ -1203,7 +1203,7 @@ static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) {
/* NOTE: This function is almost exactly identical to cq_shutdown_next() but
* merging them is a bit tricky and probably not worth it */
static void cq_shutdown_pluck(grpc_completion_queue* cq) {
- cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq);
+ cq_pluck_data* cqd = static_cast<cq_pluck_data*>DATA_FROM_CQ(cq);
/* Need an extra ref for cq here because:
* We call cq_finish_shutdown_pluck() below, that would call pollset shutdown.
diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc
index 7f7947faaa..46bf266740 100644
--- a/src/core/lib/surface/init.cc
+++ b/src/core/lib/surface/init.cc
@@ -74,12 +74,12 @@ static void do_basic_init(void) {
static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_append_filter(
- builder, (const grpc_channel_filter*)arg, nullptr, nullptr);
+ builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_prepend_filter(
- builder, (const grpc_channel_filter*)arg, nullptr, nullptr);
+ builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
static void register_builtin_channel_init() {
diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc
index 1e59434aa5..ad3ee62ad8 100644
--- a/src/core/lib/surface/server.cc
+++ b/src/core/lib/surface/server.cc
@@ -242,7 +242,7 @@ static void channel_broadcaster_init(grpc_server* s, channel_broadcaster* cb) {
}
cb->num_channels = count;
cb->channels =
- (grpc_channel**)gpr_malloc(sizeof(*cb->channels) * cb->num_channels);
+ static_cast<grpc_channel**>(gpr_malloc(sizeof(*cb->channels) * cb->num_channels));
count = 0;
for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) {
cb->channels[count++] = c->channel;
@@ -256,7 +256,7 @@ struct shutdown_cleanup_args {
};
static void shutdown_cleanup(void* arg, grpc_error* error) {
- struct shutdown_cleanup_args* a = (struct shutdown_cleanup_args*)arg;
+ struct shutdown_cleanup_args* a = static_cast<struct shutdown_cleanup_args*>(arg);
grpc_slice_unref_internal(a->slice);
gpr_free(a);
}
@@ -264,7 +264,7 @@ static void shutdown_cleanup(void* arg, grpc_error* error) {
static void send_shutdown(grpc_channel* channel, bool send_goaway,
grpc_error* send_disconnect) {
struct shutdown_cleanup_args* sc =
- (struct shutdown_cleanup_args*)gpr_malloc(sizeof(*sc));
+ static_cast<struct shutdown_cleanup_args*>(gpr_malloc(sizeof(*sc)));
GRPC_CLOSURE_INIT(&sc->closure, shutdown_cleanup, sc,
grpc_schedule_on_exec_ctx);
grpc_transport_op* op = grpc_make_transport_op(&sc->closure);
@@ -304,8 +304,8 @@ static void channel_broadcaster_shutdown(channel_broadcaster* cb,
static void request_matcher_init(request_matcher* rm, grpc_server* server) {
memset(rm, 0, sizeof(*rm));
rm->server = server;
- rm->requests_per_cq = (gpr_locked_mpscq*)gpr_malloc(
- sizeof(*rm->requests_per_cq) * server->cq_count);
+ rm->requests_per_cq = static_cast<gpr_locked_mpscq*>(gpr_malloc(
+ sizeof(*rm->requests_per_cq) * server->cq_count));
for (size_t i = 0; i < server->cq_count; i++) {
gpr_locked_mpscq_init(&rm->requests_per_cq[i]);
}
@@ -320,7 +320,7 @@ static void request_matcher_destroy(request_matcher* rm) {
}
static void kill_zombie(void* elem, grpc_error* error) {
- grpc_call_unref(grpc_call_from_top_element((grpc_call_element*)elem));
+ grpc_call_unref(grpc_call_from_top_element(static_cast<grpc_call_element*>(elem)));
}
static void request_matcher_zombify_all_pending_calls(request_matcher* rm) {
@@ -341,8 +341,8 @@ static void request_matcher_kill_requests(grpc_server* server,
grpc_error* error) {
requested_call* rc;
for (size_t i = 0; i < server->cq_count; i++) {
- while ((rc = (requested_call*)gpr_locked_mpscq_pop(
- &rm->requests_per_cq[i])) != nullptr) {
+ while ((rc = reinterpret_cast<requested_call*>(gpr_locked_mpscq_pop(
+ &rm->requests_per_cq[i]))) != nullptr) {
fail_call(server, i, rc, GRPC_ERROR_REF(error));
}
}
@@ -402,7 +402,7 @@ static void orphan_channel(channel_data* chand) {
}
static void finish_destroy_channel(void* cd, grpc_error* error) {
- channel_data* chand = (channel_data*)cd;
+ channel_data* chand = static_cast<channel_data*>(cd);
grpc_server* server = chand->server;
GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server");
server_unref(server);
@@ -469,9 +469,9 @@ static void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
}
static void publish_new_rpc(void* arg, grpc_error* error) {
- grpc_call_element* call_elem = (grpc_call_element*)arg;
- call_data* calld = (call_data*)call_elem->call_data;
- channel_data* chand = (channel_data*)call_elem->channel_data;
+ grpc_call_element* call_elem = static_cast<grpc_call_element*>(arg);
+ call_data* calld = static_cast<call_data*>(call_elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(call_elem->channel_data);
request_matcher* rm = calld->matcher;
grpc_server* server = rm->server;
@@ -488,7 +488,7 @@ static void publish_new_rpc(void* arg, grpc_error* error) {
for (size_t i = 0; i < server->cq_count; i++) {
size_t cq_idx = (chand->cq_idx + i) % server->cq_count;
requested_call* rc =
- (requested_call*)gpr_locked_mpscq_try_pop(&rm->requests_per_cq[cq_idx]);
+ reinterpret_cast<requested_call*>(gpr_locked_mpscq_try_pop(&rm->requests_per_cq[cq_idx]));
if (rc == nullptr) {
continue;
} else {
@@ -510,7 +510,7 @@ static void publish_new_rpc(void* arg, grpc_error* error) {
for (size_t i = 0; i < server->cq_count; i++) {
size_t cq_idx = (chand->cq_idx + i) % server->cq_count;
requested_call* rc =
- (requested_call*)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]);
+ reinterpret_cast<requested_call*>(gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]));
if (rc == nullptr) {
continue;
} else {
@@ -536,7 +536,7 @@ static void publish_new_rpc(void* arg, grpc_error* error) {
static void finish_start_new_rpc(
grpc_server* server, grpc_call_element* elem, request_matcher* rm,
grpc_server_register_method_payload_handling payload_handling) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (gpr_atm_acq_load(&server->shutdown_flag)) {
gpr_atm_no_barrier_store(&calld->state, ZOMBIED);
@@ -566,8 +566,8 @@ static void finish_start_new_rpc(
}
static void start_new_rpc(grpc_call_element* elem) {
- channel_data* chand = (channel_data*)elem->channel_data;
- call_data* calld = (call_data*)elem->call_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_server* server = chand->server;
uint32_t i;
uint32_t hash;
@@ -626,7 +626,7 @@ static int num_listeners(grpc_server* server) {
}
static void done_shutdown_event(void* server, grpc_cq_completion* completion) {
- server_unref((grpc_server*)server);
+ server_unref(static_cast<grpc_server*>(server));
}
static int num_channels(grpc_server* server) {
@@ -689,8 +689,8 @@ static void maybe_finish_shutdown(grpc_server* server) {
}
static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)ptr;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(ptr);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_millis op_deadline;
if (error == GRPC_ERROR_NONE) {
@@ -728,7 +728,7 @@ static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) {
static void server_mutate_op(grpc_call_element* elem,
grpc_transport_stream_op_batch* op) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (op->recv_initial_metadata) {
GPR_ASSERT(op->payload->recv_initial_metadata.recv_flags == nullptr);
@@ -750,8 +750,8 @@ static void server_start_transport_stream_op_batch(
}
static void got_initial_metadata(void* ptr, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)ptr;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(ptr);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (error == GRPC_ERROR_NONE) {
start_new_rpc(elem);
} else {
@@ -768,7 +768,7 @@ static void got_initial_metadata(void* ptr, grpc_error* error) {
static void accept_stream(void* cd, grpc_transport* transport,
const void* transport_server_data) {
- channel_data* chand = (channel_data*)cd;
+ channel_data* chand = static_cast<channel_data*>(cd);
/* create a call */
grpc_call_create_args args;
memset(&args, 0, sizeof(args));
@@ -784,7 +784,7 @@ static void accept_stream(void* cd, grpc_transport* transport,
GRPC_ERROR_UNREF(error);
return;
}
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_op op;
memset(&op, 0, sizeof(op));
op.op = GRPC_OP_RECV_INITIAL_METADATA;
@@ -796,7 +796,7 @@ static void accept_stream(void* cd, grpc_transport* transport,
}
static void channel_connectivity_changed(void* cd, grpc_error* error) {
- channel_data* chand = (channel_data*)cd;
+ channel_data* chand = static_cast<channel_data*>(cd);
grpc_server* server = chand->server;
if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) {
grpc_transport_op* op = grpc_make_transport_op(nullptr);
@@ -815,8 +815,8 @@ static void channel_connectivity_changed(void* cd, grpc_error* error) {
static grpc_error* init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
memset(calld, 0, sizeof(call_data));
calld->deadline = GRPC_MILLIS_INF_FUTURE;
calld->call = grpc_call_from_top_element(elem);
@@ -832,8 +832,8 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
static void destroy_call_elem(grpc_call_element* elem,
const grpc_call_final_info* final_info,
grpc_closure* ignored) {
- channel_data* chand = (channel_data*)elem->channel_data;
- call_data* calld = (call_data*)elem->call_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
GPR_ASSERT(calld->state != PENDING);
@@ -851,7 +851,7 @@ static void destroy_call_elem(grpc_call_element* elem,
static grpc_error* init_channel_elem(grpc_channel_element* elem,
grpc_channel_element_args* args) {
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
GPR_ASSERT(args->is_first);
GPR_ASSERT(!args->is_last);
chand->server = nullptr;
@@ -867,7 +867,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
static void destroy_channel_elem(grpc_channel_element* elem) {
size_t i;
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (chand->registered_methods) {
for (i = 0; i < chand->registered_method_slots; i++) {
grpc_slice_unref_internal(chand->registered_methods[i].method);
@@ -913,8 +913,8 @@ static void register_completion_queue(grpc_server* server,
GRPC_CQ_INTERNAL_REF(cq, "server");
n = server->cq_count++;
- server->cqs = (grpc_completion_queue**)gpr_realloc(
- server->cqs, server->cq_count * sizeof(grpc_completion_queue*));
+ server->cqs = static_cast<grpc_completion_queue**>(gpr_realloc(
+ server->cqs, server->cq_count * sizeof(grpc_completion_queue*)));
server->cqs[n] = cq;
}
@@ -939,7 +939,7 @@ void grpc_server_register_completion_queue(grpc_server* server,
grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
- grpc_server* server = (grpc_server*)gpr_zalloc(sizeof(grpc_server));
+ grpc_server* server = static_cast<grpc_server*>(gpr_zalloc(sizeof(grpc_server)));
gpr_mu_init(&server->mu_global);
gpr_mu_init(&server->mu_call);
@@ -988,7 +988,7 @@ void* grpc_server_register_method(
flags);
return nullptr;
}
- m = (registered_method*)gpr_zalloc(sizeof(registered_method));
+ m = static_cast<registered_method*>(gpr_zalloc(sizeof(registered_method)));
m->method = gpr_strdup(method);
m->host = gpr_strdup(host);
m->next = server->registered_methods;
@@ -999,7 +999,7 @@ void* grpc_server_register_method(
}
static void start_listeners(void* s, grpc_error* error) {
- grpc_server* server = (grpc_server*)s;
+ grpc_server* server = static_cast<grpc_server*>(s);
for (listener* l = server->listeners; l; l = l->next) {
l->start(server, l->arg, server->pollsets, server->pollset_count);
}
@@ -1021,7 +1021,7 @@ void grpc_server_start(grpc_server* server) {
server->started = true;
server->pollset_count = 0;
server->pollsets =
- (grpc_pollset**)gpr_malloc(sizeof(grpc_pollset*) * server->cq_count);
+ static_cast<grpc_pollset**>(gpr_malloc(sizeof(grpc_pollset*) * server->cq_count));
for (i = 0; i < server->cq_count; i++) {
if (grpc_cq_can_listen(server->cqs[i])) {
server->pollsets[server->pollset_count++] =
@@ -1063,9 +1063,9 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport,
grpc_transport_op* op = nullptr;
channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport);
- chand = (channel_data*)grpc_channel_stack_element(
+ chand = static_cast<channel_data*>(grpc_channel_stack_element(
grpc_channel_get_channel_stack(channel), 0)
- ->channel_data;
+ ->channel_data);
chand->server = s;
server_ref(s);
chand->channel = channel;
@@ -1076,7 +1076,7 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport,
}
if (cq_idx == s->cq_count) {
/* completion queue not found: pick a random one to publish new calls to */
- cq_idx = (size_t)rand() % s->cq_count;
+ cq_idx = static_cast<size_t>(rand()) % s->cq_count;
}
chand->cq_idx = cq_idx;
@@ -1089,7 +1089,7 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport,
if (num_registered_methods > 0) {
slots = 2 * num_registered_methods;
alloc = sizeof(channel_registered_method) * slots;
- chand->registered_methods = (channel_registered_method*)gpr_zalloc(alloc);
+ chand->registered_methods = static_cast<channel_registered_method*>(gpr_zalloc(alloc));
for (rm = s->registered_methods; rm; rm = rm->next) {
grpc_slice host;
bool has_host;
@@ -1118,7 +1118,7 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport,
crm->method = method;
}
GPR_ASSERT(slots <= UINT32_MAX);
- chand->registered_method_slots = (uint32_t)slots;
+ chand->registered_method_slots = static_cast<uint32_t>(slots);
chand->registered_method_max_probes = max_probes;
}
@@ -1148,7 +1148,7 @@ void done_published_shutdown(void* done_arg, grpc_cq_completion* storage) {
}
static void listener_destroy_done(void* s, grpc_error* error) {
- grpc_server* server = (grpc_server*)s;
+ grpc_server* server = static_cast<grpc_server*>(s);
gpr_mu_lock(&server->mu_global);
server->listeners_destroyed++;
maybe_finish_shutdown(server);
@@ -1176,13 +1176,13 @@ void grpc_server_shutdown_and_notify(grpc_server* server,
GPR_ASSERT(grpc_cq_begin_op(cq, tag));
if (server->shutdown_published) {
grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, nullptr,
- (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion)));
+ static_cast<grpc_cq_completion*>(gpr_malloc(sizeof(grpc_cq_completion))));
gpr_mu_unlock(&server->mu_global);
return;
}
- server->shutdown_tags = (shutdown_tag*)gpr_realloc(
+ server->shutdown_tags = static_cast<shutdown_tag*>(gpr_realloc(
server->shutdown_tags,
- sizeof(shutdown_tag) * (server->num_shutdown_tags + 1));
+ sizeof(shutdown_tag) * (server->num_shutdown_tags + 1)));
sdt = &server->shutdown_tags[server->num_shutdown_tags++];
sdt->tag = tag;
sdt->cq = cq;
@@ -1259,7 +1259,7 @@ void grpc_server_add_listener(grpc_server* server, void* arg,
size_t pollset_count),
void (*destroy)(grpc_server* server, void* arg,
grpc_closure* on_done)) {
- listener* l = (listener*)gpr_malloc(sizeof(listener));
+ listener* l = static_cast<listener*>(gpr_malloc(sizeof(listener)));
l->arg = arg;
l->start = start;
l->destroy = destroy;
@@ -1289,7 +1289,7 @@ static grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx,
matching calls */
gpr_mu_lock(&server->mu_call);
while ((calld = rm->pending_head) != nullptr) {
- rc = (requested_call*)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]);
+ rc = reinterpret_cast<requested_call*>(gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]));
if (rc == nullptr) break;
rm->pending_head = calld->pending_next;
gpr_mu_unlock(&server->mu_call);
@@ -1317,7 +1317,7 @@ grpc_call_error grpc_server_request_call(
grpc_completion_queue* cq_for_notification, void* tag) {
grpc_call_error error;
grpc_core::ExecCtx exec_ctx;
- requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc));
+ requested_call* rc = static_cast<requested_call*>(gpr_malloc(sizeof(*rc)));
GRPC_STATS_INC_SERVER_REQUESTED_CALLS();
GRPC_API_TRACE(
"grpc_server_request_call("
@@ -1364,8 +1364,8 @@ grpc_call_error grpc_server_request_registered_call(
grpc_completion_queue* cq_for_notification, void* tag) {
grpc_call_error error;
grpc_core::ExecCtx exec_ctx;
- requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc));
- registered_method* rm = (registered_method*)rmp;
+ requested_call* rc = static_cast<requested_call*>(gpr_malloc(sizeof(*rc)));
+ registered_method* rm = static_cast<registered_method*>(rmp);
GRPC_STATS_INC_SERVER_REQUESTED_CALLS();
GRPC_API_TRACE(
"grpc_server_request_registered_call("
diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc
index 2ba1cfdaa6..044183e8fd 100644
--- a/src/core/lib/transport/bdp_estimator.cc
+++ b/src/core/lib/transport/bdp_estimator.cc
@@ -40,8 +40,8 @@ BdpEstimator::BdpEstimator(const char* name)
grpc_millis BdpEstimator::CompletePing() {
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
gpr_timespec dt_ts = gpr_time_sub(now, ping_start_time_);
- double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec;
- double bw = dt > 0 ? ((double)accumulator_ / dt) : 0;
+ double dt = static_cast<double>(dt_ts.tv_sec) + 1e-9 * static_cast<double>(dt_ts.tv_nsec);
+ double bw = dt > 0 ? (static_cast<double>(accumulator_) / dt) : 0;
int start_inter_ping_delay = inter_ping_delay_;
if (grpc_bdp_estimator_trace.enabled()) {
gpr_log(GPR_DEBUG,
@@ -65,7 +65,7 @@ grpc_millis BdpEstimator::CompletePing() {
if (stable_estimate_count_ >= 2) {
inter_ping_delay_ +=
100 +
- (int)(rand() * 100.0 / RAND_MAX); // if the ping estimate is steady,
+ static_cast<int>(rand() * 100.0 / RAND_MAX); // if the ping estimate is steady,
// slowly ramp down the probe time
}
}
diff --git a/src/core/lib/transport/byte_stream.cc b/src/core/lib/transport/byte_stream.cc
index 8dcb1e0bdb..2ae0b8298a 100644
--- a/src/core/lib/transport/byte_stream.cc
+++ b/src/core/lib/transport/byte_stream.cc
@@ -49,14 +49,14 @@ void grpc_byte_stream_destroy(grpc_byte_stream* byte_stream) {
static bool slice_buffer_stream_next(grpc_byte_stream* byte_stream,
size_t max_size_hint,
grpc_closure* on_complete) {
- grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream;
+ grpc_slice_buffer_stream* stream = reinterpret_cast<grpc_slice_buffer_stream*>(byte_stream);
GPR_ASSERT(stream->cursor < stream->backing_buffer->count);
return true;
}
static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream,
grpc_slice* slice) {
- grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream;
+ grpc_slice_buffer_stream* stream = reinterpret_cast<grpc_slice_buffer_stream*>(byte_stream);
if (stream->shutdown_error != GRPC_ERROR_NONE) {
return GRPC_ERROR_REF(stream->shutdown_error);
}
@@ -69,13 +69,13 @@ static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream,
static void slice_buffer_stream_shutdown(grpc_byte_stream* byte_stream,
grpc_error* error) {
- grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream;
+ grpc_slice_buffer_stream* stream = reinterpret_cast<grpc_slice_buffer_stream*>(byte_stream);
GRPC_ERROR_UNREF(stream->shutdown_error);
stream->shutdown_error = error;
}
static void slice_buffer_stream_destroy(grpc_byte_stream* byte_stream) {
- grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream;
+ grpc_slice_buffer_stream* stream = reinterpret_cast<grpc_slice_buffer_stream*>(byte_stream);
grpc_slice_buffer_reset_and_unref_internal(stream->backing_buffer);
GRPC_ERROR_UNREF(stream->shutdown_error);
}
@@ -88,7 +88,7 @@ void grpc_slice_buffer_stream_init(grpc_slice_buffer_stream* stream,
grpc_slice_buffer* slice_buffer,
uint32_t flags) {
GPR_ASSERT(slice_buffer->length <= UINT32_MAX);
- stream->base.length = (uint32_t)slice_buffer->length;
+ stream->base.length = static_cast<uint32_t>(slice_buffer->length);
stream->base.flags = flags;
stream->base.vtable = &slice_buffer_stream_vtable;
stream->backing_buffer = slice_buffer;
@@ -112,7 +112,7 @@ void grpc_byte_stream_cache_destroy(grpc_byte_stream_cache* cache) {
static bool caching_byte_stream_next(grpc_byte_stream* byte_stream,
size_t max_size_hint,
grpc_closure* on_complete) {
- grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream;
+ grpc_caching_byte_stream* stream = reinterpret_cast<grpc_caching_byte_stream*>(byte_stream);
if (stream->shutdown_error != GRPC_ERROR_NONE) return true;
if (stream->cursor < stream->cache->cache_buffer.count) return true;
return grpc_byte_stream_next(stream->cache->underlying_stream, max_size_hint,
@@ -121,7 +121,7 @@ static bool caching_byte_stream_next(grpc_byte_stream* byte_stream,
static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream,
grpc_slice* slice) {
- grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream;
+ grpc_caching_byte_stream* stream = reinterpret_cast<grpc_caching_byte_stream*>(byte_stream);
if (stream->shutdown_error != GRPC_ERROR_NONE) {
return GRPC_ERROR_REF(stream->shutdown_error);
}
@@ -143,14 +143,14 @@ static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream,
static void caching_byte_stream_shutdown(grpc_byte_stream* byte_stream,
grpc_error* error) {
- grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream;
+ grpc_caching_byte_stream* stream = reinterpret_cast<grpc_caching_byte_stream*>(byte_stream);
GRPC_ERROR_UNREF(stream->shutdown_error);
stream->shutdown_error = GRPC_ERROR_REF(error);
grpc_byte_stream_shutdown(stream->cache->underlying_stream, error);
}
static void caching_byte_stream_destroy(grpc_byte_stream* byte_stream) {
- grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream;
+ grpc_caching_byte_stream* stream = reinterpret_cast<grpc_caching_byte_stream*>(byte_stream);
GRPC_ERROR_UNREF(stream->shutdown_error);
}
diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc
index c42cc9c8d0..183d5987ee 100644
--- a/src/core/lib/transport/connectivity_state.cc
+++ b/src/core/lib/transport/connectivity_state.cc
@@ -74,7 +74,7 @@ void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) {
grpc_connectivity_state grpc_connectivity_state_check(
grpc_connectivity_state_tracker* tracker) {
grpc_connectivity_state cur =
- (grpc_connectivity_state)gpr_atm_no_barrier_load(
+ static_cast<grpc_connectivity_state>gpr_atm_no_barrier_load(
&tracker->current_state_atm);
if (grpc_connectivity_state_trace.enabled()) {
gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name,
@@ -86,7 +86,7 @@ grpc_connectivity_state grpc_connectivity_state_check(
grpc_connectivity_state grpc_connectivity_state_get(
grpc_connectivity_state_tracker* tracker, grpc_error** error) {
grpc_connectivity_state cur =
- (grpc_connectivity_state)gpr_atm_no_barrier_load(
+ static_cast<grpc_connectivity_state>gpr_atm_no_barrier_load(
&tracker->current_state_atm);
if (grpc_connectivity_state_trace.enabled()) {
gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name,
@@ -107,7 +107,7 @@ bool grpc_connectivity_state_notify_on_state_change(
grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current,
grpc_closure* notify) {
grpc_connectivity_state cur =
- (grpc_connectivity_state)gpr_atm_no_barrier_load(
+ static_cast<grpc_connectivity_state>gpr_atm_no_barrier_load(
&tracker->current_state_atm);
if (grpc_connectivity_state_trace.enabled()) {
if (current == nullptr) {
@@ -144,7 +144,7 @@ bool grpc_connectivity_state_notify_on_state_change(
GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_REF(tracker->current_error));
} else {
grpc_connectivity_state_watcher* w =
- (grpc_connectivity_state_watcher*)gpr_malloc(sizeof(*w));
+ static_cast<grpc_connectivity_state_watcher*>(gpr_malloc(sizeof(*w)));
w->current = current;
w->notify = notify;
w->next = tracker->watchers;
@@ -158,7 +158,7 @@ void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker,
grpc_connectivity_state state,
grpc_error* error, const char* reason) {
grpc_connectivity_state cur =
- (grpc_connectivity_state)gpr_atm_no_barrier_load(
+ static_cast<grpc_connectivity_state>gpr_atm_no_barrier_load(
&tracker->current_state_atm);
grpc_connectivity_state_watcher* w;
if (grpc_connectivity_state_trace.enabled()) {
diff --git a/src/core/lib/transport/error_utils.cc b/src/core/lib/transport/error_utils.cc
index 891576f4ba..b968383eda 100644
--- a/src/core/lib/transport/error_utils.cc
+++ b/src/core/lib/transport/error_utils.cc
@@ -32,7 +32,7 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error,
// Otherwise, search through its children.
uint8_t slot = error->first_err;
while (slot != UINT8_MAX) {
- grpc_linked_error* lerr = (grpc_linked_error*)(error->arena + slot);
+ grpc_linked_error* lerr = reinterpret_cast<grpc_linked_error*>(error->arena + slot);
grpc_error* result = recursively_find_error_with_field(lerr->err, which);
if (result) return result;
slot = lerr->next;
@@ -62,10 +62,10 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline,
grpc_status_code status = GRPC_STATUS_UNKNOWN;
intptr_t integer;
if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) {
- status = (grpc_status_code)integer;
+ status = static_cast<grpc_status_code>(integer);
} else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR,
&integer)) {
- status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer,
+ status = grpc_http2_error_to_grpc_status(static_cast<grpc_http2_error_code>(integer),
deadline);
}
if (code != nullptr) *code = status;
@@ -76,10 +76,10 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline,
if (http_error != nullptr) {
if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) {
- *http_error = (grpc_http2_error_code)integer;
+ *http_error = static_cast<grpc_http2_error_code>(integer);
} else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS,
&integer)) {
- *http_error = grpc_status_to_http2_error((grpc_status_code)integer);
+ *http_error = grpc_status_to_http2_error(static_cast<grpc_status_code>(integer));
} else {
*http_error = found_error == GRPC_ERROR_NONE ? GRPC_HTTP2_NO_ERROR
: GRPC_HTTP2_INTERNAL_ERROR;
@@ -103,7 +103,7 @@ bool grpc_error_has_clear_grpc_status(grpc_error* error) {
}
uint8_t slot = error->first_err;
while (slot != UINT8_MAX) {
- grpc_linked_error* lerr = (grpc_linked_error*)(error->arena + slot);
+ grpc_linked_error* lerr = reinterpret_cast<grpc_linked_error*>(error->arena + slot);
if (grpc_error_has_clear_grpc_status(lerr->err)) {
return true;
}
diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc
index cc1edd586f..418224bc97 100644
--- a/src/core/lib/transport/metadata.cc
+++ b/src/core/lib/transport/metadata.cc
@@ -118,8 +118,8 @@ void grpc_mdctx_global_init(void) {
shard->count = 0;
gpr_atm_no_barrier_store(&shard->free_estimate, 0);
shard->capacity = INITIAL_SHARD_CAPACITY;
- shard->elems = (interned_metadata**)gpr_zalloc(sizeof(*shard->elems) *
- shard->capacity);
+ shard->elems = static_cast<interned_metadata**>(gpr_zalloc(sizeof(*shard->elems) *
+ shard->capacity));
}
}
@@ -207,7 +207,7 @@ static void grow_mdtab(mdtab_shard* shard) {
uint32_t hash;
mdtab =
- (interned_metadata**)gpr_zalloc(sizeof(interned_metadata*) * capacity);
+ static_cast<interned_metadata**>(gpr_zalloc(sizeof(interned_metadata*) * capacity));
for (i = 0; i < shard->capacity; i++) {
for (md = shard->elems[i]; md; md = next) {
@@ -227,7 +227,7 @@ static void grow_mdtab(mdtab_shard* shard) {
static void rehash_mdtab(mdtab_shard* shard) {
if (gpr_atm_no_barrier_load(&shard->free_estimate) >
- (gpr_atm)(shard->capacity / 4)) {
+ static_cast<gpr_atm>(shard->capacity / 4)) {
gc_mdtab(shard);
} else {
grow_mdtab(shard);
@@ -244,7 +244,7 @@ grpc_mdelem grpc_mdelem_create(
}
allocated_metadata* allocated =
- (allocated_metadata*)gpr_malloc(sizeof(*allocated));
+ static_cast<allocated_metadata*>(gpr_malloc(sizeof(*allocated)));
allocated->key = grpc_slice_ref_internal(key);
allocated->value = grpc_slice_ref_internal(value);
gpr_atm_rel_store(&allocated->refcnt, 1);
@@ -292,7 +292,7 @@ grpc_mdelem grpc_mdelem_create(
}
/* not found: create a new pair */
- md = (interned_metadata*)gpr_malloc(sizeof(interned_metadata));
+ md = static_cast<interned_metadata*>(gpr_malloc(sizeof(interned_metadata)));
gpr_atm_rel_store(&md->refcnt, 1);
md->key = grpc_slice_ref_internal(key);
md->value = grpc_slice_ref_internal(value);
@@ -336,7 +336,7 @@ grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata) {
grpc_slice value_slice =
grpc_slice_maybe_static_intern(metadata->value, &changed);
return grpc_mdelem_create(key_slice, value_slice,
- changed ? nullptr : (grpc_mdelem_data*)metadata);
+ changed ? nullptr : reinterpret_cast<grpc_mdelem_data*>(metadata));
}
static size_t get_base64_encoded_size(size_t raw_length) {
@@ -363,7 +363,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) {
case GRPC_MDELEM_STORAGE_STATIC:
break;
case GRPC_MDELEM_STORAGE_INTERNED: {
- interned_metadata* md = (interned_metadata*)GRPC_MDELEM_DATA(gmd);
+ interned_metadata* md = reinterpret_cast<interned_metadata*>GRPC_MDELEM_DATA(gmd);
#ifndef NDEBUG
if (grpc_trace_metadata.enabled()) {
char* key_str = grpc_slice_to_c_string(md->key);
@@ -385,7 +385,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) {
break;
}
case GRPC_MDELEM_STORAGE_ALLOCATED: {
- allocated_metadata* md = (allocated_metadata*)GRPC_MDELEM_DATA(gmd);
+ allocated_metadata* md = reinterpret_cast<allocated_metadata*>GRPC_MDELEM_DATA(gmd);
#ifndef NDEBUG
if (grpc_trace_metadata.enabled()) {
char* key_str = grpc_slice_to_c_string(md->key);
@@ -415,7 +415,7 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) {
case GRPC_MDELEM_STORAGE_STATIC:
break;
case GRPC_MDELEM_STORAGE_INTERNED: {
- interned_metadata* md = (interned_metadata*)GRPC_MDELEM_DATA(gmd);
+ interned_metadata* md = reinterpret_cast<interned_metadata*>GRPC_MDELEM_DATA(gmd);
#ifndef NDEBUG
if (grpc_trace_metadata.enabled()) {
char* key_str = grpc_slice_to_c_string(md->key);
@@ -441,7 +441,7 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) {
break;
}
case GRPC_MDELEM_STORAGE_ALLOCATED: {
- allocated_metadata* md = (allocated_metadata*)GRPC_MDELEM_DATA(gmd);
+ allocated_metadata* md = reinterpret_cast<allocated_metadata*>GRPC_MDELEM_DATA(gmd);
#ifndef NDEBUG
if (grpc_trace_metadata.enabled()) {
char* key_str = grpc_slice_to_c_string(md->key);
@@ -475,7 +475,7 @@ void* grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void*)) {
return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) -
grpc_static_mdelem_table];
case GRPC_MDELEM_STORAGE_INTERNED: {
- interned_metadata* im = (interned_metadata*)GRPC_MDELEM_DATA(md);
+ interned_metadata* im = reinterpret_cast<interned_metadata*>GRPC_MDELEM_DATA(md);
void* result;
if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) {
return (void*)gpr_atm_no_barrier_load(&im->user_data);
@@ -500,7 +500,7 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*),
return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) -
grpc_static_mdelem_table];
case GRPC_MDELEM_STORAGE_INTERNED: {
- interned_metadata* im = (interned_metadata*)GRPC_MDELEM_DATA(md);
+ interned_metadata* im = reinterpret_cast<interned_metadata*>GRPC_MDELEM_DATA(md);
GPR_ASSERT(!is_mdelem_static(md));
GPR_ASSERT((user_data == nullptr) == (destroy_func == nullptr));
gpr_mu_lock(&im->mu_user_data);
diff --git a/src/core/lib/transport/service_config.cc b/src/core/lib/transport/service_config.cc
index 5c9930a273..f5805b2fa4 100644
--- a/src/core/lib/transport/service_config.cc
+++ b/src/core/lib/transport/service_config.cc
@@ -60,7 +60,7 @@ struct grpc_service_config {
grpc_service_config* grpc_service_config_create(const char* json_string) {
grpc_service_config* service_config =
- (grpc_service_config*)gpr_malloc(sizeof(*service_config));
+ static_cast<grpc_service_config*>(gpr_malloc(sizeof(*service_config)));
service_config->json_string = gpr_strdup(json_string);
service_config->json_tree =
grpc_json_parse_string(service_config->json_string);
@@ -209,8 +209,8 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table(
num_entries += count;
}
// Populate method config table entries.
- entries = (grpc_slice_hash_table_entry*)gpr_malloc(
- num_entries * sizeof(grpc_slice_hash_table_entry));
+ entries = static_cast<grpc_slice_hash_table_entry*>(gpr_malloc(
+ num_entries * sizeof(grpc_slice_hash_table_entry)));
size_t idx = 0;
for (grpc_json* method = field->child; method != nullptr;
method = method->next) {
@@ -245,8 +245,8 @@ void* grpc_method_config_table_get(const grpc_slice_hash_table* table,
if (value == nullptr) {
char* path_str = grpc_slice_to_c_string(path);
const char* sep = strrchr(path_str, '/') + 1;
- const size_t len = (size_t)(sep - path_str);
- char* buf = (char*)gpr_malloc(len + 2); // '*' and NUL
+ const size_t len = static_cast<size_t>(sep - path_str);
+ char* buf = static_cast<char*>(gpr_malloc(len + 2)); // '*' and NUL
memcpy(buf, path_str, len);
buf[len] = '*';
buf[len + 1] = '\0';
diff --git a/src/core/lib/transport/static_metadata.cc b/src/core/lib/transport/static_metadata.cc
index ebc75724cf..5994cbc265 100644
--- a/src/core/lib/transport/static_metadata.cc
+++ b/src/core/lib/transport/static_metadata.cc
@@ -340,7 +340,7 @@ static uint32_t elems_phash(uint32_t i) {
uint32_t y = i / 99;
uint32_t h = x;
if (y < GPR_ARRAY_SIZE(elems_r)) {
- uint32_t delta = (uint32_t)elems_r[y];
+ uint32_t delta = static_cast<uint32_t>(elems_r[y]);
h += delta;
}
return h;
@@ -371,7 +371,7 @@ static const uint8_t elem_idxs[] = {
grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) {
if (a == -1 || b == -1) return GRPC_MDNULL;
- uint32_t k = (uint32_t)(a * 101 + b);
+ uint32_t k = static_cast<uint32_t>(a * 101 + b);
uint32_t h = elems_phash(k);
return h < GPR_ARRAY_SIZE(elem_keys) && elem_keys[h] == k &&
elem_idxs[h] != 255
diff --git a/src/core/lib/transport/timeout_encoding.cc b/src/core/lib/transport/timeout_encoding.cc
index 47f964af45..f47f3fa44b 100644
--- a/src/core/lib/transport/timeout_encoding.cc
+++ b/src/core/lib/transport/timeout_encoding.cc
@@ -98,7 +98,7 @@ int grpc_http2_decode_timeout(grpc_slice text, grpc_millis* timeout) {
;
/* decode numeric part */
for (; p != end && *p >= '0' && *p <= '9'; p++) {
- int32_t digit = (int32_t)(*p - (uint8_t)'0');
+ int32_t digit = static_cast<int32_t>(*p - static_cast<uint8_t>('0'));
have_digit = 1;
/* spec allows max. 8 digits, but we allow values up to 1,000,000,000 */
if (x >= (100 * 1000 * 1000)) {
@@ -138,5 +138,5 @@ int grpc_http2_decode_timeout(grpc_slice text, grpc_millis* timeout) {
return 0;
}
p++;
- return is_all_whitespace((const char*)p, (const char*)end);
+ return is_all_whitespace(reinterpret_cast<const char*>(p), reinterpret_cast<const char*>(end));
}
diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc
index ea0380e591..56fc1ce13e 100644
--- a/src/core/lib/transport/transport.cc
+++ b/src/core/lib/transport/transport.cc
@@ -101,7 +101,7 @@ grpc_slice grpc_slice_from_stream_owned_buffer(grpc_stream_refcount* refcount,
slice_stream_ref(&refcount->slice_refcount);
grpc_slice res;
res.refcount = &refcount->slice_refcount;
- res.data.refcounted.bytes = (uint8_t*)buffer;
+ res.data.refcounted.bytes = static_cast<uint8_t*>(buffer);
res.data.refcounted.length = length;
return res;
}
@@ -233,13 +233,13 @@ typedef struct {
} made_transport_op;
static void destroy_made_transport_op(void* arg, grpc_error* error) {
- made_transport_op* op = (made_transport_op*)arg;
+ made_transport_op* op = static_cast<made_transport_op*>(arg);
GRPC_CLOSURE_SCHED(op->inner_on_complete, GRPC_ERROR_REF(error));
gpr_free(op);
}
grpc_transport_op* grpc_make_transport_op(grpc_closure* on_complete) {
- made_transport_op* op = (made_transport_op*)gpr_malloc(sizeof(*op));
+ made_transport_op* op = static_cast<made_transport_op*>(gpr_malloc(sizeof(*op)));
GRPC_CLOSURE_INIT(&op->outer_on_complete, destroy_made_transport_op, op,
grpc_schedule_on_exec_ctx);
op->inner_on_complete = on_complete;
@@ -256,7 +256,7 @@ typedef struct {
} made_transport_stream_op;
static void destroy_made_transport_stream_op(void* arg, grpc_error* error) {
- made_transport_stream_op* op = (made_transport_stream_op*)arg;
+ made_transport_stream_op* op = static_cast<made_transport_stream_op*>(arg);
grpc_closure* c = op->inner_on_complete;
gpr_free(op);
GRPC_CLOSURE_RUN(c, GRPC_ERROR_REF(error));
@@ -265,7 +265,7 @@ static void destroy_made_transport_stream_op(void* arg, grpc_error* error) {
grpc_transport_stream_op_batch* grpc_make_transport_stream_op(
grpc_closure* on_complete) {
made_transport_stream_op* op =
- (made_transport_stream_op*)gpr_zalloc(sizeof(*op));
+ static_cast<made_transport_stream_op*>(gpr_zalloc(sizeof(*op)));
op->op.payload = &op->payload;
GRPC_CLOSURE_INIT(&op->outer_on_complete, destroy_made_transport_stream_op,
op, grpc_schedule_on_exec_ctx);