From 7fed69b7ad10a06c2eedaaf0279f44f2bab0d85c Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Mon, 5 Mar 2018 09:58:05 -0800 Subject: Use static_cast rather than reinterpret_cast whenever possible --- .../client_channel/lb_policy/grpclb/grpclb.cc | 27 +++++++++++----------- .../lb_policy/pick_first/pick_first.cc | 4 ++-- .../lb_policy/round_robin/round_robin.cc | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src/core/ext/filters') 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 7c0e33ff0a..cb39e4224e 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 @@ -191,7 +191,7 @@ class GrpcLb : public LoadBalancingPolicy { ~BalancerCallState(); GrpcLb* grpclb_policy() const { - return reinterpret_cast(grpclb_policy_.get()); + return static_cast(grpclb_policy_.get()); } void ScheduleNextClientLoadReportLocked(); @@ -651,7 +651,7 @@ void GrpcLb::BalancerCallState::ScheduleNextClientLoadReportLocked() { void GrpcLb::BalancerCallState::MaybeSendClientLoadReportLocked( void* arg, grpc_error* error) { - BalancerCallState* lb_calld = reinterpret_cast(arg); + BalancerCallState* lb_calld = static_cast(arg); GrpcLb* grpclb_policy = lb_calld->grpclb_policy(); lb_calld->client_load_report_timer_callback_pending_ = false; if (error != GRPC_ERROR_NONE || lb_calld != grpclb_policy->lb_calld_.get()) { @@ -721,7 +721,7 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() { void GrpcLb::BalancerCallState::ClientLoadReportDoneLocked(void* arg, grpc_error* error) { - BalancerCallState* lb_calld = reinterpret_cast(arg); + BalancerCallState* lb_calld = static_cast(arg); GrpcLb* grpclb_policy = lb_calld->grpclb_policy(); grpc_byte_buffer_destroy(lb_calld->send_message_payload_); lb_calld->send_message_payload_ = nullptr; @@ -734,7 +734,7 @@ void GrpcLb::BalancerCallState::ClientLoadReportDoneLocked(void* arg, void GrpcLb::BalancerCallState::OnInitialRequestSentLocked(void* arg, grpc_error* error) { - BalancerCallState* lb_calld = reinterpret_cast(arg); + BalancerCallState* lb_calld = static_cast(arg); grpc_byte_buffer_destroy(lb_calld->send_message_payload_); lb_calld->send_message_payload_ = nullptr; // If we attempted to send a client load report before the initial request was @@ -749,7 +749,7 @@ void GrpcLb::BalancerCallState::OnInitialRequestSentLocked(void* arg, void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked( void* arg, grpc_error* error) { - BalancerCallState* lb_calld = reinterpret_cast(arg); + BalancerCallState* lb_calld = static_cast(arg); GrpcLb* grpclb_policy = lb_calld->grpclb_policy(); // Empty payload means the LB call was cancelled. if (lb_calld != grpclb_policy->lb_calld_.get() || @@ -882,7 +882,7 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked( void GrpcLb::BalancerCallState::OnBalancerStatusReceivedLocked( void* arg, grpc_error* error) { - BalancerCallState* lb_calld = reinterpret_cast(arg); + BalancerCallState* lb_calld = static_cast(arg); GrpcLb* grpclb_policy = lb_calld->grpclb_policy(); GPR_ASSERT(lb_calld->lb_call_ != nullptr); if (grpc_lb_glb_trace.enabled()) { @@ -1283,7 +1283,7 @@ void GrpcLb::ProcessChannelArgsLocked(const grpc_channel_args& args) { return; } const grpc_lb_addresses* addresses = - reinterpret_cast(arg->value.pointer.p); + static_cast(arg->value.pointer.p); // Update fallback address list. if (fallback_backend_addresses_ != nullptr) { grpc_lb_addresses_destroy(fallback_backend_addresses_); @@ -1426,7 +1426,7 @@ void GrpcLb::StartBalancerCallRetryTimerLocked() { } void GrpcLb::OnBalancerCallRetryTimerLocked(void* arg, grpc_error* error) { - GrpcLb* grpclb_policy = reinterpret_cast(arg); + GrpcLb* grpclb_policy = static_cast(arg); grpclb_policy->retry_timer_callback_pending_ = false; if (!grpclb_policy->shutting_down_ && error == GRPC_ERROR_NONE && grpclb_policy->lb_calld_ == nullptr) { @@ -1503,8 +1503,7 @@ grpc_error* AddLbTokenToInitialMetadata( // Destroy function used when embedding client stats in call context. void DestroyClientStats(void* arg) { - grpc_grpclb_client_stats_unref( - reinterpret_cast(arg)); + grpc_grpclb_client_stats_unref(static_cast(arg)); } void GrpcLb::PendingPickSetMetadataAndContext(PendingPick* pp) { @@ -1540,7 +1539,7 @@ void GrpcLb::PendingPickSetMetadataAndContext(PendingPick* pp) { * reference to its associated round robin instance. We wrap this closure in * order to unref the round robin instance upon its invocation */ void GrpcLb::OnPendingPickComplete(void* arg, grpc_error* error) { - PendingPick* pp = reinterpret_cast(arg); + PendingPick* pp = static_cast(arg); PendingPickSetMetadataAndContext(pp); GRPC_CLOSURE_SCHED(pp->original_on_complete, GRPC_ERROR_REF(error)); Delete(pp); @@ -1739,7 +1738,7 @@ void GrpcLb::CreateOrUpdateRoundRobinPolicyLocked() { void GrpcLb::OnRoundRobinRequestReresolutionLocked(void* arg, grpc_error* error) { - GrpcLb* grpclb_policy = reinterpret_cast(arg); + GrpcLb* grpclb_policy = static_cast(arg); if (grpclb_policy->shutting_down_ || error != GRPC_ERROR_NONE) { grpclb_policy->Unref(DEBUG_LOCATION, "on_rr_reresolution_requested"); return; @@ -1820,7 +1819,7 @@ void GrpcLb::UpdateConnectivityStateFromRoundRobinPolicyLocked( void GrpcLb::OnRoundRobinConnectivityChangedLocked(void* arg, grpc_error* error) { - GrpcLb* grpclb_policy = reinterpret_cast(arg); + GrpcLb* grpclb_policy = static_cast(arg); if (grpclb_policy->shutting_down_) { grpclb_policy->Unref(DEBUG_LOCATION, "on_rr_connectivity_changed"); return; @@ -1848,7 +1847,7 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory { return nullptr; } grpc_lb_addresses* addresses = - reinterpret_cast(arg->value.pointer.p); + static_cast(arg->value.pointer.p); size_t num_grpclb_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs; diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index 818b93c882..9090c34412 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -393,8 +393,8 @@ void PickFirst::UpdateLocked(const grpc_channel_args& args) { } void PickFirst::OnConnectivityChangedLocked(void* arg, grpc_error* error) { - grpc_lb_subchannel_data* sd = reinterpret_cast(arg); - PickFirst* p = reinterpret_cast(sd->subchannel_list->policy); + grpc_lb_subchannel_data* sd = static_cast(arg); + PickFirst* p = static_cast(sd->subchannel_list->policy); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p connectivity changed for subchannel %p (%" PRIuPTR diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index 7ef7b0f6fc..e534131c02 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -412,8 +412,8 @@ void RoundRobin::UpdateConnectivityStatusLocked(grpc_lb_subchannel_data* sd, } void RoundRobin::OnConnectivityChangedLocked(void* arg, grpc_error* error) { - grpc_lb_subchannel_data* sd = reinterpret_cast(arg); - RoundRobin* p = reinterpret_cast(sd->subchannel_list->policy); + grpc_lb_subchannel_data* sd = static_cast(arg); + RoundRobin* p = static_cast(sd->subchannel_list->policy); if (grpc_lb_round_robin_trace.enabled()) { gpr_log( GPR_DEBUG, -- cgit v1.2.3