diff --git a/.clang-tidy b/.clang-tidy index 1bda6dcde7f..8a1c78a33d4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,7 +11,6 @@ Checks: '-*, -performance-unnecessary-value-param, google-*, -google-explicit-constructor, - -google-readability-casting, -google-runtime-int, -google-runtime-references, misc-definitions-in-headers, diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 8db3029e267..77b806cd050 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -2516,8 +2516,9 @@ void CallData::MaybeCacheSendOpsForBatch(PendingBatch* pending) { GPR_ASSERT(send_initial_metadata_storage_ == nullptr); grpc_metadata_batch* send_initial_metadata = batch->payload->send_initial_metadata.send_initial_metadata; - send_initial_metadata_storage_ = (grpc_linked_mdelem*)arena_->Alloc( - sizeof(grpc_linked_mdelem) * send_initial_metadata->list.count); + send_initial_metadata_storage_ = + static_cast(arena_->Alloc( + sizeof(grpc_linked_mdelem) * send_initial_metadata->list.count)); grpc_metadata_batch_copy(send_initial_metadata, &send_initial_metadata_, send_initial_metadata_storage_); send_initial_metadata_flags_ = @@ -2536,8 +2537,9 @@ void CallData::MaybeCacheSendOpsForBatch(PendingBatch* pending) { GPR_ASSERT(send_trailing_metadata_storage_ == nullptr); grpc_metadata_batch* send_trailing_metadata = batch->payload->send_trailing_metadata.send_trailing_metadata; - send_trailing_metadata_storage_ = (grpc_linked_mdelem*)arena_->Alloc( - sizeof(grpc_linked_mdelem) * send_trailing_metadata->list.count); + send_trailing_metadata_storage_ = + static_cast(arena_->Alloc( + sizeof(grpc_linked_mdelem) * send_trailing_metadata->list.count)); grpc_metadata_batch_copy(send_trailing_metadata, &send_trailing_metadata_, send_trailing_metadata_storage_); } @@ -3039,7 +3041,7 @@ bool CallData::MaybeRetry(grpc_call_element* elem, gpr_log(GPR_INFO, "chand=%p calld=%p: server push-back: retry in %u ms", chand, this, ms); } - server_pushback_ms = (grpc_millis)ms; + server_pushback_ms = static_cast(ms); } } DoRetry(elem, retry_state, server_pushback_ms); diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index 2358415fc2e..5690545cbb7 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -54,7 +54,7 @@ void grpc_client_channel_init(void) { grpc_core::GlobalSubchannelPool::Init(); grpc_channel_init_register_stage( GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter, - (void*)&grpc_client_channel_filter); + const_cast(&grpc_client_channel_filter)); grpc_http_connect_register_handshaker_factory(); grpc_client_channel_global_init_backup_polling(); } diff --git a/src/core/ext/filters/client_channel/http_connect_handshaker.cc b/src/core/ext/filters/client_channel/http_connect_handshaker.cc index 979248e279f..f469a5a9001 100644 --- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc +++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc @@ -332,7 +332,7 @@ void HttpConnectHandshaker::DoHandshake(grpc_tcp_server_acceptor* /*acceptor*/, grpc_httpcli_request request; request.host = server_name; request.ssl_host_override = nullptr; - request.http.method = (char*)"CONNECT"; + request.http.method = const_cast("CONNECT"); request.http.path = server_name; request.http.version = GRPC_HTTP_HTTP10; // Set by OnReadDone request.http.hdrs = headers; diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 9bd3fe3e015..8425a7afccd 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -172,7 +172,7 @@ class HttpProxyMapper : public ProxyMapperInterface { } grpc_arg args_to_add[2]; args_to_add[0] = grpc_channel_arg_string_create( - (char*)GRPC_ARG_HTTP_CONNECT_SERVER, + const_cast(GRPC_ARG_HTTP_CONNECT_SERVER), uri->path[0] == '/' ? uri->path + 1 : uri->path); if (user_cred != nullptr) { /* Use base64 encoding for user credentials as stated in RFC 7617 */ diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 3ef86206751..edb098bc865 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -491,7 +491,7 @@ bool GrpcLb::Serverlist::operator==(const Serverlist& other) const { void ParseServer(const GrpcLbServer& server, grpc_resolved_address* addr) { memset(addr, 0, sizeof(*addr)); if (server.drop) return; - const uint16_t netorder_port = grpc_htons((uint16_t)server.port); + const uint16_t netorder_port = grpc_htons(static_cast(server.port)); /* the addresses are given in binary format (a in(6)_addr struct) in * server->ip_address.bytes. */ if (server.ip_size == 4) { @@ -502,7 +502,8 @@ void ParseServer(const GrpcLbServer& server, grpc_resolved_address* addr) { addr4->sin_port = netorder_port; } else if (server.ip_size == 16) { addr->len = static_cast(sizeof(grpc_sockaddr_in6)); - grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)&addr->addr; + grpc_sockaddr_in6* addr6 = + reinterpret_cast(&addr->addr); addr6->sin6_family = GRPC_AF_INET6; memcpy(&addr6->sin6_addr, server.ip_addr, server.ip_size); addr6->sin6_port = netorder_port; @@ -532,17 +533,18 @@ bool IsServerValid(const GrpcLbServer& server, size_t idx, bool log) { if (GPR_UNLIKELY(server.port >> 16 != 0)) { if (log) { gpr_log(GPR_ERROR, - "Invalid port '%d' at index %lu of serverlist. Ignoring.", - server.port, (unsigned long)idx); + "Invalid port '%d' at index %" PRIuPTR + " of serverlist. Ignoring.", + server.port, idx); } return false; } if (GPR_UNLIKELY(server.ip_size != 4 && server.ip_size != 16)) { if (log) { gpr_log(GPR_ERROR, - "Expected IP to be 4 or 16 bytes, got %d at index %lu of " - "serverlist. Ignoring", - server.ip_size, (unsigned long)idx); + "Expected IP to be 4 or 16 bytes, got %d at index %" PRIuPTR + " of serverlist. Ignoring", + server.ip_size, idx); } return false; } @@ -844,8 +846,9 @@ void GrpcLb::BalancerCallState::StartQuery() { // with the callback. auto self = Ref(DEBUG_LOCATION, "on_initial_request_sent"); self.release(); - call_error = grpc_call_start_batch_and_execute( - lb_call_, ops, (size_t)(op - ops), &lb_on_initial_request_sent_); + call_error = grpc_call_start_batch_and_execute(lb_call_, ops, + static_cast(op - ops), + &lb_on_initial_request_sent_); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: recv initial metadata. op = ops; @@ -867,7 +870,8 @@ void GrpcLb::BalancerCallState::StartQuery() { self = Ref(DEBUG_LOCATION, "on_message_received"); self.release(); call_error = grpc_call_start_batch_and_execute( - lb_call_, ops, (size_t)(op - ops), &lb_on_balancer_message_received_); + lb_call_, ops, static_cast(op - ops), + &lb_on_balancer_message_received_); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: recv server status. op = ops; @@ -883,7 +887,8 @@ void GrpcLb::BalancerCallState::StartQuery() { // ref instead of a new ref. When it's invoked, it's the initial ref that is // unreffed. call_error = grpc_call_start_batch_and_execute( - lb_call_, ops, (size_t)(op - ops), &lb_on_balancer_status_received_); + lb_call_, ops, static_cast(op - ops), + &lb_on_balancer_status_received_); GPR_ASSERT(GRPC_CALL_OK == call_error); } @@ -1354,7 +1359,7 @@ GrpcLb::GrpcLb(Args args) } GrpcLb::~GrpcLb() { - gpr_free((void*)server_name_); + gpr_free(const_cast(server_name_)); grpc_channel_args_destroy(args_); } @@ -1457,7 +1462,7 @@ void GrpcLb::ProcessAddressesAndChannelArgsLocked( // since we use this to trigger the client_load_reporting filter. static const char* args_to_remove[] = {GRPC_ARG_LB_POLICY_NAME}; grpc_arg new_arg = grpc_channel_arg_string_create( - (char*)GRPC_ARG_LB_POLICY_NAME, (char*)"grpclb"); + const_cast(GRPC_ARG_LB_POLICY_NAME), const_cast("grpclb")); grpc_channel_args_destroy(args_); args_ = grpc_channel_args_copy_and_add_and_remove( &args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), &new_arg, 1); @@ -1766,7 +1771,8 @@ bool maybe_add_client_load_reporting_filter(grpc_channel_stack_builder* builder, // will minimize the number of metadata elements that the filter // needs to iterate through to find the ClientStats object. return grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, nullptr, nullptr); + builder, static_cast(arg), nullptr, + nullptr); } return true; } @@ -1777,10 +1783,10 @@ void grpc_lb_policy_grpclb_init() { grpc_core::LoadBalancingPolicyRegistry::Builder:: RegisterLoadBalancingPolicyFactory( absl::make_unique()); - grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, - GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_client_load_reporting_filter, - (void*)&grpc_client_load_reporting_filter); + grpc_channel_init_register_stage( + GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, + maybe_add_client_load_reporting_filter, + const_cast(&grpc_client_load_reporting_filter)); } void grpc_lb_policy_grpclb_shutdown() {} diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc index 062f4830e31..ff18f768a47 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc @@ -43,8 +43,8 @@ namespace grpc_core { class GrpcPolledFdPosix : public GrpcPolledFd { public: GrpcPolledFdPosix(ares_socket_t as, grpc_pollset_set* driver_pollset_set) - : name_(absl::StrCat("c-ares fd: ", (int)as)), as_(as) { - fd_ = grpc_fd_create((int)as, name_.c_str(), false); + : name_(absl::StrCat("c-ares fd: ", static_cast(as))), as_(as) { + fd_ = grpc_fd_create(static_cast(as), name_.c_str(), false); driver_pollset_set_ = driver_pollset_set; grpc_pollset_set_add_fd(driver_pollset_set_, fd_); } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index 27a8d753c6e..2fd902d0338 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -139,8 +139,8 @@ void grpc_cares_wrapper_address_sorting_sort(const grpc_ares_request* r, if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_cares_address_sorting)) { log_address_sorting_list(r, *addresses, "input"); } - address_sorting_sortable* sortables = (address_sorting_sortable*)gpr_zalloc( - sizeof(address_sorting_sortable) * addresses->size()); + address_sorting_sortable* sortables = static_cast( + gpr_zalloc(sizeof(address_sorting_sortable) * addresses->size())); for (size_t i = 0; i < addresses->size(); ++i) { sortables[i].user_data = &(*addresses)[i]; memcpy(&sortables[i].dest_addr.addr, &(*addresses)[i].address().addr, diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc index 005de558ad7..8b405f717e0 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -339,7 +339,7 @@ grpc_arg FakeResolverResponseGenerator::MakeChannelArg( FakeResolverResponseGenerator* generator) { grpc_arg arg; arg.type = GRPC_ARG_POINTER; - arg.key = (char*)GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR; + arg.key = const_cast(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR); arg.value.pointer.p = generator; arg.value.pointer.vtable = &response_generator_arg_vtable; return arg; diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index d5c17602e4d..6834ec65224 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -189,7 +189,8 @@ void SubchannelCall::StartTransportStreamOpBatch( void* SubchannelCall::GetParentData() { grpc_channel_stack* chanstk = connected_subchannel_->channel_stack(); - return (char*)this + GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(SubchannelCall)) + + return reinterpret_cast(this) + + GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(SubchannelCall)) + GPR_ROUND_UP_TO_ALIGNMENT_SIZE(chanstk->call_stack_size); } @@ -702,7 +703,7 @@ Subchannel::Subchannel(SubchannelKey* key, const grpc_integer_options options = { GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX}; size_t channel_tracer_max_memory = - (size_t)grpc_channel_arg_get_integer(arg, options); + static_cast(grpc_channel_arg_get_integer(arg, options)); if (channelz_enabled) { channelz_node_ = MakeRefCounted( GetTargetAddress(), channel_tracer_max_memory); @@ -912,7 +913,7 @@ void Subchannel::ResetBackoff() { grpc_arg Subchannel::CreateSubchannelAddressArg( const grpc_resolved_address* addr) { return grpc_channel_arg_string_create( - (char*)GRPC_ARG_SUBCHANNEL_ADDRESS, + const_cast(GRPC_ARG_SUBCHANNEL_ADDRESS), gpr_strdup(addr->len > 0 ? grpc_sockaddr_to_uri(addr).c_str() : "")); } diff --git a/src/core/ext/filters/deadline/deadline_filter.cc b/src/core/ext/filters/deadline/deadline_filter.cc index bd168444f8a..837e337b64b 100644 --- a/src/core/ext/filters/deadline/deadline_filter.cc +++ b/src/core/ext/filters/deadline/deadline_filter.cc @@ -383,10 +383,12 @@ static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder, void grpc_deadline_filter_init(void) { grpc_channel_init_register_stage( GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_deadline_filter, (void*)&grpc_client_deadline_filter); + maybe_add_deadline_filter, + const_cast(&grpc_client_deadline_filter)); grpc_channel_init_register_stage( GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_deadline_filter, (void*)&grpc_server_deadline_filter); + maybe_add_deadline_filter, + const_cast(&grpc_server_deadline_filter)); } void grpc_deadline_filter_shutdown(void) {} diff --git a/src/core/ext/filters/http/client_authority_filter.cc b/src/core/ext/filters/http/client_authority_filter.cc index 2c3cae6adbc..9511d2591a3 100644 --- a/src/core/ext/filters/http/client_authority_filter.cc +++ b/src/core/ext/filters/http/client_authority_filter.cc @@ -148,12 +148,12 @@ static bool add_client_authority_filter(grpc_channel_stack_builder* builder, } void grpc_client_authority_filter_init(void) { - grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, - add_client_authority_filter, - (void*)&grpc_client_authority_filter); - grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, - add_client_authority_filter, - (void*)&grpc_client_authority_filter); + grpc_channel_init_register_stage( + GRPC_CLIENT_SUBCHANNEL, INT_MAX, add_client_authority_filter, + const_cast(&grpc_client_authority_filter)); + grpc_channel_init_register_stage( + GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, add_client_authority_filter, + const_cast(&grpc_client_authority_filter)); } void grpc_client_authority_filter_shutdown(void) {} diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index 637dc3030f2..d5577d56145 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -93,13 +93,16 @@ void grpc_http_filters_init(void) { maybe_add_optional_filter, &decompress_filter); grpc_channel_init_register_stage( GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_required_filter, (void*)&grpc_http_client_filter); + maybe_add_required_filter, + const_cast(&grpc_http_client_filter)); grpc_channel_init_register_stage( GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_required_filter, (void*)&grpc_http_client_filter); + maybe_add_required_filter, + const_cast(&grpc_http_client_filter)); grpc_channel_init_register_stage( GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_required_filter, (void*)&grpc_http_server_filter); + maybe_add_required_filter, + const_cast(&grpc_http_server_filter)); } void grpc_http_filters_shutdown(void) {} diff --git a/src/core/ext/filters/message_size/message_size_filter.cc b/src/core/ext/filters/message_size/message_size_filter.cc index 78e70542bf8..10a58d98066 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -302,7 +302,7 @@ static grpc_error* message_size_init_call_elem( static void message_size_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(elem->call_data); calld->~call_data(); } diff --git a/src/core/ext/filters/workarounds/workaround_utils.cc b/src/core/ext/filters/workarounds/workaround_utils.cc index 4dabe896d3b..2a184ba895f 100644 --- a/src/core/ext/filters/workarounds/workaround_utils.cc +++ b/src/core/ext/filters/workarounds/workaround_utils.cc @@ -42,7 +42,7 @@ grpc_workaround_user_agent_md* grpc_parse_user_agent(grpc_mdelem md) { user_agent_md->workaround_active[i] = ua_parser[i](md); } } - grpc_mdelem_set_user_data(md, destroy_user_agent_md, (void*)user_agent_md); + grpc_mdelem_set_user_data(md, destroy_user_agent_md, user_agent_md); return user_agent_md; } diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index ef2d7fd11ba..27e64fb8f3e 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -42,7 +42,8 @@ grpc_channel* grpc_insecure_channel_create_from_fd( (target, fd, args)); grpc_arg default_authority_arg = grpc_channel_arg_string_create( - (char*)GRPC_ARG_DEFAULT_AUTHORITY, (char*)"test.authority"); + const_cast(GRPC_ARG_DEFAULT_AUTHORITY), + const_cast("test.authority")); grpc_channel_args* final_args = grpc_channel_args_copy_and_add(args, &default_authority_arg, 1); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 1b5ce21bc52..900cd3cc053 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -616,7 +616,7 @@ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t, metadata_buffer{grpc_chttp2_incoming_metadata_buffer(arena), grpc_chttp2_incoming_metadata_buffer(arena)} { if (server_data) { - id = static_cast((uintptr_t)server_data); + id = static_cast(reinterpret_cast(server_data)); *t->accepting_stream = this; grpc_chttp2_stream_map_add(&t->stream_map, id, this); post_destructive_reclaimer(t); @@ -749,7 +749,7 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; t->accept_stream_cb(t->accept_stream_cb_user_data, &t->base, - (void*)static_cast(id)); + reinterpret_cast(id)); t->accepting_stream = nullptr; return accepting; } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index 6711996683e..4b5a3ff29a3 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -1059,8 +1059,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { unsigned int header_index; for (header_index = 0; header_index < s->header_array.count; header_index++) { - gpr_free((void*)s->header_array.headers[header_index].key); - gpr_free((void*)s->header_array.headers[header_index].value); + gpr_free(const_cast(s->header_array.headers[header_index].key)); + gpr_free(const_cast(s->header_array.headers[header_index].value)); } stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; if (t->use_packet_coalescing) { diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 92afeca69dd..213c142b974 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -153,10 +153,11 @@ struct inproc_stream { // side to avoid destruction INPROC_LOG(GPR_INFO, "calling accept stream cb %p %p", st->accept_stream_cb, st->accept_stream_data); - (*st->accept_stream_cb)(st->accept_stream_data, &st->base, (void*)this); + (*st->accept_stream_cb)(st->accept_stream_data, &st->base, this); } else { // This is the server-side and is being called through accept_stream_cb - inproc_stream* cs = (inproc_stream*)server_data; + inproc_stream* cs = const_cast( + static_cast(server_data)); other_side = cs; // Ref the server-side stream on behalf of the client now ref("inproc_init_stream:srv"); @@ -1281,8 +1282,8 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, // Add a default authority channel argument for the client grpc_arg default_authority_arg; default_authority_arg.type = GRPC_ARG_STRING; - default_authority_arg.key = (char*)GRPC_ARG_DEFAULT_AUTHORITY; - default_authority_arg.value.string = (char*)"inproc.authority"; + default_authority_arg.key = const_cast(GRPC_ARG_DEFAULT_AUTHORITY); + default_authority_arg.value.string = const_cast("inproc.authority"); grpc_channel_args* client_args = grpc_channel_args_copy_and_add(args, &default_authority_arg, 1); diff --git a/src/core/ext/xds/xds_client.cc b/src/core/ext/xds/xds_client.cc index 3d2832e2873..c9dad45bc82 100644 --- a/src/core/ext/xds/xds_client.cc +++ b/src/core/ext/xds/xds_client.cc @@ -707,8 +707,8 @@ XdsClient::ChannelState::AdsCallState::AdsCallState( GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET; op->reserved = nullptr; op++; - call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops), - nullptr); + call_error = grpc_call_start_batch_and_execute( + call_, ops, static_cast(op - ops), nullptr); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: send request message. GRPC_CLOSURE_INIT(&on_request_sent_, OnRequestSent, this, @@ -742,8 +742,8 @@ XdsClient::ChannelState::AdsCallState::AdsCallState( Ref(DEBUG_LOCATION, "ADS+OnResponseReceivedLocked").release(); GRPC_CLOSURE_INIT(&on_response_received_, OnResponseReceived, this, grpc_schedule_on_exec_ctx); - call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops), - &on_response_received_); + call_error = grpc_call_start_batch_and_execute( + call_, ops, static_cast(op - ops), &on_response_received_); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: recv server status. op = ops; @@ -759,8 +759,8 @@ XdsClient::ChannelState::AdsCallState::AdsCallState( // unreffed. GRPC_CLOSURE_INIT(&on_status_received_, OnStatusReceived, this, grpc_schedule_on_exec_ctx); - call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops), - &on_status_received_); + call_error = grpc_call_start_batch_and_execute( + call_, ops, static_cast(op - ops), &on_status_received_); GPR_ASSERT(GRPC_CALL_OK == call_error); } @@ -1479,8 +1479,8 @@ XdsClient::ChannelState::LrsCallState::LrsCallState( Ref(DEBUG_LOCATION, "LRS+OnInitialRequestSentLocked").release(); GRPC_CLOSURE_INIT(&on_initial_request_sent_, OnInitialRequestSent, this, grpc_schedule_on_exec_ctx); - call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops), - &on_initial_request_sent_); + call_error = grpc_call_start_batch_and_execute( + call_, ops, static_cast(op - ops), &on_initial_request_sent_); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: recv initial metadata. op = ops; @@ -1499,8 +1499,8 @@ XdsClient::ChannelState::LrsCallState::LrsCallState( Ref(DEBUG_LOCATION, "LRS+OnResponseReceivedLocked").release(); GRPC_CLOSURE_INIT(&on_response_received_, OnResponseReceived, this, grpc_schedule_on_exec_ctx); - call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops), - &on_response_received_); + call_error = grpc_call_start_batch_and_execute( + call_, ops, static_cast(op - ops), &on_response_received_); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: recv server status. op = ops; @@ -1516,8 +1516,8 @@ XdsClient::ChannelState::LrsCallState::LrsCallState( // unreffed. GRPC_CLOSURE_INIT(&on_status_received_, OnStatusReceived, this, grpc_schedule_on_exec_ctx); - call_error = grpc_call_start_batch_and_execute(call_, ops, (size_t)(op - ops), - &on_status_received_); + call_error = grpc_call_start_batch_and_execute( + call_, ops, static_cast(op - ops), &on_status_received_); GPR_ASSERT(GRPC_CALL_OK == call_error); } diff --git a/src/core/lib/compression/compression_args.cc b/src/core/lib/compression/compression_args.cc index 6bbda64e263..03e1a8881b6 100644 --- a/src/core/lib/compression/compression_args.cc +++ b/src/core/lib/compression/compression_args.cc @@ -55,7 +55,7 @@ grpc_channel_args* grpc_channel_args_set_channel_default_compression_algorithm( GPR_ASSERT(algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT); grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char*)GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM; + tmp.key = const_cast(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM); tmp.value.integer = algorithm; return grpc_channel_args_copy_and_add(a, &tmp, 1); } @@ -108,7 +108,8 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( /* create a new arg */ grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char*)GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET; + tmp.key = + const_cast(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET); /* all enabled by default */ tmp.value.integer = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; if (state != 0) { diff --git a/src/core/lib/gpr/alloc.cc b/src/core/lib/gpr/alloc.cc index 8c7345b7db5..5bfdc8d1562 100644 --- a/src/core/lib/gpr/alloc.cc +++ b/src/core/lib/gpr/alloc.cc @@ -66,9 +66,10 @@ void* gpr_malloc_aligned(size_t size, size_t alignment) { GPR_ASSERT(((alignment - 1) & alignment) == 0); // Must be power of 2. size_t extra = alignment - 1 + sizeof(void*); void* p = gpr_malloc(size + extra); - void** ret = (void**)(((uintptr_t)p + extra) & ~(alignment - 1)); + void** ret = reinterpret_cast( + (reinterpret_cast(p) + extra) & ~(alignment - 1)); ret[-1] = p; - return (void*)ret; + return ret; } void gpr_free_aligned(void* ptr) { gpr_free((static_cast(ptr))[-1]); } diff --git a/src/core/lib/gpr/log.cc b/src/core/lib/gpr/log.cc index 4ce53017fd9..9a5a54f666a 100644 --- a/src/core/lib/gpr/log.cc +++ b/src/core/lib/gpr/log.cc @@ -38,7 +38,7 @@ static constexpr gpr_atm GPR_LOG_SEVERITY_UNSET = GPR_LOG_SEVERITY_ERROR + 10; static constexpr gpr_atm GPR_LOG_SEVERITY_NONE = GPR_LOG_SEVERITY_ERROR + 11; void gpr_default_log(gpr_log_func_args* args); -static gpr_atm g_log_func = (gpr_atm)gpr_default_log; +static gpr_atm g_log_func = reinterpret_cast(gpr_default_log); static gpr_atm g_min_severity_to_print = GPR_LOG_SEVERITY_UNSET; static gpr_atm g_min_severity_to_print_stacktrace = GPR_LOG_SEVERITY_UNSET; @@ -80,7 +80,7 @@ void gpr_log_message(const char* file, int line, gpr_log_severity severity, lfargs.line = line; lfargs.severity = severity; lfargs.message = message; - ((gpr_log_func)gpr_atm_no_barrier_load(&g_log_func))(&lfargs); + reinterpret_cast(gpr_atm_no_barrier_load(&g_log_func))(&lfargs); } void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print) { diff --git a/src/core/lib/gpr/string.cc b/src/core/lib/gpr/string.cc index 24376645d1e..cbafdfcd29e 100644 --- a/src/core/lib/gpr/string.cc +++ b/src/core/lib/gpr/string.cc @@ -55,7 +55,7 @@ char* gpr_strdup(const char* src) { std::string gpr_format_timespec(gpr_timespec tm) { char time_buffer[35]; char ns_buffer[11]; // '.' + 9 digits of precision - struct tm* tm_info = localtime((const time_t*)&tm.tv_sec); + struct tm* tm_info = localtime(reinterpret_cast(&tm.tv_sec)); strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%dT%H:%M:%S", tm_info); snprintf(ns_buffer, 11, ".%09d", tm.tv_nsec); // This loop trims off trailing zeros by inserting a null character that the @@ -119,7 +119,8 @@ 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, (isprint(*cur) ? *(char*)cur : '.')); + dump_out_append( + out, (isprint(*cur) ? *reinterpret_cast(cur) : '.')); } if (!out_was_empty) { dump_out_append(out, '\''); @@ -311,7 +312,7 @@ void gpr_string_split(const char* input, const char* sep, char*** strs, void* gpr_memrchr(const void* s, int c, size_t n) { if (s == nullptr) return nullptr; - char* b = (char*)s; + char* b = const_cast(reinterpret_cast(s)); size_t i; for (i = 0; i < n; i++) { if (b[n - i - 1] == c) { diff --git a/src/core/lib/gpr/sync.cc b/src/core/lib/gpr/sync.cc index 2f18fc5ecb4..36c35da38df 100644 --- a/src/core/lib/gpr/sync.cc +++ b/src/core/lib/gpr/sync.cc @@ -48,7 +48,7 @@ static void event_initialize(void) { /* Hash ev into an element of sync_array[]. */ static struct sync_array_s* hash(gpr_event* ev) { - return &sync_array[((uintptr_t)ev) % event_sync_partitions]; + return &sync_array[reinterpret_cast(ev) % event_sync_partitions]; } void gpr_event_init(gpr_event* ev) { @@ -67,16 +67,16 @@ void gpr_event_set(gpr_event* ev, void* value) { } void* gpr_event_get(gpr_event* ev) { - return (void*)gpr_atm_acq_load(&ev->state); + return reinterpret_cast(gpr_atm_acq_load(&ev->state)); } void* gpr_event_wait(gpr_event* ev, gpr_timespec abs_deadline) { - void* result = (void*)gpr_atm_acq_load(&ev->state); + void* result = reinterpret_cast(gpr_atm_acq_load(&ev->state)); if (result == nullptr) { struct sync_array_s* s = hash(ev); gpr_mu_lock(&s->mu); do { - result = (void*)gpr_atm_acq_load(&ev->state); + result = reinterpret_cast(gpr_atm_acq_load(&ev->state)); } while (result == nullptr && !gpr_cv_wait(&s->cv, &s->mu, abs_deadline)); gpr_mu_unlock(&s->mu); } diff --git a/src/core/lib/gprpp/thd_posix.cc b/src/core/lib/gprpp/thd_posix.cc index b441ae46cb9..c3449bdacfd 100644 --- a/src/core/lib/gprpp/thd_posix.cc +++ b/src/core/lib/gprpp/thd_posix.cc @@ -199,6 +199,11 @@ Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, } // namespace grpc_core // The following is in the external namespace as it is exposed as C89 API -gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)pthread_self(); } +gpr_thd_id gpr_thd_currentid(void) { + // Use C-style casting because Linux and OSX have different definitions + // of pthread_t so that a single C++ cast doesn't handle it. + // NOLINTNEXTLINE(google-readability-casting) + return (gpr_thd_id)pthread_self(); +} #endif /* GPR_POSIX_SYNC */ diff --git a/src/core/lib/gprpp/thd_windows.cc b/src/core/lib/gprpp/thd_windows.cc index bd3b7a36ebb..fb90afd0f70 100644 --- a/src/core/lib/gprpp/thd_windows.cc +++ b/src/core/lib/gprpp/thd_windows.cc @@ -171,6 +171,8 @@ Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, } // namespace grpc_core -gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)g_thd_info; } +gpr_thd_id gpr_thd_currentid(void) { + return reinterpret_cast(g_thd_info); +} #endif /* GPR_WINDOWS */ diff --git a/src/core/lib/http/httpcli.cc b/src/core/lib/http/httpcli.cc index bf93552df7a..8d024dd3ac5 100644 --- a/src/core/lib/http/httpcli.cc +++ b/src/core/lib/http/httpcli.cc @@ -209,7 +209,7 @@ static void next_address(internal_request* req, grpc_error* error) { GRPC_CLOSURE_INIT(&req->connected, on_connected, req, grpc_schedule_on_exec_ctx); grpc_arg arg = grpc_channel_arg_pointer_create( - (char*)GRPC_ARG_RESOURCE_QUOTA, req->resource_quota, + const_cast(GRPC_ARG_RESOURCE_QUOTA), req->resource_quota, grpc_resource_quota_arg_vtable()); grpc_channel_args args = {1, &arg}; grpc_tcp_client_connect(&req->connected, &req->ep, req->context->pollset_set, diff --git a/src/core/lib/http/parser.cc b/src/core/lib/http/parser.cc index b95a942f706..3a0b2be4a85 100644 --- a/src/core/lib/http/parser.cc +++ b/src/core/lib/http/parser.cc @@ -281,8 +281,7 @@ 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 = - static_cast(gpr_realloc((void*)*body, parser->body_capacity)); + *body = static_cast(gpr_realloc(*body, parser->body_capacity)); } (*body)[*body_length] = static_cast(byte); (*body_length)++; diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index ed0ae174887..043b3bb4032 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -34,13 +34,14 @@ namespace { grpc_error* DecodeCancelStateError(gpr_atm cancel_state) { if (cancel_state & 1) { - return (grpc_error*)(cancel_state & ~static_cast(1)); + return reinterpret_cast(cancel_state & + ~static_cast(1)); } return GRPC_ERROR_NONE; } gpr_atm EncodeCancelStateError(grpc_error* error) { - return static_cast(1) | (gpr_atm)error; + return static_cast(1) | reinterpret_cast(error); } } // namespace @@ -203,7 +204,8 @@ void CallCombiner::SetNotifyOnCancel(grpc_closure* closure) { ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_REF(original_error)); break; } else { - if (gpr_atm_full_cas(&cancel_state_, original_state, (gpr_atm)closure)) { + if (gpr_atm_full_cas(&cancel_state_, original_state, + reinterpret_cast(closure))) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { gpr_log(GPR_INFO, "call_combiner=%p: setting notify_on_cancel=%p", this, closure); @@ -212,7 +214,7 @@ void CallCombiner::SetNotifyOnCancel(grpc_closure* closure) { // closure with GRPC_ERROR_NONE. This allows callers to clean // up any resources they may be holding for the callback. if (original_state != 0) { - closure = (grpc_closure*)original_state; + closure = reinterpret_cast(original_state); if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { gpr_log(GPR_INFO, "call_combiner=%p: scheduling old cancel callback=%p", this, @@ -239,7 +241,8 @@ void CallCombiner::Cancel(grpc_error* error) { if (gpr_atm_full_cas(&cancel_state_, original_state, EncodeCancelStateError(error))) { if (original_state != 0) { - grpc_closure* notify_on_cancel = (grpc_closure*)original_state; + grpc_closure* notify_on_cancel = + reinterpret_cast(original_state); if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { gpr_log(GPR_INFO, "call_combiner=%p: scheduling notify_on_cancel callback=%p", diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 4b85766aef6..aa5a2ea44f4 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -146,7 +146,8 @@ static void combiner_exec(grpc_core::Combiner* lock, grpc_closure* cl, // offload for one or two actions, and that's fine gpr_atm initiator = gpr_atm_no_barrier_load(&lock->initiating_exec_ctx_or_null); - if (initiator != 0 && initiator != (gpr_atm)grpc_core::ExecCtx::Get()) { + if (initiator != 0 && + initiator != reinterpret_cast(grpc_core::ExecCtx::Get())) { gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, 0); } } diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index b57c10c50c6..091014593ee 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -166,7 +166,8 @@ static void error_destroy(grpc_error* err) { GPR_ASSERT(!grpc_error_is_special(err)); unref_errs(err); unref_strs(err); - gpr_free((void*)gpr_atm_acq_load(&err->atomics.error_string)); + gpr_free( + reinterpret_cast(gpr_atm_acq_load(&err->atomics.error_string))); gpr_free(err); } @@ -237,10 +238,10 @@ static void internal_set_str(grpc_error** err, grpc_error_strs which, if (slot == UINT8_MAX) { slot = get_placement(err, sizeof(value)); if (slot == UINT8_MAX) { - const char* str = grpc_slice_to_c_string(value); + char* str = grpc_slice_to_c_string(value); gpr_log(GPR_ERROR, "Error %p is full, dropping string {\"%s\":\"%s\"}", *err, error_str_name(which), str); - gpr_free((void*)str); + gpr_free(str); return; } } else { @@ -258,10 +259,10 @@ static void internal_set_time(grpc_error** err, grpc_error_times which, if (slot == UINT8_MAX) { slot = get_placement(err, sizeof(value)); if (slot == UINT8_MAX) { - const char* time_str = fmt_time(value); + char* time_str = fmt_time(value); gpr_log(GPR_ERROR, "Error %p is full, dropping \"%s\":\"%s\"}", *err, error_time_name(which), time_str); - gpr_free((void*)time_str); + gpr_free(time_str); return; } } @@ -426,7 +427,8 @@ static grpc_error* copy_error_and_unref(grpc_error* in) { // bulk memcpy of the rest of the struct. // NOLINTNEXTLINE(bugprone-sizeof-expression) size_t skip = sizeof(&out->atomics); - memcpy((void*)((uintptr_t)out + skip), (void*)((uintptr_t)in + skip), + memcpy(reinterpret_cast(reinterpret_cast(out) + skip), + reinterpret_cast(reinterpret_cast(in) + skip), sizeof(*in) + (in->arena_size * sizeof(intptr_t)) - skip); // manually set the atomics and the new capacity gpr_atm_no_barrier_store(&out->atomics.error_string, 0); @@ -632,8 +634,8 @@ static char* fmt_str(const grpc_slice& slice) { char* s = nullptr; size_t sz = 0; size_t cap = 0; - append_esc_str((const uint8_t*)GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_LENGTH(slice), &s, &sz, &cap); + append_esc_str(GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice), &s, &sz, + &cap); append_chr(0, &s, &sz, &cap); return s; } @@ -744,7 +746,8 @@ const char* grpc_error_string(grpc_error* err) { if (err == GRPC_ERROR_OOM) return oom_error_string; if (err == GRPC_ERROR_CANCELLED) return cancelled_error_string; - void* p = (void*)gpr_atm_acq_load(&err->atomics.error_string); + void* p = + reinterpret_cast(gpr_atm_acq_load(&err->atomics.error_string)); if (p != nullptr) { return static_cast(p); } @@ -763,9 +766,10 @@ const char* grpc_error_string(grpc_error* err) { char* out = finish_kvs(&kvs); - if (!gpr_atm_rel_cas(&err->atomics.error_string, 0, (gpr_atm)out)) { + if (!gpr_atm_rel_cas(&err->atomics.error_string, 0, + reinterpret_cast(out))) { gpr_free(out); - out = (char*)gpr_atm_acq_load(&err->atomics.error_string); + out = reinterpret_cast(gpr_atm_acq_load(&err->atomics.error_string)); } return out; diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 7a257bca308..8a1013da21f 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -803,7 +803,8 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, neighborhood->active_root = pollset->next = pollset->prev = pollset; /* Make this the designated poller if there isn't one already */ if (worker->state == UNKICKED && - gpr_atm_no_barrier_cas(&g_active_poller, 0, (gpr_atm)worker)) { + gpr_atm_no_barrier_cas(&g_active_poller, 0, + reinterpret_cast(worker))) { SET_KICK_STATE(worker, DESIGNATED_POLLER); } } else { @@ -885,8 +886,9 @@ static bool check_neighborhood_for_available_poller( do { switch (inspect_worker->state) { case UNKICKED: - if (gpr_atm_no_barrier_cas(&g_active_poller, 0, - (gpr_atm)inspect_worker)) { + if (gpr_atm_no_barrier_cas( + &g_active_poller, 0, + reinterpret_cast(inspect_worker))) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, " .. choose next poller to be %p", inspect_worker); @@ -944,7 +946,8 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, SET_KICK_STATE(worker, KICKED); grpc_closure_list_move(&worker->schedule_on_end_work, grpc_core::ExecCtx::Get()->closure_list()); - if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { + if (gpr_atm_no_barrier_load(&g_active_poller) == + reinterpret_cast(worker)) { if (worker->next != worker && worker->next->state == UNKICKED) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, " .. choose next poller to be peer %p", worker); @@ -1071,8 +1074,9 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, std::vector log; log.push_back(absl::StrFormat( "PS:%p KICK:%p curps=%p curworker=%p root=%p", pollset, specific_worker, - (void*)gpr_tls_get(&g_current_thread_pollset), - (void*)gpr_tls_get(&g_current_thread_worker), pollset->root_worker)); + reinterpret_cast(gpr_tls_get(&g_current_thread_pollset)), + reinterpret_cast(gpr_tls_get(&g_current_thread_worker)), + pollset->root_worker)); if (pollset->root_worker != nullptr) { log.push_back(absl::StrFormat( " {kick_state=%s next=%p {kick_state=%s}}", @@ -1088,7 +1092,8 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } if (specific_worker == nullptr) { - if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { + if (gpr_tls_get(&g_current_thread_pollset) != + reinterpret_cast(pollset)) { grpc_pollset_worker* root_worker = pollset->root_worker; if (root_worker == nullptr) { GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); @@ -1115,8 +1120,9 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, goto done; } else if (root_worker == next_worker && // only try and wake up a poller // if there is no next worker - root_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load( - &g_active_poller)) { + root_worker == + reinterpret_cast( + gpr_atm_no_barrier_load(&g_active_poller))) { GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, " .. kicked %p", root_worker); @@ -1180,7 +1186,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } goto done; } else if (gpr_tls_get(&g_current_thread_worker) == - (intptr_t)specific_worker) { + reinterpret_cast(specific_worker)) { GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, " .. mark %p kicked", specific_worker); @@ -1188,7 +1194,8 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, SET_KICK_STATE(specific_worker, KICKED); goto done; } else if (specific_worker == - (grpc_pollset_worker*)gpr_atm_no_barrier_load(&g_active_poller)) { + reinterpret_cast( + gpr_atm_no_barrier_load(&g_active_poller))) { GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, " .. kick active poller"); @@ -1223,7 +1230,7 @@ static void pollset_add_fd(grpc_pollset* /*pollset*/, grpc_fd* /*fd*/) {} */ static grpc_pollset_set* pollset_set_create(void) { - return (grpc_pollset_set*)(static_cast(0xdeafbeef)); + return reinterpret_cast(static_cast(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 d3392f34c12..acd095a43ed 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -577,7 +577,8 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { } struct epoll_event ev; ev.events = static_cast(EPOLLIN | EPOLLET); - ev.data.ptr = (void*)(1 | (intptr_t) & (*p)->wakeup); + ev.data.ptr = + reinterpret_cast(1 | reinterpret_cast(&(*p)->wakeup)); if (epoll_ctl(epfd, EPOLL_CTL_ADD, (*p)->wakeup.read_fd, &ev) != 0) { err = GRPC_OS_ERROR(errno, "epoll_ctl"); GRPC_FD_TRACE( @@ -692,7 +693,8 @@ static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) { GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); return GRPC_ERROR_NONE; } - if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { + if (gpr_tls_get(&g_current_thread_worker) == + reinterpret_cast(specific_worker)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, "PS:%p kicked_specific_but_awake", p); } @@ -729,13 +731,14 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, GRPC_STATS_INC_POLLSET_KICK(); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, - "PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p", - pollset, specific_worker, - (void*)gpr_tls_get(&g_current_thread_pollset), - (void*)gpr_tls_get(&g_current_thread_worker), pollset->root_worker); + "PS:%p kick %p tls_pollset=%" PRIxPTR " tls_worker=%" PRIxPTR + " pollset.root_worker=%p", + pollset, specific_worker, gpr_tls_get(&g_current_thread_pollset), + gpr_tls_get(&g_current_thread_worker), pollset->root_worker); } if (specific_worker == nullptr) { - if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { + if (gpr_tls_get(&g_current_thread_pollset) != + reinterpret_cast(pollset)) { if (pollset->root_worker == nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, "PS:%p kicked_any_without_poller", pollset); @@ -881,15 +884,16 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset, int n = pollable_obj->event_cursor++; struct epoll_event* ev = &pollable_obj->events[n]; void* data_ptr = ev->data.ptr; - if (1 & (intptr_t)data_ptr) { + if (1 & reinterpret_cast(data_ptr)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, "PS:%p got pollset_wakeup %p", pollset, data_ptr); } - append_error(&error, - grpc_wakeup_fd_consume_wakeup( - (grpc_wakeup_fd*)((~static_cast(1)) & - (intptr_t)data_ptr)), - err_desc); + append_error( + &error, + grpc_wakeup_fd_consume_wakeup(reinterpret_cast( + ~static_cast(1) & + reinterpret_cast(data_ptr))), + err_desc); } else { grpc_fd* fd = reinterpret_cast(reinterpret_cast(data_ptr) & ~2); diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 7d40c801e13..e58d1d39c48 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -775,7 +775,7 @@ static grpc_error* pollset_kick_ext(grpc_pollset* p, } p->kicked_without_pollers = true; } else if (gpr_tls_get(&g_current_thread_worker) != - (intptr_t)specific_worker) { + reinterpret_cast(specific_worker)) { GPR_TIMER_MARK("different_thread_worker", 0); if ((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) != 0) { specific_worker->reevaluate_polling_on_wakeup = true; @@ -792,18 +792,20 @@ static grpc_error* pollset_kick_ext(grpc_pollset* p, kick_append_error(&error, grpc_wakeup_fd_wakeup(&specific_worker->wakeup_fd->fd)); } - } else if (gpr_tls_get(&g_current_thread_poller) != (intptr_t)p) { + } else if (gpr_tls_get(&g_current_thread_poller) != + reinterpret_cast(p)) { GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0); GPR_TIMER_MARK("kick_anonymous", 0); specific_worker = pop_front_worker(p); if (specific_worker != nullptr) { - if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { + if (gpr_tls_get(&g_current_thread_worker) == + reinterpret_cast(specific_worker)) { GPR_TIMER_MARK("kick_anonymous_not_self", 0); push_back_worker(p, specific_worker); specific_worker = pop_front_worker(p); if ((flags & GRPC_POLLSET_CAN_KICK_SELF) == 0 && gpr_tls_get(&g_current_thread_worker) == - (intptr_t)specific_worker) { + reinterpret_cast(specific_worker)) { push_back_worker(p, specific_worker); specific_worker = nullptr; } @@ -987,7 +989,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, void* buf = gpr_malloc(pfd_size + watch_size); pfds = static_cast(buf); watchers = static_cast( - (void*)(static_cast(buf) + pfd_size)); + static_cast((static_cast(buf) + pfd_size))); } fd_count = 0; diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 9f92c9fae21..b1d21bc91e6 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -283,7 +283,8 @@ void Executor::Enqueue(grpc_closure* closure, grpc_error* error, return; } - ThreadState* ts = (ThreadState*)gpr_tls_get(&g_this_thread_state); + ThreadState* ts = + reinterpret_cast(gpr_tls_get(&g_this_thread_state)); if (ts == nullptr) { ts = &thd_state_[GPR_HASH_POINTER(grpc_core::ExecCtx::Get(), cur_thread_count)]; diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 802e3bdcb4d..02646db428d 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -59,7 +59,7 @@ void grpc_iomgr_init() { gpr_cv_init(&g_rcv); grpc_core::Executor::InitAll(); g_root_object.next = g_root_object.prev = &g_root_object; - g_root_object.name = (char*)"root"; + g_root_object.name = const_cast("root"); grpc_iomgr_platform_init(); grpc_timer_list_init(); grpc_core::grpc_errqueue_init(); diff --git a/src/core/lib/iomgr/lockfree_event.cc b/src/core/lib/iomgr/lockfree_event.cc index 82a2c52ad21..b3fd8e0b63f 100644 --- a/src/core/lib/iomgr/lockfree_event.cc +++ b/src/core/lib/iomgr/lockfree_event.cc @@ -96,8 +96,9 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { * referencing it. */ gpr_atm curr = gpr_atm_acq_load(&state_); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_DEBUG, "LockfreeEvent::NotifyOn: %p curr=%p closure=%p", this, - (void*)curr, closure); + gpr_log(GPR_DEBUG, + "LockfreeEvent::NotifyOn: %p curr=%" PRIxPTR " closure=%p", this, + curr, closure); } switch (curr) { case kClosureNotReady: { @@ -108,7 +109,8 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { The release itself pairs with the acquire half of a set_ready full barrier. */ - if (gpr_atm_rel_cas(&state_, kClosureNotReady, (gpr_atm)closure)) { + if (gpr_atm_rel_cas(&state_, kClosureNotReady, + reinterpret_cast(closure))) { return; /* Successful. Return */ } @@ -137,7 +139,8 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { contains a pointer to the shutdown-error). If the fd is shutdown, schedule the closure with the shutdown error */ if ((curr & kShutdownBit) > 0) { - grpc_error* shutdown_err = (grpc_error*)(curr & ~kShutdownBit); + grpc_error* shutdown_err = + reinterpret_cast(curr & ~kShutdownBit); ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "FD Shutdown", &shutdown_err, 1)); @@ -157,13 +160,14 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { } bool LockfreeEvent::SetShutdown(grpc_error* shutdown_error) { - gpr_atm new_state = (gpr_atm)shutdown_error | kShutdownBit; + gpr_atm new_state = reinterpret_cast(shutdown_error) | kShutdownBit; while (true) { gpr_atm curr = gpr_atm_no_barrier_load(&state_); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_DEBUG, "LockfreeEvent::SetShutdown: %p curr=%p err=%s", - &state_, (void*)curr, grpc_error_string(shutdown_error)); + gpr_log(GPR_DEBUG, + "LockfreeEvent::SetShutdown: %p curr=%" PRIxPTR " err=%s", + &state_, curr, grpc_error_string(shutdown_error)); } switch (curr) { case kClosureReady: @@ -190,7 +194,7 @@ bool LockfreeEvent::SetShutdown(grpc_error* shutdown_error) { happens-after on that edge), and a release to pair with anything loading the shutdown state. */ if (gpr_atm_full_cas(&state_, curr, new_state)) { - ExecCtx::Run(DEBUG_LOCATION, (grpc_closure*)curr, + ExecCtx::Run(DEBUG_LOCATION, reinterpret_cast(curr), GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "FD Shutdown", &shutdown_error, 1)); return true; @@ -211,8 +215,8 @@ void LockfreeEvent::SetReady() { gpr_atm curr = gpr_atm_no_barrier_load(&state_); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { - gpr_log(GPR_DEBUG, "LockfreeEvent::SetReady: %p curr=%p", &state_, - (void*)curr); + gpr_log(GPR_DEBUG, "LockfreeEvent::SetReady: %p curr=%" PRIxPTR, &state_, + curr); } switch (curr) { @@ -240,7 +244,8 @@ void LockfreeEvent::SetReady() { spurious set_ready; release pairs with this or the acquire in notify_on (or set_shutdown) */ else if (gpr_atm_full_cas(&state_, curr, kClosureNotReady)) { - ExecCtx::Run(DEBUG_LOCATION, (grpc_closure*)curr, GRPC_ERROR_NONE); + ExecCtx::Run(DEBUG_LOCATION, reinterpret_cast(curr), + GRPC_ERROR_NONE); return; } /* else the state changed again (only possible by either a racing diff --git a/src/core/lib/iomgr/pollset_set_custom.cc b/src/core/lib/iomgr/pollset_set_custom.cc index 2c1df608197..0cc90891c4c 100644 --- a/src/core/lib/iomgr/pollset_set_custom.cc +++ b/src/core/lib/iomgr/pollset_set_custom.cc @@ -23,7 +23,7 @@ #include "src/core/lib/iomgr/pollset_set.h" static grpc_pollset_set* pollset_set_create(void) { - return (grpc_pollset_set*)((intptr_t)0xdeafbeef); + return reinterpret_cast(static_cast(0xdeafbeef)); } static void pollset_set_destroy(grpc_pollset_set* /*pollset_set*/) {} diff --git a/src/core/lib/iomgr/python_util.h b/src/core/lib/iomgr/python_util.h index a8c2fe4148c..05d72a58ad0 100644 --- a/src/core/lib/iomgr/python_util.h +++ b/src/core/lib/iomgr/python_util.h @@ -36,7 +36,7 @@ inline grpc_error* grpc_socket_error(char* error) { } inline char* grpc_slice_buffer_start(grpc_slice_buffer* buffer, int i) { - return (char*)GRPC_SLICE_START_PTR(buffer->slices[i]); + return reinterpret_cast(GRPC_SLICE_START_PTR(buffer->slices[i])); } inline int grpc_slice_buffer_length(grpc_slice_buffer* buffer, int i) { diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index dbe84e3466c..464cccdc861 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -659,8 +659,8 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) { if (name != nullptr) { resource_quota->name = name; } else { - resource_quota->name = - absl::StrCat("anonymous_pool_", (intptr_t)resource_quota); + resource_quota->name = absl::StrCat( + "anonymous_pool_", reinterpret_cast(resource_quota)); } GRPC_CLOSURE_INIT(&resource_quota->rq_step_closure, rq_step, resource_quota, nullptr); @@ -807,8 +807,8 @@ grpc_resource_user* grpc_resource_user_create( if (name != nullptr) { resource_user->name = name; } else { - resource_user->name = - absl::StrCat("anonymous_resource_user_", (intptr_t)resource_user); + resource_user->name = absl::StrCat( + "anonymous_resource_user_", reinterpret_cast(resource_user)); } return resource_user; } diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc index 2856be48bf0..6d90c13ac17 100644 --- a/src/core/lib/iomgr/sockaddr_utils.cc +++ b/src/core/lib/iomgr/sockaddr_utils.cc @@ -201,8 +201,8 @@ std::string grpc_sockaddr_to_string(const grpc_resolved_address* resolved_addr, void grpc_string_to_sockaddr(grpc_resolved_address* out, const char* addr, int port) { memset(out, 0, sizeof(grpc_resolved_address)); - grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)out->addr; - grpc_sockaddr_in* addr4 = (grpc_sockaddr_in*)out->addr; + grpc_sockaddr_in6* addr6 = reinterpret_cast(out->addr); + grpc_sockaddr_in* addr4 = reinterpret_cast(out->addr); if (grpc_inet_pton(GRPC_AF_INET6, addr, &addr6->sin6_addr) == 1) { addr6->sin6_family = GRPC_AF_INET6; out->len = sizeof(grpc_sockaddr_in6); @@ -260,9 +260,11 @@ int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case GRPC_AF_INET: - return grpc_ntohs(((grpc_sockaddr_in*)addr)->sin_port); + return grpc_ntohs( + (reinterpret_cast(addr))->sin_port); case GRPC_AF_INET6: - return grpc_ntohs(((grpc_sockaddr_in6*)addr)->sin6_port); + return grpc_ntohs( + (reinterpret_cast(addr))->sin6_port); default: if (grpc_is_unix_socket(resolved_addr)) { return 1; @@ -273,19 +275,17 @@ 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 grpc_sockaddr* addr = - reinterpret_cast(resolved_addr->addr); +int grpc_sockaddr_set_port(grpc_resolved_address* resolved_addr, int port) { + grpc_sockaddr* addr = reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case GRPC_AF_INET: GPR_ASSERT(port >= 0 && port < 65536); - ((grpc_sockaddr_in*)addr)->sin_port = + (reinterpret_cast(addr))->sin_port = grpc_htons(static_cast(port)); return 1; case GRPC_AF_INET6: GPR_ASSERT(port >= 0 && port < 65536); - ((grpc_sockaddr_in6*)addr)->sin6_port = + (reinterpret_cast(addr))->sin6_port = grpc_htons(static_cast(port)); return 1; default: diff --git a/src/core/lib/iomgr/sockaddr_utils.h b/src/core/lib/iomgr/sockaddr_utils.h index 051c275d2c8..ba91e56d008 100644 --- a/src/core/lib/iomgr/sockaddr_utils.h +++ b/src/core/lib/iomgr/sockaddr_utils.h @@ -56,7 +56,7 @@ void grpc_sockaddr_make_wildcard6(int port, grpc_resolved_address* wild_out); int grpc_sockaddr_get_port(const grpc_resolved_address* addr); /* Set IP port number of a sockaddr */ -int grpc_sockaddr_set_port(const grpc_resolved_address* addr, int port); +int grpc_sockaddr_set_port(grpc_resolved_address* addr, int port); // Converts a sockaddr into a newly-allocated human-readable string. // diff --git a/src/core/lib/iomgr/socket_factory_posix.cc b/src/core/lib/iomgr/socket_factory_posix.cc index 57137769c83..8d1bd71a111 100644 --- a/src/core/lib/iomgr/socket_factory_posix.cc +++ b/src/core/lib/iomgr/socket_factory_posix.cc @@ -87,8 +87,9 @@ static const grpc_arg_pointer_vtable socket_factory_arg_vtable = { socket_factory_arg_copy, socket_factory_arg_destroy, socket_factory_cmp}; grpc_arg grpc_socket_factory_to_arg(grpc_socket_factory* factory) { - return grpc_channel_arg_pointer_create((char*)GRPC_ARG_SOCKET_FACTORY, - factory, &socket_factory_arg_vtable); + return grpc_channel_arg_pointer_create( + const_cast(GRPC_ARG_SOCKET_FACTORY), factory, + &socket_factory_arg_vtable); } #endif diff --git a/src/core/lib/iomgr/socket_mutator.cc b/src/core/lib/iomgr/socket_mutator.cc index a448c9f61c3..918754adb07 100644 --- a/src/core/lib/iomgr/socket_mutator.cc +++ b/src/core/lib/iomgr/socket_mutator.cc @@ -78,6 +78,7 @@ static const grpc_arg_pointer_vtable socket_mutator_arg_vtable = { socket_mutator_arg_copy, socket_mutator_arg_destroy, socket_mutator_cmp}; grpc_arg grpc_socket_mutator_to_arg(grpc_socket_mutator* mutator) { - return grpc_channel_arg_pointer_create((char*)GRPC_ARG_SOCKET_MUTATOR, - mutator, &socket_mutator_arg_vtable); + return grpc_channel_arg_pointer_create( + const_cast(GRPC_ARG_SOCKET_MUTATOR), mutator, + &socket_mutator_arg_vtable); } diff --git a/src/core/lib/iomgr/tcp_client_custom.cc b/src/core/lib/iomgr/tcp_client_custom.cc index 5e8a3a1edd2..046380c3ab5 100644 --- a/src/core/lib/iomgr/tcp_client_custom.cc +++ b/src/core/lib/iomgr/tcp_client_custom.cc @@ -61,7 +61,7 @@ static void custom_close_callback(grpc_custom_socket* /*socket*/) {} static void on_alarm(void* acp, grpc_error* error) { int done; - grpc_custom_socket* socket = (grpc_custom_socket*)acp; + grpc_custom_socket* socket = static_cast(acp); grpc_custom_tcp_connect* connect = socket->connector; if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { const char* str = grpc_error_string(error); @@ -124,13 +124,14 @@ static void tcp_connect(grpc_closure* closure, grpc_endpoint** ep, for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == 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); + resource_quota = + grpc_resource_quota_ref_internal(static_cast( + channel_args->args[i].value.pointer.p)); } } } grpc_custom_socket* socket = - (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + static_cast(gpr_malloc(sizeof(grpc_custom_socket))); socket->refs = 2; grpc_custom_socket_vtable->init(socket, GRPC_AF_UNSPEC); grpc_custom_tcp_connect* connect = new grpc_custom_tcp_connect(); @@ -153,8 +154,8 @@ static void tcp_connect(grpc_closure* closure, grpc_endpoint** ep, grpc_schedule_on_exec_ctx); grpc_timer_init(&connect->alarm, deadline, &connect->on_alarm); grpc_custom_socket_vtable->connect( - socket, (const grpc_sockaddr*)resolved_addr->addr, resolved_addr->len, - custom_connect_callback); + socket, reinterpret_cast(resolved_addr->addr), + resolved_addr->len, custom_connect_callback); } grpc_tcp_client_vtable custom_tcp_client_vtable = {tcp_connect}; diff --git a/src/core/lib/iomgr/tcp_custom.cc b/src/core/lib/iomgr/tcp_custom.cc index 06763f69257..0f45c75c0d5 100644 --- a/src/core/lib/iomgr/tcp_custom.cc +++ b/src/core/lib/iomgr/tcp_custom.cc @@ -73,7 +73,8 @@ struct custom_tcp_endpoint { std::string local_address; }; static void tcp_free(grpc_custom_socket* s) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)s->endpoint; + custom_tcp_endpoint* tcp = + reinterpret_cast(s->endpoint); grpc_resource_user_unref(tcp->resource_user); delete tcp; s->refs--; @@ -149,18 +150,19 @@ static void custom_read_callback(grpc_custom_socket* socket, size_t nread, grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ExecCtx exec_ctx; grpc_slice_buffer garbage; - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + custom_tcp_endpoint* tcp = + reinterpret_cast(socket->endpoint); if (error == GRPC_ERROR_NONE && nread == 0) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); } if (error == GRPC_ERROR_NONE) { // Successful read - if ((size_t)nread < tcp->read_slices->length) { + if (nread < tcp->read_slices->length) { /* TODO(murgatroid99): Instead of discarding the unused part of the read * buffer, reuse it as the next read buffer. */ grpc_slice_buffer_init(&garbage); - grpc_slice_buffer_trim_end( - tcp->read_slices, tcp->read_slices->length - (size_t)nread, &garbage); + grpc_slice_buffer_trim_end(tcp->read_slices, + tcp->read_slices->length - nread, &garbage); grpc_slice_buffer_reset_and_unref_internal(&garbage); } } else { @@ -170,7 +172,7 @@ static void custom_read_callback(grpc_custom_socket* socket, size_t nread, } static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)tcpp; + custom_tcp_endpoint* tcp = static_cast(tcpp); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { gpr_log(GPR_INFO, "TCP:%p read_allocation_done: %s", tcp->socket, grpc_error_string(error)); @@ -179,7 +181,8 @@ static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { /* Before calling read, we allocate a buffer with exactly one slice * to tcp->read_slices and wait for the callback indicating that the * allocation was successful. So slices[0] should always exist here */ - char* buffer = (char*)GRPC_SLICE_START_PTR(tcp->read_slices->slices[0]); + char* buffer = reinterpret_cast( + GRPC_SLICE_START_PTR(tcp->read_slices->slices[0])); size_t len = GRPC_SLICE_LENGTH(tcp->read_slices->slices[0]); grpc_custom_socket_vtable->read(tcp->socket, buffer, len, custom_read_callback); @@ -195,7 +198,7 @@ static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { static void endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, grpc_closure* cb, bool /*urgent*/) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + custom_tcp_endpoint* tcp = reinterpret_cast(ep); GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); GPR_ASSERT(tcp->read_cb == nullptr); tcp->read_cb = cb; @@ -213,7 +216,8 @@ static void custom_write_callback(grpc_custom_socket* socket, grpc_error* error) { grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ExecCtx exec_ctx; - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + custom_tcp_endpoint* tcp = + reinterpret_cast(socket->endpoint); grpc_closure* cb = tcp->write_cb; tcp->write_cb = nullptr; if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { @@ -226,7 +230,7 @@ static void custom_write_callback(grpc_custom_socket* socket, static void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* write_slices, grpc_closure* cb, void* /*arg*/) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + custom_tcp_endpoint* tcp = reinterpret_cast(ep); GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { @@ -284,7 +288,7 @@ static void endpoint_delete_from_pollset_set(grpc_endpoint* ep, } static void endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + custom_tcp_endpoint* tcp = reinterpret_cast(ep); if (!tcp->shutting_down) { if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { const char* str = grpc_error_string(why); @@ -309,28 +313,29 @@ static void custom_close_callback(grpc_custom_socket* socket) { } else if (socket->endpoint) { grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ExecCtx exec_ctx; - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + custom_tcp_endpoint* tcp = + reinterpret_cast(socket->endpoint); TCP_UNREF(tcp, "destroy"); } } static void endpoint_destroy(grpc_endpoint* ep) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + custom_tcp_endpoint* tcp = reinterpret_cast(ep); grpc_custom_socket_vtable->close(tcp->socket, custom_close_callback); } static absl::string_view endpoint_get_peer(grpc_endpoint* ep) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + custom_tcp_endpoint* tcp = reinterpret_cast(ep); return tcp->peer_string; } static absl::string_view endpoint_get_local_address(grpc_endpoint* ep) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + custom_tcp_endpoint* tcp = reinterpret_cast(ep); return tcp->local_address; } static grpc_resource_user* endpoint_get_resource_user(grpc_endpoint* ep) { - custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + custom_tcp_endpoint* tcp = reinterpret_cast(ep); return tcp->resource_user; } @@ -362,7 +367,7 @@ grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket, gpr_log(GPR_INFO, "Creating TCP endpoint %p", socket); } socket->refs++; - socket->endpoint = (grpc_endpoint*)tcp; + socket->endpoint = reinterpret_cast(tcp); tcp->socket = socket; tcp->base.vtable = &vtable; gpr_ref_init(&tcp->refcount, 1); diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index b968ef9d6a8..d33e9ef12c0 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -465,7 +465,8 @@ static void run_poller(void* bp, grpc_error* /*error_ignored*/) { if (gpr_atm_no_barrier_load(&g_uncovered_notifications_pending) == 1 && gpr_atm_full_cas(&g_uncovered_notifications_pending, 1, 0)) { gpr_mu_lock(p->pollset_mu); - bool cas_ok = gpr_atm_full_cas(&g_backup_poller, (gpr_atm)p, 0); + bool cas_ok = + gpr_atm_full_cas(&g_backup_poller, reinterpret_cast(p), 0); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { gpr_log(GPR_INFO, "BACKUP_POLLER:%p done cas_ok=%d", p, cas_ok); } @@ -487,7 +488,8 @@ static void run_poller(void* bp, grpc_error* /*error_ignored*/) { } static void drop_uncovered(grpc_tcp* /*tcp*/) { - backup_poller* p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller); + backup_poller* p = + reinterpret_cast(gpr_atm_acq_load(&g_backup_poller)); gpr_atm old_count = gpr_atm_full_fetch_add(&g_uncovered_notifications_pending, -1); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { @@ -526,8 +528,8 @@ static void cover_self(grpc_tcp* tcp) { GRPC_ERROR_NONE, grpc_core::ExecutorType::DEFAULT, grpc_core::ExecutorJobType::LONG); } else { - while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == - nullptr) { + while ((p = reinterpret_cast( + gpr_atm_acq_load(&g_backup_poller))) == nullptr) { // spin waiting for backup poller } } diff --git a/src/core/lib/iomgr/tcp_server_custom.cc b/src/core/lib/iomgr/tcp_server_custom.cc index 284be9c82fd..18d74945be5 100644 --- a/src/core/lib/iomgr/tcp_server_custom.cc +++ b/src/core/lib/iomgr/tcp_server_custom.cc @@ -83,7 +83,8 @@ struct grpc_tcp_server { static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server) { - grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); + grpc_tcp_server* s = + static_cast(gpr_malloc(sizeof(grpc_tcp_server))); // Let the implementation decide if so_reuseport can be enabled or not. s->so_reuseport = true; s->resource_quota = grpc_resource_quota_create(nullptr); @@ -95,7 +96,7 @@ static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, if (args->args[i].type == GRPC_ARG_POINTER) { grpc_resource_quota_unref_internal(s->resource_quota); s->resource_quota = grpc_resource_quota_ref_internal( - (grpc_resource_quota*)args->args[i].value.pointer.p); + static_cast(args->args[i].value.pointer.p)); } else { grpc_resource_quota_unref_internal(s->resource_quota); gpr_free(s); @@ -213,7 +214,7 @@ static void tcp_server_unref(grpc_tcp_server* s) { static void finish_accept(grpc_tcp_listener* sp, grpc_custom_socket* socket) { grpc_tcp_server_acceptor* acceptor = - (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); + static_cast(gpr_malloc(sizeof(*acceptor))); grpc_endpoint* ep = nullptr; grpc_resolved_address peer_name; std::string peer_name_string; @@ -222,7 +223,8 @@ static void finish_accept(grpc_tcp_listener* sp, grpc_custom_socket* socket) { memset(&peer_name, 0, sizeof(grpc_resolved_address)); peer_name.len = GRPC_MAX_SOCKADDR_SIZE; err = grpc_custom_socket_vtable->getpeername( - socket, (grpc_sockaddr*)&peer_name.addr, (int*)&peer_name.len); + socket, reinterpret_cast(&peer_name.addr), + reinterpret_cast(&peer_name.len)); if (err == GRPC_ERROR_NONE) { peer_name_string = grpc_sockaddr_to_uri(&peer_name); } else { @@ -262,8 +264,8 @@ static void custom_accept_callback(grpc_custom_socket* socket, } finish_accept(sp, client); if (!sp->closed) { - grpc_custom_socket* new_socket = - (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + grpc_custom_socket* new_socket = static_cast( + gpr_malloc(sizeof(grpc_custom_socket))); new_socket->endpoint = nullptr; new_socket->listener = nullptr; new_socket->connector = nullptr; @@ -290,8 +292,9 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, flags |= GRPC_CUSTOM_SOCKET_OPT_SO_REUSEPORT; } - error = grpc_custom_socket_vtable->bind(socket, (grpc_sockaddr*)addr->addr, - addr->len, flags); + error = grpc_custom_socket_vtable->bind( + socket, reinterpret_cast(const_cast(addr->addr)), + addr->len, flags); if (error != GRPC_ERROR_NONE) { return error; } @@ -303,7 +306,8 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE; error = grpc_custom_socket_vtable->getsockname( - socket, (grpc_sockaddr*)&sockname_temp.addr, (int*)&sockname_temp.len); + socket, reinterpret_cast(&sockname_temp.addr), + reinterpret_cast(&sockname_temp.len)); if (error != GRPC_ERROR_NONE) { return error; } @@ -312,7 +316,7 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, GPR_ASSERT(port >= 0); GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); - sp = (grpc_tcp_listener*)gpr_zalloc(sizeof(grpc_tcp_listener)); + sp = static_cast(gpr_zalloc(sizeof(grpc_tcp_listener))); sp->next = nullptr; if (s->head == nullptr) { s->head = sp; @@ -358,12 +362,13 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s, socket = sp->socket; sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE; if (nullptr == grpc_custom_socket_vtable->getsockname( - socket, (grpc_sockaddr*)&sockname_temp.addr, - (int*)&sockname_temp.len)) { + socket, + reinterpret_cast(&sockname_temp.addr), + reinterpret_cast(&sockname_temp.len))) { *port = grpc_sockaddr_get_port(&sockname_temp); if (*port > 0) { - allocated_addr = - (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address)); + allocated_addr = static_cast( + gpr_malloc(sizeof(grpc_resolved_address))); memcpy(allocated_addr, addr, sizeof(grpc_resolved_address)); grpc_sockaddr_set_port(allocated_addr, *port); addr = allocated_addr; @@ -391,7 +396,8 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s, } family = grpc_sockaddr_get_family(addr); - socket = (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + socket = + static_cast(gpr_malloc(sizeof(grpc_custom_socket))); socket->refs = 1; socket->endpoint = nullptr; socket->listener = nullptr; @@ -430,8 +436,8 @@ static void tcp_server_start(grpc_tcp_server* server, server->on_accept_cb = on_accept_cb; server->on_accept_cb_arg = cb_arg; for (sp = server->head; sp; sp = sp->next) { - grpc_custom_socket* new_socket = - (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + grpc_custom_socket* new_socket = static_cast( + gpr_malloc(sizeof(grpc_custom_socket))); new_socket->endpoint = nullptr; new_socket->listener = nullptr; new_socket->connector = nullptr; diff --git a/src/core/lib/iomgr/timer_custom.cc b/src/core/lib/iomgr/timer_custom.cc index 4d0e4e9fabc..867359a28db 100644 --- a/src/core/lib/iomgr/timer_custom.cc +++ b/src/core/lib/iomgr/timer_custom.cc @@ -57,16 +57,16 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline, timer->pending = true; timer->closure = closure; grpc_custom_timer* timer_wrapper = - (grpc_custom_timer*)gpr_malloc(sizeof(grpc_custom_timer)); + static_cast(gpr_malloc(sizeof(grpc_custom_timer))); timer_wrapper->timeout_ms = timeout; - timer->custom_timer = (void*)timer_wrapper; + timer->custom_timer = timer_wrapper; timer_wrapper->original = timer; custom_timer_impl->start(timer_wrapper); } static void timer_cancel(grpc_timer* timer) { GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); - grpc_custom_timer* tw = (grpc_custom_timer*)timer->custom_timer; + grpc_custom_timer* tw = static_cast(timer->custom_timer); if (timer->pending) { timer->pending = false; grpc_core::ExecCtx::Run(DEBUG_LOCATION, timer->closure, diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index 6490c8df09d..c2eacc5053d 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -570,8 +570,7 @@ static int add_socket_to_server(grpc_udp_server* s, int fd, return port; } -int grpc_udp_server_add_port(grpc_udp_server* s, - const grpc_resolved_address* addr, +int grpc_udp_server_add_port(grpc_udp_server* s, grpc_resolved_address* addr, int rcv_buf_size, int snd_buf_size, GrpcUdpHandlerFactory* handler_factory, size_t num_listeners) { diff --git a/src/core/lib/iomgr/udp_server.h b/src/core/lib/iomgr/udp_server.h index 6cda332a5bb..ba7acbbe59f 100644 --- a/src/core/lib/iomgr/udp_server.h +++ b/src/core/lib/iomgr/udp_server.h @@ -93,8 +93,7 @@ int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index); /* TODO(ctiller): deprecate this, and make grpc_udp_server_add_ports to handle all of the multiple socket port matching logic in one place */ -int grpc_udp_server_add_port(grpc_udp_server* s, - const grpc_resolved_address* addr, +int grpc_udp_server_add_port(grpc_udp_server* s, grpc_resolved_address* addr, int rcv_buf_size, int snd_buf_size, GrpcUdpHandlerFactory* handler_factory, size_t num_listeners); diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 30f5d835bc7..034aa91005e 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -96,16 +96,15 @@ std::string grpc_sockaddr_to_uri_unix_if_possible( if (addr->sa_family != AF_UNIX) { return ""; } - if (((struct sockaddr_un*)addr)->sun_path[0] == '\0' && - ((struct sockaddr_un*)addr)->sun_path[1] != '\0') { - const struct sockaddr_un* un = - reinterpret_cast(resolved_addr->addr); + const auto* unix_addr = reinterpret_cast(addr); + if (unix_addr->sun_path[0] == '\0' && unix_addr->sun_path[1] != '\0') { return absl::StrCat( "unix-abstract:", - absl::string_view(un->sun_path + 1, - resolved_addr->len - sizeof(un->sun_family) - 1)); + absl::string_view( + unix_addr->sun_path + 1, + resolved_addr->len - sizeof(unix_addr->sun_family) - 1)); } - return absl::StrCat("unix:", ((struct sockaddr_un*)addr)->sun_path); + return absl::StrCat("unix:", unix_addr->sun_path); } #endif diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 28805a56b2d..d760d82f226 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -295,8 +295,9 @@ static const grpc_arg_pointer_vtable auth_context_pointer_vtable = { auth_context_pointer_cmp}; grpc_arg grpc_auth_context_to_arg(grpc_auth_context* c) { - return grpc_channel_arg_pointer_create((char*)GRPC_AUTH_CONTEXT_ARG, c, - &auth_context_pointer_vtable); + return grpc_channel_arg_pointer_create( + const_cast(GRPC_AUTH_CONTEXT_ARG), c, + &auth_context_pointer_vtable); } grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) { diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index 8283090a156..d2f4c9c6bb5 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -67,9 +67,9 @@ static const grpc_arg_pointer_vtable credentials_pointer_vtable = { grpc_arg grpc_channel_credentials_to_arg( grpc_channel_credentials* credentials) { - return grpc_channel_arg_pointer_create((char*)GRPC_ARG_CHANNEL_CREDENTIALS, - credentials, - &credentials_pointer_vtable); + return grpc_channel_arg_pointer_create( + const_cast(GRPC_ARG_CHANNEL_CREDENTIALS), credentials, + &credentials_pointer_vtable); } grpc_channel_credentials* grpc_channel_credentials_from_arg( @@ -135,8 +135,8 @@ static const grpc_arg_pointer_vtable cred_ptr_vtable = { server_credentials_pointer_cmp}; grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials* c) { - return grpc_channel_arg_pointer_create((char*)GRPC_SERVER_CREDENTIALS_ARG, c, - &cred_ptr_vtable); + return grpc_channel_arg_pointer_create( + const_cast(GRPC_SERVER_CREDENTIALS_ARG), c, &cred_ptr_vtable); } grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) { diff --git a/src/core/lib/security/credentials/external/aws_request_signer.cc b/src/core/lib/security/credentials/external/aws_request_signer.cc index d4c80e63b75..b51f595df36 100644 --- a/src/core/lib/security/credentials/external/aws_request_signer.cc +++ b/src/core/lib/security/credentials/external/aws_request_signer.cc @@ -55,7 +55,8 @@ std::string HMAC(const std::string& key, const std::string& msg) { unsigned int len; unsigned char digest[EVP_MAX_MD_SIZE]; HMAC(EVP_sha256(), key.c_str(), key.length(), - (const unsigned char*)msg.c_str(), msg.length(), digest, &len); + reinterpret_cast(msg.c_str()), msg.length(), + digest, &len); return std::string(digest, digest + len); } diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc index 8fd0493ee44..eef636d0043 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.cc +++ b/src/core/lib/security/credentials/fake/fake_credentials.cc @@ -76,7 +76,8 @@ grpc_fake_transport_security_server_credentials_create() { grpc_arg grpc_fake_transport_expected_targets_arg(char* expected_targets) { return grpc_channel_arg_string_create( - (char*)GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS, expected_targets); + const_cast(GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS), + expected_targets); } const char* grpc_fake_transport_get_expected_targets( 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 9162bad47bc..46c792755db 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 @@ -175,8 +175,8 @@ static int is_metadata_server_reachable() { detector.is_done = 0; detector.success = 0; memset(&request, 0, sizeof(grpc_httpcli_request)); - request.host = (char*)GRPC_COMPUTE_ENGINE_DETECTION_HOST; - request.http.path = (char*)"/"; + request.host = const_cast(GRPC_COMPUTE_ENGINE_DETECTION_HOST); + request.http.path = const_cast("/"); grpc_httpcli_context_init(&context); grpc_resource_quota* resource_quota = grpc_resource_quota_create("google_default_credentials"); diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc index 3b61742064b..8f5a94f4bfd 100644 --- a/src/core/lib/security/credentials/jwt/json_token.cc +++ b/src/core/lib/security/credentials/jwt/json_token.cc @@ -112,7 +112,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) { goto end; } result.private_key = - PEM_read_bio_RSAPrivateKey(bio, nullptr, nullptr, (void*)""); + PEM_read_bio_RSAPrivateKey(bio, nullptr, nullptr, const_cast("")); if (result.private_key == nullptr) { gpr_log(GPR_ERROR, "Could not deserialize private key."); goto end; diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index a6ed657dbf2..ec3aed8ad0a 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -696,7 +696,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* /*error*/) { req.host = gpr_strdup(jwks_uri); req.http.path = const_cast(strchr(jwks_uri, '/')); if (req.http.path == nullptr) { - req.http.path = (char*)""; + req.http.path = const_cast(""); } else { *(req.host + (req.http.path - jwks_uri)) = '\0'; } @@ -757,8 +757,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 = static_cast(gpr_memrchr( - (void*)email_domain, '.', static_cast(dot - email_domain))); + dot = static_cast( + gpr_memrchr(email_domain, '.', static_cast(dot - email_domain))); if (dot == nullptr) return email_domain; return dot + 1; } diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 8e1ec57ddaf..1ed839a57c9 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -386,8 +386,9 @@ class grpc_compute_engine_token_fetcher_credentials const_cast("Google")}; grpc_httpcli_request request; memset(&request, 0, sizeof(grpc_httpcli_request)); - request.host = (char*)GRPC_COMPUTE_ENGINE_METADATA_HOST; - request.http.path = (char*)GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH; + request.host = const_cast(GRPC_COMPUTE_ENGINE_METADATA_HOST); + request.http.path = + const_cast(GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH); request.http.hdr_count = 1; request.http.hdrs = &header; /* TODO(ctiller): Carry the resource_quota in ctx and share it with the host @@ -445,8 +446,8 @@ void grpc_google_refresh_token_credentials::fetch_oauth2( GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING, refresh_token_.client_id, refresh_token_.client_secret, refresh_token_.refresh_token); memset(&request, 0, sizeof(grpc_httpcli_request)); - request.host = (char*)GRPC_GOOGLE_OAUTH2_SERVICE_HOST; - request.http.path = (char*)GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH; + request.host = const_cast(GRPC_GOOGLE_OAUTH2_SERVICE_HOST); + request.http.path = const_cast(GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH); request.http.hdr_count = 1; request.http.hdrs = &header; request.handshaker = &grpc_httpcli_ssl; @@ -577,8 +578,8 @@ class StsTokenFetcherCredentials const_cast("application/x-www-form-urlencoded")}; grpc_httpcli_request request; memset(&request, 0, sizeof(grpc_httpcli_request)); - request.host = (char*)sts_url_->authority; - request.http.path = (char*)sts_url_->path; + request.host = sts_url_->authority; + request.http.path = sts_url_->path; request.http.hdr_count = 1; request.http.hdrs = &header; request.handshaker = (strcmp(sts_url_->scheme, "https") == 0) diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 9cb8b815442..a5b01cd84e8 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -224,7 +224,7 @@ bool grpc_plugin_credentials::get_request_metadata( grpc_slice_unref_internal(creds_md[i].key); grpc_slice_unref_internal(creds_md[i].value); } - gpr_free((void*)error_details); + gpr_free(const_cast(error_details)); gpr_free(request); } return retval; diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 3bb7790f5c9..e2a1ad03c0f 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -38,8 +38,8 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp, size_t num_key_cert_pairs) { if (kp == nullptr) return; for (size_t i = 0; i < num_key_cert_pairs; i++) { - gpr_free((void*)kp[i].private_key); - gpr_free((void*)kp[i].cert_chain); + gpr_free(const_cast(kp[i].private_key)); + gpr_free(const_cast(kp[i].cert_chain)); } gpr_free(kp); } @@ -87,7 +87,7 @@ grpc_ssl_credentials::create_security_connector( return sc; } grpc_arg new_arg = grpc_channel_arg_string_create( - (char*)GRPC_ARG_HTTP2_SCHEME, (char*)"https"); + const_cast(GRPC_ARG_HTTP2_SCHEME), const_cast("https")); *new_args = grpc_channel_args_copy_and_add(args, &new_arg, 1); return sc; } @@ -262,8 +262,8 @@ void grpc_ssl_server_certificate_config_destroy( grpc_ssl_server_certificate_config* config) { if (config == nullptr) return; for (size_t i = 0; i < config->num_key_cert_pairs; i++) { - gpr_free((void*)config->pem_key_cert_pairs[i].private_key); - gpr_free((void*)config->pem_key_cert_pairs[i].cert_chain); + gpr_free(const_cast(config->pem_key_cert_pairs[i].private_key)); + gpr_free(const_cast(config->pem_key_cert_pairs[i].cert_chain)); } gpr_free(config->pem_key_cert_pairs); gpr_free(config->pem_root_certs); diff --git a/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc b/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc index 9e69d986887..e6ec16f6613 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +++ b/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc @@ -172,7 +172,7 @@ FileWatcherCertificateProvider::~FileWatcherCertificateProvider() { // Reset distributor's callback to make sure the callback won't be invoked // again after this object(provider) is destroyed. distributor_->SetWatchStatusCallback(nullptr); - gpr_event_set(&shutdown_event_, (void*)(1)); + gpr_event_set(&shutdown_event_, reinterpret_cast(1)); refresh_thread_.Join(); } diff --git a/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc b/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc index 12e462bb9dd..cf2b4c60df9 100644 --- a/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +++ b/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc @@ -46,7 +46,7 @@ grpc_tls_server_authorization_check_config:: grpc_tls_server_authorization_check_config:: ~grpc_tls_server_authorization_check_config() { if (destruct_ != nullptr) { - destruct_((void*)config_user_data_); + destruct_(config_user_data_); } } diff --git a/src/core/lib/security/credentials/tls/tls_credentials.cc b/src/core/lib/security/credentials/tls/tls_credentials.cc index f2c4b3b807d..06887e760cc 100644 --- a/src/core/lib/security/credentials/tls/tls_credentials.cc +++ b/src/core/lib/security/credentials/tls/tls_credentials.cc @@ -92,7 +92,7 @@ TlsCredentials::create_security_connector( } if (args != nullptr) { grpc_arg new_arg = grpc_channel_arg_string_create( - (char*)GRPC_ARG_HTTP2_SCHEME, (char*)"https"); + const_cast(GRPC_ARG_HTTP2_SCHEME), const_cast("https")); *new_args = grpc_channel_args_copy_and_add(args, &new_arg, 1); } return sc; diff --git a/src/core/lib/security/security_connector/security_connector.cc b/src/core/lib/security/security_connector/security_connector.cc index b3825fe2267..822fe15c3f7 100644 --- a/src/core/lib/security/security_connector/security_connector.cc +++ b/src/core/lib/security/security_connector/security_connector.cc @@ -104,8 +104,9 @@ static const grpc_arg_pointer_vtable connector_arg_vtable = { connector_arg_copy, connector_arg_destroy, connector_cmp}; grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc) { - return grpc_channel_arg_pointer_create((char*)GRPC_ARG_SECURITY_CONNECTOR, sc, - &connector_arg_vtable); + return grpc_channel_arg_pointer_create( + const_cast(GRPC_ARG_SECURITY_CONNECTOR), sc, + &connector_arg_vtable); } grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) { diff --git a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc index 7d4574e2581..41a2252435c 100644 --- a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +++ b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc @@ -111,7 +111,7 @@ class grpc_ssl_channel_security_connector final const tsi_result result = tsi_create_ssl_client_handshaker_factory_with_options( &options, &client_handshaker_factory_); - gpr_free((void*)options.alpn_protocols); + gpr_free(options.alpn_protocols); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); @@ -258,7 +258,7 @@ class grpc_ssl_server_security_connector const tsi_result result = tsi_create_ssl_server_handshaker_factory_with_options( &options, &server_handshaker_factory_); - gpr_free((void*)alpn_protocol_strings); + gpr_free(alpn_protocol_strings); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); @@ -368,7 +368,7 @@ class grpc_ssl_server_security_connector grpc_tsi_ssl_pem_key_cert_pairs_destroy( const_cast(options.pem_key_cert_pairs), options.num_key_cert_pairs); - gpr_free((void*)alpn_protocol_strings); + gpr_free(alpn_protocol_strings); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", diff --git a/src/core/lib/security/security_connector/ssl_utils.cc b/src/core/lib/security/security_connector/ssl_utils.cc index 1761c346c41..f1797d5d80a 100644 --- a/src/core/lib/security/security_connector/ssl_utils.cc +++ b/src/core/lib/security/security_connector/ssl_utils.cc @@ -427,7 +427,7 @@ grpc_security_status grpc_ssl_tsi_client_handshaker_factory_init( const tsi_result result = tsi_create_ssl_client_handshaker_factory_with_options(&options, handshaker_factory); - gpr_free((void*)options.alpn_protocols); + gpr_free(options.alpn_protocols); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); @@ -459,7 +459,7 @@ grpc_security_status grpc_ssl_tsi_server_handshaker_factory_init( const tsi_result result = tsi_create_ssl_server_handshaker_factory_with_options(&options, handshaker_factory); - gpr_free((void*)alpn_protocol_strings); + gpr_free(alpn_protocol_strings); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); diff --git a/src/core/lib/security/security_connector/tls/tls_security_connector.cc b/src/core/lib/security/security_connector/tls/tls_security_connector.cc index a03e3bf4be9..0bb961786f6 100644 --- a/src/core/lib/security/security_connector/tls/tls_security_connector.cc +++ b/src/core/lib/security/security_connector/tls/tls_security_connector.cc @@ -419,9 +419,9 @@ void TlsChannelSecurityConnector::ServerAuthorizationCheckArgDestroy( if (arg == nullptr) { return; } - gpr_free((void*)arg->target_name); - gpr_free((void*)arg->peer_cert); - if (arg->peer_cert_full_chain) gpr_free((void*)arg->peer_cert_full_chain); + gpr_free(const_cast(arg->target_name)); + gpr_free(const_cast(arg->peer_cert)); + gpr_free(const_cast(arg->peer_cert_full_chain)); delete arg->error_details; if (arg->destroy_context != nullptr) { arg->destroy_context(arg->context); diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 5563d5bd6a4..e7b98850132 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -241,8 +241,8 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error* error) { handshaker_result_, &unused_bytes, &unused_bytes_size); // Create secure endpoint. if (unused_bytes_size > 0) { - grpc_slice slice = - grpc_slice_from_copied_buffer((char*)unused_bytes, unused_bytes_size); + grpc_slice slice = grpc_slice_from_copied_buffer( + reinterpret_cast(unused_bytes), unused_bytes_size); args_->endpoint = grpc_secure_endpoint_create( protector, zero_copy_protector, args_->endpoint, &slice, 1); grpc_slice_unref_internal(slice); diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index d14ae4d243d..3e9db709ada 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -310,20 +310,24 @@ 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); + parent_call* p = + reinterpret_cast(gpr_atm_acq_load(&call->parent_call_atm)); if (p == nullptr) { p = call->arena->New(); - if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm) nullptr, - (gpr_atm)p)) { + if (!gpr_atm_rel_cas(&call->parent_call_atm, + reinterpret_cast(nullptr), + reinterpret_cast(p))) { p->~parent_call(); - p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); + p = reinterpret_cast( + gpr_atm_acq_load(&call->parent_call_atm)); } } return p; } static parent_call* get_parent_call(grpc_call* call) { - return (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); + return reinterpret_cast( + gpr_atm_acq_load(&call->parent_call_atm)); } size_t grpc_call_get_initial_size_estimate() { @@ -649,7 +653,8 @@ static void execute_batch(grpc_call* call, } char* grpc_call_get_peer(grpc_call* call) { - char* peer_string = (char*)gpr_atm_acq_load(&call->peer_string); + char* peer_string = + reinterpret_cast(gpr_atm_acq_load(&call->peer_string)); if (peer_string != nullptr) return gpr_strdup(peer_string); peer_string = grpc_channel_get_target(call->channel); if (peer_string != nullptr) return peer_string; @@ -828,8 +833,8 @@ static void set_encodings_accepted_by_peer(grpc_call* /*call*/, accepted_user_data = grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); if (accepted_user_data != nullptr) { - *encodings_accepted_by_peer = - static_cast(((uintptr_t)accepted_user_data) - 1); + *encodings_accepted_by_peer = static_cast( + reinterpret_cast(accepted_user_data) - 1); return; } @@ -869,7 +874,8 @@ static void set_encodings_accepted_by_peer(grpc_call* /*call*/, grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, - (void*)((static_cast(*encodings_accepted_by_peer)) + 1)); + reinterpret_cast( + static_cast(*encodings_accepted_by_peer) + 1)); } uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call* call) { @@ -883,8 +889,8 @@ grpc_call_test_only_get_incoming_stream_encodings(grpc_call* call) { return call->incoming_stream_compression_algorithm; } -static grpc_linked_mdelem* linked_from_md(const grpc_metadata* md) { - return (grpc_linked_mdelem*)&md->internal_data; +static grpc_linked_mdelem* linked_from_md(grpc_metadata* md) { + return reinterpret_cast(&md->internal_data); } static grpc_metadata* get_md_elem(grpc_metadata* metadata, @@ -907,8 +913,7 @@ static int prepare_application_metadata(grpc_call* call, int count, grpc_metadata_batch* batch = &call->metadata_batch[0 /* is_receiving */][is_trailing]; for (i = 0; i < total_count; i++) { - const grpc_metadata* md = - get_md_elem(metadata, additional_metadata, i, count); + grpc_metadata* md = get_md_elem(metadata, additional_metadata, i, count); grpc_linked_mdelem* l = linked_from_md(md); GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); if (!GRPC_LOG_IF_ERROR("validate_metadata", @@ -927,8 +932,7 @@ static int prepare_application_metadata(grpc_call* call, int count, } if (i != total_count) { for (int j = 0; j < i; j++) { - const grpc_metadata* md = - get_md_elem(metadata, additional_metadata, j, count); + grpc_metadata* md = get_md_elem(metadata, additional_metadata, j, count); grpc_linked_mdelem* l = linked_from_md(md); GRPC_MDELEM_UNREF(l->md); } @@ -1230,9 +1234,10 @@ static void post_batch_completion(batch_control* bctl) { if (bctl->completion_data.notify_tag.is_closure) { /* unrefs error */ bctl->call = nullptr; - grpc_core::Closure::Run(DEBUG_LOCATION, - (grpc_closure*)bctl->completion_data.notify_tag.tag, - error); + grpc_core::Closure::Run( + DEBUG_LOCATION, + static_cast(bctl->completion_data.notify_tag.tag), + error); GRPC_CALL_INTERNAL_UNREF(call, "completion"); } else { /* unrefs error */ @@ -1356,7 +1361,8 @@ static void receiving_stream_ready(void* bctlp, grpc_error* error) { * object with rel_cas, and will not use it after the cas. Its corresponding * acq_load is in receiving_initial_metadata_ready() */ if (error != GRPC_ERROR_NONE || call->receiving_stream == nullptr || - !gpr_atm_rel_cas(&call->recv_state, RECV_NONE, (gpr_atm)bctlp)) { + !gpr_atm_rel_cas(&call->recv_state, RECV_NONE, + reinterpret_cast(bctlp))) { process_data_after_md(bctl); } } @@ -1570,7 +1576,8 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, static_cast( gpr_malloc(sizeof(grpc_cq_completion)))); } else { - grpc_core::Closure::Run(DEBUG_LOCATION, (grpc_closure*)notify_tag, + grpc_core::Closure::Run(DEBUG_LOCATION, + static_cast(notify_tag), GRPC_ERROR_NONE); } error = GRPC_CALL_OK; diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index 62eb1c3f9d6..17f6c901d1f 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -87,7 +87,7 @@ 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 = - static_cast((void*)static_cast(0xdeadbeef)); + static_cast(reinterpret_cast(0xdeadbeef)); } } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index fe04ecc61fd..c262cc95978 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -447,7 +447,8 @@ void grpc_cq_global_init() { } void grpc_completion_queue_thread_local_cache_init(grpc_completion_queue* cq) { - if ((grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == nullptr) { + if (reinterpret_cast(gpr_tls_get(&g_cached_cq)) == + nullptr) { gpr_tls_set(&g_cached_event, (intptr_t)0); gpr_tls_set(&g_cached_cq, (intptr_t)cq); } @@ -456,10 +457,10 @@ void grpc_completion_queue_thread_local_cache_init(grpc_completion_queue* cq) { int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, void** tag, int* ok) { grpc_cq_completion* storage = - (grpc_cq_completion*)gpr_tls_get(&g_cached_event); + reinterpret_cast(gpr_tls_get(&g_cached_event)); int ret = 0; - if (storage != nullptr && - (grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) { + if (storage != nullptr && reinterpret_cast( + gpr_tls_get(&g_cached_cq)) == cq) { *tag = storage->tag; grpc_core::ExecCtx exec_ctx; *ok = (storage->next & static_cast(1)) == 1; @@ -717,8 +718,10 @@ static void cq_end_op_for_next( cq_check_tag(cq, tag, true); /* Used in debug builds only */ - if ((grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq && - (grpc_cq_completion*)gpr_tls_get(&g_cached_event) == nullptr) { + if (reinterpret_cast(gpr_tls_get(&g_cached_cq)) == + cq && + reinterpret_cast(gpr_tls_get(&g_cached_event)) == + nullptr) { gpr_tls_set(&g_cached_event, (intptr_t)storage); } else { /* Add the completion to the queue */ @@ -793,8 +796,8 @@ static void cq_end_op_for_pluck( storage->tag = tag; storage->done = done; storage->done_arg = done_arg; - storage->next = - ((uintptr_t)&cqd->completed_head) | (static_cast(is_success)); + storage->next = reinterpret_cast(&cqd->completed_head) | + static_cast(is_success); gpr_mu_lock(cq->mu); cq_check_tag(cq, tag, false); /* Used in debug builds only */ @@ -802,7 +805,7 @@ static void cq_end_op_for_pluck( /* Add to the list of completions */ cqd->things_queued_ever.FetchAdd(1, grpc_core::MemoryOrder::RELAXED); cqd->completed_tail->next = - ((uintptr_t)storage) | (1u & cqd->completed_tail->next); + reinterpret_cast(storage) | (1u & cqd->completed_tail->next); cqd->completed_tail = storage; if (cqd->pending_events.FetchSub(1, grpc_core::MemoryOrder::ACQ_REL) == 1) { @@ -1176,8 +1179,8 @@ class ExecCtxPluck : public grpc_core::ExecCtx { cqd->things_queued_ever.Load(grpc_core::MemoryOrder::RELAXED); grpc_cq_completion* c; grpc_cq_completion* prev = &cqd->completed_head; - while ((c = (grpc_cq_completion*)(prev->next & - ~static_cast(1))) != + while ((c = reinterpret_cast( + prev->next & ~static_cast(1))) != &cqd->completed_head) { if (c->tag == a->tag) { prev->next = (prev->next & static_cast(1)) | @@ -1248,9 +1251,9 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, break; } prev = &cqd->completed_head; - while ( - (c = (grpc_cq_completion*)(prev->next & ~static_cast(1))) != - &cqd->completed_head) { + while ((c = reinterpret_cast( + prev->next & ~static_cast(1))) != + &cqd->completed_head) { if (c->tag == tag) { prev->next = (prev->next & static_cast(1)) | (c->next & ~static_cast(1)); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index ff5b074ca34..0b2151b73b9 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -101,11 +101,12 @@ static void register_builtin_channel_init() { grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, grpc_add_connected_filter, nullptr); - grpc_channel_init_register_stage(GRPC_CLIENT_LAME_CHANNEL, - GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - append_filter, (void*)&grpc_lame_filter); - grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter, - (void*)&grpc_core::Server::kServerTopFilter); + grpc_channel_init_register_stage( + GRPC_CLIENT_LAME_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, + append_filter, const_cast(&grpc_lame_filter)); + grpc_channel_init_register_stage( + GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter, + const_cast(&grpc_core::Server::kServerTopFilter)); } typedef struct grpc_plugin { diff --git a/src/core/lib/transport/static_metadata.cc b/src/core/lib/transport/static_metadata.cc index e027c00d390..483a40f0325 100644 --- a/src/core/lib/transport/static_metadata.cc +++ b/src/core/lib/transport/static_metadata.cc @@ -1207,7 +1207,7 @@ static uint32_t elems_phash(uint32_t i) { uint32_t y = i / 108; uint32_t h = x; if (y < GPR_ARRAY_SIZE(elems_r)) { - uint32_t delta = (uint32_t)elems_r[y]; + uint32_t delta = static_cast(elems_r[y]); h += delta; } return h; diff --git a/src/core/lib/transport/status_metadata.cc b/src/core/lib/transport/status_metadata.cc index c83d6b0d2dc..1b19307e7c6 100644 --- a/src/core/lib/transport/status_metadata.cc +++ b/src/core/lib/transport/status_metadata.cc @@ -42,14 +42,15 @@ grpc_status_code grpc_get_status_code_from_metadata(grpc_mdelem md) { } void* user_data = grpc_mdelem_get_user_data(md, destroy_status); if (user_data != nullptr) { - return static_cast((intptr_t)user_data - STATUS_OFFSET); + return static_cast(reinterpret_cast(user_data) - + STATUS_OFFSET); } uint32_t status; 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*)static_cast(status + STATUS_OFFSET)); + grpc_mdelem_set_user_data(md, destroy_status, + reinterpret_cast(status + STATUS_OFFSET)); return static_cast(status); } diff --git a/src/core/tsi/alts/crypt/gsec.cc b/src/core/tsi/alts/crypt/gsec.cc index 6236591a97c..d4de9cdbff4 100644 --- a/src/core/tsi/alts/crypt/gsec.cc +++ b/src/core/tsi/alts/crypt/gsec.cc @@ -43,8 +43,9 @@ grpc_status_code gsec_aead_crypter_encrypt( char** error_details) { if (crypter != nullptr && crypter->vtable != nullptr && crypter->vtable->encrypt_iovec != nullptr) { - struct iovec aad_vec = {(void*)aad, aad_length}; - struct iovec plaintext_vec = {(void*)plaintext, plaintext_length}; + struct iovec aad_vec = {const_cast(aad), aad_length}; + struct iovec plaintext_vec = {const_cast(plaintext), + plaintext_length}; struct iovec ciphertext_vec = {ciphertext_and_tag, ciphertext_and_tag_length}; return crypter->vtable->encrypt_iovec( @@ -81,8 +82,8 @@ grpc_status_code gsec_aead_crypter_decrypt( size_t plaintext_length, size_t* bytes_written, char** error_details) { if (crypter != nullptr && crypter->vtable != nullptr && crypter->vtable->decrypt_iovec != nullptr) { - struct iovec aad_vec = {(void*)aad, aad_length}; - struct iovec ciphertext_vec = {(void*)ciphertext_and_tag, + struct iovec aad_vec = {const_cast(aad), aad_length}; + struct iovec ciphertext_vec = {const_cast(ciphertext_and_tag), ciphertext_and_tag_length}; struct iovec plaintext_vec = {plaintext, plaintext_length}; return crypter->vtable->decrypt_iovec( diff --git a/src/core/tsi/alts/frame_protector/frame_handler.cc b/src/core/tsi/alts/frame_protector/frame_handler.cc index d3fda63b3dd..aa90bbc634a 100644 --- a/src/core/tsi/alts/frame_protector/frame_handler.cc +++ b/src/core/tsi/alts/frame_protector/frame_handler.cc @@ -31,16 +31,18 @@ /* Use little endian to interpret a string of bytes as uint32_t. */ static uint32_t load_32_le(const unsigned char* buffer) { - return (((uint32_t)buffer[3]) << 24) | (((uint32_t)buffer[2]) << 16) | - (((uint32_t)buffer[1]) << 8) | ((uint32_t)buffer[0]); + return (static_cast(buffer[3]) << 24) | + (static_cast(buffer[2]) << 16) | + (static_cast(buffer[1]) << 8) | + static_cast(buffer[0]); } /* Store uint32_t as a string of little endian bytes. */ static void store_32_le(uint32_t value, unsigned char* buffer) { - buffer[3] = (unsigned char)(value >> 24) & 0xFF; - buffer[2] = (unsigned char)(value >> 16) & 0xFF; - buffer[1] = (unsigned char)(value >> 8) & 0xFF; - buffer[0] = (unsigned char)(value)&0xFF; + buffer[3] = static_cast(value >> 24) & 0xFF; + buffer[2] = static_cast(value >> 16) & 0xFF; + buffer[1] = static_cast(value >> 8) & 0xFF; + buffer[0] = static_cast(value) & 0xFF; } /* Frame writer implementation. */ diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc index e2f04f7310d..845b23fe65b 100644 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc @@ -279,7 +279,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, if (code != GRPC_STATUS_OK) { upb_strview details = grpc_gcp_HandshakerStatus_details(resp_status); if (details.size > 0) { - char* error_details = (char*)gpr_zalloc(details.size + 1); + char* error_details = static_cast(gpr_zalloc(details.size + 1)); memcpy(error_details, details.data, details.size); gpr_log(GPR_ERROR, "Error from handshaker service:%s", error_details); gpr_free(error_details); diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc index 6a548e50dd4..26c18a45048 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc @@ -56,16 +56,18 @@ static void maybe_append_error_msg(const char* appendix, char** dst) { /* Use little endian to interpret a string of bytes as uint32_t. */ static uint32_t load_32_le(const unsigned char* buffer) { - return (((uint32_t)buffer[3]) << 24) | (((uint32_t)buffer[2]) << 16) | - (((uint32_t)buffer[1]) << 8) | ((uint32_t)buffer[0]); + return (static_cast(buffer[3]) << 24) | + (static_cast(buffer[2]) << 16) | + (static_cast(buffer[1]) << 8) | + static_cast(buffer[0]); } /* Store uint32_t as a string of little endian bytes. */ static void store_32_le(uint32_t value, unsigned char* buffer) { - buffer[3] = (unsigned char)(value >> 24) & 0xFF; - buffer[2] = (unsigned char)(value >> 16) & 0xFF; - buffer[1] = (unsigned char)(value >> 8) & 0xFF; - buffer[0] = (unsigned char)(value)&0xFF; + buffer[3] = static_cast(value >> 24) & 0xFF; + buffer[2] = static_cast(value >> 16) & 0xFF; + buffer[1] = static_cast(value >> 8) & 0xFF; + buffer[0] = static_cast(value) & 0xFF; } /* Ensures header and tag iovec have sufficient length. */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc index 0cdf97465d0..e0ce64104c9 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc @@ -87,10 +87,10 @@ static bool read_frame_size(const grpc_slice_buffer* sb, } GPR_ASSERT(remaining == 0); /* Gets little-endian frame size. */ - uint32_t frame_size = (((uint32_t)frame_size_buffer[3]) << 24) | - (((uint32_t)frame_size_buffer[2]) << 16) | - (((uint32_t)frame_size_buffer[1]) << 8) | - ((uint32_t)frame_size_buffer[0]); + uint32_t frame_size = (static_cast(frame_size_buffer[3]) << 24) | + (static_cast(frame_size_buffer[2]) << 16) | + (static_cast(frame_size_buffer[1]) << 8) | + static_cast(frame_size_buffer[0]); if (frame_size > kMaxFrameLength) { gpr_log(GPR_ERROR, "Frame size is larger than maximum frame size"); return false; diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index 06756543f8d..0b256a1fc21 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -524,7 +524,8 @@ static tsi_result fake_handshaker_result_create_frame_protector( static tsi_result fake_handshaker_result_get_unused_bytes( const tsi_handshaker_result* self, const unsigned char** bytes, size_t* bytes_size) { - fake_handshaker_result* result = (fake_handshaker_result*)self; + fake_handshaker_result* result = reinterpret_cast( + const_cast(self)); *bytes_size = result->unused_bytes_size; *bytes = result->unused_bytes; return TSI_OK; @@ -581,8 +582,9 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( static_cast(impl->next_message_to_send + 2); const char* msg_string = tsi_fake_handshake_message_to_string(impl->next_message_to_send); - result = tsi_fake_frame_set_data((unsigned char*)msg_string, - strlen(msg_string), &impl->outgoing_frame); + result = tsi_fake_frame_set_data( + reinterpret_cast(const_cast(msg_string)), + strlen(msg_string), &impl->outgoing_frame); if (result != TSI_OK) return result; if (next_message_to_send > TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { next_message_to_send = TSI_FAKE_HANDSHAKE_MESSAGE_MAX; diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 8108ff26bb8..59f6294be66 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -340,8 +340,7 @@ static tsi_result add_pem_certificate(X509* cert, tsi_peer_property* property) { return TSI_INTERNAL_ERROR; } tsi_result result = tsi_construct_string_peer_property( - TSI_X509_PEM_CERT_PROPERTY, (const char*)contents, - static_cast(len), property); + TSI_X509_PEM_CERT_PROPERTY, contents, static_cast(len), property); BIO_free(bio); return result; } @@ -554,12 +553,12 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, X509* certificate = nullptr; BIO* pem; GPR_ASSERT(pem_cert_chain_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_cert_chain, - static_cast(pem_cert_chain_size)); + pem = BIO_new_mem_buf(pem_cert_chain, static_cast(pem_cert_chain_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { - certificate = PEM_read_bio_X509_AUX(pem, nullptr, nullptr, (void*)""); + certificate = + PEM_read_bio_X509_AUX(pem, nullptr, nullptr, const_cast("")); if (certificate == nullptr) { result = TSI_INVALID_ARGUMENT; break; @@ -570,7 +569,7 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, } while (true) { X509* certificate_authority = - PEM_read_bio_X509(pem, nullptr, nullptr, (void*)""); + PEM_read_bio_X509(pem, nullptr, nullptr, const_cast("")); if (certificate_authority == nullptr) { ERR_clear_error(); break; /* Done reading. */ @@ -674,10 +673,11 @@ static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX* context, EVP_PKEY* private_key = nullptr; BIO* pem; GPR_ASSERT(pem_key_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_key, static_cast(pem_key_size)); + pem = BIO_new_mem_buf(pem_key, static_cast(pem_key_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { - private_key = PEM_read_bio_PrivateKey(pem, nullptr, nullptr, (void*)""); + private_key = + PEM_read_bio_PrivateKey(pem, nullptr, nullptr, const_cast("")); if (private_key == nullptr) { result = TSI_INVALID_ARGUMENT; break; @@ -718,7 +718,7 @@ static tsi_result x509_store_load_certs(X509_STORE* cert_store, X509_NAME* root_name = nullptr; BIO* pem; GPR_ASSERT(pem_roots_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_roots, static_cast(pem_roots_size)); + pem = BIO_new_mem_buf(pem_roots, static_cast(pem_roots_size)); if (cert_store == nullptr) return TSI_INVALID_ARGUMENT; if (pem == nullptr) return TSI_OUT_OF_RESOURCES; if (root_names != nullptr) { @@ -727,7 +727,7 @@ static tsi_result x509_store_load_certs(X509_STORE* cert_store, } while (true) { - root = PEM_read_bio_X509_AUX(pem, nullptr, nullptr, (void*)""); + root = PEM_read_bio_X509_AUX(pem, nullptr, nullptr, const_cast("")); if (root == nullptr) { ERR_clear_error(); break; /* We're at the end of stream. */ @@ -837,10 +837,10 @@ tsi_result tsi_ssl_extract_x509_subject_names_from_pem_cert( tsi_result result = TSI_OK; X509* cert = nullptr; BIO* pem; - pem = BIO_new_mem_buf((void*)pem_cert, static_cast(strlen(pem_cert))); + pem = BIO_new_mem_buf(pem_cert, static_cast(strlen(pem_cert))); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; - cert = PEM_read_bio_X509(pem, nullptr, nullptr, (void*)""); + cert = PEM_read_bio_X509(pem, nullptr, nullptr, const_cast("")); if (cert == nullptr) { gpr_log(GPR_ERROR, "Invalid certificate"); result = TSI_INVALID_ARGUMENT; @@ -1207,8 +1207,8 @@ tsi_result tsi_ssl_get_cert_chain_contents(STACK_OF(X509) * peer_chain, return TSI_INTERNAL_ERROR; } tsi_result result = tsi_construct_string_peer_property( - TSI_X509_PEM_CERT_CHAIN_PROPERTY, (const char*)contents, - static_cast(len), property); + TSI_X509_PEM_CERT_CHAIN_PROPERTY, contents, static_cast(len), + property); BIO_free(bio); return result; } @@ -1712,7 +1712,7 @@ static int client_handshaker_factory_npn_callback( const unsigned char* in, unsigned int inlen, void* arg) { tsi_ssl_client_handshaker_factory* factory = static_cast(arg); - return select_protocol_list((const unsigned char**)out, outlen, + return select_protocol_list(const_cast(out), outlen, factory->alpn_protocol_list, factory->alpn_protocol_list_length, in, inlen); } diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index 8df6c7b98f5..ab56d6073fe 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -87,7 +87,7 @@ void ChannelFilterPluginInit() { for (size_t i = 0; i < channel_filters->size(); ++i) { FilterRecord& filter = (*channel_filters)[i]; grpc_channel_init_register_stage(filter.stack_type, filter.priority, - MaybeAddFilter, (void*)&filter); + MaybeAddFilter, &filter); } } diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 1d1f2624dc0..a636504082a 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -95,7 +95,7 @@ ServerBuilder& ServerBuilder::RegisterAsyncGenericService( gpr_log(GPR_ERROR, "Adding multiple generic services is unsupported for now. " "Dropping the service %p", - (void*)service); + service); } else { generic_service_ = service; } @@ -122,7 +122,7 @@ ServerBuilder& ServerBuilder::experimental_type::RegisterCallbackGenericService( gpr_log(GPR_ERROR, "Adding multiple generic services is unsupported for now. " "Dropping the service %p", - (void*)service); + service); } else { builder_->callback_generic_service_ = service; } diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 1f366758fd4..000215edf2d 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -53,13 +53,13 @@ static void thd_func(void* arg) { if (a->validator != nullptr) { a->validator(a->server, a->cq, a->registered_method); } - gpr_event_set(&a->done_thd, (void*)1); + gpr_event_set(&a->done_thd, reinterpret_cast(1)); } /* Sets the done_write event */ static void set_done_write(void* arg, grpc_error* /*error*/) { gpr_event* done_write = static_cast(arg); - gpr_event_set(done_write, (void*)1); + gpr_event_set(done_write, reinterpret_cast(1)); } static void server_setup_transport(void* ts, grpc_transport* transport) { @@ -72,7 +72,7 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { /* Sets the read_done event */ static void set_read_done(void* arg, grpc_error* /*error*/) { gpr_event* read_done = static_cast(arg); - gpr_event_set(read_done, (void*)1); + gpr_event_set(read_done, reinterpret_cast(1)); } /* shutdown client */ @@ -307,7 +307,7 @@ bool rst_stream_client_validator(grpc_slice_buffer* incoming, void* /*arg*/) { return success; } -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } void server_verifier_request_call(grpc_server* server, grpc_completion_queue* cq, diff --git a/test/core/bad_client/tests/duplicate_header.cc b/test/core/bad_client/tests/duplicate_header.cc index ae191330281..1fa1fd2f97f 100644 --- a/test/core/bad_client/tests/duplicate_header.cc +++ b/test/core/bad_client/tests/duplicate_header.cc @@ -49,7 +49,7 @@ "\x00\x00\x20\x00\x00\x00\x00\x00\x01" \ "\x00\x00\x00\x00" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void verifier(grpc_server* server, grpc_completion_queue* cq, void* /*registered_method*/) { diff --git a/test/core/bad_client/tests/head_of_line_blocking.cc b/test/core/bad_client/tests/head_of_line_blocking.cc index c856b9b122c..08d7bb8e4c5 100644 --- a/test/core/bad_client/tests/head_of_line_blocking.cc +++ b/test/core/bad_client/tests/head_of_line_blocking.cc @@ -66,7 +66,7 @@ static const char prefix[] = "\x01\x00\x00\x27\x10" ""; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void verifier(grpc_server* server, grpc_completion_queue* cq, void* registered_method) { diff --git a/test/core/bad_client/tests/server_registered_method.cc b/test/core/bad_client/tests/server_registered_method.cc index da0ac28d53b..69e26925044 100644 --- a/test/core/bad_client/tests/server_registered_method.cc +++ b/test/core/bad_client/tests/server_registered_method.cc @@ -38,7 +38,7 @@ "\x10\x02te\x08trailers" \ "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void verifier_succeeds(grpc_server* server, grpc_completion_queue* cq, void* registered_method) { diff --git a/test/core/bad_client/tests/simple_request.cc b/test/core/bad_client/tests/simple_request.cc index d1df05dd349..a4aacc20e8f 100644 --- a/test/core/bad_client/tests/simple_request.cc +++ b/test/core/bad_client/tests/simple_request.cc @@ -85,7 +85,7 @@ "\x10\x0cgrpc-timeout\x02" \ "5S" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void verifier(grpc_server* server, grpc_completion_queue* cq, void* /*registered_method*/) { diff --git a/test/core/bad_connection/close_fd_test.cc b/test/core/bad_connection/close_fd_test.cc index 05498f33521..1c89ee72c11 100644 --- a/test/core/bad_connection/close_fd_test.cc +++ b/test/core/bad_connection/close_fd_test.cc @@ -44,7 +44,7 @@ #include "src/core/lib/surface/completion_queue.h" #include "src/core/lib/surface/server.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } typedef struct test_ctx test_ctx; diff --git a/test/core/bad_ssl/bad_ssl_test.cc b/test/core/bad_ssl/bad_ssl_test.cc index e273f20a201..8fbf52b5cc0 100644 --- a/test/core/bad_ssl/bad_ssl_test.cc +++ b/test/core/bad_ssl/bad_ssl_test.cc @@ -34,7 +34,7 @@ #include "test/core/util/subprocess.h" #include "test/core/util/test_config.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void run_test(const char* target, size_t nops) { grpc_channel_credentials* ssl_creds = @@ -147,7 +147,7 @@ int main(int argc, char** argv) { args[1] = const_cast("--bind"); std::string joined = grpc_core::JoinHostPort("::", port); args[2] = const_cast(joined.c_str()); - svr = gpr_subprocess_create(4, (const char**)args); + svr = gpr_subprocess_create(4, const_cast(args)); gpr_free(args[0]); for (i = 3; i <= 4; i++) { diff --git a/test/core/bad_ssl/server_common.cc b/test/core/bad_ssl/server_common.cc index ebbe2b60a5a..88740a49b6d 100644 --- a/test/core/bad_ssl/server_common.cc +++ b/test/core/bad_ssl/server_common.cc @@ -62,7 +62,8 @@ void bad_ssl_run(grpc_server* server) { grpc_server_start(server); error = grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, (void*)1); + &request_metadata_recv, cq, cq, + reinterpret_cast(1)); GPR_ASSERT(GRPC_CALL_OK == error); signal(SIGINT, sigint_handler); diff --git a/test/core/channel/channel_stack_builder_test.cc b/test/core/channel/channel_stack_builder_test.cc index e408e4d48c6..b154ad205f0 100644 --- a/test/core/channel/channel_stack_builder_test.cc +++ b/test/core/channel/channel_stack_builder_test.cc @@ -111,12 +111,12 @@ static bool add_original_filter(grpc_channel_stack_builder* builder, } static void init_plugin(void) { - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, - add_original_filter, - (void*)&original_filter); - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, - add_replacement_filter, - (void*)&replacement_filter); + grpc_channel_init_register_stage( + GRPC_CLIENT_CHANNEL, INT_MAX, add_original_filter, + const_cast(&original_filter)); + grpc_channel_init_register_stage( + GRPC_CLIENT_CHANNEL, INT_MAX, add_replacement_filter, + const_cast(&replacement_filter)); } static void destroy_plugin(void) {} diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc index 4a7af6a881f..f0917fa67fa 100644 --- a/test/core/channel/channel_trace_test.cc +++ b/test/core/channel/channel_trace_test.cc @@ -73,8 +73,8 @@ void ValidateChannelTraceData(const Json& json, Json::Object object = json.object_value(); Json& num_events_logged_json = object["numEventsLogged"]; ASSERT_EQ(num_events_logged_json.type(), Json::Type::STRING); - size_t num_events_logged = - (size_t)strtol(num_events_logged_json.string_value().c_str(), nullptr, 0); + size_t num_events_logged = static_cast( + strtol(num_events_logged_json.string_value().c_str(), nullptr, 0)); ASSERT_EQ(num_events_logged, num_events_logged_expected); Json& start_time_json = object["creationTimestamp"]; ASSERT_EQ(start_time_json.type(), Json::Type::STRING); diff --git a/test/core/channel/channelz_test.cc b/test/core/channel/channelz_test.cc index 9fc5dbcd8b9..3c7c89848e0 100644 --- a/test/core/channel/channelz_test.cc +++ b/test/core/channel/channelz_test.cc @@ -200,8 +200,8 @@ void ValidateChildInteger(const Json::Object& object, const std::string& key, } ASSERT_NE(it, object.end()); ASSERT_EQ(it->second.type(), Json::Type::STRING); - int64_t gotten_number = - (int64_t)strtol(it->second.string_value().c_str(), nullptr, 0); + int64_t gotten_number = static_cast( + strtol(it->second.string_value().c_str(), nullptr, 0)); EXPECT_EQ(gotten_number, expected); } diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index d0521375e85..163a4f42776 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -128,7 +128,7 @@ class ResultHandler : public grpc_core::Resolver::ResultHandler { GPR_ASSERT(output != nullptr); output->result = std::move(result); output->error = GRPC_ERROR_NONE; - gpr_event_set(&output->ev, (void*)1); + gpr_event_set(&output->ev, reinterpret_cast(1)); } void ReturnError(grpc_error* error) override { @@ -136,7 +136,7 @@ class ResultHandler : public grpc_core::Resolver::ResultHandler { reinterpret_cast(gpr_atm_acq_load(&output_)); GPR_ASSERT(output != nullptr); output->error = error; - gpr_event_set(&output->ev, (void*)1); + gpr_event_set(&output->ev, reinterpret_cast(1)); } private: diff --git a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc index 2d5e37c9f3e..d10468a2092 100644 --- a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc @@ -174,7 +174,7 @@ static void poll_pollset_until_request_done(iomgr_args* args) { gpr_mu_unlock(args->mu); grpc_core::ExecCtx::Get()->Flush(); } - gpr_event_set(&args->ev, (void*)1); + gpr_event_set(&args->ev, reinterpret_cast(1)); } struct OnResolutionCallbackArg; diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index f0316ba4385..c5cdf4b63e5 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -54,7 +54,7 @@ class ResultHandler : public grpc_core::Resolver::ResultHandler { for (size_t i = 0; i < expected_.addresses.size(); ++i) { GPR_ASSERT(actual.addresses[i] == expected_.addresses[i]); } - gpr_event_set(ev_, (void*)1); + gpr_event_set(ev_, reinterpret_cast(1)); ev_ = nullptr; } diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 8cc0b619b18..cb5427fe837 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -93,7 +93,7 @@ static grpc_closure on_read; static grpc_closure on_writing_settings_frame; static grpc_closure on_write; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void done_write(void* /*arg*/, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); @@ -286,7 +286,7 @@ static void actually_poll_server(void* arg) { } test_tcp_server_poll(pa->server, 1000); } - gpr_event_set(pa->signal_when_done, (void*)1); + gpr_event_set(pa->signal_when_done, reinterpret_cast(1)); gpr_free(pa); } diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index 7df6f0ebd5e..59d7c69409b 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -33,7 +33,7 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -static void* tag(intptr_t i) { return (void*)i; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void run_test(bool wait_for_ready, bool use_service_config) { grpc_channel* chan; diff --git a/test/core/end2end/cq_verifier.cc b/test/core/end2end/cq_verifier.cc index b8da655fd56..da526ea9927 100644 --- a/test/core/end2end/cq_verifier.cc +++ b/test/core/end2end/cq_verifier.cc @@ -186,14 +186,17 @@ int byte_buffer_eq_string(grpc_byte_buffer* bb, const char* str) { return byte_buffer_eq_slice(bb, grpc_slice_from_copied_string(str)); } -static bool is_probably_integer(void* p) { return ((uintptr_t)p) < 1000000; } +static bool is_probably_integer(void* p) { + return reinterpret_cast(p) < 1000000; +} namespace { std::string ExpectationString(const Expectation& e) { std::string out; if (is_probably_integer(e.tag)) { - out = absl::StrFormat("tag(%" PRIdPTR ") ", (intptr_t)e.tag); + out = absl::StrFormat("tag(%" PRIdPTR ") ", + reinterpret_cast(e.tag)); } else { out = absl::StrFormat("%p ", e.tag); } diff --git a/test/core/end2end/dualstack_socket_test.cc b/test/core/end2end/dualstack_socket_test.cc index 63b0ddaa92e..2b332dca30c 100644 --- a/test/core/end2end/dualstack_socket_test.cc +++ b/test/core/end2end/dualstack_socket_test.cc @@ -48,7 +48,7 @@ /* This test exercises IPv4, IPv6, and dualstack sockets in various ways. */ -static void* tag(intptr_t i) { return (void*)i; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void drain_cq(grpc_completion_queue* cq) { grpc_event ev; diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index 8901ca6547e..3d55bffd814 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -33,7 +33,7 @@ bool leak_check = true; static void discard_write(grpc_slice /*slice*/) {} -static void* tag(int n) { return (void*)static_cast(n); } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void dont_log(gpr_log_func_args* /*args*/) {} diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index 377a1a99c19..1f1b40ed7d0 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -29,8 +29,7 @@ bool leak_check = true; static void discard_write(grpc_slice /*slice*/) {} -static void* tag(int n) { return (void*)static_cast(n); } -static int detag(void* p) { return static_cast((uintptr_t)p); } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void dont_log(gpr_log_func_args* /*args*/) {} @@ -84,12 +83,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { case GRPC_QUEUE_SHUTDOWN: break; case GRPC_OP_COMPLETE: - switch (detag(ev.tag)) { - case 1: - requested_calls--; - // TODO(ctiller): keep reading that call! - break; + if (ev.tag == tag(1)) { + requested_calls--; + // TODO(ctiller): keep reading that call! } + break; } } diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 6c76c243b21..d0ca2196e05 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -44,7 +44,7 @@ extern grpc_address_resolver_vtable* grpc_resolve_address_impl; static grpc_address_resolver_vtable* default_resolver; -static void* tag(intptr_t i) { return (void*)i; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static gpr_mu g_mu; static int g_resolve_port = -1; diff --git a/test/core/end2end/h2_ssl_session_reuse_test.cc b/test/core/end2end/h2_ssl_session_reuse_test.cc index a209d8f62f8..4aeac24395a 100644 --- a/test/core/end2end/h2_ssl_session_reuse_test.cc +++ b/test/core/end2end/h2_ssl_session_reuse_test.cc @@ -44,7 +44,7 @@ namespace grpc { namespace testing { namespace { -void* tag(intptr_t t) { return (void*)t; } +void* tag(intptr_t t) { return reinterpret_cast(t); } gpr_timespec five_seconds_time() { return grpc_timeout_seconds_to_deadline(5); } diff --git a/test/core/end2end/invalid_call_argument_test.cc b/test/core/end2end/invalid_call_argument_test.cc index 7c2e961a298..10ca9fbe4d4 100644 --- a/test/core/end2end/invalid_call_argument_test.cc +++ b/test/core/end2end/invalid_call_argument_test.cc @@ -31,7 +31,7 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -static void* tag(intptr_t i) { return (void*)i; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } struct test_state { int is_client; diff --git a/test/core/end2end/no_server_test.cc b/test/core/end2end/no_server_test.cc index f5cf823f589..e69d92c640e 100644 --- a/test/core/end2end/no_server_test.cc +++ b/test/core/end2end/no_server_test.cc @@ -27,7 +27,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/util/test_config.h" -static void* tag(intptr_t i) { return (void*)i; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } void run_test(bool wait_for_ready) { gpr_log(GPR_INFO, "TEST: wait_for_ready=%d", wait_for_ready); diff --git a/test/core/end2end/tests/authority_not_supported.cc b/test/core/end2end/tests/authority_not_supported.cc index 01a95e4e10b..18cc6f5f120 100644 --- a/test/core/end2end/tests/authority_not_supported.cc +++ b/test/core/end2end/tests/authority_not_supported.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/bad_hostname.cc b/test/core/end2end/tests/bad_hostname.cc index b6f06a20d6a..33281ab88b5 100644 --- a/test/core/end2end/tests/bad_hostname.cc +++ b/test/core/end2end/tests/bad_hostname.cc @@ -29,7 +29,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/bad_ping.cc b/test/core/end2end/tests/bad_ping.cc index 12aff71e188..6d927ee490d 100644 --- a/test/core/end2end/tests/bad_ping.cc +++ b/test/core/end2end/tests/bad_ping.cc @@ -32,7 +32,7 @@ #define MAX_PING_STRIKES 2 -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void drain_cq(grpc_completion_queue* cq) { grpc_event ev; diff --git a/test/core/end2end/tests/binary_metadata.cc b/test/core/end2end/tests/binary_metadata.cc index cdf5b1eb94d..6bcaac5e83e 100644 --- a/test/core/end2end/tests/binary_metadata.cc +++ b/test/core/end2end/tests/binary_metadata.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/call_creds.cc b/test/core/end2end/tests/call_creds.cc index 9d4b0c30c20..a11c95e1b5d 100644 --- a/test/core/end2end/tests/call_creds.cc +++ b/test/core/end2end/tests/call_creds.cc @@ -42,7 +42,7 @@ static const char overridden_fake_md_value[] = "overridden_fake_value"; typedef enum { NONE, OVERRIDE, DESTROY, FAIL } override_mode; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/call_host_override.cc b/test/core/end2end/tests/call_host_override.cc index b5b79fda705..2538999d493 100644 --- a/test/core/end2end/tests/call_host_override.cc +++ b/test/core/end2end/tests/call_host_override.cc @@ -31,7 +31,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index 510bf3cee5f..d80f524e393 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -34,7 +34,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/cancel_after_client_done.cc b/test/core/end2end/tests/cancel_after_client_done.cc index 6e9378378ed..5ff9dd08abd 100644 --- a/test/core/end2end/tests/cancel_after_client_done.cc +++ b/test/core/end2end/tests/cancel_after_client_done.cc @@ -30,7 +30,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/cancel_after_invoke.cc b/test/core/end2end/tests/cancel_after_invoke.cc index 78009eb3bb3..2d58b99ca84 100644 --- a/test/core/end2end/tests/cancel_after_invoke.cc +++ b/test/core/end2end/tests/cancel_after_invoke.cc @@ -31,7 +31,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index 609ac570d90..ea03daed8e5 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -34,7 +34,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/cancel_before_invoke.cc b/test/core/end2end/tests/cancel_before_invoke.cc index abb2dbc8c3c..f118ffff80a 100644 --- a/test/core/end2end/tests/cancel_before_invoke.cc +++ b/test/core/end2end/tests/cancel_before_invoke.cc @@ -28,7 +28,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/cancel_in_a_vacuum.cc b/test/core/end2end/tests/cancel_in_a_vacuum.cc index 4672e64a4e1..4b530f18686 100644 --- a/test/core/end2end/tests/cancel_in_a_vacuum.cc +++ b/test/core/end2end/tests/cancel_in_a_vacuum.cc @@ -30,7 +30,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/cancel_with_status.cc b/test/core/end2end/tests/cancel_with_status.cc index 2d6ad771fcc..80eb5e00d29 100644 --- a/test/core/end2end/tests/cancel_with_status.cc +++ b/test/core/end2end/tests/cancel_with_status.cc @@ -31,7 +31,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -140,8 +140,8 @@ static void simple_request_body(grpc_end2end_test_config /*config*/, GPR_ASSERT(GRPC_CALL_OK == error); char* dynamic_string = gpr_strdup("xyz"); - grpc_call_cancel_with_status(c, GRPC_STATUS_UNIMPLEMENTED, - (const char*)dynamic_string, nullptr); + grpc_call_cancel_with_status(c, GRPC_STATUS_UNIMPLEMENTED, dynamic_string, + nullptr); // The API of \a description allows for it to be a dynamic/non-const // string, test this guarantee. gpr_free(dynamic_string); diff --git a/test/core/end2end/tests/channelz.cc b/test/core/end2end/tests/channelz.cc index 1be992dc0e8..20618736e72 100644 --- a/test/core/end2end/tests/channelz.cc +++ b/test/core/end2end/tests/channelz.cc @@ -33,7 +33,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/client_streaming.cc b/test/core/end2end/tests/client_streaming.cc index e3f8868ed16..f9cfaff7115 100644 --- a/test/core/end2end/tests/client_streaming.cc +++ b/test/core/end2end/tests/client_streaming.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index c703449282f..05ffb500a46 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -39,7 +39,7 @@ #include "src/core/lib/transport/static_metadata.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index 1f589d11437..208672e261f 100644 --- a/test/core/end2end/tests/connectivity.cc +++ b/test/core/end2end/tests/connectivity.cc @@ -25,7 +25,7 @@ #include "src/core/lib/gprpp/thd.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } typedef struct { gpr_event started; @@ -47,7 +47,7 @@ struct CallbackContext { static void child_thread(void* arg) { child_events* ce = static_cast(arg); grpc_event ev; - gpr_event_set(&ce->started, (void*)1); + gpr_event_set(&ce->started, reinterpret_cast(1)); gpr_log(GPR_DEBUG, "verifying"); ev = grpc_completion_queue_next(ce->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), nullptr); @@ -176,22 +176,22 @@ static void test_connectivity(grpc_end2end_test_config config) { static void cb_watch_connectivity( grpc_experimental_completion_queue_functor* functor, int success) { - CallbackContext* cb_ctx = (CallbackContext*)functor; + CallbackContext* cb_ctx = reinterpret_cast(functor); gpr_log(GPR_DEBUG, "cb_watch_connectivity called, verifying"); /* callback must not have errors */ GPR_ASSERT(success != 0); - gpr_event_set(&cb_ctx->finished, (void*)1); + gpr_event_set(&cb_ctx->finished, reinterpret_cast(1)); } static void cb_shutdown(grpc_experimental_completion_queue_functor* functor, int /*success*/) { - CallbackContext* cb_ctx = (CallbackContext*)functor; + CallbackContext* cb_ctx = reinterpret_cast(functor); gpr_log(GPR_DEBUG, "cb_shutdown called, nothing to do"); - gpr_event_set(&cb_ctx->finished, (void*)1); + gpr_event_set(&cb_ctx->finished, reinterpret_cast(1)); } static void test_watch_connectivity_cq_callback( diff --git a/test/core/end2end/tests/default_host.cc b/test/core/end2end/tests/default_host.cc index ec2baef4c96..3527073afc4 100644 --- a/test/core/end2end/tests/default_host.cc +++ b/test/core/end2end/tests/default_host.cc @@ -29,7 +29,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/disappearing_server.cc b/test/core/end2end/tests/disappearing_server.cc index b281d44003d..e8fa4e4fec4 100644 --- a/test/core/end2end/tests/disappearing_server.cc +++ b/test/core/end2end/tests/disappearing_server.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static gpr_timespec n_seconds_from_now(int n) { return grpc_timeout_seconds_to_deadline(n); diff --git a/test/core/end2end/tests/empty_batch.cc b/test/core/end2end/tests/empty_batch.cc index 1144ebf1759..7325616f3fe 100644 --- a/test/core/end2end/tests/empty_batch.cc +++ b/test/core/end2end/tests/empty_batch.cc @@ -29,7 +29,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/filter_causes_close.cc b/test/core/end2end/tests/filter_causes_close.cc index 7f99b9219e2..fb1af999699 100644 --- a/test/core/end2end/tests/filter_causes_close.cc +++ b/test/core/end2end/tests/filter_causes_close.cc @@ -32,7 +32,7 @@ static bool g_enable_filter = false; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/filter_context.cc b/test/core/end2end/tests/filter_context.cc index 0c418748334..5b02e067d08 100644 --- a/test/core/end2end/tests/filter_context.cc +++ b/test/core/end2end/tests/filter_context.cc @@ -36,7 +36,7 @@ enum { TIMEOUT = 200000 }; static bool g_enable_filter = false; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -295,14 +295,18 @@ static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { } static void init_plugin(void) { - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, - maybe_add_filter, (void*)&test_filter); - grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, - maybe_add_filter, (void*)&test_filter); - grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, - maybe_add_filter, (void*)&test_filter); - grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, - maybe_add_filter, (void*)&test_filter); + grpc_channel_init_register_stage( + GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_filter)); + grpc_channel_init_register_stage( + GRPC_CLIENT_SUBCHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_filter)); + grpc_channel_init_register_stage( + GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_filter)); + grpc_channel_init_register_stage( + GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_filter)); } static void destroy_plugin(void) {} diff --git a/test/core/end2end/tests/filter_init_fails.cc b/test/core/end2end/tests/filter_init_fails.cc index 4c9b16155a8..2ac21cf0035 100644 --- a/test/core/end2end/tests/filter_init_fails.cc +++ b/test/core/end2end/tests/filter_init_fails.cc @@ -38,7 +38,7 @@ static bool g_enable_client_channel_filter = false; static bool g_enable_client_subchannel_filter = false; static bool g_channel_filter_init_failure = false; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/filter_latency.cc b/test/core/end2end/tests/filter_latency.cc index b0992b1aa8e..1a8091e86ed 100644 --- a/test/core/end2end/tests/filter_latency.cc +++ b/test/core/end2end/tests/filter_latency.cc @@ -39,7 +39,7 @@ static gpr_mu g_mu; static gpr_timespec g_client_latency; static gpr_timespec g_server_latency; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -326,15 +326,15 @@ static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { static void init_plugin(void) { gpr_mu_init(&g_mu); - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, - maybe_add_filter, - (void*)&test_client_filter); - grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, - maybe_add_filter, - (void*)&test_client_filter); - grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, - maybe_add_filter, - (void*)&test_server_filter); + grpc_channel_init_register_stage( + GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_client_filter)); + grpc_channel_init_register_stage( + GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_client_filter)); + grpc_channel_init_register_stage( + GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_server_filter)); } static void destroy_plugin(void) { gpr_mu_destroy(&g_mu); } diff --git a/test/core/end2end/tests/filter_status_code.cc b/test/core/end2end/tests/filter_status_code.cc index 3fc47acc681..061166fa111 100644 --- a/test/core/end2end/tests/filter_status_code.cc +++ b/test/core/end2end/tests/filter_status_code.cc @@ -52,7 +52,7 @@ static gpr_cv g_server_code_cv; static grpc_status_code g_client_status_code; static grpc_status_code g_server_status_code; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -376,15 +376,15 @@ static void init_plugin(void) { g_client_code_recv = false; g_server_code_recv = false; - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, - maybe_add_filter, - (void*)&test_client_filter); - grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, - maybe_add_filter, - (void*)&test_client_filter); - grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, - maybe_add_filter, - (void*)&test_server_filter); + grpc_channel_init_register_stage( + GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_client_filter)); + grpc_channel_init_register_stage( + GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_client_filter)); + grpc_channel_init_register_stage( + GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter, + const_cast(&test_server_filter)); } static void destroy_plugin(void) { diff --git a/test/core/end2end/tests/graceful_server_shutdown.cc b/test/core/end2end/tests/graceful_server_shutdown.cc index 376b00bca24..93561bf5c3d 100644 --- a/test/core/end2end/tests/graceful_server_shutdown.cc +++ b/test/core/end2end/tests/graceful_server_shutdown.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/high_initial_seqno.cc b/test/core/end2end/tests/high_initial_seqno.cc index 30ccc83dfbc..55005947499 100644 --- a/test/core/end2end/tests/high_initial_seqno.cc +++ b/test/core/end2end/tests/high_initial_seqno.cc @@ -34,7 +34,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/hpack_size.cc b/test/core/end2end/tests/hpack_size.cc index 8dfb9ebdd68..a9be0144fac 100644 --- a/test/core/end2end/tests/hpack_size.cc +++ b/test/core/end2end/tests/hpack_size.cc @@ -35,7 +35,7 @@ #include "src/core/lib/gpr/useful.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } const char* hobbits[][2] = { {"Adaldrida", "Brandybuck"}, {"Adamanta", "Took"}, diff --git a/test/core/end2end/tests/idempotent_request.cc b/test/core/end2end/tests/idempotent_request.cc index f91375c0ca6..294b94c70d2 100644 --- a/test/core/end2end/tests/idempotent_request.cc +++ b/test/core/end2end/tests/idempotent_request.cc @@ -30,7 +30,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/invoke_large_request.cc b/test/core/end2end/tests/invoke_large_request.cc index 2ac09a36d93..987125f622d 100644 --- a/test/core/end2end/tests/invoke_large_request.cc +++ b/test/core/end2end/tests/invoke_large_request.cc @@ -33,7 +33,7 @@ #include "src/core/lib/gpr/useful.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/keepalive_timeout.cc b/test/core/end2end/tests/keepalive_timeout.cc index 1750f6fe5ee..a1aacd024bd 100644 --- a/test/core/end2end/tests/keepalive_timeout.cc +++ b/test/core/end2end/tests/keepalive_timeout.cc @@ -37,7 +37,7 @@ #include "src/core/lib/iomgr/ev_posix.h" #endif // GRPC_POSIX_SOCKET -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/large_metadata.cc b/test/core/end2end/tests/large_metadata.cc index fb1fe412566..07983d8eb96 100644 --- a/test/core/end2end/tests/large_metadata.cc +++ b/test/core/end2end/tests/large_metadata.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/max_concurrent_streams.cc b/test/core/end2end/tests/max_concurrent_streams.cc index 90f2f5a065d..bd7d7cd4e8f 100644 --- a/test/core/end2end/tests/max_concurrent_streams.cc +++ b/test/core/end2end/tests/max_concurrent_streams.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -343,7 +343,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { * both); * check this here */ /* We'll get tag 303 or 403, we want 300, 400 */ - live_call = (static_cast((intptr_t)ev.tag)) - 1; + live_call = (static_cast(reinterpret_cast(ev.tag))) - 1; got_client_start = 1; } } diff --git a/test/core/end2end/tests/max_connection_age.cc b/test/core/end2end/tests/max_connection_age.cc index a8979f0a5cf..63b804294d8 100644 --- a/test/core/end2end/tests/max_connection_age.cc +++ b/test/core/end2end/tests/max_connection_age.cc @@ -45,7 +45,7 @@ /* The grace period for the test to observe the channel shutdown process */ #define IMMEDIATE_SHUTDOWN_GRACE_TIME_MS 3000 -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void drain_cq(grpc_completion_queue* cq) { grpc_event ev; diff --git a/test/core/end2end/tests/max_connection_idle.cc b/test/core/end2end/tests/max_connection_idle.cc index 53701ab6137..6df32f4b376 100644 --- a/test/core/end2end/tests/max_connection_idle.cc +++ b/test/core/end2end/tests/max_connection_idle.cc @@ -32,7 +32,7 @@ #define MAX_CONNECTION_IDLE_MS 500 #define MAX_CONNECTION_AGE_MS 9999 -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void drain_cq(grpc_completion_queue* cq) { grpc_event ev; diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index 256cc982940..ca9f8605282 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -34,7 +34,7 @@ #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/negative_deadline.cc b/test/core/end2end/tests/negative_deadline.cc index 464267c92f1..e975f371db8 100644 --- a/test/core/end2end/tests/negative_deadline.cc +++ b/test/core/end2end/tests/negative_deadline.cc @@ -30,7 +30,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/no_error_on_hotpath.cc b/test/core/end2end/tests/no_error_on_hotpath.cc index 7affd5ba6f6..411ed93e5d1 100644 --- a/test/core/end2end/tests/no_error_on_hotpath.cc +++ b/test/core/end2end/tests/no_error_on_hotpath.cc @@ -31,7 +31,7 @@ #include "src/core/lib/iomgr/error.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/no_logging.cc b/test/core/end2end/tests/no_logging.cc index 8341501af2a..5f325271f92 100644 --- a/test/core/end2end/tests/no_logging.cc +++ b/test/core/end2end/tests/no_logging.cc @@ -36,7 +36,7 @@ enum { TIMEOUT = 200000 }; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } void gpr_default_log(gpr_log_func_args* args); @@ -53,10 +53,11 @@ static void test_no_error_log(gpr_log_func_args* args) { } } -static gpr_atm g_log_func = (gpr_atm)gpr_default_log; +static gpr_atm g_log_func = reinterpret_cast(gpr_default_log); static void log_dispatcher_func(gpr_log_func_args* args) { - gpr_log_func log_func = (gpr_log_func)gpr_atm_no_barrier_load(&g_log_func); + gpr_log_func log_func = + reinterpret_cast(gpr_atm_no_barrier_load(&g_log_func)); log_func(args); } diff --git a/test/core/end2end/tests/no_op.cc b/test/core/end2end/tests/no_op.cc index 020f8422192..2c515f10c22 100644 --- a/test/core/end2end/tests/no_op.cc +++ b/test/core/end2end/tests/no_op.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/payload.cc b/test/core/end2end/tests/payload.cc index 6e2bc1690b6..fab5daf837d 100644 --- a/test/core/end2end/tests/payload.cc +++ b/test/core/end2end/tests/payload.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/ping.cc b/test/core/end2end/tests/ping.cc index 0a979626155..28bef18c026 100644 --- a/test/core/end2end/tests/ping.cc +++ b/test/core/end2end/tests/ping.cc @@ -29,7 +29,7 @@ #define PING_NUM 5 -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static void test_ping(grpc_end2end_test_config config, int min_time_between_pings_ms) { diff --git a/test/core/end2end/tests/ping_pong_streaming.cc b/test/core/end2end/tests/ping_pong_streaming.cc index 30ee0bf8b82..4e030e015c1 100644 --- a/test/core/end2end/tests/ping_pong_streaming.cc +++ b/test/core/end2end/tests/ping_pong_streaming.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/proxy_auth.cc b/test/core/end2end/tests/proxy_auth.cc index 3f1443f5b56..3684b27a099 100644 --- a/test/core/end2end/tests/proxy_auth.cc +++ b/test/core/end2end/tests/proxy_auth.cc @@ -34,7 +34,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/registered_call.cc b/test/core/end2end/tests/registered_call.cc index 6228476e5e9..719758ea1fc 100644 --- a/test/core/end2end/tests/registered_call.cc +++ b/test/core/end2end/tests/registered_call.cc @@ -30,7 +30,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/request_with_flags.cc b/test/core/end2end/tests/request_with_flags.cc index f3baf3790fb..348e0b66a6a 100644 --- a/test/core/end2end/tests/request_with_flags.cc +++ b/test/core/end2end/tests/request_with_flags.cc @@ -30,7 +30,7 @@ #include "src/core/lib/transport/byte_stream.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/request_with_payload.cc b/test/core/end2end/tests/request_with_payload.cc index 37d9481f282..404c3bf6d7d 100644 --- a/test/core/end2end/tests/request_with_payload.cc +++ b/test/core/end2end/tests/request_with_payload.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/resource_quota_server.cc b/test/core/end2end/tests/resource_quota_server.cc index df83caa6625..96c0686f3a7 100644 --- a/test/core/end2end/tests/resource_quota_server.cc +++ b/test/core/end2end/tests/resource_quota_server.cc @@ -28,7 +28,7 @@ #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -238,7 +238,7 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_completion_queue_next(f.cq, n_seconds_from_now(60), nullptr); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - int ev_tag = static_cast((intptr_t)ev.tag); + int ev_tag = static_cast(reinterpret_cast(ev.tag)); if (ev_tag < CLIENT_BASE_TAG) { abort(); /* illegal tag */ } else if (ev_tag < SERVER_START_BASE_TAG) { diff --git a/test/core/end2end/tests/retry.cc b/test/core/end2end/tests/retry.cc index 243dedc62c1..5e9f8aa52da 100644 --- a/test/core/end2end/tests/retry.cc +++ b/test/core/end2end/tests/retry.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -182,7 +182,8 @@ static void test_retry(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -221,7 +222,8 @@ static void test_retry(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); @@ -281,7 +283,8 @@ static void test_retry(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(202), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(202), true); diff --git a/test/core/end2end/tests/retry_cancellation.cc b/test/core/end2end/tests/retry_cancellation.cc index 86a835303fd..261e962c369 100644 --- a/test/core/end2end/tests/retry_cancellation.cc +++ b/test/core/end2end/tests/retry_cancellation.cc @@ -40,7 +40,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -186,7 +186,8 @@ static void test_retry_cancellation(grpc_end2end_test_config config, op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); // Server gets a call and fails with retryable status. @@ -219,7 +220,8 @@ static void test_retry_cancellation(grpc_end2end_test_config config, op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); diff --git a/test/core/end2end/tests/retry_disabled.cc b/test/core/end2end/tests/retry_disabled.cc index 340daed27b4..3cdc0452c70 100644 --- a/test/core/end2end/tests/retry_disabled.cc +++ b/test/core/end2end/tests/retry_disabled.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -186,7 +186,8 @@ static void test_retry_disabled(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -218,7 +219,8 @@ static void test_retry_disabled(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); diff --git a/test/core/end2end/tests/retry_exceeds_buffer_size_in_initial_batch.cc b/test/core/end2end/tests/retry_exceeds_buffer_size_in_initial_batch.cc index 8d2dcc72ca4..4d5f6914c82 100644 --- a/test/core/end2end/tests/retry_exceeds_buffer_size_in_initial_batch.cc +++ b/test/core/end2end/tests/retry_exceeds_buffer_size_in_initial_batch.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -189,7 +189,8 @@ static void test_retry_exceeds_buffer_size_in_initial_batch( op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -221,7 +222,8 @@ static void test_retry_exceeds_buffer_size_in_initial_batch( op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); diff --git a/test/core/end2end/tests/retry_exceeds_buffer_size_in_subsequent_batch.cc b/test/core/end2end/tests/retry_exceeds_buffer_size_in_subsequent_batch.cc index 6a93834dcdd..1c99f4c31ba 100644 --- a/test/core/end2end/tests/retry_exceeds_buffer_size_in_subsequent_batch.cc +++ b/test/core/end2end/tests/retry_exceeds_buffer_size_in_subsequent_batch.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -178,7 +178,8 @@ static void test_retry_exceeds_buffer_size_in_subsequent_batch( op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(1), true); cq_verify(cqv); @@ -201,7 +202,8 @@ static void test_retry_exceeds_buffer_size_in_subsequent_batch( op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(2), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -233,7 +235,8 @@ static void test_retry_exceeds_buffer_size_in_subsequent_batch( op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); diff --git a/test/core/end2end/tests/retry_non_retriable_status.cc b/test/core/end2end/tests/retry_non_retriable_status.cc index b8ae4aded27..51247138bef 100644 --- a/test/core/end2end/tests/retry_non_retriable_status.cc +++ b/test/core/end2end/tests/retry_non_retriable_status.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -181,7 +181,8 @@ static void test_retry_non_retriable_status(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -213,7 +214,8 @@ static void test_retry_non_retriable_status(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); diff --git a/test/core/end2end/tests/retry_non_retriable_status_before_recv_trailing_metadata_started.cc b/test/core/end2end/tests/retry_non_retriable_status_before_recv_trailing_metadata_started.cc index c0f35d98f2b..5bdada8a1f6 100644 --- a/test/core/end2end/tests/retry_non_retriable_status_before_recv_trailing_metadata_started.cc +++ b/test/core/end2end/tests/retry_non_retriable_status_before_recv_trailing_metadata_started.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -179,7 +179,8 @@ test_retry_non_retriable_status_before_recv_trailing_metadata_started( op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -211,7 +212,8 @@ test_retry_non_retriable_status_before_recv_trailing_metadata_started( op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); @@ -225,7 +227,8 @@ test_retry_non_retriable_status_before_recv_trailing_metadata_started( op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(2), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(2), true); diff --git a/test/core/end2end/tests/retry_recv_initial_metadata.cc b/test/core/end2end/tests/retry_recv_initial_metadata.cc index 6205373c3ab..eae84eee257 100644 --- a/test/core/end2end/tests/retry_recv_initial_metadata.cc +++ b/test/core/end2end/tests/retry_recv_initial_metadata.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -182,7 +182,8 @@ static void test_retry_recv_initial_metadata(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -208,7 +209,8 @@ static void test_retry_recv_initial_metadata(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); @@ -224,7 +226,8 @@ static void test_retry_recv_initial_metadata(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(103), true); diff --git a/test/core/end2end/tests/retry_recv_message.cc b/test/core/end2end/tests/retry_recv_message.cc index 75be2588bf8..f720591f926 100644 --- a/test/core/end2end/tests/retry_recv_message.cc +++ b/test/core/end2end/tests/retry_recv_message.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -182,7 +182,8 @@ static void test_retry_recv_message(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -217,7 +218,8 @@ static void test_retry_recv_message(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(103), true); diff --git a/test/core/end2end/tests/retry_server_pushback_delay.cc b/test/core/end2end/tests/retry_server_pushback_delay.cc index 221b4168282..122eb494dc8 100644 --- a/test/core/end2end/tests/retry_server_pushback_delay.cc +++ b/test/core/end2end/tests/retry_server_pushback_delay.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -187,7 +187,8 @@ static void test_retry_server_pushback_delay(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -220,7 +221,8 @@ static void test_retry_server_pushback_delay(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); @@ -274,7 +276,8 @@ static void test_retry_server_pushback_delay(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(202), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(202), true); diff --git a/test/core/end2end/tests/retry_server_pushback_disabled.cc b/test/core/end2end/tests/retry_server_pushback_disabled.cc index 28515eb4d7f..44a37a42195 100644 --- a/test/core/end2end/tests/retry_server_pushback_disabled.cc +++ b/test/core/end2end/tests/retry_server_pushback_disabled.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -188,7 +188,8 @@ static void test_retry_server_pushback_disabled( op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -220,7 +221,8 @@ static void test_retry_server_pushback_disabled( op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); @@ -262,7 +264,8 @@ static void test_retry_server_pushback_disabled( op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(202), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(202), true); diff --git a/test/core/end2end/tests/retry_streaming.cc b/test/core/end2end/tests/retry_streaming.cc index 784014cf330..25219102b80 100644 --- a/test/core/end2end/tests/retry_streaming.cc +++ b/test/core/end2end/tests/retry_streaming.cc @@ -40,7 +40,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -200,7 +200,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); // Client sends initial metadata and a message. @@ -212,7 +213,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = request_payload; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(2), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(2), true); cq_verify(cqv); @@ -240,7 +242,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); cq_verify(cqv); @@ -251,7 +254,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = request2_payload; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(3), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(3), true); cq_verify(cqv); @@ -262,7 +266,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request2_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(103), true); cq_verify(cqv); @@ -281,7 +286,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->data.send_status_from_server.status = GRPC_STATUS_ABORTED; op->data.send_status_from_server.status_details = &status_details; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(104), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(104), true); cq_verify(cqv); @@ -323,7 +329,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(202), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(202), true); cq_verify(cqv); @@ -334,7 +341,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request2_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(203), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(203), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(203), true); cq_verify(cqv); @@ -347,7 +355,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op++; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(4), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(4), true); cq_verify(cqv); @@ -358,7 +367,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request3_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(204), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(204), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(204), true); cq_verify(cqv); @@ -383,7 +393,8 @@ static void test_retry_streaming(grpc_end2end_test_config config) { op->data.send_status_from_server.status = GRPC_STATUS_ABORTED; op->data.send_status_from_server.status_details = &status_details; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(205), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(205), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(205), true); CQ_EXPECT_COMPLETION(cqv, tag(1), true); diff --git a/test/core/end2end/tests/retry_streaming_after_commit.cc b/test/core/end2end/tests/retry_streaming_after_commit.cc index 509d56df238..de7d7c3d372 100644 --- a/test/core/end2end/tests/retry_streaming_after_commit.cc +++ b/test/core/end2end/tests/retry_streaming_after_commit.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -177,7 +177,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &response_payload_recv; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(2), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); // Client sends initial metadata and a message. @@ -189,7 +190,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = request_payload; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(3), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(3), true); cq_verify(cqv); @@ -217,7 +219,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); cq_verify(cqv); @@ -231,7 +234,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = response_payload; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(103), true); // Client receives initial metadata and a message. @@ -246,7 +250,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op++; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(4), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(4), true); cq_verify(cqv); @@ -257,7 +262,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request2_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(104), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(104), true); cq_verify(cqv); @@ -278,7 +284,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->data.send_status_from_server.status = GRPC_STATUS_ABORTED; op->data.send_status_from_server.status_details = &status_details; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(105), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(105), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(105), true); cq_verify(cqv); @@ -289,7 +296,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &response2_payload_recv; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(5), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(5), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(5), true); cq_verify(cqv); @@ -302,7 +310,8 @@ static void test_retry_streaming_after_commit(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(1), true); cq_verify(cqv); diff --git a/test/core/end2end/tests/retry_streaming_succeeds_before_replay_finished.cc b/test/core/end2end/tests/retry_streaming_succeeds_before_replay_finished.cc index dbe2ef19f2d..866c948161d 100644 --- a/test/core/end2end/tests/retry_streaming_succeeds_before_replay_finished.cc +++ b/test/core/end2end/tests/retry_streaming_succeeds_before_replay_finished.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -183,7 +183,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); // Client sends initial metadata and a message. @@ -195,7 +196,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = request_payload; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(2), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(2), true); cq_verify(cqv); @@ -223,7 +225,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); cq_verify(cqv); @@ -234,7 +237,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = request2_payload; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(3), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(3), true); cq_verify(cqv); @@ -245,7 +249,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request2_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(103), true); cq_verify(cqv); @@ -256,7 +261,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = request3_payload; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(4), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(4), true); cq_verify(cqv); @@ -267,7 +273,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request3_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(104), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(104), true); cq_verify(cqv); @@ -286,7 +293,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->data.send_status_from_server.status = GRPC_STATUS_ABORTED; op->data.send_status_from_server.status_details = &status_details; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(105), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(105), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(105), true); cq_verify(cqv); @@ -332,7 +340,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(202), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(202), true); cq_verify(cqv); @@ -353,7 +362,8 @@ static void test_retry_streaming_succeeds_before_replay_finished( op->data.send_status_from_server.status = GRPC_STATUS_ABORTED; op->data.send_status_from_server.status_details = &status_details; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(205), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(205), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(205), true); CQ_EXPECT_COMPLETION(cqv, tag(1), true); diff --git a/test/core/end2end/tests/retry_throttled.cc b/test/core/end2end/tests/retry_throttled.cc index 61ced017c14..9fdca88ec2f 100644 --- a/test/core/end2end/tests/retry_throttled.cc +++ b/test/core/end2end/tests/retry_throttled.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -188,7 +188,8 @@ static void test_retry_throttled(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -220,7 +221,8 @@ static void test_retry_throttled(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); diff --git a/test/core/end2end/tests/retry_too_many_attempts.cc b/test/core/end2end/tests/retry_too_many_attempts.cc index 20944511f38..2a8301fd2ee 100644 --- a/test/core/end2end/tests/retry_too_many_attempts.cc +++ b/test/core/end2end/tests/retry_too_many_attempts.cc @@ -37,7 +37,7 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -182,7 +182,8 @@ static void test_retry_too_many_attempts(grpc_end2end_test_config config) { op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -214,7 +215,8 @@ static void test_retry_too_many_attempts(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), true); @@ -255,7 +257,8 @@ static void test_retry_too_many_attempts(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(202), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(202), true); diff --git a/test/core/end2end/tests/server_finishes_request.cc b/test/core/end2end/tests/server_finishes_request.cc index dc489a4c7fb..859fa61ca80 100644 --- a/test/core/end2end/tests/server_finishes_request.cc +++ b/test/core/end2end/tests/server_finishes_request.cc @@ -29,7 +29,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/server_streaming.cc b/test/core/end2end/tests/server_streaming.cc index ece86f80951..f457e650647 100644 --- a/test/core/end2end/tests/server_streaming.cc +++ b/test/core/end2end/tests/server_streaming.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/shutdown_finishes_calls.cc b/test/core/end2end/tests/shutdown_finishes_calls.cc index 60b738ef9ef..443c3cef604 100644 --- a/test/core/end2end/tests/shutdown_finishes_calls.cc +++ b/test/core/end2end/tests/shutdown_finishes_calls.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/shutdown_finishes_tags.cc b/test/core/end2end/tests/shutdown_finishes_tags.cc index 55caacb7ff9..92f45e5e504 100644 --- a/test/core/end2end/tests/shutdown_finishes_tags.cc +++ b/test/core/end2end/tests/shutdown_finishes_tags.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -77,7 +77,7 @@ static void test_early_server_shutdown_finishes_tags( grpc_end2end_test_fixture f = begin_test( config, "test_early_server_shutdown_finishes_tags", nullptr, nullptr); cq_verifier* cqv = cq_verifier_create(f.cq); - grpc_call* s = (grpc_call*)static_cast(1); + grpc_call* s = reinterpret_cast(1); grpc_call_details call_details; grpc_metadata_array request_metadata_recv; diff --git a/test/core/end2end/tests/simple_cacheable_request.cc b/test/core/end2end/tests/simple_cacheable_request.cc index be6d16ecad7..25a09a765fc 100644 --- a/test/core/end2end/tests/simple_cacheable_request.cc +++ b/test/core/end2end/tests/simple_cacheable_request.cc @@ -29,7 +29,7 @@ enum { TIMEOUT = 200000 }; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/simple_delayed_request.cc b/test/core/end2end/tests/simple_delayed_request.cc index 4b2b7ce77fc..947e3976f87 100644 --- a/test/core/end2end/tests/simple_delayed_request.cc +++ b/test/core/end2end/tests/simple_delayed_request.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static gpr_timespec n_seconds_from_now(int n) { return grpc_timeout_seconds_to_deadline(n); diff --git a/test/core/end2end/tests/simple_metadata.cc b/test/core/end2end/tests/simple_metadata.cc index 3e476c2129d..9e1a18b7af7 100644 --- a/test/core/end2end/tests/simple_metadata.cc +++ b/test/core/end2end/tests/simple_metadata.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/simple_request.cc b/test/core/end2end/tests/simple_request.cc index afeb43df057..c9782a1c967 100644 --- a/test/core/end2end/tests/simple_request.cc +++ b/test/core/end2end/tests/simple_request.cc @@ -32,7 +32,7 @@ #include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, @@ -228,7 +228,7 @@ static void simple_request_body(grpc_end2end_test_config config, GPR_ASSERT(was_cancelled == 0); grpc_slice_unref(details); - gpr_free((void*)error_string); + gpr_free(const_cast(error_string)); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index 8fa7af50567..3bb481af587 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -39,7 +39,7 @@ #include "src/core/lib/transport/static_metadata.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index b67566e91bc..cf29185f8ff 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -31,7 +31,7 @@ #include "src/core/lib/surface/call.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index 39698bde442..36c6cd28a66 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -32,7 +32,7 @@ #include "src/core/lib/surface/call.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/streaming_error_response.cc b/test/core/end2end/tests/streaming_error_response.cc index 0502bba15cb..df0c7784736 100644 --- a/test/core/end2end/tests/streaming_error_response.cc +++ b/test/core/end2end/tests/streaming_error_response.cc @@ -30,7 +30,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/trailing_metadata.cc b/test/core/end2end/tests/trailing_metadata.cc index 5cf6f2bb115..1201729909d 100644 --- a/test/core/end2end/tests/trailing_metadata.cc +++ b/test/core/end2end/tests/trailing_metadata.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index 5ffb477aebc..69b33ebcf15 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -36,7 +36,7 @@ #include "src/core/lib/transport/static_metadata.h" #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/write_buffering.cc b/test/core/end2end/tests/write_buffering.cc index 2f7ee9c8926..2f1b297309b 100644 --- a/test/core/end2end/tests/write_buffering.cc +++ b/test/core/end2end/tests/write_buffering.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/end2end/tests/write_buffering_at_end.cc b/test/core/end2end/tests/write_buffering_at_end.cc index 886d491a10f..55c208f346b 100644 --- a/test/core/end2end/tests/write_buffering_at_end.cc +++ b/test/core/end2end/tests/write_buffering_at_end.cc @@ -27,7 +27,7 @@ #include #include "test/core/end2end/cq_verifier.h" -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char* test_name, diff --git a/test/core/fling/client.cc b/test/core/fling/client.cc index 2a7a5ca6232..c9db1951a7c 100644 --- a/test/core/fling/client.cc +++ b/test/core/fling/client.cc @@ -104,7 +104,8 @@ static void init_ping_pong_stream(void) { stream_init_ops[1].op = GRPC_OP_RECV_INITIAL_METADATA; stream_init_ops[1].data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; - error = grpc_call_start_batch(call, stream_init_ops, 2, (void*)1, nullptr); + error = grpc_call_start_batch(call, stream_init_ops, 2, + reinterpret_cast(1), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); @@ -119,7 +120,8 @@ static void init_ping_pong_stream(void) { static void step_ping_pong_stream(void) { GPR_TIMER_SCOPE("ping_pong", 1); grpc_call_error error; - error = grpc_call_start_batch(call, stream_step_ops, 2, (void*)1, nullptr); + error = grpc_call_start_batch(call, stream_step_ops, 2, + reinterpret_cast(1), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); grpc_byte_buffer_destroy(response_payload_recv); diff --git a/test/core/fling/fling_stream_test.cc b/test/core/fling/fling_stream_test.cc index 54ce02d94c6..80b1ebda284 100644 --- a/test/core/fling/fling_stream_test.cc +++ b/test/core/fling/fling_stream_test.cc @@ -50,7 +50,7 @@ int main(int /*argc*/, char** argv) { std::string joined = grpc_core::JoinHostPort("::", port); args[2] = const_cast(joined.c_str()); args[3] = const_cast("--no-secure"); - svr = gpr_subprocess_create(4, (const char**)args); + svr = gpr_subprocess_create(4, const_cast(args)); /* start the client */ command = @@ -62,7 +62,7 @@ int main(int /*argc*/, char** argv) { args[3] = const_cast("--scenario=ping-pong-stream"); args[4] = const_cast("--no-secure"); args[5] = nullptr; - cli = gpr_subprocess_create(6, (const char**)args); + cli = gpr_subprocess_create(6, const_cast(args)); /* wait for completion */ printf("waiting for client\n"); diff --git a/test/core/fling/fling_test.cc b/test/core/fling/fling_test.cc index f1c67288863..0f0d8fe46f1 100644 --- a/test/core/fling/fling_test.cc +++ b/test/core/fling/fling_test.cc @@ -52,7 +52,7 @@ int main(int /*argc*/, const char** argv) { std::string joined = grpc_core::JoinHostPort("::", port); args[2] = const_cast(joined.c_str()); args[3] = const_cast("--no-secure"); - svr = gpr_subprocess_create(4, (const char**)args); + svr = gpr_subprocess_create(4, const_cast(args)); /* start the client */ command = @@ -64,7 +64,7 @@ int main(int /*argc*/, const char** argv) { args[3] = const_cast("--scenario=ping-pong-request"); args[4] = const_cast("--no-secure"); args[5] = nullptr; - cli = gpr_subprocess_create(6, (const char**)args); + cli = gpr_subprocess_create(6, const_cast(args)); /* wait for completion */ printf("waiting for client\n"); diff --git a/test/core/fling/server.cc b/test/core/fling/server.cc index 4085e28ed22..af9bd557fbc 100644 --- a/test/core/fling/server.cc +++ b/test/core/fling/server.cc @@ -59,7 +59,7 @@ static int was_cancelled = 2; static grpc_op unary_ops[6]; static int got_sigint = 0; -static void* tag(intptr_t t) { return (void*)t; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } typedef enum { FLING_SERVER_NEW_REQUEST = 1, @@ -253,7 +253,7 @@ int main(int argc, char** argv) { s = static_cast(ev.tag); switch (ev.type) { case GRPC_OP_COMPLETE: - switch ((intptr_t)s) { + switch (reinterpret_cast(s)) { case FLING_SERVER_NEW_REQUEST: if (call != nullptr) { if (0 == grpc_slice_str_cmp(call_details.method, diff --git a/test/core/gpr/arena_test.cc b/test/core/gpr/arena_test.cc index c7aa63ab2e9..64bd0589897 100644 --- a/test/core/gpr/arena_test.cc +++ b/test/core/gpr/arena_test.cc @@ -106,7 +106,7 @@ static void concurrent_test(void) { thds[i].Start(); } - gpr_event_set(&args.ev_start, (void*)1); + gpr_event_set(&args.ev_start, reinterpret_cast(1)); for (auto& th : thds) { th.Join(); diff --git a/test/core/gpr/sync_test.cc b/test/core/gpr/sync_test.cc index fc7216e3601..ae0025f25bc 100644 --- a/test/core/gpr/sync_test.cc +++ b/test/core/gpr/sync_test.cc @@ -431,7 +431,7 @@ static void refinc(void* v /*=m*/) { } } if (gpr_unref(&m->thread_refcount)) { - gpr_event_set(&m->event, (void*)1); + gpr_event_set(&m->event, reinterpret_cast(1)); } mark_thread_done(m); } diff --git a/test/core/gprpp/fork_test.cc b/test/core/gprpp/fork_test.cc index 0f56eead49d..bc69f77c049 100644 --- a/test/core/gprpp/fork_test.cc +++ b/test/core/gprpp/fork_test.cc @@ -51,7 +51,7 @@ static void test_init() { #define CONCURRENT_TEST_THREADS 100 static void sleeping_thd(void* arg) { - int64_t sleep_ms = (int64_t)arg; + int64_t sleep_ms = reinterpret_cast(arg); gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(sleep_ms, GPR_TIMESPAN))); } @@ -74,8 +74,8 @@ static void test_thd_count() { for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) { intptr_t sleep_time_ms = (i * THREAD_DELAY_MS) / (CONCURRENT_TEST_THREADS - 1); - thds[i] = - grpc_core::Thread("grpc_fork_test", sleeping_thd, (void*)sleep_time_ms); + thds[i] = grpc_core::Thread("grpc_fork_test", sleeping_thd, + reinterpret_cast(sleep_time_ms)); thds[i].Start(); } grpc_core::Fork::AwaitThreads(); @@ -88,7 +88,7 @@ static void test_thd_count() { } static void exec_ctx_thread(void* arg) { - bool* exec_ctx_created = (bool*)arg; + bool* exec_ctx_created = static_cast(arg); grpc_core::Fork::IncExecCtxCount(); *exec_ctx_created = true; } diff --git a/test/core/gprpp/mpscq_test.cc b/test/core/gprpp/mpscq_test.cc index 2c1760f58a0..406679425b0 100644 --- a/test/core/gprpp/mpscq_test.cc +++ b/test/core/gprpp/mpscq_test.cc @@ -90,7 +90,7 @@ static void test_mt(void) { } size_t num_done = 0; size_t spins = 0; - gpr_event_set(&start, (void*)1); + gpr_event_set(&start, reinterpret_cast(1)); while (num_done != GPR_ARRAY_SIZE(thds)) { MultiProducerSingleConsumerQueue::Node* n; while ((n = q.Pop()) == nullptr) { @@ -168,7 +168,7 @@ static void test_mt_multipop(void) { pull_thds[i] = grpc_core::Thread("grpc_multipop_pull", pull_thread, &pa); pull_thds[i].Start(); } - gpr_event_set(&start, (void*)1); + gpr_event_set(&start, reinterpret_cast(1)); for (auto& pth : pull_thds) { pth.Join(); } diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index af78fcd04c1..86a7d76fcd6 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -106,7 +106,8 @@ static int alpn_select_cb(SSL* /*ssl*/, const uint8_t** out, uint8_t* out_len, const uint8_t* alpn_preferred = static_cast(arg); *out = alpn_preferred; - *out_len = static_cast(strlen((char*)alpn_preferred)); + *out_len = static_cast( + strlen(reinterpret_cast(alpn_preferred))); // Validate that the ALPN list includes "h2" and "grpc-exp", that "grpc-exp" // precedes "h2". diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 7a78d2d4d2b..a227050555b 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -184,7 +184,8 @@ int main(int argc, char** argv) { /* start the server */ args[1 + arg_shift] = const_cast("--port"); gpr_asprintf(&args[2 + arg_shift], "%d", port); - server = gpr_subprocess_create(3 + arg_shift, (const char**)args); + server = + gpr_subprocess_create(3 + arg_shift, const_cast(args)); GPR_ASSERT(server); gpr_free(args[0]); if (arg_shift) gpr_free(args[1]); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index 5ed28784c6f..542fe553d19 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -192,7 +192,7 @@ int main(int argc, char** argv) { args[1 + arg_shift] = const_cast("--port"); gpr_asprintf(&args[2 + arg_shift], "%d", port); args[3 + arg_shift] = const_cast("--ssl"); - server = gpr_subprocess_create(4 + arg_shift, (const char**)args); + server = gpr_subprocess_create(4 + arg_shift, const_cast(args)); GPR_ASSERT(server); gpr_free(args[0]); if (arg_shift) gpr_free(args[1]); diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 1554a0909cd..fa0a23df59c 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -33,7 +33,7 @@ static void test_no_op(void) { } static void set_event_to_true(void* value, grpc_error* /*error*/) { - gpr_event_set(static_cast(value), (void*)1); + gpr_event_set(static_cast(value), reinterpret_cast(1)); } static void test_execute_one(void) { @@ -115,7 +115,7 @@ static void test_execute_many(void) { static gpr_event got_in_finally; static void in_finally(void* /*arg*/, grpc_error* /*error*/) { - gpr_event_set(&got_in_finally, (void*)1); + gpr_event_set(&got_in_finally, reinterpret_cast(1)); } static void add_finally(void* arg, grpc_error* /*error*/) { diff --git a/test/core/iomgr/parse_address_with_named_scope_id_test.cc b/test/core/iomgr/parse_address_with_named_scope_id_test.cc index 536e1469e98..1fcc60b1e98 100644 --- a/test/core/iomgr/parse_address_with_named_scope_id_test.cc +++ b/test/core/iomgr/parse_address_with_named_scope_id_test.cc @@ -101,10 +101,10 @@ int main(int argc, char** argv) { // system recognizes, and then use that for the test. for (size_t i = 1; i < 65536; i++) { if (if_indextoname(i, arbitrary_interface_name) != nullptr) { - gpr_log( - GPR_DEBUG, - "Found interface at index %d named %s. Will use this for the test", - (int)i, arbitrary_interface_name); + gpr_log(GPR_DEBUG, + "Found interface at index %" PRIuPTR + " named %s. Will use this for the test", + i, arbitrary_interface_name); break; } } diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 3e6d3462925..c8bebc73372 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -109,7 +109,7 @@ static void actually_poll(void* argsp) { gpr_mu_unlock(args->mu); grpc_core::ExecCtx::Get()->Flush(); } - gpr_event_set(&args->ev, (void*)1); + gpr_event_set(&args->ev, reinterpret_cast(1)); } static void poll_pollset_until_request_done(args_struct* args) { @@ -158,11 +158,11 @@ static void test_named_and_numeric_scope_ids(void) { // system recognizes, and then use that for the test. for (size_t i = 1; i < 65536; i++) { if (if_indextoname(i, arbitrary_interface_name) != nullptr) { - gpr_log( - GPR_DEBUG, - "Found interface at index %d named %s. Will use this for the test", - (int)i, arbitrary_interface_name); - interface_index = (int)i; + gpr_log(GPR_DEBUG, + "Found interface at index %" PRIuPTR + " named %s. Will use this for the test", + i, arbitrary_interface_name); + interface_index = static_cast(i); break; } } diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index ca7c914f51b..62496204c3e 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -101,7 +101,7 @@ static void poll_pollset_until_request_done(args_struct* args) { gpr_mu_unlock(args->mu); grpc_core::ExecCtx::Get()->Flush(); } - gpr_event_set(&args->ev, (void*)1); + gpr_event_set(&args->ev, reinterpret_cast(1)); } static void must_succeed(void* argsp, grpc_error* err) { diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index d5d86a37e7a..7f516b77a43 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -45,7 +45,7 @@ static void assert_counter_becomes(int* ctr, int value) { } static void set_event_cb(void* a, grpc_error* /*error*/) { - gpr_event_set(static_cast(a), (void*)1); + gpr_event_set(static_cast(a), reinterpret_cast(1)); } grpc_closure* set_event(gpr_event* ev) { return GRPC_CLOSURE_CREATE(set_event_cb, ev, grpc_schedule_on_exec_ctx); diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index ad6e126d0c2..3d995eedc11 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -89,14 +89,15 @@ static void create_inet_sockets(int sv[2]) { GPR_ASSERT(client); int ret; do { - ret = connect(client, (sockaddr*)&addr, sizeof(sockaddr_in)); + ret = connect(client, reinterpret_cast(&addr), + sizeof(sockaddr_in)); } while (ret == -1 && errno == EINTR); /* Accept client connection */ len = sizeof(socklen_t); int server; do { - server = accept(sock, (sockaddr*)&addr, (socklen_t*)&len); + server = accept(sock, reinterpret_cast(&addr), &len); } while (server == -1 && errno == EINTR); GPR_ASSERT(server != -1); @@ -388,7 +389,7 @@ void timestamps_verifier(void* arg, grpc_core::Timestamps* ts, GPR_ASSERT(ts->sendmsg_time.time.clock_type == GPR_CLOCK_REALTIME); GPR_ASSERT(ts->scheduled_time.time.clock_type == GPR_CLOCK_REALTIME); GPR_ASSERT(ts->acked_time.time.clock_type == GPR_CLOCK_REALTIME); - gpr_atm* done_timestamps = (gpr_atm*)arg; + gpr_atm* done_timestamps = static_cast(arg); gpr_atm_rel_store(done_timestamps, static_cast(1)); } @@ -447,7 +448,7 @@ static void write_test(size_t num_bytes, size_t slice_size, gpr_atm_rel_store(&done_timestamps, static_cast(0)); grpc_endpoint_write(ep, &outgoing, &write_done_closure, grpc_event_engine_can_track_errors() && collect_timestamps - ? (void*)&done_timestamps + ? &done_timestamps : nullptr); drain_socket_blocking(sv[0], num_bytes, num_bytes); exec_ctx.Flush(); diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index fa2444948b6..a26926d5a84 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -42,7 +42,7 @@ static const int64_t kMillisIn25Days = 2160000000; static const int64_t kHoursIn25Days = 600; static void cb(void* arg, grpc_error* error) { - cb_called[(intptr_t)arg][error == GRPC_ERROR_NONE]++; + cb_called[reinterpret_cast(arg)][error == GRPC_ERROR_NONE]++; } static void add_test(void) { diff --git a/test/core/iomgr/work_serializer_test.cc b/test/core/iomgr/work_serializer_test.cc index fa8ef54f439..bbc9e3f74ab 100644 --- a/test/core/iomgr/work_serializer_test.cc +++ b/test/core/iomgr/work_serializer_test.cc @@ -38,7 +38,8 @@ TEST(WorkSerializerTest, ExecuteOne) { grpc_core::WorkSerializer lock; gpr_event done; gpr_event_init(&done); - lock.Run([&done]() { gpr_event_set(&done, (void*)1); }, DEBUG_LOCATION); + lock.Run([&done]() { gpr_event_set(&done, reinterpret_cast(1)); }, + DEBUG_LOCATION); EXPECT_TRUE(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) != nullptr); } @@ -81,8 +82,9 @@ class TestThread { // sleep for a little bit, to test other threads picking up the load gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); } - self->lock_->Run([self]() { gpr_event_set(&self->done_, (void*)1); }, - DEBUG_LOCATION); + self->lock_->Run( + [self]() { gpr_event_set(&self->done_, reinterpret_cast(1)); }, + DEBUG_LOCATION); } grpc_core::WorkSerializer* lock_ = nullptr; diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index a60d874b6eb..71178cb657d 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -382,7 +382,8 @@ static void test_jwt_verifier_google_email_issuer_success(void) { grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, - on_verification_success, (void*)expected_user_data); + on_verification_success, + const_cast(expected_user_data)); grpc_jwt_verifier_destroy(verifier); grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); @@ -415,7 +416,8 @@ static void test_jwt_verifier_custom_email_issuer_success(void) { grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, - on_verification_success, (void*)expected_user_data); + on_verification_success, + const_cast(expected_user_data)); grpc_jwt_verifier_destroy(verifier); grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); @@ -462,7 +464,8 @@ static void test_jwt_verifier_url_issuer_success(void) { grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, - on_verification_success, (void*)expected_user_data); + on_verification_success, + const_cast(expected_user_data)); grpc_jwt_verifier_destroy(verifier); grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); @@ -502,7 +505,7 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { GPR_ASSERT(jwt != nullptr); grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, - (void*)expected_user_data); + const_cast(expected_user_data)); grpc_jwt_verifier_destroy(verifier); grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); @@ -525,7 +528,7 @@ static void test_jwt_verifier_bad_json_key(void) { GPR_ASSERT(jwt != nullptr); grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, - (void*)expected_user_data); + const_cast(expected_user_data)); grpc_jwt_verifier_destroy(verifier); grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); @@ -577,7 +580,7 @@ static void test_jwt_verifier_bad_signature(void) { GPR_ASSERT(jwt != nullptr); grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_bad_signature, - (void*)expected_user_data); + const_cast(expected_user_data)); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); grpc_core::ExecCtx::Get()->Flush(); @@ -606,7 +609,7 @@ static void test_jwt_verifier_bad_format(void) { httpcli_post_should_not_be_called); grpc_jwt_verifier_verify(verifier, nullptr, "bad jwt", expected_audience, on_verification_bad_format, - (void*)expected_user_data); + const_cast(expected_user_data)); grpc_jwt_verifier_destroy(verifier); grpc_core::ExecCtx::Get()->Flush(); grpc_httpcli_set_override(nullptr, nullptr); diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index 3d8304bc986..22079f88ae8 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -31,7 +31,7 @@ static void* create_test_tag(void) { static intptr_t i = 0; - return (void*)(++i); + return reinterpret_cast(++i); } /* helper for tests to shutdown correctly and tersely */ diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index e68d21beefc..a466cd22d8c 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -31,7 +31,7 @@ static void* create_test_tag(void) { static intptr_t i = 0; - return (void*)(++i); + return reinterpret_cast(++i); } /* helper for tests to shutdown correctly and tersely */ @@ -146,7 +146,7 @@ static void producer_thread(void* arg) { int i; gpr_log(GPR_INFO, "producer %d started", opt->id); - gpr_event_set(&opt->on_started, (void*)static_cast(1)); + gpr_event_set(&opt->on_started, reinterpret_cast(1)); GPR_ASSERT(gpr_event_wait(opt->phase1, ten_seconds_time())); gpr_log(GPR_INFO, "producer %d phase 1", opt->id); @@ -155,13 +155,13 @@ static void producer_thread(void* arg) { } gpr_log(GPR_INFO, "producer %d phase 1 done", opt->id); - gpr_event_set(&opt->on_phase1_done, (void*)static_cast(1)); + gpr_event_set(&opt->on_phase1_done, reinterpret_cast(1)); GPR_ASSERT(gpr_event_wait(opt->phase2, ten_seconds_time())); gpr_log(GPR_INFO, "producer %d phase 2", opt->id); for (i = 0; i < TEST_THREAD_EVENTS; i++) { grpc_core::ExecCtx exec_ctx; - grpc_cq_end_op(opt->cc, (void*)static_cast(1), GRPC_ERROR_NONE, + grpc_cq_end_op(opt->cc, reinterpret_cast(1), GRPC_ERROR_NONE, free_completion, nullptr, static_cast( gpr_malloc(sizeof(grpc_cq_completion)))); @@ -169,7 +169,7 @@ static void producer_thread(void* arg) { } gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); - gpr_event_set(&opt->on_finished, (void*)static_cast(1)); + gpr_event_set(&opt->on_finished, reinterpret_cast(1)); } static void consumer_thread(void* arg) { @@ -177,13 +177,13 @@ static void consumer_thread(void* arg) { grpc_event ev; gpr_log(GPR_INFO, "consumer %d started", opt->id); - gpr_event_set(&opt->on_started, (void*)static_cast(1)); + gpr_event_set(&opt->on_started, reinterpret_cast(1)); GPR_ASSERT(gpr_event_wait(opt->phase1, ten_seconds_time())); gpr_log(GPR_INFO, "consumer %d phase 1", opt->id); gpr_log(GPR_INFO, "consumer %d phase 1 done", opt->id); - gpr_event_set(&opt->on_phase1_done, (void*)static_cast(1)); + gpr_event_set(&opt->on_phase1_done, reinterpret_cast(1)); GPR_ASSERT(gpr_event_wait(opt->phase2, ten_seconds_time())); gpr_log(GPR_INFO, "consumer %d phase 2", opt->id); @@ -197,7 +197,7 @@ static void consumer_thread(void* arg) { break; case GRPC_QUEUE_SHUTDOWN: gpr_log(GPR_INFO, "consumer %d phase 2 done", opt->id); - gpr_event_set(&opt->on_finished, (void*)static_cast(1)); + gpr_event_set(&opt->on_finished, reinterpret_cast(1)); return; case GRPC_QUEUE_TIMEOUT: gpr_log(GPR_ERROR, "Invalid timeout received"); @@ -244,7 +244,7 @@ static void test_threading(size_t producers, size_t consumers) { /* start phase1: producers will pre-declare all operations they will complete */ gpr_log(GPR_INFO, "start phase 1"); - gpr_event_set(&phase1, (void*)static_cast(1)); + gpr_event_set(&phase1, reinterpret_cast(1)); gpr_log(GPR_INFO, "wait phase 1"); for (i = 0; i < producers + consumers; i++) { @@ -254,7 +254,7 @@ static void test_threading(size_t producers, size_t consumers) { /* start phase2: operations will complete, and consumers will consume them */ gpr_log(GPR_INFO, "start phase 2"); - gpr_event_set(&phase2, (void*)static_cast(1)); + gpr_event_set(&phase2, reinterpret_cast(1)); /* in parallel, we shutdown the completion channel - all events should still be consumed */ diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index b317758b355..f2edbc86a0b 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -66,8 +66,7 @@ // it should never take longer that this to shutdown the server #define SERVER_SHUTDOWN_TIMEOUT 30000 -static void* tag(int n) { return (void*)static_cast(n); } -static int detag(void* p) { return static_cast((uintptr_t)p); } +static void* tag(int n) { return reinterpret_cast(n); } void create_loop_destroy(void* addr) { for (int i = 0; i < NUM_OUTER_LOOPS; ++i) { @@ -113,7 +112,7 @@ void server_thread(void* vargs) { grpc_timeout_milliseconds_to_deadline(SERVER_SHUTDOWN_TIMEOUT); ev = grpc_completion_queue_next(args->cq, deadline, nullptr); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - GPR_ASSERT(detag(ev.tag) == 0xd1e); + GPR_ASSERT(ev.tag == tag(0xd1e)); } static void on_connect(void* vargs, grpc_endpoint* tcp, @@ -148,7 +147,7 @@ void bad_server_thread(void* vargs) { args->addr = absl::StrCat("localhost:", port); grpc_tcp_server_start(s, &args->pollset, on_connect, args); - gpr_event_set(&args->ready, (void*)1); + gpr_event_set(&args->ready, reinterpret_cast(1)); gpr_mu_lock(args->mu); while (args->stop.load(std::memory_order_acquire) == false) { diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 1160268002b..bac7ee008ee 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -36,7 +36,7 @@ class Watcher : public grpc_core::ConnectivityStateWatcherInterface { } }; -static void* tag(intptr_t x) { return (void*)x; } +static void* tag(intptr_t t) { return reinterpret_cast(t); } static grpc_closure transport_op_cb; diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index 1b2cce86819..2a348daeaa5 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -45,8 +45,9 @@ static void channel_idle_start_watch(grpc_channel* channel, GPR_ASSERT(grpc_channel_check_connectivity_state(channel, 0) == GRPC_CHANNEL_IDLE); - grpc_channel_watch_connectivity_state( - channel, GRPC_CHANNEL_IDLE, connect_deadline, cq, (void*)(next_tag++)); + grpc_channel_watch_connectivity_state(channel, GRPC_CHANNEL_IDLE, + connect_deadline, cq, + reinterpret_cast(next_tag++)); gpr_log(GPR_DEBUG, "number of active connect watchers: %d", grpc_channel_num_external_connectivity_watchers(channel)); } @@ -136,7 +137,8 @@ static void run_channel_shutdown_before_timeout_test( GRPC_CHANNEL_IDLE); grpc_channel_watch_connectivity_state(channel, GRPC_CHANNEL_IDLE, - connect_deadline, cq, (void*)1); + connect_deadline, cq, + reinterpret_cast(1)); grpc_channel_destroy(channel); grpc_event ev = grpc_completion_queue_next( diff --git a/test/core/transport/chttp2/stream_map_test.cc b/test/core/transport/chttp2/stream_map_test.cc index 3452c86cdc9..fb03732c91b 100644 --- a/test/core/transport/chttp2/stream_map_test.cc +++ b/test/core/transport/chttp2/stream_map_test.cc @@ -55,13 +55,13 @@ static void test_basic_add_find(uint32_t n) { grpc_chttp2_stream_map_init(&map, 8); GPR_ASSERT(0 == grpc_chttp2_stream_map_size(&map)); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); + grpc_chttp2_stream_map_add(&map, i, reinterpret_cast(i)); } GPR_ASSERT(n == grpc_chttp2_stream_map_size(&map)); GPR_ASSERT(nullptr == grpc_chttp2_stream_map_find(&map, 0)); GPR_ASSERT(nullptr == grpc_chttp2_stream_map_find(&map, n + 1)); for (i = 1; i <= n; i++) { - got = (uintptr_t)grpc_chttp2_stream_map_find(&map, i); + got = reinterpret_cast(grpc_chttp2_stream_map_find(&map, i)); GPR_ASSERT(i == got); } grpc_chttp2_stream_map_destroy(&map); @@ -84,7 +84,7 @@ static void check_delete_evens(grpc_chttp2_stream_map* map, uint32_t n) { GPR_ASSERT(nullptr == grpc_chttp2_stream_map_find(map, n + 1)); for (i = 1; i <= n; i++) { if (i & 1) { - got = (uintptr_t)grpc_chttp2_stream_map_find(map, i); + got = reinterpret_cast(grpc_chttp2_stream_map_find(map, i)); GPR_ASSERT(i == got); } else { GPR_ASSERT(nullptr == grpc_chttp2_stream_map_find(map, i)); @@ -110,7 +110,7 @@ static void test_delete_evens_sweep(uint32_t n) { grpc_chttp2_stream_map_init(&map, 8); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); + grpc_chttp2_stream_map_add(&map, i, reinterpret_cast(i)); } for (i = 1; i <= n; i++) { if ((i & 1) == 0) { @@ -132,7 +132,7 @@ static void test_delete_evens_incremental(uint32_t n) { grpc_chttp2_stream_map_init(&map, 8); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); + grpc_chttp2_stream_map_add(&map, i, reinterpret_cast(i)); if ((i & 1) == 0) { grpc_chttp2_stream_map_delete(&map, i); } @@ -154,7 +154,7 @@ static void test_periodic_compaction(uint32_t n) { grpc_chttp2_stream_map_init(&map, 16); GPR_ASSERT(map.capacity == 16); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); + grpc_chttp2_stream_map_add(&map, i, reinterpret_cast(i)); if (i > 8) { del = i - 8; GPR_ASSERT((void*)(uintptr_t)del == diff --git a/test/core/transport/chttp2/too_many_pings_test.cc b/test/core/transport/chttp2/too_many_pings_test.cc index 38cb77ce275..08d635a1d69 100644 --- a/test/core/transport/chttp2/too_many_pings_test.cc +++ b/test/core/transport/chttp2/too_many_pings_test.cc @@ -59,7 +59,7 @@ namespace { -void* tag(int i) { return (void*)static_cast(i); } +void* tag(intptr_t t) { return reinterpret_cast(t); } // Perform a simple RPC where the server cancels the request with // grpc_call_cancel_with_status @@ -249,10 +249,10 @@ grpc_status_code PerformWaitingCall(grpc_channel* channel, grpc_server* server, // Shuts down and destroys the server. void ServerShutdownAndDestroy(grpc_server* server, grpc_completion_queue* cq) { // Shutdown and destroy server - grpc_server_shutdown_and_notify(server, cq, (void*)(1000)); + grpc_server_shutdown_and_notify(server, cq, reinterpret_cast(1000)); while (grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr) - .tag != (void*)(1000)) { + .tag != reinterpret_cast(1000)) { } grpc_server_destroy(server); } @@ -273,11 +273,11 @@ void VerifyChannelDisconnected(grpc_channel* channel, grpc_completion_queue* cq) { // Verify channel gets disconnected. Use a ping to make sure that clients // tries sending/receiving bytes if the channel is connected. - grpc_channel_ping(channel, cq, (void*)(2000), nullptr); + grpc_channel_ping(channel, cq, reinterpret_cast(2000), nullptr); grpc_event ev = grpc_completion_queue_next( cq, grpc_timeout_seconds_to_deadline(5), nullptr); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - GPR_ASSERT(ev.tag == (void*)(2000)); + GPR_ASSERT(ev.tag == reinterpret_cast(2000)); GPR_ASSERT(ev.success == 0); GPR_ASSERT(grpc_channel_check_connectivity_state(channel, 0) != GRPC_CHANNEL_READY); diff --git a/test/core/tsi/alts/crypt/gsec_test_util.cc b/test/core/tsi/alts/crypt/gsec_test_util.cc index c682fb8e4dc..89c887f9a27 100644 --- a/test/core/tsi/alts/crypt/gsec_test_util.cc +++ b/test/core/tsi/alts/crypt/gsec_test_util.cc @@ -42,7 +42,7 @@ void gsec_test_random_array(uint8_t** bytes, size_t length) { uint32_t gsec_test_bias_random_uint32(uint32_t max_length) { uint32_t value; - gsec_test_random_bytes((uint8_t*)(&value), sizeof(value)); + gsec_test_random_bytes(reinterpret_cast(&value), sizeof(value)); return value % max_length; } diff --git a/test/core/tsi/alts/frame_protector/frame_handler_test.cc b/test/core/tsi/alts/frame_protector/frame_handler_test.cc index 6780eb7127e..8bfa5306cfd 100644 --- a/test/core/tsi/alts/frame_protector/frame_handler_test.cc +++ b/test/core/tsi/alts/frame_protector/frame_handler_test.cc @@ -107,7 +107,7 @@ static void frame_n_deframe(frame_handler* handler, unsigned char* payload, static void frame_handler_test_frame_deframe() { unsigned char payload[] = "hello world"; - size_t payload_length = strlen((char*)payload) + 1; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; frame_handler* handler = create_frame_handler(); frame_n_deframe(handler, payload, payload_length, frame_length(payload_length), frame_length(payload_length)); diff --git a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc index 09e15573fb0..c96a6141f43 100644 --- a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc +++ b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc @@ -368,8 +368,9 @@ class FakeTcpServer { memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_port = htons(port_); - ((char*)&addr.sin6_addr)[15] = 1; - if (bind(accept_socket_, (const sockaddr*)&addr, sizeof(addr)) != 0) { + (reinterpret_cast(&addr.sin6_addr))[15] = 1; + if (bind(accept_socket_, reinterpret_cast(&addr), + sizeof(addr)) != 0) { gpr_log(GPR_ERROR, "Failed to bind socket to [::1]:%d : %d", port_, errno); abort(); @@ -387,7 +388,7 @@ class FakeTcpServer { gpr_log(GPR_DEBUG, "FakeTcpServer stop and " "join server thread"); - gpr_event_set(&stop_ev_, (void*)1); + gpr_event_set(&stop_ev_, reinterpret_cast(1)); run_server_loop_thd_->join(); gpr_log(GPR_DEBUG, "FakeTcpServer join server " diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 61053040501..a450001635b 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -366,8 +366,8 @@ static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) { } static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp) { - gpr_free((void*)kp.private_key); - gpr_free((void*)kp.cert_chain); + gpr_free(const_cast(kp.private_key)); + gpr_free(const_cast(kp.cert_chain)); } static void ssl_test_destruct(tsi_test_fixture* fixture) { diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index 26349dbfcaa..2975cee1a80 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -197,7 +197,8 @@ void tsi_test_frame_protector_send_message_to_peer( uint8_t* message = is_client ? config->client_message : config->server_message; GPR_ASSERT(message != nullptr); - const unsigned char* message_bytes = (const unsigned char*)message; + const unsigned char* message_bytes = + reinterpret_cast(message); tsi_result result = TSI_OK; /* Do protect and send protected data to peer. */ while (message_size > 0 && result == TSI_OK) { @@ -370,10 +371,10 @@ static void do_handshaker_next(handshaker_args* args) { args->transferred_data = true; } /* Peform handshaker next. */ - result = tsi_handshaker_next(handshaker, args->handshake_buffer, buf_size, - (const unsigned char**)&bytes_to_send, - &bytes_to_send_size, &handshaker_result, - &on_handshake_next_done_wrapper, args); + result = tsi_handshaker_next( + handshaker, args->handshake_buffer, buf_size, + const_cast(&bytes_to_send), &bytes_to_send_size, + &handshaker_result, &on_handshake_next_done_wrapper, args); if (result != TSI_ASYNC) { args->error = on_handshake_next_done( result, args, bytes_to_send, bytes_to_send_size, handshaker_result); diff --git a/test/core/util/cmdline_test.cc b/test/core/util/cmdline_test.cc index c15e5e36df9..c1eb5e39a0f 100644 --- a/test/core/util/cmdline_test.cc +++ b/test/core/util/cmdline_test.cc @@ -30,7 +30,7 @@ static void test_simple_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo"), + char* args[] = {const_cast(__FILE__), const_cast("-foo"), const_cast("3")}; LOG_TEST(); @@ -46,7 +46,7 @@ static void test_simple_int(void) { static void test_eq_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo=3")}; + char* args[] = {const_cast(__FILE__), const_cast("-foo=3")}; LOG_TEST(); @@ -61,7 +61,7 @@ static void test_eq_int(void) { static void test_2dash_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo"), + char* args[] = {const_cast(__FILE__), const_cast("--foo"), const_cast("3")}; LOG_TEST(); @@ -77,7 +77,7 @@ static void test_2dash_int(void) { static void test_2dash_eq_int(void) { int x = 1; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=3")}; + char* args[] = {const_cast(__FILE__), const_cast("--foo=3")}; LOG_TEST(); @@ -92,7 +92,7 @@ static void test_2dash_eq_int(void) { static void test_simple_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo"), + char* args[] = {const_cast(__FILE__), const_cast("-foo"), const_cast("3")}; LOG_TEST(); @@ -108,7 +108,7 @@ static void test_simple_string(void) { static void test_eq_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("-foo=3")}; + char* args[] = {const_cast(__FILE__), const_cast("-foo=3")}; LOG_TEST(); @@ -123,7 +123,7 @@ static void test_eq_string(void) { static void test_2dash_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo"), + char* args[] = {const_cast(__FILE__), const_cast("--foo"), const_cast("3")}; LOG_TEST(); @@ -139,7 +139,7 @@ static void test_2dash_string(void) { static void test_2dash_eq_string(void) { const char* x = nullptr; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=3")}; + char* args[] = {const_cast(__FILE__), const_cast("--foo=3")}; LOG_TEST(); @@ -154,7 +154,7 @@ static void test_2dash_eq_string(void) { static void test_flag_on(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo")}; + char* args[] = {const_cast(__FILE__), const_cast("--foo")}; LOG_TEST(); @@ -169,7 +169,7 @@ static void test_flag_on(void) { static void test_flag_no(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--no-foo")}; + char* args[] = {const_cast(__FILE__), const_cast("--no-foo")}; LOG_TEST(); @@ -184,7 +184,7 @@ static void test_flag_no(void) { static void test_flag_val_1(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=1")}; + char* args[] = {const_cast(__FILE__), const_cast("--foo=1")}; LOG_TEST(); @@ -199,7 +199,7 @@ static void test_flag_val_1(void) { static void test_flag_val_0(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=0")}; + char* args[] = {const_cast(__FILE__), const_cast("--foo=0")}; LOG_TEST(); @@ -214,7 +214,7 @@ static void test_flag_val_0(void) { static void test_flag_val_true(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=true")}; + char* args[] = {const_cast(__FILE__), const_cast("--foo=true")}; LOG_TEST(); @@ -229,7 +229,8 @@ static void test_flag_val_true(void) { static void test_flag_val_false(void) { int x = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--foo=false")}; + char* args[] = {const_cast(__FILE__), + const_cast("--foo=false")}; LOG_TEST(); @@ -247,7 +248,7 @@ static void test_many(void) { int flag = 2; gpr_cmdline* cl; - char* args[] = {(char*)__FILE__, const_cast("--str"), + char* args[] = {const_cast(__FILE__), const_cast("--str"), const_cast("hello"), const_cast("-x=4"), const_cast("-no-flag")}; @@ -275,7 +276,7 @@ static void extra_arg_cb(void* user_data, const char* arg) { static void test_extra(void) { gpr_cmdline* cl; int count = 0; - char* args[] = {(char*)__FILE__, const_cast("a"), + char* args[] = {const_cast(__FILE__), const_cast("a"), const_cast("b"), const_cast("c")}; LOG_TEST(); @@ -291,7 +292,7 @@ static void test_extra(void) { static void test_extra_dashdash(void) { gpr_cmdline* cl; int count = 0; - char* args[] = {(char*)__FILE__, const_cast("--"), + char* args[] = {const_cast(__FILE__), const_cast("--"), const_cast("a"), const_cast("b"), const_cast("c")}; @@ -341,7 +342,7 @@ static void test_help(void) { int x = 0; int flag = 2; - char* help[] = {(char*)__FILE__, const_cast("-h")}; + char* help[] = {const_cast(__FILE__), const_cast("-h")}; LOG_TEST(); @@ -365,7 +366,8 @@ static void test_badargs1(void) { int x = 0; int flag = 2; - char* bad_arg_name[] = {(char*)__FILE__, const_cast("--y")}; + char* bad_arg_name[] = {const_cast(__FILE__), + const_cast("--y")}; LOG_TEST(); @@ -390,7 +392,8 @@ static void test_badargs2(void) { int x = 0; int flag = 2; - char* bad_int_value[] = {(char*)__FILE__, const_cast("--x"), + char* bad_int_value[] = {const_cast(__FILE__), + const_cast("--x"), const_cast("henry")}; LOG_TEST(); @@ -416,7 +419,8 @@ static void test_badargs3(void) { int x = 0; int flag = 2; - char* bad_bool_value[] = {(char*)__FILE__, const_cast("--flag=henry")}; + char* bad_bool_value[] = {const_cast(__FILE__), + const_cast("--flag=henry")}; LOG_TEST(); @@ -441,7 +445,8 @@ static void test_badargs4(void) { int x = 0; int flag = 2; - char* bad_bool_value[] = {(char*)__FILE__, const_cast("--no-str")}; + char* bad_bool_value[] = {const_cast(__FILE__), + const_cast("--no-str")}; LOG_TEST(); diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc index 7e495c311cc..b62613b8d34 100644 --- a/test/core/util/mock_endpoint.cc +++ b/test/core/util/mock_endpoint.cc @@ -132,7 +132,8 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota) { mock_endpoint* m = static_cast(gpr_malloc(sizeof(*m))); m->base.vtable = &vtable; - std::string name = absl::StrFormat("mock_endpoint_%" PRIxPTR, (intptr_t)m); + std::string name = + absl::StrFormat("mock_endpoint_%" PRIxPTR, reinterpret_cast(m)); m->resource_user = grpc_resource_user_create(resource_quota, name.c_str()); grpc_slice_buffer_init(&m->read_buffer); gpr_mu_init(&m->mu); diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc index e8a8fc5e7d8..f856481bc65 100644 --- a/test/core/util/passthru_endpoint.cc +++ b/test/core/util/passthru_endpoint.cc @@ -197,8 +197,8 @@ static void half_init(half* m, passthru_endpoint* parent, m->parent = parent; grpc_slice_buffer_init(&m->read_buffer); m->on_read = nullptr; - std::string name = absl::StrFormat("passthru_endpoint_%s_%" PRIxPTR, - half_name, (intptr_t)parent); + std::string name = + absl::StrFormat("passthru_endpoint_%s_%p", half_name, parent); m->resource_user = grpc_resource_user_create(resource_quota, name.c_str()); } diff --git a/test/core/util/stack_tracer.cc b/test/core/util/stack_tracer.cc index 228e5bbe726..f611ff1e2f8 100644 --- a/test/core/util/stack_tracer.cc +++ b/test/core/util/stack_tracer.cc @@ -97,8 +97,7 @@ std::string GetCurrentStackTrace() { void* stack[kNumStackFrames]; int frame_sizes[kNumStackFrames]; int depth = absl::GetStackFrames(stack, frame_sizes, kNumStackFrames, 1); - DumpStackTrace(stack, frame_sizes, depth, true, DebugWriteToString, - (void*)&result); + DumpStackTrace(stack, frame_sizes, depth, true, DebugWriteToString, &result); return result; } diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index ead9fb138f7..53050a82953 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -48,7 +48,7 @@ class TestSocketMutator : public grpc_socket_mutator { // bool test_mutator_mutate_fd(int fd, grpc_socket_mutator* mutator) { - TestSocketMutator* tsm = (TestSocketMutator*)mutator; + TestSocketMutator* tsm = reinterpret_cast(mutator); return tsm->MutateFd(fd); } @@ -57,7 +57,7 @@ int test_mutator_compare(grpc_socket_mutator* a, grpc_socket_mutator* b) { } void test_mutator_destroy(grpc_socket_mutator* mutator) { - TestSocketMutator* tsm = (TestSocketMutator*)mutator; + TestSocketMutator* tsm = reinterpret_cast(mutator); delete tsm; } diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 4bb5c1cb730..f914fdd7a53 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -60,7 +60,7 @@ namespace testing { namespace { -void* tag(int i) { return (void*)static_cast(i); } +void* tag(int t) { return reinterpret_cast(t); } int detag(void* p) { return static_cast(reinterpret_cast(p)); } class Verifier { diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index e89971e018b..08e75eff61f 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -1357,7 +1357,7 @@ TEST_P(End2endTest, RpcMaxMessageSize) { void ReaderThreadFunc(ClientReaderWriter* stream, gpr_event* ev) { EchoResponse resp; - gpr_event_set(ev, (void*)1); + gpr_event_set(ev, reinterpret_cast(1)); while (stream->Read(&resp)) { gpr_log(GPR_INFO, "Read message"); } diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index 6287677f5dc..0d8f1d787bc 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -51,7 +51,7 @@ namespace grpc { namespace testing { namespace { -void* tag(int i) { return (void*)static_cast(i); } +void* tag(int i) { return reinterpret_cast(i); } void verify_ok(CompletionQueue* cq, int i, bool expect_ok) { bool ok; diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 32aacc416bc..cff1cf8b829 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -48,7 +48,7 @@ namespace grpc { namespace testing { namespace { -void* tag(int i) { return (void*)static_cast(i); } +void* tag(int i) { return reinterpret_cast(i); } void verify_ok(CompletionQueue* cq, int i, bool expect_ok) { bool ok; diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 8646b5a54b1..76e1f830594 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -49,7 +49,7 @@ using ::grpc::experimental::GenericCallbackServerContext; using ::grpc::experimental::ServerGenericBidiReactor; #endif -void* tag(int i) { return (void*)static_cast(i); } +void* tag(int i) { return reinterpret_cast(i); } bool VerifyReturnSuccess(CompletionQueue* cq, int i) { void* got_tag; diff --git a/test/cpp/end2end/interceptors_util.h b/test/cpp/end2end/interceptors_util.h index 01009cdc93f..0b386b3cd27 100644 --- a/test/cpp/end2end/interceptors_util.h +++ b/test/cpp/end2end/interceptors_util.h @@ -191,7 +191,7 @@ bool CheckMetadata(const std::multimap& map, std::vector> CreateDummyClientInterceptors(); -inline void* tag(int i) { return (void*)static_cast(i); } +inline void* tag(int i) { return reinterpret_cast(i); } inline int detag(void* p) { return static_cast(reinterpret_cast(p)); } diff --git a/test/cpp/end2end/raw_end2end_test.cc b/test/cpp/end2end/raw_end2end_test.cc index 31edffdc948..d6300ecad66 100644 --- a/test/cpp/end2end/raw_end2end_test.cc +++ b/test/cpp/end2end/raw_end2end_test.cc @@ -50,7 +50,7 @@ namespace testing { namespace { -void* tag(int i) { return (void*)static_cast(i); } +void* tag(int i) { return reinterpret_cast(i); } int detag(void* p) { return static_cast(reinterpret_cast(p)); } class Verifier { diff --git a/test/cpp/end2end/shutdown_test.cc b/test/cpp/end2end/shutdown_test.cc index 37dfcd44a71..ed86f8a9135 100644 --- a/test/cpp/end2end/shutdown_test.cc +++ b/test/cpp/end2end/shutdown_test.cc @@ -48,7 +48,7 @@ class TestServiceImpl : public ::grpc::testing::EchoTestService::Service { Status Echo(ServerContext* context, const EchoRequest* /*request*/, EchoResponse* /*response*/) override { - gpr_event_set(ev_, (void*)1); + gpr_event_set(ev_, reinterpret_cast(1)); while (!context->IsCancelled()) { } return Status::OK; diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index eeb93ce0c80..0e7da2e01ed 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -245,7 +245,7 @@ class CommonStressTestAsyncServer : public BaseClass { service_.RequestEcho(contexts_[i].srv_ctx.get(), &contexts_[i].recv_request, contexts_[i].response_writer.get(), cq_.get(), - cq_.get(), (void*)static_cast(i)); + cq_.get(), reinterpret_cast(i)); } } struct Context { @@ -369,8 +369,7 @@ class AsyncClientEnd2endTest : public ::testing::Test { request.set_message("Hello: " + std::to_string(i)); call->response_reader = common_.GetStub()->AsyncEcho(&call->context, request, &cq_); - call->response_reader->Finish(&call->response, &call->status, - (void*)call); + call->response_reader->Finish(&call->response, &call->status, call); grpc::internal::MutexLock l(&mu_); rpcs_outstanding_++; diff --git a/test/cpp/end2end/time_change_test.cc b/test/cpp/end2end/time_change_test.cc index 9f1bc15d8b2..1d4efcf3368 100644 --- a/test/cpp/end2end/time_change_test.cc +++ b/test/cpp/end2end/time_change_test.cc @@ -97,7 +97,7 @@ namespace { // gpr_now() is called with invalid clock_type TEST(TimespecTest, GprNowInvalidClockType) { // initialize to some junk value - gpr_clock_type invalid_clock_type = (gpr_clock_type)32641; + gpr_clock_type invalid_clock_type = static_cast(32641); EXPECT_DEATH(gpr_now(invalid_clock_type), ".*"); } diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index e6b718b84a1..51f66d482a2 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -149,7 +149,7 @@ class TestServiceImpl : public TestService::Service { const SimpleRequest* /*request*/, SimpleResponse* response) override { gpr_timespec ts = gpr_now(GPR_CLOCK_PRECISE); - std::string timestamp = std::to_string((long long unsigned)ts.tv_nsec); + std::string timestamp = std::to_string(ts.tv_nsec); response->mutable_payload()->set_body(timestamp.c_str(), timestamp.size()); context->AddInitialMetadata("cache-control", "max-age=60, public"); return Status::OK; diff --git a/test/cpp/interop/xds_interop_client.cc b/test/cpp/interop/xds_interop_client.cc index 78c71b0a185..1e6282f3220 100644 --- a/test/cpp/interop/xds_interop_client.cc +++ b/test/cpp/interop/xds_interop_client.cc @@ -246,7 +246,7 @@ class TestClient { &call->context, SimpleRequest::default_instance(), &cq_); call->simple_response_reader->StartCall(); call->simple_response_reader->Finish(&call->simple_response, &call->status, - (void*)call); + call); } void AsyncEmptyCall( @@ -278,7 +278,7 @@ class TestClient { &call->context, Empty::default_instance(), &cq_); call->empty_response_reader->StartCall(); call->empty_response_reader->Finish(&call->empty_response, &call->status, - (void*)call); + call); } void AsyncCompleteRpc() { diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index 6a783d30aca..220504b3de8 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -244,7 +244,7 @@ class Stream { grpc_transport_destroy_stream(stream->f_->transport(), static_cast(stream->stream_), stream->destroy_closure_); - gpr_event_set(&stream->done_, (void*)(1)); + gpr_event_set(&stream->done_, reinterpret_cast(1)); } Fixture* f_; @@ -396,7 +396,7 @@ static void BM_TransportEmptyOp(benchmark::State& state) { std::unique_ptr stream_cancel_closure = MakeTestClosure([&](grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); - gpr_event_set(stream_cancel_done, (void*)(1)); + gpr_event_set(stream_cancel_done, reinterpret_cast(1)); }); op.on_complete = stream_cancel_closure.get(); s->Op(&op); @@ -444,7 +444,7 @@ static void BM_TransportStreamSend(benchmark::State& state) { std::unique_ptr c = MakeTestClosure([&](grpc_error* /*error*/) { if (!state.KeepRunning()) { - gpr_event_set(bm_done, (void*)(1)); + gpr_event_set(bm_done, reinterpret_cast(1)); return; } grpc_slice_buffer send_buffer; @@ -480,7 +480,7 @@ static void BM_TransportStreamSend(benchmark::State& state) { std::unique_ptr stream_cancel_closure = MakeTestClosure([&](grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); - gpr_event_set(stream_cancel_done, (void*)(1)); + gpr_event_set(stream_cancel_done, reinterpret_cast(1)); }); op.on_complete = stream_cancel_closure.get(); s->Op(&op); @@ -666,7 +666,7 @@ static void BM_TransportStreamRecv(benchmark::State& state) { std::unique_ptr stream_cancel_closure = MakeTestClosure([&](grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); - gpr_event_set(stream_cancel_done, (void*)(1)); + gpr_event_set(stream_cancel_done, reinterpret_cast(1)); }); op.on_complete = stream_cancel_closure.get(); s->Op(&op); diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index b89eafb9c2c..f0082491be3 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -78,7 +78,7 @@ static grpc_error* pollset_work(grpc_pollset* ps, gpr_mu_unlock(&ps->mu); - void* tag = (void*)static_cast(10); // Some random number + void* tag = reinterpret_cast(10); // Some random number GPR_ASSERT(grpc_cq_begin_op(g_cq, tag)); grpc_cq_end_op( g_cq, tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 9fa42b5aa07..de031286c22 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -112,21 +112,24 @@ class TrickledCHTTP2 : public EndpointPairFixture { void AddToLabel(std::ostream& out, benchmark::State& state) override { out << " writes/iter:" - << ((double)stats_->num_writes / (double)state.iterations()) + << (static_cast(stats_->num_writes) / + static_cast(state.iterations())) << " cli_transport_stalls/iter:" - << ((double) - client_stats_.streams_stalled_due_to_transport_flow_control / - (double)state.iterations()) + << (static_cast( + client_stats_.streams_stalled_due_to_transport_flow_control) / + static_cast(state.iterations())) << " cli_stream_stalls/iter:" - << ((double)client_stats_.streams_stalled_due_to_stream_flow_control / - (double)state.iterations()) + << (static_cast( + client_stats_.streams_stalled_due_to_stream_flow_control) / + static_cast(state.iterations())) << " svr_transport_stalls/iter:" - << ((double) - server_stats_.streams_stalled_due_to_transport_flow_control / - (double)state.iterations()) + << (static_cast( + server_stats_.streams_stalled_due_to_transport_flow_control) / + static_cast(state.iterations())) << " svr_stream_stalls/iter:" - << ((double)server_stats_.streams_stalled_due_to_stream_flow_control / - (double)state.iterations()); + << (static_cast( + server_stats_.streams_stalled_due_to_stream_flow_control) / + static_cast(state.iterations())); } void Log(int64_t iteration) GPR_ATTRIBUTE_NO_TSAN { @@ -194,10 +197,10 @@ class TrickledCHTTP2 : public EndpointPairFixture { grpc_trickle_endpoint_trickle(endpoint_pair_.server); if (update_stats) { - UpdateStats((grpc_chttp2_transport*)client_transport_, &client_stats_, - client_backlog); - UpdateStats((grpc_chttp2_transport*)server_transport_, &server_stats_, - server_backlog); + UpdateStats(reinterpret_cast(client_transport_), + &client_stats_, client_backlog); + UpdateStats(reinterpret_cast(server_transport_), + &server_stats_, server_backlog); } } @@ -281,7 +284,7 @@ static void BM_PumpStreamServerToClient_Trickle(benchmark::State& state) { while (need_tags) { TrickleCQNext(fixture.get(), &t, &ok, -1); GPR_ASSERT(ok); - int i = (int)(intptr_t)t; + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -327,7 +330,7 @@ static void BM_PumpStreamServerToClient_Trickle(benchmark::State& state) { request_rw->Read(&recv_response, tag(0)); continue; } - int i = (int)(intptr_t)t; + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -404,7 +407,7 @@ static void BM_PumpUnbalancedUnary_Trickle(benchmark::State& state) { TrickleCQNext(fixture.get(), &t, &ok, in_warmup ? -1 : state.iterations()); GPR_ASSERT(ok); - int tagnum = (int)reinterpret_cast(t); + int tagnum = static_cast(reinterpret_cast(t)); GPR_ASSERT(i & (1 << tagnum)); i -= 1 << tagnum; } diff --git a/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h b/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h index db9be84fefb..9ca213cee0d 100644 --- a/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h +++ b/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h @@ -83,7 +83,7 @@ static void BM_StreamingPingPong(benchmark::State& state) { while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -99,7 +99,7 @@ static void BM_StreamingPingPong(benchmark::State& state) { while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); // If server recv is complete, start the server send operation if (i == 1) { @@ -122,7 +122,7 @@ static void BM_StreamingPingPong(benchmark::State& state) { need_tags = (1 << 0) | (1 << 1) | (1 << 2); while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -175,7 +175,7 @@ static void BM_StreamingPingPongMsgs(benchmark::State& state) { while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -190,7 +190,7 @@ static void BM_StreamingPingPongMsgs(benchmark::State& state) { while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); // If server recv is complete, start the server send operation if (i == 1) { @@ -210,7 +210,7 @@ static void BM_StreamingPingPongMsgs(benchmark::State& state) { need_tags = (1 << 0) | (1 << 1) | (1 << 2); while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -297,10 +297,10 @@ static void BM_StreamingPingPongWithCoalescingApi(benchmark::State& state) { // established). It is necessary when client init metadata is // coalesced GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - while (static_cast((intptr_t)t) != 0) { + while (static_cast(reinterpret_cast(t)) != 0) { // In some cases tag:2 comes before tag:0 (write tag comes out // first), this while loop is to make sure get tag:0. - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(await_tags & (1 << i)); await_tags &= ~(1 << i); GPR_ASSERT(fixture->cq()->Next(&t, &ok)); @@ -317,7 +317,7 @@ static void BM_StreamingPingPongWithCoalescingApi(benchmark::State& state) { while (await_tags != 0) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); // If server recv is complete, start the server send operation if (i == 3) { @@ -367,8 +367,8 @@ static void BM_StreamingPingPongWithCoalescingApi(benchmark::State& state) { // wait for server call data structure(call_hook, etc.) to be // initialized, since initial metadata is corked. GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - while (static_cast((intptr_t)t) != 0) { - int i = static_cast((intptr_t)t); + while (static_cast(reinterpret_cast(t)) != 0) { + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(expect_tags & (1 << i)); expect_tags &= ~(1 << i); GPR_ASSERT(fixture->cq()->Next(&t, &ok)); @@ -385,7 +385,7 @@ static void BM_StreamingPingPongWithCoalescingApi(benchmark::State& state) { while (expect_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(expect_tags & (1 << i)); expect_tags &= ~(1 << i); } diff --git a/test/cpp/microbenchmarks/fullstack_streaming_pump.h b/test/cpp/microbenchmarks/fullstack_streaming_pump.h index cf72710ccb9..d05258bb919 100644 --- a/test/cpp/microbenchmarks/fullstack_streaming_pump.h +++ b/test/cpp/microbenchmarks/fullstack_streaming_pump.h @@ -62,7 +62,7 @@ static void BM_PumpStreamClientToServer(benchmark::State& state) { while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -85,7 +85,7 @@ static void BM_PumpStreamClientToServer(benchmark::State& state) { need_tags = (1 << 0) | (1 << 1); while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -95,7 +95,7 @@ static void BM_PumpStreamClientToServer(benchmark::State& state) { need_tags = (1 << 0) | (1 << 1); while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -131,7 +131,7 @@ static void BM_PumpStreamServerToClient(benchmark::State& state) { while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } @@ -154,7 +154,7 @@ static void BM_PumpStreamServerToClient(benchmark::State& state) { need_tags = (1 << 0) | (1 << 1); while (need_tags) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - int i = static_cast((intptr_t)t); + int i = static_cast(reinterpret_cast(t)); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } diff --git a/test/cpp/naming/address_sorting_test.cc b/test/cpp/naming/address_sorting_test.cc index 2f890149273..edcee212b10 100644 --- a/test/cpp/naming/address_sorting_test.cc +++ b/test/cpp/naming/address_sorting_test.cc @@ -787,7 +787,7 @@ TEST_F(AddressSortingTest, TestSorterKnowsIpv6LoopbackIsAvailable) { sockaddr_in6 ipv6_loopback; memset(&ipv6_loopback, 0, sizeof(ipv6_loopback)); ipv6_loopback.sin6_family = AF_INET6; - ((char*)&ipv6_loopback.sin6_addr)[15] = 1; + (reinterpret_cast(&ipv6_loopback.sin6_addr))[15] = 1; ipv6_loopback.sin6_port = htons(443); // Set up the source and destination parameters of // address_sorting_get_source_addr @@ -803,7 +803,7 @@ TEST_F(AddressSortingTest, TestSorterKnowsIpv6LoopbackIsAvailable) { // Now also check that the source address was filled in correctly. EXPECT_GT(source_for_sort_input_dest.len, 0u); sockaddr_in6* source_addr_output = - (sockaddr_in6*)source_for_sort_input_dest.addr; + reinterpret_cast(source_for_sort_input_dest.addr); EXPECT_EQ(source_addr_output->sin6_family, AF_INET6); char* buf = static_cast(gpr_zalloc(100)); EXPECT_NE(inet_ntop(AF_INET6, &source_addr_output->sin6_addr, buf, 100), diff --git a/test/cpp/naming/cancel_ares_query_test.cc b/test/cpp/naming/cancel_ares_query_test.cc index 0163c2eff26..371e3e5eb4e 100644 --- a/test/cpp/naming/cancel_ares_query_test.cc +++ b/test/cpp/naming/cancel_ares_query_test.cc @@ -57,7 +57,7 @@ namespace { -void* Tag(intptr_t t) { return (void*)t; } +void* Tag(intptr_t t) { return reinterpret_cast(t); } gpr_timespec FiveSecondsFromNow(void) { return grpc_timeout_seconds_to_deadline(5); @@ -87,7 +87,7 @@ struct ArgsStruct { }; void ArgsInit(ArgsStruct* args) { - args->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + args->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); @@ -374,7 +374,7 @@ void TestCancelDuringActiveQuery( // Teardown grpc_channel_args_destroy(client_args); grpc_slice_unref(details); - gpr_free((void*)error_string); + gpr_free(const_cast(error_string)); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/cpp/naming/dns_test_util.cc b/test/cpp/naming/dns_test_util.cc index e44ccc20c6a..ca97bf3e7f6 100644 --- a/test/cpp/naming/dns_test_util.cc +++ b/test/cpp/naming/dns_test_util.cc @@ -51,8 +51,9 @@ FakeNonResponsiveDNSServer::FakeNonResponsiveDNSServer(int port) { memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_port = htons(port); - ((char*)&addr.sin6_addr)[15] = 1; - if (bind(udp_socket_, (const sockaddr*)&addr, sizeof(addr)) != 0) { + (reinterpret_cast(&addr.sin6_addr))[15] = 1; + if (bind(udp_socket_, reinterpret_cast(&addr), + sizeof(addr)) != 0) { gpr_log(GPR_DEBUG, "Failed to bind UDP ipv6 socket to [::1]:%d", port); abort(); } @@ -73,7 +74,8 @@ FakeNonResponsiveDNSServer::FakeNonResponsiveDNSServer(int port) { abort(); } #endif - if (bind(tcp_socket_, (const sockaddr*)&addr, sizeof(addr)) != 0) { + if (bind(tcp_socket_, reinterpret_cast(&addr), + sizeof(addr)) != 0) { gpr_log(GPR_DEBUG, "Failed to bind TCP ipv6 socket to [::1]:%d", port); abort(); } diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 2296a9385be..b5565784d24 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -202,7 +202,7 @@ struct ArgsStruct { void ArgsInit(ArgsStruct* args) { gpr_event_init(&args->ev); - args->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + args->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); @@ -257,7 +257,7 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) { NSecondDeadline(1)))); gpr_mu_unlock(args->mu); } - gpr_event_set(&args->ev, (void*)1); + gpr_event_set(&args->ev, reinterpret_cast(1)); } void CheckServiceConfigResultLocked(const char* service_config_json, @@ -361,7 +361,7 @@ void OpenAndCloseSocketsStressLoop(int dummy_port, gpr_event* done_ev) { memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_port = htons(dummy_port); - ((char*)&addr.sin6_addr)[15] = 1; + (reinterpret_cast(&addr.sin6_addr))[15] = 1; for (;;) { if (gpr_event_get(done_ev)) { return; @@ -541,7 +541,7 @@ void InjectBrokenNameServerList(ares_channel channel) { absl::GetFlag(FLAGS_local_dns_server_address).c_str()); // Put the non-responsive DNS server at the front of c-ares's nameserver list. dns_server_addrs[0].family = AF_INET6; - ((char*)&dns_server_addrs[0].addr.addr6)[15] = 0x1; + (reinterpret_cast(&dns_server_addrs[0].addr.addr6))[15] = 0x1; dns_server_addrs[0].tcp_port = g_fake_non_responsive_dns_server_port; dns_server_addrs[0].udp_port = g_fake_non_responsive_dns_server_port; dns_server_addrs[0].next = &dns_server_addrs[1]; @@ -550,8 +550,8 @@ void InjectBrokenNameServerList(ares_channel channel) { // and will skip over to this healthy DNS server, without causing any DNS // resolution errors. dns_server_addrs[1].family = AF_INET; - ((char*)&dns_server_addrs[1].addr.addr4)[0] = 0x7f; - ((char*)&dns_server_addrs[1].addr.addr4)[3] = 0x1; + (reinterpret_cast(&dns_server_addrs[1].addr.addr4))[0] = 0x7f; + (reinterpret_cast(&dns_server_addrs[1].addr.addr4))[3] = 0x1; dns_server_addrs[1].tcp_port = atoi(local_dns_server_port.c_str()); dns_server_addrs[1].udp_port = atoi(local_dns_server_port.c_str()); dns_server_addrs[1].next = nullptr; @@ -660,7 +660,7 @@ TEST(ResolverComponentTest, TestResolvesRelevantRecordsWithConcurrentFdStress) { // Run the resolver test RunResolvesRelevantRecordsTest(ResultHandler::Create); // Shutdown and join stress thread - gpr_event_set(&done_ev, (void*)1); + gpr_event_set(&done_ev, reinterpret_cast(1)); socket_stress_thread.join(); } diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 29cb327e823..5cb4d9dd1d6 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -411,7 +411,7 @@ class Client { void MaybeStartRequests() { if (!started_requests_) { started_requests_ = true; - gpr_event_set(&start_requests_, (void*)1); + gpr_event_set(&start_requests_, reinterpret_cast(1)); } } diff --git a/test/cpp/server/server_builder_with_socket_mutator_test.cc b/test/cpp/server/server_builder_with_socket_mutator_test.cc index c7d4382b756..ab4308007ce 100644 --- a/test/cpp/server/server_builder_with_socket_mutator_test.cc +++ b/test/cpp/server/server_builder_with_socket_mutator_test.cc @@ -64,7 +64,7 @@ bool mock_socket_mutator_mutate_fd(int /*fd*/, grpc_socket_mutator* m) { int mock_socket_mutator_compare(grpc_socket_mutator* a, grpc_socket_mutator* b) { - return (uintptr_t)a - (uintptr_t)b; + return reinterpret_cast(a) - reinterpret_cast(b); } void mock_socket_mutator_destroy(grpc_socket_mutator* m) { diff --git a/test/cpp/server/server_request_call_test.cc b/test/cpp/server/server_request_call_test.cc index 4b30de34b68..5ce852575e3 100644 --- a/test/cpp/server/server_request_call_test.cc +++ b/test/cpp/server/server_request_call_test.cc @@ -65,7 +65,7 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { std::lock_guard lock(mu); if (!shutting_down) { service.RequestEcho(&ctx, &req, &responder, cq.get(), cq.get(), - (void*)1); + reinterpret_cast(1)); } } @@ -106,7 +106,8 @@ TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { continue; } gpr_log(GPR_INFO, "Finishing request %d", n); - responder.Finish(response, grpc::Status::OK, (void*)2); + responder.Finish(response, grpc::Status::OK, + reinterpret_cast(2)); if (!cq->Next(&tag, &ok)) { break; } diff --git a/test/cpp/util/channelz_sampler_test.cc b/test/cpp/util/channelz_sampler_test.cc index efd01e78d40..89d82c60a46 100644 --- a/test/cpp/util/channelz_sampler_test.cc +++ b/test/cpp/util/channelz_sampler_test.cc @@ -155,8 +155,8 @@ TEST(ChannelzSamplerTest, SimpleTest) { GPR_ASSERT(0); } delete test_driver; - gpr_event_set(&done_ev1, (void*)1); - gpr_event_set(&done_ev2, (void*)1); + gpr_event_set(&done_ev1, reinterpret_cast(1)); + gpr_event_set(&done_ev2, reinterpret_cast(1)); client_thread_1.join(); client_thread_2.join(); } diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc index 30f3c1d6c03..34def7a66f2 100644 --- a/test/cpp/util/cli_call.cc +++ b/test/cpp/util/cli_call.cc @@ -32,7 +32,7 @@ namespace grpc { namespace testing { namespace { -void* tag(int i) { return (void*)static_cast(i); } +void* tag(intptr_t t) { return reinterpret_cast(t); } } // namespace Status CliCall::Call(const std::shared_ptr& channel, diff --git a/test/cpp/util/grpc_cli.cc b/test/cpp/util/grpc_cli.cc index 45419197b75..a1b275a9b95 100644 --- a/test/cpp/util/grpc_cli.cc +++ b/test/cpp/util/grpc_cli.cc @@ -88,7 +88,7 @@ int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); return grpc::testing::GrpcToolMainLib( - argc, (const char**)argv, grpc::testing::CliCredentials(), + argc, const_cast(argv), grpc::testing::CliCredentials(), std::bind(SimplePrint, absl::GetFlag(FLAGS_outfile), std::placeholders::_1)); } diff --git a/test/cpp/util/grpc_tool.cc b/test/cpp/util/grpc_tool.cc index 0ad20ebeead..0c73135648a 100644 --- a/test/cpp/util/grpc_tool.cc +++ b/test/cpp/util/grpc_tool.cc @@ -280,7 +280,7 @@ void Usage(const std::string& msg) { } const Command* FindCommand(const std::string& name) { - for (int i = 0; i < (int)ArraySize(ops); i++) { + for (int i = 0; i < static_cast(ArraySize(ops)); i++) { if (name == ops[i].command) { return &ops[i]; } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 4d3a38cf249..08cc139033e 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -637,7 +637,7 @@ static uint32_t %(name)s_phash(uint32_t i) { uint32_t y = i / %(t)d; uint32_t h = x; if (y < GPR_ARRAY_SIZE(%(name)s_r)) { - uint32_t delta = (uint32_t)%(name)s_r[y]; + uint32_t delta = static_cast(%(name)s_r[y]); h += delta; } return h;