From a8ac4e72657a8bbee8f886bfbf587da67c40ce6b Mon Sep 17 00:00:00 2001 From: Eryu Xia Date: Thu, 8 Dec 2022 15:33:49 -0800 Subject: [PATCH] Revert "[ObjC]fix 64 to 32 bit clang conversion warning in src/core/lib (#29877)" (#31843) This reverts commit eb0a5918116fa7c600ab1e2fb47782a5c55c55b9. --- include/grpcpp/test/channel_test_peer.h | 2 +- .../lb_policy/priority/priority.cc | 6 +++--- .../chttp2/transport/chttp2_transport.cc | 2 +- .../transport/chttp2/transport/flow_control.cc | 2 +- .../transport/chttp2/transport/flow_control.h | 2 +- .../transport/chttp2/transport/hpack_parser.cc | 3 +-- .../chttp2/transport/hpack_parser_table.cc | 3 +-- .../lib/compression/compression_internal.cc | 6 +++--- src/core/lib/event_engine/posix_engine/timer.cc | 2 +- .../lib/event_engine/posix_engine/timer_heap.cc | 4 ++-- src/core/lib/gpr/time_precise.cc | 2 +- src/core/lib/gprpp/bitset.h | 2 +- src/core/lib/gprpp/status_helper.cc | 2 +- src/core/lib/iomgr/tcp_client_posix.cc | 6 +++--- src/core/lib/iomgr/tcp_posix.cc | 17 +++++++---------- .../load_system_roots_supported.cc | 2 +- src/core/lib/slice/slice.h | 2 +- src/core/lib/slice/slice_internal.h | 2 +- src/core/lib/surface/call.cc | 2 +- src/core/lib/surface/channel.h | 2 +- .../alts_zero_copy_grpc_protector.cc | 4 ++-- src/core/tsi/fake_transport_security.cc | 3 +-- src/cpp/client/channel_test_peer.cc | 4 +--- test/cpp/end2end/end2end_test.cc | 2 +- 24 files changed, 38 insertions(+), 46 deletions(-) diff --git a/include/grpcpp/test/channel_test_peer.h b/include/grpcpp/test/channel_test_peer.h index 28be49681eb..e41bbfa4604 100644 --- a/include/grpcpp/test/channel_test_peer.h +++ b/include/grpcpp/test/channel_test_peer.h @@ -31,7 +31,7 @@ class ChannelTestPeer { /// Provide the gRPC Core channel grpc_channel* channel() const { return channel_->c_channel_; } - size_t registered_calls() const; + int registered_calls() const; int registration_attempts() const; private: diff --git a/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc b/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc index 0a06add1d7a..a9490c365fd 100644 --- a/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +++ b/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc @@ -471,9 +471,9 @@ void PriorityLb::ChoosePriorityLocked() { } } // Did not find any child in CONNECTING, delegate to last child. - SetCurrentPriorityLocked( - static_cast(config_->priorities().size() - 1), - /*deactivate_lower_priorities=*/false, "no usable children"); + SetCurrentPriorityLocked(config_->priorities().size() - 1, + /*deactivate_lower_priorities=*/false, + "no usable children"); } void PriorityLb::SetCurrentPriorityLocked(int32_t priority, diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index d9e15e8503f..670dc05f101 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -1304,7 +1304,7 @@ static void perform_stream_op_locked(void* stream_op, if (op->send_message) { t->num_messages_in_next_write++; grpc_core::global_stats().IncrementHttp2SendMessageSize( - static_cast(op->payload->send_message.send_message->Length())); + op->payload->send_message.send_message->Length()); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->send_message_finished = add_closure_barrier(op->on_complete); const uint32_t flags = op_payload->send_message.flags; diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index be412f13b96..e1c26124bc5 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -294,7 +294,7 @@ void TransportFlowControl::UpdateSetting( urgency = FlowControlAction::Urgency::UPDATE_IMMEDIATELY; } *desired_value = new_desired_value; - (action->*set)(urgency, static_cast(*desired_value)); + (action->*set)(urgency, *desired_value); } } else { int64_t delta = new_desired_value - *desired_value; diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index d641ea5eb48..e4d71d2e133 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -259,7 +259,7 @@ class TransportFlowControl final { BdpEstimator* bdp_estimator() { return &bdp_estimator_; } uint32_t acked_init_window() const { return acked_init_window_; } - int64_t sent_init_window() const { return target_initial_window_size_; } + uint32_t sent_init_window() const { return target_initial_window_size_; } FlowControlAction SetAckedInitialWindow(uint32_t value); diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 67d00594969..46d7195d078 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -1104,8 +1104,7 @@ class HPackParser::Parser { const auto transport_size = key_string.size() + value_slice.size() + hpack_constants::kEntryOverhead; return grpc_metadata_batch::Parse( - key->string_view(), std::move(value_slice), - static_cast(transport_size), + key->string_view(), std::move(value_slice), transport_size, [key_string](absl::string_view error, const Slice& value) { ReportMetadataParseError(key_string, error, value.as_string_view()); }); diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc index eea3b3faa55..6ddcb455000 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc @@ -229,8 +229,7 @@ HPackTable::Memento MakeMemento(size_t i) { auto sm = kStaticTable[i]; return grpc_metadata_batch::Parse( sm.key, Slice::FromStaticString(sm.value), - static_cast(strlen(sm.key) + strlen(sm.value) + - hpack_constants::kEntryOverhead), + strlen(sm.key) + strlen(sm.value) + hpack_constants::kEntryOverhead, [](absl::string_view, const Slice&) { abort(); // not expecting to see this }); diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc index 6590704d263..7fae483c6e8 100644 --- a/src/core/lib/compression/compression_internal.cc +++ b/src/core/lib/compression/compression_internal.cc @@ -156,7 +156,7 @@ CompressionAlgorithmSet::CompressionAlgorithmForLevel( CompressionAlgorithmSet CompressionAlgorithmSet::FromUint32(uint32_t value) { CompressionAlgorithmSet set; - for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { + for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (value & (1u << i)) { set.set_.set(i); } @@ -185,7 +185,7 @@ CompressionAlgorithmSet::CompressionAlgorithmSet( bool CompressionAlgorithmSet::IsSet( grpc_compression_algorithm algorithm) const { - int i = algorithm; + size_t i = static_cast(algorithm); if (i < GRPC_COMPRESS_ALGORITHMS_COUNT) { return set_.is_set(i); } else { @@ -194,7 +194,7 @@ bool CompressionAlgorithmSet::IsSet( } void CompressionAlgorithmSet::Set(grpc_compression_algorithm algorithm) { - int i = algorithm; + size_t i = static_cast(algorithm); if (i < GRPC_COMPRESS_ALGORITHMS_COUNT) { set_.set(i); } diff --git a/src/core/lib/event_engine/posix_engine/timer.cc b/src/core/lib/event_engine/posix_engine/timer.cc index e0c7c68a26d..f026d6a3960 100644 --- a/src/core/lib/event_engine/posix_engine/timer.cc +++ b/src/core/lib/event_engine/posix_engine/timer.cc @@ -59,7 +59,7 @@ TimerList::TimerList(TimerListHost* host) shard.queue_deadline_cap = grpc_core::Timestamp::FromMillisecondsAfterProcessEpoch( min_timer_.load(std::memory_order_relaxed)); - shard.shard_queue_index = static_cast(i); + shard.shard_queue_index = i; shard.list.next = shard.list.prev = &shard.list; shard.min_deadline = shard.ComputeMinDeadline(); shard_queue_[i] = &shard; diff --git a/src/core/lib/event_engine/posix_engine/timer_heap.cc b/src/core/lib/event_engine/posix_engine/timer_heap.cc index c0f2ba379b9..7ad40468824 100644 --- a/src/core/lib/event_engine/posix_engine/timer_heap.cc +++ b/src/core/lib/event_engine/posix_engine/timer_heap.cc @@ -69,7 +69,7 @@ void TimerHeap::AdjustDownwards(size_t i, Timer* t) { } void TimerHeap::NoteChangedPriority(Timer* timer) { - uint32_t i = static_cast(timer->heap_index); + uint32_t i = timer->heap_index; uint32_t parent = static_cast((static_cast(i) - 1) / 2); if (timers_[parent]->deadline > timer->deadline) { AdjustUpwards(i, timer); @@ -86,7 +86,7 @@ bool TimerHeap::Add(Timer* timer) { } void TimerHeap::Remove(Timer* timer) { - size_t i = timer->heap_index; + uint32_t i = timer->heap_index; if (i == timers_.size() - 1) { timers_.pop_back(); return; diff --git a/src/core/lib/gpr/time_precise.cc b/src/core/lib/gpr/time_precise.cc index 6ec04903228..c66b981d321 100644 --- a/src/core/lib/gpr/time_precise.cc +++ b/src/core/lib/gpr/time_precise.cc @@ -149,7 +149,7 @@ gpr_cycle_counter gpr_get_cycle_counter() { gpr_timespec gpr_cycle_counter_to_time(gpr_cycle_counter cycles) { gpr_timespec ts; ts.tv_sec = static_cast(cycles / GPR_US_PER_SEC); - ts.tv_nsec = static_cast((cycles - ts.tv_sec * GPR_US_PER_SEC) * + ts.tv_nsec = static_cast((cycles - ts.tv_sec * GPR_US_PER_SEC) * GPR_NS_PER_US); ts.clock_type = GPR_CLOCK_PRECISE; return ts; diff --git a/src/core/lib/gprpp/bitset.h b/src/core/lib/gprpp/bitset.h index f636b0a4754..77ed4552415 100644 --- a/src/core/lib/gprpp/bitset.h +++ b/src/core/lib/gprpp/bitset.h @@ -157,7 +157,7 @@ class BitSet { ToInt() const { Int result = 0; for (size_t i = 0; i < kTotalBits; i++) { - if (is_set(static_cast(i))) result |= (Int(1) << i); + if (is_set(i)) result |= (Int(1) << i); } return result; } diff --git a/src/core/lib/gprpp/status_helper.cc b/src/core/lib/gprpp/status_helper.cc index bbf5ad864cc..31930dd120f 100644 --- a/src/core/lib/gprpp/status_helper.cc +++ b/src/core/lib/gprpp/status_helper.cc @@ -269,7 +269,7 @@ void StatusAddChild(absl::Status* status, absl::Status child) { children = *old_children; } char head_buf[sizeof(uint32_t)]; - EncodeUInt32ToBytes(static_cast(buf_len), head_buf); + EncodeUInt32ToBytes(buf_len, head_buf); children.Append(absl::string_view(head_buf, sizeof(uint32_t))); children.Append(absl::string_view(buf, buf_len)); status->SetPayload(kChildrenPropertyUrl, std::move(children)); diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index cc175ce55d9..a109e25e494 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -244,7 +244,7 @@ static void on_writable(void* acp, grpc_error_handle error) { finish: if (!connect_cancelled) { - size_t shard_number = ac->connection_handle % (*g_connection_shards).size(); + int shard_number = ac->connection_handle % (*g_connection_shards).size(); struct ConnectionShard* shard = &(*g_connection_shards)[shard_number]; { grpc_core::MutexLock lock(&shard->mu); @@ -379,7 +379,7 @@ int64_t grpc_tcp_client_create_from_prepared_fd( ac->addr_str.c_str(), fdobj); } - size_t shard_number = connection_id % (*g_connection_shards).size(); + int shard_number = connection_id % (*g_connection_shards).size(); struct ConnectionShard* shard = &(*g_connection_shards)[shard_number]; { grpc_core::MutexLock lock(&shard->mu); @@ -417,7 +417,7 @@ static bool tcp_cancel_connect(int64_t connection_handle) { if (connection_handle <= 0) { return false; } - size_t shard_number = connection_handle % (*g_connection_shards).size(); + int shard_number = connection_handle % (*g_connection_shards).size(); struct ConnectionShard* shard = &(*g_connection_shards)[shard_number]; async_connect* ac = nullptr; { diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 6db4d04c845..a2f362d1ba1 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -914,9 +914,9 @@ static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error) msg.msg_flags = 0; grpc_core::global_stats().IncrementTcpReadOffer( - static_cast(tcp->incoming_buffer->length)); + tcp->incoming_buffer->length); grpc_core::global_stats().IncrementTcpReadOfferIovSize( - static_cast(tcp->incoming_buffer->count)); + tcp->incoming_buffer->count); do { grpc_core::global_stats().IncrementSyscallRead(); @@ -955,8 +955,7 @@ static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error) return true; } - grpc_core::global_stats().IncrementTcpReadSize( - static_cast(read_bytes)); + grpc_core::global_stats().IncrementTcpReadSize(read_bytes); add_to_estimate(tcp, static_cast(read_bytes)); GPR_DEBUG_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length - total_read_bytes); @@ -1058,8 +1057,8 @@ static void maybe_make_read_slices(grpc_tcp* tcp) if (low_memory_pressure && target_length > allocate_length) { allocate_length = target_length; } - int extra_wanted = static_cast(allocate_length) - - static_cast(tcp->incoming_buffer->length); + int extra_wanted = + allocate_length - static_cast(tcp->incoming_buffer->length); if (extra_wanted >= (low_memory_pressure ? kSmallAlloc * 3 / 2 : kBigAlloc)) { while (extra_wanted > 0) { @@ -1603,8 +1602,7 @@ static bool do_tcp_flush_zerocopy(grpc_tcp* tcp, TcpZerocopySendRecord* record, if (!tried_sending_message) { msg.msg_control = nullptr; msg.msg_controllen = 0; - grpc_core::global_stats().IncrementTcpWriteSize( - static_cast(sending_length)); + grpc_core::global_stats().IncrementTcpWriteSize(sending_length); grpc_core::global_stats().IncrementTcpWriteIovSize(iov_size); sent_length = tcp_send(tcp->fd, &msg, &saved_errno, MSG_ZEROCOPY); } @@ -1717,8 +1715,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error_handle* error) { msg.msg_control = nullptr; msg.msg_controllen = 0; - grpc_core::global_stats().IncrementTcpWriteSize( - static_cast(sending_length)); + grpc_core::global_stats().IncrementTcpWriteSize(sending_length); grpc_core::global_stats().IncrementTcpWriteIovSize(iov_size); sent_length = tcp_send(tcp->fd, &msg, &saved_errno); diff --git a/src/core/lib/security/security_connector/load_system_roots_supported.cc b/src/core/lib/security/security_connector/load_system_roots_supported.cc index 608ab0dd2ba..44cab4cbd48 100644 --- a/src/core/lib/security/security_connector/load_system_roots_supported.cc +++ b/src/core/lib/security/security_connector/load_system_roots_supported.cc @@ -134,7 +134,7 @@ grpc_slice CreateRootCertsBundle(const char* certs_directory) { if (file_descriptor != -1) { // Read file into bundle. size_t cert_file_size = roots_filenames[i].size; - ssize_t read_ret = + int read_ret = read(file_descriptor, bundle_string + bytes_read, cert_file_size); if (read_ret != -1) { bytes_read += read_ret; diff --git a/src/core/lib/slice/slice.h b/src/core/lib/slice/slice.h index fe7cfd09552..f95d0d87f1d 100644 --- a/src/core/lib/slice/slice.h +++ b/src/core/lib/slice/slice.h @@ -207,7 +207,7 @@ struct CopyConstructors { static Out FromInt64(int64_t i) { char buffer[GPR_LTOA_MIN_BUFSIZE]; - int64_ttoa(i, buffer); + gpr_ltoa(i, buffer); return FromCopiedString(buffer); } }; diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 4d840f75b03..e29ed382d1f 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -79,7 +79,7 @@ inline absl::string_view StringViewFromSlice(const grpc_slice& slice) { } // namespace grpc_core inline uint32_t grpc_slice_hash(const grpc_slice& s) { - return static_cast(absl::HashOf(grpc_core::StringViewFromSlice(s))); + return absl::HashOf(grpc_core::StringViewFromSlice(s)); } namespace grpc_core { diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 6bdf115010c..ef8e2afb2fe 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -636,7 +636,7 @@ grpc_error_handle FilterStackCall::Create(grpc_call_create_args* args, grpc_error_handle error; grpc_channel_stack* channel_stack = channel->channel_stack(); size_t initial_size = channel->CallSizeEstimate(); - global_stats().IncrementCallInitialSize(static_cast(initial_size)); + global_stats().IncrementCallInitialSize(initial_size); size_t call_alloc_size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(FilterStackCall)) + channel_stack->call_stack_size; diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index d0a8c96eefb..b0cdae32c7c 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -145,7 +145,7 @@ class Channel : public RefCounted, bool is_promising() const { return is_promising_; } RegisteredCall* RegisterCall(const char* method, const char* host); - size_t TestOnlyRegisteredCalls() { + int TestOnlyRegisteredCalls() { MutexLock lock(®istration_table_.mu); return registration_table_.map.size(); } 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 0eb5a6724b1..ad35dacee2c 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 @@ -217,8 +217,8 @@ static tsi_result alts_zero_copy_grpc_protector_unprotect( } if (min_progress_size != nullptr) { if (protector->parsed_frame_size > kZeroCopyFrameLengthFieldSize) { - *min_progress_size = static_cast(protector->parsed_frame_size - - protector->protected_sb.length); + *min_progress_size = + protector->parsed_frame_size - protector->protected_sb.length; } else { *min_progress_size = 1; } diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index 0a288087b15..c0d451701ac 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -485,8 +485,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( } if (min_progress_size != nullptr) { if (impl->parsed_frame_size > TSI_FAKE_FRAME_HEADER_SIZE) { - *min_progress_size = - static_cast(impl->parsed_frame_size - impl->protected_sb.length); + *min_progress_size = impl->parsed_frame_size - impl->protected_sb.length; } else { *min_progress_size = 1; } diff --git a/src/cpp/client/channel_test_peer.cc b/src/cpp/client/channel_test_peer.cc index 08401480c39..d91f692ea6e 100644 --- a/src/cpp/client/channel_test_peer.cc +++ b/src/cpp/client/channel_test_peer.cc @@ -16,8 +16,6 @@ * */ -#include - #include #include @@ -26,7 +24,7 @@ namespace grpc { namespace testing { -size_t ChannelTestPeer::registered_calls() const { +int ChannelTestPeer::registered_calls() const { return grpc_core::Channel::FromC(channel_->c_channel_) ->TestOnlyRegisteredCalls(); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 9cb91612c5d..9fdedbdd7d8 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -859,7 +859,7 @@ TEST_P(End2endTest, MultipleRpcs) { TEST_P(End2endTest, ManyStubs) { ResetStub(); ChannelTestPeer peer(channel_.get()); - size_t registered_calls_pre = peer.registered_calls(); + int registered_calls_pre = peer.registered_calls(); int registration_attempts_pre = peer.registration_attempts(); for (int i = 0; i < 1000; ++i) { grpc::testing::EchoTestService::NewStub(channel_);