Skip to content

Commit

Permalink
[ObjC]fix 64 to 32 bit clang conversion warning in src/core/lib (grpc…
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahShiSFB authored Dec 8, 2022
1 parent f17592d commit eb0a591
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion include/grpcpp/test/channel_test_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChannelTestPeer {

/// Provide the gRPC Core channel
grpc_channel* channel() const { return channel_->c_channel_; }
int registered_calls() const;
size_t registered_calls() const;
int registration_attempts() const;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ void PriorityLb::ChoosePriorityLocked() {
}
}
// Did not find any child in CONNECTING, delegate to last child.
SetCurrentPriorityLocked(config_->priorities().size() - 1,
/*deactivate_lower_priorities=*/false,
"no usable children");
SetCurrentPriorityLocked(
static_cast<int32_t>(config_->priorities().size() - 1),
/*deactivate_lower_priorities=*/false, "no usable children");
}

void PriorityLb::SetCurrentPriorityLocked(int32_t priority,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
op->payload->send_message.send_message->Length());
static_cast<int>(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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/transport/chttp2/transport/flow_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void TransportFlowControl::UpdateSetting(
urgency = FlowControlAction::Urgency::UPDATE_IMMEDIATELY;
}
*desired_value = new_desired_value;
(action->*set)(urgency, *desired_value);
(action->*set)(urgency, static_cast<uint32_t>(*desired_value));
}
} else {
int64_t delta = new_desired_value - *desired_value;
Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/transport/chttp2/transport/flow_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class TransportFlowControl final {
BdpEstimator* bdp_estimator() { return &bdp_estimator_; }

uint32_t acked_init_window() const { return acked_init_window_; }
uint32_t sent_init_window() const { return target_initial_window_size_; }
int64_t sent_init_window() const { return target_initial_window_size_; }

FlowControlAction SetAckedInitialWindow(uint32_t value);

Expand Down
3 changes: 2 additions & 1 deletion src/core/ext/transport/chttp2/transport/hpack_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,8 @@ 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), transport_size,
key->string_view(), std::move(value_slice),
static_cast<uint32_t>(transport_size),
[key_string](absl::string_view error, const Slice& value) {
ReportMetadataParseError(key_string, error, value.as_string_view());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ HPackTable::Memento MakeMemento(size_t i) {
auto sm = kStaticTable[i];
return grpc_metadata_batch::Parse(
sm.key, Slice::FromStaticString(sm.value),
strlen(sm.key) + strlen(sm.value) + hpack_constants::kEntryOverhead,
static_cast<uint32_t>(strlen(sm.key) + strlen(sm.value) +
hpack_constants::kEntryOverhead),
[](absl::string_view, const Slice&) {
abort(); // not expecting to see this
});
Expand Down
6 changes: 3 additions & 3 deletions src/core/lib/compression/compression_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ CompressionAlgorithmSet::CompressionAlgorithmForLevel(

CompressionAlgorithmSet CompressionAlgorithmSet::FromUint32(uint32_t value) {
CompressionAlgorithmSet set;
for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (value & (1u << i)) {
set.set_.set(i);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ CompressionAlgorithmSet::CompressionAlgorithmSet(

bool CompressionAlgorithmSet::IsSet(
grpc_compression_algorithm algorithm) const {
size_t i = static_cast<size_t>(algorithm);
int i = algorithm;
if (i < GRPC_COMPRESS_ALGORITHMS_COUNT) {
return set_.is_set(i);
} else {
Expand All @@ -194,7 +194,7 @@ bool CompressionAlgorithmSet::IsSet(
}

void CompressionAlgorithmSet::Set(grpc_compression_algorithm algorithm) {
size_t i = static_cast<size_t>(algorithm);
int i = algorithm;
if (i < GRPC_COMPRESS_ALGORITHMS_COUNT) {
set_.set(i);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/event_engine/posix_engine/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = i;
shard.shard_queue_index = static_cast<uint32_t>(i);
shard.list.next = shard.list.prev = &shard.list;
shard.min_deadline = shard.ComputeMinDeadline();
shard_queue_[i] = &shard;
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/event_engine/posix_engine/timer_heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void TimerHeap::AdjustDownwards(size_t i, Timer* t) {
}

void TimerHeap::NoteChangedPriority(Timer* timer) {
uint32_t i = timer->heap_index;
uint32_t i = static_cast<uint32_t>(timer->heap_index);
uint32_t parent = static_cast<uint32_t>((static_cast<int>(i) - 1) / 2);
if (timers_[parent]->deadline > timer->deadline) {
AdjustUpwards(i, timer);
Expand All @@ -86,7 +86,7 @@ bool TimerHeap::Add(Timer* timer) {
}

void TimerHeap::Remove(Timer* timer) {
uint32_t i = timer->heap_index;
size_t i = timer->heap_index;
if (i == timers_.size() - 1) {
timers_.pop_back();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/gpr/time_precise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(cycles / GPR_US_PER_SEC);
ts.tv_nsec = static_cast<int64_t>((cycles - ts.tv_sec * GPR_US_PER_SEC) *
ts.tv_nsec = static_cast<int32_t>((cycles - ts.tv_sec * GPR_US_PER_SEC) *
GPR_NS_PER_US);
ts.clock_type = GPR_CLOCK_PRECISE;
return ts;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/gprpp/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class BitSet {
ToInt() const {
Int result = 0;
for (size_t i = 0; i < kTotalBits; i++) {
if (is_set(i)) result |= (Int(1) << i);
if (is_set(static_cast<int>(i))) result |= (Int(1) << i);
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/gprpp/status_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void StatusAddChild(absl::Status* status, absl::Status child) {
children = *old_children;
}
char head_buf[sizeof(uint32_t)];
EncodeUInt32ToBytes(buf_len, head_buf);
EncodeUInt32ToBytes(static_cast<uint32_t>(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));
Expand Down
6 changes: 3 additions & 3 deletions src/core/lib/iomgr/tcp_client_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static void on_writable(void* acp, grpc_error_handle error) {

finish:
if (!connect_cancelled) {
int shard_number = ac->connection_handle % (*g_connection_shards).size();
size_t shard_number = ac->connection_handle % (*g_connection_shards).size();
struct ConnectionShard* shard = &(*g_connection_shards)[shard_number];
{
grpc_core::MutexLock lock(&shard->mu);
Expand Down Expand Up @@ -379,7 +379,7 @@ int64_t grpc_tcp_client_create_from_prepared_fd(
ac->addr_str.c_str(), fdobj);
}

int shard_number = connection_id % (*g_connection_shards).size();
size_t shard_number = connection_id % (*g_connection_shards).size();
struct ConnectionShard* shard = &(*g_connection_shards)[shard_number];
{
grpc_core::MutexLock lock(&shard->mu);
Expand Down Expand Up @@ -417,7 +417,7 @@ static bool tcp_cancel_connect(int64_t connection_handle) {
if (connection_handle <= 0) {
return false;
}
int shard_number = connection_handle % (*g_connection_shards).size();
size_t shard_number = connection_handle % (*g_connection_shards).size();
struct ConnectionShard* shard = &(*g_connection_shards)[shard_number];
async_connect* ac = nullptr;
{
Expand Down
17 changes: 10 additions & 7 deletions src/core/lib/iomgr/tcp_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
tcp->incoming_buffer->length);
static_cast<int>(tcp->incoming_buffer->length));
grpc_core::global_stats().IncrementTcpReadOfferIovSize(
tcp->incoming_buffer->count);
static_cast<int>(tcp->incoming_buffer->count));

do {
grpc_core::global_stats().IncrementSyscallRead();
Expand Down Expand Up @@ -955,7 +955,8 @@ static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error)
return true;
}

grpc_core::global_stats().IncrementTcpReadSize(read_bytes);
grpc_core::global_stats().IncrementTcpReadSize(
static_cast<int>(read_bytes));
add_to_estimate(tcp, static_cast<size_t>(read_bytes));
GPR_DEBUG_ASSERT((size_t)read_bytes <=
tcp->incoming_buffer->length - total_read_bytes);
Expand Down Expand Up @@ -1057,8 +1058,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 =
allocate_length - static_cast<int>(tcp->incoming_buffer->length);
int extra_wanted = static_cast<int>(allocate_length) -
static_cast<int>(tcp->incoming_buffer->length);
if (extra_wanted >=
(low_memory_pressure ? kSmallAlloc * 3 / 2 : kBigAlloc)) {
while (extra_wanted > 0) {
Expand Down Expand Up @@ -1602,7 +1603,8 @@ 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(sending_length);
grpc_core::global_stats().IncrementTcpWriteSize(
static_cast<int>(sending_length));
grpc_core::global_stats().IncrementTcpWriteIovSize(iov_size);
sent_length = tcp_send(tcp->fd, &msg, &saved_errno, MSG_ZEROCOPY);
}
Expand Down Expand Up @@ -1715,7 +1717,8 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error_handle* error) {
msg.msg_control = nullptr;
msg.msg_controllen = 0;

grpc_core::global_stats().IncrementTcpWriteSize(sending_length);
grpc_core::global_stats().IncrementTcpWriteSize(
static_cast<int>(sending_length));
grpc_core::global_stats().IncrementTcpWriteIovSize(iov_size);

sent_length = tcp_send(tcp->fd, &msg, &saved_errno);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
int read_ret =
ssize_t read_ret =
read(file_descriptor, bundle_string + bytes_read, cert_file_size);
if (read_ret != -1) {
bytes_read += read_ret;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/slice/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct CopyConstructors {

static Out FromInt64(int64_t i) {
char buffer[GPR_LTOA_MIN_BUFSIZE];
gpr_ltoa(i, buffer);
int64_ttoa(i, buffer);
return FromCopiedString(buffer);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/slice/slice_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 absl::HashOf(grpc_core::StringViewFromSlice(s));
return static_cast<uint32_t>(absl::HashOf(grpc_core::StringViewFromSlice(s)));
}

namespace grpc_core {
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/surface/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(initial_size);
global_stats().IncrementCallInitialSize(static_cast<int>(initial_size));
size_t call_alloc_size =
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(FilterStackCall)) +
channel_stack->call_stack_size;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/surface/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Channel : public RefCounted<Channel>,
bool is_promising() const { return is_promising_; }
RegisteredCall* RegisterCall(const char* method, const char* host);

int TestOnlyRegisteredCalls() {
size_t TestOnlyRegisteredCalls() {
MutexLock lock(&registration_table_.mu);
return registration_table_.map.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
protector->parsed_frame_size - protector->protected_sb.length;
*min_progress_size = static_cast<int>(protector->parsed_frame_size -
protector->protected_sb.length);
} else {
*min_progress_size = 1;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/tsi/fake_transport_security.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ 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 = impl->parsed_frame_size - impl->protected_sb.length;
*min_progress_size =
static_cast<int>(impl->parsed_frame_size - impl->protected_sb.length);
} else {
*min_progress_size = 1;
}
Expand Down
4 changes: 3 additions & 1 deletion src/cpp/client/channel_test_peer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#include <stddef.h>

#include <grpcpp/channel.h>
#include <grpcpp/test/channel_test_peer.h>

Expand All @@ -24,7 +26,7 @@
namespace grpc {
namespace testing {

int ChannelTestPeer::registered_calls() const {
size_t ChannelTestPeer::registered_calls() const {
return grpc_core::Channel::FromC(channel_->c_channel_)
->TestOnlyRegisteredCalls();
}
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/end2end/end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ TEST_P(End2endTest, MultipleRpcs) {
TEST_P(End2endTest, ManyStubs) {
ResetStub();
ChannelTestPeer peer(channel_.get());
int registered_calls_pre = peer.registered_calls();
size_t 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_);
Expand Down

0 comments on commit eb0a591

Please sign in to comment.