From d4d0a30c6f569e031d0bfaa31f0410b855f362a3 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 25 Jan 2018 13:24:03 -0800 Subject: Privatize useful.h and avl.h --- test/core/end2end/tests/large_metadata.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'test/core/end2end/tests/large_metadata.cc') diff --git a/test/core/end2end/tests/large_metadata.cc b/test/core/end2end/tests/large_metadata.cc index 8ddf433ac0..c1343f902d 100644 --- a/test/core/end2end/tests/large_metadata.cc +++ b/test/core/end2end/tests/large_metadata.cc @@ -25,7 +25,6 @@ #include #include #include -#include #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } -- cgit v1.2.3 From be82e64b3debcdb1d9ec6a149fc85af0d46bfb7e Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Fri, 9 Feb 2018 09:16:55 -0800 Subject: Autofix c casts to c++ casts --- src/core/ext/census/grpc_context.cc | 2 +- .../ext/filters/client_channel/backup_poller.cc | 8 +- .../filters/client_channel/channel_connectivity.cc | 12 +- .../ext/filters/client_channel/client_channel.cc | 148 ++++++++-------- .../client_channel/client_channel_factory.cc | 4 +- .../client_channel/client_channel_plugin.cc | 2 +- .../client_channel/http_connect_handshaker.cc | 16 +- .../grpclb/client_load_reporting_filter.cc | 14 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 95 +++++----- .../lb_policy/grpclb/grpclb_client_stats.cc | 12 +- .../lb_policy/grpclb/load_balancer_api.cc | 43 +++-- .../lb_policy/pick_first/pick_first.cc | 32 ++-- .../lb_policy/round_robin/round_robin.cc | 48 +++--- .../client_channel/lb_policy/subchannel_list.cc | 18 +- .../filters/client_channel/lb_policy_factory.cc | 14 +- .../ext/filters/client_channel/parse_address.cc | 14 +- .../client_channel/proxy_mapper_registry.cc | 4 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 2 +- .../dns/c_ares/grpc_ares_ev_driver_posix.cc | 8 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 44 ++--- .../ext/filters/client_channel/retry_throttle.cc | 34 ++-- src/core/ext/filters/client_channel/subchannel.cc | 36 ++-- .../ext/filters/client_channel/subchannel_index.cc | 24 +-- src/core/ext/filters/client_channel/uri_parser.cc | 6 +- src/core/ext/filters/deadline/deadline_filter.cc | 36 ++-- .../ext/filters/http/client/http_client_filter.cc | 42 ++--- src/core/ext/filters/http/http_filters_plugin.cc | 4 +- .../message_compress/message_compress_filter.cc | 40 ++--- .../ext/filters/http/server/http_server_filter.cc | 28 +-- .../load_reporting/server_load_reporting_filter.cc | 16 +- .../load_reporting/server_load_reporting_plugin.cc | 2 +- src/core/ext/filters/max_age/max_age_filter.cc | 26 +-- .../filters/message_size/message_size_filter.cc | 30 ++-- .../workaround_cronet_compression_filter.cc | 8 +- .../ext/filters/workarounds/workaround_utils.cc | 8 +- .../transport/chttp2/client/chttp2_connector.cc | 20 +-- .../chttp2/client/secure/secure_channel_create.cc | 6 +- .../ext/transport/chttp2/server/chttp2_server.cc | 24 +-- .../ext/transport/chttp2/transport/bin_decoder.cc | 12 +- .../ext/transport/chttp2/transport/bin_encoder.cc | 28 +-- .../transport/chttp2/transport/chttp2_transport.cc | 192 ++++++++++----------- .../ext/transport/chttp2/transport/flow_control.cc | 24 +-- .../ext/transport/chttp2/transport/flow_control.h | 4 +- .../ext/transport/chttp2/transport/frame_data.cc | 44 ++--- .../ext/transport/chttp2/transport/frame_goaway.cc | 50 +++--- .../ext/transport/chttp2/transport/frame_ping.cc | 24 +-- .../transport/chttp2/transport/frame_rst_stream.cc | 30 ++-- .../transport/chttp2/transport/frame_settings.cc | 34 ++-- .../chttp2/transport/frame_window_update.cc | 22 +-- .../transport/chttp2/transport/hpack_encoder.cc | 34 ++-- .../ext/transport/chttp2/transport/hpack_parser.cc | 56 +++--- .../ext/transport/chttp2/transport/hpack_table.cc | 12 +- .../transport/chttp2/transport/http2_settings.cc | 2 +- .../chttp2/transport/incoming_metadata.cc | 4 +- src/core/ext/transport/chttp2/transport/parsing.cc | 44 ++--- .../ext/transport/chttp2/transport/stream_map.cc | 10 +- src/core/ext/transport/chttp2/transport/varint.cc | 10 +- src/core/ext/transport/chttp2/transport/writing.cc | 16 +- .../transport/cronet/transport/cronet_transport.cc | 84 ++++----- src/core/ext/transport/inproc/inproc_transport.cc | 40 ++--- src/core/lib/avl/avl.cc | 2 +- src/core/lib/backoff/backoff.cc | 6 +- src/core/lib/channel/channel_args.cc | 20 +-- src/core/lib/channel/channel_stack.cc | 10 +- src/core/lib/channel/channel_stack_builder.cc | 12 +- src/core/lib/channel/connected_channel.cc | 34 ++-- src/core/lib/channel/handshaker.cc | 12 +- src/core/lib/channel/handshaker_registry.cc | 4 +- src/core/lib/compression/compression_internal.cc | 2 +- src/core/lib/compression/message_compress.cc | 8 +- .../lib/compression/stream_compression_gzip.cc | 16 +- .../lib/compression/stream_compression_identity.cc | 2 +- src/core/lib/debug/stats.cc | 12 +- src/core/lib/debug/trace.cc | 6 +- src/core/lib/gpr/alloc.cc | 2 +- src/core/lib/gpr/arena.cc | 20 +-- src/core/lib/gpr/cpu_linux.cc | 6 +- src/core/lib/gpr/host_port.cc | 6 +- src/core/lib/gpr/log.cc | 8 +- src/core/lib/gpr/log_linux.cc | 2 +- src/core/lib/gpr/murmur_hash.cc | 8 +- src/core/lib/gpr/string.cc | 30 ++-- src/core/lib/gpr/string_posix.cc | 6 +- src/core/lib/gpr/sync_posix.cc | 2 +- src/core/lib/gpr/thd_posix.cc | 10 +- src/core/lib/gpr/time.cc | 6 +- src/core/lib/gpr/time_posix.cc | 4 +- src/core/lib/http/format_request.cc | 4 +- src/core/lib/http/httpcli.cc | 12 +- src/core/lib/http/httpcli_security_connector.cc | 20 +-- src/core/lib/http/parser.cc | 22 +-- src/core/lib/iomgr/call_combiner.cc | 14 +- src/core/lib/iomgr/closure.h | 4 +- src/core/lib/iomgr/combiner.cc | 8 +- src/core/lib/iomgr/error.cc | 66 +++---- src/core/lib/iomgr/ev_epoll1_linux.cc | 20 +-- src/core/lib/iomgr/ev_epollex_linux.cc | 34 ++-- src/core/lib/iomgr/ev_epollsig_linux.cc | 22 +-- src/core/lib/iomgr/ev_poll_posix.cc | 52 +++--- src/core/lib/iomgr/ev_posix.cc | 6 +- src/core/lib/iomgr/exec_ctx.cc | 12 +- src/core/lib/iomgr/executor.cc | 18 +- src/core/lib/iomgr/gethostname_host_name_max.cc | 2 +- src/core/lib/iomgr/is_epollexclusive_available.cc | 2 +- src/core/lib/iomgr/load_file.cc | 4 +- src/core/lib/iomgr/resolve_address_posix.cc | 10 +- src/core/lib/iomgr/resource_quota.cc | 64 +++---- src/core/lib/iomgr/sockaddr_utils.cc | 44 ++--- src/core/lib/iomgr/socket_factory_posix.cc | 8 +- src/core/lib/iomgr/socket_mutator.cc | 8 +- src/core/lib/iomgr/socket_utils_common_posix.cc | 6 +- src/core/lib/iomgr/socket_utils_linux.cc | 4 +- src/core/lib/iomgr/tcp_client_posix.cc | 10 +- src/core/lib/iomgr/tcp_posix.cc | 74 ++++---- src/core/lib/iomgr/tcp_server_posix.cc | 18 +- .../lib/iomgr/tcp_server_utils_posix_common.cc | 10 +- .../lib/iomgr/tcp_server_utils_posix_ifaddrs.cc | 4 +- src/core/lib/iomgr/timer_generic.cc | 20 +-- src/core/lib/iomgr/timer_heap.cc | 12 +- src/core/lib/iomgr/timer_manager.cc | 4 +- src/core/lib/iomgr/udp_server.cc | 30 ++-- src/core/lib/iomgr/unix_sockets_posix.cc | 14 +- src/core/lib/iomgr/wakeup_fd_cv.cc | 6 +- src/core/lib/json/json.cc | 2 +- src/core/lib/json/json_reader.cc | 12 +- src/core/lib/json/json_string.cc | 36 ++-- src/core/lib/json/json_writer.cc | 16 +- src/core/lib/security/context/security_context.cc | 26 +-- .../credentials/composite/composite_credentials.cc | 28 +-- src/core/lib/security/credentials/credentials.cc | 16 +- .../security/credentials/credentials_metadata.cc | 2 +- .../security/credentials/fake/fake_credentials.cc | 12 +- .../google_default/google_default_credentials.cc | 8 +- .../security/credentials/iam/iam_credentials.cc | 6 +- .../lib/security/credentials/jwt/json_token.cc | 6 +- .../security/credentials/jwt/jwt_credentials.cc | 14 +- .../lib/security/credentials/jwt/jwt_verifier.cc | 32 ++-- .../credentials/oauth2/oauth2_credentials.cc | 36 ++-- .../credentials/plugin/plugin_credentials.cc | 14 +- .../security/credentials/ssl/ssl_credentials.cc | 40 ++--- .../lib/security/transport/client_auth_filter.cc | 56 +++--- src/core/lib/security/transport/lb_targets_info.cc | 10 +- src/core/lib/security/transport/secure_endpoint.cc | 34 ++-- .../lib/security/transport/security_connector.cc | 76 ++++---- .../lib/security/transport/security_handshaker.cc | 32 ++-- .../lib/security/transport/server_auth_filter.cc | 42 ++--- src/core/lib/slice/b64.cc | 30 ++-- src/core/lib/slice/percent_encoding.cc | 10 +- src/core/lib/slice/slice.cc | 64 +++---- src/core/lib/slice/slice_buffer.cc | 22 +-- src/core/lib/slice/slice_hash_table.cc | 4 +- src/core/lib/slice/slice_intern.cc | 30 ++-- src/core/lib/slice/slice_string_helpers.cc | 4 +- src/core/lib/surface/byte_buffer.cc | 4 +- src/core/lib/surface/call.cc | 78 ++++----- src/core/lib/surface/channel.cc | 24 +-- src/core/lib/surface/channel_init.cc | 10 +- src/core/lib/surface/channel_ping.cc | 4 +- src/core/lib/surface/completion_queue.cc | 92 +++++----- src/core/lib/surface/init.cc | 4 +- src/core/lib/surface/server.cc | 104 +++++------ src/core/lib/transport/bdp_estimator.cc | 6 +- src/core/lib/transport/byte_stream.cc | 18 +- src/core/lib/transport/connectivity_state.cc | 10 +- src/core/lib/transport/error_utils.cc | 12 +- src/core/lib/transport/metadata.cc | 26 +-- src/core/lib/transport/service_config.cc | 10 +- src/core/lib/transport/static_metadata.cc | 4 +- src/core/lib/transport/timeout_encoding.cc | 4 +- src/core/lib/transport/transport.cc | 10 +- src/core/tsi/fake_transport_security.cc | 82 ++++----- src/core/tsi/ssl_transport_security.cc | 144 ++++++++-------- src/core/tsi/transport_security.cc | 6 +- src/core/tsi/transport_security_adapter.cc | 20 +-- src/cpp/common/channel_filter.cc | 2 +- src/cpp/common/channel_filter.h | 2 +- src/cpp/util/time_cc.cc | 8 +- test/core/avl/avl_test.cc | 12 +- test/core/backoff/backoff_test.cc | 10 +- test/core/bad_client/bad_client.cc | 8 +- test/core/bad_client/tests/duplicate_header.cc | 4 +- .../core/bad_client/tests/head_of_line_blocking.cc | 6 +- test/core/bad_client/tests/window_overflow.cc | 6 +- test/core/bad_ssl/bad_ssl_test.cc | 4 +- test/core/bad_ssl/servers/cert.cc | 4 +- test/core/channel/channel_args_test.cc | 10 +- test/core/channel/channel_stack_builder_test.cc | 2 +- test/core/channel/channel_stack_test.cc | 16 +- test/core/client_channel/parse_address_test.cc | 6 +- .../resolvers/dns_resolver_connectivity_test.cc | 2 +- test/core/compression/stream_compression_test.cc | 6 +- test/core/end2end/bad_server_response_test.cc | 8 +- test/core/end2end/cq_verifier.cc | 4 +- test/core/end2end/dualstack_socket_test.cc | 6 +- test/core/end2end/fixtures/h2_oauth2.cc | 6 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 28 +-- test/core/end2end/fixtures/proxy.cc | 36 ++-- test/core/end2end/fuzzers/api_fuzzer.cc | 10 +- test/core/end2end/fuzzers/client_fuzzer.cc | 2 +- test/core/end2end/fuzzers/server_fuzzer.cc | 4 +- test/core/end2end/goaway_server_test.cc | 6 +- test/core/end2end/h2_ssl_cert_test.cc | 2 +- test/core/end2end/invalid_call_argument_test.cc | 4 +- test/core/end2end/tests/authority_not_supported.cc | 2 +- test/core/end2end/tests/bad_hostname.cc | 2 +- test/core/end2end/tests/bad_ping.cc | 4 +- test/core/end2end/tests/binary_metadata.cc | 6 +- test/core/end2end/tests/call_creds.cc | 8 +- test/core/end2end/tests/cancel_after_accept.cc | 4 +- .../core/end2end/tests/cancel_after_client_done.cc | 4 +- test/core/end2end/tests/cancel_after_round_trip.cc | 8 +- test/core/end2end/tests/compressed_payload.cc | 24 +-- test/core/end2end/tests/connectivity.cc | 2 +- test/core/end2end/tests/default_host.cc | 4 +- test/core/end2end/tests/disappearing_server.cc | 4 +- test/core/end2end/tests/filter_call_init_fails.cc | 8 +- test/core/end2end/tests/filter_causes_close.cc | 8 +- test/core/end2end/tests/filter_latency.cc | 6 +- test/core/end2end/tests/filter_status_code.cc | 12 +- .../core/end2end/tests/graceful_server_shutdown.cc | 4 +- test/core/end2end/tests/high_initial_seqno.cc | 4 +- test/core/end2end/tests/hpack_size.cc | 4 +- test/core/end2end/tests/idempotent_request.cc | 4 +- test/core/end2end/tests/invoke_large_request.cc | 6 +- test/core/end2end/tests/keepalive_timeout.cc | 6 +- test/core/end2end/tests/large_metadata.cc | 8 +- test/core/end2end/tests/load_reporting_hook.cc | 6 +- test/core/end2end/tests/max_concurrent_streams.cc | 38 ++-- test/core/end2end/tests/max_connection_age.cc | 10 +- test/core/end2end/tests/max_connection_idle.cc | 4 +- test/core/end2end/tests/max_message_length.cc | 8 +- test/core/end2end/tests/network_status_change.cc | 6 +- test/core/end2end/tests/no_logging.cc | 4 +- test/core/end2end/tests/payload.cc | 10 +- test/core/end2end/tests/ping_pong_streaming.cc | 14 +- test/core/end2end/tests/proxy_auth.cc | 4 +- test/core/end2end/tests/registered_call.cc | 4 +- test/core/end2end/tests/request_with_flags.cc | 2 +- test/core/end2end/tests/request_with_payload.cc | 6 +- test/core/end2end/tests/resource_quota_server.cc | 34 ++-- test/core/end2end/tests/server_finishes_request.cc | 4 +- test/core/end2end/tests/shutdown_finishes_calls.cc | 4 +- test/core/end2end/tests/shutdown_finishes_tags.cc | 2 +- .../core/end2end/tests/simple_cacheable_request.cc | 6 +- test/core/end2end/tests/simple_delayed_request.cc | 4 +- test/core/end2end/tests/simple_metadata.cc | 6 +- test/core/end2end/tests/simple_request.cc | 4 +- .../tests/stream_compression_compressed_payload.cc | 24 +-- .../end2end/tests/stream_compression_payload.cc | 10 +- .../stream_compression_ping_pong_streaming.cc | 14 +- .../core/end2end/tests/streaming_error_response.cc | 12 +- test/core/end2end/tests/trailing_metadata.cc | 6 +- .../end2end/tests/workaround_cronet_compression.cc | 14 +- test/core/end2end/tests/write_buffering.cc | 18 +- test/core/end2end/tests/write_buffering_at_end.cc | 18 +- test/core/fling/client.cc | 4 +- test/core/fling/fling_stream_test.cc | 2 +- test/core/fling/fling_test.cc | 2 +- test/core/fling/server.cc | 4 +- test/core/gpr/alloc_test.cc | 2 +- test/core/gpr/arena_test.cc | 2 +- test/core/gpr/cpu_test.cc | 4 +- test/core/gpr/mpscq_test.cc | 6 +- test/core/gpr/murmur_hash_test.cc | 4 +- test/core/gpr/spinlock_test.cc | 12 +- test/core/gpr/sync_test.cc | 10 +- test/core/gpr/time_test.cc | 2 +- test/core/handshake/client_ssl.cc | 22 +-- .../handshake/readahead_handshaker_server_ssl.cc | 2 +- test/core/handshake/server_ssl_common.cc | 18 +- test/core/http/httpcli_test.cc | 6 +- test/core/http/httpscli_test.cc | 6 +- test/core/iomgr/endpoint_pair_test.cc | 2 +- test/core/iomgr/endpoint_tests.cc | 8 +- test/core/iomgr/ev_epollsig_linux_test.cc | 2 +- test/core/iomgr/fd_posix_test.cc | 6 +- test/core/iomgr/pollset_set_test.cc | 2 +- test/core/iomgr/resource_quota_test.cc | 4 +- test/core/iomgr/sockaddr_utils_test.cc | 16 +- test/core/iomgr/socket_utils_test.cc | 10 +- test/core/iomgr/tcp_client_posix_test.cc | 6 +- test/core/iomgr/tcp_posix_test.cc | 36 ++-- test/core/iomgr/tcp_server_posix_test.cc | 16 +- test/core/iomgr/timer_heap_test.cc | 10 +- test/core/iomgr/udp_server_test.cc | 18 +- test/core/iomgr/wakeup_fd_cv_test.cc | 2 +- test/core/json/json_rewrite.cc | 4 +- test/core/json/json_rewrite_test.cc | 4 +- test/core/memory_usage/client.cc | 16 +- test/core/memory_usage/memory_usage_test.cc | 2 +- test/core/memory_usage/server.cc | 12 +- .../core/network_benchmarks/low_level_ping_pong.cc | 18 +- test/core/security/create_jwt.cc | 2 +- test/core/security/credentials_test.cc | 25 ++- test/core/security/fetch_oauth2.cc | 2 +- test/core/security/json_token_test.cc | 10 +- test/core/security/jwt_verifier_test.cc | 10 +- test/core/security/oauth2_utils.cc | 6 +- .../security/print_google_default_creds_token.cc | 4 +- test/core/security/secure_endpoint_test.cc | 12 +- test/core/security/verify_jwt.cc | 2 +- test/core/slice/b64_test.cc | 6 +- test/core/slice/percent_encode_fuzzer.cc | 2 +- test/core/slice/slice_test.cc | 10 +- .../surface/completion_queue_threading_test.cc | 18 +- test/core/surface/concurrent_connectivity_test.cc | 16 +- test/core/surface/lame_client_test.cc | 4 +- test/core/transport/chttp2/hpack_encoder_test.cc | 4 +- .../core/transport/chttp2/settings_timeout_test.cc | 6 +- test/core/transport/chttp2/stream_map_test.cc | 8 +- test/core/transport/metadata_test.cc | 6 +- test/core/transport/timeout_encoding_test.cc | 12 +- test/core/tsi/fake_transport_security_test.cc | 4 +- test/core/tsi/ssl_transport_security_test.cc | 32 ++-- test/core/tsi/transport_security_test_lib.cc | 8 +- test/core/util/cmdline.cc | 20 +-- test/core/util/debugger_macros.cc | 2 +- test/core/util/histogram.cc | 14 +- test/core/util/memory_counters.cc | 8 +- test/core/util/mock_endpoint.cc | 14 +- test/core/util/parse_hexstring.cc | 4 +- test/core/util/passthru_endpoint.cc | 20 +-- test/core/util/port.cc | 2 +- test/core/util/port_server_client.cc | 12 +- test/core/util/reconnect_server.cc | 4 +- test/core/util/slice_splitter.cc | 8 +- test/core/util/subprocess_posix.cc | 6 +- test/core/util/test_config.cc | 8 +- test/core/util/test_tcp_server.cc | 4 +- test/core/util/trickle_endpoint.cc | 32 ++-- test/cpp/codegen/proto_utils_test.cc | 4 +- test/cpp/common/alarm_test.cc | 20 +-- test/cpp/end2end/async_end2end_test.cc | 2 +- test/cpp/end2end/end2end_test.cc | 2 +- test/cpp/end2end/filter_end2end_test.cc | 2 +- test/cpp/end2end/generic_end2end_test.cc | 2 +- test/cpp/end2end/hybrid_end2end_test.cc | 2 +- test/cpp/end2end/thread_stress_test.cc | 2 +- test/cpp/grpclb/grpclb_test.cc | 22 +-- test/cpp/interop/interop_client.cc | 4 +- test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 6 +- test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 4 +- .../microbenchmarks/fullstack_context_mutators.h | 4 +- test/cpp/microbenchmarks/fullstack_fixtures.h | 4 +- .../fullstack_streaming_ping_pong.h | 24 +-- .../cpp/microbenchmarks/fullstack_streaming_pump.h | 10 +- .../microbenchmarks/fullstack_unary_ping_pong.h | 2 +- test/cpp/microbenchmarks/helpers.cc | 6 +- test/cpp/performance/writes_per_rpc_test.cc | 4 +- test/cpp/qps/report.cc | 6 +- test/cpp/qps/server.h | 2 +- test/cpp/util/cli_call.cc | 2 +- .../util/proto_reflection_descriptor_database.cc | 2 +- 353 files changed, 2743 insertions(+), 2748 deletions(-) (limited to 'test/core/end2end/tests/large_metadata.cc') diff --git a/src/core/ext/census/grpc_context.cc b/src/core/ext/census/grpc_context.cc index ffe7c51ff8..5cd3b18614 100644 --- a/src/core/ext/census/grpc_context.cc +++ b/src/core/ext/census/grpc_context.cc @@ -31,5 +31,5 @@ void grpc_census_call_set_context(grpc_call* call, census_context* context) { census_context* grpc_census_call_get_context(grpc_call* call) { GRPC_API_TRACE("grpc_census_call_get_context(call=%p)", 1, (call)); - return (census_context*)grpc_call_context_get(call, GRPC_CONTEXT_TRACING); + return static_cast(grpc_call_context_get(call, GRPC_CONTEXT_TRACING)); } diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index 906a72b662..35f1b97b77 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -80,7 +80,7 @@ static void backup_poller_shutdown_unref(backup_poller* p) { } static void done_poller(void* arg, grpc_error* error) { - backup_poller_shutdown_unref((backup_poller*)arg); + backup_poller_shutdown_unref(static_cast(arg)); } static void g_poller_unref() { @@ -102,7 +102,7 @@ static void g_poller_unref() { } static void run_poller(void* arg, grpc_error* error) { - backup_poller* p = (backup_poller*)arg; + backup_poller* p = static_cast(arg); if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("run_poller", GRPC_ERROR_REF(error)); @@ -133,8 +133,8 @@ void grpc_client_channel_start_backup_polling( } gpr_mu_lock(&g_poller_mu); if (g_poller == nullptr) { - g_poller = (backup_poller*)gpr_zalloc(sizeof(backup_poller)); - g_poller->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + g_poller = static_cast(gpr_zalloc(sizeof(backup_poller))); + g_poller->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); g_poller->shutting_down = false; grpc_pollset_init(g_poller->pollset, &g_poller->pollset_mu); gpr_ref_init(&g_poller->refs, 0); diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index a827aa30ec..74c6cfe93c 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -89,7 +89,7 @@ static void delete_state_watcher(state_watcher* w) { static void finished_completion(void* pw, grpc_cq_completion* ignored) { bool should_delete = false; - state_watcher* w = (state_watcher*)pw; + state_watcher* w = static_cast(pw); gpr_mu_lock(&w->mu); switch (w->phase) { case WAITING: @@ -162,11 +162,11 @@ static void partly_done(state_watcher* w, bool due_to_completion, } static void watch_complete(void* pw, grpc_error* error) { - partly_done((state_watcher*)pw, true, GRPC_ERROR_REF(error)); + partly_done(static_cast(pw), true, GRPC_ERROR_REF(error)); } static void timeout_complete(void* pw, grpc_error* error) { - partly_done((state_watcher*)pw, false, GRPC_ERROR_REF(error)); + partly_done(static_cast(pw), false, GRPC_ERROR_REF(error)); } int grpc_channel_num_external_connectivity_watchers(grpc_channel* channel) { @@ -182,7 +182,7 @@ typedef struct watcher_timer_init_arg { } watcher_timer_init_arg; static void watcher_timer_init(void* arg, grpc_error* error_ignored) { - watcher_timer_init_arg* wa = (watcher_timer_init_arg*)arg; + watcher_timer_init_arg* wa = static_cast(arg); grpc_timer_init(&wa->w->alarm, grpc_timespec_to_millis_round_up(wa->deadline), &wa->w->on_timeout); @@ -201,7 +201,7 @@ void grpc_channel_watch_connectivity_state( grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); grpc_core::ExecCtx exec_ctx; - state_watcher* w = (state_watcher*)gpr_malloc(sizeof(*w)); + state_watcher* w = static_cast(gpr_malloc(sizeof(*w))); GRPC_API_TRACE( "grpc_channel_watch_connectivity_state(" @@ -228,7 +228,7 @@ void grpc_channel_watch_connectivity_state( w->error = nullptr; watcher_timer_init_arg* wa = - (watcher_timer_init_arg*)gpr_malloc(sizeof(watcher_timer_init_arg)); + static_cast(gpr_malloc(sizeof(watcher_timer_init_arg))); wa->w = w; wa->deadline = deadline; GRPC_CLOSURE_INIT(&w->watcher_timer_init, watcher_timer_init, wa, diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index cbee74c22d..ee2f21a064 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -88,10 +88,10 @@ static void method_parameters_unref(method_parameters* method_params) { // Wrappers to pass to grpc_service_config_create_method_config_table(). static void* method_parameters_ref_wrapper(void* value) { - return method_parameters_ref((method_parameters*)value); + return method_parameters_ref(static_cast(value)); } static void method_parameters_unref_wrapper(void* value) { - method_parameters_unref((method_parameters*)value); + method_parameters_unref(static_cast(value)); } static bool parse_wait_for_ready(grpc_json* field, @@ -119,7 +119,7 @@ static bool parse_timeout(grpc_json* field, grpc_millis* timeout) { gpr_free(buf); return false; } - int num_digits = (int)strlen(decimal_point + 1); + int num_digits = static_cast(strlen(decimal_point + 1)); if (num_digits > 9) { // We don't accept greater precision than nanos. gpr_free(buf); return false; @@ -149,7 +149,7 @@ static void* method_parameters_create_from_json(const grpc_json* json) { } } method_parameters* value = - (method_parameters*)gpr_malloc(sizeof(method_parameters)); + static_cast(gpr_malloc(sizeof(method_parameters))); gpr_ref_init(&value->refs, 1); value->timeout = timeout; value->wait_for_ready = wait_for_ready; @@ -260,7 +260,7 @@ static void set_channel_connectivity_state_locked(channel_data* chand, } static void on_lb_policy_state_changed_locked(void* arg, grpc_error* error) { - lb_policy_connectivity_watcher* w = (lb_policy_connectivity_watcher*)arg; + lb_policy_connectivity_watcher* w = static_cast(arg); /* check if the notification is for the latest policy */ if (w->lb_policy == w->chand->lb_policy) { if (grpc_client_channel_trace.enabled()) { @@ -281,7 +281,7 @@ static void watch_lb_policy_locked(channel_data* chand, grpc_lb_policy* lb_policy, grpc_connectivity_state current_state) { lb_policy_connectivity_watcher* w = - (lb_policy_connectivity_watcher*)gpr_malloc(sizeof(*w)); + static_cast(gpr_malloc(sizeof(*w))); GRPC_CHANNEL_STACK_REF(chand->owning_stack, "watch_lb_policy"); w->chand = chand; GRPC_CLOSURE_INIT(&w->on_changed, on_lb_policy_state_changed_locked, w, @@ -310,7 +310,7 @@ typedef struct { static void parse_retry_throttle_params(const grpc_json* field, void* arg) { service_config_parsing_state* parsing_state = - (service_config_parsing_state*)arg; + static_cast(arg); if (strcmp(field->key, "retryThrottling") == 0) { if (parsing_state->retry_throttle_data != nullptr) return; // Duplicate. if (field->type != GRPC_JSON_OBJECT) return; @@ -334,7 +334,7 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { uint32_t decimal_value = 0; const char* decimal_point = strchr(sub_field->value, '.'); if (decimal_point != nullptr) { - whole_len = (size_t)(decimal_point - sub_field->value); + whole_len = static_cast(decimal_point - sub_field->value); multiplier = 1000; size_t decimal_len = strlen(decimal_point + 1); if (decimal_len > 3) decimal_len = 3; @@ -353,7 +353,7 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { &whole_value)) { return; } - milli_token_ratio = (int)((whole_value * multiplier) + decimal_value); + milli_token_ratio = static_cast((whole_value * multiplier) + decimal_value); if (milli_token_ratio <= 0) return; } } @@ -364,7 +364,7 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { } static void request_reresolution_locked(void* arg, grpc_error* error) { - reresolution_request_args* args = (reresolution_request_args*)arg; + reresolution_request_args* args = static_cast(arg); channel_data* chand = args->chand; // If this invocation is for a stale LB policy, treat it as an LB shutdown // signal. @@ -383,7 +383,7 @@ static void request_reresolution_locked(void* arg, grpc_error* error) { } static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: got resolver result: error=%s", chand, grpc_error_string(error)); @@ -412,7 +412,7 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES); if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_POINTER) { grpc_lb_addresses* addresses = - (grpc_lb_addresses*)channel_arg->value.pointer.p; + static_cast(channel_arg->value.pointer.p); bool found_balancer_address = false; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) { @@ -458,7 +458,7 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { lb_policy_name); } else { reresolution_request_args* args = - (reresolution_request_args*)gpr_zalloc(sizeof(*args)); + static_cast(gpr_zalloc(sizeof(*args))); args->chand = chand; args->lb_policy = new_lb_policy; GRPC_CLOSURE_INIT(&args->closure, request_reresolution_locked, args, @@ -610,10 +610,10 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { } static void start_transport_op_locked(void* arg, grpc_error* error_ignored) { - grpc_transport_op* op = (grpc_transport_op*)arg; + grpc_transport_op* op = static_cast(arg); grpc_channel_element* elem = - (grpc_channel_element*)op->handler_private.extra_arg; - channel_data* chand = (channel_data*)elem->channel_data; + static_cast(op->handler_private.extra_arg); + channel_data* chand = static_cast(elem->channel_data); if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( @@ -668,7 +668,7 @@ static void start_transport_op_locked(void* arg, grpc_error* error_ignored) { static void cc_start_transport_op(grpc_channel_element* elem, grpc_transport_op* op) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); GPR_ASSERT(op->set_accept_stream == false); if (op->bind_pollset != nullptr) { @@ -685,7 +685,7 @@ static void cc_start_transport_op(grpc_channel_element* elem, static void cc_get_channel_info(grpc_channel_element* elem, const grpc_channel_info* info) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); gpr_mu_lock(&chand->info_mu); if (info->lb_policy_name != nullptr) { *info->lb_policy_name = chand->info_lb_policy_name == nullptr @@ -704,7 +704,7 @@ static void cc_get_channel_info(grpc_channel_element* elem, /* Constructor for channel_data */ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); GPR_ASSERT(args->is_last); GPR_ASSERT(elem->filter == &grpc_client_channel_filter); // Initialize data members. @@ -736,9 +736,9 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, "client channel factory arg must be a pointer"); } grpc_client_channel_factory_ref( - (grpc_client_channel_factory*)arg->value.pointer.p); + static_cast(arg->value.pointer.p)); chand->client_channel_factory = - (grpc_client_channel_factory*)arg->value.pointer.p; + static_cast(arg->value.pointer.p); // Get server name to resolve, using proxy mapper if needed. arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); if (arg == nullptr) { @@ -775,7 +775,7 @@ static void shutdown_resolver_locked(void* arg, grpc_error* error) { /* Destructor for channel_data */ static void cc_destroy_channel_elem(grpc_channel_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); if (chand->resolver != nullptr) { GRPC_CLOSURE_SCHED( GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver.release(), @@ -867,7 +867,7 @@ typedef struct client_channel_call_data { grpc_subchannel_call* grpc_client_channel_get_subchannel_call( grpc_call_element* elem) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); return calld->subchannel_call; } @@ -886,7 +886,7 @@ static void waiting_for_pick_batches_add( // This is called via the call combiner, so access to calld is synchronized. static void fail_pending_batch_in_call_combiner(void* arg, grpc_error* error) { - call_data* calld = (call_data*)arg; + call_data* calld = static_cast(arg); if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_transport_stream_op_batch_finish_with_failure( @@ -898,7 +898,7 @@ static void fail_pending_batch_in_call_combiner(void* arg, grpc_error* error) { // This is called via the call combiner, so access to calld is synchronized. static void waiting_for_pick_batches_fail(grpc_call_element* elem, grpc_error* error) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: failing %" PRIuPTR " pending batches: %s", @@ -926,7 +926,7 @@ static void waiting_for_pick_batches_fail(grpc_call_element* elem, // This is called via the call combiner, so access to calld is synchronized. static void run_pending_batch_in_call_combiner(void* arg, grpc_error* ignored) { - call_data* calld = (call_data*)arg; + call_data* calld = static_cast(arg); if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_subchannel_call_process_op( @@ -937,8 +937,8 @@ static void run_pending_batch_in_call_combiner(void* arg, grpc_error* ignored) { // This is called via the call combiner, so access to calld is synchronized. static void waiting_for_pick_batches_resume(grpc_call_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending %" PRIuPTR @@ -962,8 +962,8 @@ static void waiting_for_pick_batches_resume(grpc_call_element* elem) { // Applies service config to the call. Must be invoked once we know // that the resolver has returned results to the channel. static void apply_service_config_to_call_locked(grpc_call_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: applying service config to call", chand, calld); @@ -973,8 +973,8 @@ static void apply_service_config_to_call_locked(grpc_call_element* elem) { grpc_server_retry_throttle_data_ref(chand->retry_throttle_data); } if (chand->method_params_table != nullptr) { - calld->method_params = (method_parameters*)grpc_method_config_table_get( - chand->method_params_table, calld->path); + calld->method_params = static_cast(grpc_method_config_table_get( + chand->method_params_table, calld->path)); if (calld->method_params != nullptr) { method_parameters_ref(calld->method_params); // If the deadline from the service config is shorter than the one @@ -995,8 +995,8 @@ static void apply_service_config_to_call_locked(grpc_call_element* elem) { static void create_subchannel_call_locked(grpc_call_element* elem, grpc_error* error) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); const grpc_core::ConnectedSubchannel::CallArgs call_args = { calld->pollent, // pollent calld->path, // path @@ -1023,8 +1023,8 @@ static void create_subchannel_call_locked(grpc_call_element* elem, // Invoked when a pick is completed, on both success or failure. static void pick_done_locked(grpc_call_element* elem, grpc_error* error) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); if (calld->pick.connected_subchannel == nullptr) { // Failed to create subchannel. GRPC_ERROR_UNREF(calld->error); @@ -1051,8 +1051,8 @@ static void pick_done_locked(grpc_call_element* elem, grpc_error* error) { // pick was done asynchronously. Removes the call's polling entity from // chand->interested_parties before invoking pick_done_locked(). static void async_pick_done_locked(grpc_call_element* elem, grpc_error* error) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); grpc_polling_entity_del_from_pollset_set(calld->pollent, chand->interested_parties); pick_done_locked(elem, error); @@ -1061,9 +1061,9 @@ static void async_pick_done_locked(grpc_call_element* elem, grpc_error* error) { // Note: This runs under the client_channel combiner, but will NOT be // holding the call combiner. static void pick_callback_cancel_locked(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); // Note: chand->lb_policy may have changed since we started our pick, // in which case we will be cancelling the pick on a policy other than // the one we started it on. However, this will just be a no-op. @@ -1081,9 +1081,9 @@ static void pick_callback_cancel_locked(void* arg, grpc_error* error) { // Callback invoked by grpc_lb_policy_pick_locked() for async picks. // Unrefs the LB policy and invokes async_pick_done_locked(). static void pick_callback_done_locked(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed asynchronously", chand, calld); @@ -1096,8 +1096,8 @@ static void pick_callback_done_locked(void* arg, grpc_error* error) { // If the pick was completed synchronously, unrefs the LB policy and // returns true. static bool pick_callback_start_locked(grpc_call_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: starting pick on lb_policy=%p", chand, calld, chand->lb_policy); @@ -1161,7 +1161,7 @@ typedef struct { // holding the call combiner. static void pick_after_resolver_result_cancel_locked(void* arg, grpc_error* error) { - pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; + pick_after_resolver_result_args* args = static_cast(arg); if (args->finished) { gpr_free(args); return; @@ -1175,8 +1175,8 @@ static void pick_after_resolver_result_cancel_locked(void* arg, // async_pick_done_locked() to propagate the error back to the caller. args->finished = true; grpc_call_element* elem = args->elem; - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick waiting for resolver result", @@ -1195,7 +1195,7 @@ static void pick_after_resolver_result_start_locked(grpc_call_element* elem); static void pick_after_resolver_result_done_locked(void* arg, grpc_error* error) { - pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; + pick_after_resolver_result_args* args = static_cast(arg); if (args->finished) { /* cancelled, do nothing */ if (grpc_client_channel_trace.enabled()) { @@ -1206,8 +1206,8 @@ static void pick_after_resolver_result_done_locked(void* arg, } args->finished = true; grpc_call_element* elem = args->elem; - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); if (error != GRPC_ERROR_NONE) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver failed to return data", @@ -1255,15 +1255,15 @@ static void pick_after_resolver_result_done_locked(void* arg, } static void pick_after_resolver_result_start_locked(grpc_call_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: deferring pick pending resolver result", chand, calld); } pick_after_resolver_result_args* args = - (pick_after_resolver_result_args*)gpr_zalloc(sizeof(*args)); + static_cast(gpr_zalloc(sizeof(*args))); args->elem = elem; GRPC_CLOSURE_INIT(&args->closure, pick_after_resolver_result_done_locked, args, grpc_combiner_scheduler(chand->combiner)); @@ -1277,9 +1277,9 @@ static void pick_after_resolver_result_start_locked(grpc_call_element* elem) { } static void start_pick_locked(void* arg, grpc_error* ignored) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); GPR_ASSERT(calld->pick.connected_subchannel == nullptr); if (chand->lb_policy != nullptr) { // We already have an LB policy, so ask it for a pick. @@ -1310,8 +1310,8 @@ static void start_pick_locked(void* arg, grpc_error* ignored) { } static void on_complete(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); if (calld->retry_throttle_data != nullptr) { if (error == GRPC_ERROR_NONE) { grpc_server_retry_throttle_data_record_success( @@ -1331,8 +1331,8 @@ static void on_complete(void* arg, grpc_error* error) { static void cc_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { GPR_TIMER_SCOPE("cc_start_transport_stream_op_batch", 0); - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); if (chand->deadline_checking_enabled) { grpc_deadline_state_client_start_transport_stream_op_batch(elem, batch); } @@ -1419,8 +1419,8 @@ static void cc_start_transport_stream_op_batch( /* Constructor for call_data */ static grpc_error* cc_init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); // Initialize data members. calld->path = grpc_slice_ref_internal(args->path); calld->call_start_time = args->start_time; @@ -1439,8 +1439,8 @@ static grpc_error* cc_init_call_elem(grpc_call_element* elem, static void cc_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); if (chand->deadline_checking_enabled) { grpc_deadline_state_destroy(elem); } @@ -1471,7 +1471,7 @@ static void cc_destroy_call_elem(grpc_call_element* elem, static void cc_set_pollset_or_pollset_set(grpc_call_element* elem, grpc_polling_entity* pollent) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); calld->pollent = pollent; } @@ -1494,7 +1494,7 @@ const grpc_channel_filter grpc_client_channel_filter = { }; static void try_to_connect_locked(void* arg, grpc_error* error_ignored) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); if (chand->lb_policy != nullptr) { grpc_lb_policy_exit_idle_locked(chand->lb_policy); } else { @@ -1508,7 +1508,7 @@ static void try_to_connect_locked(void* arg, grpc_error* error_ignored) { grpc_connectivity_state grpc_client_channel_check_connectivity_state( grpc_channel_element* elem, int try_to_connect) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); grpc_connectivity_state out = grpc_connectivity_state_check(&chand->state_tracker); if (out == GRPC_CHANNEL_IDLE && try_to_connect) { @@ -1579,7 +1579,7 @@ static void external_connectivity_watcher_list_remove( int grpc_client_channel_num_external_connectivity_watchers( grpc_channel_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); int count = 0; gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); @@ -1595,7 +1595,7 @@ int grpc_client_channel_num_external_connectivity_watchers( } static void on_external_watch_complete_locked(void* arg, grpc_error* error) { - external_connectivity_watcher* w = (external_connectivity_watcher*)arg; + external_connectivity_watcher* w = static_cast(arg); grpc_closure* follow_up = w->on_complete; grpc_polling_entity_del_from_pollset_set(&w->pollent, w->chand->interested_parties); @@ -1608,7 +1608,7 @@ static void on_external_watch_complete_locked(void* arg, grpc_error* error) { static void watch_connectivity_state_locked(void* arg, grpc_error* error_ignored) { - external_connectivity_watcher* w = (external_connectivity_watcher*)arg; + external_connectivity_watcher* w = static_cast(arg); external_connectivity_watcher* found = nullptr; if (w->state != nullptr) { external_connectivity_watcher_list_append(w->chand, w); @@ -1637,9 +1637,9 @@ void grpc_client_channel_watch_connectivity_state( grpc_channel_element* elem, grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* closure, grpc_closure* watcher_timer_init) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); external_connectivity_watcher* w = - (external_connectivity_watcher*)gpr_zalloc(sizeof(*w)); + static_cast(gpr_zalloc(sizeof(*w))); w->chand = chand; w->pollent = pollent; w->on_complete = closure; diff --git a/src/core/ext/filters/client_channel/client_channel_factory.cc b/src/core/ext/filters/client_channel/client_channel_factory.cc index 60c95d7dc9..a21db1ff69 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.cc +++ b/src/core/ext/filters/client_channel/client_channel_factory.cc @@ -39,12 +39,12 @@ grpc_channel* grpc_client_channel_factory_create_channel( } static void* factory_arg_copy(void* factory) { - grpc_client_channel_factory_ref((grpc_client_channel_factory*)factory); + grpc_client_channel_factory_ref(static_cast(factory)); return factory; } static void factory_arg_destroy(void* factory) { - grpc_client_channel_factory_unref((grpc_client_channel_factory*)factory); + grpc_client_channel_factory_unref(static_cast(factory)); } static int factory_arg_cmp(void* factory1, void* factory2) { 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 d756d9cc05..9172fa781c 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -36,7 +36,7 @@ static bool append_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter*)arg, nullptr, nullptr); + builder, static_cast(arg), nullptr, nullptr); } static bool set_default_host_if_unset(grpc_channel_stack_builder* builder, 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 6bfd038887..b4684a81dc 100644 --- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc +++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc @@ -119,7 +119,7 @@ static void handshake_failed_locked(http_connect_handshaker* handshaker, // Callback invoked when finished writing HTTP CONNECT request. static void on_write_done(void* arg, grpc_error* error) { - http_connect_handshaker* handshaker = (http_connect_handshaker*)arg; + http_connect_handshaker* handshaker = static_cast(arg); gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the write failed or we're shutting down, clean up and invoke the @@ -139,7 +139,7 @@ static void on_write_done(void* arg, grpc_error* error) { // Callback invoked for reading HTTP CONNECT response. static void on_read_done(void* arg, grpc_error* error) { - http_connect_handshaker* handshaker = (http_connect_handshaker*)arg; + http_connect_handshaker* handshaker = static_cast(arg); gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the read failed or we're shutting down, clean up and invoke the @@ -224,13 +224,13 @@ done: // static void http_connect_handshaker_destroy(grpc_handshaker* handshaker_in) { - http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; + http_connect_handshaker* handshaker = reinterpret_cast(handshaker_in); http_connect_handshaker_unref(handshaker); } static void http_connect_handshaker_shutdown(grpc_handshaker* handshaker_in, grpc_error* why) { - http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; + http_connect_handshaker* handshaker = reinterpret_cast(handshaker_in); gpr_mu_lock(&handshaker->mu); if (!handshaker->shutdown) { handshaker->shutdown = true; @@ -244,7 +244,7 @@ static void http_connect_handshaker_shutdown(grpc_handshaker* handshaker_in, static void http_connect_handshaker_do_handshake( grpc_handshaker* handshaker_in, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; + http_connect_handshaker* handshaker = reinterpret_cast(handshaker_in); // Check for HTTP CONNECT channel arg. // If not found, invoke on_handshake_done without doing anything. const grpc_arg* arg = @@ -270,8 +270,8 @@ static void http_connect_handshaker_do_handshake( GPR_ASSERT(arg->type == GRPC_ARG_STRING); gpr_string_split(arg->value.string, "\n", &header_strings, &num_header_strings); - headers = (grpc_http_header*)gpr_malloc(sizeof(grpc_http_header) * - num_header_strings); + headers = static_cast(gpr_malloc(sizeof(grpc_http_header) * + num_header_strings)); for (size_t i = 0; i < num_header_strings; ++i) { char* sep = strchr(header_strings[i], ':'); if (sep == nullptr) { @@ -324,7 +324,7 @@ static const grpc_handshaker_vtable http_connect_handshaker_vtable = { static grpc_handshaker* grpc_http_connect_handshaker_create() { http_connect_handshaker* handshaker = - (http_connect_handshaker*)gpr_malloc(sizeof(*handshaker)); + static_cast(gpr_malloc(sizeof(*handshaker))); memset(handshaker, 0, sizeof(*handshaker)); grpc_handshaker_init(&http_connect_handshaker_vtable, &handshaker->base); gpr_mu_init(&handshaker->mu); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc index d6b759227e..b048989d4e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -48,7 +48,7 @@ struct call_data { } // namespace static void on_complete_for_send(void* arg, grpc_error* error) { - call_data* calld = (call_data*)arg; + call_data* calld = static_cast(arg); if (error == GRPC_ERROR_NONE) { calld->send_initial_metadata_succeeded = true; } @@ -56,7 +56,7 @@ static void on_complete_for_send(void* arg, grpc_error* error) { } static void recv_initial_metadata_ready(void* arg, grpc_error* error) { - call_data* calld = (call_data*)arg; + call_data* calld = static_cast(arg); if (error == GRPC_ERROR_NONE) { calld->recv_initial_metadata_succeeded = true; } @@ -66,13 +66,13 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) { static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); // Get stats object from context and take a ref. GPR_ASSERT(args->context != nullptr); if (args->context[GRPC_GRPCLB_CLIENT_STATS].value != nullptr) { calld->client_stats = grpc_grpclb_client_stats_ref( - (grpc_grpclb_client_stats*)args->context[GRPC_GRPCLB_CLIENT_STATS] - .value); + static_cast(args->context[GRPC_GRPCLB_CLIENT_STATS] + .value)); // Record call started. grpc_grpclb_client_stats_add_call_started(calld->client_stats); } @@ -82,7 +82,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (calld->client_stats != nullptr) { // Record call finished, optionally setting client_failed_to_send and // received. @@ -97,7 +97,7 @@ static void destroy_call_elem(grpc_call_element* elem, static void start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); GPR_TIMER_SCOPE("clr_start_transport_stream_op_batch", 0); if (calld->client_stats != nullptr) { // Intercept send_initial_metadata. 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 ac47990478..9ebc15d985 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 @@ -320,7 +320,7 @@ static void glb_lb_call_data_ref(glb_lb_call_data* lb_calld, const gpr_atm count = gpr_atm_acq_load(&lb_calld->refs.count); gpr_log(GPR_DEBUG, "[%s %p] lb_calld %p REF %lu->%lu (%s)", grpc_lb_glb_trace.name(), lb_calld->glb_policy, lb_calld, - (unsigned long)(count - 1), (unsigned long)count, reason); + static_cast(count - 1), static_cast(count), reason); } } @@ -331,7 +331,7 @@ static void glb_lb_call_data_unref(glb_lb_call_data* lb_calld, const gpr_atm count = gpr_atm_acq_load(&lb_calld->refs.count); gpr_log(GPR_DEBUG, "[%s %p] lb_calld %p UNREF %lu->%lu (%s)", grpc_lb_glb_trace.name(), lb_calld->glb_policy, lb_calld, - (unsigned long)(count + 1), (unsigned long)count, reason); + static_cast(count + 1), static_cast(count), reason); } if (done) { GPR_ASSERT(lb_calld->lb_call != nullptr); @@ -372,7 +372,7 @@ static grpc_error* initial_metadata_add_lb_token( } static void destroy_client_stats(void* arg) { - grpc_grpclb_client_stats_unref((grpc_grpclb_client_stats*)arg); + grpc_grpclb_client_stats_unref(static_cast(arg)); } static void pending_pick_set_metadata_and_context(pending_pick* pp) { @@ -408,7 +408,7 @@ static void pending_pick_set_metadata_and_context(pending_pick* pp) { * reference to its associated round robin instance. We wrap this closure in * order to unref the round robin instance upon its invocation */ static void pending_pick_complete(void* arg, grpc_error* error) { - pending_pick* pp = (pending_pick*)arg; + pending_pick* pp = static_cast(arg); pending_pick_set_metadata_and_context(pp); GRPC_CLOSURE_SCHED(pp->original_on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); @@ -416,7 +416,7 @@ static void pending_pick_complete(void* arg, grpc_error* error) { static pending_pick* pending_pick_create(glb_lb_policy* glb_policy, grpc_lb_policy_pick_state* pick) { - pending_pick* pp = (pending_pick*)gpr_zalloc(sizeof(*pp)); + pending_pick* pp = static_cast(gpr_zalloc(sizeof(*pp))); pp->pick = pick; pp->glb_policy = glb_policy; GRPC_CLOSURE_INIT(&pp->on_complete, pending_pick_complete, pp, @@ -433,7 +433,7 @@ static void pending_pick_add(pending_pick** root, pending_pick* new_pp) { static void pending_ping_add(pending_ping** root, grpc_closure* on_initiate, grpc_closure* on_ack) { - pending_ping* pping = (pending_ping*)gpr_zalloc(sizeof(*pping)); + pending_ping* pping = static_cast(gpr_zalloc(sizeof(*pping))); pping->on_initiate = on_initiate; pping->on_ack = on_ack; pping->next = *root; @@ -448,7 +448,7 @@ static bool is_server_valid(const grpc_grpclb_server* server, size_t idx, if (log) { gpr_log(GPR_ERROR, "Invalid port '%d' at index %lu of serverlist. Ignoring.", - server->port, (unsigned long)idx); + server->port, static_cast(idx)); } return false; } @@ -457,7 +457,7 @@ static bool is_server_valid(const grpc_grpclb_server* server, size_t idx, gpr_log(GPR_ERROR, "Expected IP to be 4 or 16 bytes, got %d at index %lu of " "serverlist. Ignoring", - ip->size, (unsigned long)idx); + ip->size, static_cast(idx)); } return false; } @@ -487,19 +487,19 @@ static void parse_server(const grpc_grpclb_server* server, grpc_resolved_address* addr) { memset(addr, 0, sizeof(*addr)); if (server->drop) return; - const uint16_t netorder_port = htons((uint16_t)server->port); + const uint16_t netorder_port = htons(static_cast(server->port)); /* the addresses are given in binary format (a in(6)_addr struct) in * server->ip_address.bytes. */ const grpc_grpclb_ip_address* ip = &server->ip_address; if (ip->size == 4) { addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in* addr4 = (struct sockaddr_in*)&addr->addr; + struct sockaddr_in* addr4 = reinterpret_cast(&addr->addr); addr4->sin_family = AF_INET; memcpy(&addr4->sin_addr, ip->bytes, ip->size); addr4->sin_port = netorder_port; } else if (ip->size == 16) { addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6* addr6 = (struct sockaddr_in6*)&addr->addr; + struct sockaddr_in6* addr6 = reinterpret_cast(&addr->addr); addr6->sin6_family = AF_INET6; memcpy(&addr6->sin6_addr, ip->bytes, ip->size); addr6->sin6_port = netorder_port; @@ -684,7 +684,7 @@ static bool pick_from_internal_rr_locked(glb_lb_policy* glb_policy, grpc_grpclb_client_stats_ref(glb_policy->lb_calld->client_stats); } GPR_ASSERT(pp->pick->user_data == nullptr); - pp->pick->user_data = (void**)&pp->lb_token; + pp->pick->user_data = reinterpret_cast(&pp->lb_token); // Pick via the RR policy. bool pick_done = grpc_lb_policy_pick_locked(glb_policy->rr_policy, pp->pick); if (pick_done) { @@ -716,7 +716,7 @@ static grpc_lb_policy_args* lb_policy_args_create(glb_lb_policy* glb_policy) { addresses = grpc_lb_addresses_copy(glb_policy->fallback_backend_addresses); } GPR_ASSERT(addresses != nullptr); - grpc_lb_policy_args* args = (grpc_lb_policy_args*)gpr_zalloc(sizeof(*args)); + grpc_lb_policy_args* args = static_cast(gpr_zalloc(sizeof(*args))); args->client_channel_factory = glb_policy->cc_factory; args->combiner = glb_policy->base.combiner; // Replace the LB addresses in the channel args that we pass down to @@ -823,7 +823,7 @@ static void rr_handover_locked(glb_lb_policy* glb_policy) { } static void on_rr_connectivity_changed_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; + glb_lb_policy* glb_policy = static_cast(arg); if (glb_policy->shutting_down) { GRPC_LB_POLICY_UNREF(&glb_policy->base, "glb_rr_connectivity_cb"); return; @@ -859,8 +859,8 @@ static grpc_slice_hash_table_entry targets_info_entry_create( } static int balancer_name_cmp_fn(void* a, void* b) { - const char* a_str = (const char*)a; - const char* b_str = (const char*)b; + const char* a_str = static_cast(a); + const char* b_str = static_cast(b); return strcmp(a_str, b_str); } @@ -887,8 +887,8 @@ static grpc_channel_args* build_lb_channel_args( grpc_lb_addresses* lb_addresses = grpc_lb_addresses_create(num_grpclb_addrs, nullptr); grpc_slice_hash_table_entry* targets_info_entries = - (grpc_slice_hash_table_entry*)gpr_zalloc(sizeof(*targets_info_entries) * - num_grpclb_addrs); + static_cast(gpr_zalloc(sizeof(*targets_info_entries) * + num_grpclb_addrs)); size_t lb_addresses_idx = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { @@ -931,7 +931,7 @@ static grpc_channel_args* build_lb_channel_args( } static void glb_destroy(grpc_lb_policy* pol) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); GPR_ASSERT(glb_policy->pending_picks == nullptr); GPR_ASSERT(glb_policy->pending_pings == nullptr); gpr_free((void*)glb_policy->server_name); @@ -951,7 +951,7 @@ static void glb_destroy(grpc_lb_policy* pol) { static void glb_shutdown_locked(grpc_lb_policy* pol, grpc_lb_policy* new_policy) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); glb_policy->shutting_down = true; if (glb_policy->lb_calld != nullptr) { @@ -1027,7 +1027,7 @@ static void glb_shutdown_locked(grpc_lb_policy* pol, static void glb_cancel_pick_locked(grpc_lb_policy* pol, grpc_lb_policy_pick_state* pick, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); pending_pick* pp = glb_policy->pending_picks; glb_policy->pending_picks = nullptr; while (pp != nullptr) { @@ -1064,7 +1064,7 @@ static void glb_cancel_picks_locked(grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); pending_pick* pp = glb_policy->pending_picks; glb_policy->pending_picks = nullptr; while (pp != nullptr) { @@ -1111,7 +1111,7 @@ static void start_picking_locked(glb_lb_policy* glb_policy) { } static void glb_exit_idle_locked(grpc_lb_policy* pol) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); if (!glb_policy->started_picking) { start_picking_locked(glb_policy); } @@ -1119,7 +1119,7 @@ static void glb_exit_idle_locked(grpc_lb_policy* pol) { static int glb_pick_locked(grpc_lb_policy* pol, grpc_lb_policy_pick_state* pick) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); pending_pick* pp = pending_pick_create(glb_policy, pick); bool pick_done = false; if (glb_policy->rr_policy != nullptr) { @@ -1165,14 +1165,14 @@ static int glb_pick_locked(grpc_lb_policy* pol, static grpc_connectivity_state glb_check_connectivity_locked( grpc_lb_policy* pol, grpc_error** connectivity_error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); return grpc_connectivity_state_get(&glb_policy->state_tracker, connectivity_error); } static void glb_ping_one_locked(grpc_lb_policy* pol, grpc_closure* on_initiate, grpc_closure* on_ack) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); if (glb_policy->rr_policy) { grpc_lb_policy_ping_one_locked(glb_policy->rr_policy, on_initiate, on_ack); } else { @@ -1186,13 +1186,13 @@ static void glb_ping_one_locked(grpc_lb_policy* pol, grpc_closure* on_initiate, static void glb_notify_on_state_change_locked(grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { - glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + glb_lb_policy* glb_policy = reinterpret_cast(pol); grpc_connectivity_state_notify_on_state_change(&glb_policy->state_tracker, current, notify); } static void lb_call_on_retry_timer_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; + glb_lb_policy* glb_policy = static_cast(arg); glb_policy->retry_timer_callback_pending = false; if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE && glb_policy->lb_calld == nullptr) { @@ -1244,7 +1244,7 @@ static void schedule_next_client_load_report(glb_lb_call_data* lb_calld) { } static void client_load_report_done_locked(void* arg, grpc_error* error) { - glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_call_data* lb_calld = static_cast(arg); glb_lb_policy* glb_policy = lb_calld->glb_policy; grpc_byte_buffer_destroy(lb_calld->send_message_payload); lb_calld->send_message_payload = nullptr; @@ -1257,8 +1257,7 @@ static void client_load_report_done_locked(void* arg, grpc_error* error) { static bool load_report_counters_are_zero(grpc_grpclb_request* request) { grpc_grpclb_dropped_call_counts* drop_entries = - (grpc_grpclb_dropped_call_counts*) - request->client_stats.calls_finished_with_drop.arg; + static_cast(request->client_stats.calls_finished_with_drop.arg); return request->client_stats.num_calls_started == 0 && request->client_stats.num_calls_finished == 0 && request->client_stats.num_calls_finished_with_client_failed_to_send == @@ -1307,7 +1306,7 @@ static void send_client_load_report_locked(glb_lb_call_data* lb_calld) { } static void maybe_send_client_load_report_locked(void* arg, grpc_error* error) { - glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_call_data* lb_calld = static_cast(arg); glb_lb_policy* glb_policy = lb_calld->glb_policy; lb_calld->client_load_report_timer_callback_pending = false; if (error != GRPC_ERROR_NONE || lb_calld != glb_policy->lb_calld) { @@ -1339,7 +1338,7 @@ static glb_lb_call_data* lb_call_data_create_locked(glb_lb_policy* glb_policy) { glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE : grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; - glb_lb_call_data* lb_calld = (glb_lb_call_data*)gpr_zalloc(sizeof(*lb_calld)); + glb_lb_call_data* lb_calld = static_cast(gpr_zalloc(sizeof(*lb_calld))); lb_calld->lb_call = grpc_channel_create_pollset_set_call( glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, @@ -1413,7 +1412,7 @@ static void query_for_backends_locked(glb_lb_policy* glb_policy) { glb_lb_call_data_ref(glb_policy->lb_calld, "lb_on_sent_initial_request_locked"); call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_calld->lb_call, ops, (size_t)(op - ops), + glb_policy->lb_calld->lb_call, ops, static_cast(op - ops), &glb_policy->lb_calld->lb_on_sent_initial_request); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: recv initial metadata. @@ -1433,7 +1432,7 @@ static void query_for_backends_locked(glb_lb_policy* glb_policy) { op++; glb_lb_call_data_ref(glb_policy->lb_calld, "lb_on_response_received_locked"); call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_calld->lb_call, ops, (size_t)(op - ops), + glb_policy->lb_calld->lb_call, ops, static_cast(op - ops), &glb_policy->lb_calld->lb_on_response_received); GPR_ASSERT(GRPC_CALL_OK == call_error); // Op: recv server status. @@ -1451,13 +1450,13 @@ static void query_for_backends_locked(glb_lb_policy* glb_policy) { // 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( - glb_policy->lb_calld->lb_call, ops, (size_t)(op - ops), + glb_policy->lb_calld->lb_call, ops, static_cast(op - ops), &glb_policy->lb_calld->lb_on_server_status_received); GPR_ASSERT(GRPC_CALL_OK == call_error); } static void lb_on_sent_initial_request_locked(void* arg, grpc_error* error) { - glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_call_data* 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 @@ -1471,7 +1470,7 @@ static void lb_on_sent_initial_request_locked(void* arg, grpc_error* error) { } static void lb_on_response_received_locked(void* arg, grpc_error* error) { - glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_call_data* lb_calld = static_cast(arg); glb_lb_policy* glb_policy = lb_calld->glb_policy; // Empty payload means the LB call was cancelled. if (lb_calld != glb_policy->lb_calld || @@ -1594,7 +1593,7 @@ static void lb_on_response_received_locked(void* arg, grpc_error* error) { // Reuse the "lb_on_response_received_locked" ref taken in // query_for_backends_locked(). const grpc_call_error call_error = grpc_call_start_batch_and_execute( - lb_calld->lb_call, ops, (size_t)(op - ops), + lb_calld->lb_call, ops, static_cast(op - ops), &lb_calld->lb_on_response_received); GPR_ASSERT(GRPC_CALL_OK == call_error); } else { @@ -1604,7 +1603,7 @@ static void lb_on_response_received_locked(void* arg, grpc_error* error) { } static void lb_on_server_status_received_locked(void* arg, grpc_error* error) { - glb_lb_call_data* lb_calld = (glb_lb_call_data*)arg; + glb_lb_call_data* lb_calld = static_cast(arg); glb_lb_policy* glb_policy = lb_calld->glb_policy; GPR_ASSERT(lb_calld->lb_call != nullptr); if (grpc_lb_glb_trace.enabled()) { @@ -1641,7 +1640,7 @@ static void lb_on_server_status_received_locked(void* arg, grpc_error* error) { } static void lb_on_fallback_timer_locked(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; + glb_lb_policy* glb_policy = static_cast(arg); glb_policy->fallback_timer_callback_pending = false; /* If we receive a serverlist after the timer fires but before this callback * actually runs, don't fall back. */ @@ -1673,7 +1672,7 @@ static void fallback_update_locked(glb_lb_policy* glb_policy, static void glb_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* args) { - glb_lb_policy* glb_policy = (glb_lb_policy*)policy; + glb_lb_policy* glb_policy = reinterpret_cast(policy); const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { @@ -1694,7 +1693,7 @@ static void glb_update_locked(grpc_lb_policy* policy, return; } const grpc_lb_addresses* addresses = - (const grpc_lb_addresses*)arg->value.pointer.p; + static_cast(arg->value.pointer.p); // If a non-empty serverlist hasn't been received from the balancer, // propagate the update to fallback_backend_addresses. if (glb_policy->serverlist == nullptr) { @@ -1731,7 +1730,7 @@ static void glb_update_locked(grpc_lb_policy* policy, // stayed READY throughout the update (for example if the update is identical). static void glb_lb_channel_on_connectivity_changed_cb(void* arg, grpc_error* error) { - glb_lb_policy* glb_policy = (glb_lb_policy*)arg; + glb_lb_policy* glb_policy = static_cast(arg); if (glb_policy->shutting_down) goto done; // Re-initialize the lb_call. This should also take care of updating the // embedded RR policy. Note that the current RR policy, if any, will stay in @@ -1777,7 +1776,7 @@ static void glb_lb_channel_on_connectivity_changed_cb(void* arg, static void glb_set_reresolve_closure_locked( grpc_lb_policy* policy, grpc_closure* request_reresolution) { - glb_lb_policy* glb_policy = (glb_lb_policy*)policy; + glb_lb_policy* glb_policy = reinterpret_cast(policy); GPR_ASSERT(!glb_policy->shutting_down); GPR_ASSERT(glb_policy->base.request_reresolution == nullptr); if (glb_policy->rr_policy != nullptr) { @@ -1810,14 +1809,14 @@ static grpc_lb_policy* glb_create(grpc_lb_policy_factory* factory, if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { return nullptr; } - grpc_lb_addresses* addresses = (grpc_lb_addresses*)arg->value.pointer.p; + grpc_lb_addresses* addresses = 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; } if (num_grpclb_addrs == 0) return nullptr; - glb_lb_policy* glb_policy = (glb_lb_policy*)gpr_zalloc(sizeof(*glb_policy)); + glb_lb_policy* glb_policy = static_cast(gpr_zalloc(sizeof(*glb_policy))); /* Get server name. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); @@ -1921,7 +1920,7 @@ static bool maybe_add_client_load_reporting_filter( if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING && strcmp(channel_arg->value.string, "grpclb") == 0) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter*)arg, nullptr, nullptr); + builder, static_cast(arg), nullptr, nullptr); } return true; } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc index 45c9f17301..f9ffea6c39 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc @@ -42,7 +42,7 @@ struct grpc_grpclb_client_stats { grpc_grpclb_client_stats* grpc_grpclb_client_stats_create() { grpc_grpclb_client_stats* client_stats = - (grpc_grpclb_client_stats*)gpr_zalloc(sizeof(*client_stats)); + static_cast(gpr_zalloc(sizeof(*client_stats))); gpr_ref_init(&client_stats->refs, 1); return client_stats; } @@ -88,8 +88,8 @@ void grpc_grpclb_client_stats_add_call_dropped_locked( // Record the drop. if (client_stats->drop_token_counts == nullptr) { client_stats->drop_token_counts = - (grpc_grpclb_dropped_call_counts*)gpr_zalloc( - sizeof(grpc_grpclb_dropped_call_counts)); + static_cast(gpr_zalloc( + sizeof(grpc_grpclb_dropped_call_counts))); } grpc_grpclb_dropped_call_counts* drop_token_counts = client_stats->drop_token_counts; @@ -104,9 +104,9 @@ void grpc_grpclb_client_stats_add_call_dropped_locked( while (new_num_entries < drop_token_counts->num_entries + 1) { new_num_entries *= 2; } - drop_token_counts->token_counts = (grpc_grpclb_drop_token_count*)gpr_realloc( + drop_token_counts->token_counts = static_cast(gpr_realloc( drop_token_counts->token_counts, - new_num_entries * sizeof(grpc_grpclb_drop_token_count)); + new_num_entries * sizeof(grpc_grpclb_drop_token_count))); grpc_grpclb_drop_token_count* new_entry = &drop_token_counts->token_counts[drop_token_counts->num_entries++]; new_entry->token = gpr_strdup(token); @@ -114,7 +114,7 @@ void grpc_grpclb_client_stats_add_call_dropped_locked( } static void atomic_get_and_reset_counter(int64_t* value, gpr_atm* counter) { - *value = (int64_t)gpr_atm_acq_load(counter); + *value = static_castgpr_atm_acq_load(counter); gpr_atm_full_fetch_add(counter, (gpr_atm)(-*value)); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc index fc781da330..ee6dd27eb5 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc @@ -25,7 +25,7 @@ /* invoked once for every Server in ServerList */ static bool count_serverlist(pb_istream_t* stream, const pb_field_t* field, void** arg) { - grpc_grpclb_serverlist* sl = (grpc_grpclb_serverlist*)*arg; + grpc_grpclb_serverlist* sl = static_cast(*arg); grpc_grpclb_server server; if (!pb_decode(stream, grpc_lb_v1_Server_fields, &server)) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); @@ -46,10 +46,10 @@ typedef struct decode_serverlist_arg { /* invoked once for every Server in ServerList */ static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field, void** arg) { - decode_serverlist_arg* dec_arg = (decode_serverlist_arg*)*arg; + decode_serverlist_arg* dec_arg = static_cast(*arg); GPR_ASSERT(dec_arg->serverlist->num_servers >= dec_arg->decoding_idx); grpc_grpclb_server* server = - (grpc_grpclb_server*)gpr_zalloc(sizeof(grpc_grpclb_server)); + static_cast(gpr_zalloc(sizeof(grpc_grpclb_server))); if (!pb_decode(stream, grpc_lb_v1_Server_fields, server)) { gpr_free(server); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); @@ -61,7 +61,7 @@ static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field, grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name) { grpc_grpclb_request* req = - (grpc_grpclb_request*)gpr_malloc(sizeof(grpc_grpclb_request)); + static_cast(gpr_malloc(sizeof(grpc_grpclb_request))); req->has_client_stats = false; req->has_initial_request = true; req->initial_request.has_name = true; @@ -80,15 +80,15 @@ static void populate_timestamp(gpr_timespec timestamp, static bool encode_string(pb_ostream_t* stream, const pb_field_t* field, void* const* arg) { - char* str = (char*)*arg; + char* str = static_cast(*arg); if (!pb_encode_tag_for_field(stream, field)) return false; - return pb_encode_string(stream, (uint8_t*)str, strlen(str)); + return pb_encode_string(stream, reinterpret_cast(str), strlen(str)); } static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field, void* const* arg) { grpc_grpclb_dropped_call_counts* drop_entries = - (grpc_grpclb_dropped_call_counts*)*arg; + static_cast(*arg); if (drop_entries == nullptr) return true; for (size_t i = 0; i < drop_entries->num_entries; ++i) { if (!pb_encode_tag_for_field(stream, field)) return false; @@ -108,7 +108,7 @@ static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field, grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked( grpc_grpclb_client_stats* client_stats) { grpc_grpclb_request* req = - (grpc_grpclb_request*)gpr_zalloc(sizeof(grpc_grpclb_request)); + static_cast(gpr_zalloc(sizeof(grpc_grpclb_request))); req->has_client_stats = true; req->client_stats.has_timestamp = true; populate_timestamp(gpr_now(GPR_CLOCK_REALTIME), &req->client_stats.timestamp); @@ -123,8 +123,8 @@ grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked( &req->client_stats.num_calls_finished, &req->client_stats.num_calls_finished_with_client_failed_to_send, &req->client_stats.num_calls_finished_known_received, - (grpc_grpclb_dropped_call_counts**)&req->client_stats - .calls_finished_with_drop.arg); + reinterpret_cast(&req->client_stats + .calls_finished_with_drop.arg)); return req; } @@ -148,8 +148,7 @@ grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request) { void grpc_grpclb_request_destroy(grpc_grpclb_request* request) { if (request->has_client_stats) { grpc_grpclb_dropped_call_counts* drop_entries = - (grpc_grpclb_dropped_call_counts*) - request->client_stats.calls_finished_with_drop.arg; + static_cast(request->client_stats.calls_finished_with_drop.arg); grpc_grpclb_dropped_call_counts_destroy(drop_entries); } gpr_free(request); @@ -171,8 +170,8 @@ grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( if (!res.has_initial_response) return nullptr; grpc_grpclb_initial_response* initial_res = - (grpc_grpclb_initial_response*)gpr_malloc( - sizeof(grpc_grpclb_initial_response)); + static_cast(gpr_malloc( + sizeof(grpc_grpclb_initial_response))); memcpy(initial_res, &res.initial_response, sizeof(grpc_grpclb_initial_response)); @@ -186,7 +185,7 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); pb_istream_t stream_at_start = stream; grpc_grpclb_serverlist* sl = - (grpc_grpclb_serverlist*)gpr_zalloc(sizeof(grpc_grpclb_serverlist)); + static_cast(gpr_zalloc(sizeof(grpc_grpclb_serverlist))); grpc_grpclb_response res; memset(&res, 0, sizeof(grpc_grpclb_response)); // First pass: count number of servers. @@ -200,8 +199,8 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( } // Second pass: populate servers. if (sl->num_servers > 0) { - sl->servers = (grpc_grpclb_server**)gpr_zalloc(sizeof(grpc_grpclb_server*) * - sl->num_servers); + sl->servers = static_cast(gpr_zalloc(sizeof(grpc_grpclb_server*) * + sl->num_servers)); decode_serverlist_arg decode_arg; memset(&decode_arg, 0, sizeof(decode_arg)); decode_arg.serverlist = sl; @@ -232,13 +231,13 @@ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) { grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy( const grpc_grpclb_serverlist* sl) { grpc_grpclb_serverlist* copy = - (grpc_grpclb_serverlist*)gpr_zalloc(sizeof(grpc_grpclb_serverlist)); + static_cast(gpr_zalloc(sizeof(grpc_grpclb_serverlist))); copy->num_servers = sl->num_servers; - copy->servers = (grpc_grpclb_server**)gpr_malloc(sizeof(grpc_grpclb_server*) * - sl->num_servers); + copy->servers = static_cast(gpr_malloc(sizeof(grpc_grpclb_server*) * + sl->num_servers)); for (size_t i = 0; i < sl->num_servers; i++) { copy->servers[i] = - (grpc_grpclb_server*)gpr_malloc(sizeof(grpc_grpclb_server)); + static_cast(gpr_malloc(sizeof(grpc_grpclb_server))); memcpy(copy->servers[i], sl->servers[i], sizeof(grpc_grpclb_server)); } return copy; @@ -291,7 +290,7 @@ int grpc_grpclb_duration_compare(const grpc_grpclb_duration* lhs, } grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb) { - return (grpc_millis)( + return static_cast( (duration_pb->has_seconds ? duration_pb->seconds : 0) * GPR_MS_PER_SEC + (duration_pb->has_nanos ? duration_pb->nanos : 0) / GPR_NS_PER_MS); } 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 725b78d478..7e957e082c 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 @@ -51,7 +51,7 @@ typedef struct { } pick_first_lb_policy; static void pf_destroy(grpc_lb_policy* pol) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); GPR_ASSERT(p->subchannel_list == nullptr); GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); GPR_ASSERT(p->pending_picks == nullptr); @@ -65,7 +65,7 @@ static void pf_destroy(grpc_lb_policy* pol) { static void pf_shutdown_locked(grpc_lb_policy* pol, grpc_lb_policy* new_policy) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p Shutting down", p); @@ -105,7 +105,7 @@ static void pf_shutdown_locked(grpc_lb_policy* pol, static void pf_cancel_pick_locked(grpc_lb_policy* pol, grpc_lb_policy_pick_state* pick, grpc_error* error) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); grpc_lb_policy_pick_state* pp = p->pending_picks; p->pending_picks = nullptr; while (pp != nullptr) { @@ -128,7 +128,7 @@ static void pf_cancel_picks_locked(grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); grpc_lb_policy_pick_state* pick = p->pending_picks; p->pending_picks = nullptr; while (pick != nullptr) { @@ -165,7 +165,7 @@ static void start_picking_locked(pick_first_lb_policy* p) { } static void pf_exit_idle_locked(grpc_lb_policy* pol) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); if (!p->started_picking) { start_picking_locked(p); } @@ -173,7 +173,7 @@ static void pf_exit_idle_locked(grpc_lb_policy* pol) { static int pf_pick_locked(grpc_lb_policy* pol, grpc_lb_policy_pick_state* pick) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); // If we have a selected subchannel already, return synchronously. if (p->selected != nullptr) { pick->connected_subchannel = p->selected->connected_subchannel; @@ -200,21 +200,21 @@ static void destroy_unselected_subchannels_locked(pick_first_lb_policy* p) { static grpc_connectivity_state pf_check_connectivity_locked( grpc_lb_policy* pol, grpc_error** error) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); return grpc_connectivity_state_get(&p->state_tracker, error); } static void pf_notify_on_state_change_locked(grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); grpc_connectivity_state_notify_on_state_change(&p->state_tracker, current, notify); } static void pf_ping_one_locked(grpc_lb_policy* pol, grpc_closure* on_initiate, grpc_closure* on_ack) { - pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pick_first_lb_policy* p = reinterpret_cast(pol); if (p->selected) { p->selected->connected_subchannel->Ping(on_initiate, on_ack); } else { @@ -229,7 +229,7 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error); static void pf_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* args) { - pick_first_lb_policy* p = (pick_first_lb_policy*)policy; + pick_first_lb_policy* p = reinterpret_cast(policy); const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { @@ -249,10 +249,10 @@ static void pf_update_locked(grpc_lb_policy* policy, return; } const grpc_lb_addresses* addresses = - (const grpc_lb_addresses*)arg->value.pointer.p; + static_cast(arg->value.pointer.p); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_INFO, "Pick First %p received update with %lu addresses", - (void*)p, (unsigned long)addresses->num_addresses); + (void*)p, static_cast(addresses->num_addresses)); } grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create( &p->base, &grpc_lb_pick_first_trace, addresses, args, @@ -347,8 +347,8 @@ static void pf_update_locked(grpc_lb_policy* policy, } static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { - grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; - pick_first_lb_policy* p = (pick_first_lb_policy*)sd->subchannel_list->policy; + grpc_lb_subchannel_data* sd = static_cast(arg); + pick_first_lb_policy* p = reinterpret_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 @@ -521,7 +521,7 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { static void pf_set_reresolve_closure_locked( grpc_lb_policy* policy, grpc_closure* request_reresolution) { - pick_first_lb_policy* p = (pick_first_lb_policy*)policy; + pick_first_lb_policy* p = reinterpret_cast(policy); GPR_ASSERT(!p->shutdown); GPR_ASSERT(policy->request_reresolution == nullptr); policy->request_reresolution = request_reresolution; @@ -547,7 +547,7 @@ static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* create_pick_first(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); - pick_first_lb_policy* p = (pick_first_lb_policy*)gpr_zalloc(sizeof(*p)); + pick_first_lb_policy* p = static_cast(gpr_zalloc(sizeof(*p))); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p); } 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 ab6d3e6a03..b0e1c79500 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 @@ -82,8 +82,8 @@ static size_t get_next_ready_subchannel_index_locked( gpr_log(GPR_INFO, "[RR %p] getting next ready subchannel (out of %lu), " "last_ready_subchannel_index=%lu", - (void*)p, (unsigned long)p->subchannel_list->num_subchannels, - (unsigned long)p->last_ready_subchannel_index); + (void*)p, static_cast(p->subchannel_list->num_subchannels), + static_cast(p->last_ready_subchannel_index)); } for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { const size_t index = (i + p->last_ready_subchannel_index + 1) % @@ -94,7 +94,7 @@ static size_t get_next_ready_subchannel_index_locked( "[RR %p] checking subchannel %p, subchannel_list %p, index %lu: " "state=%s", (void*)p, (void*)p->subchannel_list->subchannels[index].subchannel, - (void*)p->subchannel_list, (unsigned long)index, + (void*)p->subchannel_list, static_cast(index), grpc_connectivity_state_name( p->subchannel_list->subchannels[index].curr_connectivity_state)); } @@ -106,7 +106,7 @@ static size_t get_next_ready_subchannel_index_locked( "subchannel_list %p", (void*)p, (void*)p->subchannel_list->subchannels[index].subchannel, - (unsigned long)index, (void*)p->subchannel_list); + static_cast(index), (void*)p->subchannel_list); } return index; } @@ -125,7 +125,7 @@ static void update_last_ready_subchannel_index_locked(round_robin_lb_policy* p, if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] setting last_ready_subchannel_index=%lu (SC %p, CSC %p)", - (void*)p, (unsigned long)last_ready_index, + (void*)p, static_cast(last_ready_index), (void*)p->subchannel_list->subchannels[last_ready_index].subchannel, (void*)p->subchannel_list->subchannels[last_ready_index] .connected_subchannel.get()); @@ -133,7 +133,7 @@ static void update_last_ready_subchannel_index_locked(round_robin_lb_policy* p, } static void rr_destroy(grpc_lb_policy* pol) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p", (void*)pol, (void*)pol); @@ -147,7 +147,7 @@ static void rr_destroy(grpc_lb_policy* pol) { static void rr_shutdown_locked(grpc_lb_policy* pol, grpc_lb_policy* new_policy) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Shutting down", p); @@ -187,7 +187,7 @@ static void rr_shutdown_locked(grpc_lb_policy* pol, static void rr_cancel_pick_locked(grpc_lb_policy* pol, grpc_lb_policy_pick_state* pick, grpc_error* error) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); grpc_lb_policy_pick_state* pp = p->pending_picks; p->pending_picks = nullptr; while (pp != nullptr) { @@ -210,7 +210,7 @@ static void rr_cancel_picks_locked(grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); grpc_lb_policy_pick_state* pick = p->pending_picks; p->pending_picks = nullptr; while (pick != nullptr) { @@ -243,7 +243,7 @@ static void start_picking_locked(round_robin_lb_policy* p) { } static void rr_exit_idle_locked(grpc_lb_policy* pol) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); if (!p->started_picking) { start_picking_locked(p); } @@ -251,7 +251,7 @@ static void rr_exit_idle_locked(grpc_lb_policy* pol) { static int rr_pick_locked(grpc_lb_policy* pol, grpc_lb_policy_pick_state* pick) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_INFO, "[RR %p] Trying to pick (shutdown: %d)", pol, p->shutdown); @@ -334,7 +334,7 @@ static void update_lb_connectivity_status_locked(grpc_lb_subchannel_data* sd, * subchannel_list->num_subchannels. */ grpc_lb_subchannel_list* subchannel_list = sd->subchannel_list; - round_robin_lb_policy* p = (round_robin_lb_policy*)subchannel_list->policy; + round_robin_lb_policy* p = reinterpret_cast(subchannel_list->policy); GPR_ASSERT(sd->curr_connectivity_state != GRPC_CHANNEL_IDLE); if (subchannel_list->num_ready > 0) { /* 1) READY */ @@ -355,9 +355,9 @@ static void update_lb_connectivity_status_locked(grpc_lb_subchannel_data* sd, } static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { - grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; + grpc_lb_subchannel_data* sd = static_cast(arg); round_robin_lb_policy* p = - (round_robin_lb_policy*)sd->subchannel_list->policy; + reinterpret_cast(sd->subchannel_list->policy); if (grpc_lb_round_robin_trace.enabled()) { gpr_log( GPR_DEBUG, @@ -426,7 +426,7 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { if (grpc_lb_round_robin_trace.enabled()) { const unsigned long num_subchannels = p->subchannel_list != nullptr - ? (unsigned long)p->subchannel_list->num_subchannels + ? static_cast(p->subchannel_list->num_subchannels) : 0; gpr_log(GPR_DEBUG, "[RR %p] phasing out subchannel list %p (size %lu) in favor " @@ -467,7 +467,7 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { "[RR %p] Fulfilling pending pick. Target <-- subchannel %p " "(subchannel_list %p, index %lu)", (void*)p, (void*)selected->subchannel, - (void*)p->subchannel_list, (unsigned long)next_ready_index); + (void*)p->subchannel_list, static_cast(next_ready_index)); } GRPC_CLOSURE_SCHED(pick->on_complete, GRPC_ERROR_NONE); } @@ -490,21 +490,21 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { static grpc_connectivity_state rr_check_connectivity_locked( grpc_lb_policy* pol, grpc_error** error) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); return grpc_connectivity_state_get(&p->state_tracker, error); } static void rr_notify_on_state_change_locked(grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); grpc_connectivity_state_notify_on_state_change(&p->state_tracker, current, notify); } static void rr_ping_one_locked(grpc_lb_policy* pol, grpc_closure* on_initiate, grpc_closure* on_ack) { - round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + round_robin_lb_policy* p = reinterpret_cast(pol); const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); if (next_ready_index < p->subchannel_list->num_subchannels) { grpc_lb_subchannel_data* selected = @@ -522,7 +522,7 @@ static void rr_ping_one_locked(grpc_lb_policy* pol, grpc_closure* on_initiate, static void rr_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* args) { - round_robin_lb_policy* p = (round_robin_lb_policy*)policy; + round_robin_lb_policy* p = reinterpret_cast(policy); const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { @@ -537,7 +537,7 @@ static void rr_update_locked(grpc_lb_policy* policy, } return; } - grpc_lb_addresses* addresses = (grpc_lb_addresses*)arg->value.pointer.p; + grpc_lb_addresses* addresses = static_cast(arg->value.pointer.p); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] received update with %" PRIuPTR " addresses", p, addresses->num_addresses); @@ -617,7 +617,7 @@ static void rr_update_locked(grpc_lb_policy* policy, static void rr_set_reresolve_closure_locked( grpc_lb_policy* policy, grpc_closure* request_reresolution) { - round_robin_lb_policy* p = (round_robin_lb_policy*)policy; + round_robin_lb_policy* p = reinterpret_cast(policy); GPR_ASSERT(!p->shutdown); GPR_ASSERT(policy->request_reresolution == nullptr); policy->request_reresolution = request_reresolution; @@ -643,7 +643,7 @@ static void round_robin_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* round_robin_create(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); - round_robin_lb_policy* p = (round_robin_lb_policy*)gpr_zalloc(sizeof(*p)); + round_robin_lb_policy* p = static_cast(gpr_zalloc(sizeof(*p))); grpc_lb_policy_init(&p->base, &round_robin_lb_policy_vtable, args->combiner); grpc_subchannel_index_ref(); grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, @@ -651,7 +651,7 @@ static grpc_lb_policy* round_robin_create(grpc_lb_policy_factory* factory, rr_update_locked(&p->base, args); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Created with %lu subchannels", (void*)p, - (unsigned long)p->subchannel_list->num_subchannels); + static_cast(p->subchannel_list->num_subchannels)); } return &p->base; } diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc index 75f7ca2d12..b671b2ae39 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -37,7 +37,7 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_lb_subchannel_data* sd, " (subchannel %p): unreffing subchannel", sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, sd->subchannel_list, - (size_t)(sd - sd->subchannel_list->subchannels), + static_cast(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel); } GRPC_SUBCHANNEL_UNREF(sd->subchannel, reason); @@ -60,7 +60,7 @@ void grpc_lb_subchannel_data_start_connectivity_watch( " (subchannel %p): requesting connectivity change " "notification (from %s)", sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, - sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), + sd->subchannel_list, static_cast(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, grpc_connectivity_state_name(sd->pending_connectivity_state_unsafe)); } @@ -79,7 +79,7 @@ void grpc_lb_subchannel_data_stop_connectivity_watch( " (subchannel %p): stopping connectivity watch", sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, sd->subchannel_list, - (size_t)(sd - sd->subchannel_list->subchannels), + static_cast(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel); } GPR_ASSERT(sd->connectivity_notification_pending); @@ -91,7 +91,7 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb) { grpc_lb_subchannel_list* subchannel_list = - (grpc_lb_subchannel_list*)gpr_zalloc(sizeof(*subchannel_list)); + static_cast(gpr_zalloc(sizeof(*subchannel_list))); if (tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Creating subchannel list %p for %" PRIuPTR " subchannels", @@ -100,8 +100,8 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( subchannel_list->policy = p; subchannel_list->tracer = tracer; gpr_ref_init(&subchannel_list->refcount, 1); - subchannel_list->subchannels = (grpc_lb_subchannel_data*)gpr_zalloc( - sizeof(grpc_lb_subchannel_data) * addresses->num_addresses); + subchannel_list->subchannels = static_cast(gpr_zalloc( + sizeof(grpc_lb_subchannel_data) * addresses->num_addresses)); // We need to remove the LB addresses in order to be able to compare the // subchannel keys of subchannels from a different batch of addresses. static const char* keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS, @@ -190,7 +190,7 @@ void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); gpr_log(GPR_DEBUG, "[%s %p] subchannel_list %p REF %lu->%lu (%s)", subchannel_list->tracer->name(), subchannel_list->policy, - subchannel_list, (unsigned long)(count - 1), (unsigned long)count, + subchannel_list, static_cast(count - 1), static_cast(count), reason); } } @@ -202,7 +202,7 @@ void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); gpr_log(GPR_DEBUG, "[%s %p] subchannel_list %p UNREF %lu->%lu (%s)", subchannel_list->tracer->name(), subchannel_list->policy, - subchannel_list, (unsigned long)(count + 1), (unsigned long)count, + subchannel_list, static_cast(count + 1), static_cast(count), reason); } if (done) { @@ -230,7 +230,7 @@ static void subchannel_data_cancel_connectivity_watch( " (subchannel %p): canceling connectivity watch (%s)", sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, sd->subchannel_list, - (size_t)(sd - sd->subchannel_list->subchannels), + static_cast(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, reason); } grpc_subchannel_notify_on_state_change(sd->subchannel, nullptr, nullptr, diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.cc b/src/core/ext/filters/client_channel/lb_policy_factory.cc index dbf69fdcba..b9b9e298a5 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.cc +++ b/src/core/ext/filters/client_channel/lb_policy_factory.cc @@ -29,11 +29,11 @@ grpc_lb_addresses* grpc_lb_addresses_create( size_t num_addresses, const grpc_lb_user_data_vtable* user_data_vtable) { grpc_lb_addresses* addresses = - (grpc_lb_addresses*)gpr_zalloc(sizeof(grpc_lb_addresses)); + static_cast(gpr_zalloc(sizeof(grpc_lb_addresses))); addresses->num_addresses = num_addresses; addresses->user_data_vtable = user_data_vtable; const size_t addresses_size = sizeof(grpc_lb_address) * num_addresses; - addresses->addresses = (grpc_lb_address*)gpr_zalloc(addresses_size); + addresses->addresses = static_cast(gpr_zalloc(addresses_size)); return addresses; } @@ -124,14 +124,14 @@ void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { } static void* lb_addresses_copy(void* addresses) { - return grpc_lb_addresses_copy((grpc_lb_addresses*)addresses); + return grpc_lb_addresses_copy(static_cast(addresses)); } static void lb_addresses_destroy(void* addresses) { - grpc_lb_addresses_destroy((grpc_lb_addresses*)addresses); + grpc_lb_addresses_destroy(static_cast(addresses)); } static int lb_addresses_cmp(void* addresses1, void* addresses2) { - return grpc_lb_addresses_cmp((grpc_lb_addresses*)addresses1, - (grpc_lb_addresses*)addresses2); + return grpc_lb_addresses_cmp(static_cast(addresses1), + static_cast(addresses2)); } static const grpc_arg_pointer_vtable lb_addresses_arg_vtable = { lb_addresses_copy, lb_addresses_destroy, lb_addresses_cmp}; @@ -148,7 +148,7 @@ grpc_lb_addresses* grpc_lb_addresses_find_channel_arg( grpc_channel_args_find(channel_args, GRPC_ARG_LB_ADDRESSES); if (lb_addresses_arg == nullptr || lb_addresses_arg->type != GRPC_ARG_POINTER) return nullptr; - return (grpc_lb_addresses*)lb_addresses_arg->value.pointer.p; + return static_cast(lb_addresses_arg->value.pointer.p); } void grpc_lb_policy_factory_ref(grpc_lb_policy_factory* factory) { diff --git a/src/core/ext/filters/client_channel/parse_address.cc b/src/core/ext/filters/client_channel/parse_address.cc index 4b6905eaa3..c95560dd82 100644 --- a/src/core/ext/filters/client_channel/parse_address.cc +++ b/src/core/ext/filters/client_channel/parse_address.cc @@ -40,7 +40,7 @@ bool grpc_parse_unix(const grpc_uri* uri, gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme); return false; } - struct sockaddr_un* un = (struct sockaddr_un*)resolved_addr->addr; + struct sockaddr_un* un = reinterpret_cast(resolved_addr->addr); const size_t maxlen = sizeof(un->sun_path); const size_t path_len = strnlen(uri->path, maxlen); if (path_len == maxlen) return false; @@ -69,7 +69,7 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, // Parse IP address. memset(addr, 0, sizeof(*addr)); addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in* in = (struct sockaddr_in*)addr->addr; + struct sockaddr_in* in = reinterpret_cast(addr->addr); in->sin_family = AF_INET; if (inet_pton(AF_INET, host, &in->sin_addr) == 0) { if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); @@ -85,7 +85,7 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); goto done; } - in->sin_port = htons((uint16_t)port_num); + in->sin_port = htons(static_cast(port_num)); success = true; done: gpr_free(host); @@ -115,14 +115,14 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, // Parse IP address. memset(addr, 0, sizeof(*addr)); addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6* in6 = (struct sockaddr_in6*)addr->addr; + struct sockaddr_in6* in6 = reinterpret_cast(addr->addr); in6->sin6_family = AF_INET6; // Handle the RFC6874 syntax for IPv6 zone identifiers. - char* host_end = (char*)gpr_memrchr(host, '%', strlen(host)); + char* host_end = static_cast(gpr_memrchr(host, '%', strlen(host))); if (host_end != nullptr) { GPR_ASSERT(host_end >= host); char host_without_scope[INET6_ADDRSTRLEN]; - size_t host_without_scope_len = (size_t)(host_end - host); + size_t host_without_scope_len = static_cast(host_end - host); uint32_t sin6_scope_id = 0; strncpy(host_without_scope, host, host_without_scope_len); host_without_scope[host_without_scope_len] = '\0'; @@ -154,7 +154,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); goto done; } - in6->sin6_port = htons((uint16_t)port_num); + in6->sin6_port = htons(static_cast(port_num)); success = true; done: gpr_free(host); diff --git a/src/core/ext/filters/client_channel/proxy_mapper_registry.cc b/src/core/ext/filters/client_channel/proxy_mapper_registry.cc index 51778a20cc..b42597e363 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +++ b/src/core/ext/filters/client_channel/proxy_mapper_registry.cc @@ -34,8 +34,8 @@ typedef struct { static void grpc_proxy_mapper_list_register(grpc_proxy_mapper_list* list, bool at_start, grpc_proxy_mapper* mapper) { - list->list = (grpc_proxy_mapper**)gpr_realloc( - list->list, (list->num_mappers + 1) * sizeof(grpc_proxy_mapper*)); + list->list = static_cast(gpr_realloc( + list->list, (list->num_mappers + 1) * sizeof(grpc_proxy_mapper*))); if (at_start) { memmove(list->list + 1, list->list, sizeof(grpc_proxy_mapper*) * list->num_mappers); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 6e03ae447f..9e3a8c891e 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -312,7 +312,7 @@ void AresDnsResolver::OnResolvedLocked(void* arg, grpc_error* error) { if (lb_policy_name != nullptr) { args_to_remove[num_args_to_remove++] = GRPC_ARG_LB_POLICY_NAME; new_args[num_args_to_add++] = grpc_channel_arg_string_create( - (char*)GRPC_ARG_LB_POLICY_NAME, (char*)lb_policy_name); + (char*)GRPC_ARG_LB_POLICY_NAME, const_cast(lb_policy_name)); } } } 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 2bf86f82b0..3b23b53e60 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 @@ -124,7 +124,7 @@ static void fd_node_shutdown(fd_node* fdn) { grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, grpc_pollset_set* pollset_set) { - *ev_driver = (grpc_ares_ev_driver*)gpr_malloc(sizeof(grpc_ares_ev_driver)); + *ev_driver = static_cast(gpr_malloc(sizeof(grpc_ares_ev_driver))); int status = ares_init(&(*ev_driver)->channel); gpr_log(GPR_DEBUG, "grpc_ares_ev_driver_create"); if (status != ARES_SUCCESS) { @@ -195,7 +195,7 @@ static bool grpc_ares_is_fd_still_readable(grpc_ares_ev_driver* ev_driver, } static void on_readable_cb(void* arg, grpc_error* error) { - fd_node* fdn = (fd_node*)arg; + fd_node* fdn = static_cast(arg); grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); const int fd = grpc_fd_wrapped_fd(fdn->fd); @@ -229,7 +229,7 @@ static void on_readable_cb(void* arg, grpc_error* error) { } static void on_writable_cb(void* arg, grpc_error* error) { - fd_node* fdn = (fd_node*)arg; + fd_node* fdn = static_cast(arg); grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); const int fd = grpc_fd_wrapped_fd(fdn->fd); @@ -280,7 +280,7 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { if (fdn == nullptr) { char* fd_name; gpr_asprintf(&fd_name, "ares_ev_driver-%" PRIuPTR, i); - fdn = (fd_node*)gpr_malloc(sizeof(fd_node)); + fdn = static_cast(gpr_malloc(sizeof(fd_node))); gpr_log(GPR_DEBUG, "new fd: %d", socks[i]); fdn->fd = grpc_fd_create(socks[i], fd_name); fdn->ev_driver = ev_driver; 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 3ec1b6f9fe..93f5f44fa6 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 @@ -88,7 +88,7 @@ static uint16_t strhtons(const char* port) { } else if (strcmp(port, "https") == 0) { return htons(443); } - return htons((unsigned short)atoi(port)); + return htons(static_cast(atoi(port))); } static void grpc_ares_request_ref(grpc_ares_request* r) { @@ -110,8 +110,8 @@ static void grpc_ares_request_unref(grpc_ares_request* r) { static grpc_ares_hostbyname_request* create_hostbyname_request( grpc_ares_request* parent_request, char* host, uint16_t port, bool is_balancer) { - grpc_ares_hostbyname_request* hr = (grpc_ares_hostbyname_request*)gpr_zalloc( - sizeof(grpc_ares_hostbyname_request)); + grpc_ares_hostbyname_request* hr = static_cast(gpr_zalloc( + sizeof(grpc_ares_hostbyname_request))); hr->parent_request = parent_request; hr->host = gpr_strdup(host); hr->port = port; @@ -128,7 +128,7 @@ static void destroy_hostbyname_request(grpc_ares_hostbyname_request* hr) { static void on_hostbyname_done_cb(void* arg, int status, int timeouts, struct hostent* hostent) { - grpc_ares_hostbyname_request* hr = (grpc_ares_hostbyname_request*)arg; + grpc_ares_hostbyname_request* hr = static_cast(arg); grpc_ares_request* r = hr->parent_request; gpr_mu_lock(&r->mu); if (status == ARES_SUCCESS) { @@ -144,9 +144,9 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, for (i = 0; hostent->h_addr_list[i] != nullptr; i++) { } (*lb_addresses)->num_addresses += i; - (*lb_addresses)->addresses = (grpc_lb_address*)gpr_realloc( + (*lb_addresses)->addresses = static_cast(gpr_realloc( (*lb_addresses)->addresses, - sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses); + sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses)); for (i = prev_naddr; i < (*lb_addresses)->num_addresses; i++) { switch (hostent->h_addrtype) { case AF_INET6: { @@ -155,7 +155,7 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, memset(&addr, 0, addr_len); memcpy(&addr.sin6_addr, hostent->h_addr_list[i - prev_naddr], sizeof(struct in6_addr)); - addr.sin6_family = (sa_family_t)hostent->h_addrtype; + addr.sin6_family = static_cast(hostent->h_addrtype); addr.sin6_port = hr->port; grpc_lb_addresses_set_address( *lb_addresses, i, &addr, addr_len, @@ -176,7 +176,7 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, memset(&addr, 0, addr_len); memcpy(&addr.sin_addr, hostent->h_addr_list[i - prev_naddr], sizeof(struct in_addr)); - addr.sin_family = (sa_family_t)hostent->h_addrtype; + addr.sin_family = static_cast(hostent->h_addrtype); addr.sin_port = hr->port; grpc_lb_addresses_set_address( *lb_addresses, i, &addr, addr_len, @@ -211,7 +211,7 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, static void on_srv_query_done_cb(void* arg, int status, int timeouts, unsigned char* abuf, int alen) { - grpc_ares_request* r = (grpc_ares_request*)arg; + grpc_ares_request* r = static_cast(arg); grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "on_query_srv_done_cb"); if (status == ARES_SUCCESS) { @@ -259,7 +259,7 @@ static void on_txt_done_cb(void* arg, int status, int timeouts, unsigned char* buf, int len) { gpr_log(GPR_DEBUG, "on_txt_done_cb"); char* error_msg; - grpc_ares_request* r = (grpc_ares_request*)arg; + grpc_ares_request* r = static_cast(arg); const size_t prefix_len = sizeof(g_service_config_attribute_prefix) - 1; struct ares_txt_ext* result = nullptr; struct ares_txt_ext* reply = nullptr; @@ -279,13 +279,13 @@ static void on_txt_done_cb(void* arg, int status, int timeouts, // Found a service config record. if (result != nullptr) { size_t service_config_len = result->length - prefix_len; - *r->service_config_json_out = (char*)gpr_malloc(service_config_len + 1); + *r->service_config_json_out = static_cast(gpr_malloc(service_config_len + 1)); memcpy(*r->service_config_json_out, result->txt + prefix_len, service_config_len); for (result = result->next; result != nullptr && !result->record_start; result = result->next) { - *r->service_config_json_out = (char*)gpr_realloc( - *r->service_config_json_out, service_config_len + result->length + 1); + *r->service_config_json_out = static_cast(gpr_realloc( + *r->service_config_json_out, service_config_len + result->length + 1)); memcpy(*r->service_config_json_out + service_config_len, result->txt, result->length); service_config_len += result->length; @@ -348,7 +348,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( error = grpc_ares_ev_driver_create(&ev_driver, interested_parties); if (error != GRPC_ERROR_NONE) goto error_cleanup; - r = (grpc_ares_request*)gpr_zalloc(sizeof(grpc_ares_request)); + r = static_cast(gpr_zalloc(sizeof(grpc_ares_request))); gpr_mu_init(&r->mu); r->ev_driver = ev_driver; r->on_done = on_done; @@ -364,7 +364,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( grpc_resolved_address addr; if (grpc_parse_ipv4_hostport(dns_server, &addr, false /* log_errors */)) { r->dns_server_addr.family = AF_INET; - struct sockaddr_in* in = (struct sockaddr_in*)addr.addr; + struct sockaddr_in* in = reinterpret_cast(addr.addr); memcpy(&r->dns_server_addr.addr.addr4, &in->sin_addr, sizeof(struct in_addr)); r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr); @@ -372,7 +372,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( } else if (grpc_parse_ipv6_hostport(dns_server, &addr, false /* log_errors */)) { r->dns_server_addr.family = AF_INET6; - struct sockaddr_in6* in6 = (struct sockaddr_in6*)addr.addr; + struct sockaddr_in6* in6 = reinterpret_cast(addr.addr); memcpy(&r->dns_server_addr.addr.addr6, &in6->sin6_addr, sizeof(struct in6_addr)); r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr); @@ -487,16 +487,16 @@ typedef struct grpc_resolve_address_ares_request { static void on_dns_lookup_done_cb(void* arg, grpc_error* error) { grpc_resolve_address_ares_request* r = - (grpc_resolve_address_ares_request*)arg; + static_cast(arg); grpc_resolved_addresses** resolved_addresses = r->addrs_out; if (r->lb_addrs == nullptr || r->lb_addrs->num_addresses == 0) { *resolved_addresses = nullptr; } else { *resolved_addresses = - (grpc_resolved_addresses*)gpr_zalloc(sizeof(grpc_resolved_addresses)); + static_cast(gpr_zalloc(sizeof(grpc_resolved_addresses))); (*resolved_addresses)->naddrs = r->lb_addrs->num_addresses; - (*resolved_addresses)->addrs = (grpc_resolved_address*)gpr_zalloc( - sizeof(grpc_resolved_address) * (*resolved_addresses)->naddrs); + (*resolved_addresses)->addrs = static_cast(gpr_zalloc( + sizeof(grpc_resolved_address) * (*resolved_addresses)->naddrs)); for (size_t i = 0; i < (*resolved_addresses)->naddrs; i++) { GPR_ASSERT(!r->lb_addrs->addresses[i].is_balancer); memcpy(&(*resolved_addresses)->addrs[i], @@ -514,8 +514,8 @@ static void grpc_resolve_address_ares_impl(const char* name, grpc_closure* on_done, grpc_resolved_addresses** addrs) { grpc_resolve_address_ares_request* r = - (grpc_resolve_address_ares_request*)gpr_zalloc( - sizeof(grpc_resolve_address_ares_request)); + static_cast(gpr_zalloc( + sizeof(grpc_resolve_address_ares_request))); r->addrs_out = addrs; r->on_resolve_address_done = on_done; GRPC_CLOSURE_INIT(&r->on_dns_lookup_done, on_dns_lookup_done_cb, r, diff --git a/src/core/ext/filters/client_channel/retry_throttle.cc b/src/core/ext/filters/client_channel/retry_throttle.cc index 0d38feb242..d1e0820560 100644 --- a/src/core/ext/filters/client_channel/retry_throttle.cc +++ b/src/core/ext/filters/client_channel/retry_throttle.cc @@ -59,9 +59,9 @@ bool grpc_server_retry_throttle_data_record_failure( // First, check if we are stale and need to be replaced. get_replacement_throttle_data_if_needed(&throttle_data); // We decrement milli_tokens by 1000 (1 token) for each failure. - const int new_value = (int)gpr_atm_no_barrier_clamped_add( - &throttle_data->milli_tokens, (gpr_atm)-1000, (gpr_atm)0, - (gpr_atm)throttle_data->max_milli_tokens); + const int new_value = static_cast(gpr_atm_no_barrier_clamped_add( + &throttle_data->milli_tokens, static_cast(-1000), static_cast(0), + static_cast(throttle_data->max_milli_tokens))); // Retries are allowed as long as the new value is above the threshold // (max_milli_tokens / 2). return new_value > throttle_data->max_milli_tokens / 2; @@ -73,8 +73,8 @@ void grpc_server_retry_throttle_data_record_success( get_replacement_throttle_data_if_needed(&throttle_data); // We increment milli_tokens by milli_token_ratio for each success. gpr_atm_no_barrier_clamped_add( - &throttle_data->milli_tokens, (gpr_atm)throttle_data->milli_token_ratio, - (gpr_atm)0, (gpr_atm)throttle_data->max_milli_tokens); + &throttle_data->milli_tokens, static_cast(throttle_data->milli_token_ratio), + static_cast(0), static_cast(throttle_data->max_milli_tokens)); } grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_ref( @@ -100,7 +100,7 @@ static grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_create( int max_milli_tokens, int milli_token_ratio, grpc_server_retry_throttle_data* old_throttle_data) { grpc_server_retry_throttle_data* throttle_data = - (grpc_server_retry_throttle_data*)gpr_malloc(sizeof(*throttle_data)); + static_cast(gpr_malloc(sizeof(*throttle_data))); memset(throttle_data, 0, sizeof(*throttle_data)); gpr_ref_init(&throttle_data->refs, 1); throttle_data->max_milli_tokens = max_milli_tokens; @@ -112,9 +112,9 @@ static grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_create( // we will start out doing the same thing on the new one. if (old_throttle_data != nullptr) { double token_fraction = - (int)gpr_atm_acq_load(&old_throttle_data->milli_tokens) / - (double)old_throttle_data->max_milli_tokens; - initial_milli_tokens = (int)(token_fraction * max_milli_tokens); + static_castgpr_atm_acq_load(&old_throttle_data->milli_tokens) / + static_cast(old_throttle_data->max_milli_tokens); + initial_milli_tokens = static_cast(token_fraction * max_milli_tokens); } gpr_atm_rel_store(&throttle_data->milli_tokens, (gpr_atm)initial_milli_tokens); @@ -132,22 +132,22 @@ static grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_create( // static void* copy_server_name(void* key, void* unused) { - return gpr_strdup((const char*)key); + return gpr_strdup(static_cast(key)); } static long compare_server_name(void* key1, void* key2, void* unused) { - return strcmp((const char*)key1, (const char*)key2); + return strcmp(static_cast(key1), static_cast(key2)); } static void destroy_server_retry_throttle_data(void* value, void* unused) { grpc_server_retry_throttle_data* throttle_data = - (grpc_server_retry_throttle_data*)value; + static_cast(value); grpc_server_retry_throttle_data_unref(throttle_data); } static void* copy_server_retry_throttle_data(void* value, void* unused) { grpc_server_retry_throttle_data* throttle_data = - (grpc_server_retry_throttle_data*)value; + static_cast(value); return grpc_server_retry_throttle_data_ref(throttle_data); } @@ -178,13 +178,13 @@ grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server( const char* server_name, int max_milli_tokens, int milli_token_ratio) { gpr_mu_lock(&g_mu); grpc_server_retry_throttle_data* throttle_data = - (grpc_server_retry_throttle_data*)grpc_avl_get(g_avl, (char*)server_name, - nullptr); + static_cast(grpc_avl_get(g_avl, const_cast(server_name), + nullptr)); if (throttle_data == nullptr) { // Entry not found. Create a new one. throttle_data = grpc_server_retry_throttle_data_create( max_milli_tokens, milli_token_ratio, nullptr); - g_avl = grpc_avl_add(g_avl, (char*)server_name, throttle_data, nullptr); + g_avl = grpc_avl_add(g_avl, const_cast(server_name), throttle_data, nullptr); } else { if (throttle_data->max_milli_tokens != max_milli_tokens || throttle_data->milli_token_ratio != milli_token_ratio) { @@ -192,7 +192,7 @@ grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server( // the original one. throttle_data = grpc_server_retry_throttle_data_create( max_milli_tokens, milli_token_ratio, throttle_data); - g_avl = grpc_avl_add(g_avl, (char*)server_name, throttle_data, nullptr); + g_avl = grpc_avl_add(g_avl, const_cast(server_name), throttle_data, nullptr); } else { // Entry found. Increase refcount. grpc_server_retry_throttle_data_ref(throttle_data); diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 6d4c4f931e..55b11b89d9 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -159,7 +159,7 @@ static void on_subchannel_connected(void* subchannel, grpc_error* error); */ static void connection_destroy(void* arg, grpc_error* error) { - grpc_channel_stack* stk = (grpc_channel_stack*)arg; + grpc_channel_stack* stk = static_cast(arg); grpc_channel_stack_destroy(stk); gpr_free(stk); } @@ -169,7 +169,7 @@ static void connection_destroy(void* arg, grpc_error* error) { */ static void subchannel_destroy(void* arg, grpc_error* error) { - grpc_subchannel* c = (grpc_subchannel*)arg; + grpc_subchannel* c = static_cast(arg); gpr_free((void*)c->filters); grpc_channel_args_destroy(c->args); grpc_connectivity_state_destroy(&c->state_tracker); @@ -241,7 +241,7 @@ static void disconnect(grpc_subchannel* c) { void grpc_subchannel_unref(grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; // add a weak ref and subtract a strong ref (atomically) - old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS), + old_refs = ref_mutate(c, static_cast(1) - static_cast(1 << INTERNAL_REF_BITS), 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) { disconnect(c); @@ -252,7 +252,7 @@ void grpc_subchannel_unref(grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { void grpc_subchannel_weak_unref( grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; - old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); + old_refs = ref_mutate(c, -static_cast(1), 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); if (old_refs == 1) { GRPC_CLOSURE_SCHED( GRPC_CLOSURE_CREATE(subchannel_destroy, c, grpc_schedule_on_exec_ctx), @@ -318,15 +318,15 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, } GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(); - c = (grpc_subchannel*)gpr_zalloc(sizeof(*c)); + c = static_cast(gpr_zalloc(sizeof(*c))); c->key = key; gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS); c->connector = connector; grpc_connector_ref(c->connector); c->num_filters = args->filter_count; if (c->num_filters > 0) { - c->filters = (const grpc_channel_filter**)gpr_malloc( - sizeof(grpc_channel_filter*) * c->num_filters); + c->filters = static_cast(gpr_malloc( + sizeof(grpc_channel_filter*) * c->num_filters)); memcpy((void*)c->filters, args->filters, sizeof(grpc_channel_filter*) * c->num_filters); } else { @@ -334,7 +334,7 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, } c->pollset_set = grpc_pollset_set_create(); grpc_resolved_address* addr = - (grpc_resolved_address*)gpr_malloc(sizeof(*addr)); + static_cast(gpr_malloc(sizeof(*addr))); grpc_get_subchannel_address_arg(args->args, addr); grpc_resolved_address* new_address = nullptr; grpc_channel_args* new_args = nullptr; @@ -391,7 +391,7 @@ grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel* c, } static void on_external_state_watcher_done(void* arg, grpc_error* error) { - external_state_watcher* w = (external_state_watcher*)arg; + external_state_watcher* w = static_cast(arg); grpc_closure* follow_up = w->notify; if (w->pollset_set != nullptr) { grpc_pollset_set_del_pollset_set(w->subchannel->pollset_set, @@ -407,7 +407,7 @@ static void on_external_state_watcher_done(void* arg, grpc_error* error) { } static void on_alarm(void* arg, grpc_error* error) { - grpc_subchannel* c = (grpc_subchannel*)arg; + grpc_subchannel* c = static_cast(arg); gpr_mu_lock(&c->mu); c->have_alarm = false; if (c->disconnected) { @@ -486,7 +486,7 @@ void grpc_subchannel_notify_on_state_change( } gpr_mu_unlock(&c->mu); } else { - w = (external_state_watcher*)gpr_malloc(sizeof(*w)); + w = static_cast(gpr_malloc(sizeof(*w))); w->subchannel = c; w->pollset_set = interested_parties; w->notify = notify; @@ -509,7 +509,7 @@ void grpc_subchannel_notify_on_state_change( static void on_connected_subchannel_connectivity_changed(void* p, grpc_error* error) { - state_watcher* connected_subchannel_watcher = (state_watcher*)p; + state_watcher* connected_subchannel_watcher = static_cast(p); grpc_subchannel* c = connected_subchannel_watcher->subchannel; gpr_mu* mu = &c->mu; @@ -570,7 +570,7 @@ static bool publish_transport_locked(grpc_subchannel* c) { } grpc_channel_stack* stk; grpc_error* error = grpc_channel_stack_builder_finish( - builder, 0, 1, connection_destroy, nullptr, (void**)&stk); + builder, 0, 1, connection_destroy, nullptr, reinterpret_cast(&stk)); if (error != GRPC_ERROR_NONE) { grpc_transport_destroy(c->connecting_result.transport); gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", @@ -582,7 +582,7 @@ static bool publish_transport_locked(grpc_subchannel* c) { /* initialize state watcher */ state_watcher* connected_subchannel_watcher = - (state_watcher*)gpr_zalloc(sizeof(*connected_subchannel_watcher)); + static_cast(gpr_zalloc(sizeof(*connected_subchannel_watcher))); connected_subchannel_watcher->subchannel = c; connected_subchannel_watcher->connectivity_state = GRPC_CHANNEL_READY; GRPC_CLOSURE_INIT(&connected_subchannel_watcher->closure, @@ -617,7 +617,7 @@ static bool publish_transport_locked(grpc_subchannel* c) { } static void on_subchannel_connected(void* arg, grpc_error* error) { - grpc_subchannel* c = (grpc_subchannel*)arg; + grpc_subchannel* c = static_cast(arg); grpc_channel_args* delete_channel_args = c->connecting_result.channel_args; GRPC_SUBCHANNEL_WEAK_REF(c, "on_subchannel_connected"); @@ -653,7 +653,7 @@ static void on_subchannel_connected(void* arg, grpc_error* error) { static void subchannel_call_destroy(void* call, grpc_error* error) { GPR_TIMER_SCOPE("grpc_subchannel_call_unref.destroy", 0); - grpc_subchannel_call* c = (grpc_subchannel_call*)call; + grpc_subchannel_call* c = static_cast(call); GPR_ASSERT(c->schedule_closure_after_destroy != nullptr); grpc_core::ConnectedSubchannel* connection = c->connection; grpc_call_stack_destroy(SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr, @@ -770,9 +770,9 @@ void ConnectedSubchannel::Ping(grpc_closure* on_initiate, grpc_error* ConnectedSubchannel::CreateCall(const CallArgs& args, grpc_subchannel_call** call) { - *call = (grpc_subchannel_call*)gpr_arena_alloc( + *call = static_cast(gpr_arena_alloc( args.arena, - sizeof(grpc_subchannel_call) + channel_stack_->call_stack_size); + sizeof(grpc_subchannel_call) + channel_stack_->call_stack_size)); grpc_call_stack* callstk = SUBCHANNEL_CALL_TO_CALL_STACK(*call); RefCountedPtr connection = Ref(DEBUG_LOCATION, "subchannel_call"); diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index 69dbdccc18..2deafb380b 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -45,12 +45,12 @@ static bool g_force_creation = false; static grpc_subchannel_key* create_key( const grpc_subchannel_args* args, grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args)) { - grpc_subchannel_key* k = (grpc_subchannel_key*)gpr_malloc(sizeof(*k)); + grpc_subchannel_key* k = static_cast(gpr_malloc(sizeof(*k))); k->args.filter_count = args->filter_count; if (k->args.filter_count > 0) { - k->args.filters = (const grpc_channel_filter**)gpr_malloc( - sizeof(*k->args.filters) * k->args.filter_count); - memcpy((grpc_channel_filter*)k->args.filters, args->filters, + k->args.filters = static_cast(gpr_malloc( + sizeof(*k->args.filters) * k->args.filter_count)); + memcpy(reinterpret_cast(k->args.filters), args->filters, sizeof(*k->args.filters) * k->args.filter_count); } else { k->args.filters = nullptr; @@ -82,22 +82,22 @@ int grpc_subchannel_key_compare(const grpc_subchannel_key* a, } void grpc_subchannel_key_destroy(grpc_subchannel_key* k) { - gpr_free((grpc_channel_args*)k->args.filters); - grpc_channel_args_destroy((grpc_channel_args*)k->args.args); + gpr_free(reinterpret_cast(k->args.filters)); + grpc_channel_args_destroy(const_cast(k->args.args)); gpr_free(k); } static void sck_avl_destroy(void* p, void* user_data) { - grpc_subchannel_key_destroy((grpc_subchannel_key*)p); + grpc_subchannel_key_destroy(static_cast(p)); } static void* sck_avl_copy(void* p, void* unused) { - return subchannel_key_copy((grpc_subchannel_key*)p); + return subchannel_key_copy(static_cast(p)); } static long sck_avl_compare(void* a, void* b, void* unused) { - return grpc_subchannel_key_compare((grpc_subchannel_key*)a, - (grpc_subchannel_key*)b); + return grpc_subchannel_key_compare(static_cast(a), + static_cast(b)); } static void scv_avl_destroy(void* p, void* user_data) { @@ -170,7 +170,7 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = (grpc_subchannel*)grpc_avl_get(index, key, grpc_core::ExecCtx::Get()); + c = static_cast(grpc_avl_get(index, key, grpc_core::ExecCtx::Get())); if (c != nullptr) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -221,7 +221,7 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, // Check to see if this key still refers to the previously // registered subchannel grpc_subchannel* c = - (grpc_subchannel*)grpc_avl_get(index, key, grpc_core::ExecCtx::Get()); + static_cast(grpc_avl_get(index, key, grpc_core::ExecCtx::Get())); if (c != constructed) { grpc_avl_unref(index, grpc_core::ExecCtx::Get()); break; diff --git a/src/core/ext/filters/client_channel/uri_parser.cc b/src/core/ext/filters/client_channel/uri_parser.cc index c5f2d6822c..cd07a6fbf5 100644 --- a/src/core/ext/filters/client_channel/uri_parser.cc +++ b/src/core/ext/filters/client_channel/uri_parser.cc @@ -45,7 +45,7 @@ static grpc_uri* bad_uri(const char* uri_text, size_t pos, const char* section, gpr_log(GPR_ERROR, "%s%s'", line_prefix, uri_text); gpr_free(line_prefix); - line_prefix = (char*)gpr_malloc(pfx_len + 1); + line_prefix = static_cast(gpr_malloc(pfx_len + 1)); memset(line_prefix, ' ', pfx_len); line_prefix[pfx_len] = 0; gpr_log(GPR_ERROR, "%s^ here", line_prefix); @@ -159,7 +159,7 @@ static void parse_query_parts(grpc_uri* uri) { gpr_string_split(uri->query, QUERY_PARTS_SEPARATOR, &uri->query_parts, &uri->num_query_parts); uri->query_parts_values = - (char**)gpr_malloc(uri->num_query_parts * sizeof(char**)); + static_cast(gpr_malloc(uri->num_query_parts * sizeof(char**))); for (size_t i = 0; i < uri->num_query_parts; i++) { char** query_param_parts; size_t num_query_param_parts; @@ -271,7 +271,7 @@ grpc_uri* grpc_uri_parse(const char* uri_text, bool suppress_errors) { fragment_end = i; } - uri = (grpc_uri*)gpr_zalloc(sizeof(*uri)); + uri = static_cast(gpr_zalloc(sizeof(*uri))); uri->scheme = decode_and_copy_component(uri_text, scheme_begin, scheme_end); uri->authority = decode_and_copy_component(uri_text, authority_begin, authority_end); diff --git a/src/core/ext/filters/deadline/deadline_filter.cc b/src/core/ext/filters/deadline/deadline_filter.cc index c430f3d2d4..a936d17e8d 100644 --- a/src/core/ext/filters/deadline/deadline_filter.cc +++ b/src/core/ext/filters/deadline/deadline_filter.cc @@ -37,7 +37,7 @@ // The on_complete callback used when sending a cancel_error batch down the // filter stack. Yields the call combiner when the batch returns. static void yield_call_combiner(void* arg, grpc_error* ignored) { - grpc_deadline_state* deadline_state = (grpc_deadline_state*)arg; + grpc_deadline_state* deadline_state = static_cast(arg); GRPC_CALL_COMBINER_STOP(deadline_state->call_combiner, "got on_complete from cancel_stream batch"); GRPC_CALL_STACK_UNREF(deadline_state->call_stack, "deadline_timer"); @@ -46,8 +46,8 @@ static void yield_call_combiner(void* arg, grpc_error* ignored) { // This is called via the call combiner, so access to deadline_state is // synchronized. static void send_cancel_op_in_call_combiner(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + grpc_deadline_state* deadline_state = static_cast(elem->call_data); grpc_transport_stream_op_batch* batch = grpc_make_transport_stream_op( GRPC_CLOSURE_INIT(&deadline_state->timer_callback, yield_call_combiner, deadline_state, grpc_schedule_on_exec_ctx)); @@ -58,8 +58,8 @@ static void send_cancel_op_in_call_combiner(void* arg, grpc_error* error) { // Timer callback. static void timer_callback(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + grpc_deadline_state* deadline_state = static_cast(elem->call_data); if (error != GRPC_ERROR_CANCELLED) { error = grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Deadline Exceeded"), @@ -85,7 +85,7 @@ static void start_timer_if_needed(grpc_call_element* elem, if (deadline == GRPC_MILLIS_INF_FUTURE) { return; } - grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; + grpc_deadline_state* deadline_state = static_cast(elem->call_data); grpc_closure* closure = nullptr; switch (deadline_state->timer_state) { case GRPC_DEADLINE_STATE_PENDING: @@ -126,7 +126,7 @@ static void cancel_timer_if_needed(grpc_deadline_state* deadline_state) { // Callback run when the call is complete. static void on_complete(void* arg, grpc_error* error) { - grpc_deadline_state* deadline_state = (grpc_deadline_state*)arg; + grpc_deadline_state* deadline_state = static_cast(arg); cancel_timer_if_needed(deadline_state); // Invoke the next callback. GRPC_CLOSURE_RUN(deadline_state->next_on_complete, GRPC_ERROR_REF(error)); @@ -151,9 +151,9 @@ struct start_timer_after_init_state { }; static void start_timer_after_init(void* arg, grpc_error* error) { struct start_timer_after_init_state* state = - (struct start_timer_after_init_state*)arg; + static_cast(arg); grpc_deadline_state* deadline_state = - (grpc_deadline_state*)state->elem->call_data; + static_cast(state->elem->call_data); if (!state->in_call_combiner) { // We are initially called without holding the call combiner, so we // need to bounce ourselves into it. @@ -173,7 +173,7 @@ void grpc_deadline_state_init(grpc_call_element* elem, grpc_call_stack* call_stack, grpc_call_combiner* call_combiner, grpc_millis deadline) { - grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; + grpc_deadline_state* deadline_state = static_cast(elem->call_data); deadline_state->call_stack = call_stack; deadline_state->call_combiner = call_combiner; // Deadline will always be infinite on servers, so the timer will only be @@ -187,7 +187,7 @@ void grpc_deadline_state_init(grpc_call_element* elem, // create a closure to start the timer, and we schedule that closure // to be run after call stack initialization is done. struct start_timer_after_init_state* state = - (struct start_timer_after_init_state*)gpr_zalloc(sizeof(*state)); + static_cast(gpr_zalloc(sizeof(*state))); state->elem = elem; state->deadline = deadline; GRPC_CLOSURE_INIT(&state->closure, start_timer_after_init, state, @@ -197,20 +197,20 @@ void grpc_deadline_state_init(grpc_call_element* elem, } void grpc_deadline_state_destroy(grpc_call_element* elem) { - grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; + grpc_deadline_state* deadline_state = static_cast(elem->call_data); cancel_timer_if_needed(deadline_state); } void grpc_deadline_state_reset(grpc_call_element* elem, grpc_millis new_deadline) { - grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; + grpc_deadline_state* deadline_state = static_cast(elem->call_data); cancel_timer_if_needed(deadline_state); start_timer_if_needed(elem, new_deadline); } void grpc_deadline_state_client_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; + grpc_deadline_state* deadline_state = static_cast(elem->call_data); if (op->cancel_stream) { cancel_timer_if_needed(deadline_state); } else { @@ -278,8 +278,8 @@ static void client_start_transport_stream_op_batch( // Callback for receiving initial metadata on the server. static void recv_initial_metadata_ready(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - server_call_data* calld = (server_call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + server_call_data* calld = static_cast(elem->call_data); // Get deadline from metadata and start the timer if needed. start_timer_if_needed(elem, calld->recv_initial_metadata->deadline); // Invoke the next callback. @@ -290,7 +290,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) { // Method for starting a call op for server filter. static void server_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - server_call_data* calld = (server_call_data*)elem->call_data; + server_call_data* calld = static_cast(elem->call_data); if (op->cancel_stream) { cancel_timer_if_needed(&calld->base.deadline_state); } else { @@ -360,7 +360,7 @@ static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder, return grpc_deadline_checking_enabled( grpc_channel_stack_builder_get_channel_arguments(builder)) ? grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, nullptr, nullptr) + builder, static_cast(arg), nullptr, nullptr) : true; } diff --git a/src/core/ext/filters/http/client/http_client_filter.cc b/src/core/ext/filters/http/client/http_client_filter.cc index befd5a3c28..aabc405bec 100644 --- a/src/core/ext/filters/http/client/http_client_filter.cc +++ b/src/core/ext/filters/http/client/http_client_filter.cc @@ -138,8 +138,8 @@ static grpc_error* client_filter_incoming_metadata(grpc_call_element* elem, } static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (error == GRPC_ERROR_NONE) { error = client_filter_incoming_metadata(elem, calld->recv_initial_metadata); } else { @@ -150,8 +150,8 @@ static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { static void recv_trailing_metadata_on_complete(void* user_data, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (error == GRPC_ERROR_NONE) { error = client_filter_incoming_metadata(elem, calld->recv_trailing_metadata); @@ -162,8 +162,8 @@ static void recv_trailing_metadata_on_complete(void* user_data, } static void send_message_on_complete(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); grpc_byte_stream_cache_destroy(&calld->send_message_cache); GRPC_CLOSURE_RUN(calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); @@ -189,7 +189,7 @@ static grpc_error* pull_slice_from_send_message(call_data* calld) { // and on_send_message_next_done() will be invoked when it is complete. static grpc_error* read_all_available_send_message_data(call_data* calld) { while (grpc_byte_stream_next(&calld->send_message_caching_stream.base, - ~(size_t)0, &calld->on_send_message_next_done)) { + ~static_cast(0), &calld->on_send_message_next_done)) { grpc_error* error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) return error; if (calld->send_message_bytes_read == @@ -202,8 +202,8 @@ static grpc_error* read_all_available_send_message_data(call_data* calld) { // Async callback for grpc_byte_stream_next(). static void on_send_message_next_done(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( calld->send_message_batch, error, calld->call_combiner); @@ -224,7 +224,7 @@ static void on_send_message_next_done(void* arg, grpc_error* error) { } static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { - char* payload_bytes = (char*)gpr_malloc(slice_buffer->length + 1); + char* payload_bytes = static_cast(gpr_malloc(slice_buffer->length + 1)); size_t offset = 0; for (size_t i = 0; i < slice_buffer->count; ++i) { memcpy(payload_bytes + offset, @@ -240,7 +240,7 @@ static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { // append the base64-encoded query for a GET request. static grpc_error* update_path_for_get(grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_slice path_slice = GRPC_MDVALUE(batch->payload->send_initial_metadata.send_initial_metadata ->idx.named.path->md); @@ -253,19 +253,19 @@ static grpc_error* update_path_for_get(grpc_call_element* elem, false /* multi_line */); grpc_slice path_with_query_slice = GRPC_SLICE_MALLOC(estimated_len); /* memcopy individual pieces into this slice */ - char* write_ptr = (char*)GRPC_SLICE_START_PTR(path_with_query_slice); - char* original_path = (char*)GRPC_SLICE_START_PTR(path_slice); + char* write_ptr = reinterpret_castGRPC_SLICE_START_PTR(path_with_query_slice); + char* original_path = reinterpret_castGRPC_SLICE_START_PTR(path_slice); memcpy(write_ptr, original_path, GRPC_SLICE_LENGTH(path_slice)); write_ptr += GRPC_SLICE_LENGTH(path_slice); *write_ptr++ = '?'; char* payload_bytes = slice_buffer_to_string(&calld->send_message_cache.cache_buffer); - grpc_base64_encode_core((char*)write_ptr, payload_bytes, + grpc_base64_encode_core(write_ptr, payload_bytes, batch->payload->send_message.send_message->length, true /* url_safe */, false /* multi_line */); gpr_free(payload_bytes); /* remove trailing unused memory and add trailing 0 to terminate string */ - char* t = (char*)GRPC_SLICE_START_PTR(path_with_query_slice); + char* t = reinterpret_castGRPC_SLICE_START_PTR(path_with_query_slice); /* safe to use strlen since base64_encode will always add '\0' */ path_with_query_slice = grpc_slice_sub_no_ref(path_with_query_slice, 0, strlen(t)); @@ -287,8 +287,8 @@ static void remove_if_present(grpc_metadata_batch* batch, static void hc_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { - call_data* calld = (call_data*)elem->call_data; - channel_data* channeld = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* channeld = static_cast(elem->channel_data); GPR_TIMER_SCOPE("hc_start_transport_stream_op_batch", 0); if (batch->recv_initial_metadata) { @@ -409,7 +409,7 @@ done: /* Constructor for call_data */ static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); calld->call_combiner = args->call_combiner; GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready, recv_initial_metadata_ready, elem, @@ -458,7 +458,7 @@ static size_t max_payload_size_from_args(const grpc_channel_args* args) { gpr_log(GPR_ERROR, "%s: must be an integer", GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET); } else { - return (size_t)args->args[i].value.integer; + return static_cast(args->args[i].value.integer); } } } @@ -519,7 +519,7 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args, /* Constructor for channel_data */ static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); GPR_ASSERT(!args->is_last); GPR_ASSERT(args->optional_transport != nullptr); chand->static_scheme = scheme_from_args(args->channel_args); @@ -534,7 +534,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, /* Destructor for channel data */ static void destroy_channel_elem(grpc_channel_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); GRPC_MDELEM_UNREF(chand->user_agent); } diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index deec77c96f..b89cb028ea 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -43,7 +43,7 @@ static bool is_building_http_like_transport( static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder, void* arg) { if (!is_building_http_like_transport(builder)) return true; - optional_filter* filtarg = (optional_filter*)arg; + optional_filter* filtarg = static_cast(arg); const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); bool enable = grpc_channel_arg_get_bool( @@ -58,7 +58,7 @@ static bool maybe_add_required_filter(grpc_channel_stack_builder* builder, void* arg) { return is_building_http_like_transport(builder) ? grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, nullptr, nullptr) + builder, static_cast(arg), nullptr, nullptr) : true; } diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index 408301467c..223548d3bf 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -80,8 +80,8 @@ struct channel_data { static bool skip_compression(grpc_call_element* elem, uint32_t flags, bool has_compression_algorithm) { - call_data* calld = (call_data*)elem->call_data; - channel_data* channeld = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* channeld = static_cast(elem->channel_data); if (flags & (GRPC_WRITE_NO_COMPRESS | GRPC_WRITE_INTERNAL_COMPRESS)) { return true; @@ -103,8 +103,8 @@ static grpc_error* process_send_initial_metadata( static grpc_error* process_send_initial_metadata( grpc_call_element* elem, grpc_metadata_batch* initial_metadata, bool* has_compression_algorithm) { - call_data* calld = (call_data*)elem->call_data; - channel_data* channeld = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* channeld = static_cast(elem->channel_data); *has_compression_algorithm = false; grpc_compression_algorithm compression_algorithm; grpc_stream_compression_algorithm stream_compression_algorithm = @@ -194,15 +194,15 @@ static grpc_error* process_send_initial_metadata( } static void send_message_on_complete(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); grpc_slice_buffer_reset_and_unref_internal(&calld->slices); GRPC_CLOSURE_RUN(calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); } static void send_message_batch_continue(grpc_call_element* elem) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); // Note: The call to grpc_call_next_op() results in yielding the // call combiner, so we need to clear calld->send_message_batch // before we do that. @@ -213,7 +213,7 @@ static void send_message_batch_continue(grpc_call_element* elem) { } static void finish_send_message(grpc_call_element* elem) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); // Compress the data if appropriate. grpc_slice_buffer tmp; grpc_slice_buffer_init(&tmp); @@ -226,7 +226,7 @@ static void finish_send_message(grpc_call_element* elem) { const char* algo_name; const size_t before_size = calld->slices.length; const size_t after_size = tmp.length; - const float savings_ratio = 1.0f - (float)after_size / (float)before_size; + const float savings_ratio = 1.0f - static_cast(after_size) / static_cast(before_size); GPR_ASSERT(grpc_message_compression_algorithm_name( calld->message_compression_algorithm, &algo_name)); gpr_log(GPR_DEBUG, @@ -264,7 +264,7 @@ static void finish_send_message(grpc_call_element* elem) { static void fail_send_message_batch_in_call_combiner(void* arg, grpc_error* error) { - call_data* calld = (call_data*)arg; + call_data* calld = static_cast(arg); if (calld->send_message_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( calld->send_message_batch, GRPC_ERROR_REF(error), calld->call_combiner); @@ -289,9 +289,9 @@ static grpc_error* pull_slice_from_send_message(call_data* calld) { // an async call to grpc_byte_stream_next() has been started, which will // eventually result in calling on_send_message_next_done(). static void continue_reading_send_message(grpc_call_element* elem) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); while (grpc_byte_stream_next( - calld->send_message_batch->payload->send_message.send_message, ~(size_t)0, + calld->send_message_batch->payload->send_message.send_message, ~static_cast(0), &calld->on_send_message_next_done)) { grpc_error* error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) { @@ -310,8 +310,8 @@ static void continue_reading_send_message(grpc_call_element* elem) { // Async callback for grpc_byte_stream_next(). static void on_send_message_next_done(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. fail_send_message_batch_in_call_combiner(calld, error); @@ -333,8 +333,8 @@ static void on_send_message_next_done(void* arg, grpc_error* error) { } static void start_send_message_batch(void* arg, grpc_error* unused) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); if (skip_compression( elem, calld->send_message_batch->payload->send_message.send_message->flags, @@ -348,7 +348,7 @@ static void start_send_message_batch(void* arg, grpc_error* unused) { static void compress_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { GPR_TIMER_SCOPE("compress_start_transport_stream_op_batch", 0); - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); // Handle cancel_stream. if (batch->cancel_stream) { GRPC_ERROR_UNREF(calld->cancel_error); @@ -424,7 +424,7 @@ static void compress_start_transport_stream_op_batch( /* Constructor for call_data */ static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); calld->call_combiner = args->call_combiner; calld->cancel_error = GRPC_ERROR_NONE; grpc_slice_buffer_init(&calld->slices); @@ -441,7 +441,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_slice_buffer_destroy_internal(&calld->slices); GRPC_ERROR_UNREF(calld->cancel_error); } @@ -449,7 +449,7 @@ static void destroy_call_elem(grpc_call_element* elem, /* Constructor for channel_data */ static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { - channel_data* channeld = (channel_data*)elem->channel_data; + channel_data* channeld = static_cast(elem->channel_data); channeld->enabled_algorithms_bitset = grpc_channel_args_compression_algorithm_get_states(args->channel_args); diff --git a/src/core/ext/filters/http/server/http_server_filter.cc b/src/core/ext/filters/http/server/http_server_filter.cc index 6ea942f053..560b5795e3 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -95,7 +95,7 @@ static void add_error(const char* error_name, grpc_error** cumulative, static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, grpc_metadata_batch* b) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_error* error = GRPC_ERROR_NONE; static const char* error_name = "Failed processing incoming headers"; @@ -204,7 +204,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, * query parameter which is base64 encoded request payload. */ const char k_query_separator = '?'; grpc_slice path_slice = GRPC_MDVALUE(b->idx.named.path->md); - uint8_t* path_ptr = (uint8_t*)GRPC_SLICE_START_PTR(path_slice); + uint8_t* path_ptr = GRPC_SLICE_START_PTR(path_slice); size_t path_length = GRPC_SLICE_LENGTH(path_slice); /* offset of the character '?' */ size_t offset = 0; @@ -226,7 +226,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, const int k_url_safe = 1; grpc_slice_buffer_add(&calld->read_slice_buffer, grpc_base64_decode_with_len( - (const char*)GRPC_SLICE_START_PTR(query_slice), + reinterpret_castGRPC_SLICE_START_PTR(query_slice), GRPC_SLICE_LENGTH(query_slice), k_url_safe)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); @@ -262,8 +262,8 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, } static void hs_on_recv(void* user_data, grpc_error* err) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (err == GRPC_ERROR_NONE) { err = server_filter_incoming_metadata(elem, calld->recv_initial_metadata); } else { @@ -273,13 +273,13 @@ static void hs_on_recv(void* user_data, grpc_error* err) { } static void hs_on_complete(void* user_data, grpc_error* err) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); /* Call recv_message_ready if we got the payload via the path field */ if (calld->seen_path_with_query && calld->recv_message_ready != nullptr) { *calld->pp_recv_message = calld->payload_bin_delivered ? nullptr - : (grpc_byte_stream*)&calld->read_stream; + : reinterpret_cast(&calld->read_stream); // Re-enter call combiner for recv_message_ready, since the surface // code will release the call combiner for each callback it receives. GRPC_CALL_COMBINER_START(calld->call_combiner, calld->recv_message_ready, @@ -292,8 +292,8 @@ static void hs_on_complete(void* user_data, grpc_error* err) { } static void hs_recv_message_ready(void* user_data, grpc_error* err) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (calld->seen_path_with_query) { // Do nothing. This is probably a GET request, and payload will be // returned in hs_on_complete callback. @@ -309,7 +309,7 @@ static void hs_recv_message_ready(void* user_data, grpc_error* err) { static grpc_error* hs_mutate_op(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { /* grab pointers to our data from the call element */ - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (op->send_initial_metadata) { grpc_error* error = GRPC_ERROR_NONE; @@ -368,7 +368,7 @@ static grpc_error* hs_mutate_op(grpc_call_element* elem, static void hs_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { GPR_TIMER_SCOPE("hs_start_transport_stream_op_batch", 0); - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_error* error = hs_mutate_op(elem, op); if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure(op, error, @@ -382,7 +382,7 @@ static void hs_start_transport_stream_op_batch( static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { /* grab pointers to our data from the call element */ - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); /* initialize members */ calld->call_combiner = args->call_combiner; GRPC_CLOSURE_INIT(&calld->hs_on_recv, hs_on_recv, elem, @@ -399,7 +399,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_slice_buffer_destroy_internal(&calld->read_slice_buffer); } diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc index 4c87d9755e..79b144a6eb 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc @@ -57,8 +57,8 @@ struct channel_data { } // namespace static void on_initial_md_ready(void* user_data, grpc_error* err) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (err == GRPC_ERROR_NONE) { if (calld->recv_initial_metadata->idx.named.path != nullptr) { @@ -88,7 +88,7 @@ static void on_initial_md_ready(void* user_data, grpc_error* err) { /* Constructor for call_data */ static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); calld->id = (intptr_t)args->call_stack; GRPC_CLOSURE_INIT(&calld->on_initial_md_ready, on_initial_md_ready, elem, grpc_schedule_on_exec_ctx); @@ -111,7 +111,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); /* TODO(dgq): do something with the data channel_data *chand = elem->channel_data; @@ -140,7 +140,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); chand->id = (intptr_t)args->channel_stack; /* TODO(dgq): do something with the data @@ -173,8 +173,8 @@ static void destroy_channel_elem(grpc_channel_element* elem) { static grpc_filtered_mdelem lr_trailing_md_filter(void* user_data, grpc_mdelem md) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_LB_COST_BIN)) { calld->trailing_md_string = GRPC_MDVALUE(md); return GRPC_FILTERED_REMOVE(); @@ -185,7 +185,7 @@ static grpc_filtered_mdelem lr_trailing_md_filter(void* user_data, static void lr_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { GPR_TIMER_SCOPE("lr_start_transport_stream_op_batch", 0); - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (op->recv_initial_metadata) { /* substitute our callback for the higher callback */ diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc index 9d1dfcbb4c..4255a77ea0 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc @@ -41,7 +41,7 @@ static bool maybe_add_server_load_reporting_filter( grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); - const grpc_channel_filter* filter = (const grpc_channel_filter*)arg; + const grpc_channel_filter* filter = static_cast(arg); grpc_channel_stack_builder_iterator* it = grpc_channel_stack_builder_iterator_find(builder, filter->name); const bool already_has_load_reporting_filter = diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index a3f9780f3f..ba41e4674b 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -206,7 +206,7 @@ static void decrease_call_count(channel_data* chand) { } static void start_max_idle_timer_after_init(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); /* Decrease call_count. If there are no active calls at this time, max_idle_timer will start here. If the number of active calls is not 0, max_idle_timer will start after all the active calls end. */ @@ -216,7 +216,7 @@ static void start_max_idle_timer_after_init(void* arg, grpc_error* error) { } static void start_max_age_timer_after_init(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); @@ -234,7 +234,7 @@ static void start_max_age_timer_after_init(void* arg, grpc_error* error) { static void start_max_age_grace_timer_after_goaway_op(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_grace_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_grace_timer"); @@ -262,7 +262,7 @@ static void close_max_idle_channel(channel_data* chand) { } static void max_idle_timer_cb(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); if (error == GRPC_ERROR_NONE) { bool try_again = true; while (try_again) { @@ -285,7 +285,7 @@ static void max_idle_timer_cb(void* arg, grpc_error* error) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer"); grpc_timer_init(&chand->max_idle_timer, - (grpc_millis)gpr_atm_no_barrier_load( + static_castgpr_atm_no_barrier_load( &chand->last_enter_idle_time_millis) + chand->max_connection_idle, &chand->max_idle_timer_cb); @@ -306,7 +306,7 @@ static void max_idle_timer_cb(void* arg, grpc_error* error) { } static void close_max_age_channel(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_timer_pending = false; gpr_mu_unlock(&chand->max_age_timer_mu); @@ -328,7 +328,7 @@ static void close_max_age_channel(void* arg, grpc_error* error) { } static void force_close_max_age_channel(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_grace_timer_pending = false; gpr_mu_unlock(&chand->max_age_timer_mu); @@ -346,7 +346,7 @@ static void force_close_max_age_channel(void* arg, grpc_error* error) { } static void channel_connectivity_changed(void* arg, grpc_error* error) { - channel_data* chand = (channel_data*)arg; + channel_data* chand = static_cast(arg); if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed; @@ -384,15 +384,15 @@ add_random_max_connection_age_jitter_and_convert_to_grpc_millis(int value) { double result = multiplier * value; /* INT_MAX - 0.5 converts the value to float, so that result will not be cast to int implicitly before the comparison. */ - return result > ((double)GRPC_MILLIS_INF_FUTURE) - 0.5 + return result > (static_castGRPC_MILLIS_INF_FUTURE) - 0.5 ? GRPC_MILLIS_INF_FUTURE - : (grpc_millis)result; + : static_cast(result); } /* Constructor for call_data. */ static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); increase_call_count(chand); return GRPC_ERROR_NONE; } @@ -401,14 +401,14 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); decrease_call_count(chand); } /* Constructor for channel_data. */ static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); gpr_mu_init(&chand->max_age_timer_mu); chand->max_age_timer_pending = false; chand->max_age_grace_timer_pending = false; 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 8d76c4a837..a2406a24dd 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -42,14 +42,14 @@ typedef struct { static void* refcounted_message_size_limits_ref(void* value) { refcounted_message_size_limits* limits = - (refcounted_message_size_limits*)value; + static_cast(value); gpr_ref(&limits->refs); return value; } static void refcounted_message_size_limits_unref(void* value) { refcounted_message_size_limits* limits = - (refcounted_message_size_limits*)value; + static_cast(value); if (gpr_unref(&limits->refs)) { gpr_free(value); } @@ -78,8 +78,8 @@ static void* refcounted_message_size_limits_create_from_json( } } refcounted_message_size_limits* value = - (refcounted_message_size_limits*)gpr_malloc( - sizeof(refcounted_message_size_limits)); + static_cast(gpr_malloc( + sizeof(refcounted_message_size_limits))); gpr_ref_init(&value->refs, 1); value->limits.max_send_size = max_request_message_bytes; value->limits.max_recv_size = max_response_message_bytes; @@ -110,10 +110,10 @@ struct channel_data { // Callback invoked when we receive a message. Here we check the max // receive message size. static void recv_message_ready(void* user_data, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (*calld->recv_message != nullptr && calld->limits.max_recv_size >= 0 && - (*calld->recv_message)->length > (size_t)calld->limits.max_recv_size) { + (*calld->recv_message)->length > static_cast(calld->limits.max_recv_size)) { char* message_string; gpr_asprintf(&message_string, "Received message larger than max (%u vs. %d)", @@ -138,11 +138,11 @@ static void recv_message_ready(void* user_data, grpc_error* error) { // Start transport stream op. static void start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); // Check max send message size. if (op->send_message && calld->limits.max_send_size >= 0 && op->payload->send_message.send_message->length > - (size_t)calld->limits.max_send_size) { + static_cast(calld->limits.max_send_size)) { char* message_string; gpr_asprintf(&message_string, "Sent message larger than max (%u vs. %d)", op->payload->send_message.send_message->length, @@ -170,8 +170,8 @@ static void start_transport_stream_op_batch( // Constructor for call_data. static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); calld->call_combiner = args->call_combiner; calld->next_recv_message_ready = nullptr; GRPC_CLOSURE_INIT(&calld->recv_message_ready, recv_message_ready, elem, @@ -183,8 +183,8 @@ static grpc_error* init_call_elem(grpc_call_element* elem, calld->limits = chand->limits; if (chand->method_limit_table != nullptr) { refcounted_message_size_limits* limits = - (refcounted_message_size_limits*)grpc_method_config_table_get( - chand->method_limit_table, args->path); + static_cast(grpc_method_config_table_get( + chand->method_limit_table, args->path)); if (limits != nullptr) { if (limits->limits.max_send_size >= 0 && (limits->limits.max_send_size < calld->limits.max_send_size || @@ -242,7 +242,7 @@ message_size_limits get_message_size_limits( static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); chand->limits = get_message_size_limits(args->channel_args); // Get method config table from channel args. const grpc_arg* channel_arg = @@ -265,7 +265,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, // Destructor for channel_data. static void destroy_channel_elem(grpc_channel_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); grpc_slice_hash_table_unref(chand->method_limit_table); } diff --git a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc index 88bb8c71cc..3092ed2056 100644 --- a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +++ b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc @@ -53,8 +53,8 @@ static bool get_user_agent_mdelem(const grpc_metadata_batch* batch, // Callback invoked when we receive an initial metadata. static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); if (GRPC_ERROR_NONE == error) { grpc_mdelem md; @@ -75,7 +75,7 @@ static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { // Start transport stream op. static void start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); // Inject callback for receiving initial metadata if (op->recv_initial_metadata) { @@ -102,7 +102,7 @@ static void start_transport_stream_op_batch( // Constructor for call_data. static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); calld->next_recv_initial_metadata_ready = nullptr; calld->workaround_active = false; GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready, diff --git a/src/core/ext/filters/workarounds/workaround_utils.cc b/src/core/ext/filters/workarounds/workaround_utils.cc index 9d76582ea2..b94c7536d0 100644 --- a/src/core/ext/filters/workarounds/workaround_utils.cc +++ b/src/core/ext/filters/workarounds/workaround_utils.cc @@ -27,14 +27,14 @@ static void destroy_user_agent_md(void* user_agent_md) { grpc_workaround_user_agent_md* grpc_parse_user_agent(grpc_mdelem md) { grpc_workaround_user_agent_md* user_agent_md = - (grpc_workaround_user_agent_md*)grpc_mdelem_get_user_data( - md, destroy_user_agent_md); + static_cast(grpc_mdelem_get_user_data( + md, destroy_user_agent_md)); if (nullptr != user_agent_md) { return user_agent_md; } - user_agent_md = (grpc_workaround_user_agent_md*)gpr_malloc( - sizeof(grpc_workaround_user_agent_md)); + user_agent_md = static_cast(gpr_malloc( + sizeof(grpc_workaround_user_agent_md))); for (int i = 0; i < GRPC_MAX_WORKAROUND_ID; i++) { if (ua_parser[i]) { user_agent_md->workaround_active[i] = ua_parser[i](md); diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index db5962e7fd..7eb9ebc27e 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -57,12 +57,12 @@ typedef struct { } chttp2_connector; static void chttp2_connector_ref(grpc_connector* con) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast(con); gpr_ref(&c->refs); } static void chttp2_connector_unref(grpc_connector* con) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast(con); if (gpr_unref(&c->refs)) { gpr_mu_destroy(&c->mu); // If handshaking is not yet in progress, destroy the endpoint. @@ -73,7 +73,7 @@ static void chttp2_connector_unref(grpc_connector* con) { } static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast(con); gpr_mu_lock(&c->mu); c->shutdown = true; if (c->handshake_mgr != nullptr) { @@ -89,8 +89,8 @@ static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) { } static void on_handshake_done(void* arg, grpc_error* error) { - grpc_handshaker_args* args = (grpc_handshaker_args*)arg; - chttp2_connector* c = (chttp2_connector*)args->user_data; + grpc_handshaker_args* args = static_cast(arg); + chttp2_connector* c = static_cast(args->user_data); gpr_mu_lock(&c->mu); if (error != GRPC_ERROR_NONE || c->shutdown) { if (error == GRPC_ERROR_NONE) { @@ -150,7 +150,7 @@ static void on_handshake_done(void* arg, grpc_error* error) { grpc_handshake_manager_destroy(c->handshake_mgr); c->handshake_mgr = nullptr; gpr_mu_unlock(&c->mu); - chttp2_connector_unref((grpc_connector*)c); + chttp2_connector_unref(reinterpret_cast(c)); } static void start_handshake_locked(chttp2_connector* c) { @@ -166,7 +166,7 @@ static void start_handshake_locked(chttp2_connector* c) { } static void connected(void* arg, grpc_error* error) { - chttp2_connector* c = (chttp2_connector*)arg; + chttp2_connector* c = static_cast(arg); gpr_mu_lock(&c->mu); GPR_ASSERT(c->connecting); c->connecting = false; @@ -184,7 +184,7 @@ static void connected(void* arg, grpc_error* error) { grpc_endpoint_shutdown(c->endpoint, GRPC_ERROR_REF(error)); } gpr_mu_unlock(&c->mu); - chttp2_connector_unref((grpc_connector*)arg); + chttp2_connector_unref(static_cast(arg)); } else { GPR_ASSERT(c->endpoint != nullptr); start_handshake_locked(c); @@ -196,7 +196,7 @@ static void chttp2_connector_connect(grpc_connector* con, const grpc_connect_in_args* args, grpc_connect_out_args* result, grpc_closure* notify) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast(con); grpc_resolved_address addr; grpc_get_subchannel_address_arg(args->channel_args, &addr); gpr_mu_lock(&c->mu); @@ -219,7 +219,7 @@ static const grpc_connector_vtable chttp2_connector_vtable = { chttp2_connector_connect}; grpc_connector* grpc_chttp2_connector_create() { - chttp2_connector* c = (chttp2_connector*)gpr_zalloc(sizeof(*c)); + chttp2_connector* c = static_cast(gpr_zalloc(sizeof(*c))); c->base.vtable = &chttp2_connector_vtable; gpr_mu_init(&c->mu); gpr_ref_init(&c->refs, 1); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index d39c362cd3..322fcb23e1 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -87,7 +87,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const grpc_slice key = grpc_slice_from_static_string( target_uri->path[0] == '/' ? target_uri->path + 1 : target_uri->path); const char* value = - (const char*)grpc_slice_hash_table_get(targets_info, key); + static_cast(grpc_slice_hash_table_get(targets_info, key)); if (value != nullptr) target_name_to_check = gpr_strdup(value); grpc_slice_unref_internal(key); } @@ -129,7 +129,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_channel_args_destroy(new_args_from_connector); } grpc_subchannel_args* final_sc_args = - (grpc_subchannel_args*)gpr_malloc(sizeof(*final_sc_args)); + static_cast(gpr_malloc(sizeof(*final_sc_args))); memcpy(final_sc_args, args, sizeof(*args)); final_sc_args->args = new_args; return final_sc_args; @@ -148,7 +148,7 @@ static grpc_subchannel* client_channel_factory_create_subchannel( grpc_connector* connector = grpc_chttp2_connector_create(); grpc_subchannel* s = grpc_subchannel_create(connector, subchannel_args); grpc_connector_unref(connector); - grpc_channel_args_destroy((grpc_channel_args*)subchannel_args->args); + grpc_channel_args_destroy(const_cast(subchannel_args->args)); gpr_free(subchannel_args); return s; } diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index bab46f8f30..c1e7946f5f 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -79,7 +79,7 @@ static void server_connection_state_unref( } static void on_timeout(void* arg, grpc_error* error) { - server_connection_state* connection_state = (server_connection_state*)arg; + server_connection_state* connection_state = static_cast(arg); // Note that we may be called with GRPC_ERROR_NONE when the timer fires // or with an error indicating that the timer system is being shut down. if (error != GRPC_ERROR_CANCELLED) { @@ -92,7 +92,7 @@ static void on_timeout(void* arg, grpc_error* error) { } static void on_receive_settings(void* arg, grpc_error* error) { - server_connection_state* connection_state = (server_connection_state*)arg; + server_connection_state* connection_state = static_cast(arg); if (error == GRPC_ERROR_NONE) { grpc_timer_cancel(&connection_state->timer); } @@ -100,9 +100,9 @@ static void on_receive_settings(void* arg, grpc_error* error) { } static void on_handshake_done(void* arg, grpc_error* error) { - grpc_handshaker_args* args = (grpc_handshaker_args*)arg; + grpc_handshaker_args* args = static_cast(arg); server_connection_state* connection_state = - (server_connection_state*)args->user_data; + static_cast(args->user_data); gpr_mu_lock(&connection_state->svr_state->mu); if (error != GRPC_ERROR_NONE || connection_state->svr_state->shutdown) { const char* error_str = grpc_error_string(error); @@ -132,7 +132,7 @@ static void on_handshake_done(void* arg, grpc_error* error) { connection_state->accepting_pollset, args->args); // Use notify_on_receive_settings callback to enforce the // handshake deadline. - connection_state->transport = (grpc_chttp2_transport*)transport; + connection_state->transport = reinterpret_cast(transport); gpr_ref(&connection_state->refs); GRPC_CLOSURE_INIT(&connection_state->on_receive_settings, on_receive_settings, connection_state, @@ -162,7 +162,7 @@ static void on_handshake_done(void* arg, grpc_error* error) { static void on_accept(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { - server_state* state = (server_state*)arg; + server_state* state = static_cast(arg); gpr_mu_lock(&state->mu); if (state->shutdown) { gpr_mu_unlock(&state->mu); @@ -177,7 +177,7 @@ static void on_accept(void* arg, grpc_endpoint* tcp, gpr_mu_unlock(&state->mu); grpc_tcp_server_ref(state->tcp_server); server_connection_state* connection_state = - (server_connection_state*)gpr_zalloc(sizeof(*connection_state)); + static_cast(gpr_zalloc(sizeof(*connection_state))); gpr_ref_init(&connection_state->refs, 1); connection_state->svr_state = state; connection_state->accepting_pollset = accepting_pollset; @@ -201,7 +201,7 @@ static void on_accept(void* arg, grpc_endpoint* tcp, static void server_start_listener(grpc_server* server, void* arg, grpc_pollset** pollsets, size_t pollset_count) { - server_state* state = (server_state*)arg; + server_state* state = static_cast(arg); gpr_mu_lock(&state->mu); state->shutdown = false; gpr_mu_unlock(&state->mu); @@ -210,7 +210,7 @@ static void server_start_listener(grpc_server* server, void* arg, } static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { - server_state* state = (server_state*)arg; + server_state* state = static_cast(arg); /* ensure all threads have unlocked */ gpr_mu_lock(&state->mu); grpc_closure* destroy_done = state->server_destroy_listener_done; @@ -234,7 +234,7 @@ static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { callbacks) */ static void server_destroy_listener(grpc_server* server, void* arg, grpc_closure* destroy_done) { - server_state* state = (server_state*)arg; + server_state* state = static_cast(arg); gpr_mu_lock(&state->mu); state->shutdown = true; state->server_destroy_listener_done = destroy_done; @@ -264,7 +264,7 @@ grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, if (err != GRPC_ERROR_NONE) { goto error; } - state = (server_state*)gpr_zalloc(sizeof(*state)); + state = static_cast(gpr_zalloc(sizeof(*state))); GRPC_CLOSURE_INIT(&state->tcp_server_shutdown_complete, tcp_server_shutdown_complete, state, grpc_schedule_on_exec_ctx); @@ -281,7 +281,7 @@ grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, gpr_mu_init(&state->mu); naddrs = resolved->naddrs; - errors = (grpc_error**)gpr_malloc(sizeof(*errors) * naddrs); + errors = static_cast(gpr_malloc(sizeof(*errors) * naddrs)); for (i = 0; i < naddrs; i++) { errors[i] = grpc_tcp_server_add_port(tcp_server, &resolved->addrs[i], &port_temp); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 74778ac046..0e5e4d0535 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -57,7 +57,7 @@ static bool input_is_valid(uint8_t* input_ptr, size_t length) { gpr_log(GPR_ERROR, "Base64 decoding failed, invalid character '%c' in base64 " "input.\n", - (char)(*input_ptr)); + static_cast(*input_ptr)); return false; } } @@ -94,7 +94,7 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx) { } // Process the tail of input data - input_tail = (size_t)(ctx->input_end - ctx->input_cur); + input_tail = static_cast(ctx->input_end - ctx->input_cur); if (input_tail == 4) { // Process the input data with pad chars if (ctx->input_cur[3] == '=') { @@ -141,7 +141,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) { "Base64 decoding failed, input of " "grpc_chttp2_base64_decode has a length of %d, which is not a " "multiple of 4.\n", - (int)input_length); + static_cast(input_length)); return grpc_empty_slice(); } @@ -186,7 +186,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, "Base64 decoding failed, input of " "grpc_chttp2_base64_decode_with_length has a length of %d, which " "has a tail of 1 byte.\n", - (int)input_length); + static_cast(input_length)); grpc_slice_unref_internal(output); return grpc_empty_slice(); } @@ -195,8 +195,8 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, gpr_log(GPR_ERROR, "Base64 decoding failed, output_length %d is longer " "than the max possible output length %d.\n", - (int)output_length, - (int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); + static_cast(output_length), + static_cast(input_length / 4 * 3 + tail_xtra[input_length % 4])); grpc_slice_unref_internal(output); return grpc_empty_slice(); } diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.cc b/src/core/ext/transport/chttp2/transport/bin_encoder.cc index 09f984d7b2..d9c095ede7 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -53,7 +53,7 @@ grpc_slice grpc_chttp2_base64_encode(grpc_slice input) { size_t output_length = input_triplets * 4 + tail_xtra[tail_case]; grpc_slice output = GRPC_SLICE_MALLOC(output_length); uint8_t* in = GRPC_SLICE_START_PTR(input); - char* out = (char*)GRPC_SLICE_START_PTR(output); + char* out = reinterpret_castGRPC_SLICE_START_PTR(output); size_t i; /* encode full triplets */ @@ -115,7 +115,7 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) { while (temp_length > 8) { temp_length -= 8; - *out++ = (uint8_t)(temp >> temp_length); + *out++ = static_cast(temp >> temp_length); } } @@ -124,8 +124,8 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) { * expanded form due to the "integral promotion" performed (see section * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type * is then required to avoid the compiler warning */ - *out++ = (uint8_t)((uint8_t)(temp << (8u - temp_length)) | - (uint8_t)(0xffu >> temp_length)); + *out++ = static_cast(static_cast(temp << (8u - temp_length)) | + static_cast(0xffu >> temp_length)); } GPR_ASSERT(out == GRPC_SLICE_END_PTR(output)); @@ -142,7 +142,7 @@ typedef struct { static void enc_flush_some(huff_out* out) { while (out->temp_length > 8) { out->temp_length -= 8; - *out->out++ = (uint8_t)(out->temp >> out->temp_length); + *out->out++ = static_cast(out->temp >> out->temp_length); } } @@ -150,8 +150,8 @@ static void enc_add2(huff_out* out, uint8_t a, uint8_t b) { b64_huff_sym sa = huff_alphabet[a]; b64_huff_sym sb = huff_alphabet[b]; out->temp = (out->temp << (sa.length + sb.length)) | - ((uint32_t)sa.bits << sb.length) | sb.bits; - out->temp_length += (uint32_t)sa.length + (uint32_t)sb.length; + (static_cast(sa.bits) << sb.length) | sb.bits; + out->temp_length += static_cast(sa.length) + static_cast(sb.length); enc_flush_some(out); } @@ -181,11 +181,11 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { /* encode full triplets */ for (i = 0; i < input_triplets; i++) { - const uint8_t low_to_high = (uint8_t)((in[0] & 0x3) << 4); + const uint8_t low_to_high = static_cast((in[0] & 0x3) << 4); const uint8_t high_to_low = in[1] >> 4; enc_add2(&out, in[0] >> 2, low_to_high | high_to_low); - const uint8_t a = (uint8_t)((in[1] & 0xf) << 2); + const uint8_t a = static_cast((in[1] & 0xf) << 2); const uint8_t b = (in[2] >> 6); enc_add2(&out, a | b, in[2] & 0x3f); in += 3; @@ -196,14 +196,14 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { case 0: break; case 1: - enc_add2(&out, in[0] >> 2, (uint8_t)((in[0] & 0x3) << 4)); + enc_add2(&out, in[0] >> 2, static_cast((in[0] & 0x3) << 4)); in += 1; break; case 2: { - const uint8_t low_to_high = (uint8_t)((in[0] & 0x3) << 4); + const uint8_t low_to_high = static_cast((in[0] & 0x3) << 4); const uint8_t high_to_low = in[1] >> 4; enc_add2(&out, in[0] >> 2, low_to_high | high_to_low); - enc_add1(&out, (uint8_t)((in[1] & 0xf) << 2)); + enc_add1(&out, static_cast((in[1] & 0xf) << 2)); in += 2; break; } @@ -214,8 +214,8 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { * expanded form due to the "integral promotion" performed (see section * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type * is then required to avoid the compiler warning */ - *out.out++ = (uint8_t)((uint8_t)(out.temp << (8u - out.temp_length)) | - (uint8_t)(0xffu >> out.temp_length)); + *out.out++ = static_cast(static_cast(out.temp << (8u - out.temp_length)) | + static_cast(0xffu >> out.temp_length)); } GPR_ASSERT(out.out <= GRPC_SLICE_END_PTR(output)); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 7c35fafe36..ec5431bb00 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -378,7 +378,7 @@ static void init_transport(grpc_chttp2_transport* t, GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER, t->next_stream_id & 1, is_client ? "client" : "server"); } else { - t->next_stream_id = (uint32_t)value; + t->next_stream_id = static_cast(value); } } } else if (0 == strcmp(channel_args->args[i].key, @@ -388,7 +388,7 @@ static void init_transport(grpc_chttp2_transport* t, grpc_channel_arg_get_integer(&channel_args->args[i], options); if (value >= 0) { grpc_chttp2_hpack_compressor_set_max_usable_size(&t->hpack_compressor, - (uint32_t)value); + static_cast(value)); } } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) { @@ -421,8 +421,8 @@ static void init_transport(grpc_chttp2_transport* t, INT_MAX}); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) { - t->write_buffer_size = (uint32_t)grpc_channel_arg_get_integer( - &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE}); + t->write_buffer_size = static_cast(grpc_channel_arg_get_integer( + &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE})); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_BDP_PROBE)) { enable_bdp = grpc_channel_arg_get_bool(&channel_args->args[i], true); @@ -448,8 +448,8 @@ static void init_transport(grpc_chttp2_transport* t, } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) { t->keepalive_permit_without_calls = - (uint32_t)grpc_channel_arg_get_integer(&channel_args->args[i], - {0, 0, 1}); + static_cast(grpc_channel_arg_get_integer(&channel_args->args[i], + {0, 0, 1})); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_OPTIMIZATION_TARGET)) { if (channel_args->args[i].type != GRPC_ARG_STRING) { @@ -498,7 +498,7 @@ static void init_transport(grpc_chttp2_transport* t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, {-1, 5, INT32_MAX}, {true, true}}}; - for (j = 0; j < (int)GPR_ARRAY_SIZE(settings_map); j++) { + for (j = 0; j < static_castGPR_ARRAY_SIZE(settings_map); j++) { if (0 == strcmp(channel_args->args[i].key, settings_map[j].channel_arg_name)) { if (!settings_map[j].availability[is_client]) { @@ -510,7 +510,7 @@ static void init_transport(grpc_chttp2_transport* t, &channel_args->args[i], settings_map[j].integer_options); if (value >= 0) { queue_setting_update(t, settings_map[j].setting_id, - (uint32_t)value); + static_cast(value)); } } break; @@ -562,7 +562,7 @@ static void init_transport(grpc_chttp2_transport* t, } static void destroy_transport_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); t->destroying = 1; close_transport_locked( t, grpc_error_set_int( @@ -572,7 +572,7 @@ static void destroy_transport_locked(void* tp, grpc_error* error) { } static void destroy_transport(grpc_transport* gt) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast(gt); GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(destroy_transport_locked, t, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); @@ -656,8 +656,8 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena) { GPR_TIMER_SCOPE("init_stream", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + grpc_chttp2_transport* t = reinterpret_cast(gt); + grpc_chttp2_stream* s = reinterpret_cast(gs); s->t = t; s->refcount = refcount; @@ -685,7 +685,7 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, GRPC_CHTTP2_REF_TRANSPORT(t, "stream"); if (server_data) { - s->id = (uint32_t)(uintptr_t)server_data; + s->id = static_cast((uintptr_t)server_data); *t->accepting_stream = s; grpc_chttp2_stream_map_add(&t->stream_map, s->id, s); post_destructive_reclaimer(t); @@ -705,7 +705,7 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, static void destroy_stream_locked(void* sp, grpc_error* error) { GPR_TIMER_SCOPE("destroy_stream", 0); - grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; + grpc_chttp2_stream* s = static_cast(sp); grpc_chttp2_transport* t = s->t; GPR_ASSERT((s->write_closed && s->read_closed) || s->id == 0); @@ -753,8 +753,8 @@ static void destroy_stream_locked(void* sp, grpc_error* error) { static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { GPR_TIMER_SCOPE("destroy_stream", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + grpc_chttp2_transport* t = reinterpret_cast(gt); + grpc_chttp2_stream* s = reinterpret_cast(gs); if (s->stream_compression_ctx != nullptr) { grpc_stream_compression_context_destroy(s->stream_compression_ctx); @@ -774,7 +774,7 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, uint32_t id) { - return (grpc_chttp2_stream*)grpc_chttp2_stream_map_find(&t->stream_map, id); + return static_cast(grpc_chttp2_stream_map_find(&t->stream_map, id)); } grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, @@ -786,7 +786,7 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data, - &t->base, (void*)(uintptr_t)id); + &t->base, (void*)static_cast(id)); t->accepting_stream = nullptr; return accepting; } @@ -968,7 +968,7 @@ static const char* begin_writing_desc(bool partial, bool inlined) { static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { GPR_TIMER_SCOPE("write_action_begin_locked", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = static_cast(gt); GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE); grpc_chttp2_begin_write_result r; if (t->closed_with_error != GRPC_ERROR_NONE) { @@ -1005,7 +1005,7 @@ static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { static void write_action(void* gt, grpc_error* error) { GPR_TIMER_SCOPE("write_action", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = static_cast(gt); grpc_endpoint_write( t->ep, &t->outbuf, GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end_locked, t, @@ -1014,7 +1014,7 @@ static void write_action(void* gt, grpc_error* error) { static void write_action_end_locked(void* tp, grpc_error* error) { GPR_TIMER_SCOPE("terminate_writing_with_lock", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); if (error != GRPC_ERROR_NONE) { close_transport_locked(t, GRPC_ERROR_REF(error)); @@ -1083,7 +1083,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, t->goaway_error = grpc_error_set_str( grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"), - GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)goaway_error), + GRPC_ERROR_INT_HTTP2_ERROR, static_cast(goaway_error)), GRPC_ERROR_STR_RAW_BYTES, goaway_text); /* When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug @@ -1095,11 +1095,11 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, gpr_log(GPR_ERROR, "Received a GOAWAY with error code ENHANCE_YOUR_CALM and debug " "data equal to \"too_many_pings\""); - double current_keepalive_time_ms = (double)t->keepalive_time; + double current_keepalive_time_ms = static_cast(t->keepalive_time); t->keepalive_time = current_keepalive_time_ms > INT_MAX / KEEPALIVE_TIME_BACKOFF_MULTIPLIER ? GRPC_MILLIS_INF_FUTURE - : (grpc_millis)(current_keepalive_time_ms * + : static_cast(current_keepalive_time_ms * KEEPALIVE_TIME_BACKOFF_MULTIPLIER); } @@ -1189,8 +1189,8 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, "complete_closure_step: t=%p %p refs=%d flags=0x%04x desc=%s err=%s " "write_state=%s", t, closure, - (int)(closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT), - (int)(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT), desc, + static_cast(closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT), + static_cast(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT), desc, errstr, write_state_name(t->write_state)); } if (error != GRPC_ERROR_NONE) { @@ -1239,7 +1239,7 @@ static void maybe_become_writable_due_to_send_msg(grpc_chttp2_transport* t, static void add_fetched_slice_locked(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { s->fetched_send_message_length += - (uint32_t)GRPC_SLICE_LENGTH(s->fetching_slice); + static_castGRPC_SLICE_LENGTH(s->fetching_slice); grpc_slice_buffer_add(&s->flow_controlled_buffer, s->fetching_slice); maybe_become_writable_due_to_send_msg(t, s); } @@ -1262,7 +1262,7 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, } else { grpc_chttp2_write_cb* cb = t->write_cb_pool; if (cb == nullptr) { - cb = (grpc_chttp2_write_cb*)gpr_malloc(sizeof(*cb)); + cb = static_cast(gpr_malloc(sizeof(*cb))); } else { t->write_cb_pool = cb->next; } @@ -1293,7 +1293,7 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, } static void complete_fetch_locked(void* gs, grpc_error* error) { - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + grpc_chttp2_stream* s = static_cast(gs); grpc_chttp2_transport* t = s->t; if (error == GRPC_ERROR_NONE) { error = grpc_byte_stream_pull(s->fetching_send_message, &s->fetching_slice); @@ -1328,8 +1328,8 @@ static void perform_stream_op_locked(void* stream_op, GPR_TIMER_SCOPE("perform_stream_op_locked", 0); grpc_transport_stream_op_batch* op = - (grpc_transport_stream_op_batch*)stream_op; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)op->handler_private.extra_arg; + static_cast(stream_op); + grpc_chttp2_stream* s = static_cast(op->handler_private.extra_arg); grpc_transport_stream_op_batch_payload* op_payload = op->payload; grpc_chttp2_transport* t = s->t; @@ -1408,8 +1408,8 @@ static void perform_stream_op_locked(void* stream_op, "to-be-sent initial metadata size " "exceeds peer limit"), GRPC_ERROR_INT_SIZE, - (intptr_t)metadata_size), - GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit), + static_cast(metadata_size)), + GRPC_ERROR_INT_LIMIT, static_cast(metadata_peer_limit)), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); } else { if (contains_non_ok_status(s->send_initial_metadata)) { @@ -1482,15 +1482,15 @@ static void perform_stream_op_locked(void* stream_op, uint32_t flags = op_payload->send_message.send_message->flags; frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; size_t len = op_payload->send_message.send_message->length; - frame_hdr[1] = (uint8_t)(len >> 24); - frame_hdr[2] = (uint8_t)(len >> 16); - frame_hdr[3] = (uint8_t)(len >> 8); - frame_hdr[4] = (uint8_t)(len); + frame_hdr[1] = static_cast(len >> 24); + frame_hdr[2] = static_cast(len >> 16); + frame_hdr[3] = static_cast(len >> 8); + frame_hdr[4] = static_cast(len); s->fetching_send_message = op_payload->send_message.send_message; s->fetched_send_message_length = 0; s->next_message_end_offset = s->flow_controlled_bytes_written + - (int64_t)s->flow_controlled_buffer.length + - (int64_t)len; + static_cast(s->flow_controlled_buffer.length) + + static_cast(len); if (flags & GRPC_WRITE_BUFFER_HINT) { s->next_message_end_offset -= t->write_buffer_size; s->write_buffering = true; @@ -1524,8 +1524,8 @@ static void perform_stream_op_locked(void* stream_op, "to-be-sent trailing metadata size " "exceeds peer limit"), GRPC_ERROR_INT_SIZE, - (intptr_t)metadata_size), - GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit), + static_cast(metadata_size)), + GRPC_ERROR_INT_LIMIT, static_cast(metadata_peer_limit)), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); } else { if (contains_non_ok_status(s->send_trailing_metadata)) { @@ -1605,8 +1605,8 @@ static void perform_stream_op_locked(void* stream_op, static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, grpc_transport_stream_op_batch* op) { GPR_TIMER_SCOPE("perform_stream_op", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + grpc_chttp2_transport* t = reinterpret_cast(gt); + grpc_chttp2_stream* s = reinterpret_cast(gs); if (!t->is_client) { if (op->send_initial_metadata) { @@ -1662,7 +1662,7 @@ static void send_ping_locked(grpc_chttp2_transport* t, } static void retry_initiate_ping_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); t->ping_state.is_delayed_ping_timer_set = false; if (error == GRPC_ERROR_NONE) { grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); @@ -1690,7 +1690,7 @@ static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) { grpc_slice slice; grpc_error_get_status(error, GRPC_MILLIS_INF_FUTURE, nullptr, &slice, &http_error, nullptr); - grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error, + grpc_chttp2_goaway_append(t->last_new_stream_id, static_cast(http_error), grpc_slice_ref_internal(slice), &t->qbuf); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT); GRPC_ERROR_UNREF(error); @@ -1714,9 +1714,9 @@ void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) { static void perform_transport_op_locked(void* stream_op, grpc_error* error_ignored) { - grpc_transport_op* op = (grpc_transport_op*)stream_op; + grpc_transport_op* op = static_cast(stream_op); grpc_chttp2_transport* t = - (grpc_chttp2_transport*)op->handler_private.extra_arg; + static_cast(op->handler_private.extra_arg); if (op->goaway_error) { send_goaway(t, op->goaway_error); @@ -1757,7 +1757,7 @@ static void perform_transport_op_locked(void* stream_op, } static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast(gt); char* msg = grpc_transport_op_string(op); gpr_free(msg); op->handler_private.extra_arg = gt; @@ -1926,7 +1926,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, static void remove_stream(grpc_chttp2_transport* t, uint32_t id, grpc_error* error) { grpc_chttp2_stream* s = - (grpc_chttp2_stream*)grpc_chttp2_stream_map_delete(&t->stream_map, id); + static_cast(grpc_chttp2_stream_map_delete(&t->stream_map, id)); GPR_ASSERT(s); if (t->incoming_stream == s) { t->incoming_stream = nullptr; @@ -1978,7 +1978,7 @@ void grpc_chttp2_cancel_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error_get_status(due_to_error, s->deadline, nullptr, nullptr, &http_error, nullptr); grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error, + &t->qbuf, grpc_chttp2_rst_stream_create(s->id, static_cast(http_error), &s->stats.outgoing)); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); } @@ -2180,7 +2180,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = '0'; *p++ = '0'; GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(http_status_hdr); + len += static_castGRPC_SLICE_LENGTH(http_status_hdr); content_type_hdr = GRPC_SLICE_MALLOC(31); p = GRPC_SLICE_START_PTR(content_type_hdr); @@ -2216,7 +2216,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = 'p'; *p++ = 'c'; GPR_ASSERT(p == GRPC_SLICE_END_PTR(content_type_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(content_type_hdr); + len += static_castGRPC_SLICE_LENGTH(content_type_hdr); } status_hdr = GRPC_SLICE_MALLOC(15 + (grpc_status >= 10)); @@ -2236,14 +2236,14 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = 's'; if (grpc_status < 10) { *p++ = 1; - *p++ = (uint8_t)('0' + grpc_status); + *p++ = static_cast('0' + grpc_status); } else { *p++ = 2; - *p++ = (uint8_t)('0' + (grpc_status / 10)); - *p++ = (uint8_t)('0' + (grpc_status % 10)); + *p++ = static_cast('0' + (grpc_status / 10)); + *p++ = static_cast('0' + (grpc_status % 10)); } GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr); + len += static_castGRPC_SLICE_LENGTH(status_hdr); size_t msg_len = GRPC_SLICE_LENGTH(slice); GPR_ASSERT(msg_len <= UINT32_MAX); @@ -2267,20 +2267,20 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 1, 0, p, (uint32_t)msg_len_len); p += msg_len_len; GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); - len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx); - len += (uint32_t)msg_len; + len += static_castGRPC_SLICE_LENGTH(message_pfx); + len += static_cast(msg_len); hdr = GRPC_SLICE_MALLOC(9); p = GRPC_SLICE_START_PTR(hdr); - *p++ = (uint8_t)(len >> 16); - *p++ = (uint8_t)(len >> 8); - *p++ = (uint8_t)(len); + *p++ = static_cast(len >> 16); + *p++ = static_cast(len >> 8); + *p++ = static_cast(len); *p++ = GRPC_CHTTP2_FRAME_HEADER; *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; - *p++ = (uint8_t)(s->id >> 24); - *p++ = (uint8_t)(s->id >> 16); - *p++ = (uint8_t)(s->id >> 8); - *p++ = (uint8_t)(s->id); + *p++ = static_cast(s->id >> 24); + *p++ = static_cast(s->id >> 16); + *p++ = static_cast(s->id >> 8); + *p++ = static_cast(s->id); GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr)); grpc_slice_buffer_add(&t->qbuf, hdr); @@ -2305,8 +2305,8 @@ typedef struct { } cancel_stream_cb_args; static void cancel_stream_cb(void* user_data, uint32_t key, void* stream) { - cancel_stream_cb_args* args = (cancel_stream_cb_args*)user_data; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)stream; + cancel_stream_cb_args* args = static_cast(user_data); + grpc_chttp2_stream* s = static_cast(stream); grpc_chttp2_cancel_stream(args->t, s, GRPC_ERROR_REF(args->error)); } @@ -2389,7 +2389,7 @@ static grpc_error* try_http_parsing(grpc_chttp2_transport* t) { static void read_action_locked(void* tp, grpc_error* error) { GPR_TIMER_SCOPE("reading_action_locked", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); GRPC_ERROR_REF(error); @@ -2411,7 +2411,7 @@ static void read_action_locked(void* tp, grpc_error* error) { grpc_core::BdpEstimator* bdp_est = t->flow_control->bdp_estimator(); if (bdp_est) { bdp_est->AddIncomingBytes( - (int64_t)GRPC_SLICE_LENGTH(t->read_buffer.slices[i])); + static_castGRPC_SLICE_LENGTH(t->read_buffer.slices[i])); } errors[1] = grpc_chttp2_perform_read(t, t->read_buffer.slices[i]); } @@ -2480,7 +2480,7 @@ static void schedule_bdp_ping_locked(grpc_chttp2_transport* t) { } static void start_bdp_ping_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Start BDP ping err=%s", t->peer_string, grpc_error_string(error)); @@ -2493,7 +2493,7 @@ static void start_bdp_ping_locked(void* tp, grpc_error* error) { } static void finish_bdp_ping_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Complete BDP ping err=%s", t->peer_string, grpc_error_string(error)); @@ -2512,7 +2512,7 @@ static void finish_bdp_ping_locked(void* tp, grpc_error* error) { } static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); GPR_ASSERT(t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = false; if (error != GRPC_ERROR_NONE) { @@ -2550,11 +2550,11 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, } } else if (0 == strcmp(args->args[i].key, GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) { - const bool value = (uint32_t)grpc_channel_arg_get_integer( + const bool value = static_cast(grpc_channel_arg_get_integer( &args->args[i], {is_client ? g_default_client_keepalive_permit_without_calls : g_default_server_keepalive_timeout_ms, - 0, 1}); + 0, 1})); if (is_client) { g_default_client_keepalive_permit_without_calls = value; } else { @@ -2590,7 +2590,7 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, } static void init_keepalive_ping_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast(arg); GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); if (t->destroying || t->closed_with_error != GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; @@ -2619,7 +2619,7 @@ static void init_keepalive_ping_locked(void* arg, grpc_error* error) { } static void start_keepalive_ping_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast(arg); GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); grpc_timer_init(&t->keepalive_watchdog_timer, grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, @@ -2627,7 +2627,7 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) { } static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast(arg); if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; @@ -2642,7 +2642,7 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { } static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast(arg); if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; @@ -2682,13 +2682,13 @@ static void connectivity_state_set(grpc_chttp2_transport* t, static void set_pollset(grpc_transport* gt, grpc_stream* gs, grpc_pollset* pollset) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast(gt); grpc_endpoint_add_to_pollset(t->ep, pollset); } static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, grpc_pollset_set* pollset_set) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast(gt); grpc_endpoint_add_to_pollset_set(t->ep, pollset_set); } @@ -2697,7 +2697,7 @@ static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, */ static void reset_byte_stream(void* arg, grpc_error* error) { - grpc_chttp2_stream* s = (grpc_chttp2_stream*)arg; + grpc_chttp2_stream* s = static_cast(arg); s->pending_byte_stream = false; if (error == GRPC_ERROR_NONE) { @@ -2723,7 +2723,7 @@ static void incoming_byte_stream_unref(grpc_chttp2_incoming_byte_stream* bs) { static void incoming_byte_stream_next_locked(void* argp, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)argp; + static_cast(argp); grpc_chttp2_transport* t = bs->transport; grpc_chttp2_stream* s = bs->stream; @@ -2771,7 +2771,7 @@ static bool incoming_byte_stream_next(grpc_byte_stream* byte_stream, grpc_closure* on_complete) { GPR_TIMER_SCOPE("incoming_byte_stream_next", 0); grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast(byte_stream); grpc_chttp2_stream* s = bs->stream; if (s->unprocessed_incoming_frames_buffer.length > 0) { return true; @@ -2792,7 +2792,7 @@ static grpc_error* incoming_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { GPR_TIMER_SCOPE("incoming_byte_stream_pull", 0); grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast(byte_stream); grpc_chttp2_stream* s = bs->stream; grpc_error* error; @@ -2843,7 +2843,7 @@ static void incoming_byte_stream_destroy_locked(void* byte_stream, static void incoming_byte_stream_destroy(grpc_byte_stream* byte_stream) { GPR_TIMER_SCOPE("incoming_byte_stream_destroy", 0); grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast(byte_stream); GRPC_CLOSURE_SCHED( GRPC_CLOSURE_INIT(&bs->destroy_action, incoming_byte_stream_destroy_locked, bs, @@ -2876,7 +2876,7 @@ grpc_error* grpc_chttp2_incoming_byte_stream_push( grpc_slice_unref_internal(slice); return error; } else { - bs->remaining_bytes -= (uint32_t)GRPC_SLICE_LENGTH(slice); + bs->remaining_bytes -= static_castGRPC_SLICE_LENGTH(slice); if (slice_out != nullptr) { *slice_out = slice; } @@ -2904,7 +2904,7 @@ grpc_error* grpc_chttp2_incoming_byte_stream_finished( static void incoming_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast(byte_stream); GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( bs, error, true /* reset_on_error */)); } @@ -2916,7 +2916,7 @@ static const grpc_byte_stream_vtable grpc_chttp2_incoming_byte_stream_vtable = { static void incoming_byte_stream_destroy_locked(void* byte_stream, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + static_cast(byte_stream); grpc_chttp2_stream* s = bs->stream; grpc_chttp2_transport* t = s->t; @@ -2931,8 +2931,8 @@ grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, uint32_t flags) { grpc_chttp2_incoming_byte_stream* incoming_byte_stream = - (grpc_chttp2_incoming_byte_stream*)gpr_malloc( - sizeof(*incoming_byte_stream)); + static_cast(gpr_malloc( + sizeof(*incoming_byte_stream))); incoming_byte_stream->base.length = frame_size; incoming_byte_stream->remaining_bytes = frame_size; incoming_byte_stream->base.flags = flags; @@ -2968,7 +2968,7 @@ static void post_destructive_reclaimer(grpc_chttp2_transport* t) { } static void benign_reclaimer_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast(arg); if (error == GRPC_ERROR_NONE && grpc_chttp2_stream_map_size(&t->stream_map) == 0) { /* Channel with no active streams: send a goaway to try and make it @@ -2996,12 +2996,12 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) { } static void destructive_reclaimer_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast(arg); size_t n = grpc_chttp2_stream_map_size(&t->stream_map); t->destructive_reclaimer_registered = false; if (error == GRPC_ERROR_NONE && n > 0) { grpc_chttp2_stream* s = - (grpc_chttp2_stream*)grpc_chttp2_stream_map_rand(&t->stream_map); + static_cast(grpc_chttp2_stream_map_rand(&t->stream_map)); if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "HTTP2: %s - abandon stream id %d", t->peer_string, s->id); @@ -3078,7 +3078,7 @@ const char* grpc_chttp2_initiate_write_reason_string( } static grpc_endpoint* chttp2_get_endpoint(grpc_transport* t) { - return ((grpc_chttp2_transport*)t)->ep; + return (reinterpret_cast(t))->ep; } static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream), @@ -3097,7 +3097,7 @@ static const grpc_transport_vtable* get_vtable(void) { return &vtable; } grpc_transport* grpc_create_chttp2_transport( const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) { grpc_chttp2_transport* t = - (grpc_chttp2_transport*)gpr_zalloc(sizeof(grpc_chttp2_transport)); + static_cast(gpr_zalloc(sizeof(grpc_chttp2_transport))); init_transport(t, channel_args, ep, is_client); return &t->base; } @@ -3105,7 +3105,7 @@ grpc_transport* grpc_create_chttp2_transport( void grpc_chttp2_transport_start_reading( grpc_transport* transport, grpc_slice_buffer* read_buffer, grpc_closure* notify_on_receive_settings) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)transport; + grpc_chttp2_transport* t = reinterpret_cast(transport); GRPC_CHTTP2_REF_TRANSPORT( t, "reading_action"); /* matches unref inside reading_action */ if (read_buffer != nullptr) { diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index 311fbd60b1..e9014d8234 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -184,10 +184,10 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t, uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) { FlowControlTrace trace("t updt sent", this, nullptr); - const uint32_t target_announced_window = (const uint32_t)target_window(); + const uint32_t target_announced_window = static_cast(target_window()); if ((writing_anyway || announced_window_ <= target_announced_window / 2) && announced_window_ != target_announced_window) { - const uint32_t announce = (uint32_t)GPR_CLAMP( + const uint32_t announce = static_castGPR_CLAMP( target_announced_window - announced_window_, 0, UINT32_MAX); announced_window_ += announce; return announce; @@ -261,7 +261,7 @@ grpc_error* StreamFlowControl::RecvData(int64_t incoming_frame_size) { uint32_t StreamFlowControl::MaybeSendUpdate() { FlowControlTrace trace("s updt sent", tfc_, this); if (local_window_delta_ > announced_window_delta_) { - uint32_t announce = (uint32_t)GPR_CLAMP( + uint32_t announce = static_castGPR_CLAMP( local_window_delta_ - announced_window_delta_, 0, UINT32_MAX); UpdateAnnouncedWindowDelta(tfc_, announce); return announce; @@ -281,12 +281,12 @@ void StreamFlowControl::IncomingByteStreamUpdate(size_t max_size_hint, if (max_size_hint >= UINT32_MAX - sent_init_window) { max_recv_bytes = UINT32_MAX - sent_init_window; } else { - max_recv_bytes = (uint32_t)max_size_hint; + max_recv_bytes = static_cast(max_size_hint); } /* account for bytes already received but unknown to higher layers */ if (max_recv_bytes >= have_already) { - max_recv_bytes -= (uint32_t)have_already; + max_recv_bytes -= static_cast(have_already); } else { max_recv_bytes = 0; } @@ -295,7 +295,7 @@ void StreamFlowControl::IncomingByteStreamUpdate(size_t max_size_hint, GPR_ASSERT(max_recv_bytes <= UINT32_MAX - sent_init_window); if (local_window_delta_ < max_recv_bytes) { uint32_t add_max_recv_bytes = - (uint32_t)(max_recv_bytes - local_window_delta_); + static_cast(max_recv_bytes - local_window_delta_); local_window_delta_ += add_max_recv_bytes; } } @@ -328,7 +328,7 @@ double TransportFlowControl::TargetLogBdp() { double TransportFlowControl::SmoothLogBdp(double value) { grpc_millis now = grpc_core::ExecCtx::Get()->Now(); double bdp_error = value - pid_controller_.last_control_value(); - const double dt = (double)(now - last_pid_update_) * 1e-3; + const double dt = static_cast(now - last_pid_update_) * 1e-3; last_pid_update_ = now; // Limit dt to 100ms const double kMaxDt = 0.1; @@ -338,7 +338,7 @@ double TransportFlowControl::SmoothLogBdp(double value) { FlowControlAction::Urgency TransportFlowControl::DeltaUrgency( int64_t value, grpc_chttp2_setting_id setting_id) { int64_t delta = - (int64_t)value - (int64_t)t_->settings[GRPC_LOCAL_SETTINGS][setting_id]; + value - static_cast(t_->settings[GRPC_LOCAL_SETTINGS][setting_id]); // TODO(ncteisen): tune this if (delta != 0 && (delta <= -value / 5 || delta >= value / 5)) { return FlowControlAction::Urgency::QUEUE_UPDATE; @@ -357,22 +357,22 @@ FlowControlAction TransportFlowControl::PeriodicUpdate() { const double target = pow(2, SmoothLogBdp(TargetLogBdp())); // Though initial window 'could' drop to 0, we keep the floor at 128 - target_initial_window_size_ = (int32_t)GPR_CLAMP(target, 128, INT32_MAX); + target_initial_window_size_ = static_castGPR_CLAMP(target, 128, INT32_MAX); action.set_send_initial_window_update( DeltaUrgency(target_initial_window_size_, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE), - (uint32_t)target_initial_window_size_); + static_cast(target_initial_window_size_)); // get bandwidth estimate and update max_frame accordingly. double bw_dbl = bdp_estimator_.EstimateBandwidth(); // we target the max of BDP or bandwidth in microseconds. - int32_t frame_size = (int32_t)GPR_CLAMP( + int32_t frame_size = static_castGPR_CLAMP( GPR_MAX((int32_t)GPR_CLAMP(bw_dbl, 0, INT_MAX) / 1000, target_initial_window_size_), 16384, 16777215); action.set_send_max_frame_size_update( - DeltaUrgency((int64_t)frame_size, GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE), + DeltaUrgency(static_cast(frame_size), GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE), frame_size); } return UpdateAction(action); diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 19c189393f..7800a55d40 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -44,7 +44,7 @@ namespace grpc_core { namespace chttp2 { static constexpr uint32_t kDefaultWindow = 65535; -static constexpr int64_t kMaxWindow = (int64_t)((1u << 31) - 1); +static constexpr int64_t kMaxWindow = static_cast((1u << 31) - 1); // TODO(ncteisen): Tune this static constexpr uint32_t kFrameSize = 1024 * 1024; @@ -271,7 +271,7 @@ class TransportFlowControl final : public TransportFlowControlBase { // See comment above announced_stream_total_over_incoming_window_ for the // logic behind this decision. int64_t target_window() const override { - return (uint32_t)GPR_MIN((int64_t)((1u << 31) - 1), + return static_castGPR_MIN((int64_t)((1u << 31) - 1), announced_stream_total_over_incoming_window_ + target_initial_window_size_); } diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index 5ea495f2db..dd4830cc17 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -53,7 +53,7 @@ grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, gpr_asprintf(&msg, "unsupported data flags: 0x%02x", flags); grpc_error* err = grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg), - GRPC_ERROR_INT_STREAM_ID, (intptr_t)stream_id); + GRPC_ERROR_INT_STREAM_ID, static_cast(stream_id)); gpr_free(msg); return err; } @@ -78,15 +78,15 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, hdr = GRPC_SLICE_MALLOC(header_size); p = GRPC_SLICE_START_PTR(hdr); GPR_ASSERT(write_bytes < (1 << 24)); - *p++ = (uint8_t)(write_bytes >> 16); - *p++ = (uint8_t)(write_bytes >> 8); - *p++ = (uint8_t)(write_bytes); + *p++ = static_cast(write_bytes >> 16); + *p++ = static_cast(write_bytes >> 8); + *p++ = static_cast(write_bytes); *p++ = GRPC_CHTTP2_FRAME_DATA; *p++ = is_eof ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0; - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); + *p++ = static_cast(id >> 24); + *p++ = static_cast(id >> 16); + *p++ = static_cast(id >> 8); + *p++ = static_cast(id); grpc_slice_buffer_add(outbuf, hdr); grpc_slice_buffer_move_first_no_ref(inbuf, write_bytes, outbuf); @@ -139,7 +139,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( gpr_asprintf(&msg, "Bad GRPC frame type 0x%02x", p->frame_type); p->error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID, - (intptr_t)s->id); + static_cast(s->id)); gpr_free(msg); msg = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); p->error = grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES, @@ -159,7 +159,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( /* fallthrough */ case GRPC_CHTTP2_DATA_FH_1: s->stats.incoming.framing_bytes++; - p->frame_size = ((uint32_t)*cur) << 24; + p->frame_size = (static_cast(*cur)) << 24; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_2; grpc_slice_unref_internal(slice); @@ -168,7 +168,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( /* fallthrough */ case GRPC_CHTTP2_DATA_FH_2: s->stats.incoming.framing_bytes++; - p->frame_size |= ((uint32_t)*cur) << 16; + p->frame_size |= (static_cast(*cur)) << 16; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_3; grpc_slice_unref_internal(slice); @@ -177,7 +177,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( /* fallthrough */ case GRPC_CHTTP2_DATA_FH_3: s->stats.incoming.framing_bytes++; - p->frame_size |= ((uint32_t)*cur) << 8; + p->frame_size |= (static_cast(*cur)) << 8; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_4; grpc_slice_unref_internal(slice); @@ -188,7 +188,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( s->stats.incoming.framing_bytes++; GPR_ASSERT(stream_out != nullptr); GPR_ASSERT(p->parsing_frame == nullptr); - p->frame_size |= ((uint32_t)*cur); + p->frame_size |= (static_cast(*cur)); p->state = GRPC_CHTTP2_DATA_FRAME; ++cur; message_flags = 0; @@ -209,7 +209,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (cur != end) { grpc_slice_buffer_undo_take_first( slices, - grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); + grpc_slice_sub(slice, static_cast(cur - beg), static_cast(end - beg))); } grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; @@ -220,13 +220,13 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_slice_unref_internal(slice); continue; } - uint32_t remaining = (uint32_t)(end - cur); + uint32_t remaining = static_cast(end - cur); if (remaining == p->frame_size) { s->stats.incoming.data_bytes += remaining; if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( p->parsing_frame, - grpc_slice_sub(slice, (size_t)(cur - beg), - (size_t)(end - beg)), + grpc_slice_sub(slice, static_cast(cur - beg), + static_cast(end - beg)), slice_out))) { grpc_slice_unref_internal(slice); return error; @@ -245,8 +245,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( s->stats.incoming.data_bytes += remaining; if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( p->parsing_frame, - grpc_slice_sub(slice, (size_t)(cur - beg), - (size_t)(end - beg)), + grpc_slice_sub(slice, static_cast(cur - beg), + static_cast(end - beg)), slice_out))) { return error; } @@ -259,8 +259,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (GRPC_ERROR_NONE != (grpc_chttp2_incoming_byte_stream_push( p->parsing_frame, - grpc_slice_sub(slice, (size_t)(cur - beg), - (size_t)(cur + p->frame_size - beg)), + grpc_slice_sub(slice, static_cast(cur - beg), + static_cast(cur + p->frame_size - beg)), slice_out))) { grpc_slice_unref_internal(slice); return error; @@ -276,7 +276,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( cur += p->frame_size; grpc_slice_buffer_undo_take_first( slices, - grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); + grpc_slice_sub(slice, static_cast(cur - beg), static_cast(end - beg))); grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; } diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index b60b4227fe..d712bc657e 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -46,7 +46,7 @@ grpc_error* grpc_chttp2_goaway_parser_begin_frame(grpc_chttp2_goaway_parser* p, gpr_free(p->debug_data); p->debug_length = length - 8; - p->debug_data = (char*)gpr_malloc(p->debug_length); + p->debug_data = static_cast(gpr_malloc(p->debug_length)); p->debug_pos = 0; p->state = GRPC_CHTTP2_GOAWAY_LSI0; return GRPC_ERROR_NONE; @@ -59,7 +59,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_goaway_parser* p = (grpc_chttp2_goaway_parser*)parser; + grpc_chttp2_goaway_parser* p = static_cast(parser); switch (p->state) { case GRPC_CHTTP2_GOAWAY_LSI0: @@ -67,7 +67,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI0; return GRPC_ERROR_NONE; } - p->last_stream_id = ((uint32_t)*cur) << 24; + p->last_stream_id = (static_cast(*cur)) << 24; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI1: @@ -75,7 +75,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI1; return GRPC_ERROR_NONE; } - p->last_stream_id |= ((uint32_t)*cur) << 16; + p->last_stream_id |= (static_cast(*cur)) << 16; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI2: @@ -83,7 +83,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI2; return GRPC_ERROR_NONE; } - p->last_stream_id |= ((uint32_t)*cur) << 8; + p->last_stream_id |= (static_cast(*cur)) << 8; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI3: @@ -91,7 +91,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI3; return GRPC_ERROR_NONE; } - p->last_stream_id |= ((uint32_t)*cur); + p->last_stream_id |= (static_cast(*cur)); ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR0: @@ -99,7 +99,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR0; return GRPC_ERROR_NONE; } - p->error_code = ((uint32_t)*cur) << 24; + p->error_code = (static_cast(*cur)) << 24; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR1: @@ -107,7 +107,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR1; return GRPC_ERROR_NONE; } - p->error_code |= ((uint32_t)*cur) << 16; + p->error_code |= (static_cast(*cur)) << 16; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR2: @@ -115,7 +115,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR2; return GRPC_ERROR_NONE; } - p->error_code |= ((uint32_t)*cur) << 8; + p->error_code |= (static_cast(*cur)) << 8; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR3: @@ -123,18 +123,18 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR3; return GRPC_ERROR_NONE; } - p->error_code |= ((uint32_t)*cur); + p->error_code |= (static_cast(*cur)); ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: if (end != cur) - memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); + memcpy(p->debug_data + p->debug_pos, cur, static_cast(end - cur)); GPR_ASSERT((size_t)(end - cur) < UINT32_MAX - p->debug_pos); - p->debug_pos += (uint32_t)(end - cur); + p->debug_pos += static_cast(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; if (is_last) { grpc_chttp2_add_incoming_goaway( - t, (uint32_t)p->error_code, + t, p->error_code, grpc_slice_new(p->debug_data, p->debug_length, gpr_free)); p->debug_data = nullptr; } @@ -151,12 +151,12 @@ void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, uint8_t* p = GRPC_SLICE_START_PTR(header); uint32_t frame_length; GPR_ASSERT(GRPC_SLICE_LENGTH(debug_data) < UINT32_MAX - 4 - 4); - frame_length = 4 + 4 + (uint32_t)GRPC_SLICE_LENGTH(debug_data); + frame_length = 4 + 4 + static_castGRPC_SLICE_LENGTH(debug_data); /* frame header: length */ - *p++ = (uint8_t)(frame_length >> 16); - *p++ = (uint8_t)(frame_length >> 8); - *p++ = (uint8_t)(frame_length); + *p++ = static_cast(frame_length >> 16); + *p++ = static_cast(frame_length >> 8); + *p++ = static_cast(frame_length); /* frame header: type */ *p++ = GRPC_CHTTP2_FRAME_GOAWAY; /* frame header: flags */ @@ -167,15 +167,15 @@ void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, *p++ = 0; *p++ = 0; /* payload: last stream id */ - *p++ = (uint8_t)(last_stream_id >> 24); - *p++ = (uint8_t)(last_stream_id >> 16); - *p++ = (uint8_t)(last_stream_id >> 8); - *p++ = (uint8_t)(last_stream_id); + *p++ = static_cast(last_stream_id >> 24); + *p++ = static_cast(last_stream_id >> 16); + *p++ = static_cast(last_stream_id >> 8); + *p++ = static_cast(last_stream_id); /* payload: error code */ - *p++ = (uint8_t)(error_code >> 24); - *p++ = (uint8_t)(error_code >> 16); - *p++ = (uint8_t)(error_code >> 8); - *p++ = (uint8_t)(error_code); + *p++ = static_cast(error_code >> 24); + *p++ = static_cast(error_code >> 16); + *p++ = static_cast(error_code >> 8); + *p++ = static_cast(error_code); GPR_ASSERT(p == GRPC_SLICE_END_PTR(header)); grpc_slice_buffer_add(slice_buffer, header); grpc_slice_buffer_add(slice_buffer, debug_data); diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index 298a56721a..6229459397 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -40,14 +40,14 @@ grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) { *p++ = 0; *p++ = 0; *p++ = 0; - *p++ = (uint8_t)(opaque_8bytes >> 56); - *p++ = (uint8_t)(opaque_8bytes >> 48); - *p++ = (uint8_t)(opaque_8bytes >> 40); - *p++ = (uint8_t)(opaque_8bytes >> 32); - *p++ = (uint8_t)(opaque_8bytes >> 24); - *p++ = (uint8_t)(opaque_8bytes >> 16); - *p++ = (uint8_t)(opaque_8bytes >> 8); - *p++ = (uint8_t)(opaque_8bytes); + *p++ = static_cast(opaque_8bytes >> 56); + *p++ = static_cast(opaque_8bytes >> 48); + *p++ = static_cast(opaque_8bytes >> 40); + *p++ = static_cast(opaque_8bytes >> 32); + *p++ = static_cast(opaque_8bytes >> 24); + *p++ = static_cast(opaque_8bytes >> 16); + *p++ = static_cast(opaque_8bytes >> 8); + *p++ = static_cast(opaque_8bytes); return slice; } @@ -75,10 +75,10 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_ping_parser* p = (grpc_chttp2_ping_parser*)parser; + grpc_chttp2_ping_parser* p = static_cast(parser); while (p->byte != 8 && cur != end) { - p->opaque_8bytes |= (((uint64_t)*cur) << (56 - 8 * p->byte)); + p->opaque_8bytes |= ((static_cast(*cur)) << (56 - 8 * p->byte)); cur++; p->byte++; } @@ -112,8 +112,8 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, if (!g_disable_ping_ack) { if (t->ping_ack_count == t->ping_ack_capacity) { t->ping_ack_capacity = GPR_MAX(t->ping_ack_capacity * 3 / 2, 3); - t->ping_acks = (uint64_t*)gpr_realloc( - t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks)); + t->ping_acks = static_cast(gpr_realloc( + t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks))); } t->ping_acks[t->ping_ack_count++] = p->opaque_8bytes; grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE); diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc index fee576678d..0b2bc4baed 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -42,15 +42,15 @@ grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, // Flags. *p++ = 0; // Stream ID. - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); + *p++ = static_cast(id >> 24); + *p++ = static_cast(id >> 16); + *p++ = static_cast(id >> 8); + *p++ = static_cast(id); // Error code. - *p++ = (uint8_t)(code >> 24); - *p++ = (uint8_t)(code >> 16); - *p++ = (uint8_t)(code >> 8); - *p++ = (uint8_t)(code); + *p++ = static_cast(code >> 24); + *p++ = static_cast(code >> 16); + *p++ = static_cast(code >> 8); + *p++ = static_cast(code); return slice; } @@ -76,21 +76,21 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_rst_stream_parser* p = (grpc_chttp2_rst_stream_parser*)parser; + grpc_chttp2_rst_stream_parser* p = static_cast(parser); while (p->byte != 4 && cur != end) { p->reason_bytes[p->byte] = *cur; cur++; p->byte++; } - s->stats.incoming.framing_bytes += (uint64_t)(end - cur); + s->stats.incoming.framing_bytes += static_cast(end - cur); if (p->byte == 4) { GPR_ASSERT(is_last); - uint32_t reason = (((uint32_t)p->reason_bytes[0]) << 24) | - (((uint32_t)p->reason_bytes[1]) << 16) | - (((uint32_t)p->reason_bytes[2]) << 8) | - (((uint32_t)p->reason_bytes[3])); + uint32_t reason = ((static_cast(p->reason_bytes[0])) << 24) | + ((static_cast(p->reason_bytes[1])) << 16) | + ((static_cast(p->reason_bytes[2])) << 8) | + ((static_cast(p->reason_bytes[3]))); grpc_error* error = GRPC_ERROR_NONE; if (reason != GRPC_HTTP2_NO_ERROR || s->metadata_buffer[1].size == 0) { char* message; @@ -99,7 +99,7 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, grpc_error_set_str(GRPC_ERROR_CREATE_FROM_STATIC_STRING("RST_STREAM"), GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_copied_string(message)), - GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason); + GRPC_ERROR_INT_HTTP2_ERROR, static_cast(reason)); gpr_free(message); } grpc_chttp2_mark_stream_closed(t, s, true, true, error); diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index 36d6b48f02..2501ad9397 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -31,9 +31,9 @@ #include "src/core/lib/transport/http2_errors.h" static uint8_t* fill_header(uint8_t* out, uint32_t length, uint8_t flags) { - *out++ = (uint8_t)(length >> 16); - *out++ = (uint8_t)(length >> 8); - *out++ = (uint8_t)(length); + *out++ = static_cast(length >> 16); + *out++ = static_cast(length >> 8); + *out++ = static_cast(length); *out++ = GRPC_CHTTP2_FRAME_SETTINGS; *out++ = flags; *out++ = 0; @@ -60,12 +60,12 @@ grpc_slice grpc_chttp2_settings_create(uint32_t* old_settings, for (i = 0; i < count; i++) { if (new_settings[i] != old_settings[i] || (force_mask & (1u << i)) != 0) { - *p++ = (uint8_t)(grpc_setting_id_to_wire_id[i] >> 8); - *p++ = (uint8_t)(grpc_setting_id_to_wire_id[i]); - *p++ = (uint8_t)(new_settings[i] >> 24); - *p++ = (uint8_t)(new_settings[i] >> 16); - *p++ = (uint8_t)(new_settings[i] >> 8); - *p++ = (uint8_t)(new_settings[i]); + *p++ = static_cast(grpc_setting_id_to_wire_id[i] >> 8); + *p++ = static_cast(grpc_setting_id_to_wire_id[i]); + *p++ = static_cast(new_settings[i] >> 24); + *p++ = static_cast(new_settings[i] >> 16); + *p++ = static_cast(new_settings[i] >> 8); + *p++ = static_cast(new_settings[i]); old_settings[i] = new_settings[i]; } } @@ -110,7 +110,7 @@ grpc_error* grpc_chttp2_settings_parser_begin_frame( grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { - grpc_chttp2_settings_parser* parser = (grpc_chttp2_settings_parser*)p; + grpc_chttp2_settings_parser* parser = static_cast(p); const uint8_t* cur = GRPC_SLICE_START_PTR(slice); const uint8_t* end = GRPC_SLICE_END_PTR(slice); char* msg; @@ -137,7 +137,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, } return GRPC_ERROR_NONE; } - parser->id = (uint16_t)(((uint16_t)*cur) << 8); + parser->id = static_cast((static_cast(*cur)) << 8); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_ID1: @@ -145,7 +145,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_ID1; return GRPC_ERROR_NONE; } - parser->id = (uint16_t)(parser->id | (*cur)); + parser->id = static_cast(parser->id | (*cur)); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL0: @@ -153,7 +153,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_VAL0; return GRPC_ERROR_NONE; } - parser->value = ((uint32_t)*cur) << 24; + parser->value = (static_cast(*cur)) << 24; cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL1: @@ -161,7 +161,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_VAL1; return GRPC_ERROR_NONE; } - parser->value |= ((uint32_t)*cur) << 16; + parser->value |= (static_cast(*cur)) << 16; cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL2: @@ -169,7 +169,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_VAL2; return GRPC_ERROR_NONE; } - parser->value |= ((uint32_t)*cur) << 8; + parser->value |= (static_cast(*cur)) << 8; cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL3: @@ -212,11 +212,11 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, if (id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE && parser->incoming_settings[id] != parser->value) { t->initial_window_update += - (int64_t)parser->value - parser->incoming_settings[id]; + static_cast(parser->value) - parser->incoming_settings[id]; if (grpc_http_trace.enabled() || grpc_flowctl_trace.enabled()) { gpr_log(GPR_DEBUG, "%p[%s] adding %d for initial_window change", t, t->is_client ? "cli" : "svr", - (int)t->initial_window_update); + static_cast(t->initial_window_update)); } } parser->incoming_settings[id] = parser->value; diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.cc b/src/core/ext/transport/chttp2/transport/frame_window_update.cc index 418ca144ce..95be5b42d2 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -37,14 +37,14 @@ grpc_slice grpc_chttp2_window_update_create( *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE; *p++ = 0; - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); - *p++ = (uint8_t)(window_update >> 24); - *p++ = (uint8_t)(window_update >> 16); - *p++ = (uint8_t)(window_update >> 8); - *p++ = (uint8_t)(window_update); + *p++ = static_cast(id >> 24); + *p++ = static_cast(id >> 16); + *p++ = static_cast(id >> 8); + *p++ = static_cast(id); + *p++ = static_cast(window_update >> 24); + *p++ = static_cast(window_update >> 16); + *p++ = static_cast(window_update >> 8); + *p++ = static_cast(window_update); return slice; } @@ -73,16 +73,16 @@ grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; grpc_chttp2_window_update_parser* p = - (grpc_chttp2_window_update_parser*)parser; + static_cast(parser); while (p->byte != 4 && cur != end) { - p->amount |= ((uint32_t)*cur) << (8 * (3 - p->byte)); + p->amount |= (static_cast(*cur)) << (8 * (3 - p->byte)); cur++; p->byte++; } if (s != nullptr) { - s->stats.incoming.framing_bytes += (uint32_t)(end - cur); + s->stats.incoming.framing_bytes += static_cast(end - cur); } if (p->byte == 4) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index ba6b43b1dd..dc0e475aa1 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -78,15 +78,15 @@ typedef struct { static void fill_header(uint8_t* p, uint8_t type, uint32_t id, size_t len, uint8_t flags) { GPR_ASSERT(len < 16777316); - *p++ = (uint8_t)(len >> 16); - *p++ = (uint8_t)(len >> 8); - *p++ = (uint8_t)(len); + *p++ = static_cast(len >> 16); + *p++ = static_cast(len >> 8); + *p++ = static_cast(len); *p++ = type; *p++ = flags; - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); + *p++ = static_cast(id >> 24); + *p++ = static_cast(id >> 16); + *p++ = static_cast(id >> 8); + *p++ = static_cast(id); } /* finish a frame - fill in the previously reserved header */ @@ -98,7 +98,7 @@ static void finish_frame(framer_state* st, int is_header_boundary, fill_header( GRPC_SLICE_START_PTR(st->output->slices[st->header_idx]), type, st->stream_id, st->output->length - st->output_length_at_start_of_frame, - (uint8_t)((is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | + static_cast((is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); st->stats->framing_bytes += 9; st->is_first_frame = 0; @@ -170,7 +170,7 @@ static void evict_entry(grpc_chttp2_hpack_compressor* c) { c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); GPR_ASSERT(c->table_elems > 0); c->table_size = - (uint16_t)(c->table_size - + static_cast(c->table_size - c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); c->table_elems--; } @@ -197,8 +197,8 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c, evict_entry(c); } GPR_ASSERT(c->table_elems < c->max_table_size); - c->table_elem_size[new_index % c->cap_table_elems] = (uint16_t)elem_size; - c->table_size = (uint16_t)(c->table_size + elem_size); + c->table_elem_size[new_index % c->cap_table_elems] = static_cast(elem_size); + c->table_size = static_cast(c->table_size + elem_size); c->table_elems++; return new_index; @@ -394,9 +394,9 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor* c, GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + uint32_t len_key = static_castGRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); wire_value value = get_wire_value(elem, st->use_true_binary_metadata); - uint32_t len_val = (uint32_t)wire_value_length(value); + uint32_t len_val = static_cast(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); GPR_ASSERT(len_key <= UINT32_MAX); @@ -416,9 +416,9 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor* c, GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + uint32_t len_key = static_castGRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); wire_value value = get_wire_value(elem, st->use_true_binary_metadata); - uint32_t len_val = (uint32_t)wire_value_length(value); + uint32_t len_val = static_cast(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); GPR_ASSERT(len_key <= UINT32_MAX); @@ -584,7 +584,7 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c) { c->max_table_elems = c->cap_table_elems; c->max_usable_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE; c->table_elem_size = - (uint16_t*)gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems); + static_cast(gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems)); memset(c->table_elem_size, 0, sizeof(*c->table_elem_size) * c->cap_table_elems); for (size_t i = 0; i < GPR_ARRAY_SIZE(c->entries_keys); i++) { @@ -612,7 +612,7 @@ void grpc_chttp2_hpack_compressor_set_max_usable_size( static void rebuild_elems(grpc_chttp2_hpack_compressor* c, uint32_t new_cap) { uint16_t* table_elem_size = - (uint16_t*)gpr_malloc(sizeof(*table_elem_size) * new_cap); + static_cast(gpr_malloc(sizeof(*table_elem_size) * new_cap)); uint32_t i; memset(table_elem_size, 0, sizeof(*table_elem_size) * new_cap); diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 66cc2884e1..4b512b6439 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -757,8 +757,8 @@ static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p, return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Invalid HPACK index received"), - GRPC_ERROR_INT_INDEX, (intptr_t)p->index), - GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); + GRPC_ERROR_INT_INDEX, static_cast(p->index)), + GRPC_ERROR_INT_SIZE, static_cast(p->table.num_ents)); } GRPC_MDELEM_REF(md); GRPC_STATS_INC_HPACK_RECV_INDEXED(); @@ -1087,7 +1087,7 @@ static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, return GRPC_ERROR_NONE; } - *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 7; + *p->parsing.value += ((static_cast(*cur)) & 0x7f) << 7; if ((*cur) & 0x80) { return parse_value2(p, cur + 1, end); @@ -1105,7 +1105,7 @@ static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, return GRPC_ERROR_NONE; } - *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 14; + *p->parsing.value += ((static_cast(*cur)) & 0x7f) << 14; if ((*cur) & 0x80) { return parse_value3(p, cur + 1, end); @@ -1123,7 +1123,7 @@ static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, return GRPC_ERROR_NONE; } - *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 21; + *p->parsing.value += ((static_cast(*cur)) & 0x7f) << 21; if ((*cur) & 0x80) { return parse_value4(p, cur + 1, end); @@ -1152,7 +1152,7 @@ static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur, } cur_value = *p->parsing.value; - add_value = ((uint32_t)c) << 28; + add_value = (static_cast(c)) << 28; if (add_value > 0xffffffffu - cur_value) { goto error; } @@ -1227,13 +1227,13 @@ static void append_bytes(grpc_chttp2_hpack_parser_string* str, if (length == 0) return; if (length + str->data.copied.length > str->data.copied.capacity) { GPR_ASSERT(str->data.copied.length + length <= UINT32_MAX); - str->data.copied.capacity = (uint32_t)(str->data.copied.length + length); + str->data.copied.capacity = static_cast(str->data.copied.length + length); str->data.copied.str = - (char*)gpr_realloc(str->data.copied.str, str->data.copied.capacity); + static_cast(gpr_realloc(str->data.copied.str, str->data.copied.capacity)); } memcpy(str->data.copied.str + str->data.copied.length, data, length); GPR_ASSERT(length <= UINT32_MAX - str->data.copied.length); - str->data.copied.length += (uint32_t)length; + str->data.copied.length += static_cast(length); } static grpc_error* append_string(grpc_chttp2_hpack_parser* p, @@ -1241,9 +1241,9 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, grpc_chttp2_hpack_parser_string* str = p->parsing.str; uint32_t bits; uint8_t decoded[3]; - switch ((binary_state)p->binary) { + switch (static_cast(p->binary)) { case NOT_BINARY: - append_bytes(str, cur, (size_t)(end - cur)); + append_bytes(str, cur, static_cast(end - cur)); return GRPC_ERROR_NONE; case BINARY_BEGIN: if (cur == end) { @@ -1255,7 +1255,7 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, ++cur; p->binary = NOT_BINARY; GRPC_STATS_INC_HPACK_RECV_BINARY(); - append_bytes(str, cur, (size_t)(end - cur)); + append_bytes(str, cur, static_cast(end - cur)); return GRPC_ERROR_NONE; } GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(); @@ -1324,9 +1324,9 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, goto b64_byte3; p->base64_buffer |= bits; bits = p->base64_buffer; - decoded[0] = (uint8_t)(bits >> 16); - decoded[1] = (uint8_t)(bits >> 8); - decoded[2] = (uint8_t)(bits); + decoded[0] = static_cast(bits >> 16); + decoded[1] = static_cast(bits >> 8); + decoded[2] = static_cast(bits); append_bytes(str, decoded, 3); goto b64_byte0; } @@ -1340,7 +1340,7 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, uint8_t decoded[2]; uint32_t bits; grpc_chttp2_hpack_parser_string* str = p->parsing.str; - switch ((binary_state)p->binary) { + switch (static_cast(p->binary)) { case NOT_BINARY: break; case BINARY_BEGIN: @@ -1361,7 +1361,7 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, gpr_free(msg); return parse_error(p, cur, end, err); } - decoded[0] = (uint8_t)(bits >> 16); + decoded[0] = static_cast(bits >> 16); append_bytes(str, decoded, 1); break; case B64_BYTE3: @@ -1374,8 +1374,8 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, gpr_free(msg); return parse_error(p, cur, end, err); } - decoded[0] = (uint8_t)(bits >> 16); - decoded[1] = (uint8_t)(bits >> 8); + decoded[0] = static_cast(bits >> 16); + decoded[1] = static_cast(bits >> 8); append_bytes(str, decoded, 2); break; } @@ -1388,7 +1388,7 @@ static grpc_error* huff_nibble(grpc_chttp2_hpack_parser* p, uint8_t nibble) { int16_t next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble]; if (emit != -1) { if (emit >= 0 && emit < 256) { - uint8_t c = (uint8_t)emit; + uint8_t c = static_cast(emit); grpc_error* err = append_string(p, &c, (&c) + 1); if (err != GRPC_ERROR_NONE) return err; } else { @@ -1426,7 +1426,7 @@ static grpc_error* add_str_bytes(grpc_chttp2_hpack_parser* p, static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { size_t remaining = p->strlen - p->strgot; - size_t given = (size_t)(end - cur); + size_t given = static_cast(end - cur); if (remaining <= given) { grpc_error* err = add_str_bytes(p, cur, cur + remaining); if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); @@ -1437,7 +1437,7 @@ static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, grpc_error* err = add_str_bytes(p, cur, cur + given); if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); GPR_ASSERT(given <= UINT32_MAX - p->strgot); - p->strgot += (uint32_t)given; + p->strgot += static_cast(given); p->state = parse_string; return GRPC_ERROR_NONE; } @@ -1448,12 +1448,12 @@ static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, uint8_t binary, grpc_chttp2_hpack_parser_string* str) { - if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && + if (!p->huff && binary == NOT_BINARY && (end - cur) >= static_cast(p->strlen) && p->current_slice_refcount != nullptr) { GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(); str->copied = false; str->data.referenced.refcount = p->current_slice_refcount; - str->data.referenced.data.refcounted.bytes = (uint8_t*)cur; + str->data.referenced.data.refcounted.bytes = const_cast(cur); str->data.referenced.data.refcounted.length = p->strlen; grpc_slice_ref_internal(str->data.referenced); return parse_next(p, cur + p->strlen, end); @@ -1503,8 +1503,8 @@ static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p, return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Invalid HPACK index received"), - GRPC_ERROR_INT_INDEX, (intptr_t)p->index), - GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); + GRPC_ERROR_INT_INDEX, static_cast(p->index)), + GRPC_ERROR_INT_SIZE, static_cast(p->table.num_ents)); } *is = grpc_is_binary_header(GRPC_MDKEY(elem)); return GRPC_ERROR_NONE; @@ -1589,7 +1589,7 @@ static const maybe_complete_func_type maybe_complete_funcs[] = { grpc_chttp2_maybe_complete_recv_trailing_metadata}; static void force_client_rst_stream(void* sp, grpc_error* error) { - grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; + grpc_chttp2_stream* s = static_cast(sp); grpc_chttp2_transport* t = s->t; if (!s->write_closed) { grpc_slice_buffer_add( @@ -1618,7 +1618,7 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { GPR_TIMER_SCOPE("grpc_chttp2_hpack_parser_parse", 0); - grpc_chttp2_hpack_parser* parser = (grpc_chttp2_hpack_parser*)hpack_parser; + grpc_chttp2_hpack_parser* parser = static_cast(hpack_parser); if (s != nullptr) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index 9fad158d27..e8c44e35ab 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -173,7 +173,7 @@ void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl) { GRPC_CHTTP2_INITIAL_HPACK_TABLE_SIZE; tbl->max_entries = tbl->cap_entries = entries_for_bytes(tbl->current_table_bytes); - tbl->ents = (grpc_mdelem*)gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries); + tbl->ents = static_cast(gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries)); memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { tbl->static_ents[i - 1] = grpc_mdelem_from_slices( @@ -218,14 +218,14 @@ static void evict1(grpc_chttp2_hptbl* tbl) { GRPC_SLICE_LENGTH(GRPC_MDVALUE(first_ent)) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GPR_ASSERT(elem_bytes <= tbl->mem_used); - tbl->mem_used -= (uint32_t)elem_bytes; + tbl->mem_used -= static_cast(elem_bytes); tbl->first_ent = ((tbl->first_ent + 1) % tbl->cap_entries); tbl->num_ents--; GRPC_MDELEM_UNREF(first_ent); } static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { - grpc_mdelem* ents = (grpc_mdelem*)gpr_malloc(sizeof(*ents) * new_cap); + grpc_mdelem* ents = static_cast(gpr_malloc(sizeof(*ents) * new_cap)); uint32_t i; for (i = 0; i < tbl->num_ents; i++) { @@ -320,7 +320,7 @@ grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { } /* evict entries to ensure no overflow */ - while (elem_bytes > (size_t)tbl->current_table_bytes - tbl->mem_used) { + while (elem_bytes > static_cast(tbl->current_table_bytes) - tbl->mem_used) { evict1(tbl); } @@ -330,7 +330,7 @@ grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { /* update accounting values */ tbl->num_ents++; - tbl->mem_used += (uint32_t)elem_bytes; + tbl->mem_used += static_cast(elem_bytes); return GRPC_ERROR_NONE; } @@ -351,7 +351,7 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( /* Scan the dynamic table */ for (i = 0; i < tbl->num_ents; i++) { uint32_t idx = - (uint32_t)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); + static_cast(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); grpc_mdelem ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; r.index = idx; diff --git a/src/core/ext/transport/chttp2/transport/http2_settings.cc b/src/core/ext/transport/chttp2/transport/http2_settings.cc index 4248496f48..745b1656f9 100644 --- a/src/core/ext/transport/chttp2/transport/http2_settings.cc +++ b/src/core/ext/transport/chttp2/transport/http2_settings.cc @@ -35,7 +35,7 @@ bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id* out) { h += 4; break; } - *out = (grpc_chttp2_setting_id)h; + *out = static_cast(h); return h < GPR_ARRAY_SIZE(grpc_setting_id_to_wire_id) && grpc_setting_id_to_wire_id[h] == wire_id; } diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index ef0c9ed230..2d06bb5038 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc @@ -42,8 +42,8 @@ grpc_error* grpc_chttp2_incoming_metadata_buffer_add( buffer->size += GRPC_MDELEM_LENGTH(elem); return grpc_metadata_batch_add_tail( &buffer->batch, - (grpc_linked_mdelem*)gpr_arena_alloc(buffer->arena, - sizeof(grpc_linked_mdelem)), + static_cast(gpr_arena_alloc(buffer->arena, + sizeof(grpc_linked_mdelem))), elem); } diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index fb6d30b62d..d720397de5 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -88,15 +88,15 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " "at byte %d", GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state], - (int)(uint8_t)GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state], - *cur, (int)*cur, t->deframe_state); + static_cast(static_cast(GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state])), + *cur, static_cast(*cur), t->deframe_state); err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } ++cur; t->deframe_state = - (grpc_chttp2_deframe_transport_state)(1 + (int)t->deframe_state); + static_cast(1 + static_cast(t->deframe_state)); } if (cur == end) { return GRPC_ERROR_NONE; @@ -105,7 +105,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, dts_fh_0: case GRPC_DTS_FH_0: GPR_ASSERT(cur < end); - t->incoming_frame_size = ((uint32_t)*cur) << 16; + t->incoming_frame_size = (static_cast(*cur)) << 16; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_1; return GRPC_ERROR_NONE; @@ -113,7 +113,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_1: GPR_ASSERT(cur < end); - t->incoming_frame_size |= ((uint32_t)*cur) << 8; + t->incoming_frame_size |= (static_cast(*cur)) << 8; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_2; return GRPC_ERROR_NONE; @@ -145,7 +145,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_5: GPR_ASSERT(cur < end); - t->incoming_stream_id = (((uint32_t)*cur) & 0x7f) << 24; + t->incoming_stream_id = ((static_cast(*cur)) & 0x7f) << 24; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_6; return GRPC_ERROR_NONE; @@ -153,7 +153,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_6: GPR_ASSERT(cur < end); - t->incoming_stream_id |= ((uint32_t)*cur) << 16; + t->incoming_stream_id |= (static_cast(*cur)) << 16; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_7; return GRPC_ERROR_NONE; @@ -161,7 +161,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_7: GPR_ASSERT(cur < end); - t->incoming_stream_id |= ((uint32_t)*cur) << 8; + t->incoming_stream_id |= (static_cast(*cur)) << 8; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_8; return GRPC_ERROR_NONE; @@ -169,7 +169,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_8: GPR_ASSERT(cur < end); - t->incoming_stream_id |= ((uint32_t)*cur); + t->incoming_stream_id |= (static_cast(*cur)); t->deframe_state = GRPC_DTS_FRAME; err = init_frame_parser(t); if (err != GRPC_ERROR_NONE) { @@ -205,11 +205,11 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); - if ((uint32_t)(end - cur) == t->incoming_frame_size) { + if (static_cast(end - cur) == t->incoming_frame_size) { err = parse_frame_slice(t, - grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), + grpc_slice_sub_no_ref(slice, static_cast(cur - beg), + static_cast(end - beg)), 1); if (err != GRPC_ERROR_NONE) { return err; @@ -217,8 +217,8 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, t->deframe_state = GRPC_DTS_FH_0; t->incoming_stream = nullptr; return GRPC_ERROR_NONE; - } else if ((uint32_t)(end - cur) > t->incoming_frame_size) { - size_t cur_offset = (size_t)(cur - beg); + } else if (static_cast(end - cur) > t->incoming_frame_size) { + size_t cur_offset = static_cast(cur - beg); err = parse_frame_slice( t, grpc_slice_sub_no_ref(slice, cur_offset, @@ -233,13 +233,13 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, } else { err = parse_frame_slice(t, - grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), + grpc_slice_sub_no_ref(slice, static_cast(cur - beg), + static_cast(end - beg)), 0); if (err != GRPC_ERROR_NONE) { return err; } - t->incoming_frame_size -= (uint32_t)(end - cur); + t->incoming_frame_size -= static_cast(end - cur); return GRPC_ERROR_NONE; } GPR_UNREACHABLE_CODE(return nullptr); @@ -325,7 +325,7 @@ static grpc_error* init_skip_frame_parser(grpc_chttp2_transport* t, t->hpack_parser.on_header = skip_header; t->hpack_parser.on_header_user_data = nullptr; t->hpack_parser.is_boundary = is_eoh; - t->hpack_parser.is_eof = (uint8_t)(is_eoh ? t->header_eof : 0); + t->hpack_parser.is_eof = static_cast(is_eoh ? t->header_eof : 0); } else { t->parser = skip_parser; } @@ -394,7 +394,7 @@ static void free_timeout(void* p) { gpr_free(p); } static void on_initial_header(void* tp, grpc_mdelem md) { GPR_TIMER_SCOPE("on_initial_header", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); grpc_chttp2_stream* s = t->incoming_stream; GPR_ASSERT(s != nullptr); @@ -429,7 +429,7 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (GRPC_MDELEM_IS_INTERNED(md)) { /* store the result */ - cached_timeout = (grpc_millis*)gpr_malloc(sizeof(grpc_millis)); + cached_timeout = static_cast(gpr_malloc(sizeof(grpc_millis))); *cached_timeout = timeout; grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } @@ -474,7 +474,7 @@ static void on_initial_header(void* tp, grpc_mdelem md) { static void on_trailing_header(void* tp, grpc_mdelem md) { GPR_TIMER_SCOPE("on_trailing_header", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast(tp); grpc_chttp2_stream* s = t->incoming_stream; GPR_ASSERT(s != nullptr); @@ -634,7 +634,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, } t->hpack_parser.on_header_user_data = t; t->hpack_parser.is_boundary = is_eoh; - t->hpack_parser.is_eof = (uint8_t)(is_eoh ? t->header_eof : 0); + t->hpack_parser.is_eof = static_cast(is_eoh ? t->header_eof : 0); if (!is_continuation && (t->incoming_frame_flags & GRPC_CHTTP2_FLAG_HAS_PRIORITY)) { grpc_chttp2_hpack_parser_set_has_priority(&t->hpack_parser); diff --git a/src/core/ext/transport/chttp2/transport/stream_map.cc b/src/core/ext/transport/chttp2/transport/stream_map.cc index d59ff405f5..045f868430 100644 --- a/src/core/ext/transport/chttp2/transport/stream_map.cc +++ b/src/core/ext/transport/chttp2/transport/stream_map.cc @@ -26,8 +26,8 @@ void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map* map, size_t initial_capacity) { GPR_ASSERT(initial_capacity > 1); - map->keys = (uint32_t*)gpr_malloc(sizeof(uint32_t) * initial_capacity); - map->values = (void**)gpr_malloc(sizeof(void*) * initial_capacity); + map->keys = static_cast(gpr_malloc(sizeof(uint32_t) * initial_capacity)); + map->values = static_cast(gpr_malloc(sizeof(void*) * initial_capacity)); map->count = 0; map->free = 0; map->capacity = initial_capacity; @@ -72,9 +72,9 @@ void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map* map, uint32_t key, won't help much */ map->capacity = capacity = 3 * capacity / 2; map->keys = keys = - (uint32_t*)gpr_realloc(keys, capacity * sizeof(uint32_t)); + static_cast(gpr_realloc(keys, capacity * sizeof(uint32_t))); map->values = values = - (void**)gpr_realloc(values, capacity * sizeof(void*)); + static_cast(gpr_realloc(values, capacity * sizeof(void*))); } } @@ -146,7 +146,7 @@ void* grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map* map) { map->free = 0; GPR_ASSERT(map->count > 0); } - return map->values[((size_t)rand()) % map->count]; + return map->values[(static_cast(rand())) % map->count]; } void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map* map, diff --git a/src/core/ext/transport/chttp2/transport/varint.cc b/src/core/ext/transport/chttp2/transport/varint.cc index 0d94ddcbc3..621a8100c7 100644 --- a/src/core/ext/transport/chttp2/transport/varint.cc +++ b/src/core/ext/transport/chttp2/transport/varint.cc @@ -36,19 +36,19 @@ void grpc_chttp2_hpack_write_varint_tail(uint32_t tail_value, uint8_t* target, uint32_t tail_length) { switch (tail_length) { case 5: - target[4] = (uint8_t)((tail_value >> 28) | 0x80); + target[4] = static_cast((tail_value >> 28) | 0x80); /* fallthrough */ case 4: - target[3] = (uint8_t)((tail_value >> 21) | 0x80); + target[3] = static_cast((tail_value >> 21) | 0x80); /* fallthrough */ case 3: - target[2] = (uint8_t)((tail_value >> 14) | 0x80); + target[2] = static_cast((tail_value >> 14) | 0x80); /* fallthrough */ case 2: - target[1] = (uint8_t)((tail_value >> 7) | 0x80); + target[1] = static_cast((tail_value >> 7) | 0x80); /* fallthrough */ case 1: - target[0] = (uint8_t)((tail_value) | 0x80); + target[0] = static_cast((tail_value) | 0x80); } target[tail_length - 1] &= 0x7f; } diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 1d6c9b0582..b5970fd646 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -83,8 +83,8 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { "%s: Ping delayed [%p]: not enough time elapsed since last ping. " " Last ping %f: Next ping %f: Now %f", t->is_client ? "CLIENT" : "SERVER", t->peer_string, - (double)t->ping_state.last_ping_sent_time, - (double)next_allowed_ping, (double)now); + static_cast(t->ping_state.last_ping_sent_time), + static_cast(next_allowed_ping), static_cast(now)); } if (!t->ping_state.is_delayed_ping_timer_set) { t->ping_state.is_delayed_ping_timer_set = true; @@ -147,7 +147,7 @@ static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s, t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE], t->flow_control->remote_window(), - (uint32_t)GPR_MAX( + static_castGPR_MAX( 0, s->flow_control->remote_window_delta() + (int64_t)t->settings[GRPC_PEER_SETTINGS] @@ -310,14 +310,14 @@ class DataSendContext { sending_bytes_before_(s_->sending_bytes) {} uint32_t stream_remote_window() const { - return (uint32_t)GPR_MAX( + return static_castGPR_MAX( 0, s_->flow_control->remote_window_delta() + (int64_t)t_->settings[GRPC_PEER_SETTINGS] [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]); } uint32_t max_outgoing() const { - return (uint32_t)GPR_MIN( + return static_castGPR_MIN( t_->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], GPR_MIN(stream_remote_window(), t_->flow_control->remote_window())); } @@ -326,7 +326,7 @@ class DataSendContext { void FlushCompressedBytes() { uint32_t send_bytes = - (uint32_t)GPR_MIN(max_outgoing(), s_->compressed_data_buffer.length); + static_castGPR_MIN(max_outgoing(), s_->compressed_data_buffer.length); bool is_last_data_frame = (send_bytes == s_->compressed_data_buffer.length && s_->flow_controlled_buffer.length == 0 && @@ -376,7 +376,7 @@ class DataSendContext { void CallCallbacks() { if (update_list(t_, s_, - (int64_t)(s_->sending_bytes - sending_bytes_before_), + static_cast(s_->sending_bytes - sending_bytes_before_), &s_->on_flow_controlled_cbs, &s_->flow_controlled_bytes_flowed, GRPC_ERROR_NONE)) { write_context_->NoteScheduledResults(); @@ -624,7 +624,7 @@ void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error) { while (grpc_chttp2_list_pop_writing_stream(t, &s)) { if (s->sending_bytes != 0) { - update_list(t, s, (int64_t)s->sending_bytes, &s->on_write_finished_cbs, + update_list(t, s, static_cast(s->sending_bytes), &s->on_write_finished_cbs, &s->flow_controlled_bytes_written, GRPC_ERROR_REF(error)); s->sending_bytes = 0; } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index e23c07f16c..3111b6db43 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -284,7 +284,7 @@ static void maybe_flush_read(stream_obj* s) { CRONET_LOG(GPR_DEBUG, "%p: Flush read", s); s->state.flush_read = true; null_and_maybe_free_read_buffer(s); - s->state.rs.read_buffer = (char*)gpr_malloc(GRPC_FLUSH_READ_SIZE); + s->state.rs.read_buffer = static_cast(gpr_malloc(GRPC_FLUSH_READ_SIZE)); if (!s->state.pending_read_from_cronet) { CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); bidirectional_stream_read(s->cbs, s->state.rs.read_buffer, @@ -310,7 +310,7 @@ static void add_to_storage(struct stream_obj* s, /* add new op at the beginning of the linked list. The memory is freed in remove_from_storage */ struct op_and_state* new_op = - (struct op_and_state*)gpr_malloc(sizeof(struct op_and_state)); + static_cast(gpr_malloc(sizeof(struct op_and_state))); memcpy(&new_op->op, op, sizeof(grpc_transport_stream_op_batch)); memset(&new_op->state, 0, sizeof(new_op->state)); new_op->s = s; @@ -399,7 +399,7 @@ static void on_failed(bidirectional_stream* stream, int net_error) { gpr_log(GPR_ERROR, "on_failed(%p, %d)", stream, net_error); grpc_core::ExecCtx exec_ctx; - stream_obj* s = (stream_obj*)stream->annotation; + stream_obj* s = static_cast(stream->annotation); gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_FAILED] = true; @@ -425,7 +425,7 @@ static void on_canceled(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream); grpc_core::ExecCtx exec_ctx; - stream_obj* s = (stream_obj*)stream->annotation; + stream_obj* s = static_cast(stream->annotation); gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_CANCELED] = true; @@ -451,7 +451,7 @@ static void on_succeeded(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream); grpc_core::ExecCtx exec_ctx; - stream_obj* s = (stream_obj*)stream->annotation; + stream_obj* s = static_cast(stream->annotation); gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_SUCCEEDED] = true; @@ -468,8 +468,8 @@ static void on_succeeded(bidirectional_stream* stream) { static void on_stream_ready(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "W: on_stream_ready(%p)", stream); grpc_core::ExecCtx exec_ctx; - stream_obj* s = (stream_obj*)stream->annotation; - grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; + stream_obj* s = static_cast(stream->annotation); + grpc_cronet_transport* t = s->curr_ct; gpr_mu_lock(&s->mu); s->state.state_op_done[OP_SEND_INITIAL_METADATA] = true; s->state.state_callback_received[OP_SEND_INITIAL_METADATA] = true; @@ -500,7 +500,7 @@ static void on_response_headers_received( grpc_core::ExecCtx exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol); - stream_obj* s = (stream_obj*)stream->annotation; + stream_obj* s = static_cast(stream->annotation); /* Identify if this is a header or a trailer (in a trailer-only response case) */ @@ -550,7 +550,7 @@ static void on_response_headers_received( */ static void on_write_completed(bidirectional_stream* stream, const char* data) { grpc_core::ExecCtx exec_ctx; - stream_obj* s = (stream_obj*)stream->annotation; + stream_obj* s = static_cast(stream->annotation); CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); gpr_mu_lock(&s->mu); if (s->state.ws.write_buffer) { @@ -568,7 +568,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { static void on_read_completed(bidirectional_stream* stream, char* data, int count) { grpc_core::ExecCtx exec_ctx; - stream_obj* s = (stream_obj*)stream->annotation; + stream_obj* s = static_cast(stream->annotation); CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data, count); gpr_mu_lock(&s->mu); @@ -612,8 +612,8 @@ static void on_response_trailers_received( grpc_core::ExecCtx exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, trailers); - stream_obj* s = (stream_obj*)stream->annotation; - grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; + stream_obj* s = static_cast(stream->annotation); + grpc_cronet_transport* t = s->curr_ct; gpr_mu_lock(&s->mu); memset(&s->state.rs.trailing_metadata, 0, sizeof(s->state.rs.trailing_metadata)); @@ -671,17 +671,17 @@ static void create_grpc_frame(grpc_slice_buffer* write_slice_buffer, size_t length = GRPC_SLICE_LENGTH(slice); *p_write_buffer_size = length + GRPC_HEADER_SIZE_IN_BYTES; /* This is freed in the on_write_completed callback */ - char* write_buffer = (char*)gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES); + char* write_buffer = static_cast(gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES)); *pp_write_buffer = write_buffer; - uint8_t* p = (uint8_t*)write_buffer; + uint8_t* p = reinterpret_cast(write_buffer); /* Append 5 byte header */ /* Compressed flag */ - *p++ = (uint8_t)((flags & GRPC_WRITE_INTERNAL_COMPRESS) ? 1 : 0); + *p++ = static_cast((flags & GRPC_WRITE_INTERNAL_COMPRESS) ? 1 : 0); /* Message length */ - *p++ = (uint8_t)(length >> 24); - *p++ = (uint8_t)(length >> 16); - *p++ = (uint8_t)(length >> 8); - *p++ = (uint8_t)(length); + *p++ = static_cast(length >> 24); + *p++ = static_cast(length >> 16); + *p++ = static_cast(length >> 8); + *p++ = static_cast(length); /* append actual data */ memcpy(p, GRPC_SLICE_START_PTR(slice), length); grpc_slice_unref_internal(slice); @@ -704,8 +704,8 @@ static void convert_metadata_to_cronet_headers( /* Allocate enough memory. It is freed in the on_stream_ready callback */ bidirectional_stream_header* headers = - (bidirectional_stream_header*)gpr_malloc( - sizeof(bidirectional_stream_header) * num_headers_available); + static_cast(gpr_malloc( + sizeof(bidirectional_stream_header) * num_headers_available)); *pp_headers = headers; /* Walk the linked list again, this time copying the header fields. @@ -753,7 +753,7 @@ static void convert_metadata_to_cronet_headers( break; } } - *p_num_headers = (size_t)num_headers; + *p_num_headers = num_headers; } static void parse_grpc_header(const uint8_t* data, int* length, @@ -762,10 +762,10 @@ static void parse_grpc_header(const uint8_t* data, int* length, const uint8_t* p = data + 1; *compressed = ((c & 0x01) == 0x01); *length = 0; - *length |= ((uint8_t)*p++) << 24; - *length |= ((uint8_t)*p++) << 16; - *length |= ((uint8_t)*p++) << 8; - *length |= ((uint8_t)*p++); + *length |= (*p++) << 24; + *length |= (*p++) << 16; + *length |= (*p++) << 8; + *length |= (*p++); } static bool header_has_authority(grpc_linked_mdelem* head) { @@ -968,7 +968,7 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op, static enum e_op_result execute_stream_op(struct op_and_state* oas) { grpc_transport_stream_op_batch* stream_op = &oas->op; struct stream_obj* s = oas->s; - grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; + grpc_cronet_transport* t = s->curr_ct; struct op_state* stream_state = &s->state; enum e_op_result result = NO_ACTION_POSSIBLE; if (stream_op->send_initial_metadata && @@ -1050,7 +1050,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { stream_state->ws.write_buffer); stream_state->state_callback_received[OP_SEND_MESSAGE] = false; bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer, - (int)write_buffer_size, false); + static_cast(write_buffer_size), false); grpc_slice_buffer_destroy_internal(&write_slice_buffer); if (t->use_packet_coalescing) { if (!stream_op->send_trailing_metadata) { @@ -1151,14 +1151,14 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { stream_state->rs.remaining_bytes == 0) { /* Start a read operation for data */ stream_state->rs.length_field_received = true; - parse_grpc_header((const uint8_t*)stream_state->rs.read_buffer, + parse_grpc_header(reinterpret_cast(stream_state->rs.read_buffer), &stream_state->rs.length_field, &stream_state->rs.compressed); CRONET_LOG(GPR_DEBUG, "length field = %d", stream_state->rs.length_field); if (stream_state->rs.length_field > 0) { stream_state->rs.read_buffer = - (char*)gpr_malloc((size_t)stream_state->rs.length_field); + static_cast(gpr_malloc(static_cast(stream_state->rs.length_field))); GPR_ASSERT(stream_state->rs.read_buffer); stream_state->rs.remaining_bytes = stream_state->rs.length_field; stream_state->rs.received_bytes = 0; @@ -1181,8 +1181,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags |= GRPC_WRITE_INTERNAL_COMPRESS; } - *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = - (grpc_byte_buffer*)&stream_state->rs.sbs; + *(reinterpret_cast(stream_op->payload->recv_message.recv_message)) = + reinterpret_cast(&stream_state->rs.sbs); GRPC_CLOSURE_SCHED( stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); @@ -1225,7 +1225,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { GRPC_SLICE_MALLOC((uint32_t)stream_state->rs.length_field); uint8_t* dst_p = GRPC_SLICE_START_PTR(read_data_slice); memcpy(dst_p, stream_state->rs.read_buffer, - (size_t)stream_state->rs.length_field); + static_cast(stream_state->rs.length_field)); null_and_maybe_free_read_buffer(s); /* Clean up read_slice_buffer in case there is unread data. */ grpc_slice_buffer_destroy_internal(&stream_state->rs.read_slice_buffer); @@ -1237,8 +1237,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags = GRPC_WRITE_INTERNAL_COMPRESS; } - *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = - (grpc_byte_buffer*)&stream_state->rs.sbs; + *(reinterpret_cast(stream_op->payload->recv_message.recv_message)) = + reinterpret_cast(&stream_state->rs.sbs); GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; @@ -1325,7 +1325,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { static int init_stream(grpc_transport* gt, grpc_stream* gs, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena) { - stream_obj* s = (stream_obj*)gs; + stream_obj* s = reinterpret_cast(gs); s->refcount = refcount; GRPC_CRONET_STREAM_REF(s, "cronet transport"); @@ -1348,7 +1348,7 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, s->state.pending_read_from_cronet = false; s->curr_gs = gs; - s->curr_ct = (grpc_cronet_transport*)gt; + s->curr_ct = reinterpret_cast(gt); s->arena = arena; gpr_mu_init(&s->mu); @@ -1381,14 +1381,14 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_CANCELLED); return; } - stream_obj* s = (stream_obj*)gs; + stream_obj* s = reinterpret_cast(gs); add_to_storage(s, op); execute_from_storage(s); } static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { - stream_obj* s = (stream_obj*)gs; + stream_obj* s = reinterpret_cast(gs); null_and_maybe_free_read_buffer(s); /* Clean up read_slice_buffer in case there is unread data. */ grpc_slice_buffer_destroy_internal(&s->state.rs.read_slice_buffer); @@ -1418,13 +1418,13 @@ grpc_transport* grpc_create_cronet_transport(void* engine, const char* target, const grpc_channel_args* args, void* reserved) { grpc_cronet_transport* ct = - (grpc_cronet_transport*)gpr_malloc(sizeof(grpc_cronet_transport)); + static_cast(gpr_malloc(sizeof(grpc_cronet_transport))); if (!ct) { goto error; } ct->base.vtable = &grpc_cronet_vtable; - ct->engine = (stream_engine*)engine; - ct->host = (char*)gpr_malloc(strlen(target) + 1); + ct->engine = static_cast(engine); + ct->host = static_cast(gpr_malloc(strlen(target) + 1)); if (!ct->host) { goto error; } diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 8dd0b7dce2..97d908fa5d 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -209,7 +209,7 @@ static grpc_error* fill_in_metadata(inproc_stream* s, for (grpc_linked_mdelem* elem = metadata->list.head; (elem != nullptr) && (error == GRPC_ERROR_NONE); elem = elem->next) { grpc_linked_mdelem* nelem = - (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*nelem)); + static_cast(gpr_arena_alloc(s->arena, sizeof(*nelem))); nelem->md = grpc_mdelem_from_slices(grpc_slice_intern(GRPC_MDKEY(elem->md)), grpc_slice_intern(GRPC_MDVALUE(elem->md))); @@ -223,8 +223,8 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena) { INPROC_LOG(GPR_DEBUG, "init_stream %p %p %p", gt, gs, server_data); - inproc_transport* t = (inproc_transport*)gt; - inproc_stream* s = (inproc_stream*)gs; + inproc_transport* t = reinterpret_cast(gt); + inproc_stream* s = reinterpret_cast(gs); s->arena = arena; s->refs = refcount; @@ -368,11 +368,11 @@ static void close_other_side_locked(inproc_stream* s, const char* reason) { static void complete_if_batch_end_locked(inproc_stream* s, grpc_error* error, grpc_transport_stream_op_batch* op, const char* msg) { - int is_sm = (int)(op == s->send_message_op); - int is_stm = (int)(op == s->send_trailing_md_op); - int is_rim = (int)(op == s->recv_initial_md_op); - int is_rm = (int)(op == s->recv_message_op); - int is_rtm = (int)(op == s->recv_trailing_md_op); + int is_sm = static_cast(op == s->send_message_op); + int is_stm = static_cast(op == s->send_trailing_md_op); + int is_rim = static_cast(op == s->recv_initial_md_op); + int is_rm = static_cast(op == s->recv_message_op); + int is_rtm = static_cast(op == s->recv_trailing_md_op); if ((is_sm + is_stm + is_rim + is_rm + is_rtm) == 1) { INPROC_LOG(GPR_DEBUG, "%s %p %p %p", msg, s, op, error); @@ -426,12 +426,12 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { grpc_metadata_batch fake_md; grpc_metadata_batch_init(&fake_md); grpc_linked_mdelem* path_md = - (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*path_md)); + static_cast(gpr_arena_alloc(s->arena, sizeof(*path_md))); path_md->md = grpc_mdelem_from_slices(g_fake_path_key, g_fake_path_value); GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, path_md) == GRPC_ERROR_NONE); grpc_linked_mdelem* auth_md = - (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*auth_md)); + static_cast(gpr_arena_alloc(s->arena, sizeof(*auth_md))); auth_md->md = grpc_mdelem_from_slices(g_fake_auth_key, g_fake_auth_value); GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, auth_md) == GRPC_ERROR_NONE); @@ -566,7 +566,7 @@ static void op_state_machine(void* arg, grpc_error* error) { bool needs_close = false; INPROC_LOG(GPR_DEBUG, "op_state_machine %p", arg); - inproc_stream* s = (inproc_stream*)arg; + inproc_stream* s = static_cast(arg); gpr_mu* mu = &s->t->mu->mu; // keep aside in case s gets closed gpr_mu_lock(mu); s->op_closure_scheduled = false; @@ -863,7 +863,7 @@ static bool cancel_stream_locked(inproc_stream* s, grpc_error* error) { static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, grpc_transport_stream_op_batch* op) { INPROC_LOG(GPR_DEBUG, "perform_stream_op %p %p %p", gt, gs, op); - inproc_stream* s = (inproc_stream*)gs; + inproc_stream* s = reinterpret_cast(gs); gpr_mu* mu = &s->t->mu->mu; // save aside in case s gets closed gpr_mu_lock(mu); @@ -1047,7 +1047,7 @@ static void close_transport_locked(inproc_transport* t) { } static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { - inproc_transport* t = (inproc_transport*)gt; + inproc_transport* t = reinterpret_cast(gt); INPROC_LOG(GPR_DEBUG, "perform_transport_op %p %p", t, op); gpr_mu_lock(&t->mu->mu); if (op->on_connectivity_state_change) { @@ -1082,13 +1082,13 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { INPROC_LOG(GPR_DEBUG, "destroy_stream %p %p", gs, then_schedule_closure); - inproc_stream* s = (inproc_stream*)gs; + inproc_stream* s = reinterpret_cast(gs); s->closure_at_destroy = then_schedule_closure; really_destroy_stream(s); } static void destroy_transport(grpc_transport* gt) { - inproc_transport* t = (inproc_transport*)gt; + inproc_transport* t = reinterpret_cast(gt); INPROC_LOG(GPR_DEBUG, "destroy_transport %p", t); gpr_mu_lock(&t->mu->mu); close_transport_locked(t); @@ -1151,10 +1151,10 @@ static void inproc_transports_create(grpc_transport** server_transport, grpc_transport** client_transport, const grpc_channel_args* client_args) { INPROC_LOG(GPR_DEBUG, "inproc_transports_create"); - inproc_transport* st = (inproc_transport*)gpr_zalloc(sizeof(*st)); - inproc_transport* ct = (inproc_transport*)gpr_zalloc(sizeof(*ct)); + inproc_transport* st = static_cast(gpr_zalloc(sizeof(*st))); + inproc_transport* ct = static_cast(gpr_zalloc(sizeof(*ct))); // Share one lock between both sides since both sides get affected - st->mu = ct->mu = (shared_mu*)gpr_malloc(sizeof(*st->mu)); + st->mu = ct->mu = static_cast(gpr_malloc(sizeof(*st->mu))); gpr_mu_init(&st->mu->mu); gpr_ref_init(&st->mu->refs, 2); st->base.vtable = &inproc_vtable; @@ -1173,8 +1173,8 @@ static void inproc_transports_create(grpc_transport** server_transport, ct->other_side = st; st->stream_list = nullptr; ct->stream_list = nullptr; - *server_transport = (grpc_transport*)st; - *client_transport = (grpc_transport*)ct; + *server_transport = reinterpret_cast(st); + *client_transport = reinterpret_cast(ct); } grpc_channel* grpc_inproc_channel_create(grpc_server* server, diff --git a/src/core/lib/avl/avl.cc b/src/core/lib/avl/avl.cc index acc0432af7..c674d9be28 100644 --- a/src/core/lib/avl/avl.cc +++ b/src/core/lib/avl/avl.cc @@ -79,7 +79,7 @@ static grpc_avl_node* assert_invariants(grpc_avl_node* n) { return n; } grpc_avl_node* new_node(void* key, void* value, grpc_avl_node* left, grpc_avl_node* right) { - grpc_avl_node* node = (grpc_avl_node*)gpr_malloc(sizeof(*node)); + grpc_avl_node* node = static_cast(gpr_malloc(sizeof(*node))); gpr_ref_init(&node->refs, 1); node->key = key; node->value = value; diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc index 9275fc2894..81ea429a6a 100644 --- a/src/core/lib/backoff/backoff.cc +++ b/src/core/lib/backoff/backoff.cc @@ -56,12 +56,12 @@ grpc_millis BackOff::NextAttemptTime() { return current_backoff_ + grpc_core::ExecCtx::Get()->Now(); } current_backoff_ = - (grpc_millis)(std::min(current_backoff_ * options_.multiplier(), - (double)options_.max_backoff())); + static_cast(std::min(current_backoff_ * options_.multiplier(), + static_cast(options_.max_backoff()))); const double jitter = generate_uniform_random_number_between( &rng_state_, -options_.jitter() * current_backoff_, options_.jitter() * current_backoff_); - const grpc_millis next_timeout = (grpc_millis)(current_backoff_ + jitter); + const grpc_millis next_timeout = static_cast(current_backoff_ + jitter); return next_timeout + grpc_core::ExecCtx::Get()->Now(); } diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 5cd158aff2..8f448bfd91 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -87,13 +87,13 @@ grpc_channel_args* grpc_channel_args_copy_and_add_and_remove( } // Create result. grpc_channel_args* dst = - (grpc_channel_args*)gpr_malloc(sizeof(grpc_channel_args)); + static_cast(gpr_malloc(sizeof(grpc_channel_args))); dst->num_args = num_args_to_copy + num_to_add; if (dst->num_args == 0) { dst->args = nullptr; return dst; } - dst->args = (grpc_arg*)gpr_malloc(sizeof(grpc_arg) * dst->num_args); + dst->args = static_cast(gpr_malloc(sizeof(grpc_arg) * dst->num_args)); // Copy args from src that are not being removed. size_t dst_idx = 0; if (src != nullptr) { @@ -118,7 +118,7 @@ grpc_channel_args* grpc_channel_args_copy(const grpc_channel_args* src) { grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a, const grpc_channel_args* b) { const size_t max_out = (a->num_args + b->num_args); - grpc_arg* uniques = (grpc_arg*)gpr_malloc(sizeof(*uniques) * max_out); + grpc_arg* uniques = static_cast(gpr_malloc(sizeof(*uniques) * max_out)); for (size_t i = 0; i < a->num_args; ++i) uniques[i] = a->args[i]; size_t uniques_idx = a->num_args; @@ -161,15 +161,15 @@ static int cmp_arg(const grpc_arg* a, const grpc_arg* b) { /* stabilizing comparison function: since channel_args ordering matters for * keys with the same name, we need to preserve that ordering */ static int cmp_key_stable(const void* ap, const void* bp) { - const grpc_arg* const* a = (const grpc_arg* const*)ap; - const grpc_arg* const* b = (const grpc_arg* const*)bp; + const grpc_arg* const* a = static_cast(ap); + const grpc_arg* const* b = static_cast(bp); int c = strcmp((*a)->key, (*b)->key); if (c == 0) c = GPR_ICMP(*a, *b); return c; } grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) { - grpc_arg** args = (grpc_arg**)gpr_malloc(sizeof(grpc_arg*) * a->num_args); + grpc_arg** args = static_cast(gpr_malloc(sizeof(grpc_arg*) * a->num_args)); for (size_t i = 0; i < a->num_args; i++) { args[i] = &a->args[i]; } @@ -177,9 +177,9 @@ grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) { qsort(args, a->num_args, sizeof(grpc_arg*), cmp_key_stable); grpc_channel_args* b = - (grpc_channel_args*)gpr_malloc(sizeof(grpc_channel_args)); + static_cast(gpr_malloc(sizeof(grpc_channel_args))); b->num_args = a->num_args; - b->args = (grpc_arg*)gpr_malloc(sizeof(grpc_arg) * b->num_args); + b->args = static_cast(gpr_malloc(sizeof(grpc_arg) * b->num_args)); for (size_t i = 0; i < a->num_args; i++) { b->args[i] = copy_arg(args[i]); } @@ -215,7 +215,7 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && !strcmp(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, a->args[i].key)) { - return (grpc_compression_algorithm)a->args[i].value.integer; + return static_cast(a->args[i].value.integer); break; } } @@ -296,7 +296,7 @@ uint32_t grpc_channel_args_compression_algorithm_get_states( const grpc_channel_args* a) { int* states_arg; if (find_compression_algorithm_states_bitset(a, &states_arg)) { - return (uint32_t)*states_arg; + return static_cast(*states_arg); } else { return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */ } diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 195fe0b195..c311c73b85 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -104,7 +104,7 @@ grpc_error* grpc_channel_stack_init( GRPC_STREAM_REF_INIT(&stack->refcount, initial_refs, destroy, destroy_arg, name); elems = CHANNEL_ELEMS_FROM_STACK(stack); - user_data = ((char*)elems) + ROUND_UP_TO_ALIGNMENT_SIZE( + user_data = (reinterpret_cast(elems)) + ROUND_UP_TO_ALIGNMENT_SIZE( filter_count * sizeof(grpc_channel_element)); /* init per-filter data */ @@ -162,7 +162,7 @@ grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack, GRPC_STREAM_REF_INIT(&elem_args->call_stack->refcount, initial_refs, destroy, destroy_arg, "CALL_STACK"); call_elems = CALL_ELEMS_FROM_STACK(elem_args->call_stack); - user_data = ((char*)call_elems) + + user_data = (reinterpret_cast(call_elems)) + ROUND_UP_TO_ALIGNMENT_SIZE(count * sizeof(grpc_call_element)); /* init per-filter data */ @@ -194,7 +194,7 @@ void grpc_call_stack_set_pollset_or_pollset_set(grpc_call_stack* call_stack, size_t i; call_elems = CALL_ELEMS_FROM_STACK(call_stack); - user_data = ((char*)call_elems) + + user_data = (reinterpret_cast(call_elems)) + ROUND_UP_TO_ALIGNMENT_SIZE(count * sizeof(grpc_call_element)); /* init per-filter data */ @@ -243,11 +243,11 @@ void grpc_channel_next_op(grpc_channel_element* elem, grpc_transport_op* op) { grpc_channel_stack* grpc_channel_stack_from_top_element( grpc_channel_element* elem) { - return (grpc_channel_stack*)((char*)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( + return reinterpret_cast(reinterpret_cast(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( sizeof(grpc_channel_stack))); } grpc_call_stack* grpc_call_stack_from_top_element(grpc_call_element* elem) { - return (grpc_call_stack*)((char*)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( + return reinterpret_cast(reinterpret_cast(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( sizeof(grpc_call_stack))); } diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index fcba826644..c04f4c603a 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -52,7 +52,7 @@ struct grpc_channel_stack_builder_iterator { grpc_channel_stack_builder* grpc_channel_stack_builder_create(void) { grpc_channel_stack_builder* b = - (grpc_channel_stack_builder*)gpr_zalloc(sizeof(*b)); + static_cast(gpr_zalloc(sizeof(*b))); b->begin.filter = nullptr; b->end.filter = nullptr; @@ -78,7 +78,7 @@ const char* grpc_channel_stack_builder_get_target( static grpc_channel_stack_builder_iterator* create_iterator_at_filter_node( grpc_channel_stack_builder* builder, filter_node* node) { grpc_channel_stack_builder_iterator* it = - (grpc_channel_stack_builder_iterator*)gpr_malloc(sizeof(*it)); + static_cast(gpr_malloc(sizeof(*it))); it->builder = builder; it->node = node; return it; @@ -213,7 +213,7 @@ bool grpc_channel_stack_builder_prepend_filter( static void add_after(filter_node* before, const grpc_channel_filter* filter, grpc_post_filter_create_init_func post_init_func, void* user_data) { - filter_node* new_node = (filter_node*)gpr_malloc(sizeof(*new_node)); + filter_node* new_node = static_cast(gpr_malloc(sizeof(*new_node))); new_node->next = before->next; new_node->prev = before; new_node->next->prev = new_node->prev->next = new_node; @@ -265,7 +265,7 @@ grpc_error* grpc_channel_stack_builder_finish( // create an array of filters const grpc_channel_filter** filters = - (const grpc_channel_filter**)gpr_malloc(sizeof(*filters) * num_filters); + static_cast(gpr_malloc(sizeof(*filters) * num_filters)); size_t i = 0; for (filter_node* p = builder->begin.next; p != &builder->end; p = p->next) { filters[i++] = p->filter; @@ -278,7 +278,7 @@ grpc_error* grpc_channel_stack_builder_finish( *result = gpr_zalloc(prefix_bytes + channel_stack_size); // fetch a pointer to the channel stack grpc_channel_stack* channel_stack = - (grpc_channel_stack*)((char*)(*result) + prefix_bytes); + reinterpret_cast(static_cast(*result) + prefix_bytes); // and initialize it grpc_error* error = grpc_channel_stack_init( initial_refs, destroy, destroy_arg == nullptr ? *result : destroy_arg, @@ -303,7 +303,7 @@ grpc_error* grpc_channel_stack_builder_finish( } grpc_channel_stack_builder_destroy(builder); - gpr_free((grpc_channel_filter**)filters); + gpr_free(const_cast(filters)); return error; } diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index fb26bdf586..516d49e4d3 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -52,7 +52,7 @@ typedef struct connected_channel_call_data { } call_data; static void run_in_call_combiner(void* arg, grpc_error* error) { - callback_state* state = (callback_state*)arg; + callback_state* state = static_cast(arg); GRPC_CALL_COMBINER_START(state->call_combiner, state->original_closure, GRPC_ERROR_REF(error), state->reason); } @@ -96,8 +96,8 @@ static callback_state* get_state_for_batch( into transport stream operations */ static void con_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); if (batch->recv_initial_metadata) { callback_state* state = &calld->recv_initial_metadata_ready; intercept_callback( @@ -115,7 +115,7 @@ static void con_start_transport_stream_op_batch( // calld->on_complete like we can for the other ops. However, // cancellation isn't in the fast path, so we just allocate a new // closure for each one. - callback_state* state = (callback_state*)gpr_malloc(sizeof(*state)); + callback_state* state = static_cast(gpr_malloc(sizeof(*state))); intercept_callback(calld, state, true, "on_complete (cancel_stream)", &batch->on_complete); } else { @@ -129,15 +129,15 @@ static void con_start_transport_stream_op_batch( static void con_start_transport_op(grpc_channel_element* elem, grpc_transport_op* op) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); grpc_transport_perform_op(chand->transport, op); } /* Constructor for call_data */ static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); calld->call_combiner = args->call_combiner; int r = grpc_transport_init_stream( chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), @@ -149,8 +149,8 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void set_pollset_or_pollset_set(grpc_call_element* elem, grpc_polling_entity* pollent) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); grpc_transport_set_pops(chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), pollent); } @@ -159,8 +159,8 @@ static void set_pollset_or_pollset_set(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); grpc_transport_destroy_stream(chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), then_schedule_closure); @@ -169,7 +169,7 @@ static void destroy_call_elem(grpc_call_element* elem, /* Constructor for channel_data */ static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { - channel_data* cd = (channel_data*)elem->channel_data; + channel_data* cd = static_cast(elem->channel_data); GPR_ASSERT(args->is_last); cd->transport = nullptr; return GRPC_ERROR_NONE; @@ -177,7 +177,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, /* Destructor for channel_data */ static void destroy_channel_elem(grpc_channel_element* elem) { - channel_data* cd = (channel_data*)elem->channel_data; + channel_data* cd = static_cast(elem->channel_data); if (cd->transport) { grpc_transport_destroy(cd->transport); } @@ -203,10 +203,10 @@ const grpc_channel_filter grpc_connected_filter = { static void bind_transport(grpc_channel_stack* channel_stack, grpc_channel_element* elem, void* t) { - channel_data* cd = (channel_data*)elem->channel_data; + channel_data* cd = static_cast(elem->channel_data); GPR_ASSERT(elem->filter == &grpc_connected_filter); GPR_ASSERT(cd->transport == nullptr); - cd->transport = (grpc_transport*)t; + cd->transport = static_cast(t); /* HACK(ctiller): increase call stack size for the channel to make space for channel data. We need a cleaner (but performant) way to do this, @@ -215,7 +215,7 @@ static void bind_transport(grpc_channel_stack* channel_stack, the last call element, and the last call element MUST be the connected channel. */ channel_stack->call_stack_size += - grpc_transport_stream_size((grpc_transport*)t); + grpc_transport_stream_size(static_cast(t)); } bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, @@ -228,6 +228,6 @@ bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, } grpc_stream* grpc_connected_channel_get_stream(grpc_call_element* elem) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); return TRANSPORT_STREAM_FROM_CALL_DATA(calld); } diff --git a/src/core/lib/channel/handshaker.cc b/src/core/lib/channel/handshaker.cc index dcb149c03e..daacbdebd3 100644 --- a/src/core/lib/channel/handshaker.cc +++ b/src/core/lib/channel/handshaker.cc @@ -82,7 +82,7 @@ struct grpc_handshake_manager { grpc_handshake_manager* grpc_handshake_manager_create() { grpc_handshake_manager* mgr = - (grpc_handshake_manager*)gpr_zalloc(sizeof(grpc_handshake_manager)); + static_cast(gpr_zalloc(sizeof(grpc_handshake_manager))); gpr_mu_init(&mgr->mu); gpr_ref_init(&mgr->refs, 1); return mgr; @@ -135,8 +135,8 @@ void grpc_handshake_manager_add(grpc_handshake_manager* mgr, realloc_count = mgr->count * 2; } if (realloc_count > 0) { - mgr->handshakers = (grpc_handshaker**)gpr_realloc( - mgr->handshakers, realloc_count * sizeof(grpc_handshaker*)); + mgr->handshakers = static_cast(gpr_realloc( + mgr->handshakers, realloc_count * sizeof(grpc_handshaker*))); } mgr->handshakers[mgr->count++] = handshaker; gpr_mu_unlock(&mgr->mu); @@ -197,7 +197,7 @@ static bool call_next_handshaker_locked(grpc_handshake_manager* mgr, // A function used as the handshaker-done callback when chaining // handshakers together. static void call_next_handshaker(void* arg, grpc_error* error) { - grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg; + grpc_handshake_manager* mgr = static_cast(arg); gpr_mu_lock(&mgr->mu); bool done = call_next_handshaker_locked(mgr, GRPC_ERROR_REF(error)); gpr_mu_unlock(&mgr->mu); @@ -211,7 +211,7 @@ static void call_next_handshaker(void* arg, grpc_error* error) { // Callback invoked when deadline is exceeded. static void on_timeout(void* arg, grpc_error* error) { - grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg; + grpc_handshake_manager* mgr = static_cast(arg); if (error == GRPC_ERROR_NONE) { // Timer fired, rather than being cancelled. grpc_handshake_manager_shutdown( mgr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out")); @@ -234,7 +234,7 @@ void grpc_handshake_manager_do_handshake( mgr->args.args = grpc_channel_args_copy(channel_args); mgr->args.user_data = user_data; mgr->args.read_buffer = - (grpc_slice_buffer*)gpr_malloc(sizeof(*mgr->args.read_buffer)); + static_cast(gpr_malloc(sizeof(*mgr->args.read_buffer))); grpc_slice_buffer_init(mgr->args.read_buffer); // Initialize state needed for calling handshakers. mgr->acceptor = acceptor; diff --git a/src/core/lib/channel/handshaker_registry.cc b/src/core/lib/channel/handshaker_registry.cc index 098eabf084..f23f009275 100644 --- a/src/core/lib/channel/handshaker_registry.cc +++ b/src/core/lib/channel/handshaker_registry.cc @@ -34,8 +34,8 @@ typedef struct { static void grpc_handshaker_factory_list_register( grpc_handshaker_factory_list* list, bool at_start, grpc_handshaker_factory* factory) { - list->list = (grpc_handshaker_factory**)gpr_realloc( - list->list, (list->num_factories + 1) * sizeof(grpc_handshaker_factory*)); + list->list = static_cast(gpr_realloc( + list->list, (list->num_factories + 1) * sizeof(grpc_handshaker_factory*))); if (at_start) { memmove(list->list + 1, list->list, sizeof(grpc_handshaker_factory*) * list->num_factories); diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc index 4bbaca2f98..e49c67f784 100644 --- a/src/core/lib/compression/compression_internal.cc +++ b/src/core/lib/compression/compression_internal.cc @@ -190,7 +190,7 @@ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level( GRPC_API_TRACE("grpc_message_compression_algorithm_for_level(level=%d)", 1, ((int)level)); if (level > GRPC_COMPRESS_LEVEL_HIGH) { - gpr_log(GPR_ERROR, "Unknown message compression level %d.", (int)level); + gpr_log(GPR_ERROR, "Unknown message compression level %d.", static_cast(level)); abort(); } diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc index 1e9b0f10ee..238eff780c 100644 --- a/src/core/lib/compression/message_compress.cc +++ b/src/core/lib/compression/message_compress.cc @@ -36,23 +36,23 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input, int flush; size_t i; grpc_slice outbuf = GRPC_SLICE_MALLOC(OUTPUT_BLOCK_SIZE); - const uInt uint_max = ~(uInt)0; + const uInt uint_max = ~static_cast(0); GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max); - zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf); + zs->avail_out = static_castGRPC_SLICE_LENGTH(outbuf); zs->next_out = GRPC_SLICE_START_PTR(outbuf); flush = Z_NO_FLUSH; for (i = 0; i < input->count; i++) { if (i == input->count - 1) flush = Z_FINISH; GPR_ASSERT(GRPC_SLICE_LENGTH(input->slices[i]) <= uint_max); - zs->avail_in = (uInt)GRPC_SLICE_LENGTH(input->slices[i]); + zs->avail_in = static_castGRPC_SLICE_LENGTH(input->slices[i]); zs->next_in = GRPC_SLICE_START_PTR(input->slices[i]); do { if (zs->avail_out == 0) { grpc_slice_buffer_add_indexed(output, outbuf); outbuf = GRPC_SLICE_MALLOC(OUTPUT_BLOCK_SIZE); GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max); - zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf); + zs->avail_out = static_castGRPC_SLICE_LENGTH(outbuf); zs->next_out = GRPC_SLICE_START_PTR(outbuf); } r = flate(zs, flush); diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index 897f3918a7..c48fe9305d 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -48,11 +48,11 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, size_t slice_size = max_output_size < OUTPUT_BLOCK_SIZE ? max_output_size : OUTPUT_BLOCK_SIZE; grpc_slice slice_out = GRPC_SLICE_MALLOC(slice_size); - ctx->zs.avail_out = (uInt)slice_size; + ctx->zs.avail_out = static_cast(slice_size); ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out); while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) { grpc_slice slice = grpc_slice_buffer_take_first(in); - ctx->zs.avail_in = (uInt)GRPC_SLICE_LENGTH(slice); + ctx->zs.avail_in = static_castGRPC_SLICE_LENGTH(slice); ctx->zs.next_in = GRPC_SLICE_START_PTR(slice); r = ctx->flate(&ctx->zs, Z_NO_FLUSH); if (r < 0 && r != Z_BUF_ERROR) { @@ -142,7 +142,7 @@ static bool grpc_stream_compress_gzip(grpc_stream_compression_context* ctx, return false; } grpc_stream_compression_context_gzip* gzip_ctx = - (grpc_stream_compression_context_gzip*)ctx; + reinterpret_cast(ctx); GPR_ASSERT(gzip_ctx->flate == deflate); int gzip_flush; switch (flush) { @@ -172,7 +172,7 @@ static bool grpc_stream_decompress_gzip(grpc_stream_compression_context* ctx, return false; } grpc_stream_compression_context_gzip* gzip_ctx = - (grpc_stream_compression_context_gzip*)ctx; + reinterpret_cast(ctx); GPR_ASSERT(gzip_ctx->flate == inflate); return gzip_flate(gzip_ctx, in, out, output_size, max_output_size, Z_SYNC_FLUSH, end_of_context); @@ -184,8 +184,8 @@ grpc_stream_compression_context_create_gzip( GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_GZIP_COMPRESS || method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS); grpc_stream_compression_context_gzip* gzip_ctx = - (grpc_stream_compression_context_gzip*)gpr_zalloc( - sizeof(grpc_stream_compression_context_gzip)); + static_cast(gpr_zalloc( + sizeof(grpc_stream_compression_context_gzip))); int r; if (gzip_ctx == nullptr) { return nullptr; @@ -204,7 +204,7 @@ grpc_stream_compression_context_create_gzip( } gzip_ctx->base.vtable = &grpc_stream_compression_gzip_vtable; - return (grpc_stream_compression_context*)gzip_ctx; + return reinterpret_cast(gzip_ctx); } static void grpc_stream_compression_context_destroy_gzip( @@ -213,7 +213,7 @@ static void grpc_stream_compression_context_destroy_gzip( return; } grpc_stream_compression_context_gzip* gzip_ctx = - (grpc_stream_compression_context_gzip*)ctx; + reinterpret_cast(ctx); if (gzip_ctx->flate == inflate) { inflateEnd(&gzip_ctx->zs); } else { diff --git a/src/core/lib/compression/stream_compression_identity.cc b/src/core/lib/compression/stream_compression_identity.cc index af4051144c..933d24b3a1 100644 --- a/src/core/lib/compression/stream_compression_identity.cc +++ b/src/core/lib/compression/stream_compression_identity.cc @@ -79,7 +79,7 @@ grpc_stream_compression_context_create_identity( GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS || method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS); /* No context needed in this case. Use fake context instead. */ - return (grpc_stream_compression_context*)&identity_ctx; + return &identity_ctx; } static void grpc_stream_compression_context_destroy_identity( diff --git a/src/core/lib/debug/stats.cc b/src/core/lib/debug/stats.cc index 40355c2d45..f4de6a82a9 100644 --- a/src/core/lib/debug/stats.cc +++ b/src/core/lib/debug/stats.cc @@ -33,7 +33,7 @@ static size_t g_num_cores; void grpc_stats_init(void) { g_num_cores = GPR_MAX(1, gpr_cpu_num_cores()); grpc_stats_per_cpu_storage = - (grpc_stats_data*)gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores); + static_cast(gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores)); } void grpc_stats_shutdown(void) { gpr_free(grpc_stats_per_cpu_storage); } @@ -76,14 +76,14 @@ int grpc_stats_histo_find_bucket_slow(int value, const int* table, table_size = step; } } - return (int)(table - start) - 1; + return static_cast(table - start) - 1; } size_t grpc_stats_histo_count(const grpc_stats_data* stats, grpc_stats_histograms histogram) { size_t sum = 0; for (int i = 0; i < grpc_stats_histo_buckets[histogram]; i++) { - sum += (size_t)stats->histograms[grpc_stats_histo_start[histogram] + i]; + sum += static_cast(stats->histograms[grpc_stats_histo_start[histogram] + i]); } return sum; } @@ -100,7 +100,7 @@ static double threshold_for_count_below(const gpr_atm* bucket_counts, /* find the lowest bucket that gets us above count_below */ count_so_far = 0.0; for (lower_idx = 0; lower_idx < num_buckets; lower_idx++) { - count_so_far += (double)bucket_counts[lower_idx]; + count_so_far += static_cast(bucket_counts[lower_idx]); if (count_so_far >= count_below) { break; } @@ -121,7 +121,7 @@ static double threshold_for_count_below(const gpr_atm* bucket_counts, upper_bound = bucket_boundaries[lower_idx + 1]; return upper_bound - (upper_bound - lower_bound) * (count_so_far - count_below) / - (double)bucket_counts[lower_idx]; + static_cast(bucket_counts[lower_idx]); } } @@ -133,7 +133,7 @@ double grpc_stats_histo_percentile(const grpc_stats_data* stats, return threshold_for_count_below( stats->histograms + grpc_stats_histo_start[histogram], grpc_stats_histo_bucket_boundaries[histogram], - grpc_stats_histo_buckets[histogram], (double)count * percentile / 100.0); + grpc_stats_histo_buckets[histogram], static_cast(count) * percentile / 100.0); } char* grpc_stats_data_as_json(const grpc_stats_data* data) { diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index d870bbc5e7..c0cefd0639 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -88,11 +88,11 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) { char* s; size_t len; GPR_ASSERT(end >= beg); - len = (size_t)(end - beg); - s = (char*)gpr_malloc(len + 1); + len = static_cast(end - beg); + s = static_cast(gpr_malloc(len + 1)); memcpy(s, beg, len); s[len] = 0; - *ss = (char**)gpr_realloc(*ss, sizeof(char**) * np); + *ss = static_cast(gpr_realloc(*ss, sizeof(char**) * np)); (*ss)[n] = s; *ns = np; } diff --git a/src/core/lib/gpr/alloc.cc b/src/core/lib/gpr/alloc.cc index b1d1550630..e0d25963ed 100644 --- a/src/core/lib/gpr/alloc.cc +++ b/src/core/lib/gpr/alloc.cc @@ -95,4 +95,4 @@ void* gpr_malloc_aligned(size_t size, size_t alignment) { return (void*)ret; } -void gpr_free_aligned(void* ptr) { gpr_free(((void**)ptr)[-1]); } +void gpr_free_aligned(void* ptr) { gpr_free((static_cast(ptr))[-1]); } diff --git a/src/core/lib/gpr/arena.cc b/src/core/lib/gpr/arena.cc index 5a8d7ff6ec..a1eefa56bc 100644 --- a/src/core/lib/gpr/arena.cc +++ b/src/core/lib/gpr/arena.cc @@ -51,8 +51,8 @@ static void* zalloc_aligned(size_t size) { gpr_arena* gpr_arena_create(size_t initial_size) { initial_size = ROUND_UP_TO_ALIGNMENT_SIZE(initial_size); - gpr_arena* a = (gpr_arena*)zalloc_aligned( - ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + initial_size); + gpr_arena* a = static_cast(zalloc_aligned( + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + initial_size)); a->initial_zone.size_end = initial_size; return a; } @@ -66,23 +66,23 @@ size_t gpr_arena_destroy(gpr_arena* arena) { gpr_free_aligned(z); z = next_z; } - return (size_t)size; + return static_cast(size); } void* gpr_arena_alloc(gpr_arena* arena, size_t size) { size = ROUND_UP_TO_ALIGNMENT_SIZE(size); size_t start = - (size_t)gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size); + static_cast(gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size)); zone* z = &arena->initial_zone; while (start > z->size_end) { zone* next_z = (zone*)gpr_atm_acq_load(&z->next_atm); if (next_z == nullptr) { - size_t next_z_size = (size_t)gpr_atm_no_barrier_load(&arena->size_so_far); - next_z = (zone*)zalloc_aligned(ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) + - next_z_size); + size_t next_z_size = static_castgpr_atm_no_barrier_load(&arena->size_so_far); + next_z = static_cast(zalloc_aligned(ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) + + next_z_size)); next_z->size_begin = z->size_end; next_z->size_end = z->size_end + next_z_size; - if (!gpr_atm_rel_cas(&z->next_atm, (gpr_atm)NULL, (gpr_atm)next_z)) { + if (!gpr_atm_rel_cas(&z->next_atm, static_cast(NULL), (gpr_atm)next_z)) { gpr_free_aligned(next_z); next_z = (zone*)gpr_atm_acq_load(&z->next_atm); } @@ -95,7 +95,7 @@ void* gpr_arena_alloc(gpr_arena* arena, size_t size) { GPR_ASSERT(start >= z->size_begin); GPR_ASSERT(start + size <= z->size_end); char* ptr = (z == &arena->initial_zone) - ? (char*)arena + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) - : (char*)z + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)); + ? reinterpret_cast(arena) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + : reinterpret_cast(z) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)); return ptr + start - z->size_begin; } diff --git a/src/core/lib/gpr/cpu_linux.cc b/src/core/lib/gpr/cpu_linux.cc index 21b1a71dc9..4782f9f742 100644 --- a/src/core/lib/gpr/cpu_linux.cc +++ b/src/core/lib/gpr/cpu_linux.cc @@ -45,7 +45,7 @@ static void init_num_cpus() { #endif /* This must be signed. sysconf returns -1 when the number cannot be determined */ - ncpus = (int)sysconf(_SC_NPROCESSORS_ONLN); + ncpus = static_cast(sysconf(_SC_NPROCESSORS_ONLN)); if (ncpus < 1) { gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1"); ncpus = 1; @@ -55,7 +55,7 @@ static void init_num_cpus() { unsigned gpr_cpu_num_cores(void) { static gpr_once once = GPR_ONCE_INIT; gpr_once_init(&once, init_num_cpus); - return (unsigned)ncpus; + return static_cast(ncpus); } unsigned gpr_cpu_current_cpu(void) { @@ -71,7 +71,7 @@ unsigned gpr_cpu_current_cpu(void) { gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno)); return 0; } - return (unsigned)cpu; + return static_cast(cpu); #endif } diff --git a/src/core/lib/gpr/host_port.cc b/src/core/lib/gpr/host_port.cc index 0776727906..5a03a16296 100644 --- a/src/core/lib/gpr/host_port.cc +++ b/src/core/lib/gpr/host_port.cc @@ -62,7 +62,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { return 0; } host_start = name + 1; - host_len = (size_t)(rbracket - host_start); + host_len = static_cast(rbracket - host_start); if (memchr(host_start, ':', host_len) == nullptr) { /* Require all bracketed hosts to contain a colon, because a hostname or IPv4 address should never use brackets. */ @@ -73,7 +73,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { if (colon != nullptr && strchr(colon + 1, ':') == nullptr) { /* Exactly 1 colon. Split into host:port. */ host_start = name; - host_len = (size_t)(colon - name); + host_len = static_cast(colon - name); port_start = colon + 1; } else { /* 0 or 2+ colons. Bare hostname or IPv6 litearal. */ @@ -84,7 +84,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { } /* Allocate return values. */ - *host = (char*)gpr_malloc(host_len + 1); + *host = static_cast(gpr_malloc(host_len + 1)); memcpy(*host, host_start, host_len); (*host)[host_len] = '\0'; diff --git a/src/core/lib/gpr/log.cc b/src/core/lib/gpr/log.cc index 19c0f6c34d..9211a00a69 100644 --- a/src/core/lib/gpr/log.cc +++ b/src/core/lib/gpr/log.cc @@ -45,7 +45,7 @@ const char* gpr_log_severity_string(gpr_log_severity severity) { void gpr_log_message(const char* file, int line, gpr_log_severity severity, const char* message) { - if ((gpr_atm)severity < gpr_atm_no_barrier_load(&g_min_severity_to_print)) { + if (static_cast(severity) < gpr_atm_no_barrier_load(&g_min_severity_to_print)) { return; } @@ -70,11 +70,11 @@ void gpr_log_verbosity_init() { gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR; if (verbosity != nullptr) { if (gpr_stricmp(verbosity, "DEBUG") == 0) { - min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_DEBUG; + min_severity_to_print = static_cast(GPR_LOG_SEVERITY_DEBUG); } else if (gpr_stricmp(verbosity, "INFO") == 0) { - min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_INFO; + min_severity_to_print = static_cast(GPR_LOG_SEVERITY_INFO); } else if (gpr_stricmp(verbosity, "ERROR") == 0) { - min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_ERROR; + min_severity_to_print = static_cast(GPR_LOG_SEVERITY_ERROR); } gpr_free(verbosity); } diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc index 6b1f1c71e4..d743eedf38 100644 --- a/src/core/lib/gpr/log_linux.cc +++ b/src/core/lib/gpr/log_linux.cc @@ -67,7 +67,7 @@ void gpr_default_log(gpr_log_func_args* args) { static __thread long tid = 0; if (tid == 0) tid = gettid(); - timer = (time_t)now.tv_sec; + timer = static_cast(now.tv_sec); final_slash = strrchr(args->file, '/'); if (final_slash == nullptr) display_file = args->file; diff --git a/src/core/lib/gpr/murmur_hash.cc b/src/core/lib/gpr/murmur_hash.cc index 3f5e04d211..01a7290c67 100644 --- a/src/core/lib/gpr/murmur_hash.cc +++ b/src/core/lib/gpr/murmur_hash.cc @@ -36,7 +36,7 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { const uint32_t c1 = 0xcc9e2d51; const uint32_t c2 = 0x1b873593; - const uint8_t* keyptr = (const uint8_t*)key; + const uint8_t* keyptr = static_cast(key); const size_t bsize = sizeof(k1); const size_t nblocks = len / bsize; @@ -58,10 +58,10 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { /* tail */ switch (len & 3) { case 3: - k1 ^= ((uint32_t)keyptr[2]) << 16; + k1 ^= (static_cast(keyptr[2])) << 16; /* fallthrough */ case 2: - k1 ^= ((uint32_t)keyptr[1]) << 8; + k1 ^= (static_cast(keyptr[1])) << 8; /* fallthrough */ case 1: k1 ^= keyptr[0]; @@ -72,7 +72,7 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { }; /* finalization */ - h1 ^= (uint32_t)len; + h1 ^= static_cast(len); FMIX32(h1); return h1; } diff --git a/src/core/lib/gpr/string.cc b/src/core/lib/gpr/string.cc index 6b360e4013..9c07f43cae 100644 --- a/src/core/lib/gpr/string.cc +++ b/src/core/lib/gpr/string.cc @@ -40,7 +40,7 @@ char* gpr_strdup(const char* src) { } len = strlen(src) + 1; - dst = (char*)gpr_malloc(len); + dst = static_cast(gpr_malloc(len)); memcpy(dst, src, len); @@ -61,7 +61,7 @@ static dump_out dump_out_create(void) { static void dump_out_append(dump_out* out, char c) { if (out->length == out->capacity) { out->capacity = GPR_MAX(8, 2 * out->capacity); - out->data = (char*)gpr_realloc(out->data, out->capacity); + out->data = static_cast(gpr_realloc(out->data, out->capacity)); } out->data[out->length++] = c; } @@ -69,7 +69,7 @@ static void dump_out_append(dump_out* out, char c) { static void hexdump(dump_out* out, const char* buf, size_t len) { static const char* hex = "0123456789abcdef"; - const uint8_t* const beg = (const uint8_t*)buf; + const uint8_t* const beg = reinterpret_cast(buf); const uint8_t* const end = beg + len; const uint8_t* cur; @@ -81,7 +81,7 @@ static void hexdump(dump_out* out, const char* buf, size_t len) { } static void asciidump(dump_out* out, const char* buf, size_t len) { - const uint8_t* const beg = (const uint8_t*)buf; + const uint8_t* const beg = reinterpret_cast(buf); const uint8_t* const end = beg + len; const uint8_t* cur; int out_was_empty = (out->length == 0); @@ -90,7 +90,7 @@ static void asciidump(dump_out* out, const char* buf, size_t len) { dump_out_append(out, '\''); } for (cur = beg; cur != end; ++cur) { - dump_out_append(out, (char)(isprint(*cur) ? *(char*)cur : '.')); + dump_out_append(out, (isprint(*cur) ? *(char*)cur : '.')); } if (!out_was_empty) { dump_out_append(out, '\''); @@ -118,7 +118,7 @@ int gpr_parse_bytes_to_uint32(const char* buf, size_t len, uint32_t* result) { for (i = 0; i < len; i++) { if (buf[i] < '0' || buf[i] > '9') return 0; /* bad char */ - new_val = 10 * out + (uint32_t)(buf[i] - '0'); + new_val = 10 * out + static_cast(buf[i] - '0'); if (new_val < out) return 0; /* overflow */ out = new_val; } @@ -148,7 +148,7 @@ int gpr_ltoa(long value, char* string) { sign = value < 0 ? -1 : 1; while (value) { - string[i++] = (char)('0' + sign * (value % 10)); + string[i++] = static_cast('0' + sign * (value % 10)); value /= 10; } if (sign < 0) string[i++] = '-'; @@ -169,7 +169,7 @@ int int64_ttoa(int64_t value, char* string) { sign = value < 0 ? -1 : 1; while (value) { - string[i++] = (char)('0' + sign * (value % 10)); + string[i++] = static_cast('0' + sign * (value % 10)); value /= 10; } if (sign < 0) string[i++] = '-'; @@ -182,13 +182,13 @@ int gpr_parse_nonnegative_int(const char* value) { char* end; long result = strtol(value, &end, 0); if (*end != '\0' || result < 0 || result > INT_MAX) return -1; - return (int)result; + return static_cast(result); } char* gpr_leftpad(const char* str, char flag, size_t length) { const size_t str_length = strlen(str); const size_t out_length = str_length > length ? str_length : length; - char* out = (char*)gpr_malloc(out_length + 1); + char* out = static_cast(gpr_malloc(out_length + 1)); memset(out, flag, out_length - str_length); memcpy(out + out_length - str_length, str, str_length); out[out_length] = 0; @@ -212,7 +212,7 @@ char* gpr_strjoin_sep(const char** strs, size_t nstrs, const char* sep, if (nstrs > 0) { out_length += sep_len * (nstrs - 1); /* separators */ } - out = (char*)gpr_malloc(out_length); + out = static_cast(gpr_malloc(out_length)); out_length = 0; for (i = 0; i < nstrs; i++) { const size_t slen = strlen(strs[i]); @@ -243,7 +243,7 @@ void gpr_strvec_destroy(gpr_strvec* sv) { void gpr_strvec_add(gpr_strvec* sv, char* str) { if (sv->count == sv->capacity) { sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2); - sv->strs = (char**)gpr_realloc(sv->strs, sizeof(char*) * sv->capacity); + sv->strs = static_cast(gpr_realloc(sv->strs, sizeof(char*) * sv->capacity)); } sv->strs[sv->count++] = str; } @@ -265,12 +265,12 @@ int gpr_stricmp(const char* a, const char* b) { static void add_string_to_split(const char* beg, const char* end, char*** strs, size_t* nstrs, size_t* capstrs) { - char* out = (char*)gpr_malloc((size_t)(end - beg) + 1); - memcpy(out, beg, (size_t)(end - beg)); + char* out = static_cast(gpr_malloc(static_cast(end - beg) + 1)); + memcpy(out, beg, static_cast(end - beg)); out[end - beg] = 0; if (*nstrs == *capstrs) { *capstrs = GPR_MAX(8, 2 * *capstrs); - *strs = (char**)gpr_realloc(*strs, sizeof(*strs) * *capstrs); + *strs = static_cast(gpr_realloc(*strs, sizeof(*strs) * *capstrs)); } (*strs)[*nstrs] = out; ++*nstrs; diff --git a/src/core/lib/gpr/string_posix.cc b/src/core/lib/gpr/string_posix.cc index 8b818e39b9..d32775fb3b 100644 --- a/src/core/lib/gpr/string_posix.cc +++ b/src/core/lib/gpr/string_posix.cc @@ -43,8 +43,8 @@ int gpr_asprintf(char** strp, const char* format, ...) { } /* Allocate a new buffer, with space for the NUL terminator. */ - strp_buflen = (size_t)ret + 1; - if ((*strp = (char*)gpr_malloc(strp_buflen)) == nullptr) { + strp_buflen = static_cast(ret) + 1; + if ((*strp = static_cast(gpr_malloc(strp_buflen))) == nullptr) { /* This shouldn't happen, because gpr_malloc() calls abort(). */ return -1; } @@ -59,7 +59,7 @@ int gpr_asprintf(char** strp, const char* format, ...) { va_start(args, format); ret = vsnprintf(*strp, strp_buflen, format, args); va_end(args); - if ((size_t)ret == strp_buflen - 1) { + if (static_cast(ret) == strp_buflen - 1) { return ret; } diff --git a/src/core/lib/gpr/sync_posix.cc b/src/core/lib/gpr/sync_posix.cc index f23a8b2486..848d23730c 100644 --- a/src/core/lib/gpr/sync_posix.cc +++ b/src/core/lib/gpr/sync_posix.cc @@ -84,7 +84,7 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) { #else abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME); #endif // GPR_LINUX - abs_deadline_ts.tv_sec = (time_t)abs_deadline.tv_sec; + abs_deadline_ts.tv_sec = static_cast(abs_deadline.tv_sec); abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); } diff --git a/src/core/lib/gpr/thd_posix.cc b/src/core/lib/gpr/thd_posix.cc index 683fd4575e..e8e61ca396 100644 --- a/src/core/lib/gpr/thd_posix.cc +++ b/src/core/lib/gpr/thd_posix.cc @@ -49,7 +49,7 @@ static void dec_thd_count(); /* Body of every thread started via gpr_thd_new. */ static void* thread_body(void* v) { - struct thd_arg a = *(struct thd_arg*)v; + struct thd_arg a = *static_cast(v); free(v); if (a.name != nullptr) { #if GPR_APPLE_PTHREAD_NAME @@ -77,7 +77,7 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name, pthread_t p; /* don't use gpr_malloc as we may cause an infinite recursion with * the profiling code */ - struct thd_arg* a = (struct thd_arg*)malloc(sizeof(*a)); + struct thd_arg* a = static_cast(malloc(sizeof(*a))); GPR_ASSERT(a != nullptr); a->body = thd_body; a->arg = arg; @@ -99,13 +99,13 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name, free(a); dec_thd_count(); } - *t = (gpr_thd_id)p; + *t = static_cast(p); return thread_started; } -gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)pthread_self(); } +gpr_thd_id gpr_thd_currentid(void) { return static_cast(pthread_self()); } -void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, nullptr); } +void gpr_thd_join(gpr_thd_id t) { pthread_join(static_cast(t), nullptr); } /***************************************** * Only used when fork support is enabled diff --git a/src/core/lib/gpr/time.cc b/src/core/lib/gpr/time.cc index 6903674d75..9ebfaa7525 100644 --- a/src/core/lib/gpr/time.cc +++ b/src/core/lib/gpr/time.cc @@ -81,7 +81,7 @@ static gpr_timespec to_seconds_from_sub_second_time(int64_t time_in_units, units_per_sec) - 1; } - out.tv_nsec = (int32_t)((time_in_units - out.tv_sec * units_per_sec) * + out.tv_nsec = static_cast((time_in_units - out.tv_sec * units_per_sec) * GPR_NS_PER_SEC / units_per_sec); out.clock_type = type; } @@ -216,12 +216,12 @@ int32_t gpr_time_to_millis(gpr_timespec t) { care?) */ return -2147483647; } else { - return (int32_t)(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS); + return static_cast(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS); } } double gpr_timespec_to_micros(gpr_timespec t) { - return (double)t.tv_sec * GPR_US_PER_SEC + t.tv_nsec * 1e-3; + return static_cast(t.tv_sec) * GPR_US_PER_SEC + t.tv_nsec * 1e-3; } gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type) { diff --git a/src/core/lib/gpr/time_posix.cc b/src/core/lib/gpr/time_posix.cc index 9c7e86b080..09171c9c48 100644 --- a/src/core/lib/gpr/time_posix.cc +++ b/src/core/lib/gpr/time_posix.cc @@ -37,7 +37,7 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) { /* fine to assert, as this is only used in gpr_sleep_until */ GPR_ASSERT(gts.tv_sec <= INT32_MAX && gts.tv_sec >= INT32_MIN); } - rv.tv_sec = (time_t)gts.tv_sec; + rv.tv_sec = static_cast(gts.tv_sec); rv.tv_nsec = gts.tv_nsec; return rv; } @@ -52,7 +52,7 @@ static gpr_timespec gpr_from_timespec(struct timespec ts, */ gpr_timespec rv; rv.tv_sec = ts.tv_sec; - rv.tv_nsec = (int32_t)ts.tv_nsec; + rv.tv_nsec = static_cast(ts.tv_nsec); rv.clock_type = clock_type; return rv; } diff --git a/src/core/lib/http/format_request.cc b/src/core/lib/http/format_request.cc index 884a70e550..ff273ffc1a 100644 --- a/src/core/lib/http/format_request.cc +++ b/src/core/lib/http/format_request.cc @@ -89,7 +89,7 @@ grpc_slice grpc_httpcli_format_post_request(const grpc_httpcli_request* request, if (!has_content_type) { gpr_strvec_add(&out, gpr_strdup("Content-Type: text/plain\r\n")); } - gpr_asprintf(&tmp, "Content-Length: %lu\r\n", (unsigned long)body_size); + gpr_asprintf(&tmp, "Content-Length: %lu\r\n", static_cast(body_size)); gpr_strvec_add(&out, tmp); } gpr_strvec_add(&out, gpr_strdup("\r\n")); @@ -97,7 +97,7 @@ grpc_slice grpc_httpcli_format_post_request(const grpc_httpcli_request* request, gpr_strvec_destroy(&out); if (body_bytes) { - tmp = (char*)gpr_realloc(tmp, out_len + body_size); + tmp = static_cast(gpr_realloc(tmp, out_len + body_size)); memcpy(tmp + out_len, body_bytes, body_size); out_len += body_size; } diff --git a/src/core/lib/http/httpcli.cc b/src/core/lib/http/httpcli.cc index 9775ed08ad..2cdca48487 100644 --- a/src/core/lib/http/httpcli.cc +++ b/src/core/lib/http/httpcli.cc @@ -123,7 +123,7 @@ static void do_read(internal_request* req) { } static void on_read(void* user_data, grpc_error* error) { - internal_request* req = (internal_request*)user_data; + internal_request* req = static_cast(user_data); size_t i; for (i = 0; i < req->incoming.count; i++) { @@ -150,7 +150,7 @@ static void on_read(void* user_data, grpc_error* error) { static void on_written(internal_request* req) { do_read(req); } static void done_write(void* arg, grpc_error* error) { - internal_request* req = (internal_request*)arg; + internal_request* req = static_cast(arg); if (error == GRPC_ERROR_NONE) { on_written(req); } else { @@ -165,7 +165,7 @@ static void start_write(internal_request* req) { } static void on_handshake_done(void* arg, grpc_endpoint* ep) { - internal_request* req = (internal_request*)arg; + internal_request* req = static_cast(arg); if (!ep) { next_address(req, GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -178,7 +178,7 @@ static void on_handshake_done(void* arg, grpc_endpoint* ep) { } static void on_connected(void* arg, grpc_error* error) { - internal_request* req = (internal_request*)arg; + internal_request* req = static_cast(arg); if (!req->ep) { next_address(req, GRPC_ERROR_REF(error)); @@ -212,7 +212,7 @@ static void next_address(internal_request* req, grpc_error* error) { } static void on_resolved(void* arg, grpc_error* error) { - internal_request* req = (internal_request*)arg; + internal_request* req = static_cast(arg); if (error != GRPC_ERROR_NONE) { finish(req, GRPC_ERROR_REF(error)); return; @@ -229,7 +229,7 @@ static void internal_request_begin(grpc_httpcli_context* context, grpc_httpcli_response* response, const char* name, grpc_slice request_text) { internal_request* req = - (internal_request*)gpr_malloc(sizeof(internal_request)); + static_cast(gpr_malloc(sizeof(internal_request))); memset(req, 0, sizeof(*req)); req->request_text = request_text; grpc_http_parser_init(&req->parser, GRPC_HTTP_RESPONSE, response); diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index 8664418144..ab684f6093 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -40,7 +40,7 @@ typedef struct { static void httpcli_ssl_destroy(grpc_security_connector* sc) { grpc_httpcli_ssl_channel_security_connector* c = - (grpc_httpcli_ssl_channel_security_connector*)sc; + reinterpret_cast(sc); if (c->handshaker_factory != nullptr) { tsi_ssl_client_handshaker_factory_unref(c->handshaker_factory); c->handshaker_factory = nullptr; @@ -52,7 +52,7 @@ static void httpcli_ssl_destroy(grpc_security_connector* sc) { static void httpcli_ssl_add_handshakers(grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_httpcli_ssl_channel_security_connector* c = - (grpc_httpcli_ssl_channel_security_connector*)sc; + reinterpret_cast(sc); tsi_handshaker* handshaker = nullptr; if (c->handshaker_factory != nullptr) { tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker( @@ -71,7 +71,7 @@ static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_httpcli_ssl_channel_security_connector* c = - (grpc_httpcli_ssl_channel_security_connector*)sc; + reinterpret_cast(sc); grpc_error* error = GRPC_ERROR_NONE; /* Check the peer name. */ @@ -90,9 +90,9 @@ static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer, static int httpcli_ssl_cmp(grpc_security_connector* sc1, grpc_security_connector* sc2) { grpc_httpcli_ssl_channel_security_connector* c1 = - (grpc_httpcli_ssl_channel_security_connector*)sc1; + reinterpret_cast(sc1); grpc_httpcli_ssl_channel_security_connector* c2 = - (grpc_httpcli_ssl_channel_security_connector*)sc2; + reinterpret_cast(sc2); return strcmp(c1->secure_peer_name, c2->secure_peer_name); } @@ -111,8 +111,8 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( return GRPC_SECURITY_ERROR; } - c = (grpc_httpcli_ssl_channel_security_connector*)gpr_zalloc( - sizeof(grpc_httpcli_ssl_channel_security_connector)); + c = static_cast(gpr_zalloc( + sizeof(grpc_httpcli_ssl_channel_security_connector))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.vtable = &httpcli_ssl_vtable; @@ -146,8 +146,8 @@ typedef struct { } on_done_closure; static void on_handshake_done(void* arg, grpc_error* error) { - grpc_handshaker_args* args = (grpc_handshaker_args*)arg; - on_done_closure* c = (on_done_closure*)args->user_data; + grpc_handshaker_args* args = static_cast(arg); + on_done_closure* c = static_cast(args->user_data); if (error != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(error); gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg); @@ -166,7 +166,7 @@ static void on_handshake_done(void* arg, grpc_error* error) { static void ssl_handshake(void* arg, grpc_endpoint* tcp, const char* host, grpc_millis deadline, void (*on_done)(void* arg, grpc_endpoint* endpoint)) { - on_done_closure* c = (on_done_closure*)gpr_malloc(sizeof(*c)); + on_done_closure* c = static_cast(gpr_malloc(sizeof(*c))); const char* pem_root_certs = grpc_get_default_ssl_roots(); if (pem_root_certs == nullptr) { gpr_log(GPR_ERROR, "Could not get default pem root certs."); diff --git a/src/core/lib/http/parser.cc b/src/core/lib/http/parser.cc index ee6941fde3..74689a6671 100644 --- a/src/core/lib/http/parser.cc +++ b/src/core/lib/http/parser.cc @@ -29,7 +29,7 @@ grpc_core::TraceFlag grpc_http1_trace(false, "http1"); static char* buf2str(void* buffer, size_t length) { - char* out = (char*)gpr_malloc(length + 1); + char* out = static_cast(gpr_malloc(length + 1)); memcpy(out, buffer, length); out[length] = 0; return out; @@ -88,14 +88,14 @@ static grpc_error* handle_request_line(grpc_http_parser* parser) { if (cur == end) return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "No method on HTTP request line"); - parser->http.request->method = buf2str(beg, (size_t)(cur - beg - 1)); + parser->http.request->method = buf2str(beg, static_cast(cur - beg - 1)); beg = cur; while (cur != end && *cur++ != ' ') ; if (cur == end) return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No path on HTTP request line"); - parser->http.request->path = buf2str(beg, (size_t)(cur - beg - 1)); + parser->http.request->path = buf2str(beg, static_cast(cur - beg - 1)); if (cur == end || *cur++ != 'H') return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'H'"); @@ -107,12 +107,12 @@ static grpc_error* handle_request_line(grpc_http_parser* parser) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'P'"); if (cur == end || *cur++ != '/') return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected '/'"); - vers_major = (uint8_t)(*cur++ - '1' + 1); + vers_major = static_cast(*cur++ - '1' + 1); ++cur; if (cur == end) return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "End of line in HTTP version string"); - vers_minor = (uint8_t)(*cur++ - '1' + 1); + vers_minor = static_cast(*cur++ - '1' + 1); if (vers_major == 1) { if (vers_minor == 0) { @@ -175,14 +175,14 @@ static grpc_error* add_header(grpc_http_parser* parser) { goto done; } GPR_ASSERT(cur >= beg); - hdr.key = buf2str(beg, (size_t)(cur - beg)); + hdr.key = buf2str(beg, static_cast(cur - beg)); cur++; /* skip : */ while (cur != end && (*cur == ' ' || *cur == '\t')) { cur++; } GPR_ASSERT((size_t)(end - cur) >= parser->cur_line_end_length); - hdr.value = buf2str(cur, (size_t)(end - cur) - parser->cur_line_end_length); + hdr.value = buf2str(cur, static_cast(end - cur) - parser->cur_line_end_length); switch (parser->type) { case GRPC_HTTP_RESPONSE: @@ -198,8 +198,8 @@ static grpc_error* add_header(grpc_http_parser* parser) { if (*hdr_count == parser->hdr_capacity) { parser->hdr_capacity = GPR_MAX(parser->hdr_capacity + 1, parser->hdr_capacity * 3 / 2); - *hdrs = (grpc_http_header*)gpr_realloc( - *hdrs, parser->hdr_capacity * sizeof(**hdrs)); + *hdrs = static_cast(gpr_realloc( + *hdrs, parser->hdr_capacity * sizeof(**hdrs))); } (*hdrs)[(*hdr_count)++] = hdr; @@ -257,9 +257,9 @@ static grpc_error* addbyte_body(grpc_http_parser* parser, uint8_t byte) { if (*body_length == parser->body_capacity) { parser->body_capacity = GPR_MAX(8, parser->body_capacity * 3 / 2); - *body = (char*)gpr_realloc((void*)*body, parser->body_capacity); + *body = static_cast(gpr_realloc((void*)*body, parser->body_capacity)); } - (*body)[*body_length] = (char)byte; + (*body)[*body_length] = static_cast(byte); (*body_length)++; return GRPC_ERROR_NONE; diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index 0e4c9cb3b3..f180594545 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -28,13 +28,13 @@ grpc_core::TraceFlag grpc_call_combiner_trace(false, "call_combiner"); static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) { if (cancel_state & 1) { - return (grpc_error*)(cancel_state & ~(gpr_atm)1); + return (grpc_error*)(cancel_state & ~static_cast(1)); } return GRPC_ERROR_NONE; } static gpr_atm encode_cancel_state_error(grpc_error* error) { - return (gpr_atm)1 | (gpr_atm)error; + return static_cast(1) | (gpr_atm)error; } void grpc_call_combiner_init(grpc_call_combiner* call_combiner) { @@ -69,7 +69,7 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner, grpc_error_string(error)); } size_t prev_size = - (size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1); + static_cast(gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1)); if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, prev_size + 1); @@ -90,7 +90,7 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner, } // Queue was not empty, so add closure to queue. closure->error_data.error = error; - gpr_mpscq_push(&call_combiner->queue, (gpr_mpscq_node*)closure); + gpr_mpscq_push(&call_combiner->queue, reinterpret_cast(closure)); } } @@ -103,7 +103,7 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, call_combiner DEBUG_FMT_ARGS, reason); } size_t prev_size = - (size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1); + static_cast(gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1)); if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, prev_size - 1); @@ -115,8 +115,8 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, gpr_log(GPR_DEBUG, " checking queue"); } bool empty; - grpc_closure* closure = (grpc_closure*)gpr_mpscq_pop_and_check_end( - &call_combiner->queue, &empty); + grpc_closure* closure = reinterpret_cast(gpr_mpscq_pop_and_check_end( + &call_combiner->queue, &empty)); if (closure == nullptr) { // This can happen either due to a race condition within the mpscq // code or because of a race with grpc_call_combiner_start(). diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index 2bf2578c63..64527d6bb1 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -143,7 +143,7 @@ typedef struct { } wrapped_closure; inline void closure_wrapper(void* arg, grpc_error* error) { - wrapped_closure* wc = (wrapped_closure*)arg; + wrapped_closure* wc = static_cast(arg); grpc_iomgr_cb_func cb = wc->cb; void* cb_arg = wc->cb_arg; gpr_free(wc); @@ -161,7 +161,7 @@ inline grpc_closure* grpc_closure_create(grpc_iomgr_cb_func cb, void* cb_arg, grpc_closure_scheduler* scheduler) { #endif closure_impl::wrapped_closure* wc = - (closure_impl::wrapped_closure*)gpr_malloc(sizeof(*wc)); + static_cast(gpr_malloc(sizeof(*wc))); wc->cb = cb; wc->cb_arg = cb_arg; #ifndef NDEBUG diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 2965d807c1..6ff6fccf03 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -72,7 +72,7 @@ static const grpc_closure_scheduler_vtable finally_scheduler = { static void offload(void* arg, grpc_error* error); grpc_combiner* grpc_combiner_create(void) { - grpc_combiner* lock = (grpc_combiner*)gpr_zalloc(sizeof(*lock)); + grpc_combiner* lock = static_cast(gpr_zalloc(sizeof(*lock))); gpr_ref_init(&lock->refs, 1); lock->scheduler.vtable = &scheduler; lock->finally_scheduler.vtable = &finally_scheduler; @@ -194,7 +194,7 @@ static void move_next() { } static void offload(void* arg, grpc_error* error) { - grpc_combiner* lock = (grpc_combiner*)arg; + grpc_combiner* lock = static_cast(arg); push_last_on_exec_ctx(lock); } @@ -249,7 +249,7 @@ bool grpc_combiner_continue_exec_ctx() { return true; } GPR_TIMER_SCOPE("combiner.exec1", 0); - grpc_closure* cl = (grpc_closure*)n; + grpc_closure* cl = reinterpret_cast(n); grpc_error* cl_err = cl->error_data.error; #ifndef NDEBUG cl->scheduled = false; @@ -342,7 +342,7 @@ static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) { } static void enqueue_finally(void* closure, grpc_error* error) { - combiner_finally_exec((grpc_closure*)closure, GRPC_ERROR_REF(error)); + combiner_finally_exec(static_cast(closure), GRPC_ERROR_REF(error)); } grpc_closure_scheduler* grpc_combiner_scheduler(grpc_combiner* combiner) { diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index d5b5013269..0ba0617f75 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -148,7 +148,7 @@ grpc_error* grpc_error_ref(grpc_error* err) { static void unref_errs(grpc_error* err) { uint8_t slot = err->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = (grpc_linked_error*)(err->arena + slot); + grpc_linked_error* lerr = reinterpret_cast(err->arena + slot); GRPC_ERROR_UNREF(lerr->err); GPR_ASSERT(err->last_err == slot ? lerr->next == UINT8_MAX : lerr->next != UINT8_MAX); @@ -162,7 +162,7 @@ static void unref_strs(grpc_error* err) { for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) { uint8_t slot = err->strs[which]; if (slot != UINT8_MAX) { - unref_slice(*(grpc_slice*)(err->arena + slot)); + unref_slice(*reinterpret_cast(err->arena + slot)); } } } @@ -198,18 +198,18 @@ void grpc_error_unref(grpc_error* err) { static uint8_t get_placement(grpc_error** err, size_t size) { GPR_ASSERT(*err); - uint8_t slots = (uint8_t)(size / sizeof(intptr_t)); + uint8_t slots = static_cast(size / sizeof(intptr_t)); if ((*err)->arena_size + slots > (*err)->arena_capacity) { (*err)->arena_capacity = - (uint8_t)GPR_MIN(UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2)); + static_castGPR_MIN(UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2)); if ((*err)->arena_size + slots > (*err)->arena_capacity) { return UINT8_MAX; } #ifndef NDEBUG grpc_error* orig = *err; #endif - *err = (grpc_error*)gpr_realloc( - *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t)); + *err = static_cast(gpr_realloc( + *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t))); #ifndef NDEBUG if (grpc_trace_error_refcount.enabled()) { if (*err != orig) { @@ -219,7 +219,7 @@ static uint8_t get_placement(grpc_error** err, size_t size) { #endif } uint8_t placement = (*err)->arena_size; - (*err)->arena_size = (uint8_t)((*err)->arena_size + slots); + (*err)->arena_size = static_cast((*err)->arena_size + slots); return placement; } @@ -251,7 +251,7 @@ static void internal_set_str(grpc_error** err, grpc_error_strs which, return; } } else { - unref_slice(*(grpc_slice*)((*err)->arena + slot)); + unref_slice(*reinterpret_cast((*err)->arena + slot)); } (*err)->strs[which] = slot; memcpy((*err)->arena + slot, &value, sizeof(value)); @@ -291,7 +291,7 @@ static void internal_add_error(grpc_error** err, grpc_error* new_err) { } else { GPR_ASSERT((*err)->last_err != UINT8_MAX); grpc_linked_error* old_last = - (grpc_linked_error*)((*err)->arena + (*err)->last_err); + reinterpret_cast((*err)->arena + (*err)->last_err); old_last->next = slot; (*err)->last_err = slot; } @@ -315,11 +315,11 @@ grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc, grpc_error** referencing, size_t num_referencing) { GPR_TIMER_SCOPE("grpc_error_create", 0); - uint8_t initial_arena_capacity = (uint8_t)( + uint8_t initial_arena_capacity = static_cast( DEFAULT_ERROR_CAPACITY + - (uint8_t)(num_referencing * SLOTS_PER_LINKED_ERROR) + SURPLUS_CAPACITY); - grpc_error* err = (grpc_error*)gpr_malloc( - sizeof(*err) + initial_arena_capacity * sizeof(intptr_t)); + static_cast(num_referencing * SLOTS_PER_LINKED_ERROR) + SURPLUS_CAPACITY); + grpc_error* err = static_cast(gpr_malloc( + sizeof(*err) + initial_arena_capacity * sizeof(intptr_t))); if (err == nullptr) { // TODO(ctiller): make gpr_malloc return NULL return GRPC_ERROR_OOM; } @@ -362,7 +362,7 @@ static void ref_strs(grpc_error* err) { for (size_t i = 0; i < GRPC_ERROR_STR_MAX; ++i) { uint8_t slot = err->strs[i]; if (slot != UINT8_MAX) { - grpc_slice_ref_internal(*(grpc_slice*)(err->arena + slot)); + grpc_slice_ref_internal(*reinterpret_cast(err->arena + slot)); } } } @@ -370,7 +370,7 @@ static void ref_strs(grpc_error* err) { static void ref_errs(grpc_error* err) { uint8_t slot = err->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = (grpc_linked_error*)(err->arena + slot); + grpc_linked_error* lerr = reinterpret_cast(err->arena + slot); GRPC_ERROR_REF(lerr->err); slot = lerr->next; } @@ -399,11 +399,11 @@ static grpc_error* copy_error_and_unref(grpc_error* in) { uint8_t new_arena_capacity = in->arena_capacity; // the returned err will be added to, so we ensure this is room to avoid // unneeded allocations. - if (in->arena_capacity - in->arena_size < (uint8_t)SLOTS_PER_STR) { - new_arena_capacity = (uint8_t)(3 * new_arena_capacity / 2); + if (in->arena_capacity - in->arena_size < static_castSLOTS_PER_STR) { + new_arena_capacity = static_cast(3 * new_arena_capacity / 2); } - out = (grpc_error*)gpr_malloc(sizeof(*in) + - new_arena_capacity * sizeof(intptr_t)); + out = static_cast(gpr_malloc(sizeof(*in) + + new_arena_capacity * sizeof(intptr_t))); #ifndef NDEBUG if (grpc_trace_error_refcount.enabled()) { gpr_log(GPR_DEBUG, "%p create copying %p", out, in); @@ -487,7 +487,7 @@ bool grpc_error_get_str(grpc_error* err, grpc_error_strs which, } uint8_t slot = err->strs[which]; if (slot != UINT8_MAX) { - *str = *(grpc_slice*)(err->arena + slot); + *str = *reinterpret_cast(err->arena + slot); return true; } else { return false; @@ -519,7 +519,7 @@ typedef struct { static void append_chr(char c, char** s, size_t* sz, size_t* cap) { if (*sz == *cap) { *cap = GPR_MAX(8, 3 * *cap / 2); - *s = (char*)gpr_realloc(*s, *cap); + *s = static_cast(gpr_realloc(*s, *cap)); } (*s)[(*sz)++] = c; } @@ -562,7 +562,7 @@ static void append_esc_str(const uint8_t* str, size_t len, char** s, size_t* sz, break; } } else { - append_chr((char)*str, s, sz, cap); + append_chr(static_cast(*str), s, sz, cap); } } append_chr('"', s, sz, cap); @@ -572,7 +572,7 @@ static void append_kv(kv_pairs* kvs, char* key, char* value) { if (kvs->num_kvs == kvs->cap_kvs) { kvs->cap_kvs = GPR_MAX(3 * kvs->cap_kvs / 2, 4); kvs->kvs = - (kv_pair*)gpr_realloc(kvs->kvs, sizeof(*kvs->kvs) * kvs->cap_kvs); + static_cast(gpr_realloc(kvs->kvs, sizeof(*kvs->kvs) * kvs->cap_kvs)); } kvs->kvs[kvs->num_kvs].key = key; kvs->kvs[kvs->num_kvs].value = value; @@ -593,7 +593,7 @@ static void collect_ints_kvs(grpc_error* err, kv_pairs* kvs) { for (size_t which = 0; which < GRPC_ERROR_INT_MAX; ++which) { uint8_t slot = err->ints[which]; if (slot != UINT8_MAX) { - append_kv(kvs, key_int((grpc_error_ints)which), + append_kv(kvs, key_int(static_cast(which)), fmt_int(err->arena[slot])); } } @@ -617,8 +617,8 @@ static void collect_strs_kvs(grpc_error* err, kv_pairs* kvs) { for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) { uint8_t slot = err->strs[which]; if (slot != UINT8_MAX) { - append_kv(kvs, key_str((grpc_error_strs)which), - fmt_str(*(grpc_slice*)(err->arena + slot))); + append_kv(kvs, key_str(static_cast(which)), + fmt_str(*reinterpret_cast(err->arena + slot))); } } } @@ -652,8 +652,8 @@ static void collect_times_kvs(grpc_error* err, kv_pairs* kvs) { for (size_t which = 0; which < GRPC_ERROR_TIME_MAX; ++which) { uint8_t slot = err->times[which]; if (slot != UINT8_MAX) { - append_kv(kvs, key_time((grpc_error_times)which), - fmt_time(*(gpr_timespec*)(err->arena + slot))); + append_kv(kvs, key_time(static_cast(which)), + fmt_time(*reinterpret_cast(err->arena + slot))); } } } @@ -662,7 +662,7 @@ static void add_errs(grpc_error* err, char** s, size_t* sz, size_t* cap) { uint8_t slot = err->first_err; bool first = true; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = (grpc_linked_error*)(err->arena + slot); + grpc_linked_error* lerr = reinterpret_cast(err->arena + slot); if (!first) append_chr(',', s, sz, cap); first = false; const char* e = grpc_error_string(lerr->err); @@ -685,8 +685,8 @@ static char* errs_string(grpc_error* err) { } static int cmp_kvs(const void* a, const void* b) { - const kv_pair* ka = (const kv_pair*)a; - const kv_pair* kb = (const kv_pair*)b; + const kv_pair* ka = static_cast(a); + const kv_pair* kb = static_cast(b); return strcmp(ka->key, kb->key); } @@ -698,7 +698,7 @@ static char* finish_kvs(kv_pairs* kvs) { append_chr('{', &s, &sz, &cap); for (size_t i = 0; i < kvs->num_kvs; i++) { if (i != 0) append_chr(',', &s, &sz, &cap); - append_esc_str((const uint8_t*)kvs->kvs[i].key, strlen(kvs->kvs[i].key), &s, + append_esc_str(reinterpret_cast(kvs->kvs[i].key), strlen(kvs->kvs[i].key), &s, &sz, &cap); gpr_free(kvs->kvs[i].key); append_chr(':', &s, &sz, &cap); @@ -720,7 +720,7 @@ const char* grpc_error_string(grpc_error* err) { void* p = (void*)gpr_atm_acq_load(&err->atomics.error_string); if (p != nullptr) { - return (const char*)p; + return static_cast(p); } kv_pairs kvs; diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index a05d74c50a..ad013c01b6 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -281,7 +281,7 @@ static grpc_fd* fd_create(int fd, const char* name) { gpr_mu_unlock(&fd_freelist_mu); if (new_fd == nullptr) { - new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd)); + new_fd = static_cast(gpr_malloc(sizeof(grpc_fd))); new_fd->read_closure.Init(); new_fd->write_closure.Init(); } @@ -304,7 +304,7 @@ static grpc_fd* fd_create(int fd, const char* name) { gpr_free(fd_name); struct epoll_event ev; - ev.events = (uint32_t)(EPOLLIN | EPOLLOUT | EPOLLET); + ev.events = static_cast(EPOLLIN | EPOLLOUT | EPOLLET); ev.data.ptr = new_fd; if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_ADD, fd, &ev) != 0) { gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno)); @@ -440,7 +440,7 @@ static worker_remove_result worker_remove(grpc_pollset* pollset, } static size_t choose_neighborhood(void) { - return (size_t)gpr_cpu_current_cpu() % g_num_neighborhoods; + return static_cast(gpr_cpu_current_cpu()) % g_num_neighborhoods; } static grpc_error* pollset_global_init(void) { @@ -451,15 +451,15 @@ static grpc_error* pollset_global_init(void) { grpc_error* err = grpc_wakeup_fd_init(&global_wakeup_fd); if (err != GRPC_ERROR_NONE) return err; struct epoll_event ev; - ev.events = (uint32_t)(EPOLLIN | EPOLLET); + ev.events = static_cast(EPOLLIN | EPOLLET); ev.data.ptr = &global_wakeup_fd; if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_ADD, global_wakeup_fd.read_fd, &ev) != 0) { return GRPC_OS_ERROR(errno, "epoll_ctl"); } g_num_neighborhoods = GPR_CLAMP(gpr_cpu_num_cores(), 1, MAX_NEIGHBORHOODS); - g_neighborhoods = (pollset_neighborhood*)gpr_zalloc(sizeof(*g_neighborhoods) * - g_num_neighborhoods); + g_neighborhoods = static_cast(gpr_zalloc(sizeof(*g_neighborhoods) * + g_num_neighborhoods)); for (size_t i = 0; i < g_num_neighborhoods; i++) { gpr_mu_init(&g_neighborhoods[i].mu); } @@ -579,7 +579,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { } else if (delta < 0) { return 0; } else { - return (int)delta; + return static_cast(delta); } } @@ -609,7 +609,7 @@ static grpc_error* process_epoll_events(grpc_pollset* pollset) { append_error(&error, grpc_wakeup_fd_consume_wakeup(&global_wakeup_fd), err_desc); } else { - grpc_fd* fd = (grpc_fd*)(data_ptr); + grpc_fd* fd = static_cast(data_ptr); bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0; bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0; bool write_ev = (ev->events & EPOLLOUT) != 0; @@ -881,7 +881,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, } else { gpr_atm_no_barrier_store(&g_active_poller, 0); size_t poller_neighborhood_idx = - (size_t)(pollset->neighborhood - g_neighborhoods); + static_cast(pollset->neighborhood - g_neighborhoods); gpr_mu_unlock(&pollset->mu); bool found_worker = false; bool scan_state[MAX_NEIGHBORHOODS]; @@ -1150,7 +1150,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {} */ static grpc_pollset_set* pollset_set_create(void) { - return (grpc_pollset_set*)((intptr_t)0xdeafbeef); + return (grpc_pollset_set*)(static_cast(0xdeafbeef)); } static void pollset_set_destroy(grpc_pollset_set* pss) {} diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 000faed1d9..e201845cd2 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -276,7 +276,7 @@ static void ref_by(grpc_fd* fd, int n) { } static void fd_destroy(void* arg, grpc_error* error) { - grpc_fd* fd = (grpc_fd*)arg; + grpc_fd* fd = static_cast(arg); /* Add the fd to the freelist */ grpc_iomgr_unregister_object(&fd->iomgr_object); POLLABLE_UNREF(fd->pollable_obj, "fd_pollable"); @@ -338,7 +338,7 @@ static grpc_fd* fd_create(int fd, const char* name) { gpr_mu_unlock(&fd_freelist_mu); if (new_fd == nullptr) { - new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd)); + new_fd = static_cast(gpr_malloc(sizeof(grpc_fd))); new_fd->read_closure.Init(); new_fd->write_closure.Init(); } @@ -441,7 +441,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { if (epfd == -1) { return GRPC_OS_ERROR(errno, "epoll_create1"); } - *p = (pollable*)gpr_malloc(sizeof(**p)); + *p = static_cast(gpr_malloc(sizeof(**p))); grpc_error* err = grpc_wakeup_fd_init(&(*p)->wakeup); if (err != GRPC_ERROR_NONE) { close(epfd); @@ -450,7 +450,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { return err; } struct epoll_event ev; - ev.events = (uint32_t)(EPOLLIN | EPOLLET); + ev.events = static_cast(EPOLLIN | EPOLLET); ev.data.ptr = (void*)(1 | (intptr_t) & (*p)->wakeup); if (epoll_ctl(epfd, EPOLL_CTL_ADD, (*p)->wakeup.read_fd, &ev) != 0) { err = GRPC_OS_ERROR(errno, "epoll_ctl"); @@ -479,7 +479,7 @@ static pollable* pollable_ref(pollable* p) { #else static pollable* pollable_ref(pollable* p, int line, const char* reason) { if (grpc_trace_pollable_refcount.enabled()) { - int r = (int)gpr_atm_no_barrier_load(&p->refs.count); + int r = static_castgpr_atm_no_barrier_load(&p->refs.count); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason); } @@ -494,7 +494,7 @@ static void pollable_unref(pollable* p) { static void pollable_unref(pollable* p, int line, const char* reason) { if (p == nullptr) return; if (grpc_trace_pollable_refcount.enabled()) { - int r = (int)gpr_atm_no_barrier_load(&p->refs.count); + int r = static_castgpr_atm_no_barrier_load(&p->refs.count); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason); } @@ -516,7 +516,7 @@ static grpc_error* pollable_add_fd(pollable* p, grpc_fd* fd) { } struct epoll_event ev_fd; - ev_fd.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE); + ev_fd.events = static_cast(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE); ev_fd.data.ptr = fd; if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd->fd, &ev_fd) != 0) { switch (errno) { @@ -699,7 +699,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { else if (delta < 0) return 0; else - return (int)delta; + return static_cast(delta); } static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { @@ -768,10 +768,10 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset, } append_error(&error, grpc_wakeup_fd_consume_wakeup( - (grpc_wakeup_fd*)((~(intptr_t)1) & (intptr_t)data_ptr)), + (grpc_wakeup_fd*)((~static_cast(1)) & (intptr_t)data_ptr)), err_desc); } else { - grpc_fd* fd = (grpc_fd*)data_ptr; + grpc_fd* fd = static_cast(data_ptr); bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0; bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0; bool write_ev = (ev->events & EPOLLOUT) != 0; @@ -1170,7 +1170,7 @@ static grpc_pollset_set* pss_lock_adam(grpc_pollset_set* pss) { } static grpc_pollset_set* pollset_set_create(void) { - grpc_pollset_set* pss = (grpc_pollset_set*)gpr_zalloc(sizeof(*pss)); + grpc_pollset_set* pss = static_cast(gpr_zalloc(sizeof(*pss))); gpr_mu_init(&pss->mu); gpr_ref_init(&pss->refs, 1); return pss; @@ -1211,7 +1211,7 @@ static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { if (pss->fd_count == pss->fd_capacity) { pss->fd_capacity = GPR_MAX(pss->fd_capacity * 2, 8); pss->fds = - (grpc_fd**)gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds)); + static_cast(gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds))); } REF_BY(fd, 2, "pollset_set"); pss->fds[pss->fd_count++] = fd; @@ -1319,8 +1319,8 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { err_desc); if (pss->pollset_count == pss->pollset_capacity) { pss->pollset_capacity = GPR_MAX(pss->pollset_capacity * 2, 8); - pss->pollsets = (grpc_pollset**)gpr_realloc( - pss->pollsets, pss->pollset_capacity * sizeof(*pss->pollsets)); + pss->pollsets = static_cast(gpr_realloc( + pss->pollsets, pss->pollset_capacity * sizeof(*pss->pollsets))); } pss->pollsets[pss->pollset_count++] = ps; gpr_mu_unlock(&pss->mu); @@ -1373,7 +1373,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a, b->parent = a; if (a->fd_capacity < a->fd_count + b->fd_count) { a->fd_capacity = GPR_MAX(2 * a->fd_capacity, a->fd_count + b->fd_count); - a->fds = (grpc_fd**)gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds)); + a->fds = static_cast(gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds))); } size_t initial_a_fd_count = a->fd_count; a->fd_count = 0; @@ -1390,8 +1390,8 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a, if (a->pollset_capacity < a->pollset_count + b->pollset_count) { a->pollset_capacity = GPR_MAX(2 * a->pollset_capacity, a->pollset_count + b->pollset_count); - a->pollsets = (grpc_pollset**)gpr_realloc( - a->pollsets, a->pollset_capacity * sizeof(*a->pollsets)); + a->pollsets = static_cast(gpr_realloc( + a->pollsets, a->pollset_capacity * sizeof(*a->pollsets))); } if (b->pollset_count > 0) { memcpy(a->pollsets + a->pollset_count, b->pollsets, diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 4c26bbd2c6..438b4c8c09 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -349,7 +349,7 @@ static void polling_island_add_fds_locked(polling_island* pi, grpc_fd** fds, #endif /* defined(GRPC_TSAN) */ for (i = 0; i < fd_count; i++) { - ev.events = (uint32_t)(EPOLLIN | EPOLLOUT | EPOLLET); + ev.events = static_cast(EPOLLIN | EPOLLOUT | EPOLLET); ev.data.ptr = fds[i]; err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_ADD, fds[i]->fd, &ev); @@ -369,7 +369,7 @@ static void polling_island_add_fds_locked(polling_island* pi, grpc_fd** fds, if (pi->fd_cnt == pi->fd_capacity) { pi->fd_capacity = GPR_MAX(pi->fd_capacity + 8, pi->fd_cnt * 3 / 2); pi->fds = - (grpc_fd**)gpr_realloc(pi->fds, sizeof(grpc_fd*) * pi->fd_capacity); + static_cast(gpr_realloc(pi->fds, sizeof(grpc_fd*) * pi->fd_capacity)); } pi->fds[pi->fd_cnt++] = fds[i]; @@ -388,7 +388,7 @@ static void polling_island_add_wakeup_fd_locked(polling_island* pi, char* err_msg; const char* err_desc = "polling_island_add_wakeup_fd"; - ev.events = (uint32_t)(EPOLLIN | EPOLLET); + ev.events = static_cast(EPOLLIN | EPOLLET); ev.data.ptr = wakeup_fd; err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_ADD, GRPC_WAKEUP_FD_GET_READ_FD(wakeup_fd), &ev); @@ -471,7 +471,7 @@ static polling_island* polling_island_create(grpc_fd* initial_fd, *error = GRPC_ERROR_NONE; - pi = (polling_island*)gpr_malloc(sizeof(*pi)); + pi = static_cast(gpr_malloc(sizeof(*pi))); gpr_mu_init(&pi->mu); pi->fd_cnt = 0; pi->fd_capacity = 0; @@ -815,7 +815,7 @@ static grpc_fd* fd_create(int fd, const char* name) { gpr_mu_unlock(&fd_freelist_mu); if (new_fd == nullptr) { - new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd)); + new_fd = static_cast(gpr_malloc(sizeof(grpc_fd))); gpr_mu_init(&new_fd->po.mu); new_fd->read_closure.Init(); new_fd->write_closure.Init(); @@ -976,7 +976,7 @@ static grpc_error* pollset_worker_kick(grpc_pollset_worker* worker) { grpc_error* err = GRPC_ERROR_NONE; /* Kick the worker only if it was not already kicked */ - if (gpr_atm_no_barrier_cas(&worker->is_kicked, (gpr_atm)0, (gpr_atm)1)) { + if (gpr_atm_no_barrier_cas(&worker->is_kicked, static_cast(0), static_cast(1))) { GRPC_POLLING_TRACE( "pollset_worker_kick: Kicking worker: %p (thread id: %ld)", (void*)worker, (long int)worker->pt_id); @@ -1096,7 +1096,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { else if (delta < 0) return 0; else - return (int)delta; + return static_cast(delta); } static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { @@ -1251,7 +1251,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, to the function pollset_work_and_unlock() will pick up the correct epoll_fd */ } else { - grpc_fd* fd = (grpc_fd*)data_ptr; + grpc_fd* fd = static_cast(data_ptr); int cancel = ep_ev[i].events & (EPOLLERR | EPOLLHUP); int read_ev = ep_ev[i].events & (EPOLLIN | EPOLLPRI); int write_ev = ep_ev[i].events & EPOLLOUT; @@ -1538,7 +1538,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { */ static grpc_pollset_set* pollset_set_create(void) { - grpc_pollset_set* pss = (grpc_pollset_set*)gpr_malloc(sizeof(*pss)); + grpc_pollset_set* pss = static_cast(gpr_malloc(sizeof(*pss))); gpr_mu_init(&pss->po.mu); pss->po.pi = nullptr; #ifndef NDEBUG @@ -1607,8 +1607,8 @@ void* grpc_pollset_get_polling_island(grpc_pollset* ps) { } bool grpc_are_polling_islands_equal(void* p, void* q) { - polling_island* p1 = (polling_island*)p; - polling_island* p2 = (polling_island*)q; + polling_island* p1 = static_cast(p); + polling_island* p2 = static_cast(q); /* Note: polling_island_lock_pair() may change p1 and p2 to point to the latest polling islands in their respective linked lists */ diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 9833b47bd3..769fdbc299 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -323,7 +323,7 @@ static void unref_by(grpc_fd* fd, int n) { } static grpc_fd* fd_create(int fd, const char* name) { - grpc_fd* r = (grpc_fd*)gpr_malloc(sizeof(*r)); + grpc_fd* r = static_cast(gpr_malloc(sizeof(*r))); gpr_mu_init(&r->mu); gpr_atm_rel_store(&r->refst, 1); r->shutdown = 0; @@ -835,8 +835,8 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { if (pollset->fd_count == pollset->fd_capacity) { pollset->fd_capacity = GPR_MAX(pollset->fd_capacity + 8, pollset->fd_count * 3 / 2); - pollset->fds = (grpc_fd**)gpr_realloc( - pollset->fds, sizeof(grpc_fd*) * pollset->fd_capacity); + pollset->fds = static_cast(gpr_realloc( + pollset->fds, sizeof(grpc_fd*) * pollset->fd_capacity)); } pollset->fds[pollset->fd_count++] = fd; GRPC_FD_REF(fd, "multipoller"); @@ -890,7 +890,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, pollset->local_wakeup_cache = worker.wakeup_fd->next; } else { worker.wakeup_fd = - (grpc_cached_wakeup_fd*)gpr_malloc(sizeof(*worker.wakeup_fd)); + static_cast(gpr_malloc(sizeof(*worker.wakeup_fd))); error = grpc_wakeup_fd_init(&worker.wakeup_fd->fd); if (error != GRPC_ERROR_NONE) { GRPC_LOG_IF_ERROR("pollset_work", GRPC_ERROR_REF(error)); @@ -945,8 +945,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset, const size_t pfd_size = sizeof(*pfds) * (pollset->fd_count + 2); const size_t watch_size = sizeof(*watchers) * (pollset->fd_count + 2); void* buf = gpr_malloc(pfd_size + watch_size); - pfds = (struct pollfd*)buf; - watchers = (grpc_fd_watcher*)(void*)((char*)buf + pfd_size); + pfds = static_cast(buf); + watchers = static_cast((void*)(static_cast(buf) + pfd_size)); } fd_count = 0; @@ -972,8 +972,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset, for (i = 1; i < pfd_count; i++) { grpc_fd* fd = watchers[i].fd; - pfds[i].events = (short)fd_begin_poll(fd, pollset, &worker, POLLIN, - POLLOUT, &watchers[i]); + pfds[i].events = static_cast(fd_begin_poll(fd, pollset, &worker, POLLIN, + POLLOUT, &watchers[i])); GRPC_FD_UNREF(fd, "multipoller_start"); } @@ -1123,7 +1123,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis deadline) { grpc_millis n = deadline - grpc_core::ExecCtx::Get()->Now(); if (n < 0) return 0; if (n > INT_MAX) return -1; - return (int)n; + return static_cast(n); } /******************************************************************************* @@ -1132,7 +1132,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis deadline) { static grpc_pollset_set* pollset_set_create(void) { grpc_pollset_set* pollset_set = - (grpc_pollset_set*)gpr_zalloc(sizeof(*pollset_set)); + static_cast(gpr_zalloc(sizeof(*pollset_set))); gpr_mu_init(&pollset_set->mu); return pollset_set; } @@ -1173,9 +1173,9 @@ static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, if (pollset_set->pollset_count == pollset_set->pollset_capacity) { pollset_set->pollset_capacity = GPR_MAX(8, 2 * pollset_set->pollset_capacity); - pollset_set->pollsets = (grpc_pollset**)gpr_realloc( + pollset_set->pollsets = static_cast(gpr_realloc( pollset_set->pollsets, - pollset_set->pollset_capacity * sizeof(*pollset_set->pollsets)); + pollset_set->pollset_capacity * sizeof(*pollset_set->pollsets))); } pollset_set->pollsets[pollset_set->pollset_count++] = pollset; for (i = 0, j = 0; i < pollset_set->fd_count; i++) { @@ -1222,9 +1222,9 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* bag, gpr_mu_lock(&bag->mu); if (bag->pollset_set_count == bag->pollset_set_capacity) { bag->pollset_set_capacity = GPR_MAX(8, 2 * bag->pollset_set_capacity); - bag->pollset_sets = (grpc_pollset_set**)gpr_realloc( + bag->pollset_sets = static_cast(gpr_realloc( bag->pollset_sets, - bag->pollset_set_capacity * sizeof(*bag->pollset_sets)); + bag->pollset_set_capacity * sizeof(*bag->pollset_sets))); } bag->pollset_sets[bag->pollset_set_count++] = item; for (i = 0, j = 0; i < bag->fd_count; i++) { @@ -1259,8 +1259,8 @@ static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { gpr_mu_lock(&pollset_set->mu); if (pollset_set->fd_count == pollset_set->fd_capacity) { pollset_set->fd_capacity = GPR_MAX(8, 2 * pollset_set->fd_capacity); - pollset_set->fds = (grpc_fd**)gpr_realloc( - pollset_set->fds, pollset_set->fd_capacity * sizeof(*pollset_set->fds)); + pollset_set->fds = static_cast(gpr_realloc( + pollset_set->fds, pollset_set->fd_capacity * sizeof(*pollset_set->fds))); } GRPC_FD_REF(fd, "pollset_set"); pollset_set->fds[pollset_set->fd_count++] = fd; @@ -1312,12 +1312,12 @@ static void cache_insert_locked(poll_args* args) { } static void init_result(poll_args* pargs) { - pargs->result = (poll_result*)gpr_malloc(sizeof(poll_result)); + pargs->result = static_cast(gpr_malloc(sizeof(poll_result))); gpr_ref_init(&pargs->result->refcount, 1); pargs->result->watchers = nullptr; pargs->result->watchcount = 0; pargs->result->fds = - (struct pollfd*)gpr_malloc(sizeof(struct pollfd) * pargs->nfds); + static_cast(gpr_malloc(sizeof(struct pollfd) * pargs->nfds)); memcpy(pargs->result->fds, pargs->fds, sizeof(struct pollfd) * pargs->nfds); pargs->result->nfds = pargs->nfds; pargs->result->retval = 0; @@ -1356,7 +1356,7 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) { return pargs; } - poll_args* pargs = (poll_args*)gpr_malloc(sizeof(struct poll_args)); + poll_args* pargs = static_cast(gpr_malloc(sizeof(struct poll_args))); gpr_cv_init(&pargs->trigger); pargs->fds = fds; pargs->nfds = count; @@ -1404,7 +1404,7 @@ static void cache_poller_locked(poll_args* args) { poll_cache.size = poll_cache.size * 2; poll_cache.count = 0; poll_cache.active_pollers = - (poll_args**)gpr_malloc(sizeof(void*) * poll_cache.size); + static_cast(gpr_malloc(sizeof(void*) * poll_cache.size)); for (unsigned int i = 0; i < poll_cache.size; i++) { poll_cache.active_pollers[i] = nullptr; } @@ -1461,7 +1461,7 @@ gpr_timespec thread_grace; // Poll in a background thread static void run_poll(void* args) { - poll_args* pargs = (poll_args*)args; + poll_args* pargs = static_cast(args); while (1) { poll_result* result = pargs->result; int retval = g_cvfds.poll(result->fds, result->nfds, CV_POLL_PERIOD_MS); @@ -1509,12 +1509,12 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { nfds_t nsockfds = 0; poll_result* result = nullptr; gpr_mu_lock(&g_cvfds.mu); - pollcv = (grpc_cv_node*)gpr_malloc(sizeof(grpc_cv_node)); + pollcv = static_cast(gpr_malloc(sizeof(grpc_cv_node))); pollcv->next = nullptr; gpr_cv pollcv_cv; gpr_cv_init(&pollcv_cv); pollcv->cv = &pollcv_cv; - grpc_cv_node* fd_cvs = (grpc_cv_node*)gpr_malloc(nfds * sizeof(grpc_cv_node)); + grpc_cv_node* fd_cvs = static_cast(gpr_malloc(nfds * sizeof(grpc_cv_node))); for (i = 0; i < nfds; i++) { fds[i].revents = 0; @@ -1547,7 +1547,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { res = 0; if (!skip_poll && nsockfds > 0) { struct pollfd* pollfds = - (struct pollfd*)gpr_malloc(sizeof(struct pollfd) * nsockfds); + static_cast(gpr_malloc(sizeof(struct pollfd) * nsockfds)); idx = 0; for (i = 0; i < nfds; i++) { if (fds[i].fd >= 0) { @@ -1611,7 +1611,7 @@ static void global_cv_fd_table_init() { gpr_ref_init(&g_cvfds.pollcount, 1); g_cvfds.size = CV_DEFAULT_TABLE_SIZE; g_cvfds.cvfds = - (grpc_fd_node*)gpr_malloc(sizeof(grpc_fd_node) * CV_DEFAULT_TABLE_SIZE); + static_cast(gpr_malloc(sizeof(grpc_fd_node) * CV_DEFAULT_TABLE_SIZE)); g_cvfds.free_fds = nullptr; thread_grace = gpr_time_from_millis(POLLCV_THREAD_GRACE_MS, GPR_TIMESPAN); for (int i = 0; i < CV_DEFAULT_TABLE_SIZE; i++) { @@ -1628,7 +1628,7 @@ static void global_cv_fd_table_init() { poll_cache.size = 32; poll_cache.count = 0; poll_cache.free_pollers = nullptr; - poll_cache.active_pollers = (poll_args**)gpr_malloc(sizeof(void*) * 32); + poll_cache.active_pollers = static_cast(gpr_malloc(sizeof(void*) * 32)); for (unsigned int i = 0; i < poll_cache.size; i++) { poll_cache.active_pollers[i] = nullptr; } diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index af5dfe5bf3..4280794428 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -108,11 +108,11 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) { char* s; size_t len; GPR_ASSERT(end >= beg); - len = (size_t)(end - beg); - s = (char*)gpr_malloc(len + 1); + len = static_cast(end - beg); + s = static_cast(gpr_malloc(len + 1)); memcpy(s, beg, len); s[len] = 0; - *ss = (char**)gpr_realloc(*ss, sizeof(char**) * np); + *ss = static_cast(gpr_realloc(*ss, sizeof(char**) * np)); (*ss)[n] = s; *ns = np; } diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 03c833ff07..89c6a873e6 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -54,20 +54,20 @@ static gpr_timespec g_start_time; static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time); double x = - GPR_MS_PER_SEC * (double)ts.tv_sec + (double)ts.tv_nsec / GPR_NS_PER_MS; + GPR_MS_PER_SEC * static_cast(ts.tv_sec) + static_cast(ts.tv_nsec) / GPR_NS_PER_MS; if (x < 0) return 0; if (x > GPR_ATM_MAX) return GPR_ATM_MAX; - return (gpr_atm)x; + return static_cast(x); } static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time); - double x = GPR_MS_PER_SEC * (double)ts.tv_sec + - (double)ts.tv_nsec / GPR_NS_PER_MS + - (double)(GPR_NS_PER_SEC - 1) / (double)GPR_NS_PER_SEC; + double x = GPR_MS_PER_SEC * static_cast(ts.tv_sec) + + static_cast(ts.tv_nsec) / GPR_NS_PER_MS + + static_cast(GPR_NS_PER_SEC - 1) / static_cast(GPR_NS_PER_SEC); if (x < 0) return 0; if (x > GPR_ATM_MAX) return GPR_ATM_MAX; - return (gpr_atm)x; + return static_cast(x); } gpr_timespec grpc_millis_to_timespec(grpc_millis millis, diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 3288ea3de5..901bbdd4df 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -95,7 +95,7 @@ void grpc_executor_set_threading(bool threading) { gpr_atm_no_barrier_store(&g_cur_threads, 1); gpr_tls_init(&g_this_thread_state); g_thread_state = - (thread_state*)gpr_zalloc(sizeof(thread_state) * g_max_threads); + static_cast(gpr_zalloc(sizeof(thread_state) * g_max_threads)); for (size_t i = 0; i < g_max_threads; i++) { gpr_mu_init(&g_thread_state[i].mu); gpr_cv_init(&g_thread_state[i].cv); @@ -140,7 +140,7 @@ void grpc_executor_init() { void grpc_executor_shutdown() { grpc_executor_set_threading(false); } static void executor_thread(void* arg) { - thread_state* ts = (thread_state*)arg; + thread_state* ts = static_cast(arg); gpr_tls_set(&g_this_thread_state, (intptr_t)ts); grpc_core::ExecCtx exec_ctx(0); @@ -149,7 +149,7 @@ static void executor_thread(void* arg) { for (;;) { if (executor_trace.enabled()) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: step (sub_depth=%" PRIdPTR ")", - (int)(ts - g_thread_state), subtract_depth); + static_cast(ts - g_thread_state), subtract_depth); } gpr_mu_lock(&ts->mu); ts->depth -= subtract_depth; @@ -160,7 +160,7 @@ static void executor_thread(void* arg) { if (ts->shutdown) { if (executor_trace.enabled()) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: shutdown", - (int)(ts - g_thread_state)); + static_cast(ts - g_thread_state)); } gpr_mu_unlock(&ts->mu); break; @@ -170,7 +170,7 @@ static void executor_thread(void* arg) { ts->elems = GRPC_CLOSURE_LIST_INIT; gpr_mu_unlock(&ts->mu); if (executor_trace.enabled()) { - gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state)); + gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", static_cast(ts - g_thread_state)); } grpc_core::ExecCtx::Get()->InvalidateNow(); @@ -188,7 +188,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error, } do { retry_push = false; - size_t cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads); + size_t cur_thread_count = static_castgpr_atm_no_barrier_load(&g_cur_threads); if (cur_thread_count == 0) { if (executor_trace.enabled()) { #ifndef NDEBUG @@ -219,7 +219,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error, GPR_DEBUG, "EXECUTOR: try to schedule %p (%s) (created %s:%d) to thread %d", closure, is_short ? "short" : "long", closure->file_created, - closure->line_created, (int)(ts - g_thread_state)); + closure->line_created, static_cast(ts - g_thread_state)); #else gpr_log(GPR_DEBUG, "EXECUTOR: try to schedule %p (%s) to thread %d", closure, is_short ? "short" : "long", @@ -233,7 +233,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error, // guarantee no starvation) // ... spin through queues and try again gpr_mu_unlock(&ts->mu); - size_t idx = (size_t)(ts - g_thread_state); + size_t idx = static_cast(ts - g_thread_state); ts = &g_thread_state[(idx + 1) % cur_thread_count]; if (ts == orig_ts) { retry_push = true; @@ -255,7 +255,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error, break; } if (try_new_thread && gpr_spinlock_trylock(&g_adding_thread_lock)) { - cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads); + cur_thread_count = static_castgpr_atm_no_barrier_load(&g_cur_threads); if (cur_thread_count < g_max_threads) { gpr_atm_no_barrier_store(&g_cur_threads, cur_thread_count + 1); diff --git a/src/core/lib/iomgr/gethostname_host_name_max.cc b/src/core/lib/iomgr/gethostname_host_name_max.cc index 2487160916..ae95788a1e 100644 --- a/src/core/lib/iomgr/gethostname_host_name_max.cc +++ b/src/core/lib/iomgr/gethostname_host_name_max.cc @@ -27,7 +27,7 @@ #include char* grpc_gethostname() { - char* hostname = (char*)gpr_malloc(HOST_NAME_MAX); + char* hostname = static_cast(gpr_malloc(HOST_NAME_MAX)); if (gethostname(hostname, HOST_NAME_MAX) != 0) { gpr_free(hostname); return nullptr; diff --git a/src/core/lib/iomgr/is_epollexclusive_available.cc b/src/core/lib/iomgr/is_epollexclusive_available.cc index 08f9cf2b69..a58a5775d3 100644 --- a/src/core/lib/iomgr/is_epollexclusive_available.cc +++ b/src/core/lib/iomgr/is_epollexclusive_available.cc @@ -61,7 +61,7 @@ bool grpc_is_epollexclusive_available(void) { /* choose events that should cause an error on EPOLLEXCLUSIVE enabled kernels - specifically the combination of EPOLLONESHOT and EPOLLEXCLUSIVE */ - ev.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT); + ev.events = static_cast(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT); ev.data.ptr = nullptr; if (epoll_ctl(fd, EPOLL_CTL_ADD, evfd, &ev) != 0) { if (errno != EINVAL) { diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc index b6586fbc73..5e637ff8b5 100644 --- a/src/core/lib/iomgr/load_file.cc +++ b/src/core/lib/iomgr/load_file.cc @@ -45,10 +45,10 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator, } fseek(file, 0, SEEK_END); /* Converting to size_t on the assumption that it will not fail */ - contents_size = (size_t)ftell(file); + contents_size = static_cast(ftell(file)); fseek(file, 0, SEEK_SET); contents = - (unsigned char*)gpr_malloc(contents_size + (add_null_terminator ? 1 : 0)); + static_cast(gpr_malloc(contents_size + (add_null_terminator ? 1 : 0))); bytes_read = fread(contents, 1, contents_size, file); if (bytes_read < contents_size) { error = GRPC_OS_ERROR(errno, "fread"); diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index 3eea709ce4..b49b080c12 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -115,13 +115,13 @@ static grpc_error* blocking_resolve_address_impl( /* Success path: set addrs non-NULL, fill it in */ *addresses = - (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses)); + static_cast(gpr_malloc(sizeof(grpc_resolved_addresses))); (*addresses)->naddrs = 0; for (resp = result; resp != nullptr; resp = resp->ai_next) { (*addresses)->naddrs++; } - (*addresses)->addrs = (grpc_resolved_address*)gpr_malloc( - sizeof(grpc_resolved_address) * (*addresses)->naddrs); + (*addresses)->addrs = static_cast(gpr_malloc( + sizeof(grpc_resolved_address) * (*addresses)->naddrs)); i = 0; for (resp = result; resp != nullptr; resp = resp->ai_next) { memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); @@ -155,7 +155,7 @@ typedef struct { /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ static void do_request_thread(void* rp, grpc_error* error) { - request* r = (request*)rp; + request* r = static_cast(rp); GRPC_CLOSURE_SCHED(r->on_done, grpc_blocking_resolve_address( r->name, r->default_port, r->addrs_out)); gpr_free(r->name); @@ -174,7 +174,7 @@ static void resolve_address_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { - request* r = (request*)gpr_malloc(sizeof(request)); + request* r = static_cast(gpr_malloc(sizeof(request))); GRPC_CLOSURE_INIT(&r->request_closure, do_request_thread, r, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)); r->name = gpr_strdup(name); diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index e64d772a7d..40dd29b6a4 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -244,7 +244,7 @@ static bool rq_reclaim_from_per_user_free_pool( static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive); static void rq_step(void* rq, grpc_error* error) { - grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq; + grpc_resource_quota* resource_quota = static_cast(rq); resource_quota->step_scheduled = false; do { if (rq_alloc(resource_quota)) goto done; @@ -303,7 +303,7 @@ static bool rq_alloc(grpc_resource_quota* resource_quota) { resource_user->free_pool += aborted_allocations; GRPC_CLOSURE_LIST_SCHED(&resource_user->on_allocated); gpr_mu_unlock(&resource_user->mu); - ru_unref_by(resource_user, (gpr_atm)aborted_allocations); + ru_unref_by(resource_user, static_cast(aborted_allocations)); continue; } if (resource_user->free_pool < 0 && @@ -401,12 +401,12 @@ typedef struct { } ru_slice_refcount; static void ru_slice_ref(void* p) { - ru_slice_refcount* rc = (ru_slice_refcount*)p; + ru_slice_refcount* rc = static_cast(p); gpr_ref(&rc->refs); } static void ru_slice_unref(void* p) { - ru_slice_refcount* rc = (ru_slice_refcount*)p; + ru_slice_refcount* rc = static_cast(p); if (gpr_unref(&rc->refs)) { grpc_resource_user_free(rc->resource_user, rc->size); gpr_free(rc); @@ -420,7 +420,7 @@ static const grpc_slice_refcount_vtable ru_slice_vtable = { static grpc_slice ru_slice_create(grpc_resource_user* resource_user, size_t size) { ru_slice_refcount* rc = - (ru_slice_refcount*)gpr_malloc(sizeof(ru_slice_refcount) + size); + static_cast(gpr_malloc(sizeof(ru_slice_refcount) + size)); rc->base.vtable = &ru_slice_vtable; rc->base.sub_refcount = &rc->base; gpr_ref_init(&rc->refs, 1); @@ -428,7 +428,7 @@ static grpc_slice ru_slice_create(grpc_resource_user* resource_user, rc->size = size; grpc_slice slice; slice.refcount = &rc->base; - slice.data.refcounted.bytes = (uint8_t*)(rc + 1); + slice.data.refcounted.bytes = reinterpret_cast(rc + 1); slice.data.refcounted.length = size; return slice; } @@ -439,7 +439,7 @@ static grpc_slice ru_slice_create(grpc_resource_user* resource_user, */ static void ru_allocate(void* ru, grpc_error* error) { - grpc_resource_user* resource_user = (grpc_resource_user*)ru; + grpc_resource_user* resource_user = static_cast(ru); if (rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION)) { rq_step_sched(resource_user->resource_quota); @@ -448,7 +448,7 @@ static void ru_allocate(void* ru, grpc_error* error) { } static void ru_add_to_free_pool(void* ru, grpc_error* error) { - grpc_resource_user* resource_user = (grpc_resource_user*)ru; + grpc_resource_user* resource_user = static_cast(ru); if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && rulist_empty(resource_user->resource_quota, @@ -473,7 +473,7 @@ static bool ru_post_reclaimer(grpc_resource_user* resource_user, } static void ru_post_benign_reclaimer(void* ru, grpc_error* error) { - grpc_resource_user* resource_user = (grpc_resource_user*)ru; + grpc_resource_user* resource_user = static_cast(ru); if (!ru_post_reclaimer(resource_user, false)) return; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && @@ -487,7 +487,7 @@ static void ru_post_benign_reclaimer(void* ru, grpc_error* error) { } static void ru_post_destructive_reclaimer(void* ru, grpc_error* error) { - grpc_resource_user* resource_user = (grpc_resource_user*)ru; + grpc_resource_user* resource_user = static_cast(ru); if (!ru_post_reclaimer(resource_user, true)) return; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && @@ -506,7 +506,7 @@ static void ru_shutdown(void* ru, grpc_error* error) { if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RU shutdown %p", ru); } - grpc_resource_user* resource_user = (grpc_resource_user*)ru; + grpc_resource_user* resource_user = static_cast(ru); gpr_mu_lock(&resource_user->mu); GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED); GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); @@ -521,10 +521,10 @@ static void ru_shutdown(void* ru, grpc_error* error) { } static void ru_destroy(void* ru, grpc_error* error) { - grpc_resource_user* resource_user = (grpc_resource_user*)ru; + grpc_resource_user* resource_user = static_cast(ru); GPR_ASSERT(gpr_atm_no_barrier_load(&resource_user->refs) == 0); for (int i = 0; i < GRPC_RULIST_COUNT; i++) { - rulist_remove(resource_user, (grpc_rulist)i); + rulist_remove(resource_user, static_cast(i)); } GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED); GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); @@ -540,7 +540,7 @@ static void ru_destroy(void* ru, grpc_error* error) { static void ru_allocated_slices(void* arg, grpc_error* error) { grpc_resource_user_slice_allocator* slice_allocator = - (grpc_resource_user_slice_allocator*)arg; + static_cast(arg); if (error == GRPC_ERROR_NONE) { for (size_t i = 0; i < slice_allocator->count; i++) { grpc_slice_buffer_add_indexed( @@ -563,7 +563,7 @@ typedef struct { } rq_resize_args; static void rq_resize(void* args, grpc_error* error) { - rq_resize_args* a = (rq_resize_args*)args; + rq_resize_args* a = static_cast(args); int64_t delta = a->size - a->resource_quota->size; a->resource_quota->size += delta; a->resource_quota->free_pool += delta; @@ -574,7 +574,7 @@ static void rq_resize(void* args, grpc_error* error) { } static void rq_reclamation_done(void* rq, grpc_error* error) { - grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq; + grpc_resource_quota* resource_quota = static_cast(rq); resource_quota->reclaiming = false; rq_step_sched(resource_quota); grpc_resource_quota_unref_internal(resource_quota); @@ -587,7 +587,7 @@ static void rq_reclamation_done(void* rq, grpc_error* error) { /* Public API */ grpc_resource_quota* grpc_resource_quota_create(const char* name) { grpc_resource_quota* resource_quota = - (grpc_resource_quota*)gpr_malloc(sizeof(*resource_quota)); + static_cast(gpr_malloc(sizeof(*resource_quota))); gpr_ref_init(&resource_quota->refs, 1); resource_quota->combiner = grpc_combiner_create(); resource_quota->free_pool = INT64_MAX; @@ -640,18 +640,18 @@ void grpc_resource_quota_ref(grpc_resource_quota* resource_quota) { double grpc_resource_quota_get_memory_pressure( grpc_resource_quota* resource_quota) { - return ((double)(gpr_atm_no_barrier_load( + return (static_cast(gpr_atm_no_barrier_load( &resource_quota->memory_usage_estimation))) / - ((double)MEMORY_USAGE_ESTIMATION_MAX); + (static_cast(MEMORY_USAGE_ESTIMATION_MAX)); } /* Public API */ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, size_t size) { grpc_core::ExecCtx exec_ctx; - rq_resize_args* a = (rq_resize_args*)gpr_malloc(sizeof(*a)); + rq_resize_args* a = static_cast(gpr_malloc(sizeof(*a))); a->resource_quota = grpc_resource_quota_ref_internal(resource_quota); - a->size = (int64_t)size; + a->size = static_cast(size); gpr_atm_no_barrier_store(&resource_quota->last_size, (gpr_atm)GPR_MIN((size_t)GPR_ATM_MAX, size)); GRPC_CLOSURE_INIT(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx); @@ -659,7 +659,7 @@ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, } size_t grpc_resource_quota_peek_size(grpc_resource_quota* resource_quota) { - return (size_t)gpr_atm_no_barrier_load(&resource_quota->last_size); + return static_castgpr_atm_no_barrier_load(&resource_quota->last_size); } /******************************************************************************* @@ -672,7 +672,7 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args( if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { if (channel_args->args[i].type == GRPC_ARG_POINTER) { return grpc_resource_quota_ref_internal( - (grpc_resource_quota*)channel_args->args[i].value.pointer.p); + static_cast(channel_args->args[i].value.pointer.p)); } else { gpr_log(GPR_DEBUG, GRPC_ARG_RESOURCE_QUOTA " should be a pointer"); } @@ -682,12 +682,12 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args( } static void* rq_copy(void* rq) { - grpc_resource_quota_ref((grpc_resource_quota*)rq); + grpc_resource_quota_ref(static_cast(rq)); return rq; } static void rq_destroy(void* rq) { - grpc_resource_quota_unref_internal((grpc_resource_quota*)rq); + grpc_resource_quota_unref_internal(static_cast(rq)); } static int rq_cmp(void* a, void* b) { return GPR_ICMP(a, b); } @@ -704,7 +704,7 @@ const grpc_arg_pointer_vtable* grpc_resource_quota_arg_vtable(void) { grpc_resource_user* grpc_resource_user_create( grpc_resource_quota* resource_quota, const char* name) { grpc_resource_user* resource_user = - (grpc_resource_user*)gpr_malloc(sizeof(*resource_user)); + static_cast(gpr_malloc(sizeof(*resource_user))); resource_user->resource_quota = grpc_resource_quota_ref_internal(resource_quota); GRPC_CLOSURE_INIT(&resource_user->allocate_closure, &ru_allocate, @@ -785,9 +785,9 @@ void grpc_resource_user_shutdown(grpc_resource_user* resource_user) { void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, grpc_closure* optional_on_done) { gpr_mu_lock(&resource_user->mu); - ru_ref_by(resource_user, (gpr_atm)size); - resource_user->free_pool -= (int64_t)size; - resource_user->outstanding_allocations += (int64_t)size; + ru_ref_by(resource_user, static_cast(size)); + resource_user->free_pool -= static_cast(size); + resource_user->outstanding_allocations += static_cast(size); if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RQ %s %s: alloc %" PRIdPTR "; free_pool -> %" PRId64, resource_user->resource_quota->name, resource_user->name, size, @@ -801,7 +801,7 @@ void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, GRPC_CLOSURE_SCHED(&resource_user->allocate_closure, GRPC_ERROR_NONE); } } else { - resource_user->outstanding_allocations -= (int64_t)size; + resource_user->outstanding_allocations -= static_cast(size); GRPC_CLOSURE_SCHED(optional_on_done, GRPC_ERROR_NONE); } gpr_mu_unlock(&resource_user->mu); @@ -810,7 +810,7 @@ void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) { gpr_mu_lock(&resource_user->mu); bool was_zero_or_negative = resource_user->free_pool <= 0; - resource_user->free_pool += (int64_t)size; + resource_user->free_pool += static_cast(size); if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RQ %s %s: free %" PRIdPTR "; free_pool -> %" PRId64, resource_user->resource_quota->name, resource_user->name, size, @@ -824,7 +824,7 @@ void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) { GRPC_ERROR_NONE); } gpr_mu_unlock(&resource_user->mu); - ru_unref_by(resource_user, (gpr_atm)size); + ru_unref_by(resource_user, static_cast(size)); } void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user, diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc index ac97af4dee..06f080376a 100644 --- a/src/core/lib/iomgr/sockaddr_utils.cc +++ b/src/core/lib/iomgr/sockaddr_utils.cc @@ -39,13 +39,13 @@ static const uint8_t kV4MappedPrefix[] = {0, 0, 0, 0, 0, 0, int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr4_out) { GPR_ASSERT(resolved_addr != resolved_addr4_out); - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); struct sockaddr_in* addr4_out = resolved_addr4_out == nullptr ? nullptr - : (struct sockaddr_in*)resolved_addr4_out->addr; + : reinterpret_cast(resolved_addr4_out->addr); if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr; + const struct sockaddr_in6* addr6 = reinterpret_cast(addr); if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix, sizeof(kV4MappedPrefix)) == 0) { if (resolved_addr4_out != nullptr) { @@ -66,11 +66,11 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, int grpc_sockaddr_to_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr6_out) { GPR_ASSERT(resolved_addr != resolved_addr6_out); - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); struct sockaddr_in6* addr6_out = - (struct sockaddr_in6*)resolved_addr6_out->addr; + reinterpret_cast(resolved_addr6_out->addr); if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = (const struct sockaddr_in*)addr; + const struct sockaddr_in* addr4 = reinterpret_cast(addr); memset(resolved_addr6_out, 0, sizeof(*resolved_addr6_out)); addr6_out->sin6_family = AF_INET6; memcpy(&addr6_out->sin6_addr.s6_addr[0], kV4MappedPrefix, 12); @@ -89,10 +89,10 @@ int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr, if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr4_normalized)) { resolved_addr = &addr4_normalized; } - addr = (const struct sockaddr*)resolved_addr->addr; + addr = reinterpret_cast(resolved_addr->addr); if (addr->sa_family == AF_INET) { /* Check for 0.0.0.0 */ - const struct sockaddr_in* addr4 = (const struct sockaddr_in*)addr; + const struct sockaddr_in* addr4 = reinterpret_cast(addr); if (addr4->sin_addr.s_addr != 0) { return 0; } @@ -100,7 +100,7 @@ int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr, return 1; } else if (addr->sa_family == AF_INET6) { /* Check for :: */ - const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr; + const struct sockaddr_in6* addr6 = reinterpret_cast(addr); int i; for (i = 0; i < 16; i++) { if (addr6->sin6_addr.s6_addr[i] != 0) { @@ -122,21 +122,21 @@ void grpc_sockaddr_make_wildcards(int port, grpc_resolved_address* wild4_out, void grpc_sockaddr_make_wildcard4(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in* wild_out = (struct sockaddr_in*)resolved_wild_out->addr; + struct sockaddr_in* wild_out = reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); wild_out->sin_family = AF_INET; - wild_out->sin_port = htons((uint16_t)port); + wild_out->sin_port = htons(static_cast(port)); resolved_wild_out->len = sizeof(struct sockaddr_in); } void grpc_sockaddr_make_wildcard6(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in6* wild_out = (struct sockaddr_in6*)resolved_wild_out->addr; + struct sockaddr_in6* wild_out = reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); wild_out->sin6_family = AF_INET6; - wild_out->sin6_port = htons((uint16_t)port); + wild_out->sin6_port = htons(static_cast(port)); resolved_wild_out->len = sizeof(struct sockaddr_in6); } @@ -156,13 +156,13 @@ int grpc_sockaddr_to_string(char** out, if (normalize && grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) { resolved_addr = &addr_normalized; } - addr = (const struct sockaddr*)resolved_addr->addr; + addr = reinterpret_cast(resolved_addr->addr); if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = (const struct sockaddr_in*)addr; + const struct sockaddr_in* addr4 = reinterpret_cast(addr); ip = &addr4->sin_addr; port = ntohs(addr4->sin_port); } else if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr; + const struct sockaddr_in6* addr6 = reinterpret_cast(addr); ip = &addr6->sin6_addr; port = ntohs(addr6->sin6_port); sin6_scope_id = addr6->sin6_scope_id; @@ -208,7 +208,7 @@ char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) { const char* grpc_sockaddr_get_uri_scheme( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case AF_INET: return "ipv4"; @@ -221,12 +221,12 @@ const char* grpc_sockaddr_get_uri_scheme( } int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); return addr->sa_family; } int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case AF_INET: return ntohs(((struct sockaddr_in*)addr)->sin_port); @@ -244,15 +244,15 @@ int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { int grpc_sockaddr_set_port(const grpc_resolved_address* resolved_addr, int port) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case AF_INET: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in*)addr)->sin_port = htons((uint16_t)port); + ((struct sockaddr_in*)addr)->sin_port = htons(static_cast(port)); return 1; case AF_INET6: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in6*)addr)->sin6_port = htons((uint16_t)port); + ((struct sockaddr_in6*)addr)->sin6_port = htons(static_cast(port)); return 1; default: gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", diff --git a/src/core/lib/iomgr/socket_factory_posix.cc b/src/core/lib/iomgr/socket_factory_posix.cc index 1c1b2fb270..3e696c2e10 100644 --- a/src/core/lib/iomgr/socket_factory_posix.cc +++ b/src/core/lib/iomgr/socket_factory_posix.cc @@ -69,16 +69,16 @@ void grpc_socket_factory_unref(grpc_socket_factory* factory) { } static void* socket_factory_arg_copy(void* p) { - return grpc_socket_factory_ref((grpc_socket_factory*)p); + return grpc_socket_factory_ref(static_cast(p)); } static void socket_factory_arg_destroy(void* p) { - grpc_socket_factory_unref((grpc_socket_factory*)p); + grpc_socket_factory_unref(static_cast(p)); } static int socket_factory_cmp(void* a, void* b) { - return grpc_socket_factory_compare((grpc_socket_factory*)a, - (grpc_socket_factory*)b); + return grpc_socket_factory_compare(static_cast(a), + static_cast(b)); } static const grpc_arg_pointer_vtable socket_factory_arg_vtable = { diff --git a/src/core/lib/iomgr/socket_mutator.cc b/src/core/lib/iomgr/socket_mutator.cc index 8c8f0e56e1..eb219d7cb3 100644 --- a/src/core/lib/iomgr/socket_mutator.cc +++ b/src/core/lib/iomgr/socket_mutator.cc @@ -60,16 +60,16 @@ void grpc_socket_mutator_unref(grpc_socket_mutator* mutator) { } static void* socket_mutator_arg_copy(void* p) { - return grpc_socket_mutator_ref((grpc_socket_mutator*)p); + return grpc_socket_mutator_ref(static_cast(p)); } static void socket_mutator_arg_destroy(void* p) { - grpc_socket_mutator_unref((grpc_socket_mutator*)p); + grpc_socket_mutator_unref(static_cast(p)); } static int socket_mutator_cmp(void* a, void* b) { - return grpc_socket_mutator_compare((grpc_socket_mutator*)a, - (grpc_socket_mutator*)b); + return grpc_socket_mutator_compare(static_cast(a), + static_cast(b)); } static const grpc_arg_pointer_vtable socket_mutator_arg_vtable = { diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index d02d77eb02..2668aa6d10 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -218,7 +218,7 @@ static void probe_ipv6_once(void) { memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr[15] = 1; /* [::1]:0 */ - if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) { + if (bind(fd, reinterpret_cast(&addr), sizeof(addr)) == 0) { g_ipv6_loopback_available = 1; } else { gpr_log(GPR_INFO, @@ -278,7 +278,7 @@ static int create_socket(grpc_socket_factory* factory, int domain, int type, grpc_error* grpc_create_dualstack_socket_using_factory( grpc_socket_factory* factory, const grpc_resolved_address* resolved_addr, int type, int protocol, grpc_dualstack_mode* dsmode, int* newfd) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); int family = addr->sa_family; if (family == AF_INET6) { if (grpc_ipv6_loopback_available()) { @@ -310,7 +310,7 @@ grpc_error* grpc_create_dualstack_socket_using_factory( const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { GPR_ASSERT(size <= (socklen_t)-1); - return inet_ntop(af, src, dst, (socklen_t)size); + return inet_ntop(af, src, dst, static_cast(size)); } #endif diff --git a/src/core/lib/iomgr/socket_utils_linux.cc b/src/core/lib/iomgr/socket_utils_linux.cc index 12199c5c89..edb5274e0e 100644 --- a/src/core/lib/iomgr/socket_utils_linux.cc +++ b/src/core/lib/iomgr/socket_utils_linux.cc @@ -35,8 +35,8 @@ int grpc_accept4(int sockfd, grpc_resolved_address* resolved_addr, int nonblock, GPR_ASSERT(resolved_addr->len <= (socklen_t)-1); flags |= nonblock ? SOCK_NONBLOCK : 0; flags |= cloexec ? SOCK_CLOEXEC : 0; - return accept4(sockfd, (struct sockaddr*)resolved_addr->addr, - (socklen_t*)&resolved_addr->len, flags); + return accept4(sockfd, reinterpret_cast(resolved_addr->addr), + reinterpret_cast(&resolved_addr->len), flags); } #endif diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 3dff624065..8d08127915 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -80,7 +80,7 @@ static grpc_error* prepare_socket(const grpc_resolved_address* addr, int fd, if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_SOCKET_MUTATOR)) { GPR_ASSERT(channel_args->args[i].type == GRPC_ARG_POINTER); grpc_socket_mutator* mutator = - (grpc_socket_mutator*)channel_args->args[i].value.pointer.p; + static_cast(channel_args->args[i].value.pointer.p); err = grpc_set_socket_with_mutator(fd, mutator); if (err != GRPC_ERROR_NONE) goto error; } @@ -98,7 +98,7 @@ done: static void tc_on_alarm(void* acp, grpc_error* error) { int done; - async_connect* ac = (async_connect*)acp; + async_connect* ac = static_cast(acp); if (grpc_tcp_trace.enabled()) { const char* str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str, @@ -125,7 +125,7 @@ grpc_endpoint* grpc_tcp_client_create_from_fd( } static void on_writable(void* acp, grpc_error* error) { - async_connect* ac = (async_connect*)acp; + async_connect* ac = static_cast(acp); int so_error = 0; socklen_t so_error_size; int err; @@ -291,7 +291,7 @@ void grpc_tcp_client_create_from_prepared_fd( async_connect* ac; do { GPR_ASSERT(addr->len < ~(socklen_t)0); - err = connect(fd, (const struct sockaddr*)addr->addr, (socklen_t)addr->len); + err = connect(fd, reinterpret_cast(addr->addr), static_cast(addr->len)); } while (err < 0 && errno == EINTR); if (err >= 0) { char* addr_str = grpc_sockaddr_to_uri(addr); @@ -309,7 +309,7 @@ void grpc_tcp_client_create_from_prepared_fd( grpc_pollset_set_add_fd(interested_parties, fdobj); - ac = (async_connect*)gpr_malloc(sizeof(async_connect)); + ac = static_cast(gpr_malloc(sizeof(async_connect))); ac->closure = closure; ac->ep = ep; ac->fd = fdobj; diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index e78e19761a..71819adaba 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -116,7 +116,7 @@ static void tcp_drop_uncovered_then_handle_write(void* arg /* grpc_tcp */, grpc_error* error); static void done_poller(void* bp, grpc_error* error_ignored) { - backup_poller* p = (backup_poller*)bp; + backup_poller* p = static_cast(bp); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p); } @@ -125,7 +125,7 @@ static void done_poller(void* bp, grpc_error* error_ignored) { } static void run_poller(void* bp, grpc_error* error_ignored) { - backup_poller* p = (backup_poller*)bp; + backup_poller* p = static_cast(bp); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); } @@ -165,8 +165,8 @@ static void drop_uncovered(grpc_tcp* tcp) { gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1); if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, (int)old_count, - (int)old_count - 1); + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, static_cast(old_count), + static_cast(old_count) - 1); } GPR_ASSERT(old_count != 1); } @@ -176,12 +176,12 @@ static void cover_self(grpc_tcp* tcp) { gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2); if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", (int)old_count, - 2 + (int)old_count); + gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", static_cast(old_count), + 2 + static_cast(old_count)); } if (old_count == 0) { GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(); - p = (backup_poller*)gpr_zalloc(sizeof(*p) + grpc_pollset_size()); + p = static_cast(gpr_zalloc(sizeof(*p) + grpc_pollset_size())); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p); } @@ -230,12 +230,12 @@ static void tcp_drop_uncovered_then_handle_write(void* arg, grpc_error* error) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error)); } - drop_uncovered((grpc_tcp*)arg); + drop_uncovered(static_cast(arg)); tcp_handle_write(arg, error); } static void add_to_estimate(grpc_tcp* tcp, size_t bytes) { - tcp->bytes_read_this_round += (double)bytes; + tcp->bytes_read_this_round += static_cast(bytes); } static void finish_estimate(grpc_tcp* tcp) { @@ -257,10 +257,10 @@ static size_t get_target_read_size(grpc_tcp* tcp) { double pressure = grpc_resource_quota_get_memory_pressure(rq); double target = tcp->target_length * (pressure > 0.8 ? (1.0 - pressure) / 0.2 : 1.0); - size_t sz = (((size_t)GPR_CLAMP(target, tcp->min_read_chunk_size, + size_t sz = ((static_castGPR_CLAMP(target, tcp->min_read_chunk_size, tcp->max_read_chunk_size)) + 255) & - ~(size_t)255; + ~static_cast(255); /* don't use more than 1/16th of the overall resource quota for a single read * alloc */ size_t rqmax = grpc_resource_quota_peek_size(rq); @@ -285,7 +285,7 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error); static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error); static void tcp_shutdown(grpc_endpoint* ep, grpc_error* why) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); grpc_fd_shutdown(tcp->em_fd, why); grpc_resource_user_shutdown(tcp->resource_user); } @@ -339,7 +339,7 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } static void tcp_destroy(grpc_endpoint* ep) { grpc_network_status_unregister_endpoint(ep); - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); TCP_UNREF(tcp, "destroy"); } @@ -385,7 +385,7 @@ static void tcp_do_read(grpc_tcp* tcp) { msg.msg_name = nullptr; msg.msg_namelen = 0; msg.msg_iov = iov; - msg.msg_iovlen = (msg_iovlen_type)tcp->incoming_buffer->count; + msg.msg_iovlen = static_cast(tcp->incoming_buffer->count); msg.msg_control = nullptr; msg.msg_controllen = 0; msg.msg_flags = 0; @@ -421,12 +421,12 @@ static void tcp_do_read(grpc_tcp* tcp) { TCP_UNREF(tcp, "read"); } else { GRPC_STATS_INC_TCP_READ_SIZE(read_bytes); - add_to_estimate(tcp, (size_t)read_bytes); + add_to_estimate(tcp, static_cast(read_bytes)); GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length); - if ((size_t)read_bytes < tcp->incoming_buffer->length) { + if (static_cast(read_bytes) < tcp->incoming_buffer->length) { grpc_slice_buffer_trim_end( tcp->incoming_buffer, - tcp->incoming_buffer->length - (size_t)read_bytes, + tcp->incoming_buffer->length - static_cast(read_bytes), &tcp->last_read_buffer); } GPR_ASSERT((size_t)read_bytes == tcp->incoming_buffer->length); @@ -436,7 +436,7 @@ static void tcp_do_read(grpc_tcp* tcp) { } static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { - grpc_tcp* tcp = (grpc_tcp*)tcpp; + grpc_tcp* tcp = static_cast(tcpp); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, grpc_error_string(error)); @@ -469,7 +469,7 @@ static void tcp_continue_read(grpc_tcp* tcp) { } static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) { - grpc_tcp* tcp = (grpc_tcp*)arg; + grpc_tcp* tcp = static_cast(arg); GPR_ASSERT(!tcp->finished_edge); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p got_read: %s", tcp, grpc_error_string(error)); @@ -487,7 +487,7 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) { static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer, grpc_closure* cb) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); GPR_ASSERT(tcp->read_cb == nullptr); tcp->read_cb = cb; tcp->incoming_buffer = incoming_buffer; @@ -578,7 +578,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) { } GPR_ASSERT(tcp->outgoing_byte_idx == 0); - trailing = sending_length - (size_t)sent_length; + trailing = sending_length - static_cast(sent_length); while (trailing > 0) { size_t slice_length; @@ -602,7 +602,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) { } static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) { - grpc_tcp* tcp = (grpc_tcp*)arg; + grpc_tcp* tcp = static_cast(arg); grpc_closure* cb; if (error != GRPC_ERROR_NONE) { @@ -634,7 +634,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) { static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, grpc_closure* cb) { GPR_TIMER_SCOPE("tcp_write", 0); - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); grpc_error* error = GRPC_ERROR_NONE; if (grpc_tcp_trace.enabled()) { @@ -678,34 +678,34 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, } static void tcp_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); grpc_pollset_add_fd(pollset, tcp->em_fd); } static void tcp_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); grpc_pollset_set_add_fd(pollset_set, tcp->em_fd); } static void tcp_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); grpc_pollset_set_del_fd(pollset_set, tcp->em_fd); } static char* tcp_get_peer(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); return gpr_strdup(tcp->peer_string); } static int tcp_get_fd(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); return tcp->fd; } static grpc_resource_user* tcp_get_resource_user(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); return tcp->resource_user; } @@ -733,19 +733,19 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) { - grpc_integer_options options = {(int)tcp_read_chunk_size, 1, + grpc_integer_options options = {tcp_read_chunk_size, 1, MAX_CHUNK_SIZE}; tcp_read_chunk_size = grpc_channel_arg_get_integer(&channel_args->args[i], options); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE)) { - grpc_integer_options options = {(int)tcp_read_chunk_size, 1, + grpc_integer_options options = {tcp_read_chunk_size, 1, MAX_CHUNK_SIZE}; tcp_min_read_chunk_size = grpc_channel_arg_get_integer(&channel_args->args[i], options); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE)) { - grpc_integer_options options = {(int)tcp_read_chunk_size, 1, + grpc_integer_options options = {tcp_read_chunk_size, 1, MAX_CHUNK_SIZE}; tcp_max_read_chunk_size = grpc_channel_arg_get_integer(&channel_args->args[i], options); @@ -753,7 +753,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { grpc_resource_quota_unref_internal(resource_quota); resource_quota = grpc_resource_quota_ref_internal( - (grpc_resource_quota*)channel_args->args[i].value.pointer.p); + static_cast(channel_args->args[i].value.pointer.p)); } } } @@ -764,7 +764,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, tcp_read_chunk_size = GPR_CLAMP(tcp_read_chunk_size, tcp_min_read_chunk_size, tcp_max_read_chunk_size); - grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); + grpc_tcp* tcp = static_cast(gpr_malloc(sizeof(grpc_tcp))); tcp->base.vtable = &vtable; tcp->peer_string = gpr_strdup(peer_string); tcp->fd = grpc_fd_wrapped_fd(em_fd); @@ -773,7 +773,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, tcp->release_fd_cb = nullptr; tcp->release_fd = nullptr; tcp->incoming_buffer = nullptr; - tcp->target_length = (double)tcp_read_chunk_size; + tcp->target_length = static_cast(tcp_read_chunk_size); tcp->min_read_chunk_size = tcp_min_read_chunk_size; tcp->max_read_chunk_size = tcp_max_read_chunk_size; tcp->bytes_read_this_round = 0; @@ -794,7 +794,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, } int grpc_tcp_fd(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); GPR_ASSERT(ep->vtable == &vtable); return grpc_fd_wrapped_fd(tcp->em_fd); } @@ -802,7 +802,7 @@ int grpc_tcp_fd(grpc_endpoint* ep) { void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd, grpc_closure* done) { grpc_network_status_unregister_endpoint(ep); - grpc_tcp* tcp = (grpc_tcp*)ep; + grpc_tcp* tcp = reinterpret_cast(ep); GPR_ASSERT(ep->vtable == &vtable); tcp->release_fd = fd; tcp->release_fd_cb = done; diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index 89d9160e02..f8f94e3fbb 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -72,7 +72,7 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, grpc_tcp_server** server) { gpr_once_init(&check_init, init); - grpc_tcp_server* s = (grpc_tcp_server*)gpr_zalloc(sizeof(grpc_tcp_server)); + grpc_tcp_server* s = static_cast(gpr_zalloc(sizeof(grpc_tcp_server))); s->so_reuseport = has_so_reuseport; s->expand_wildcard_addrs = false; for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) { @@ -135,7 +135,7 @@ static void finish_shutdown(grpc_tcp_server* s) { } static void destroyed_port(void* server, grpc_error* error) { - grpc_tcp_server* s = (grpc_tcp_server*)server; + grpc_tcp_server* s = static_cast(server); gpr_mu_lock(&s->mu); s->destroyed_ports++; if (s->destroyed_ports == s->nports) { @@ -194,15 +194,15 @@ static void tcp_server_destroy(grpc_tcp_server* s) { /* event manager callback when reads are ready */ static void on_read(void* arg, grpc_error* err) { - grpc_tcp_listener* sp = (grpc_tcp_listener*)arg; + grpc_tcp_listener* sp = static_cast(arg); grpc_pollset* read_notifier_pollset; if (err != GRPC_ERROR_NONE) { goto error; } read_notifier_pollset = - sp->server->pollsets[(size_t)gpr_atm_no_barrier_fetch_add( - &sp->server->next_pollset_to_assign, 1) % + sp->server->pollsets[static_cast(gpr_atm_no_barrier_fetch_add( + &sp->server->next_pollset_to_assign, 1)) % sp->server->pollset_count]; /* loop until accept4 returns EAGAIN, and then re-arm notification */ @@ -249,7 +249,7 @@ static void on_read(void* arg, grpc_error* err) { // Create acceptor. grpc_tcp_server_acceptor* acceptor = - (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); + static_cast(gpr_malloc(sizeof(*acceptor))); acceptor->from_server = sp->server; acceptor->port_index = sp->port_index; acceptor->fd_index = sp->fd_index; @@ -363,7 +363,7 @@ static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) { listener->server->nports++; grpc_sockaddr_to_string(&addr_str, &listener->addr, 1); gpr_asprintf(&name, "tcp-server-listener:%s/clone-%d", addr_str, i); - sp = (grpc_tcp_listener*)gpr_malloc(sizeof(grpc_tcp_listener)); + sp = static_cast(gpr_malloc(sizeof(grpc_tcp_listener))); sp->next = listener->next; listener->next = sp; /* sp (the new listener) is a sibling of 'listener' (the original @@ -410,8 +410,8 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, if (requested_port == 0) { for (sp = s->head; sp; sp = sp->next) { sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == getsockname(sp->fd, (struct sockaddr*)&sockname_temp.addr, - (socklen_t*)&sockname_temp.len)) { + if (0 == getsockname(sp->fd, reinterpret_cast(&sockname_temp.addr), + reinterpret_cast(&sockname_temp.len))) { int used_port = grpc_sockaddr_get_port(&sockname_temp); if (used_port > 0) { memcpy(&sockname_temp, addr, sizeof(grpc_resolved_address)); diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index 5139760634..db8ccf02eb 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -56,7 +56,7 @@ static void init_max_accept_queue_size(void) { char* end; long i = strtol(buf, &end, 10); if (i > 0 && i <= INT_MAX && end && *end == '\n') { - n = (int)i; + n = static_cast(i); } } fclose(fp); @@ -93,7 +93,7 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd, gpr_mu_lock(&s->mu); s->nports++; GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); - sp = (grpc_tcp_listener*)gpr_malloc(sizeof(grpc_tcp_listener)); + sp = static_cast(gpr_malloc(sizeof(grpc_tcp_listener))); sp->next = nullptr; if (s->head == nullptr) { s->head = sp; @@ -169,7 +169,7 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd, if (err != GRPC_ERROR_NONE) goto error; GPR_ASSERT(addr->len < ~(socklen_t)0); - if (bind(fd, (struct sockaddr*)addr->addr, (socklen_t)addr->len) < 0) { + if (bind(fd, reinterpret_cast(addr->addr), static_cast(addr->len)) < 0) { err = GRPC_OS_ERROR(errno, "bind"); goto error; } @@ -181,8 +181,8 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd, sockname_temp.len = sizeof(struct sockaddr_storage); - if (getsockname(fd, (struct sockaddr*)sockname_temp.addr, - (socklen_t*)&sockname_temp.len) < 0) { + if (getsockname(fd, reinterpret_cast(sockname_temp.addr), + reinterpret_cast(&sockname_temp.len)) < 0) { err = GRPC_OS_ERROR(errno, "getsockname"); goto error; } diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index 227bf94aa7..5470dbcff7 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -66,12 +66,12 @@ static grpc_error* get_unused_port(int* port) { if (dsmode == GRPC_DSMODE_IPV4) { grpc_sockaddr_make_wildcard4(0, &wild); } - if (bind(fd, (const struct sockaddr*)wild.addr, (socklen_t)wild.len) != 0) { + if (bind(fd, reinterpret_cast(wild.addr), static_cast(wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "bind"); close(fd); return err; } - if (getsockname(fd, (struct sockaddr*)wild.addr, (socklen_t*)&wild.len) != + if (getsockname(fd, reinterpret_cast(wild.addr), reinterpret_cast(&wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "getsockname"); close(fd); diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index ef86d237d3..b47c12b689 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -240,9 +240,9 @@ void grpc_timer_list_init() { uint32_t i; g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores()); - g_shards = (timer_shard*)gpr_zalloc(g_num_shards * sizeof(*g_shards)); + g_shards = static_cast(gpr_zalloc(g_num_shards * sizeof(*g_shards))); g_shard_queue = - (timer_shard**)gpr_zalloc(g_num_shards * sizeof(*g_shard_queue)); + static_cast(gpr_zalloc(g_num_shards * sizeof(*g_shard_queue))); g_shared_mutables.initialized = true; g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER; @@ -360,7 +360,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, } grpc_time_averaged_stats_add_sample(&shard->stats, - (double)(deadline - now) / 1000.0); + static_cast(deadline - now) / 1000.0); ADD_TO_HASH_TABLE(timer); @@ -374,7 +374,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, gpr_log(GPR_DEBUG, " .. add to shard %d with queue_deadline_cap=%" PRIdPTR " => is_first_timer=%s", - (int)(shard - g_shards), shard->queue_deadline_cap, + static_cast(shard - g_shards), shard->queue_deadline_cap, is_first_timer ? "true" : "false"); } gpr_mu_unlock(&shard->mu); @@ -461,11 +461,11 @@ static int refill_heap(timer_shard* shard, gpr_atm now) { /* Compute the new cap and put all timers under it into the queue: */ shard->queue_deadline_cap = saturating_add(GPR_MAX(now, shard->queue_deadline_cap), - (gpr_atm)(deadline_delta * 1000.0)); + static_cast(deadline_delta * 1000.0)); if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. shard[%d]->queue_deadline_cap --> %" PRIdPTR, - (int)(shard - g_shards), shard->queue_deadline_cap); + static_cast(shard - g_shards), shard->queue_deadline_cap); } for (timer = shard->list.next; timer != &shard->list; timer = next) { next = timer->next; @@ -490,7 +490,7 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { for (;;) { if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. shard[%d]: heap_empty=%s", - (int)(shard - g_shards), + static_cast(shard - g_shards), grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); } if (grpc_timer_heap_is_empty(&shard->heap)) { @@ -530,7 +530,7 @@ static size_t pop_timers(timer_shard* shard, gpr_atm now, gpr_mu_unlock(&shard->mu); if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. shard[%d] popped %" PRIdPTR, - (int)(shard - g_shards), n); + static_cast(shard - g_shards), n); } return n; } @@ -553,7 +553,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. shard[%d]->min_deadline = %" PRIdPTR, - (int)(g_shard_queue[0] - g_shards), + static_cast(g_shard_queue[0] - g_shards), g_shard_queue[0]->min_deadline); } @@ -573,7 +573,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, " .. result --> %d" ", shard[%d]->min_deadline %" PRIdPTR " --> %" PRIdPTR ", now=%" PRIdPTR, - result, (int)(g_shard_queue[0] - g_shards), + result, static_cast(g_shard_queue[0] - g_shards), g_shard_queue[0]->min_deadline, new_min_deadline, now); } diff --git a/src/core/lib/iomgr/timer_heap.cc b/src/core/lib/iomgr/timer_heap.cc index 632928fafa..9aedfd3755 100644 --- a/src/core/lib/iomgr/timer_heap.cc +++ b/src/core/lib/iomgr/timer_heap.cc @@ -35,7 +35,7 @@ its argument. */ static void adjust_upwards(grpc_timer** first, uint32_t i, grpc_timer* t) { while (i > 0) { - uint32_t parent = (uint32_t)(((int)i - 1) / 2); + uint32_t parent = static_cast((static_cast(i) - 1) / 2); if (first[parent]->deadline <= t->deadline) break; first[i] = first[parent]; first[i]->heap_index = i; @@ -74,14 +74,14 @@ static void maybe_shrink(grpc_timer_heap* heap) { if (heap->timer_count >= 8 && heap->timer_count <= heap->timer_capacity / SHRINK_FULLNESS_FACTOR / 2) { heap->timer_capacity = heap->timer_count * SHRINK_FULLNESS_FACTOR; - heap->timers = (grpc_timer**)gpr_realloc( - heap->timers, heap->timer_capacity * sizeof(grpc_timer*)); + heap->timers = static_cast(gpr_realloc( + heap->timers, heap->timer_capacity * sizeof(grpc_timer*))); } } static void note_changed_priority(grpc_timer_heap* heap, grpc_timer* timer) { uint32_t i = timer->heap_index; - uint32_t parent = (uint32_t)(((int)i - 1) / 2); + uint32_t parent = static_cast((static_cast(i) - 1) / 2); if (heap->timers[parent]->deadline > timer->deadline) { adjust_upwards(heap->timers, i, timer); } else { @@ -99,8 +99,8 @@ int grpc_timer_heap_add(grpc_timer_heap* heap, grpc_timer* timer) { if (heap->timer_count == heap->timer_capacity) { heap->timer_capacity = GPR_MAX(heap->timer_capacity + 1, heap->timer_capacity * 3 / 2); - heap->timers = (grpc_timer**)gpr_realloc( - heap->timers, heap->timer_capacity * sizeof(grpc_timer*)); + heap->timers = static_cast(gpr_realloc( + heap->timers, heap->timer_capacity * sizeof(grpc_timer*))); } timer->heap_index = heap->timer_count; adjust_upwards(heap->timers, heap->timer_count, timer); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 7fb068f10f..4cefb7fc9f 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -86,7 +86,7 @@ static void start_timer_thread_and_unlock(void) { } gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - completed_thread* ct = (completed_thread*)gpr_malloc(sizeof(*ct)); + completed_thread* ct = static_cast(gpr_malloc(sizeof(*ct))); // The call to gpr_thd_new() has to be under the same lock used by // gc_completed_threads(), particularly due to ct->t, which is written here // (internally by gpr_thd_new) and read there. Otherwise it's possible for ct @@ -276,7 +276,7 @@ static void timer_thread(void* completed_thread_ptr) { grpc_core::ExecCtx exec_ctx(0); timer_main_loop(); - timer_thread_cleanup((completed_thread*)completed_thread_ptr); + timer_thread_cleanup(static_cast(completed_thread_ptr)); } static void start_threads(void) { diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index 27d32c59ae..0d052dc166 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -132,14 +132,14 @@ static grpc_socket_factory* get_socket_factory(const grpc_channel_args* args) { const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_SOCKET_FACTORY); if (arg) { GPR_ASSERT(arg->type == GRPC_ARG_POINTER); - return (grpc_socket_factory*)arg->value.pointer.p; + return static_cast(arg->value.pointer.p); } } return nullptr; } grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { - grpc_udp_server* s = (grpc_udp_server*)gpr_malloc(sizeof(grpc_udp_server)); + grpc_udp_server* s = static_cast(gpr_malloc(sizeof(grpc_udp_server))); gpr_mu_init(&s->mu); s->socket_factory = get_socket_factory(args); if (s->socket_factory) { @@ -156,7 +156,7 @@ grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { } static void shutdown_fd(void* args, grpc_error* error) { - struct shutdown_fd_args* shutdown_args = (struct shutdown_fd_args*)args; + struct shutdown_fd_args* shutdown_args = static_cast(args); grpc_udp_listener* sp = shutdown_args->sp; gpr_log(GPR_DEBUG, "shutdown fd %d", sp->fd); gpr_mu_lock(shutdown_args->server_mu); @@ -198,7 +198,7 @@ static void finish_shutdown(grpc_udp_server* s) { } static void destroyed_port(void* server, grpc_error* error) { - grpc_udp_server* s = (grpc_udp_server*)server; + grpc_udp_server* s = static_cast(server); gpr_mu_lock(&s->mu); s->destroyed_ports++; if (s->destroyed_ports == s->nports) { @@ -260,7 +260,7 @@ void grpc_udp_server_destroy(grpc_udp_server* s, grpc_closure* on_done) { for (sp = s->head; sp; sp = sp->next) { GPR_ASSERT(sp->orphan_cb); struct shutdown_fd_args* args = - (struct shutdown_fd_args*)gpr_malloc(sizeof(*args)); + static_cast(gpr_malloc(sizeof(*args))); args->sp = sp; args->server_mu = &s->mu; GRPC_CLOSURE_INIT(&sp->orphan_fd_closure, shutdown_fd, args, @@ -279,7 +279,7 @@ static int bind_socket(grpc_socket_factory* socket_factory, int sockfd, const grpc_resolved_address* addr) { return (socket_factory != nullptr) ? grpc_socket_factory_bind(socket_factory, sockfd, addr) - : bind(sockfd, (struct sockaddr*)addr->addr, (socklen_t)addr->len); + : bind(sockfd, reinterpret_cast(addr->addr), static_cast(addr->len)); } /* Prepare a recently-created socket for listening. */ @@ -287,7 +287,7 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, const grpc_resolved_address* addr, int rcv_buf_size, int snd_buf_size) { grpc_resolved_address sockname_temp; - struct sockaddr* addr_ptr = (struct sockaddr*)addr->addr; + struct sockaddr* addr_ptr = reinterpret_cast(addr->addr); if (fd < 0) { goto error; @@ -323,8 +323,8 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, sockname_temp.len = sizeof(struct sockaddr_storage); - if (getsockname(fd, (struct sockaddr*)sockname_temp.addr, - (socklen_t*)&sockname_temp.len) < 0) { + if (getsockname(fd, reinterpret_cast(sockname_temp.addr), + reinterpret_cast(&sockname_temp.len)) < 0) { goto error; } @@ -379,7 +379,7 @@ static void do_read(void* arg, grpc_error* error) { /* event manager callback when reads are ready */ static void on_read(void* arg, grpc_error* error) { - grpc_udp_listener* sp = (grpc_udp_listener*)arg; + grpc_udp_listener* sp = static_cast(arg); gpr_mu_lock(&sp->server->mu); if (error != GRPC_ERROR_NONE) { @@ -438,7 +438,7 @@ static void do_write(void* arg, grpc_error* error) { } static void on_write(void* arg, grpc_error* error) { - grpc_udp_listener* sp = (grpc_udp_listener*)arg; + grpc_udp_listener* sp = static_cast(arg); gpr_mu_lock(&sp->server->mu); if (error != GRPC_ERROR_NONE) { @@ -479,7 +479,7 @@ static int add_socket_to_server(grpc_udp_server* s, int fd, gpr_free(addr_str); gpr_mu_lock(&s->mu); s->nports++; - sp = (grpc_udp_listener*)gpr_malloc(sizeof(grpc_udp_listener)); + sp = static_cast(gpr_malloc(sizeof(grpc_udp_listener))); sp->next = nullptr; if (s->head == nullptr) { s->head = sp; @@ -530,12 +530,12 @@ int grpc_udp_server_add_port(grpc_udp_server* s, if (grpc_sockaddr_get_port(addr) == 0) { for (sp = s->head; sp; sp = sp->next) { sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == getsockname(sp->fd, (struct sockaddr*)sockname_temp.addr, - (socklen_t*)&sockname_temp.len)) { + if (0 == getsockname(sp->fd, reinterpret_cast(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)); + 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; diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 91b7cb1e59..7365787c71 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -52,11 +52,11 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name, return err; } *addrs = - (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses)); + static_cast(gpr_malloc(sizeof(grpc_resolved_addresses))); (*addrs)->naddrs = 1; (*addrs)->addrs = - (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address)); - un = (struct sockaddr_un*)(*addrs)->addrs->addr; + static_cast(gpr_malloc(sizeof(grpc_resolved_address))); + un = reinterpret_cast((*addrs)->addrs->addr); un->sun_family = AF_UNIX; strncpy(un->sun_path, name, sizeof(un->sun_path)); (*addrs)->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; @@ -64,17 +64,17 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name, } int grpc_is_unix_socket(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); return addr->sa_family == AF_UNIX; } void grpc_unlink_if_unix_domain_socket( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return; } - struct sockaddr_un* un = (struct sockaddr_un*)resolved_addr->addr; + struct sockaddr_un* un = reinterpret_cast(resolved_addr->addr); struct stat st; if (stat(un->sun_path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) { @@ -84,7 +84,7 @@ void grpc_unlink_if_unix_domain_socket( char* grpc_sockaddr_to_uri_unix_if_possible( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; + const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return nullptr; } diff --git a/src/core/lib/iomgr/wakeup_fd_cv.cc b/src/core/lib/iomgr/wakeup_fd_cv.cc index 4818cafe3d..80f07ccf23 100644 --- a/src/core/lib/iomgr/wakeup_fd_cv.cc +++ b/src/core/lib/iomgr/wakeup_fd_cv.cc @@ -43,8 +43,8 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) { gpr_mu_lock(&g_cvfds.mu); if (!g_cvfds.free_fds) { newsize = GPR_MIN(g_cvfds.size * 2, g_cvfds.size + MAX_TABLE_RESIZE); - g_cvfds.cvfds = (grpc_fd_node*)gpr_realloc(g_cvfds.cvfds, - sizeof(grpc_fd_node) * newsize); + g_cvfds.cvfds = static_cast(gpr_realloc(g_cvfds.cvfds, + sizeof(grpc_fd_node) * newsize)); for (i = g_cvfds.size; i < newsize; i++) { g_cvfds.cvfds[i].is_set = 0; g_cvfds.cvfds[i].cvs = nullptr; @@ -54,7 +54,7 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) { g_cvfds.size = newsize; } - idx = (int)(g_cvfds.free_fds - g_cvfds.cvfds); + idx = static_cast(g_cvfds.free_fds - g_cvfds.cvfds); g_cvfds.free_fds = g_cvfds.free_fds->next_free; g_cvfds.cvfds[idx].cvs = nullptr; g_cvfds.cvfds[idx].is_set = 0; diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc index 4ad51f662a..adf35b9088 100644 --- a/src/core/lib/json/json.cc +++ b/src/core/lib/json/json.cc @@ -23,7 +23,7 @@ #include "src/core/lib/json/json.h" grpc_json* grpc_json_create(grpc_json_type type) { - grpc_json* json = (grpc_json*)gpr_zalloc(sizeof(*json)); + grpc_json* json = static_cast(gpr_zalloc(sizeof(*json))); json->type = type; return json; diff --git a/src/core/lib/json/json_reader.cc b/src/core/lib/json/json_reader.cc index 30039419b1..019214a167 100644 --- a/src/core/lib/json/json_reader.cc +++ b/src/core/lib/json/json_reader.cc @@ -138,7 +138,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { case GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL: case GRPC_JSON_STATE_VALUE_NUMBER_ZERO: case GRPC_JSON_STATE_VALUE_NUMBER_EPM: - success = (uint32_t)json_reader_set_number(reader); + success = static_cast(json_reader_set_number(reader)); if (!success) return GRPC_JSON_PARSE_ERROR; json_reader_string_clear(reader); reader->state = GRPC_JSON_STATE_VALUE_END; @@ -173,7 +173,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { } else if ((c == ']') && !reader->in_array) { return GRPC_JSON_PARSE_ERROR; } - success = (uint32_t)json_reader_set_number(reader); + success = static_cast(json_reader_set_number(reader)); if (!success) return GRPC_JSON_PARSE_ERROR; json_reader_string_clear(reader); reader->state = GRPC_JSON_STATE_VALUE_END; @@ -417,8 +417,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { } else { return GRPC_JSON_PARSE_ERROR; } - reader->unicode_char = (uint16_t)(reader->unicode_char << 4); - reader->unicode_char = (uint16_t)(reader->unicode_char | c); + reader->unicode_char = static_cast(reader->unicode_char << 4); + reader->unicode_char = static_cast(reader->unicode_char | c); switch (reader->state) { case GRPC_JSON_STATE_STRING_ESCAPE_U1: @@ -445,9 +445,9 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { if (reader->unicode_high_surrogate == 0) return GRPC_JSON_PARSE_ERROR; utf32 = 0x10000; - utf32 += (uint32_t)( + utf32 += static_cast( (reader->unicode_high_surrogate - 0xd800) * 0x400); - utf32 += (uint32_t)(reader->unicode_char - 0xdc00); + utf32 += static_cast(reader->unicode_char - 0xdc00); json_reader_string_add_utf32(reader, utf32); reader->unicode_high_surrogate = 0; } else { diff --git a/src/core/lib/json/json_string.cc b/src/core/lib/json/json_string.cc index a339eec81b..dcaf11d0c9 100644 --- a/src/core/lib/json/json_string.cc +++ b/src/core/lib/json/json_string.cc @@ -63,19 +63,19 @@ typedef struct { * bytes at a time (or multiples thereof). */ static void json_writer_output_check(void* userdata, size_t needed) { - json_writer_userdata* state = (json_writer_userdata*)userdata; + json_writer_userdata* state = static_cast(userdata); if (state->free_space >= needed) return; needed -= state->free_space; /* Round up by 256 bytes. */ needed = (needed + 0xff) & ~0xffU; - state->output = (char*)gpr_realloc(state->output, state->allocated + needed); + state->output = static_cast(gpr_realloc(state->output, state->allocated + needed)); state->free_space += needed; state->allocated += needed; } /* These are needed by the writer's implementation. */ static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = (json_writer_userdata*)userdata; + json_writer_userdata* state = static_cast(userdata); json_writer_output_check(userdata, 1); state->output[state->string_len++] = c; state->free_space--; @@ -83,7 +83,7 @@ static void json_writer_output_char(void* userdata, char c) { static void json_writer_output_string_with_len(void* userdata, const char* str, size_t len) { - json_writer_userdata* state = (json_writer_userdata*)userdata; + json_writer_userdata* state = static_cast(userdata); json_writer_output_check(userdata, len); memcpy(state->output + state->string_len, str, len); state->string_len += len; @@ -99,7 +99,7 @@ static void json_writer_output_string(void* userdata, const char* str) { * the end of the current string, and advance our output pointer. */ static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); if (state->string) { GPR_ASSERT(state->string_ptr < state->input); *state->string_ptr++ = 0; @@ -108,10 +108,10 @@ static void json_reader_string_clear(void* userdata) { } static void json_reader_string_add_char(void* userdata, uint32_t c) { - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); GPR_ASSERT(state->string_ptr < state->input); GPR_ASSERT(c <= 0xff); - *state->string_ptr++ = (uint8_t)c; + *state->string_ptr++ = static_cast(c); } /* We are converting a UTF-32 character into UTF-8 here, @@ -149,7 +149,7 @@ static void json_reader_string_add_utf32(void* userdata, uint32_t c) { */ static uint32_t json_reader_read_char(void* userdata) { uint32_t r; - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); if (state->remaining_input == 0) return GRPC_JSON_READ_CHAR_EOF; @@ -168,7 +168,7 @@ static uint32_t json_reader_read_char(void* userdata) { * our tree-in-progress inside our opaque structure. */ static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) { - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); grpc_json* json = grpc_json_create(type); json->parent = state->current_container; @@ -183,7 +183,7 @@ static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) { json->parent->child = json; } if (json->parent->type == GRPC_JSON_OBJECT) { - json->key = (char*)state->key; + json->key = reinterpret_cast(state->key); } } if (!state->top) { @@ -194,7 +194,7 @@ static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) { } static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); grpc_json* container; GPR_ASSERT(type == GRPC_JSON_ARRAY || type == GRPC_JSON_OBJECT); @@ -215,7 +215,7 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) { */ static grpc_json_type json_reader_container_ends(void* userdata) { grpc_json_type container_type = GRPC_JSON_TOP_LEVEL; - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); GPR_ASSERT(state->current_container); @@ -236,20 +236,20 @@ static grpc_json_type json_reader_container_ends(void* userdata) { * We'll keep it as a string, and leave it to the caller to evaluate it. */ static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); state->key = state->string; } static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); grpc_json* json = json_create_and_link(userdata, GRPC_JSON_STRING); - json->value = (char*)state->string; + json->value = reinterpret_cast(state->string); } static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = (json_reader_userdata*)userdata; + json_reader_userdata* state = static_cast(userdata); grpc_json* json = json_create_and_link(userdata, GRPC_JSON_NUMBER); - json->value = (char*)state->string; + json->value = reinterpret_cast(state->string); return 1; } @@ -287,7 +287,7 @@ grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) { state.top = state.current_container = state.current_value = nullptr; state.string = state.key = nullptr; - state.string_ptr = state.input = (uint8_t*)input; + state.string_ptr = state.input = reinterpret_cast(input); state.remaining_input = size; grpc_json_reader_init(&reader, &reader_vtable, &state); diff --git a/src/core/lib/json/json_writer.cc b/src/core/lib/json/json_writer.cc index 0b9c7c30ea..df49cbe4dc 100644 --- a/src/core/lib/json/json_writer.cc +++ b/src/core/lib/json/json_writer.cc @@ -52,7 +52,7 @@ static void json_writer_output_indent(grpc_json_writer* writer) { " " " "; - unsigned spaces = (unsigned)(writer->depth * writer->indent); + unsigned spaces = static_cast(writer->depth * writer->indent); if (writer->indent == 0) return; @@ -64,7 +64,7 @@ static void json_writer_output_indent(grpc_json_writer* writer) { while (spaces >= (sizeof(spacesstr) - 1)) { json_writer_output_string_with_len(writer, spacesstr, sizeof(spacesstr) - 1); - spaces -= (unsigned)(sizeof(spacesstr) - 1); + spaces -= static_cast(sizeof(spacesstr) - 1); } if (spaces == 0) return; @@ -100,12 +100,12 @@ static void json_writer_escape_string(grpc_json_writer* writer, json_writer_output_char(writer, '"'); for (;;) { - uint8_t c = (uint8_t)*string++; + uint8_t c = static_cast(*string++); if (c == 0) { break; } else if ((c >= 32) && (c <= 126)) { if ((c == '\\') || (c == '"')) json_writer_output_char(writer, '\\'); - json_writer_output_char(writer, (char)c); + json_writer_output_char(writer, static_cast(c)); } else if ((c < 32) || (c == 127)) { switch (c) { case '\b': @@ -146,7 +146,7 @@ static void json_writer_escape_string(grpc_json_writer* writer, } for (i = 0; i < extra; i++) { utf32 <<= 6; - c = (uint8_t)(*string++); + c = static_cast(*string++); /* Breaks out and bail on any invalid UTF-8 sequence, including \0. */ if ((c & 0xc0) != 0x80) { valid = 0; @@ -179,10 +179,10 @@ static void json_writer_escape_string(grpc_json_writer* writer, * That range is exactly 20 bits. */ utf32 -= 0x10000; - json_writer_escape_utf16(writer, (uint16_t)(0xd800 | (utf32 >> 10))); - json_writer_escape_utf16(writer, (uint16_t)(0xdc00 | (utf32 & 0x3ff))); + json_writer_escape_utf16(writer, static_cast(0xd800 | (utf32 >> 10))); + json_writer_escape_utf16(writer, static_cast(0xdc00 | (utf32 & 0x3ff))); } else { - json_writer_escape_utf16(writer, (uint16_t)utf32); + json_writer_escape_utf16(writer, static_cast(utf32)); } } } diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 63ec42cf86..cd8fabea28 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -44,8 +44,8 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, gpr_log(GPR_ERROR, "Method is client-side only."); return GRPC_CALL_ERROR_NOT_ON_SERVER; } - ctx = (grpc_client_security_context*)grpc_call_context_get( - call, GRPC_CONTEXT_SECURITY); + ctx = static_cast(grpc_call_context_get( + call, GRPC_CONTEXT_SECURITY)); if (ctx == nullptr) { ctx = grpc_client_security_context_create(); ctx->creds = grpc_call_credentials_ref(creds); @@ -80,13 +80,13 @@ void grpc_auth_context_release(grpc_auth_context* context) { /* --- grpc_client_security_context --- */ grpc_client_security_context* grpc_client_security_context_create(void) { - return (grpc_client_security_context*)gpr_zalloc( - sizeof(grpc_client_security_context)); + return static_cast(gpr_zalloc( + sizeof(grpc_client_security_context))); } void grpc_client_security_context_destroy(void* ctx) { grpc_core::ExecCtx exec_ctx; - grpc_client_security_context* c = (grpc_client_security_context*)ctx; + grpc_client_security_context* c = static_cast(ctx); grpc_call_credentials_unref(c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { @@ -98,12 +98,12 @@ void grpc_client_security_context_destroy(void* ctx) { /* --- grpc_server_security_context --- */ grpc_server_security_context* grpc_server_security_context_create(void) { - return (grpc_server_security_context*)gpr_zalloc( - sizeof(grpc_server_security_context)); + return static_cast(gpr_zalloc( + sizeof(grpc_server_security_context))); } void grpc_server_security_context_destroy(void* ctx) { - grpc_server_security_context* c = (grpc_server_security_context*)ctx; + grpc_server_security_context* c = static_cast(ctx); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context"); if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); @@ -117,7 +117,7 @@ static grpc_auth_property_iterator empty_iterator = {nullptr, 0, nullptr}; grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) { grpc_auth_context* ctx = - (grpc_auth_context*)gpr_zalloc(sizeof(grpc_auth_context)); + static_cast(gpr_zalloc(sizeof(grpc_auth_context))); gpr_ref_init(&ctx->refcount, 1); if (chained != nullptr) { ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained"); @@ -258,9 +258,9 @@ static void ensure_auth_context_capacity(grpc_auth_context* ctx) { if (ctx->properties.count == ctx->properties.capacity) { ctx->properties.capacity = GPR_MAX(ctx->properties.capacity + 8, ctx->properties.capacity * 2); - ctx->properties.array = (grpc_auth_property*)gpr_realloc( + ctx->properties.array = static_cast(gpr_realloc( ctx->properties.array, - ctx->properties.capacity * sizeof(grpc_auth_property)); + ctx->properties.capacity * sizeof(grpc_auth_property))); } } @@ -276,7 +276,7 @@ void grpc_auth_context_add_property(grpc_auth_context* ctx, const char* name, ensure_auth_context_capacity(ctx); prop = &ctx->properties.array[ctx->properties.count++]; prop->name = gpr_strdup(name); - prop->value = (char*)gpr_malloc(value_length + 1); + prop->value = static_cast(gpr_malloc(value_length + 1)); memcpy(prop->value, value, value_length); prop->value[value_length] = '\0'; prop->value_length = value_length; @@ -329,7 +329,7 @@ grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) { GRPC_AUTH_CONTEXT_ARG); return nullptr; } - return (grpc_auth_context*)arg->value.pointer.p; + return static_cast(arg->value.pointer.p); } grpc_auth_context* grpc_find_auth_context_in_args( diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc index e4c1604795..248177a178 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.cc +++ b/src/core/lib/security/credentials/composite/composite_credentials.cc @@ -40,7 +40,7 @@ typedef struct { } grpc_composite_call_credentials_metadata_context; static void composite_call_destruct(grpc_call_credentials* creds) { - grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; + grpc_composite_call_credentials* c = reinterpret_cast(creds); for (size_t i = 0; i < c->inner.num_creds; i++) { grpc_call_credentials_unref(c->inner.creds_array[i]); } @@ -49,7 +49,7 @@ static void composite_call_destruct(grpc_call_credentials* creds) { static void composite_call_metadata_cb(void* arg, grpc_error* error) { grpc_composite_call_credentials_metadata_context* ctx = - (grpc_composite_call_credentials_metadata_context*)arg; + static_cast(arg); if (error == GRPC_ERROR_NONE) { /* See if we need to get some more metadata. */ if (ctx->creds_index < ctx->composite_creds->inner.num_creds) { @@ -75,10 +75,10 @@ static bool composite_call_get_request_metadata( grpc_auth_metadata_context auth_md_context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; + grpc_composite_call_credentials* c = reinterpret_cast(creds); grpc_composite_call_credentials_metadata_context* ctx; - ctx = (grpc_composite_call_credentials_metadata_context*)gpr_zalloc( - sizeof(grpc_composite_call_credentials_metadata_context)); + ctx = static_cast(gpr_zalloc( + sizeof(grpc_composite_call_credentials_metadata_context))); ctx->composite_creds = c; ctx->pollent = pollent; ctx->auth_md_context = auth_md_context; @@ -106,7 +106,7 @@ static bool composite_call_get_request_metadata( static void composite_call_cancel_get_request_metadata( grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_error* error) { - grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; + grpc_composite_call_credentials* c = reinterpret_cast(creds); for (size_t i = 0; i < c->inner.num_creds; ++i) { grpc_call_credentials_cancel_get_request_metadata( c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error)); @@ -145,8 +145,8 @@ grpc_call_credentials* grpc_composite_call_credentials_create( GPR_ASSERT(reserved == nullptr); GPR_ASSERT(creds1 != nullptr); GPR_ASSERT(creds2 != nullptr); - c = (grpc_composite_call_credentials*)gpr_zalloc( - sizeof(grpc_composite_call_credentials)); + c = static_cast(gpr_zalloc( + sizeof(grpc_composite_call_credentials))); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE; c->base.vtable = &composite_call_credentials_vtable; gpr_ref_init(&c->base.refcount, 1); @@ -155,7 +155,7 @@ grpc_call_credentials* grpc_composite_call_credentials_create( c->inner.num_creds = creds1_array.num_creds + creds2_array.num_creds; creds_array_byte_size = c->inner.num_creds * sizeof(grpc_call_credentials*); c->inner.creds_array = - (grpc_call_credentials**)gpr_zalloc(creds_array_byte_size); + static_cast(gpr_zalloc(creds_array_byte_size)); for (i = 0; i < creds1_array.num_creds; i++) { grpc_call_credentials* cur_creds = creds1_array.creds_array[i]; c->inner.creds_array[i] = grpc_call_credentials_ref(cur_creds); @@ -171,7 +171,7 @@ grpc_call_credentials* grpc_composite_call_credentials_create( const grpc_call_credentials_array* grpc_composite_call_credentials_get_credentials(grpc_call_credentials* creds) { const grpc_composite_call_credentials* c = - (const grpc_composite_call_credentials*)creds; + reinterpret_cast(creds); GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0); return &c->inner; } @@ -200,7 +200,7 @@ grpc_call_credentials* grpc_credentials_contains_type( static void composite_channel_destruct(grpc_channel_credentials* creds) { grpc_composite_channel_credentials* c = - (grpc_composite_channel_credentials*)creds; + reinterpret_cast(creds); grpc_channel_credentials_unref(c->inner_creds); grpc_call_credentials_unref(c->call_creds); } @@ -210,7 +210,7 @@ static grpc_security_status composite_channel_create_security_connector( const char* target, const grpc_channel_args* args, grpc_channel_security_connector** sc, grpc_channel_args** new_args) { grpc_composite_channel_credentials* c = - (grpc_composite_channel_credentials*)creds; + reinterpret_cast(creds); grpc_security_status status = GRPC_SECURITY_ERROR; GPR_ASSERT(c->inner_creds != nullptr && c->call_creds != nullptr && @@ -236,7 +236,7 @@ static grpc_channel_credentials* composite_channel_duplicate_without_call_credentials( grpc_channel_credentials* creds) { grpc_composite_channel_credentials* c = - (grpc_composite_channel_credentials*)creds; + reinterpret_cast(creds); return grpc_channel_credentials_ref(c->inner_creds); } @@ -248,7 +248,7 @@ grpc_channel_credentials* grpc_composite_channel_credentials_create( grpc_channel_credentials* channel_creds, grpc_call_credentials* call_creds, void* reserved) { grpc_composite_channel_credentials* c = - (grpc_composite_channel_credentials*)gpr_zalloc(sizeof(*c)); + static_cast(gpr_zalloc(sizeof(*c))); GPR_ASSERT(channel_creds != nullptr && call_creds != nullptr && reserved == nullptr); GRPC_API_TRACE( diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index 009a5ce4ec..c1ca881292 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -40,8 +40,8 @@ grpc_credentials_metadata_request* grpc_credentials_metadata_request_create( grpc_call_credentials* creds) { grpc_credentials_metadata_request* r = - (grpc_credentials_metadata_request*)gpr_zalloc( - sizeof(grpc_credentials_metadata_request)); + static_cast(gpr_zalloc( + sizeof(grpc_credentials_metadata_request))); r->creds = grpc_call_credentials_ref(creds); return r; } @@ -145,11 +145,11 @@ grpc_channel_credentials_duplicate_without_call_credentials( } static void credentials_pointer_arg_destroy(void* p) { - grpc_channel_credentials_unref((grpc_channel_credentials*)p); + grpc_channel_credentials_unref(static_cast(p)); } static void* credentials_pointer_arg_copy(void* p) { - return grpc_channel_credentials_ref((grpc_channel_credentials*)p); + return grpc_channel_credentials_ref(static_cast(p)); } static int credentials_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); } @@ -173,7 +173,7 @@ grpc_channel_credentials* grpc_channel_credentials_from_arg( GRPC_ARG_CHANNEL_CREDENTIALS); return nullptr; } - return (grpc_channel_credentials*)arg->value.pointer.p; + return static_cast(arg->value.pointer.p); } grpc_channel_credentials* grpc_channel_credentials_find_in_args( @@ -240,11 +240,11 @@ void grpc_server_credentials_set_auth_metadata_processor( } static void server_credentials_pointer_arg_destroy(void* p) { - grpc_server_credentials_unref((grpc_server_credentials*)p); + grpc_server_credentials_unref(static_cast(p)); } static void* server_credentials_pointer_arg_copy(void* p) { - return grpc_server_credentials_ref((grpc_server_credentials*)p); + return grpc_server_credentials_ref(static_cast(p)); } static int server_credentials_pointer_cmp(void* a, void* b) { @@ -267,7 +267,7 @@ grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) { GRPC_SERVER_CREDENTIALS_ARG); return nullptr; } - return (grpc_server_credentials*)arg->value.pointer.p; + return static_cast(arg->value.pointer.p); } grpc_server_credentials* grpc_find_server_credentials_in_args( diff --git a/src/core/lib/security/credentials/credentials_metadata.cc b/src/core/lib/security/credentials/credentials_metadata.cc index 9ceaf21139..76e856f48e 100644 --- a/src/core/lib/security/credentials/credentials_metadata.cc +++ b/src/core/lib/security/credentials/credentials_metadata.cc @@ -34,7 +34,7 @@ static void mdelem_list_ensure_capacity(grpc_credentials_mdelem_array* list, new_size *= 2; } list->md = - (grpc_mdelem*)gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size); + static_cast(gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size)); } void grpc_credentials_mdelem_array_add(grpc_credentials_mdelem_array* list, diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc index 9065325cdd..b4f0dfdbdc 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.cc +++ b/src/core/lib/security/credentials/fake/fake_credentials.cc @@ -60,7 +60,7 @@ static grpc_server_credentials_vtable grpc_channel_credentials* grpc_fake_transport_security_credentials_create( void) { grpc_channel_credentials* c = - (grpc_channel_credentials*)gpr_zalloc(sizeof(grpc_channel_credentials)); + static_cast(gpr_zalloc(sizeof(grpc_channel_credentials))); c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY; c->vtable = &fake_transport_security_credentials_vtable; gpr_ref_init(&c->refcount, 1); @@ -70,7 +70,7 @@ grpc_channel_credentials* grpc_fake_transport_security_credentials_create( grpc_server_credentials* grpc_fake_transport_security_server_credentials_create( void) { grpc_server_credentials* c = - (grpc_server_credentials*)gpr_malloc(sizeof(grpc_server_credentials)); + static_cast(gpr_malloc(sizeof(grpc_server_credentials))); memset(c, 0, sizeof(grpc_server_credentials)); c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY; gpr_ref_init(&c->refcount, 1); @@ -97,7 +97,7 @@ const char* grpc_fake_transport_get_expected_targets( /* -- Metadata-only test credentials. -- */ static void md_only_test_destruct(grpc_call_credentials* creds) { - grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds; + grpc_md_only_test_credentials* c = reinterpret_cast(creds); GRPC_MDELEM_UNREF(c->md); } @@ -105,7 +105,7 @@ static bool md_only_test_get_request_metadata( grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds; + grpc_md_only_test_credentials* c = reinterpret_cast(creds); grpc_credentials_mdelem_array_add(md_array, c->md); if (c->is_async) { GRPC_CLOSURE_SCHED(on_request_metadata, GRPC_ERROR_NONE); @@ -126,8 +126,8 @@ static grpc_call_credentials_vtable md_only_test_vtable = { grpc_call_credentials* grpc_md_only_test_credentials_create( const char* md_key, const char* md_value, bool is_async) { - grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)gpr_zalloc( - sizeof(grpc_md_only_test_credentials)); + grpc_md_only_test_credentials* c = static_cast(gpr_zalloc( + sizeof(grpc_md_only_test_credentials))); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2; c->base.vtable = &md_only_test_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index dc19202033..dd7d52d750 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -60,7 +60,7 @@ typedef struct { static void on_compute_engine_detection_http_response(void* user_data, grpc_error* error) { - compute_engine_detector* detector = (compute_engine_detector*)user_data; + compute_engine_detector* detector = static_cast(user_data); if (error == GRPC_ERROR_NONE && detector->response.status == 200 && detector->response.hdr_count > 0) { /* Internet providers can return a generic response to all requests, so @@ -85,7 +85,7 @@ static void on_compute_engine_detection_http_response(void* user_data, } static void destroy_pollset(void* p, grpc_error* e) { - grpc_pollset_destroy((grpc_pollset*)p); + grpc_pollset_destroy(static_cast(p)); } static int is_stack_running_on_compute_engine() { @@ -98,7 +98,7 @@ static int is_stack_running_on_compute_engine() { on compute engine. */ grpc_millis max_detection_delay = GPR_MS_PER_SEC; - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &g_polling_mu); detector.pollent = grpc_polling_entity_create_from_pollset(pollset); detector.is_done = 0; @@ -171,7 +171,7 @@ static grpc_error* create_default_creds_from_path( goto end; } json = grpc_json_parse_string_with_len( - (char*)GRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data)); + reinterpret_castGRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data)); if (json == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"), diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 75acb2a58e..20f4ff95f5 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -28,7 +28,7 @@ #include static void iam_destruct(grpc_call_credentials* creds) { - grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds; + grpc_google_iam_credentials* c = reinterpret_cast(creds); grpc_credentials_mdelem_array_destroy(&c->md_array); } @@ -38,7 +38,7 @@ static bool iam_get_request_metadata(grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds; + grpc_google_iam_credentials* c = reinterpret_cast(creds); grpc_credentials_mdelem_array_append(md_array, &c->md_array); return true; } @@ -63,7 +63,7 @@ grpc_call_credentials* grpc_google_iam_credentials_create( GPR_ASSERT(token != nullptr); GPR_ASSERT(authority_selector != nullptr); grpc_google_iam_credentials* c = - (grpc_google_iam_credentials*)gpr_zalloc(sizeof(*c)); + static_cast(gpr_zalloc(sizeof(*c))); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_IAM; c->base.vtable = &iam_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc index 078f04ed11..eae1be17fd 100644 --- a/src/core/lib/security/credentials/jwt/json_token.cc +++ b/src/core/lib/security/credentials/jwt/json_token.cc @@ -96,7 +96,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) { } bio = BIO_new(BIO_s_mem()); success = BIO_puts(bio, prop_value); - if ((success < 0) || ((size_t)success != strlen(prop_value))) { + if ((success < 0) || (static_cast(success) != strlen(prop_value))) { gpr_log(GPR_ERROR, "Could not write into openssl BIO."); goto end; } @@ -219,7 +219,7 @@ static char* dot_concat_and_free_strings(char* str1, char* str2) { size_t str1_len = strlen(str1); size_t str2_len = strlen(str2); size_t result_len = str1_len + 1 /* dot */ + str2_len; - char* result = (char*)gpr_malloc(result_len + 1 /* NULL terminated */); + char* result = static_cast(gpr_malloc(result_len + 1 /* NULL terminated */)); char* current = result; memcpy(current, str1, str1_len); current += str1_len; @@ -271,7 +271,7 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, gpr_log(GPR_ERROR, "DigestFinal (get signature length) failed."); goto end; } - sig = (unsigned char*)gpr_malloc(sig_len); + sig = static_cast(gpr_malloc(sig_len)); if (EVP_DigestSignFinal(md_ctx, sig, &sig_len) != 1) { gpr_log(GPR_ERROR, "DigestFinal (signature compute) failed."); goto end; diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index 2404e860e4..44101acd78 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -42,7 +42,7 @@ static void jwt_reset_cache(grpc_service_account_jwt_access_credentials* c) { static void jwt_destruct(grpc_call_credentials* creds) { grpc_service_account_jwt_access_credentials* c = - (grpc_service_account_jwt_access_credentials*)creds; + reinterpret_cast(creds); grpc_auth_json_key_destruct(&c->key); jwt_reset_cache(c); gpr_mu_destroy(&c->cache_mu); @@ -55,7 +55,7 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds, grpc_closure* on_request_metadata, grpc_error** error) { grpc_service_account_jwt_access_credentials* c = - (grpc_service_account_jwt_access_credentials*)creds; + reinterpret_cast(creds); gpr_timespec refresh_threshold = gpr_time_from_seconds( GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN); @@ -123,8 +123,8 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key( gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); return nullptr; } - c = (grpc_service_account_jwt_access_credentials*)gpr_zalloc( - sizeof(grpc_service_account_jwt_access_credentials)); + c = static_cast(gpr_zalloc( + sizeof(grpc_service_account_jwt_access_credentials))); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_JWT; gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &jwt_vtable; @@ -133,7 +133,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key( if (gpr_time_cmp(token_lifetime, max_token_lifetime) > 0) { gpr_log(GPR_INFO, "Cropping token lifetime to maximum allowed value (%d secs).", - (int)max_token_lifetime.tv_sec); + static_cast(max_token_lifetime.tv_sec)); token_lifetime = grpc_max_auth_token_lifetime(); } c->jwt_lifetime = token_lifetime; @@ -154,7 +154,7 @@ static char* redact_private_key(const char* json_key) { while (current) { if (current->type == GRPC_JSON_STRING && strcmp(current->key, "private_key") == 0) { - current->value = (char*)redacted; + current->value = const_cast(redacted); break; } current = current->next; @@ -177,7 +177,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( ", tv_nsec: %d, clock_type: %d }, " "reserved=%p)", clean_json, token_lifetime.tv_sec, token_lifetime.tv_nsec, - (int)token_lifetime.clock_type, reserved); + static_cast(token_lifetime.clock_type), reserved); gpr_free(clean_json); } GPR_ASSERT(reserved == nullptr); diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 8b22307944..3d7541f4c9 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -82,7 +82,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, gpr_log(GPR_ERROR, "Invalid base64."); return nullptr; } - json = grpc_json_parse_string_with_len((char*)GRPC_SLICE_START_PTR(*buffer), + json = grpc_json_parse_string_with_len(reinterpret_castGRPC_SLICE_START_PTR(*buffer), GRPC_SLICE_LENGTH(*buffer)); if (json == nullptr) { grpc_slice_unref_internal(*buffer); @@ -129,7 +129,7 @@ static void jose_header_destroy(jose_header* h) { /* Takes ownership of json and buffer. */ static jose_header* jose_header_from_json(grpc_json* json, grpc_slice buffer) { grpc_json* cur; - jose_header* h = (jose_header*)gpr_zalloc(sizeof(jose_header)); + jose_header* h = static_cast(gpr_zalloc(sizeof(jose_header))); h->buffer = buffer; for (cur = json->child; cur != nullptr; cur = cur->next) { if (strcmp(cur->key, "alg") == 0) { @@ -231,7 +231,7 @@ gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) { grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer) { grpc_json* cur; grpc_jwt_claims* claims = - (grpc_jwt_claims*)gpr_malloc(sizeof(grpc_jwt_claims)); + static_cast(gpr_malloc(sizeof(grpc_jwt_claims))); memset(claims, 0, sizeof(grpc_jwt_claims)); claims->json = json; claims->buffer = buffer; @@ -347,7 +347,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create( const char* signed_jwt, size_t signed_jwt_len, void* user_data, grpc_jwt_verification_done_cb cb) { grpc_core::ExecCtx exec_ctx; - verifier_cb_ctx* ctx = (verifier_cb_ctx*)gpr_zalloc(sizeof(verifier_cb_ctx)); + verifier_cb_ctx* ctx = static_cast(gpr_zalloc(sizeof(verifier_cb_ctx))); ctx->verifier = verifier; ctx->pollent = grpc_polling_entity_create_from_pollset(pollset); ctx->header = header; @@ -429,7 +429,7 @@ static EVP_PKEY* extract_pkey_from_x509(const char* x509_str) { BIO* bio = BIO_new(BIO_s_mem()); size_t len = strlen(x509_str); GPR_ASSERT(len < INT_MAX); - BIO_write(bio, x509_str, (int)len); + BIO_write(bio, x509_str, static_cast(len)); x509 = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr); if (x509 == nullptr) { gpr_log(GPR_ERROR, "Unable to parse x509 cert."); @@ -625,7 +625,7 @@ end: } static void on_keys_retrieved(void* user_data, grpc_error* error) { - verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; + verifier_cb_ctx* ctx = static_cast(user_data); grpc_json* json = json_from_http(&ctx->responses[HTTP_RESPONSE_KEYS]); EVP_PKEY* verification_key = nullptr; grpc_jwt_verifier_status status = GRPC_JWT_VERIFIER_GENERIC_ERROR; @@ -666,7 +666,7 @@ end: static void on_openid_config_retrieved(void* user_data, grpc_error* error) { const grpc_json* cur; - verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; + verifier_cb_ctx* ctx = static_cast(user_data); const grpc_http_response* response = &ctx->responses[HTTP_RESPONSE_OPENID]; grpc_json* json = json_from_http(response); grpc_httpcli_request req; @@ -689,7 +689,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) { jwks_uri += 8; req.handshaker = &grpc_httpcli_ssl; req.host = gpr_strdup(jwks_uri); - req.http.path = (char*)strchr(jwks_uri, '/'); + req.http.path = const_cast(strchr(jwks_uri, '/')); if (req.http.path == nullptr) { req.http.path = (char*)""; } else { @@ -754,8 +754,8 @@ const char* grpc_jwt_issuer_email_domain(const char* issuer) { if (dot == nullptr || dot == email_domain) return email_domain; GPR_ASSERT(dot > email_domain); /* There may be a subdomain, we just want the domain. */ - dot = (const char*)gpr_memrchr((void*)email_domain, '.', - (size_t)(dot - email_domain)); + dot = static_cast(gpr_memrchr((void*)email_domain, '.', + static_cast(dot - email_domain))); if (dot == nullptr) return email_domain; return dot + 1; } @@ -861,7 +861,7 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, cb != nullptr); dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &header_buffer); + json = parse_json_part_from_jwt(cur, static_cast(dot - cur), &header_buffer); if (json == nullptr) goto error; header = jose_header_from_json(json, header_buffer); if (header == nullptr) goto error; @@ -869,12 +869,12 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, cur = dot + 1; dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &claims_buffer); + json = parse_json_part_from_jwt(cur, static_cast(dot - cur), &claims_buffer); if (json == nullptr) goto error; claims = grpc_jwt_claims_from_json(json, claims_buffer); if (claims == nullptr) goto error; - signed_jwt_len = (size_t)(dot - jwt); + signed_jwt_len = static_cast(dot - jwt); cur = dot + 1; signature = grpc_base64_decode(cur, 1); if (GRPC_SLICE_IS_EMPTY(signature)) goto error; @@ -893,13 +893,13 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( const grpc_jwt_verifier_email_domain_key_url_mapping* mappings, size_t num_mappings) { grpc_jwt_verifier* v = - (grpc_jwt_verifier*)gpr_zalloc(sizeof(grpc_jwt_verifier)); + static_cast(gpr_zalloc(sizeof(grpc_jwt_verifier))); grpc_httpcli_context_init(&v->http_ctx); /* We know at least of one mapping. */ v->allocated_mappings = 1 + num_mappings; - v->mappings = (email_key_mapping*)gpr_malloc(v->allocated_mappings * - sizeof(email_key_mapping)); + v->mappings = static_cast(gpr_malloc(v->allocated_mappings * + sizeof(email_key_mapping))); verifier_put_mapping(v, GRPC_GOOGLE_SERVICE_ACCOUNTS_EMAIL_DOMAIN, GRPC_GOOGLE_SERVICE_ACCOUNTS_KEY_URL_PREFIX); /* User-Provided mappings. */ diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index e243ea52c6..b4fb9a43e7 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -105,7 +105,7 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) { static void oauth2_token_fetcher_destruct(grpc_call_credentials* creds) { grpc_oauth2_token_fetcher_credentials* c = - (grpc_oauth2_token_fetcher_credentials*)creds; + reinterpret_cast(creds); GRPC_MDELEM_UNREF(c->access_token_md); gpr_mu_destroy(&c->mu); grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&c->pollent)); @@ -128,7 +128,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( } if (response->body_length > 0) { - null_terminated_body = (char*)gpr_malloc(response->body_length + 1); + null_terminated_body = static_cast(gpr_malloc(response->body_length + 1)); null_terminated_body[response->body_length] = '\0'; memcpy(null_terminated_body, response->body, response->body_length); } @@ -204,9 +204,9 @@ static void on_oauth2_token_fetcher_http_response(void* user_data, grpc_error* error) { GRPC_LOG_IF_ERROR("oauth_fetch", GRPC_ERROR_REF(error)); grpc_credentials_metadata_request* r = - (grpc_credentials_metadata_request*)user_data; + static_cast(user_data); grpc_oauth2_token_fetcher_credentials* c = - (grpc_oauth2_token_fetcher_credentials*)r->creds; + reinterpret_cast(r->creds); grpc_mdelem access_token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_credentials_status status = @@ -249,7 +249,7 @@ static bool oauth2_token_fetcher_get_request_metadata( grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { grpc_oauth2_token_fetcher_credentials* c = - (grpc_oauth2_token_fetcher_credentials*)creds; + reinterpret_cast(creds); // Check if we can use the cached token. grpc_millis refresh_threshold = GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS * GPR_MS_PER_SEC; @@ -269,8 +269,8 @@ static bool oauth2_token_fetcher_get_request_metadata( // Couldn't get the token from the cache. // Add request to c->pending_requests and start a new fetch if needed. grpc_oauth2_pending_get_request_metadata* pending_request = - (grpc_oauth2_pending_get_request_metadata*)gpr_malloc( - sizeof(*pending_request)); + static_cast(gpr_malloc( + sizeof(*pending_request))); pending_request->md_array = md_array; pending_request->on_request_metadata = on_request_metadata; pending_request->pollent = pollent; @@ -298,7 +298,7 @@ static void oauth2_token_fetcher_cancel_get_request_metadata( grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_error* error) { grpc_oauth2_token_fetcher_credentials* c = - (grpc_oauth2_token_fetcher_credentials*)creds; + reinterpret_cast(creds); gpr_mu_lock(&c->mu); grpc_oauth2_pending_get_request_metadata* prev = nullptr; grpc_oauth2_pending_get_request_metadata* pending_request = @@ -371,8 +371,8 @@ static void compute_engine_fetch_oauth2( grpc_call_credentials* grpc_google_compute_engine_credentials_create( void* reserved) { grpc_oauth2_token_fetcher_credentials* c = - (grpc_oauth2_token_fetcher_credentials*)gpr_malloc( - sizeof(grpc_oauth2_token_fetcher_credentials)); + static_cast(gpr_malloc( + sizeof(grpc_oauth2_token_fetcher_credentials))); GRPC_API_TRACE("grpc_compute_engine_credentials_create(reserved=%p)", 1, (reserved)); GPR_ASSERT(reserved == nullptr); @@ -387,7 +387,7 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create( static void refresh_token_destruct(grpc_call_credentials* creds) { grpc_google_refresh_token_credentials* c = - (grpc_google_refresh_token_credentials*)creds; + reinterpret_cast(creds); grpc_auth_refresh_token_destruct(&c->refresh_token); oauth2_token_fetcher_destruct(&c->base.base); } @@ -401,7 +401,7 @@ static void refresh_token_fetch_oauth2( grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, grpc_millis deadline) { grpc_google_refresh_token_credentials* c = - (grpc_google_refresh_token_credentials*)metadata_req->creds; + reinterpret_cast(metadata_req->creds); grpc_http_header header = {(char*)"Content-Type", (char*)"application/x-www-form-urlencoded"}; grpc_httpcli_request request; @@ -437,8 +437,8 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token( gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation"); return nullptr; } - c = (grpc_google_refresh_token_credentials*)gpr_zalloc( - sizeof(grpc_google_refresh_token_credentials)); + c = static_cast(gpr_zalloc( + sizeof(grpc_google_refresh_token_credentials))); init_oauth2_token_fetcher(&c->base, refresh_token_fetch_oauth2); c->base.base.vtable = &refresh_token_vtable; c->refresh_token = refresh_token; @@ -478,7 +478,7 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create( // static void access_token_destruct(grpc_call_credentials* creds) { - grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds; + grpc_access_token_credentials* c = reinterpret_cast(creds); GRPC_MDELEM_UNREF(c->access_token_md); } @@ -486,7 +486,7 @@ static bool access_token_get_request_metadata( grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds; + grpc_access_token_credentials* c = reinterpret_cast(creds); grpc_credentials_mdelem_array_add(md_array, c->access_token_md); return true; } @@ -503,8 +503,8 @@ static grpc_call_credentials_vtable access_token_vtable = { grpc_call_credentials* grpc_access_token_credentials_create( const char* access_token, void* reserved) { - grpc_access_token_credentials* c = (grpc_access_token_credentials*)gpr_zalloc( - sizeof(grpc_access_token_credentials)); + grpc_access_token_credentials* c = static_cast(gpr_zalloc( + sizeof(grpc_access_token_credentials))); GRPC_API_TRACE( "grpc_access_token_credentials_create(access_token=, " "reserved=%p)", diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 203ba58c67..89f94f9e6d 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -34,7 +34,7 @@ grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials"); static void plugin_destruct(grpc_call_credentials* creds) { - grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; + grpc_plugin_credentials* c = reinterpret_cast(creds); gpr_mu_destroy(&c->mu); if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) { c->plugin.destroy(c->plugin.state); @@ -118,7 +118,7 @@ static void plugin_md_request_metadata_ready(void* request, grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); grpc_plugin_credentials_pending_request* r = - (grpc_plugin_credentials_pending_request*)request; + static_cast(request); if (grpc_plugin_credentials_trace.enabled()) { gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: plugin returned " @@ -147,13 +147,13 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; + grpc_plugin_credentials* c = reinterpret_cast(creds); bool retval = true; // Synchronous return. if (c->plugin.get_metadata != nullptr) { // Create pending_request object. grpc_plugin_credentials_pending_request* pending_request = - (grpc_plugin_credentials_pending_request*)gpr_zalloc( - sizeof(*pending_request)); + static_cast(gpr_zalloc( + sizeof(*pending_request))); pending_request->creds = c; pending_request->md_array = md_array; pending_request->on_request_metadata = on_request_metadata; @@ -225,7 +225,7 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds, static void plugin_cancel_get_request_metadata( grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_error* error) { - grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; + grpc_plugin_credentials* c = reinterpret_cast(creds); gpr_mu_lock(&c->mu); for (grpc_plugin_credentials_pending_request* pending_request = c->pending_requests; @@ -252,7 +252,7 @@ static grpc_call_credentials_vtable plugin_vtable = { grpc_call_credentials* grpc_metadata_credentials_create_from_plugin( grpc_metadata_credentials_plugin plugin, void* reserved) { - grpc_plugin_credentials* c = (grpc_plugin_credentials*)gpr_zalloc(sizeof(*c)); + grpc_plugin_credentials* c = static_cast(gpr_zalloc(sizeof(*c))); GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1, (reserved)); GPR_ASSERT(reserved == nullptr); diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index d8546441c9..4237039274 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -42,7 +42,7 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp, } static void ssl_destruct(grpc_channel_credentials* creds) { - grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; + grpc_ssl_credentials* c = reinterpret_cast(creds); gpr_free(c->config.pem_root_certs); grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pair, 1); } @@ -51,7 +51,7 @@ static grpc_security_status ssl_create_security_connector( grpc_channel_credentials* creds, grpc_call_credentials* call_creds, const char* target, const grpc_channel_args* args, grpc_channel_security_connector** sc, grpc_channel_args** new_args) { - grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; + grpc_ssl_credentials* c = reinterpret_cast(creds); grpc_security_status status = GRPC_SECURITY_OK; const char* overridden_target_name = nullptr; for (size_t i = 0; args && i < args->num_args; i++) { @@ -85,8 +85,8 @@ static void ssl_build_config(const char* pem_root_certs, if (pem_key_cert_pair != nullptr) { GPR_ASSERT(pem_key_cert_pair->private_key != nullptr); GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr); - config->pem_key_cert_pair = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc( - sizeof(tsi_ssl_pem_key_cert_pair)); + config->pem_key_cert_pair = static_cast(gpr_zalloc( + sizeof(tsi_ssl_pem_key_cert_pair))); config->pem_key_cert_pair->cert_chain = gpr_strdup(pem_key_cert_pair->cert_chain); config->pem_key_cert_pair->private_key = @@ -98,7 +98,7 @@ grpc_channel_credentials* grpc_ssl_credentials_create( const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair, void* reserved) { grpc_ssl_credentials* c = - (grpc_ssl_credentials*)gpr_zalloc(sizeof(grpc_ssl_credentials)); + static_cast(gpr_zalloc(sizeof(grpc_ssl_credentials))); GRPC_API_TRACE( "grpc_ssl_credentials_create(pem_root_certs=%s, " "pem_key_cert_pair=%p, " @@ -123,7 +123,7 @@ struct grpc_ssl_server_credentials_options { }; static void ssl_server_destruct(grpc_server_credentials* creds) { - grpc_ssl_server_credentials* c = (grpc_ssl_server_credentials*)creds; + grpc_ssl_server_credentials* c = reinterpret_cast(creds); grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pairs, c->config.num_key_cert_pairs); gpr_free(c->config.pem_root_certs); @@ -143,8 +143,8 @@ tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs( tsi_ssl_pem_key_cert_pair* tsi_pairs = nullptr; if (num_key_cert_pairs > 0) { GPR_ASSERT(pem_key_cert_pairs != nullptr); - tsi_pairs = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc( - num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair)); + tsi_pairs = static_cast(gpr_zalloc( + num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair))); } for (size_t i = 0; i < num_key_cert_pairs; i++) { GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr); @@ -174,15 +174,15 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create( const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs, size_t num_key_cert_pairs) { grpc_ssl_server_certificate_config* config = - (grpc_ssl_server_certificate_config*)gpr_zalloc( - sizeof(grpc_ssl_server_certificate_config)); + static_cast(gpr_zalloc( + sizeof(grpc_ssl_server_certificate_config))); if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } if (num_key_cert_pairs > 0) { GPR_ASSERT(pem_key_cert_pairs != nullptr); - config->pem_key_cert_pairs = (grpc_ssl_pem_key_cert_pair*)gpr_zalloc( - num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair)); + config->pem_key_cert_pairs = static_cast(gpr_zalloc( + num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair))); } config->num_key_cert_pairs = num_key_cert_pairs; for (size_t i = 0; i < num_key_cert_pairs; i++) { @@ -217,8 +217,8 @@ grpc_ssl_server_credentials_create_options_using_config( gpr_log(GPR_ERROR, "Certificate config must not be NULL."); goto done; } - options = (grpc_ssl_server_credentials_options*)gpr_zalloc( - sizeof(grpc_ssl_server_credentials_options)); + options = static_cast(gpr_zalloc( + sizeof(grpc_ssl_server_credentials_options))); options->client_certificate_request = client_certificate_request; options->certificate_config = config; done: @@ -235,14 +235,14 @@ grpc_ssl_server_credentials_create_options_using_config_fetcher( } grpc_ssl_server_certificate_config_fetcher* fetcher = - (grpc_ssl_server_certificate_config_fetcher*)gpr_zalloc( - sizeof(grpc_ssl_server_certificate_config_fetcher)); + static_cast(gpr_zalloc( + sizeof(grpc_ssl_server_certificate_config_fetcher))); fetcher->cb = cb; fetcher->user_data = user_data; grpc_ssl_server_credentials_options* options = - (grpc_ssl_server_credentials_options*)gpr_zalloc( - sizeof(grpc_ssl_server_credentials_options)); + static_cast(gpr_zalloc( + sizeof(grpc_ssl_server_credentials_options))); options->client_certificate_request = client_certificate_request; options->certificate_config_fetcher = fetcher; @@ -307,8 +307,8 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options( goto done; } - c = (grpc_ssl_server_credentials*)gpr_zalloc( - sizeof(grpc_ssl_server_credentials)); + c = static_cast(gpr_zalloc( + sizeof(grpc_ssl_server_credentials))); c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL; gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &ssl_server_vtable; diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc index 802503c868..b5171acc87 100644 --- a/src/core/lib/security/transport/client_auth_filter.cc +++ b/src/core/lib/security/transport/client_auth_filter.cc @@ -70,11 +70,11 @@ struct channel_data { void grpc_auth_metadata_context_reset( grpc_auth_metadata_context* auth_md_context) { if (auth_md_context->service_url != nullptr) { - gpr_free((char*)auth_md_context->service_url); + gpr_free(const_cast(auth_md_context->service_url)); auth_md_context->service_url = nullptr; } if (auth_md_context->method_name != nullptr) { - gpr_free((char*)auth_md_context->method_name); + gpr_free(const_cast(auth_md_context->method_name)); auth_md_context->method_name = nullptr; } GRPC_AUTH_CONTEXT_UNREF( @@ -93,10 +93,10 @@ static void add_error(grpc_error** combined, grpc_error* error) { } static void on_credentials_metadata(void* arg, grpc_error* input_error) { - grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; + grpc_transport_stream_op_batch* batch = static_cast(arg); grpc_call_element* elem = - (grpc_call_element*)batch->handler_private.extra_arg; - call_data* calld = (call_data*)elem->call_data; + static_cast(batch->handler_private.extra_arg); + call_data* calld = static_cast(elem->call_data); grpc_auth_metadata_context_reset(&calld->auth_md_context); grpc_error* error = GRPC_ERROR_REF(input_error); if (error == GRPC_ERROR_NONE) { @@ -159,8 +159,8 @@ void grpc_auth_metadata_context_build( } static void cancel_get_request_metadata(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); if (error != GRPC_ERROR_NONE) { grpc_call_credentials_cancel_get_request_metadata( calld->creds, &calld->md_array, GRPC_ERROR_REF(error)); @@ -170,12 +170,12 @@ static void cancel_get_request_metadata(void* arg, grpc_error* error) { static void send_security_metadata(grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); grpc_client_security_context* ctx = - (grpc_client_security_context*)batch->payload + static_cast(batch->payload ->context[GRPC_CONTEXT_SECURITY] - .value; + .value); grpc_call_credentials* channel_call_creds = chand->security_connector->request_metadata_creds; int call_creds_has_md = (ctx != nullptr) && (ctx->creds != nullptr); @@ -231,10 +231,10 @@ static void send_security_metadata(grpc_call_element* elem, } static void on_host_checked(void* arg, grpc_error* error) { - grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; + grpc_transport_stream_op_batch* batch = static_cast(arg); grpc_call_element* elem = - (grpc_call_element*)batch->handler_private.extra_arg; - call_data* calld = (call_data*)elem->call_data; + static_cast(batch->handler_private.extra_arg); + call_data* calld = static_cast(elem->call_data); if (error == GRPC_ERROR_NONE) { send_security_metadata(elem, batch); } else { @@ -255,9 +255,9 @@ static void on_host_checked(void* arg, grpc_error* error) { } static void cancel_check_call_host(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); if (error != GRPC_ERROR_NONE) { grpc_channel_security_connector_cancel_check_call_host( chand->security_connector, &calld->async_result_closure, @@ -271,8 +271,8 @@ static void auth_start_transport_stream_op_batch( GPR_TIMER_SCOPE("auth_start_transport_stream_op_batch", 0); /* grab pointers to our data from the call element */ - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); if (!batch->cancel_stream) { GPR_ASSERT(batch->payload->context != nullptr); @@ -283,9 +283,9 @@ static void auth_start_transport_stream_op_batch( grpc_client_security_context_destroy; } grpc_client_security_context* sec_ctx = - (grpc_client_security_context*)batch->payload + static_cast(batch->payload ->context[GRPC_CONTEXT_SECURITY] - .value; + .value); GRPC_AUTH_CONTEXT_UNREF(sec_ctx->auth_context, "client auth filter"); sec_ctx->auth_context = GRPC_AUTH_CONTEXT_REF(chand->auth_context, "client_auth_filter"); @@ -346,7 +346,7 @@ static void auth_start_transport_stream_op_batch( /* Constructor for call_data */ static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); calld->owning_call = args->call_stack; calld->call_combiner = args->call_combiner; return GRPC_ERROR_NONE; @@ -354,7 +354,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void set_pollset_or_pollset_set(grpc_call_element* elem, grpc_polling_entity* pollent) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); calld->pollent = pollent; } @@ -362,7 +362,7 @@ static void set_pollset_or_pollset_set(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_credentials_mdelem_array_destroy(&calld->md_array); grpc_call_credentials_unref(calld->creds); if (calld->have_host) { @@ -391,7 +391,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } /* grab pointers to our data from the channel element */ - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); /* The first and the last filters tend to be implemented differently to handle the case that there's no 'next' filter to call on the up or down @@ -400,8 +400,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, /* initialize members */ chand->security_connector = - (grpc_channel_security_connector*)GRPC_SECURITY_CONNECTOR_REF( - sc, "client_auth_filter"); + reinterpret_cast(GRPC_SECURITY_CONNECTOR_REF( + sc, "client_auth_filter")); chand->auth_context = GRPC_AUTH_CONTEXT_REF(auth_context, "client_auth_filter"); return GRPC_ERROR_NONE; @@ -410,7 +410,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, /* Destructor for channel data */ static void destroy_channel_elem(grpc_channel_element* elem) { /* grab pointers to our data from the channel element */ - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); grpc_channel_security_connector* sc = chand->security_connector; if (sc != nullptr) { GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "client_auth_filter"); diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc index 183b1ebf35..84a72731c9 100644 --- a/src/core/lib/security/transport/lb_targets_info.cc +++ b/src/core/lib/security/transport/lb_targets_info.cc @@ -26,14 +26,14 @@ #define GRPC_ARG_LB_SECURE_NAMING_MAP "grpc.lb_secure_naming_map" static void* targets_info_copy(void* p) { - return grpc_slice_hash_table_ref((grpc_slice_hash_table*)p); + return grpc_slice_hash_table_ref(static_cast(p)); } static void targets_info_destroy(void* p) { - grpc_slice_hash_table_unref((grpc_slice_hash_table*)p); + grpc_slice_hash_table_unref(static_cast(p)); } static int targets_info_cmp(void* a, void* b) { - return grpc_slice_hash_table_cmp((const grpc_slice_hash_table*)a, - (const grpc_slice_hash_table*)b); + return grpc_slice_hash_table_cmp(static_cast(a), + static_cast(b)); } static const grpc_arg_pointer_vtable server_to_balancer_names_vtable = { targets_info_copy, targets_info_destroy, targets_info_cmp}; @@ -51,7 +51,7 @@ grpc_slice_hash_table* grpc_lb_targets_info_find_in_args( grpc_channel_args_find(args, GRPC_ARG_LB_SECURE_NAMING_MAP); if (targets_info_arg != nullptr) { GPR_ASSERT(targets_info_arg->type == GRPC_ARG_POINTER); - return (grpc_slice_hash_table*)targets_info_arg->value.pointer.p; + return static_cast(targets_info_arg->value.pointer.p); } return nullptr; } diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index 9eaa299897..a63dbc07c8 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -144,7 +144,7 @@ static void on_read(void* user_data, grpc_error* error) { unsigned i; uint8_t keep_looping = 0; tsi_result result = TSI_OK; - secure_endpoint* ep = (secure_endpoint*)user_data; + secure_endpoint* ep = static_cast(user_data); uint8_t* cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer); uint8_t* end = GRPC_SLICE_END_PTR(ep->read_staging_buffer); @@ -168,7 +168,7 @@ static void on_read(void* user_data, grpc_error* error) { size_t message_size = GRPC_SLICE_LENGTH(encrypted); while (message_size > 0 || keep_looping) { - size_t unprotected_buffer_size_written = (size_t)(end - cur); + size_t unprotected_buffer_size_written = static_cast(end - cur); size_t processed_message_size = message_size; gpr_mu_lock(&ep->protector_mu); result = tsi_frame_protector_unprotect( @@ -205,7 +205,7 @@ static void on_read(void* user_data, grpc_error* error) { ep->read_buffer, grpc_slice_split_head( &ep->read_staging_buffer, - (size_t)(cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer)))); + static_cast(cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer)))); } } @@ -226,7 +226,7 @@ static void on_read(void* user_data, grpc_error* error) { static void endpoint_read(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, grpc_closure* cb) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); ep->read_cb = cb; ep->read_buffer = slices; grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer); @@ -256,7 +256,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, unsigned i; tsi_result result = TSI_OK; - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); uint8_t* cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer); uint8_t* end = GRPC_SLICE_END_PTR(ep->write_staging_buffer); @@ -282,7 +282,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, uint8_t* message_bytes = GRPC_SLICE_START_PTR(plain); size_t message_size = GRPC_SLICE_LENGTH(plain); while (message_size > 0) { - size_t protected_buffer_size_to_send = (size_t)(end - cur); + size_t protected_buffer_size_to_send = static_cast(end - cur); size_t processed_message_size = message_size; gpr_mu_lock(&ep->protector_mu); result = tsi_frame_protector_protect(ep->protector, message_bytes, @@ -307,7 +307,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, if (result == TSI_OK) { size_t still_pending_size; do { - size_t protected_buffer_size_to_send = (size_t)(end - cur); + size_t protected_buffer_size_to_send = static_cast(end - cur); gpr_mu_lock(&ep->protector_mu); result = tsi_frame_protector_protect_flush( ep->protector, cur, &protected_buffer_size_to_send, @@ -324,7 +324,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, &ep->output_buffer, grpc_slice_split_head( &ep->write_staging_buffer, - (size_t)(cur - + static_cast(cur - GRPC_SLICE_START_PTR(ep->write_staging_buffer)))); } } @@ -343,46 +343,46 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, } static void endpoint_shutdown(grpc_endpoint* secure_ep, grpc_error* why) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); grpc_endpoint_shutdown(ep->wrapped_ep, why); } static void endpoint_destroy(grpc_endpoint* secure_ep) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); SECURE_ENDPOINT_UNREF(ep, "destroy"); } static void endpoint_add_to_pollset(grpc_endpoint* secure_ep, grpc_pollset* pollset) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); grpc_endpoint_add_to_pollset(ep->wrapped_ep, pollset); } static void endpoint_add_to_pollset_set(grpc_endpoint* secure_ep, grpc_pollset_set* pollset_set) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); grpc_endpoint_add_to_pollset_set(ep->wrapped_ep, pollset_set); } static void endpoint_delete_from_pollset_set(grpc_endpoint* secure_ep, grpc_pollset_set* pollset_set) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); grpc_endpoint_delete_from_pollset_set(ep->wrapped_ep, pollset_set); } static char* endpoint_get_peer(grpc_endpoint* secure_ep) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); return grpc_endpoint_get_peer(ep->wrapped_ep); } static int endpoint_get_fd(grpc_endpoint* secure_ep) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); return grpc_endpoint_get_fd(ep->wrapped_ep); } static grpc_resource_user* endpoint_get_resource_user( grpc_endpoint* secure_ep) { - secure_endpoint* ep = (secure_endpoint*)secure_ep; + secure_endpoint* ep = reinterpret_cast(secure_ep); return grpc_endpoint_get_resource_user(ep->wrapped_ep); } @@ -403,7 +403,7 @@ grpc_endpoint* grpc_secure_endpoint_create( grpc_endpoint* transport, grpc_slice* leftover_slices, size_t leftover_nslices) { size_t i; - secure_endpoint* ep = (secure_endpoint*)gpr_malloc(sizeof(secure_endpoint)); + secure_endpoint* ep = static_cast(gpr_malloc(sizeof(secure_endpoint))); ep->base.vtable = &vtable; ep->wrapped_ep = transport; ep->protector = protector; diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index fd632bdbab..e9a2d23535 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -239,8 +239,8 @@ static void* connector_arg_copy(void* p) { } static int connector_cmp(void* a, void* b) { - return grpc_security_connector_cmp((grpc_security_connector*)a, - (grpc_security_connector*)b); + return grpc_security_connector_cmp(static_cast(a), + static_cast(b)); } static const grpc_arg_pointer_vtable connector_arg_vtable = { @@ -258,7 +258,7 @@ grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) { GRPC_ARG_SECURITY_CONNECTOR); return nullptr; } - return (grpc_security_connector*)arg->value.pointer.p; + return static_cast(arg->value.pointer.p); } grpc_security_connector* grpc_security_connector_find_in_args( @@ -308,7 +308,7 @@ typedef struct { static void fake_channel_destroy(grpc_security_connector* sc) { grpc_fake_channel_security_connector* c = - (grpc_fake_channel_security_connector*)sc; + reinterpret_cast(sc); grpc_call_credentials_unref(c->base.request_metadata_creds); gpr_free(c->target); gpr_free(c->expected_targets); @@ -420,7 +420,7 @@ static void fake_channel_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_closure* on_peer_checked) { fake_check_peer(sc, peer, auth_context, on_peer_checked); grpc_fake_channel_security_connector* c = - (grpc_fake_channel_security_connector*)sc; + reinterpret_cast(sc); fake_secure_name_check(c->target, c->expected_targets, c->is_lb_channel); } @@ -433,9 +433,9 @@ static void fake_server_check_peer(grpc_security_connector* sc, tsi_peer peer, static int fake_channel_cmp(grpc_security_connector* sc1, grpc_security_connector* sc2) { grpc_fake_channel_security_connector* c1 = - (grpc_fake_channel_security_connector*)sc1; + reinterpret_cast(sc1); grpc_fake_channel_security_connector* c2 = - (grpc_fake_channel_security_connector*)sc2; + reinterpret_cast(sc2); int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base); if (c != 0) return c; c = strcmp(c1->target, c2->target); @@ -452,8 +452,8 @@ static int fake_channel_cmp(grpc_security_connector* sc1, static int fake_server_cmp(grpc_security_connector* sc1, grpc_security_connector* sc2) { return grpc_server_security_connector_cmp( - (grpc_server_security_connector*)sc1, - (grpc_server_security_connector*)sc2); + reinterpret_cast(sc1), + reinterpret_cast(sc2)); } static bool fake_channel_check_call_host(grpc_channel_security_connector* sc, @@ -498,7 +498,7 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create( grpc_call_credentials* request_metadata_creds, const char* target, const grpc_channel_args* args) { grpc_fake_channel_security_connector* c = - (grpc_fake_channel_security_connector*)gpr_zalloc(sizeof(*c)); + static_cast(gpr_zalloc(sizeof(*c))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME; c->base.base.vtable = &fake_channel_vtable; @@ -518,8 +518,8 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create( grpc_server_security_connector* grpc_fake_server_security_connector_create( grpc_server_credentials* server_creds) { grpc_server_security_connector* c = - (grpc_server_security_connector*)gpr_zalloc( - sizeof(grpc_server_security_connector)); + static_cast(gpr_zalloc( + sizeof(grpc_server_security_connector))); gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &fake_server_vtable; c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME; @@ -546,14 +546,14 @@ static bool server_connector_has_cert_config_fetcher( grpc_ssl_server_security_connector* c) { GPR_ASSERT(c != nullptr); grpc_ssl_server_credentials* server_creds = - (grpc_ssl_server_credentials*)c->base.server_creds; + reinterpret_cast(c->base.server_creds); GPR_ASSERT(server_creds != nullptr); return server_creds->certificate_config_fetcher.cb != nullptr; } static void ssl_channel_destroy(grpc_security_connector* sc) { grpc_ssl_channel_security_connector* c = - (grpc_ssl_channel_security_connector*)sc; + reinterpret_cast(sc); grpc_channel_credentials_unref(c->base.channel_creds); grpc_call_credentials_unref(c->base.request_metadata_creds); tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory); @@ -565,7 +565,7 @@ static void ssl_channel_destroy(grpc_security_connector* sc) { static void ssl_server_destroy(grpc_security_connector* sc) { grpc_ssl_server_security_connector* c = - (grpc_ssl_server_security_connector*)sc; + reinterpret_cast(sc); grpc_server_credentials_unref(c->base.server_creds); tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory); c->server_handshaker_factory = nullptr; @@ -575,7 +575,7 @@ static void ssl_server_destroy(grpc_security_connector* sc) { static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_ssl_channel_security_connector* c = - (grpc_ssl_channel_security_connector*)sc; + reinterpret_cast(sc); // Instantiate TSI handshaker. tsi_handshaker* tsi_hs = nullptr; tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker( @@ -598,7 +598,7 @@ static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { GPR_ASSERT(num_alpn_protocols != nullptr); *num_alpn_protocols = grpc_chttp2_num_alpn_versions(); const char** alpn_protocol_strings = - (const char**)gpr_malloc(sizeof(const char*) * (*num_alpn_protocols)); + static_cast(gpr_malloc(sizeof(const char*) * (*num_alpn_protocols))); for (size_t i = 0; i < *num_alpn_protocols; i++) { alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i); } @@ -627,12 +627,12 @@ static bool try_replace_server_handshaker_factory( config->pem_key_cert_pairs, config->num_key_cert_pairs); tsi_ssl_server_handshaker_factory* new_handshaker_factory = nullptr; grpc_ssl_server_credentials* server_creds = - (grpc_ssl_server_credentials*)sc->base.server_creds; + reinterpret_cast(sc->base.server_creds); tsi_result result = tsi_create_ssl_server_handshaker_factory_ex( cert_pairs, config->num_key_cert_pairs, config->pem_root_certs, get_tsi_client_certificate_request_type( server_creds->config.client_certificate_request), - ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols, + ssl_cipher_suites(), alpn_protocol_strings, static_cast(num_alpn_protocols), &new_handshaker_factory); gpr_free(cert_pairs); gpr_free((void*)alpn_protocol_strings); @@ -659,7 +659,7 @@ static bool try_fetch_ssl_server_credentials( if (!server_connector_has_cert_config_fetcher(sc)) return false; grpc_ssl_server_credentials* server_creds = - (grpc_ssl_server_credentials*)sc->base.server_creds; + reinterpret_cast(sc->base.server_creds); grpc_ssl_certificate_config_reload_status cb_result = server_creds->certificate_config_fetcher.cb( server_creds->certificate_config_fetcher.user_data, @@ -686,7 +686,7 @@ static bool try_fetch_ssl_server_credentials( static void ssl_server_add_handshakers(grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_ssl_server_security_connector* c = - (grpc_ssl_server_security_connector*)sc; + reinterpret_cast(sc); // Instantiate TSI handshaker. try_fetch_ssl_server_credentials(c); tsi_handshaker* tsi_hs = nullptr; @@ -788,7 +788,7 @@ static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_ssl_channel_security_connector* c = - (grpc_ssl_channel_security_connector*)sc; + reinterpret_cast(sc); grpc_error* error = ssl_check_peer(sc, c->overridden_target_name != nullptr ? c->overridden_target_name @@ -809,9 +809,9 @@ static void ssl_server_check_peer(grpc_security_connector* sc, tsi_peer peer, static int ssl_channel_cmp(grpc_security_connector* sc1, grpc_security_connector* sc2) { grpc_ssl_channel_security_connector* c1 = - (grpc_ssl_channel_security_connector*)sc1; + reinterpret_cast(sc1); grpc_ssl_channel_security_connector* c2 = - (grpc_ssl_channel_security_connector*)sc2; + reinterpret_cast(sc2); int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base); if (c != 0) return c; c = strcmp(c1->target_name, c2->target_name); @@ -825,15 +825,15 @@ static int ssl_channel_cmp(grpc_security_connector* sc1, static int ssl_server_cmp(grpc_security_connector* sc1, grpc_security_connector* sc2) { return grpc_server_security_connector_cmp( - (grpc_server_security_connector*)sc1, - (grpc_server_security_connector*)sc2); + reinterpret_cast(sc1), + reinterpret_cast(sc2)); } static void add_shallow_auth_property_to_peer(tsi_peer* peer, const grpc_auth_property* prop, const char* tsi_prop_name) { tsi_peer_property* tsi_prop = &peer->properties[peer->property_count++]; - tsi_prop->name = (char*)tsi_prop_name; + tsi_prop->name = const_cast(tsi_prop_name); tsi_prop->value.data = prop->value; tsi_prop->value.length = prop->value_length; } @@ -850,8 +850,8 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context( while (grpc_auth_property_iterator_next(&it) != nullptr) max_num_props++; if (max_num_props > 0) { - peer.properties = (tsi_peer_property*)gpr_malloc(max_num_props * - sizeof(tsi_peer_property)); + peer.properties = static_cast(gpr_malloc(max_num_props * + sizeof(tsi_peer_property))); it = grpc_auth_context_property_iterator(auth_context); while ((prop = grpc_auth_property_iterator_next(&it)) != nullptr) { if (strcmp(prop->name, GRPC_X509_SAN_PROPERTY_NAME) == 0) { @@ -879,7 +879,7 @@ static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, grpc_error** error) { grpc_ssl_channel_security_connector* c = - (grpc_ssl_channel_security_connector*)sc; + reinterpret_cast(sc); grpc_security_status status = GRPC_SECURITY_ERROR; tsi_peer peer = tsi_shallow_peer_from_ssl_auth_context(auth_context); if (ssl_host_matches_name(&peer, host)) status = GRPC_SECURITY_OK; @@ -963,7 +963,7 @@ const char* grpc_get_default_ssl_roots(void) { gpr_once_init(&once, init_default_pem_root_certs); return GRPC_SLICE_IS_EMPTY(default_pem_root_certs) ? nullptr - : (const char*)GRPC_SLICE_START_PTR(default_pem_root_certs); + : reinterpret_castGRPC_SLICE_START_PTR(default_pem_root_certs); } grpc_security_status grpc_ssl_channel_security_connector_create( @@ -994,8 +994,8 @@ grpc_security_status grpc_ssl_channel_security_connector_create( pem_root_certs = config->pem_root_certs; } - c = (grpc_ssl_channel_security_connector*)gpr_zalloc( - sizeof(grpc_ssl_channel_security_connector)); + c = static_cast(gpr_zalloc( + sizeof(grpc_ssl_channel_security_connector))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.vtable = &ssl_channel_vtable; @@ -1017,7 +1017,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create( config->pem_key_cert_pair->cert_chain != nullptr; result = tsi_create_ssl_client_handshaker_factory( has_key_cert_pair ? config->pem_key_cert_pair : nullptr, pem_root_certs, - ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols, + ssl_cipher_suites(), alpn_protocol_strings, static_cast(num_alpn_protocols), &c->client_handshaker_factory); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", @@ -1039,8 +1039,8 @@ static grpc_ssl_server_security_connector* grpc_ssl_server_security_connector_initialize( grpc_server_credentials* server_creds) { grpc_ssl_server_security_connector* c = - (grpc_ssl_server_security_connector*)gpr_zalloc( - sizeof(grpc_ssl_server_security_connector)); + static_cast(gpr_zalloc( + sizeof(grpc_ssl_server_security_connector))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.url_scheme = GRPC_SSL_URL_SCHEME; c->base.base.vtable = &ssl_server_vtable; @@ -1053,7 +1053,7 @@ grpc_security_status grpc_ssl_server_security_connector_create( grpc_server_credentials* gsc, grpc_server_security_connector** sc) { tsi_result result = TSI_OK; grpc_ssl_server_credentials* server_credentials = - (grpc_ssl_server_credentials*)gsc; + reinterpret_cast(gsc); grpc_security_status retval = GRPC_SECURITY_OK; GPR_ASSERT(server_credentials != nullptr); @@ -1078,7 +1078,7 @@ grpc_security_status grpc_ssl_server_security_connector_create( get_tsi_client_certificate_request_type( server_credentials->config.client_certificate_request), ssl_cipher_suites(), alpn_protocol_strings, - (uint16_t)num_alpn_protocols, &c->server_handshaker_factory); + static_cast(num_alpn_protocols), &c->server_handshaker_factory); gpr_free((void*)alpn_protocol_strings); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 7623fbfd5b..2e7c3570b6 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -69,7 +69,7 @@ static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) { size_t bytes_in_read_buffer = h->args->read_buffer->length; if (h->handshake_buffer_size < bytes_in_read_buffer) { h->handshake_buffer = - (uint8_t*)gpr_realloc(h->handshake_buffer, bytes_in_read_buffer); + static_cast(gpr_realloc(h->handshake_buffer, bytes_in_read_buffer)); h->handshake_buffer_size = bytes_in_read_buffer; } size_t offset = 0; @@ -205,7 +205,7 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) { } static void on_peer_checked(void* arg, grpc_error* error) { - security_handshaker* h = (security_handshaker*)arg; + security_handshaker* h = static_cast(arg); gpr_mu_lock(&h->mu); on_peer_checked_inner(h, error); gpr_mu_unlock(&h->mu); @@ -249,7 +249,7 @@ static grpc_error* on_handshake_next_done_locked( if (bytes_to_send_size > 0) { // Send data to peer, if needed. grpc_slice to_send = grpc_slice_from_copied_buffer( - (const char*)bytes_to_send, bytes_to_send_size); + reinterpret_cast(bytes_to_send), bytes_to_send_size); grpc_slice_buffer_reset_and_unref_internal(&h->outgoing); grpc_slice_buffer_add(&h->outgoing, to_send); grpc_endpoint_write(h->args->endpoint, &h->outgoing, @@ -268,7 +268,7 @@ static grpc_error* on_handshake_next_done_locked( static void on_handshake_next_done_grpc_wrapper( tsi_result result, void* user_data, const unsigned char* bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) { - security_handshaker* h = (security_handshaker*)user_data; + security_handshaker* h = static_cast(user_data); // This callback will be invoked by TSI in a non-grpc thread, so it's // safe to create our own exec_ctx here. grpc_core::ExecCtx exec_ctx; @@ -307,7 +307,7 @@ static grpc_error* do_handshaker_next_locked( } static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) { - security_handshaker* h = (security_handshaker*)arg; + security_handshaker* h = static_cast(arg); gpr_mu_lock(&h->mu); if (error != GRPC_ERROR_NONE || h->shutdown) { security_handshake_failed_locked( @@ -333,7 +333,7 @@ static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) { } static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) { - security_handshaker* h = (security_handshaker*)arg; + security_handshaker* h = static_cast(arg); gpr_mu_lock(&h->mu); if (error != GRPC_ERROR_NONE || h->shutdown) { security_handshake_failed_locked( @@ -364,13 +364,13 @@ static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) { // static void security_handshaker_destroy(grpc_handshaker* handshaker) { - security_handshaker* h = (security_handshaker*)handshaker; + security_handshaker* h = reinterpret_cast(handshaker); security_handshaker_unref(h); } static void security_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why) { - security_handshaker* h = (security_handshaker*)handshaker; + security_handshaker* h = reinterpret_cast(handshaker); gpr_mu_lock(&h->mu); if (!h->shutdown) { h->shutdown = true; @@ -385,7 +385,7 @@ static void security_handshaker_do_handshake(grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - security_handshaker* h = (security_handshaker*)handshaker; + security_handshaker* h = reinterpret_cast(handshaker); gpr_mu_lock(&h->mu); h->args = args; h->on_handshake_done = on_handshake_done; @@ -409,14 +409,14 @@ static const grpc_handshaker_vtable security_handshaker_vtable = { static grpc_handshaker* security_handshaker_create( tsi_handshaker* handshaker, grpc_security_connector* connector) { security_handshaker* h = - (security_handshaker*)gpr_zalloc(sizeof(security_handshaker)); + static_cast(gpr_zalloc(sizeof(security_handshaker))); grpc_handshaker_init(&security_handshaker_vtable, &h->base); h->handshaker = handshaker; h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake"); gpr_mu_init(&h->mu); gpr_ref_init(&h->refs, 1); h->handshake_buffer_size = GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE; - h->handshake_buffer = (uint8_t*)gpr_malloc(h->handshake_buffer_size); + h->handshake_buffer = static_cast(gpr_malloc(h->handshake_buffer_size)); GRPC_CLOSURE_INIT(&h->on_handshake_data_sent_to_peer, on_handshake_data_sent_to_peer, h, grpc_schedule_on_exec_ctx); @@ -456,7 +456,7 @@ static const grpc_handshaker_vtable fail_handshaker_vtable = { fail_handshaker_do_handshake}; static grpc_handshaker* fail_handshaker_create() { - grpc_handshaker* h = (grpc_handshaker*)gpr_malloc(sizeof(*h)); + grpc_handshaker* h = static_cast(gpr_malloc(sizeof(*h))); grpc_handshaker_init(&fail_handshaker_vtable, h); return h; } @@ -469,8 +469,8 @@ static void client_handshaker_factory_add_handshakers( grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_channel_security_connector* security_connector = - (grpc_channel_security_connector*)grpc_security_connector_find_in_args( - args); + reinterpret_cast(grpc_security_connector_find_in_args( + args)); grpc_channel_security_connector_add_handshakers(security_connector, handshake_mgr); } @@ -479,8 +479,8 @@ static void server_handshaker_factory_add_handshakers( grpc_handshaker_factory* hf, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_server_security_connector* security_connector = - (grpc_server_security_connector*)grpc_security_connector_find_in_args( - args); + reinterpret_cast(grpc_security_connector_find_in_args( + args)); grpc_server_security_connector_add_handshakers(security_connector, handshake_mgr); } diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index f82971dc56..409aded650 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -65,8 +65,8 @@ static grpc_metadata_array metadata_batch_to_md_array( grpc_slice value = GRPC_MDVALUE(md); if (result.count == result.capacity) { result.capacity = GPR_MAX(result.capacity + 8, result.capacity * 2); - result.metadata = (grpc_metadata*)gpr_realloc( - result.metadata, result.capacity * sizeof(grpc_metadata)); + result.metadata = static_cast(gpr_realloc( + result.metadata, result.capacity * sizeof(grpc_metadata))); } usr_md = &result.metadata[result.count++]; usr_md->key = grpc_slice_ref_internal(key); @@ -77,8 +77,8 @@ static grpc_metadata_array metadata_batch_to_md_array( static grpc_filtered_mdelem remove_consumed_md(void* user_data, grpc_mdelem md) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); size_t i; for (i = 0; i < calld->num_consumed_md; i++) { const grpc_metadata* consumed_md = &calld->consumed_md[i]; @@ -95,7 +95,7 @@ static void on_md_processing_done_inner(grpc_call_element* elem, const grpc_metadata* response_md, size_t num_response_md, grpc_error* error) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch; /* TODO(jboeuf): Implement support for response_md. */ if (response_md != nullptr && num_response_md > 0) { @@ -118,12 +118,12 @@ static void on_md_processing_done( void* user_data, const grpc_metadata* consumed_md, size_t num_consumed_md, const grpc_metadata* response_md, size_t num_response_md, grpc_status_code status, const char* error_details) { - grpc_call_element* elem = (grpc_call_element*)user_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(user_data); + call_data* calld = static_cast(elem->call_data); grpc_core::ExecCtx exec_ctx; // If the call was not cancelled while we were in flight, process the result. - if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, - (gpr_atm)STATE_DONE)) { + if (gpr_atm_full_cas(&calld->state, static_cast(STATE_INIT), + static_cast(STATE_DONE))) { grpc_error* error = GRPC_ERROR_NONE; if (status != GRPC_STATUS_OK) { if (error_details == nullptr) { @@ -146,12 +146,12 @@ static void on_md_processing_done( } static void cancel_call(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); // If the result was not already processed, invoke the callback now. if (error != GRPC_ERROR_NONE && - gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, - (gpr_atm)STATE_CANCELLED)) { + gpr_atm_full_cas(&calld->state, static_cast(STATE_INIT), + static_cast(STATE_CANCELLED))) { on_md_processing_done_inner(elem, nullptr, 0, nullptr, 0, GRPC_ERROR_REF(error)); } @@ -159,9 +159,9 @@ static void cancel_call(void* arg, grpc_error* error) { } static void recv_initial_metadata_ready(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch; if (error == GRPC_ERROR_NONE) { if (chand->creds != nullptr && chand->creds->processor.process != nullptr) { @@ -187,7 +187,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) { static void auth_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (batch->recv_initial_metadata) { // Inject our callback. calld->recv_initial_metadata_batch = batch; @@ -202,8 +202,8 @@ static void auth_start_transport_stream_op_batch( /* Constructor for call_data */ static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); calld->call_combiner = args->call_combiner; calld->owning_call = args->call_stack; GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready, @@ -234,7 +234,7 @@ static void destroy_call_elem(grpc_call_element* elem, static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); grpc_auth_context* auth_context = grpc_find_auth_context_in_args(args->channel_args); GPR_ASSERT(auth_context != nullptr); @@ -248,7 +248,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, /* Destructor for channel data */ static void destroy_channel_elem(grpc_channel_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "server_auth_filter"); grpc_server_credentials_unref(chand->creds); } diff --git a/src/core/lib/slice/b64.cc b/src/core/lib/slice/b64.cc index 5c6610c372..1d938be11c 100644 --- a/src/core/lib/slice/b64.cc +++ b/src/core/lib/slice/b64.cc @@ -58,7 +58,7 @@ char* grpc_base64_encode(const void* vdata, size_t data_size, int url_safe, int multiline) { size_t result_projected_size = grpc_base64_estimate_encoded_size(data_size, url_safe, multiline); - char* result = (char*)gpr_malloc(result_projected_size); + char* result = static_cast(gpr_malloc(result_projected_size)); grpc_base64_encode_core(result, vdata, data_size, url_safe, multiline); return result; } @@ -75,7 +75,7 @@ size_t grpc_base64_estimate_encoded_size(size_t data_size, int url_safe, void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, int url_safe, int multiline) { - const unsigned char* data = (const unsigned char*)vdata; + const unsigned char* data = static_cast(vdata); const char* base64_chars = url_safe ? base64_url_safe_chars : base64_url_unsafe_chars; const size_t result_projected_size = @@ -128,16 +128,16 @@ grpc_slice grpc_base64_decode(const char* b64, int url_safe) { static void decode_one_char(const unsigned char* codes, unsigned char* result, size_t* result_offset) { - uint32_t packed = ((uint32_t)codes[0] << 2) | ((uint32_t)codes[1] >> 4); - result[(*result_offset)++] = (unsigned char)packed; + uint32_t packed = (static_cast(codes[0]) << 2) | (static_cast(codes[1]) >> 4); + result[(*result_offset)++] = static_cast(packed); } static void decode_two_chars(const unsigned char* codes, unsigned char* result, size_t* result_offset) { - uint32_t packed = ((uint32_t)codes[0] << 10) | ((uint32_t)codes[1] << 4) | - ((uint32_t)codes[2] >> 2); - result[(*result_offset)++] = (unsigned char)(packed >> 8); - result[(*result_offset)++] = (unsigned char)(packed); + uint32_t packed = (static_cast(codes[0]) << 10) | (static_cast(codes[1]) << 4) | + (static_cast(codes[2]) >> 2); + result[(*result_offset)++] = static_cast(packed >> 8); + result[(*result_offset)++] = static_cast(packed); } static int decode_group(const unsigned char* codes, size_t num_codes, @@ -175,11 +175,11 @@ static int decode_group(const unsigned char* codes, size_t num_codes, decode_two_chars(codes, result, result_offset); } else { /* No padding. */ - uint32_t packed = ((uint32_t)codes[0] << 18) | ((uint32_t)codes[1] << 12) | - ((uint32_t)codes[2] << 6) | codes[3]; - result[(*result_offset)++] = (unsigned char)(packed >> 16); - result[(*result_offset)++] = (unsigned char)(packed >> 8); - result[(*result_offset)++] = (unsigned char)(packed); + uint32_t packed = (static_cast(codes[0]) << 18) | (static_cast(codes[1]) << 12) | + (static_cast(codes[2]) << 6) | codes[3]; + result[(*result_offset)++] = static_cast(packed >> 16); + result[(*result_offset)++] = static_cast(packed >> 8); + result[(*result_offset)++] = static_cast(packed); } return 1; } @@ -193,7 +193,7 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, size_t num_codes = 0; while (b64_len--) { - unsigned char c = (unsigned char)(*b64++); + unsigned char c = static_cast(*b64++); signed char code; if (c >= GPR_ARRAY_SIZE(base64_bytes)) continue; if (url_safe) { @@ -214,7 +214,7 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, goto fail; } } else { - codes[num_codes++] = (unsigned char)code; + codes[num_codes++] = static_cast(code); if (num_codes == 4) { if (!decode_group(codes, num_codes, current, &result_size)) goto fail; num_codes = 0; diff --git a/src/core/lib/slice/percent_encoding.cc b/src/core/lib/slice/percent_encoding.cc index 894e43b191..84fb554454 100644 --- a/src/core/lib/slice/percent_encoding.cc +++ b/src/core/lib/slice/percent_encoding.cc @@ -78,9 +78,9 @@ static bool valid_hex(const uint8_t* p, const uint8_t* end) { } static uint8_t dehex(uint8_t c) { - if (c >= '0' && c <= '9') return (uint8_t)(c - '0'); - if (c >= 'A' && c <= 'F') return (uint8_t)(c - 'A' + 10); - if (c >= 'a' && c <= 'f') return (uint8_t)(c - 'a' + 10); + if (c >= '0' && c <= '9') return static_cast(c - '0'); + if (c >= 'A' && c <= 'F') return static_cast(c - 'A' + 10); + if (c >= 'a' && c <= 'f') return static_cast(c - 'a' + 10); GPR_UNREACHABLE_CODE(return 255); } @@ -114,7 +114,7 @@ bool grpc_strict_percent_decode_slice(grpc_slice slice_in, uint8_t* q = GRPC_SLICE_START_PTR(*slice_out); while (p != in_end) { if (*p == '%') { - *q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2])); + *q++ = static_cast(dehex(p[1]) << 4) | (dehex(p[2])); p += 3; } else { *q++ = *p++; @@ -155,7 +155,7 @@ grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in) { if (!valid_hex(p + 1, in_end) || !valid_hex(p + 2, in_end)) { *q++ = *p++; } else { - *q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2])); + *q++ = static_cast(dehex(p[1]) << 4) | (dehex(p[2])); p += 3; } } else { diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 1eb15290eb..136cce1d1e 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -27,7 +27,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" char* grpc_slice_to_c_string(grpc_slice slice) { - char* out = (char*)gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1); + char* out = static_cast(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1)); memcpy(out, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); out[GRPC_SLICE_LENGTH(slice)] = 0; return out; @@ -104,12 +104,12 @@ typedef struct new_slice_refcount { } new_slice_refcount; static void new_slice_ref(void* p) { - new_slice_refcount* r = (new_slice_refcount*)p; + new_slice_refcount* r = static_cast(p); gpr_ref(&r->refs); } static void new_slice_unref(void* p) { - new_slice_refcount* r = (new_slice_refcount*)p; + new_slice_refcount* r = static_cast(p); if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data); gpr_free(r); @@ -125,7 +125,7 @@ grpc_slice grpc_slice_new_with_user_data(void* p, size_t len, void* user_data) { grpc_slice slice; new_slice_refcount* rc = - (new_slice_refcount*)gpr_malloc(sizeof(new_slice_refcount)); + static_cast(gpr_malloc(sizeof(new_slice_refcount))); gpr_ref_init(&rc->refs, 1); rc->rc.vtable = &new_slice_vtable; rc->rc.sub_refcount = &rc->rc; @@ -133,7 +133,7 @@ grpc_slice grpc_slice_new_with_user_data(void* p, size_t len, rc->user_data = user_data; slice.refcount = &rc->rc; - slice.data.refcounted.bytes = (uint8_t*)p; + slice.data.refcounted.bytes = static_cast(p); slice.data.refcounted.length = len; return slice; } @@ -154,12 +154,12 @@ typedef struct new_with_len_slice_refcount { } new_with_len_slice_refcount; static void new_with_len_ref(void* p) { - new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p; + new_with_len_slice_refcount* r = static_cast(p); gpr_ref(&r->refs); } static void new_with_len_unref(void* p) { - new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p; + new_with_len_slice_refcount* r = static_cast(p); if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data, r->user_length); gpr_free(r); @@ -173,8 +173,8 @@ static const grpc_slice_refcount_vtable new_with_len_vtable = { grpc_slice grpc_slice_new_with_len(void* p, size_t len, void (*destroy)(void*, size_t)) { grpc_slice slice; - new_with_len_slice_refcount* rc = (new_with_len_slice_refcount*)gpr_malloc( - sizeof(new_with_len_slice_refcount)); + new_with_len_slice_refcount* rc = static_cast(gpr_malloc( + sizeof(new_with_len_slice_refcount))); gpr_ref_init(&rc->refs, 1); rc->rc.vtable = &new_with_len_vtable; rc->rc.sub_refcount = &rc->rc; @@ -183,7 +183,7 @@ grpc_slice grpc_slice_new_with_len(void* p, size_t len, rc->user_length = len; slice.refcount = &rc->rc; - slice.data.refcounted.bytes = (uint8_t*)p; + slice.data.refcounted.bytes = static_cast(p); slice.data.refcounted.length = len; return slice; } @@ -205,12 +205,12 @@ typedef struct { } malloc_refcount; static void malloc_ref(void* p) { - malloc_refcount* r = (malloc_refcount*)p; + malloc_refcount* r = static_cast(p); gpr_ref(&r->refs); } static void malloc_unref(void* p) { - malloc_refcount* r = (malloc_refcount*)p; + malloc_refcount* r = static_cast(p); if (gpr_unref(&r->refs)) { gpr_free(r); } @@ -233,7 +233,7 @@ grpc_slice grpc_slice_malloc_large(size_t length) { bytes is an array of bytes of the requested length Both parts are placed in the same allocation returned from gpr_malloc */ malloc_refcount* rc = - (malloc_refcount*)gpr_malloc(sizeof(malloc_refcount) + length); + static_cast(gpr_malloc(sizeof(malloc_refcount) + length)); /* Initial refcount on rc is 1 - and it's up to the caller to release this reference. */ @@ -246,7 +246,7 @@ grpc_slice grpc_slice_malloc_large(size_t length) { /* The slices refcount points back to the allocated block. */ slice.refcount = &rc->base; /* The data bytes are placed immediately after the refcount struct */ - slice.data.refcounted.bytes = (uint8_t*)(rc + 1); + slice.data.refcounted.bytes = reinterpret_cast(rc + 1); /* And the length of the block is set to the requested length */ slice.data.refcounted.length = length; return slice; @@ -260,7 +260,7 @@ grpc_slice grpc_slice_malloc(size_t length) { } else { /* small slice: just inline the data */ slice.refcount = nullptr; - slice.data.inlined.length = (uint8_t)length; + slice.data.inlined.length = static_cast(length); } return slice; } @@ -283,7 +283,7 @@ grpc_slice grpc_slice_sub_no_ref(grpc_slice source, size_t begin, size_t end) { /* Enforce preconditions */ GPR_ASSERT(source.data.inlined.length >= end); subset.refcount = nullptr; - subset.data.inlined.length = (uint8_t)(end - begin); + subset.data.inlined.length = static_cast(end - begin); memcpy(subset.data.inlined.bytes, source.data.inlined.bytes + begin, end - begin); } @@ -295,7 +295,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) { if (end - begin <= sizeof(subset.data.inlined.bytes)) { subset.refcount = nullptr; - subset.data.inlined.length = (uint8_t)(end - begin); + subset.data.inlined.length = static_cast(end - begin); memcpy(subset.data.inlined.bytes, GRPC_SLICE_START_PTR(source) + begin, end - begin); } else { @@ -314,10 +314,10 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split, /* inlined data, copy it out */ GPR_ASSERT(source->data.inlined.length >= split); tail.refcount = nullptr; - tail.data.inlined.length = (uint8_t)(source->data.inlined.length - split); + tail.data.inlined.length = static_cast(source->data.inlined.length - split); memcpy(tail.data.inlined.bytes, source->data.inlined.bytes + split, tail.data.inlined.length); - source->data.inlined.length = (uint8_t)split; + source->data.inlined.length = static_cast(split); } else { size_t tail_length = source->data.refcounted.length - split; GPR_ASSERT(source->data.refcounted.length >= split); @@ -325,7 +325,7 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split, ref_whom != GRPC_SLICE_REF_TAIL) { /* Copy out the bytes - it'll be cheaper than refcounting */ tail.refcount = nullptr; - tail.data.inlined.length = (uint8_t)tail_length; + tail.data.inlined.length = static_cast(tail_length); memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split, tail_length); source->refcount = source->refcount->sub_refcount; @@ -368,17 +368,17 @@ grpc_slice grpc_slice_split_head(grpc_slice* source, size_t split) { GPR_ASSERT(source->data.inlined.length >= split); head.refcount = nullptr; - head.data.inlined.length = (uint8_t)split; + head.data.inlined.length = static_cast(split); memcpy(head.data.inlined.bytes, source->data.inlined.bytes, split); source->data.inlined.length = - (uint8_t)(source->data.inlined.length - split); + static_cast(source->data.inlined.length - split); memmove(source->data.inlined.bytes, source->data.inlined.bytes + split, source->data.inlined.length); } else if (split < sizeof(head.data.inlined.bytes)) { GPR_ASSERT(source->data.refcounted.length >= split); head.refcount = nullptr; - head.data.inlined.length = (uint8_t)split; + head.data.inlined.length = static_cast(split); memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split); source->refcount = source->refcount->sub_refcount; source->data.refcounted.bytes += split; @@ -416,7 +416,7 @@ int grpc_slice_eq(grpc_slice a, grpc_slice b) { } int grpc_slice_cmp(grpc_slice a, grpc_slice b) { - int d = (int)(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b)); + int d = static_cast(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b)); if (d != 0) return d; return memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), GRPC_SLICE_LENGTH(a)); @@ -424,7 +424,7 @@ int grpc_slice_cmp(grpc_slice a, grpc_slice b) { int grpc_slice_str_cmp(grpc_slice a, const char* b) { size_t b_length = strlen(b); - int d = (int)(GRPC_SLICE_LENGTH(a) - b_length); + int d = static_cast(GRPC_SLICE_LENGTH(a) - b_length); if (d != 0) return d; return memcmp(GRPC_SLICE_START_PTR(a), b, b_length); } @@ -443,17 +443,17 @@ int grpc_slice_buf_start_eq(grpc_slice a, const void* b, size_t len) { } int grpc_slice_rchr(grpc_slice s, char c) { - const char* b = (const char*)GRPC_SLICE_START_PTR(s); + const char* b = reinterpret_castGRPC_SLICE_START_PTR(s); int i; - for (i = (int)GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) + for (i = static_castGRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) ; return i; } int grpc_slice_chr(grpc_slice s, char c) { - const char* b = (const char*)GRPC_SLICE_START_PTR(s); - const char* p = (const char*)memchr(b, c, GRPC_SLICE_LENGTH(s)); - return p == nullptr ? -1 : (int)(p - b); + const char* b = reinterpret_castGRPC_SLICE_START_PTR(s); + const char* p = static_cast(memchr(b, c, GRPC_SLICE_LENGTH(s))); + return p == nullptr ? -1 : static_cast(p - b); } int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { @@ -466,12 +466,12 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { if (haystack_len < needle_len) return -1; if (haystack_len == needle_len) return grpc_slice_eq(haystack, needle) ? 0 : -1; - if (needle_len == 1) return grpc_slice_chr(haystack, (char)*needle_bytes); + if (needle_len == 1) return grpc_slice_chr(haystack, static_cast(*needle_bytes)); const uint8_t* last = haystack_bytes + haystack_len - needle_len; for (const uint8_t* cur = haystack_bytes; cur != last; ++cur) { if (0 == memcmp(cur, needle_bytes, needle_len)) { - return (int)(cur - haystack_bytes); + return static_cast(cur - haystack_bytes); } } return -1; diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 178c7f9e94..84a2b5f6d9 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -32,7 +32,7 @@ static void maybe_embiggen(grpc_slice_buffer* sb) { /* How far away from sb->base_slices is sb->slices pointer */ - size_t slice_offset = (size_t)(sb->slices - sb->base_slices); + size_t slice_offset = static_cast(sb->slices - sb->base_slices); size_t slice_count = sb->count + slice_offset; if (slice_count == sb->capacity) { @@ -46,11 +46,11 @@ static void maybe_embiggen(grpc_slice_buffer* sb) { GPR_ASSERT(sb->capacity > slice_count); if (sb->base_slices == sb->inlined) { sb->base_slices = - (grpc_slice*)gpr_malloc(sb->capacity * sizeof(grpc_slice)); + static_cast(gpr_malloc(sb->capacity * sizeof(grpc_slice))); memcpy(sb->base_slices, sb->inlined, slice_count * sizeof(grpc_slice)); } else { - sb->base_slices = (grpc_slice*)gpr_realloc( - sb->base_slices, sb->capacity * sizeof(grpc_slice)); + sb->base_slices = static_cast(gpr_realloc( + sb->base_slices, sb->capacity * sizeof(grpc_slice))); } sb->slices = sb->base_slices + slice_offset; @@ -89,7 +89,7 @@ uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t n) { if ((back->data.inlined.length + n) > sizeof(back->data.inlined.bytes)) goto add_new; out = back->data.inlined.bytes + back->data.inlined.length; - back->data.inlined.length = (uint8_t)(back->data.inlined.length + n); + back->data.inlined.length = static_cast(back->data.inlined.length + n); return out; add_new: @@ -97,7 +97,7 @@ add_new: back = &sb->slices[sb->count]; sb->count++; back->refcount = nullptr; - back->data.inlined.length = (uint8_t)n; + back->data.inlined.length = static_cast(n); return back->data.inlined.bytes; } @@ -126,7 +126,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) { memcpy(back->data.inlined.bytes + back->data.inlined.length, s.data.inlined.bytes, s.data.inlined.length); back->data.inlined.length = - (uint8_t)(back->data.inlined.length + s.data.inlined.length); + static_cast(back->data.inlined.length + s.data.inlined.length); } else { size_t cp1 = GRPC_SLICE_INLINED_SIZE - back->data.inlined.length; memcpy(back->data.inlined.bytes + back->data.inlined.length, @@ -136,7 +136,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) { back = &sb->slices[n]; sb->count = n + 1; back->refcount = nullptr; - back->data.inlined.length = (uint8_t)(s.data.inlined.length - cp1); + back->data.inlined.length = static_cast(s.data.inlined.length - cp1); memcpy(back->data.inlined.bytes, s.data.inlined.bytes + cp1, s.data.inlined.length - cp1); } @@ -177,8 +177,8 @@ void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { } void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) { - size_t a_offset = (size_t)(a->slices - a->base_slices); - size_t b_offset = (size_t)(b->slices - b->base_slices); + size_t a_offset = static_cast(a->slices - a->base_slices); + size_t b_offset = static_cast(b->slices - b->base_slices); size_t a_count = a->count + a_offset; size_t b_count = b->count + b_offset; @@ -287,7 +287,7 @@ void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n, void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, void* dst) { - char* dstp = (char*)dst; + char* dstp = static_cast(dst); GPR_ASSERT(src->length >= n); while (n > 0) { diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc index 89340eff84..1818b126ca 100644 --- a/src/core/lib/slice/slice_hash_table.cc +++ b/src/core/lib/slice/slice_hash_table.cc @@ -60,14 +60,14 @@ grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)) { grpc_slice_hash_table* table = - (grpc_slice_hash_table*)gpr_zalloc(sizeof(*table)); + static_cast(gpr_zalloc(sizeof(*table))); gpr_ref_init(&table->refs, 1); table->destroy_value = destroy_value; table->value_cmp = value_cmp; // Keep load factor low to improve performance of lookups. table->size = num_entries * 2; const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size; - table->entries = (grpc_slice_hash_table_entry*)gpr_zalloc(entry_size); + table->entries = static_cast(gpr_zalloc(entry_size)); for (size_t i = 0; i < num_entries; ++i) { grpc_slice_hash_table_entry* entry = &entries[i]; grpc_slice_hash_table_add(table, entry->key, entry->value); diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index cf471f30f8..f4aad73e0f 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -70,7 +70,7 @@ static uint32_t max_static_metadata_hash_probe; static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT]; static void interned_slice_ref(void* p) { - interned_slice_refcount* s = (interned_slice_refcount*)p; + interned_slice_refcount* s = static_cast(p); GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0); } @@ -91,22 +91,22 @@ static void interned_slice_destroy(interned_slice_refcount* s) { } static void interned_slice_unref(void* p) { - interned_slice_refcount* s = (interned_slice_refcount*)p; + interned_slice_refcount* s = static_cast(p); if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { interned_slice_destroy(s); } } static void interned_slice_sub_ref(void* p) { - interned_slice_ref(((char*)p) - offsetof(interned_slice_refcount, sub)); + interned_slice_ref((static_cast(p)) - offsetof(interned_slice_refcount, sub)); } static void interned_slice_sub_unref(void* p) { - interned_slice_unref(((char*)p) - offsetof(interned_slice_refcount, sub)); + interned_slice_unref((static_cast(p)) - offsetof(interned_slice_refcount, sub)); } static uint32_t interned_slice_hash(grpc_slice slice) { - interned_slice_refcount* s = (interned_slice_refcount*)slice.refcount; + interned_slice_refcount* s = reinterpret_cast(slice.refcount); return s->hash; } @@ -129,8 +129,8 @@ static void grow_shard(slice_shard* shard) { interned_slice_refcount** strtab; interned_slice_refcount *s, *next; - strtab = (interned_slice_refcount**)gpr_zalloc( - sizeof(interned_slice_refcount*) * capacity); + strtab = static_cast(gpr_zalloc( + sizeof(interned_slice_refcount*) * capacity)); for (i = 0; i < shard->capacity; i++) { for (s = shard->strs[i]; s; s = next) { @@ -148,7 +148,7 @@ static void grow_shard(slice_shard* shard) { static grpc_slice materialize(interned_slice_refcount* s) { grpc_slice slice; slice.refcount = &s->base; - slice.data.refcounted.bytes = (uint8_t*)(s + 1); + slice.data.refcounted.bytes = reinterpret_cast(s + 1); slice.data.refcounted.length = s->length; return slice; } @@ -237,8 +237,8 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { /* not found: create a new string */ /* string data goes after the internal_string header */ - s = (interned_slice_refcount*)gpr_malloc(sizeof(*s) + - GRPC_SLICE_LENGTH(slice)); + s = static_cast(gpr_malloc(sizeof(*s) + + GRPC_SLICE_LENGTH(slice))); gpr_atm_rel_store(&s->refcnt, 1); s->length = GRPC_SLICE_LENGTH(slice); s->hash = hash; @@ -268,15 +268,15 @@ void grpc_test_only_set_slice_hash_seed(uint32_t seed) { void grpc_slice_intern_init(void) { if (!g_forced_hash_seed) { - g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; + g_hash_seed = static_cast(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); } for (size_t i = 0; i < SHARD_COUNT; i++) { slice_shard* shard = &g_shards[i]; gpr_mu_init(&shard->mu); shard->count = 0; shard->capacity = INITIAL_SHARD_CAPACITY; - shard->strs = (interned_slice_refcount**)gpr_zalloc(sizeof(*shard->strs) * - shard->capacity); + shard->strs = static_cast(gpr_zalloc(sizeof(*shard->strs) * + shard->capacity)); } for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) { static_metadata_hash[i].hash = 0; @@ -291,9 +291,9 @@ void grpc_slice_intern_init(void) { GPR_ARRAY_SIZE(static_metadata_hash); if (static_metadata_hash[slot].idx == GRPC_STATIC_MDSTR_COUNT) { static_metadata_hash[slot].hash = static_metadata_hash_values[i]; - static_metadata_hash[slot].idx = (uint32_t)i; + static_metadata_hash[slot].idx = static_cast(i); if (j > max_static_metadata_hash_probe) { - max_static_metadata_hash_probe = (uint32_t)j; + max_static_metadata_hash_probe = static_cast(j); } break; } diff --git a/src/core/lib/slice/slice_string_helpers.cc b/src/core/lib/slice/slice_string_helpers.cc index 4441a26d8e..2015040c12 100644 --- a/src/core/lib/slice/slice_string_helpers.cc +++ b/src/core/lib/slice/slice_string_helpers.cc @@ -26,7 +26,7 @@ #include "src/core/lib/slice/slice_internal.h" char* grpc_dump_slice(grpc_slice s, uint32_t flags) { - return gpr_dump((const char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), + return gpr_dump(reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), flags); } @@ -110,6 +110,6 @@ void grpc_slice_split_without_space(grpc_slice str, const char* sep, } bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t* result) { - return gpr_parse_bytes_to_uint32((const char*)GRPC_SLICE_START_PTR(str), + return gpr_parse_bytes_to_uint32(reinterpret_castGRPC_SLICE_START_PTR(str), GRPC_SLICE_LENGTH(str), result) != 0; } diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc index e4c2a4a4c2..01cbf7354a 100644 --- a/src/core/lib/surface/byte_buffer.cc +++ b/src/core/lib/surface/byte_buffer.cc @@ -33,7 +33,7 @@ grpc_byte_buffer* grpc_raw_compressed_byte_buffer_create( grpc_compression_algorithm compression) { size_t i; grpc_byte_buffer* bb = - (grpc_byte_buffer*)gpr_malloc(sizeof(grpc_byte_buffer)); + static_cast(gpr_malloc(sizeof(grpc_byte_buffer))); bb->type = GRPC_BB_RAW; bb->data.raw.compression = compression; grpc_slice_buffer_init(&bb->data.raw.slice_buffer); @@ -47,7 +47,7 @@ grpc_byte_buffer* grpc_raw_compressed_byte_buffer_create( grpc_byte_buffer* grpc_raw_byte_buffer_from_reader( grpc_byte_buffer_reader* reader) { grpc_byte_buffer* bb = - (grpc_byte_buffer*)gpr_malloc(sizeof(grpc_byte_buffer)); + static_cast(gpr_malloc(sizeof(grpc_byte_buffer))); grpc_slice slice; bb->type = GRPC_BB_RAW; bb->data.raw.compression = GRPC_COMPRESS_NONE; diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index a7b932b46d..d6949103c7 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -97,7 +97,7 @@ static received_status unpack_received_status(gpr_atm atm) { if ((atm & 1) == 0) { return {false, GRPC_ERROR_NONE}; } else { - return {true, (grpc_error*)(atm & ~(gpr_atm)1)}; + return {true, (grpc_error*)(atm & ~static_cast(1))}; } } @@ -304,7 +304,7 @@ void* grpc_call_arena_alloc(grpc_call* call, size_t size) { static parent_call* get_or_create_parent_call(grpc_call* call) { parent_call* p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); if (p == nullptr) { - p = (parent_call*)gpr_arena_alloc(call->arena, sizeof(*p)); + p = static_cast(gpr_arena_alloc(call->arena, sizeof(*p))); gpr_mu_init(&p->child_list_mu); if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm) nullptr, (gpr_atm)p)) { @@ -330,8 +330,8 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, size_t initial_size = grpc_channel_get_call_size_estimate(args->channel); GRPC_STATS_INC_CALL_INITIAL_SIZE(initial_size); gpr_arena* arena = gpr_arena_create(initial_size); - call = (grpc_call*)gpr_arena_alloc( - arena, sizeof(grpc_call) + channel_stack->call_stack_size); + call = static_cast(gpr_arena_alloc( + arena, sizeof(grpc_call) + channel_stack->call_stack_size)); gpr_ref_init(&call->ext_ref, 1); call->arena = arena; grpc_call_combiner_init(&call->call_combiner); @@ -360,7 +360,7 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, GRPC_MDVALUE(args->add_initial_metadata[i])); } } - call->send_extra_metadata_count = (int)args->add_initial_metadata_count; + call->send_extra_metadata_count = static_cast(args->add_initial_metadata_count); } else { GPR_ASSERT(args->add_initial_metadata_count == 0); call->send_extra_metadata_count = 0; @@ -376,7 +376,7 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, if (args->parent != nullptr) { child_call* cc = call->child = - (child_call*)gpr_arena_alloc(arena, sizeof(child_call)); + static_cast(gpr_arena_alloc(arena, sizeof(child_call))); call->child->parent = args->parent; GRPC_CALL_INTERNAL_REF(args->parent, "child"); @@ -500,7 +500,7 @@ void grpc_call_internal_unref(grpc_call* c REF_ARG) { } static void release_call(void* call, grpc_error* error) { - grpc_call* c = (grpc_call*)call; + grpc_call* c = static_cast(call); grpc_channel* channel = c->channel; grpc_call_combiner_destroy(&c->call_combiner); gpr_free((char*)c->peer_string); @@ -513,7 +513,7 @@ static void destroy_call(void* call, grpc_error* error) { GPR_TIMER_SCOPE("destroy_call", 0); size_t i; int ii; - grpc_call* c = (grpc_call*)call; + grpc_call* c = static_cast(call); for (i = 0; i < 2; i++) { grpc_metadata_batch_destroy( &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); @@ -608,8 +608,8 @@ grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { // the filter stack. static void execute_batch_in_call_combiner(void* arg, grpc_error* ignored) { GPR_TIMER_SCOPE("execute_batch", 0); - grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; - grpc_call* call = (grpc_call*)batch->handler_private.extra_arg; + grpc_transport_stream_op_batch* batch = static_cast(arg); + grpc_call* call = static_cast(batch->handler_private.extra_arg); grpc_call_element* elem = CALL_ELEM_FROM_CALL(call, 0); GRPC_CALL_LOG_OP(GPR_INFO, elem, batch); elem->filter->start_transport_stream_op_batch(elem, batch); @@ -667,7 +667,7 @@ typedef struct { // The on_complete callback used when sending a cancel_stream batch down // the filter stack. Yields the call combiner when the batch is done. static void done_termination(void* arg, grpc_error* error) { - cancel_state* state = (cancel_state*)arg; + cancel_state* state = static_cast(arg); GRPC_CALL_COMBINER_STOP(&state->call->call_combiner, "on_complete for cancel_stream op"); GRPC_CALL_INTERNAL_UNREF(state->call, "termination"); @@ -683,7 +683,7 @@ static void cancel_with_error(grpc_call* c, status_source source, // down the filter stack in a timely manner. grpc_call_combiner_cancel(&c->call_combiner, GRPC_ERROR_REF(error)); set_status_from_error(c, source, GRPC_ERROR_REF(error)); - cancel_state* state = (cancel_state*)gpr_malloc(sizeof(*state)); + cancel_state* state = static_cast(gpr_malloc(sizeof(*state))); state->call = c; GRPC_CLOSURE_INIT(&state->finish_batch, done_termination, state, grpc_schedule_on_exec_ctx); @@ -845,7 +845,7 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel, grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); if (accepted_user_data != nullptr) { *encodings_accepted_by_peer = - (uint32_t)(((uintptr_t)accepted_user_data) - 1); + static_cast(((uintptr_t)accepted_user_data) - 1); return; } @@ -863,11 +863,11 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel, if (!stream_encoding) { r = grpc_message_compression_algorithm_parse( accept_encoding_entry_slice, - (grpc_message_compression_algorithm*)&algorithm); + reinterpret_cast(&algorithm)); } else { r = grpc_stream_compression_algorithm_parse( accept_encoding_entry_slice, - (grpc_stream_compression_algorithm*)&algorithm); + reinterpret_cast(&algorithm)); } if (r) { GPR_BITSET(encodings_accepted_by_peer, algorithm); @@ -885,7 +885,7 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel, grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, - (void*)(((uintptr_t)(*encodings_accepted_by_peer)) + 1)); + (void*)((static_cast(*encodings_accepted_by_peer)) + 1)); } uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call* call) { @@ -936,7 +936,7 @@ static int prepare_application_metadata(grpc_call* call, int count, grpc_validate_header_nonbin_value_is_legal(md->value))) { break; } - l->md = grpc_mdelem_from_grpc_metadata((grpc_metadata*)md); + l->md = grpc_mdelem_from_grpc_metadata(const_cast(md)); } if (i != total_count) { for (int j = 0; j < i; j++) { @@ -986,13 +986,13 @@ static uint32_t decode_status(grpc_mdelem md) { if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_2)) return 2; user_data = grpc_mdelem_get_user_data(md, destroy_status); if (user_data != nullptr) { - status = ((uint32_t)(intptr_t)user_data) - STATUS_OFFSET; + status = (static_cast((intptr_t)user_data)) - STATUS_OFFSET; } else { if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(md), &status)) { status = GRPC_STATUS_UNKNOWN; /* could not parse status code */ } grpc_mdelem_set_user_data(md, destroy_status, - (void*)(intptr_t)(status + STATUS_OFFSET)); + (void*)static_cast(status + STATUS_OFFSET)); } return status; } @@ -1040,8 +1040,8 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, if (dest->count + b->list.count > dest->capacity) { dest->capacity = GPR_MAX(dest->capacity + b->list.count, dest->capacity * 3 / 2); - dest->metadata = (grpc_metadata*)gpr_realloc( - dest->metadata, sizeof(grpc_metadata) * dest->capacity); + dest->metadata = static_cast(gpr_realloc( + dest->metadata, sizeof(grpc_metadata) * dest->capacity)); } for (grpc_linked_mdelem* l = b->list.head; l != nullptr; l = l->next) { mdusr = &dest->metadata[dest->count++]; @@ -1086,7 +1086,7 @@ static void recv_initial_filter(grpc_call* call, grpc_metadata_batch* b) { } static void recv_trailing_filter(void* args, grpc_metadata_batch* b) { - grpc_call* call = (grpc_call*)args; + grpc_call* call = static_cast(args); if (b->idx.named.grpc_status != nullptr) { uint32_t status_code = decode_status(b->idx.named.grpc_status->md); grpc_error* error = @@ -1095,7 +1095,7 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b) { : grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error received from peer"), GRPC_ERROR_INT_GRPC_STATUS, - (intptr_t)status_code); + static_cast(status_code)); if (b->idx.named.grpc_message != nullptr) { error = grpc_error_set_str( error, GRPC_ERROR_STR_GRPC_MESSAGE, @@ -1120,11 +1120,11 @@ grpc_call_stack* grpc_call_get_call_stack(grpc_call* call) { */ static void set_status_value_directly(grpc_status_code status, void* dest) { - *(grpc_status_code*)dest = status; + *static_cast(dest) = status; } static void set_cancelled_value(grpc_status_code status, void* dest) { - *(int*)dest = (status != GRPC_STATUS_OK); + *static_cast(dest) = (status != GRPC_STATUS_OK); } static bool are_write_flags_valid(uint32_t flags) { @@ -1171,7 +1171,7 @@ static batch_control* allocate_batch_control(grpc_call* call, batch_control** pslot = &call->active_batches[slot]; if (*pslot == nullptr) { *pslot = - (batch_control*)gpr_arena_alloc(call->arena, sizeof(batch_control)); + static_cast(gpr_arena_alloc(call->arena, sizeof(batch_control))); } batch_control* bctl = *pslot; if (bctl->call != nullptr) { @@ -1185,14 +1185,14 @@ static batch_control* allocate_batch_control(grpc_call* call, static void finish_batch_completion(void* user_data, grpc_cq_completion* storage) { - batch_control* bctl = (batch_control*)user_data; + batch_control* bctl = static_cast(user_data); grpc_call* call = bctl->call; bctl->call = nullptr; GRPC_CALL_INTERNAL_UNREF(call, "completion"); } static grpc_error* consolidate_batch_errors(batch_control* bctl) { - size_t n = (size_t)gpr_atm_acq_load(&bctl->num_errors); + size_t n = static_castgpr_atm_acq_load(&bctl->num_errors); if (n == 0) { return GRPC_ERROR_NONE; } else if (n == 1) { @@ -1332,7 +1332,7 @@ static void continue_receiving_slices(batch_control* bctl) { } static void receiving_slice_ready(void* bctlp, grpc_error* error) { - batch_control* bctl = (batch_control*)bctlp; + batch_control* bctl = static_cast(bctlp); grpc_call* call = bctl->call; grpc_byte_stream* bs = call->receiving_stream; bool release_error = false; @@ -1395,7 +1395,7 @@ static void process_data_after_md(batch_control* bctl) { } static void receiving_stream_ready(void* bctlp, grpc_error* error) { - batch_control* bctl = (batch_control*)bctlp; + batch_control* bctl = static_cast(bctlp); grpc_call* call = bctl->call; if (error != GRPC_ERROR_NONE) { if (call->receiving_stream != nullptr) { @@ -1419,7 +1419,7 @@ static void receiving_stream_ready(void* bctlp, grpc_error* error) { // before processing the received message. static void receiving_stream_ready_in_call_combiner(void* bctlp, grpc_error* error) { - batch_control* bctl = (batch_control*)bctlp; + batch_control* bctl = static_cast(bctlp); grpc_call* call = bctl->call; GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_message_ready"); receiving_stream_ready(bctlp, error); @@ -1495,7 +1495,7 @@ static void validate_filtered_metadata(batch_control* bctl) { static void add_batch_error(batch_control* bctl, grpc_error* error, bool has_cancelled) { if (error == GRPC_ERROR_NONE) return; - int idx = (int)gpr_atm_full_fetch_add(&bctl->num_errors, 1); + int idx = static_cast(gpr_atm_full_fetch_add(&bctl->num_errors, 1)); if (idx == 0 && !has_cancelled) { cancel_with_error(bctl->call, STATUS_FROM_CORE, GRPC_ERROR_REF(error)); } @@ -1503,7 +1503,7 @@ static void add_batch_error(batch_control* bctl, grpc_error* error, } static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) { - batch_control* bctl = (batch_control*)bctlp; + batch_control* bctl = static_cast(bctlp); grpc_call* call = bctl->call; GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_initial_metadata_ready"); @@ -1555,7 +1555,7 @@ static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) { } static void finish_batch(void* bctlp, grpc_error* error) { - batch_control* bctl = (batch_control*)bctlp; + batch_control* bctl = static_cast(bctlp); grpc_call* call = bctl->call; GRPC_CALL_COMBINER_STOP(&call->call_combiner, "on_complete"); add_batch_error(bctl, GRPC_ERROR_REF(error), false); @@ -1586,7 +1586,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag)); grpc_cq_end_op( call->cq, notify_tag, GRPC_ERROR_NONE, free_no_op_completion, nullptr, - (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); + static_cast(gpr_malloc(sizeof(grpc_cq_completion)))); } else { GRPC_CLOSURE_SCHED((grpc_closure*)notify_tag, GRPC_ERROR_NONE); } @@ -1600,7 +1600,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, } bctl->completion_data.notify_tag.tag = notify_tag; bctl->completion_data.notify_tag.is_closure = - (uint8_t)(is_notify_tag_closure != 0); + static_cast(is_notify_tag_closure != 0); stream_op = &bctl->op; stream_op_payload = &call->stream_op_payload; @@ -1660,9 +1660,9 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, stream_op->send_initial_metadata = true; call->sent_initial_metadata = true; if (!prepare_application_metadata( - call, (int)op->data.send_initial_metadata.count, + call, static_cast(op->data.send_initial_metadata.count), op->data.send_initial_metadata.metadata, 0, call->is_client, - &call->compression_md, (int)additional_metadata_count)) { + &call->compression_md, static_cast(additional_metadata_count))) { error = GRPC_CALL_ERROR_INVALID_METADATA; goto done_with_error; } @@ -1779,7 +1779,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, } if (!prepare_application_metadata( call, - (int)op->data.send_status_from_server.trailing_metadata_count, + static_cast(op->data.send_status_from_server.trailing_metadata_count), op->data.send_status_from_server.trailing_metadata, 1, 1, nullptr, 0)) { for (int n = 0; n < call->send_extra_metadata_count; n++) { diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 679666bc5f..06dbfdcb49 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -85,7 +85,7 @@ grpc_channel* grpc_channel_create_with_builder( } grpc_error* error = grpc_channel_stack_builder_finish( builder, sizeof(grpc_channel), 1, destroy_channel, nullptr, - (void**)&channel); + reinterpret_cast(&channel)); if (error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "channel stack builder failed: %s", grpc_error_string(error)); @@ -157,7 +157,7 @@ grpc_channel* grpc_channel_create_with_builder( strcmp(args->args[i].key, GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET)) { channel->compression_options.enabled_algorithms_bitset = - (uint32_t)args->args[i].value.integer | + static_cast(args->args[i].value.integer) | 0x1; /* always support no compression */ } } @@ -190,26 +190,26 @@ size_t grpc_channel_get_call_size_estimate(grpc_channel* channel) { (which is common) - which tends to help most allocators reuse memory 2. a small amount of allowed growth over the estimate without hitting the arena size doubling case, reducing overall memory usage */ - return ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) + + return (static_castgpr_atm_no_barrier_load(&channel->call_size_estimate) + 2 * ROUND_UP_SIZE) & - ~(size_t)(ROUND_UP_SIZE - 1); + ~static_cast(ROUND_UP_SIZE - 1); } void grpc_channel_update_call_size_estimate(grpc_channel* channel, size_t size) { - size_t cur = (size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate); + size_t cur = static_castgpr_atm_no_barrier_load(&channel->call_size_estimate); if (cur < size) { /* size grew: update estimate */ - gpr_atm_no_barrier_cas(&channel->call_size_estimate, (gpr_atm)cur, - (gpr_atm)size); + gpr_atm_no_barrier_cas(&channel->call_size_estimate, static_cast(cur), + static_cast(size)); /* if we lose: never mind, something else will likely update soon enough */ } else if (cur == size) { /* no change: holding pattern */ } else if (cur > 0) { /* size shrank: decrease estimate */ gpr_atm_no_barrier_cas( - &channel->call_size_estimate, (gpr_atm)cur, - (gpr_atm)(GPR_MIN(cur - 1, (255 * cur + size) / 256))); + &channel->call_size_estimate, static_cast(cur), + static_cast(GPR_MIN(cur - 1, (255 * cur + size) / 256))); /* if we lose: never mind, something else will likely update soon enough */ } } @@ -297,7 +297,7 @@ grpc_call* grpc_channel_create_pollset_set_call( void* grpc_channel_register_call(grpc_channel* channel, const char* method, const char* host, void* reserved) { - registered_call* rc = (registered_call*)gpr_malloc(sizeof(registered_call)); + registered_call* rc = static_cast(gpr_malloc(sizeof(registered_call))); GRPC_API_TRACE( "grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)", 4, (channel, method, host, reserved)); @@ -324,7 +324,7 @@ grpc_call* grpc_channel_create_registered_call( grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask, grpc_completion_queue* completion_queue, void* registered_call_handle, gpr_timespec deadline, void* reserved) { - registered_call* rc = (registered_call*)registered_call_handle; + registered_call* rc = static_cast(registered_call_handle); GRPC_API_TRACE( "grpc_channel_create_registered_call(" "channel=%p, parent_call=%p, propagation_mask=%x, completion_queue=%p, " @@ -362,7 +362,7 @@ void grpc_channel_internal_unref(grpc_channel* c REF_ARG) { } static void destroy_channel(void* arg, grpc_error* error) { - grpc_channel* channel = (grpc_channel*)arg; + grpc_channel* channel = static_cast(arg); grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel)); while (channel->registered_calls) { registered_call* rc = channel->registered_calls; diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index 99690e63b4..6b63195272 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -52,9 +52,9 @@ void grpc_channel_init_register_stage(grpc_channel_stack_type type, GPR_ASSERT(!g_finalized); if (g_slots[type].cap_slots == g_slots[type].num_slots) { g_slots[type].cap_slots = GPR_MAX(8, 3 * g_slots[type].cap_slots / 2); - g_slots[type].slots = (stage_slot*)gpr_realloc( + g_slots[type].slots = static_cast(gpr_realloc( g_slots[type].slots, - g_slots[type].cap_slots * sizeof(*g_slots[type].slots)); + g_slots[type].cap_slots * sizeof(*g_slots[type].slots))); } stage_slot* s = &g_slots[type].slots[g_slots[type].num_slots++]; s->insertion_order = g_slots[type].num_slots; @@ -64,8 +64,8 @@ void grpc_channel_init_register_stage(grpc_channel_stack_type type, } static int compare_slots(const void* a, const void* b) { - const stage_slot* sa = (const stage_slot*)a; - const stage_slot* sb = (const stage_slot*)b; + const stage_slot* sa = static_cast(a); + const stage_slot* sb = static_cast(b); int c = GPR_ICMP(sa->priority, sb->priority); if (c != 0) return c; @@ -84,7 +84,7 @@ void grpc_channel_init_finalize(void) { void grpc_channel_init_shutdown(void) { for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) { gpr_free(g_slots[i].slots); - g_slots[i].slots = (stage_slot*)(void*)(uintptr_t)0xdeadbeef; + g_slots[i].slots = static_cast((void*)static_cast(0xdeadbeef)); } } diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc index a030d8d0f0..513519d991 100644 --- a/src/core/lib/surface/channel_ping.cc +++ b/src/core/lib/surface/channel_ping.cc @@ -38,7 +38,7 @@ static void ping_destroy(void* arg, grpc_cq_completion* storage) { } static void ping_done(void* arg, grpc_error* error) { - ping_result* pr = (ping_result*)arg; + ping_result* pr = static_cast(arg); grpc_cq_end_op(pr->cq, pr->tag, GRPC_ERROR_REF(error), ping_destroy, pr, &pr->completion_storage); } @@ -48,7 +48,7 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, GRPC_API_TRACE("grpc_channel_ping(channel=%p, cq=%p, tag=%p, reserved=%p)", 4, (channel, cq, tag, reserved)); grpc_transport_op* op = grpc_make_transport_op(nullptr); - ping_result* pr = (ping_result*)gpr_malloc(sizeof(*pr)); + ping_result* pr = static_cast(gpr_malloc(sizeof(*pr))); grpc_channel_element* top_elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); grpc_core::ExecCtx exec_ctx; diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index a2c52082c2..2f4bcc357c 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -88,24 +88,24 @@ static size_t non_polling_poller_size(void) { } static void non_polling_poller_init(grpc_pollset* pollset, gpr_mu** mu) { - non_polling_poller* npp = (non_polling_poller*)pollset; + non_polling_poller* npp = reinterpret_cast(pollset); gpr_mu_init(&npp->mu); *mu = &npp->mu; } static void non_polling_poller_destroy(grpc_pollset* pollset) { - non_polling_poller* npp = (non_polling_poller*)pollset; + non_polling_poller* npp = reinterpret_cast(pollset); gpr_mu_destroy(&npp->mu); } static grpc_error* non_polling_poller_work(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline) { - non_polling_poller* npp = (non_polling_poller*)pollset; + non_polling_poller* npp = reinterpret_cast(pollset); if (npp->shutdown) return GRPC_ERROR_NONE; non_polling_worker w; gpr_cv_init(&w.cv); - if (worker != nullptr) *worker = (grpc_pollset_worker*)&w; + if (worker != nullptr) *worker = reinterpret_cast(&w); if (npp->root == nullptr) { npp->root = w.next = w.prev = &w; } else { @@ -138,11 +138,11 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset, static grpc_error* non_polling_poller_kick( grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { - non_polling_poller* p = (non_polling_poller*)pollset; + non_polling_poller* p = reinterpret_cast(pollset); if (specific_worker == nullptr) - specific_worker = (grpc_pollset_worker*)p->root; + specific_worker = reinterpret_cast(p->root); if (specific_worker != nullptr) { - non_polling_worker* w = (non_polling_worker*)specific_worker; + non_polling_worker* w = reinterpret_cast(specific_worker); if (!w->kicked) { w->kicked = true; gpr_cv_signal(&w->cv); @@ -153,7 +153,7 @@ static grpc_error* non_polling_poller_kick( static void non_polling_poller_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - non_polling_poller* p = (non_polling_poller*)pollset; + non_polling_poller* p = reinterpret_cast(pollset); GPR_ASSERT(closure != nullptr); p->shutdown = closure; if (p->root == nullptr) { @@ -354,10 +354,10 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, (grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) { *tag = storage->tag; grpc_core::ExecCtx exec_ctx; - *ok = (storage->next & (uintptr_t)(1)) == 1; + *ok = (storage->next & static_cast(1)) == 1; storage->done(storage->done_arg, storage); ret = 1; - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + cq_next_data* cqd = static_castDATA_FROM_CQ(cq); if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_mu_lock(cq->mu); @@ -383,7 +383,7 @@ static void cq_event_queue_destroy(grpc_cq_event_queue* q) { } static bool cq_event_queue_push(grpc_cq_event_queue* q, grpc_cq_completion* c) { - gpr_mpscq_push(&q->queue, (gpr_mpscq_node*)c); + gpr_mpscq_push(&q->queue, reinterpret_cast(c)); return gpr_atm_no_barrier_fetch_add(&q->num_queue_items, 1) == 0; } @@ -395,7 +395,7 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(); bool is_empty = false; - c = (grpc_cq_completion*)gpr_mpscq_pop_and_check_end(&q->queue, &is_empty); + c = reinterpret_cast(gpr_mpscq_pop_and_check_end(&q->queue, &is_empty)); gpr_spinlock_unlock(&q->queue_lock); if (c == nullptr && !is_empty) { @@ -415,7 +415,7 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { /* Note: The counter is not incremented/decremented atomically with push/pop. * The count is only eventually consistent */ static long cq_event_queue_num_items(grpc_cq_event_queue* q) { - return (long)gpr_atm_no_barrier_load(&q->num_queue_items); + return static_castgpr_atm_no_barrier_load(&q->num_queue_items); } grpc_completion_queue* grpc_completion_queue_create_internal( @@ -437,9 +437,9 @@ grpc_completion_queue* grpc_completion_queue_create_internal( grpc_core::ExecCtx exec_ctx; GRPC_STATS_INC_CQS_CREATED(); - cq = (grpc_completion_queue*)gpr_zalloc(sizeof(grpc_completion_queue) + + cq = static_cast(gpr_zalloc(sizeof(grpc_completion_queue) + vtable->data_size + - poller_vtable->size()); + poller_vtable->size())); cq->vtable = vtable; cq->poller_vtable = poller_vtable; @@ -456,7 +456,7 @@ grpc_completion_queue* grpc_completion_queue_create_internal( } static void cq_init_next(void* ptr) { - cq_next_data* cqd = (cq_next_data*)ptr; + cq_next_data* cqd = static_cast(ptr); /* Initial count is dropped by grpc_completion_queue_shutdown */ gpr_atm_no_barrier_store(&cqd->pending_events, 1); cqd->shutdown_called = false; @@ -465,13 +465,13 @@ static void cq_init_next(void* ptr) { } static void cq_destroy_next(void* ptr) { - cq_next_data* cqd = (cq_next_data*)ptr; + cq_next_data* cqd = static_cast(ptr); GPR_ASSERT(cq_event_queue_num_items(&cqd->queue) == 0); cq_event_queue_destroy(&cqd->queue); } static void cq_init_pluck(void* ptr) { - cq_pluck_data* cqd = (cq_pluck_data*)ptr; + cq_pluck_data* cqd = static_cast(ptr); /* Initial count is dropped by grpc_completion_queue_shutdown */ gpr_atm_no_barrier_store(&cqd->pending_events, 1); cqd->completed_tail = &cqd->completed_head; @@ -483,7 +483,7 @@ static void cq_init_pluck(void* ptr) { } static void cq_destroy_pluck(void* ptr) { - cq_pluck_data* cqd = (cq_pluck_data*)ptr; + cq_pluck_data* cqd = static_cast(ptr); GPR_ASSERT(cqd->completed_head.next == (uintptr_t)&cqd->completed_head); } @@ -515,7 +515,7 @@ void grpc_cq_internal_ref(grpc_completion_queue* cq) { } static void on_pollset_shutdown_done(void* arg, grpc_error* error) { - grpc_completion_queue* cq = (grpc_completion_queue*)arg; + grpc_completion_queue* cq = static_cast(arg); GRPC_CQ_INTERNAL_UNREF(cq, "pollset_destroy"); } @@ -548,7 +548,7 @@ static void cq_check_tag(grpc_completion_queue* cq, void* tag, bool lock_cq) { gpr_mu_lock(cq->mu); } - for (int i = 0; i < (int)cq->outstanding_tag_count; i++) { + for (int i = 0; i < static_cast(cq->outstanding_tag_count); i++) { if (cq->outstanding_tags[i] == tag) { cq->outstanding_tag_count--; GPR_SWAP(void*, cq->outstanding_tags[i], @@ -587,12 +587,12 @@ static bool atm_inc_if_nonzero(gpr_atm* counter) { } static bool cq_begin_op_for_next(grpc_completion_queue* cq, void* tag) { - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + cq_next_data* cqd = static_castDATA_FROM_CQ(cq); return atm_inc_if_nonzero(&cqd->pending_events); } static bool cq_begin_op_for_pluck(grpc_completion_queue* cq, void* tag) { - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); return atm_inc_if_nonzero(&cqd->pending_events); } @@ -601,9 +601,9 @@ bool grpc_cq_begin_op(grpc_completion_queue* cq, void* tag) { gpr_mu_lock(cq->mu); if (cq->outstanding_tag_count == cq->outstanding_tag_capacity) { cq->outstanding_tag_capacity = GPR_MAX(4, 2 * cq->outstanding_tag_capacity); - cq->outstanding_tags = (void**)gpr_realloc( + cq->outstanding_tags = static_cast(gpr_realloc( cq->outstanding_tags, - sizeof(*cq->outstanding_tags) * cq->outstanding_tag_capacity); + sizeof(*cq->outstanding_tags) * cq->outstanding_tag_capacity)); } cq->outstanding_tags[cq->outstanding_tag_count++] = tag; gpr_mu_unlock(cq->mu); @@ -632,13 +632,13 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } } - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + cq_next_data* cqd = static_castDATA_FROM_CQ(cq); int is_success = (error == GRPC_ERROR_NONE); storage->tag = tag; storage->done = done; storage->done_arg = done_arg; - storage->next = (uintptr_t)(is_success); + storage->next = static_cast(is_success); cq_check_tag(cq, tag, true); /* Used in debug builds only */ @@ -701,7 +701,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, void* done_arg, grpc_cq_completion* storage) { GPR_TIMER_SCOPE("cq_end_op_for_pluck", 0); - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); int is_success = (error == GRPC_ERROR_NONE); if (grpc_api_trace.enabled() || @@ -719,7 +719,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, storage->tag = tag; storage->done = done; storage->done_arg = done_arg; - storage->next = ((uintptr_t)&cqd->completed_head) | ((uintptr_t)(is_success)); + storage->next = ((uintptr_t)&cqd->completed_head) | (static_cast(is_success)); gpr_mu_lock(cq->mu); cq_check_tag(cq, tag, false); /* Used in debug builds only */ @@ -727,7 +727,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, /* Add to the list of completions */ gpr_atm_no_barrier_fetch_add(&cqd->things_queued_ever, 1); cqd->completed_tail->next = - ((uintptr_t)storage) | (1u & (uintptr_t)cqd->completed_tail->next); + ((uintptr_t)storage) | (1u & cqd->completed_tail->next); cqd->completed_tail = storage; if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { @@ -778,9 +778,9 @@ class ExecCtxNext : public grpc_core::ExecCtx { ExecCtxNext(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} bool CheckReadyToFinish() override { - cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; + cq_is_finished_arg* a = static_cast(check_ready_to_finish_arg_); grpc_completion_queue* cq = a->cq; - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + cq_next_data* cqd = static_castDATA_FROM_CQ(cq); GPR_ASSERT(a->stolen_completion == nullptr); gpr_atm current_last_seen_things_queued_ever = @@ -836,7 +836,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, GPR_TIMER_SCOPE("grpc_completion_queue_next", 0); grpc_event ret; - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + cq_next_data* cqd = static_castDATA_FROM_CQ(cq); GRPC_API_TRACE( "grpc_completion_queue_next(" @@ -961,7 +961,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, - grpc_completion_queue_shutdown() MUST have been called before calling this function */ static void cq_finish_shutdown_next(grpc_completion_queue* cq) { - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + cq_next_data* cqd = static_castDATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(gpr_atm_no_barrier_load(&cqd->pending_events) == 0); @@ -970,7 +970,7 @@ static void cq_finish_shutdown_next(grpc_completion_queue* cq) { } static void cq_shutdown_next(grpc_completion_queue* cq) { - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + cq_next_data* cqd = static_castDATA_FROM_CQ(cq); /* Need an extra ref for cq here because: * We call cq_finish_shutdown_next() below, that would call pollset shutdown. @@ -1003,7 +1003,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue* cq, static int add_plucker(grpc_completion_queue* cq, void* tag, grpc_pollset_worker** worker) { - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); if (cqd->num_pluckers == GRPC_MAX_COMPLETION_QUEUE_PLUCKERS) { return 0; } @@ -1015,7 +1015,7 @@ static int add_plucker(grpc_completion_queue* cq, void* tag, static void del_plucker(grpc_completion_queue* cq, void* tag, grpc_pollset_worker** worker) { - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); for (int i = 0; i < cqd->num_pluckers; i++) { if (cqd->pluckers[i].tag == tag && cqd->pluckers[i].worker == worker) { cqd->num_pluckers--; @@ -1031,9 +1031,9 @@ class ExecCtxPluck : public grpc_core::ExecCtx { ExecCtxPluck(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} bool CheckReadyToFinish() override { - cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; + cq_is_finished_arg* a = static_cast(check_ready_to_finish_arg_); grpc_completion_queue* cq = a->cq; - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); GPR_ASSERT(a->stolen_completion == nullptr); gpr_atm current_last_seen_things_queued_ever = @@ -1045,10 +1045,10 @@ class ExecCtxPluck : public grpc_core::ExecCtx { gpr_atm_no_barrier_load(&cqd->things_queued_ever); grpc_cq_completion* c; grpc_cq_completion* prev = &cqd->completed_head; - while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != + while ((c = (grpc_cq_completion*)(prev->next & ~static_cast(1))) != &cqd->completed_head) { if (c->tag == a->tag) { - prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); + prev->next = (prev->next & static_cast(1)) | (c->next & ~static_cast(1)); if (c == cqd->completed_tail) { cqd->completed_tail = prev; } @@ -1075,7 +1075,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, grpc_cq_completion* c; grpc_cq_completion* prev; grpc_pollset_worker* worker = nullptr; - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); if (grpc_cq_pluck_trace.enabled()) { GRPC_API_TRACE( @@ -1115,10 +1115,10 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, break; } prev = &cqd->completed_head; - while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != + while ((c = (grpc_cq_completion*)(prev->next & ~static_cast(1))) != &cqd->completed_head) { if (c->tag == tag) { - prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); + prev->next = (prev->next & static_cast(1)) | (c->next & ~static_cast(1)); if (c == cqd->completed_tail) { cqd->completed_tail = prev; } @@ -1191,7 +1191,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, } static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) { - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(!gpr_atm_no_barrier_load(&cqd->shutdown)); @@ -1203,7 +1203,7 @@ static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) { /* NOTE: This function is almost exactly identical to cq_shutdown_next() but * merging them is a bit tricky and probably not worth it */ static void cq_shutdown_pluck(grpc_completion_queue* cq) { - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); /* Need an extra ref for cq here because: * We call cq_finish_shutdown_pluck() below, that would call pollset shutdown. diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 7f7947faaa..46bf266740 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -74,12 +74,12 @@ static void do_basic_init(void) { static bool append_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter*)arg, nullptr, nullptr); + builder, static_cast(arg), nullptr, nullptr); } static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, nullptr, nullptr); + builder, static_cast(arg), nullptr, nullptr); } static void register_builtin_channel_init() { diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 1e59434aa5..ad3ee62ad8 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -242,7 +242,7 @@ static void channel_broadcaster_init(grpc_server* s, channel_broadcaster* cb) { } cb->num_channels = count; cb->channels = - (grpc_channel**)gpr_malloc(sizeof(*cb->channels) * cb->num_channels); + static_cast(gpr_malloc(sizeof(*cb->channels) * cb->num_channels)); count = 0; for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) { cb->channels[count++] = c->channel; @@ -256,7 +256,7 @@ struct shutdown_cleanup_args { }; static void shutdown_cleanup(void* arg, grpc_error* error) { - struct shutdown_cleanup_args* a = (struct shutdown_cleanup_args*)arg; + struct shutdown_cleanup_args* a = static_cast(arg); grpc_slice_unref_internal(a->slice); gpr_free(a); } @@ -264,7 +264,7 @@ static void shutdown_cleanup(void* arg, grpc_error* error) { static void send_shutdown(grpc_channel* channel, bool send_goaway, grpc_error* send_disconnect) { struct shutdown_cleanup_args* sc = - (struct shutdown_cleanup_args*)gpr_malloc(sizeof(*sc)); + static_cast(gpr_malloc(sizeof(*sc))); GRPC_CLOSURE_INIT(&sc->closure, shutdown_cleanup, sc, grpc_schedule_on_exec_ctx); grpc_transport_op* op = grpc_make_transport_op(&sc->closure); @@ -304,8 +304,8 @@ static void channel_broadcaster_shutdown(channel_broadcaster* cb, static void request_matcher_init(request_matcher* rm, grpc_server* server) { memset(rm, 0, sizeof(*rm)); rm->server = server; - rm->requests_per_cq = (gpr_locked_mpscq*)gpr_malloc( - sizeof(*rm->requests_per_cq) * server->cq_count); + rm->requests_per_cq = static_cast(gpr_malloc( + sizeof(*rm->requests_per_cq) * server->cq_count)); for (size_t i = 0; i < server->cq_count; i++) { gpr_locked_mpscq_init(&rm->requests_per_cq[i]); } @@ -320,7 +320,7 @@ static void request_matcher_destroy(request_matcher* rm) { } static void kill_zombie(void* elem, grpc_error* error) { - grpc_call_unref(grpc_call_from_top_element((grpc_call_element*)elem)); + grpc_call_unref(grpc_call_from_top_element(static_cast(elem))); } static void request_matcher_zombify_all_pending_calls(request_matcher* rm) { @@ -341,8 +341,8 @@ static void request_matcher_kill_requests(grpc_server* server, grpc_error* error) { requested_call* rc; for (size_t i = 0; i < server->cq_count; i++) { - while ((rc = (requested_call*)gpr_locked_mpscq_pop( - &rm->requests_per_cq[i])) != nullptr) { + while ((rc = reinterpret_cast(gpr_locked_mpscq_pop( + &rm->requests_per_cq[i]))) != nullptr) { fail_call(server, i, rc, GRPC_ERROR_REF(error)); } } @@ -402,7 +402,7 @@ static void orphan_channel(channel_data* chand) { } static void finish_destroy_channel(void* cd, grpc_error* error) { - channel_data* chand = (channel_data*)cd; + channel_data* chand = static_cast(cd); grpc_server* server = chand->server; GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server"); server_unref(server); @@ -469,9 +469,9 @@ static void publish_call(grpc_server* server, call_data* calld, size_t cq_idx, } static void publish_new_rpc(void* arg, grpc_error* error) { - grpc_call_element* call_elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)call_elem->call_data; - channel_data* chand = (channel_data*)call_elem->channel_data; + grpc_call_element* call_elem = static_cast(arg); + call_data* calld = static_cast(call_elem->call_data); + channel_data* chand = static_cast(call_elem->channel_data); request_matcher* rm = calld->matcher; grpc_server* server = rm->server; @@ -488,7 +488,7 @@ static void publish_new_rpc(void* arg, grpc_error* error) { for (size_t i = 0; i < server->cq_count; i++) { size_t cq_idx = (chand->cq_idx + i) % server->cq_count; requested_call* rc = - (requested_call*)gpr_locked_mpscq_try_pop(&rm->requests_per_cq[cq_idx]); + reinterpret_cast(gpr_locked_mpscq_try_pop(&rm->requests_per_cq[cq_idx])); if (rc == nullptr) { continue; } else { @@ -510,7 +510,7 @@ static void publish_new_rpc(void* arg, grpc_error* error) { for (size_t i = 0; i < server->cq_count; i++) { size_t cq_idx = (chand->cq_idx + i) % server->cq_count; requested_call* rc = - (requested_call*)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]); + reinterpret_cast(gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx])); if (rc == nullptr) { continue; } else { @@ -536,7 +536,7 @@ static void publish_new_rpc(void* arg, grpc_error* error) { static void finish_start_new_rpc( grpc_server* server, grpc_call_element* elem, request_matcher* rm, grpc_server_register_method_payload_handling payload_handling) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (gpr_atm_acq_load(&server->shutdown_flag)) { gpr_atm_no_barrier_store(&calld->state, ZOMBIED); @@ -566,8 +566,8 @@ static void finish_start_new_rpc( } static void start_new_rpc(grpc_call_element* elem) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); grpc_server* server = chand->server; uint32_t i; uint32_t hash; @@ -626,7 +626,7 @@ static int num_listeners(grpc_server* server) { } static void done_shutdown_event(void* server, grpc_cq_completion* completion) { - server_unref((grpc_server*)server); + server_unref(static_cast(server)); } static int num_channels(grpc_server* server) { @@ -689,8 +689,8 @@ static void maybe_finish_shutdown(grpc_server* server) { } static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)ptr; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(ptr); + call_data* calld = static_cast(elem->call_data); grpc_millis op_deadline; if (error == GRPC_ERROR_NONE) { @@ -728,7 +728,7 @@ static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) { static void server_mutate_op(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (op->recv_initial_metadata) { GPR_ASSERT(op->payload->recv_initial_metadata.recv_flags == nullptr); @@ -750,8 +750,8 @@ static void server_start_transport_stream_op_batch( } static void got_initial_metadata(void* ptr, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)ptr; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(ptr); + call_data* calld = static_cast(elem->call_data); if (error == GRPC_ERROR_NONE) { start_new_rpc(elem); } else { @@ -768,7 +768,7 @@ static void got_initial_metadata(void* ptr, grpc_error* error) { static void accept_stream(void* cd, grpc_transport* transport, const void* transport_server_data) { - channel_data* chand = (channel_data*)cd; + channel_data* chand = static_cast(cd); /* create a call */ grpc_call_create_args args; memset(&args, 0, sizeof(args)); @@ -784,7 +784,7 @@ static void accept_stream(void* cd, grpc_transport* transport, GRPC_ERROR_UNREF(error); return; } - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); grpc_op op; memset(&op, 0, sizeof(op)); op.op = GRPC_OP_RECV_INITIAL_METADATA; @@ -796,7 +796,7 @@ static void accept_stream(void* cd, grpc_transport* transport, } static void channel_connectivity_changed(void* cd, grpc_error* error) { - channel_data* chand = (channel_data*)cd; + channel_data* chand = static_cast(cd); grpc_server* server = chand->server; if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_transport_op* op = grpc_make_transport_op(nullptr); @@ -815,8 +815,8 @@ static void channel_connectivity_changed(void* cd, grpc_error* error) { static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - call_data* calld = (call_data*)elem->call_data; - channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = static_cast(elem->call_data); + channel_data* chand = static_cast(elem->channel_data); memset(calld, 0, sizeof(call_data)); calld->deadline = GRPC_MILLIS_INF_FUTURE; calld->call = grpc_call_from_top_element(elem); @@ -832,8 +832,8 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - channel_data* chand = (channel_data*)elem->channel_data; - call_data* calld = (call_data*)elem->call_data; + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); GPR_ASSERT(calld->state != PENDING); @@ -851,7 +851,7 @@ static void destroy_call_elem(grpc_call_element* elem, static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); GPR_ASSERT(args->is_first); GPR_ASSERT(!args->is_last); chand->server = nullptr; @@ -867,7 +867,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, static void destroy_channel_elem(grpc_channel_element* elem) { size_t i; - channel_data* chand = (channel_data*)elem->channel_data; + channel_data* chand = static_cast(elem->channel_data); if (chand->registered_methods) { for (i = 0; i < chand->registered_method_slots; i++) { grpc_slice_unref_internal(chand->registered_methods[i].method); @@ -913,8 +913,8 @@ static void register_completion_queue(grpc_server* server, GRPC_CQ_INTERNAL_REF(cq, "server"); n = server->cq_count++; - server->cqs = (grpc_completion_queue**)gpr_realloc( - server->cqs, server->cq_count * sizeof(grpc_completion_queue*)); + server->cqs = static_cast(gpr_realloc( + server->cqs, server->cq_count * sizeof(grpc_completion_queue*))); server->cqs[n] = cq; } @@ -939,7 +939,7 @@ void grpc_server_register_completion_queue(grpc_server* server, grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) { GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved)); - grpc_server* server = (grpc_server*)gpr_zalloc(sizeof(grpc_server)); + grpc_server* server = static_cast(gpr_zalloc(sizeof(grpc_server))); gpr_mu_init(&server->mu_global); gpr_mu_init(&server->mu_call); @@ -988,7 +988,7 @@ void* grpc_server_register_method( flags); return nullptr; } - m = (registered_method*)gpr_zalloc(sizeof(registered_method)); + m = static_cast(gpr_zalloc(sizeof(registered_method))); m->method = gpr_strdup(method); m->host = gpr_strdup(host); m->next = server->registered_methods; @@ -999,7 +999,7 @@ void* grpc_server_register_method( } static void start_listeners(void* s, grpc_error* error) { - grpc_server* server = (grpc_server*)s; + grpc_server* server = static_cast(s); for (listener* l = server->listeners; l; l = l->next) { l->start(server, l->arg, server->pollsets, server->pollset_count); } @@ -1021,7 +1021,7 @@ void grpc_server_start(grpc_server* server) { server->started = true; server->pollset_count = 0; server->pollsets = - (grpc_pollset**)gpr_malloc(sizeof(grpc_pollset*) * server->cq_count); + static_cast(gpr_malloc(sizeof(grpc_pollset*) * server->cq_count)); for (i = 0; i < server->cq_count; i++) { if (grpc_cq_can_listen(server->cqs[i])) { server->pollsets[server->pollset_count++] = @@ -1063,9 +1063,9 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, grpc_transport_op* op = nullptr; channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport); - chand = (channel_data*)grpc_channel_stack_element( + chand = static_cast(grpc_channel_stack_element( grpc_channel_get_channel_stack(channel), 0) - ->channel_data; + ->channel_data); chand->server = s; server_ref(s); chand->channel = channel; @@ -1076,7 +1076,7 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, } if (cq_idx == s->cq_count) { /* completion queue not found: pick a random one to publish new calls to */ - cq_idx = (size_t)rand() % s->cq_count; + cq_idx = static_cast(rand()) % s->cq_count; } chand->cq_idx = cq_idx; @@ -1089,7 +1089,7 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, if (num_registered_methods > 0) { slots = 2 * num_registered_methods; alloc = sizeof(channel_registered_method) * slots; - chand->registered_methods = (channel_registered_method*)gpr_zalloc(alloc); + chand->registered_methods = static_cast(gpr_zalloc(alloc)); for (rm = s->registered_methods; rm; rm = rm->next) { grpc_slice host; bool has_host; @@ -1118,7 +1118,7 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, crm->method = method; } GPR_ASSERT(slots <= UINT32_MAX); - chand->registered_method_slots = (uint32_t)slots; + chand->registered_method_slots = static_cast(slots); chand->registered_method_max_probes = max_probes; } @@ -1148,7 +1148,7 @@ void done_published_shutdown(void* done_arg, grpc_cq_completion* storage) { } static void listener_destroy_done(void* s, grpc_error* error) { - grpc_server* server = (grpc_server*)s; + grpc_server* server = static_cast(s); gpr_mu_lock(&server->mu_global); server->listeners_destroyed++; maybe_finish_shutdown(server); @@ -1176,13 +1176,13 @@ void grpc_server_shutdown_and_notify(grpc_server* server, GPR_ASSERT(grpc_cq_begin_op(cq, tag)); if (server->shutdown_published) { grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, nullptr, - (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); + static_cast(gpr_malloc(sizeof(grpc_cq_completion)))); gpr_mu_unlock(&server->mu_global); return; } - server->shutdown_tags = (shutdown_tag*)gpr_realloc( + server->shutdown_tags = static_cast(gpr_realloc( server->shutdown_tags, - sizeof(shutdown_tag) * (server->num_shutdown_tags + 1)); + sizeof(shutdown_tag) * (server->num_shutdown_tags + 1))); sdt = &server->shutdown_tags[server->num_shutdown_tags++]; sdt->tag = tag; sdt->cq = cq; @@ -1259,7 +1259,7 @@ void grpc_server_add_listener(grpc_server* server, void* arg, size_t pollset_count), void (*destroy)(grpc_server* server, void* arg, grpc_closure* on_done)) { - listener* l = (listener*)gpr_malloc(sizeof(listener)); + listener* l = static_cast(gpr_malloc(sizeof(listener))); l->arg = arg; l->start = start; l->destroy = destroy; @@ -1289,7 +1289,7 @@ static grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx, matching calls */ gpr_mu_lock(&server->mu_call); while ((calld = rm->pending_head) != nullptr) { - rc = (requested_call*)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]); + rc = reinterpret_cast(gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx])); if (rc == nullptr) break; rm->pending_head = calld->pending_next; gpr_mu_unlock(&server->mu_call); @@ -1317,7 +1317,7 @@ grpc_call_error grpc_server_request_call( grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; grpc_core::ExecCtx exec_ctx; - requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); + requested_call* rc = static_cast(gpr_malloc(sizeof(*rc))); GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); GRPC_API_TRACE( "grpc_server_request_call(" @@ -1364,8 +1364,8 @@ grpc_call_error grpc_server_request_registered_call( grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; grpc_core::ExecCtx exec_ctx; - requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); - registered_method* rm = (registered_method*)rmp; + requested_call* rc = static_cast(gpr_malloc(sizeof(*rc))); + registered_method* rm = static_cast(rmp); GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); GRPC_API_TRACE( "grpc_server_request_registered_call(" diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 2ba1cfdaa6..044183e8fd 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -40,8 +40,8 @@ BdpEstimator::BdpEstimator(const char* name) grpc_millis BdpEstimator::CompletePing() { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec dt_ts = gpr_time_sub(now, ping_start_time_); - double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec; - double bw = dt > 0 ? ((double)accumulator_ / dt) : 0; + double dt = static_cast(dt_ts.tv_sec) + 1e-9 * static_cast(dt_ts.tv_nsec); + double bw = dt > 0 ? (static_cast(accumulator_) / dt) : 0; int start_inter_ping_delay = inter_ping_delay_; if (grpc_bdp_estimator_trace.enabled()) { gpr_log(GPR_DEBUG, @@ -65,7 +65,7 @@ grpc_millis BdpEstimator::CompletePing() { if (stable_estimate_count_ >= 2) { inter_ping_delay_ += 100 + - (int)(rand() * 100.0 / RAND_MAX); // if the ping estimate is steady, + static_cast(rand() * 100.0 / RAND_MAX); // if the ping estimate is steady, // slowly ramp down the probe time } } diff --git a/src/core/lib/transport/byte_stream.cc b/src/core/lib/transport/byte_stream.cc index 8dcb1e0bdb..2ae0b8298a 100644 --- a/src/core/lib/transport/byte_stream.cc +++ b/src/core/lib/transport/byte_stream.cc @@ -49,14 +49,14 @@ void grpc_byte_stream_destroy(grpc_byte_stream* byte_stream) { static bool slice_buffer_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { - grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; + grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); GPR_ASSERT(stream->cursor < stream->backing_buffer->count); return true; } static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { - grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; + grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); if (stream->shutdown_error != GRPC_ERROR_NONE) { return GRPC_ERROR_REF(stream->shutdown_error); } @@ -69,13 +69,13 @@ static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream, static void slice_buffer_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { - grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; + grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = error; } static void slice_buffer_stream_destroy(grpc_byte_stream* byte_stream) { - grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; + grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); grpc_slice_buffer_reset_and_unref_internal(stream->backing_buffer); GRPC_ERROR_UNREF(stream->shutdown_error); } @@ -88,7 +88,7 @@ void grpc_slice_buffer_stream_init(grpc_slice_buffer_stream* stream, grpc_slice_buffer* slice_buffer, uint32_t flags) { GPR_ASSERT(slice_buffer->length <= UINT32_MAX); - stream->base.length = (uint32_t)slice_buffer->length; + stream->base.length = static_cast(slice_buffer->length); stream->base.flags = flags; stream->base.vtable = &slice_buffer_stream_vtable; stream->backing_buffer = slice_buffer; @@ -112,7 +112,7 @@ void grpc_byte_stream_cache_destroy(grpc_byte_stream_cache* cache) { static bool caching_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { - grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; + grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); if (stream->shutdown_error != GRPC_ERROR_NONE) return true; if (stream->cursor < stream->cache->cache_buffer.count) return true; return grpc_byte_stream_next(stream->cache->underlying_stream, max_size_hint, @@ -121,7 +121,7 @@ static bool caching_byte_stream_next(grpc_byte_stream* byte_stream, static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { - grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; + grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); if (stream->shutdown_error != GRPC_ERROR_NONE) { return GRPC_ERROR_REF(stream->shutdown_error); } @@ -143,14 +143,14 @@ static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, static void caching_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { - grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; + grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = GRPC_ERROR_REF(error); grpc_byte_stream_shutdown(stream->cache->underlying_stream, error); } static void caching_byte_stream_destroy(grpc_byte_stream* byte_stream) { - grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; + grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); GRPC_ERROR_UNREF(stream->shutdown_error); } diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index c42cc9c8d0..183d5987ee 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -74,7 +74,7 @@ void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) { grpc_connectivity_state grpc_connectivity_state_check( grpc_connectivity_state_tracker* tracker) { grpc_connectivity_state cur = - (grpc_connectivity_state)gpr_atm_no_barrier_load( + static_castgpr_atm_no_barrier_load( &tracker->current_state_atm); if (grpc_connectivity_state_trace.enabled()) { gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, @@ -86,7 +86,7 @@ grpc_connectivity_state grpc_connectivity_state_check( grpc_connectivity_state grpc_connectivity_state_get( grpc_connectivity_state_tracker* tracker, grpc_error** error) { grpc_connectivity_state cur = - (grpc_connectivity_state)gpr_atm_no_barrier_load( + static_castgpr_atm_no_barrier_load( &tracker->current_state_atm); if (grpc_connectivity_state_trace.enabled()) { gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, @@ -107,7 +107,7 @@ bool grpc_connectivity_state_notify_on_state_change( grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, grpc_closure* notify) { grpc_connectivity_state cur = - (grpc_connectivity_state)gpr_atm_no_barrier_load( + static_castgpr_atm_no_barrier_load( &tracker->current_state_atm); if (grpc_connectivity_state_trace.enabled()) { if (current == nullptr) { @@ -144,7 +144,7 @@ bool grpc_connectivity_state_notify_on_state_change( GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_REF(tracker->current_error)); } else { grpc_connectivity_state_watcher* w = - (grpc_connectivity_state_watcher*)gpr_malloc(sizeof(*w)); + static_cast(gpr_malloc(sizeof(*w))); w->current = current; w->notify = notify; w->next = tracker->watchers; @@ -158,7 +158,7 @@ void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, grpc_connectivity_state state, grpc_error* error, const char* reason) { grpc_connectivity_state cur = - (grpc_connectivity_state)gpr_atm_no_barrier_load( + static_castgpr_atm_no_barrier_load( &tracker->current_state_atm); grpc_connectivity_state_watcher* w; if (grpc_connectivity_state_trace.enabled()) { diff --git a/src/core/lib/transport/error_utils.cc b/src/core/lib/transport/error_utils.cc index 891576f4ba..b968383eda 100644 --- a/src/core/lib/transport/error_utils.cc +++ b/src/core/lib/transport/error_utils.cc @@ -32,7 +32,7 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error, // Otherwise, search through its children. uint8_t slot = error->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = (grpc_linked_error*)(error->arena + slot); + grpc_linked_error* lerr = reinterpret_cast(error->arena + slot); grpc_error* result = recursively_find_error_with_field(lerr->err, which); if (result) return result; slot = lerr->next; @@ -62,10 +62,10 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline, grpc_status_code status = GRPC_STATUS_UNKNOWN; intptr_t integer; if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) { - status = (grpc_status_code)integer; + status = static_cast(integer); } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { - status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer, + status = grpc_http2_error_to_grpc_status(static_cast(integer), deadline); } if (code != nullptr) *code = status; @@ -76,10 +76,10 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline, if (http_error != nullptr) { if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { - *http_error = (grpc_http2_error_code)integer; + *http_error = static_cast(integer); } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) { - *http_error = grpc_status_to_http2_error((grpc_status_code)integer); + *http_error = grpc_status_to_http2_error(static_cast(integer)); } else { *http_error = found_error == GRPC_ERROR_NONE ? GRPC_HTTP2_NO_ERROR : GRPC_HTTP2_INTERNAL_ERROR; @@ -103,7 +103,7 @@ bool grpc_error_has_clear_grpc_status(grpc_error* error) { } uint8_t slot = error->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = (grpc_linked_error*)(error->arena + slot); + grpc_linked_error* lerr = reinterpret_cast(error->arena + slot); if (grpc_error_has_clear_grpc_status(lerr->err)) { return true; } diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index cc1edd586f..418224bc97 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -118,8 +118,8 @@ void grpc_mdctx_global_init(void) { shard->count = 0; gpr_atm_no_barrier_store(&shard->free_estimate, 0); shard->capacity = INITIAL_SHARD_CAPACITY; - shard->elems = (interned_metadata**)gpr_zalloc(sizeof(*shard->elems) * - shard->capacity); + shard->elems = static_cast(gpr_zalloc(sizeof(*shard->elems) * + shard->capacity)); } } @@ -207,7 +207,7 @@ static void grow_mdtab(mdtab_shard* shard) { uint32_t hash; mdtab = - (interned_metadata**)gpr_zalloc(sizeof(interned_metadata*) * capacity); + static_cast(gpr_zalloc(sizeof(interned_metadata*) * capacity)); for (i = 0; i < shard->capacity; i++) { for (md = shard->elems[i]; md; md = next) { @@ -227,7 +227,7 @@ static void grow_mdtab(mdtab_shard* shard) { static void rehash_mdtab(mdtab_shard* shard) { if (gpr_atm_no_barrier_load(&shard->free_estimate) > - (gpr_atm)(shard->capacity / 4)) { + static_cast(shard->capacity / 4)) { gc_mdtab(shard); } else { grow_mdtab(shard); @@ -244,7 +244,7 @@ grpc_mdelem grpc_mdelem_create( } allocated_metadata* allocated = - (allocated_metadata*)gpr_malloc(sizeof(*allocated)); + static_cast(gpr_malloc(sizeof(*allocated))); allocated->key = grpc_slice_ref_internal(key); allocated->value = grpc_slice_ref_internal(value); gpr_atm_rel_store(&allocated->refcnt, 1); @@ -292,7 +292,7 @@ grpc_mdelem grpc_mdelem_create( } /* not found: create a new pair */ - md = (interned_metadata*)gpr_malloc(sizeof(interned_metadata)); + md = static_cast(gpr_malloc(sizeof(interned_metadata))); gpr_atm_rel_store(&md->refcnt, 1); md->key = grpc_slice_ref_internal(key); md->value = grpc_slice_ref_internal(value); @@ -336,7 +336,7 @@ grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata) { grpc_slice value_slice = grpc_slice_maybe_static_intern(metadata->value, &changed); return grpc_mdelem_create(key_slice, value_slice, - changed ? nullptr : (grpc_mdelem_data*)metadata); + changed ? nullptr : reinterpret_cast(metadata)); } static size_t get_base64_encoded_size(size_t raw_length) { @@ -363,7 +363,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_STATIC: break; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* md = (interned_metadata*)GRPC_MDELEM_DATA(gmd); + interned_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -385,7 +385,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { break; } case GRPC_MDELEM_STORAGE_ALLOCATED: { - allocated_metadata* md = (allocated_metadata*)GRPC_MDELEM_DATA(gmd); + allocated_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -415,7 +415,7 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_STATIC: break; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* md = (interned_metadata*)GRPC_MDELEM_DATA(gmd); + interned_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -441,7 +441,7 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) { break; } case GRPC_MDELEM_STORAGE_ALLOCATED: { - allocated_metadata* md = (allocated_metadata*)GRPC_MDELEM_DATA(gmd); + allocated_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -475,7 +475,7 @@ void* grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void*)) { return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - grpc_static_mdelem_table]; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* im = (interned_metadata*)GRPC_MDELEM_DATA(md); + interned_metadata* im = reinterpret_castGRPC_MDELEM_DATA(md); void* result; if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { return (void*)gpr_atm_no_barrier_load(&im->user_data); @@ -500,7 +500,7 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - grpc_static_mdelem_table]; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* im = (interned_metadata*)GRPC_MDELEM_DATA(md); + interned_metadata* im = reinterpret_castGRPC_MDELEM_DATA(md); GPR_ASSERT(!is_mdelem_static(md)); GPR_ASSERT((user_data == nullptr) == (destroy_func == nullptr)); gpr_mu_lock(&im->mu_user_data); diff --git a/src/core/lib/transport/service_config.cc b/src/core/lib/transport/service_config.cc index 5c9930a273..f5805b2fa4 100644 --- a/src/core/lib/transport/service_config.cc +++ b/src/core/lib/transport/service_config.cc @@ -60,7 +60,7 @@ struct grpc_service_config { grpc_service_config* grpc_service_config_create(const char* json_string) { grpc_service_config* service_config = - (grpc_service_config*)gpr_malloc(sizeof(*service_config)); + static_cast(gpr_malloc(sizeof(*service_config))); service_config->json_string = gpr_strdup(json_string); service_config->json_tree = grpc_json_parse_string(service_config->json_string); @@ -209,8 +209,8 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( num_entries += count; } // Populate method config table entries. - entries = (grpc_slice_hash_table_entry*)gpr_malloc( - num_entries * sizeof(grpc_slice_hash_table_entry)); + entries = static_cast(gpr_malloc( + num_entries * sizeof(grpc_slice_hash_table_entry))); size_t idx = 0; for (grpc_json* method = field->child; method != nullptr; method = method->next) { @@ -245,8 +245,8 @@ void* grpc_method_config_table_get(const grpc_slice_hash_table* table, if (value == nullptr) { char* path_str = grpc_slice_to_c_string(path); const char* sep = strrchr(path_str, '/') + 1; - const size_t len = (size_t)(sep - path_str); - char* buf = (char*)gpr_malloc(len + 2); // '*' and NUL + const size_t len = static_cast(sep - path_str); + char* buf = static_cast(gpr_malloc(len + 2)); // '*' and NUL memcpy(buf, path_str, len); buf[len] = '*'; buf[len + 1] = '\0'; diff --git a/src/core/lib/transport/static_metadata.cc b/src/core/lib/transport/static_metadata.cc index ebc75724cf..5994cbc265 100644 --- a/src/core/lib/transport/static_metadata.cc +++ b/src/core/lib/transport/static_metadata.cc @@ -340,7 +340,7 @@ static uint32_t elems_phash(uint32_t i) { uint32_t y = i / 99; uint32_t h = x; if (y < GPR_ARRAY_SIZE(elems_r)) { - uint32_t delta = (uint32_t)elems_r[y]; + uint32_t delta = static_cast(elems_r[y]); h += delta; } return h; @@ -371,7 +371,7 @@ static const uint8_t elem_idxs[] = { grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { if (a == -1 || b == -1) return GRPC_MDNULL; - uint32_t k = (uint32_t)(a * 101 + b); + uint32_t k = static_cast(a * 101 + b); uint32_t h = elems_phash(k); return h < GPR_ARRAY_SIZE(elem_keys) && elem_keys[h] == k && elem_idxs[h] != 255 diff --git a/src/core/lib/transport/timeout_encoding.cc b/src/core/lib/transport/timeout_encoding.cc index 47f964af45..f47f3fa44b 100644 --- a/src/core/lib/transport/timeout_encoding.cc +++ b/src/core/lib/transport/timeout_encoding.cc @@ -98,7 +98,7 @@ int grpc_http2_decode_timeout(grpc_slice text, grpc_millis* timeout) { ; /* decode numeric part */ for (; p != end && *p >= '0' && *p <= '9'; p++) { - int32_t digit = (int32_t)(*p - (uint8_t)'0'); + int32_t digit = static_cast(*p - static_cast('0')); have_digit = 1; /* spec allows max. 8 digits, but we allow values up to 1,000,000,000 */ if (x >= (100 * 1000 * 1000)) { @@ -138,5 +138,5 @@ int grpc_http2_decode_timeout(grpc_slice text, grpc_millis* timeout) { return 0; } p++; - return is_all_whitespace((const char*)p, (const char*)end); + return is_all_whitespace(reinterpret_cast(p), reinterpret_cast(end)); } diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index ea0380e591..56fc1ce13e 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -101,7 +101,7 @@ grpc_slice grpc_slice_from_stream_owned_buffer(grpc_stream_refcount* refcount, slice_stream_ref(&refcount->slice_refcount); grpc_slice res; res.refcount = &refcount->slice_refcount; - res.data.refcounted.bytes = (uint8_t*)buffer; + res.data.refcounted.bytes = static_cast(buffer); res.data.refcounted.length = length; return res; } @@ -233,13 +233,13 @@ typedef struct { } made_transport_op; static void destroy_made_transport_op(void* arg, grpc_error* error) { - made_transport_op* op = (made_transport_op*)arg; + made_transport_op* op = static_cast(arg); GRPC_CLOSURE_SCHED(op->inner_on_complete, GRPC_ERROR_REF(error)); gpr_free(op); } grpc_transport_op* grpc_make_transport_op(grpc_closure* on_complete) { - made_transport_op* op = (made_transport_op*)gpr_malloc(sizeof(*op)); + made_transport_op* op = static_cast(gpr_malloc(sizeof(*op))); GRPC_CLOSURE_INIT(&op->outer_on_complete, destroy_made_transport_op, op, grpc_schedule_on_exec_ctx); op->inner_on_complete = on_complete; @@ -256,7 +256,7 @@ typedef struct { } made_transport_stream_op; static void destroy_made_transport_stream_op(void* arg, grpc_error* error) { - made_transport_stream_op* op = (made_transport_stream_op*)arg; + made_transport_stream_op* op = static_cast(arg); grpc_closure* c = op->inner_on_complete; gpr_free(op); GRPC_CLOSURE_RUN(c, GRPC_ERROR_REF(error)); @@ -265,7 +265,7 @@ static void destroy_made_transport_stream_op(void* arg, grpc_error* error) { grpc_transport_stream_op_batch* grpc_make_transport_stream_op( grpc_closure* on_complete) { made_transport_stream_op* op = - (made_transport_stream_op*)gpr_zalloc(sizeof(*op)); + static_cast(gpr_zalloc(sizeof(*op))); op->op.payload = &op->payload; GRPC_CLOSURE_INIT(&op->outer_on_complete, destroy_made_transport_stream_op, op, grpc_schedule_on_exec_ctx); diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index 7d5aaa7305..c7eb750a5b 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -102,7 +102,7 @@ static tsi_result tsi_fake_handshake_message_from_string( for (int i = 0; i < TSI_FAKE_HANDSHAKE_MESSAGE_MAX; i++) { if (strncmp(msg_string, tsi_fake_handshake_message_strings[i], strlen(tsi_fake_handshake_message_strings[i])) == 0) { - *msg = (tsi_fake_handshake_message)i; + *msg = static_cast(i); return TSI_OK; } } @@ -111,15 +111,15 @@ static tsi_result tsi_fake_handshake_message_from_string( } static uint32_t load32_little_endian(const unsigned char* buf) { - return ((uint32_t)(buf[0]) | (uint32_t)(buf[1] << 8) | - (uint32_t)(buf[2] << 16) | (uint32_t)(buf[3] << 24)); + return (static_cast(buf[0]) | static_cast(buf[1] << 8) | + static_cast(buf[2] << 16) | static_cast(buf[3] << 24)); } static void store32_little_endian(uint32_t value, unsigned char* buf) { - buf[3] = (unsigned char)((value >> 24) & 0xFF); - buf[2] = (unsigned char)((value >> 16) & 0xFF); - buf[1] = (unsigned char)((value >> 8) & 0xFF); - buf[0] = (unsigned char)((value)&0xFF); + buf[3] = static_cast((value >> 24) & 0xFF); + buf[2] = static_cast((value >> 16) & 0xFF); + buf[1] = static_cast((value >> 8) & 0xFF); + buf[0] = static_cast((value)&0xFF); } static uint32_t read_frame_size(const grpc_slice_buffer* sb) { @@ -155,10 +155,10 @@ static void tsi_fake_frame_reset(tsi_fake_frame* frame, int needs_draining) { static void tsi_fake_frame_ensure_size(tsi_fake_frame* frame) { if (frame->data == nullptr) { frame->allocated_size = frame->size; - frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); + frame->data = static_cast(gpr_malloc(frame->allocated_size)); } else if (frame->size > frame->allocated_size) { unsigned char* new_data = - (unsigned char*)gpr_realloc(frame->data, frame->size); + static_cast(gpr_realloc(frame->data, frame->size)); frame->data = new_data; frame->allocated_size = frame->size; } @@ -177,7 +177,7 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, if (frame->needs_draining) return TSI_INTERNAL_ERROR; if (frame->data == nullptr) { frame->allocated_size = TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE; - frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); + frame->data = static_cast(gpr_malloc(frame->allocated_size)); } if (frame->offset < TSI_FAKE_FRAME_HEADER_SIZE) { @@ -187,7 +187,7 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, memcpy(frame->data + frame->offset, bytes_cursor, available_size); bytes_cursor += available_size; frame->offset += available_size; - *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); + *incoming_bytes_size = static_cast(bytes_cursor - incoming_bytes); return TSI_INCOMPLETE_DATA; } memcpy(frame->data + frame->offset, bytes_cursor, to_read_size); @@ -203,12 +203,12 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, memcpy(frame->data + frame->offset, bytes_cursor, available_size); frame->offset += available_size; bytes_cursor += available_size; - *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); + *incoming_bytes_size = static_cast(bytes_cursor - incoming_bytes); return TSI_INCOMPLETE_DATA; } memcpy(frame->data + frame->offset, bytes_cursor, to_read_size); bytes_cursor += to_read_size; - *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); + *incoming_bytes_size = static_cast(bytes_cursor - incoming_bytes); tsi_fake_frame_reset(frame, 1 /* needs_draining */); return TSI_OK; } @@ -239,7 +239,7 @@ static tsi_result tsi_fake_frame_set_data(unsigned char* data, size_t data_size, frame->offset = 0; frame->size = data_size + TSI_FAKE_FRAME_HEADER_SIZE; tsi_fake_frame_ensure_size(frame); - store32_little_endian((uint32_t)frame->size, frame->data); + store32_little_endian(static_cast(frame->size), frame->data); memcpy(frame->data + TSI_FAKE_FRAME_HEADER_SIZE, data, data_size); tsi_fake_frame_reset(frame, 1 /* needs draining */); return TSI_OK; @@ -258,7 +258,7 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast(self); unsigned char frame_header[TSI_FAKE_FRAME_HEADER_SIZE]; tsi_fake_frame* frame = &impl->protect_frame; size_t saved_output_size = *protected_output_frames_size; @@ -287,7 +287,7 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, if (frame->size == 0) { /* New frame, create a header. */ size_t written_in_frame_size = 0; - store32_little_endian((uint32_t)impl->max_frame_size, frame_header); + store32_little_endian(static_cast(impl->max_frame_size), frame_header); written_in_frame_size = TSI_FAKE_FRAME_HEADER_SIZE; result = tsi_fake_frame_decode(frame_header, &written_in_frame_size, frame); if (result != TSI_INCOMPLETE_DATA) { @@ -317,14 +317,14 @@ static tsi_result fake_protector_protect_flush( tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast(self); tsi_fake_frame* frame = &impl->protect_frame; if (!frame->needs_draining) { /* Create a short frame. */ frame->size = frame->offset; frame->offset = 0; frame->needs_draining = 1; - store32_little_endian((uint32_t)frame->size, + store32_little_endian(static_cast(frame->size), frame->data); /* Overwrite header. */ } result = tsi_fake_frame_encode(protected_output_frames, @@ -339,7 +339,7 @@ static tsi_result fake_protector_unprotect( size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast(self); tsi_fake_frame* frame = &impl->unprotect_frame; size_t saved_output_size = *unprotected_bytes_size; size_t drained_size = 0; @@ -384,7 +384,7 @@ static tsi_result fake_protector_unprotect( } static void fake_protector_destroy(tsi_frame_protector* self) { - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast(self); tsi_fake_frame_destruct(&impl->protect_frame); tsi_fake_frame_destruct(&impl->unprotect_frame); gpr_free(self); @@ -407,14 +407,14 @@ static tsi_result fake_zero_copy_grpc_protector_protect( return TSI_INVALID_ARGUMENT; } tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)self; + reinterpret_cast(self); /* Protects each frame. */ while (unprotected_slices->length > 0) { size_t frame_length = GPR_MIN(impl->max_frame_size, unprotected_slices->length + TSI_FAKE_FRAME_HEADER_SIZE); grpc_slice slice = GRPC_SLICE_MALLOC(TSI_FAKE_FRAME_HEADER_SIZE); - store32_little_endian((uint32_t)frame_length, GRPC_SLICE_START_PTR(slice)); + store32_little_endian(static_cast(frame_length), GRPC_SLICE_START_PTR(slice)); grpc_slice_buffer_add(protected_slices, slice); size_t data_length = frame_length - TSI_FAKE_FRAME_HEADER_SIZE; grpc_slice_buffer_move_first(unprotected_slices, data_length, @@ -431,7 +431,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( return TSI_INVALID_ARGUMENT; } tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)self; + reinterpret_cast(self); grpc_slice_buffer_move_into(protected_slices, &impl->protected_sb); /* Unprotect each frame, if we get a full frame. */ while (impl->protected_sb.length >= TSI_FAKE_FRAME_HEADER_SIZE) { @@ -462,7 +462,7 @@ static void fake_zero_copy_grpc_protector_destroy( tsi_zero_copy_grpc_protector* self) { if (self == nullptr) return; tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)self; + reinterpret_cast(self); grpc_slice_buffer_destroy_internal(&impl->header_sb); grpc_slice_buffer_destroy_internal(&impl->protected_sb); gpr_free(impl); @@ -520,7 +520,7 @@ static tsi_result fake_handshaker_result_get_unused_bytes( } static void fake_handshaker_result_destroy(tsi_handshaker_result* self) { - fake_handshaker_result* result = (fake_handshaker_result*)self; + fake_handshaker_result* result = reinterpret_cast(self); gpr_free(result->unused_bytes); gpr_free(self); } @@ -541,10 +541,10 @@ static tsi_result fake_handshaker_result_create( return TSI_INVALID_ARGUMENT; } fake_handshaker_result* result = - (fake_handshaker_result*)gpr_zalloc(sizeof(*result)); + static_cast(gpr_zalloc(sizeof(*result))); result->base.vtable = &handshaker_result_vtable; if (unused_bytes_size > 0) { - result->unused_bytes = (unsigned char*)gpr_malloc(unused_bytes_size); + result->unused_bytes = static_cast(gpr_malloc(unused_bytes_size)); memcpy(result->unused_bytes, unused_bytes, unused_bytes_size); } result->unused_bytes_size = unused_bytes_size; @@ -556,7 +556,7 @@ static tsi_result fake_handshaker_result_create( static tsi_result fake_handshaker_get_bytes_to_send_to_peer( tsi_handshaker* self, unsigned char* bytes, size_t* bytes_size) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast(self); tsi_result result = TSI_OK; if (impl->needs_incoming_message || impl->result == TSI_OK) { *bytes_size = 0; @@ -564,7 +564,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( } if (!impl->outgoing_frame.needs_draining) { tsi_fake_handshake_message next_message_to_send = - (tsi_fake_handshake_message)(impl->next_message_to_send + 2); + 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, @@ -598,9 +598,9 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( static tsi_result fake_handshaker_process_bytes_from_peer( tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { tsi_result result = TSI_OK; - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast(self); tsi_fake_handshake_message expected_msg = - (tsi_fake_handshake_message)(impl->next_message_to_send - 1); + static_cast(impl->next_message_to_send - 1); tsi_fake_handshake_message received_msg; if (!impl->needs_incoming_message || impl->result == TSI_OK) { @@ -612,7 +612,7 @@ static tsi_result fake_handshaker_process_bytes_from_peer( /* We now have a complete frame. */ result = tsi_fake_handshake_message_from_string( - (const char*)impl->incoming_frame.data + TSI_FAKE_FRAME_HEADER_SIZE, + reinterpret_cast(impl->incoming_frame.data) + TSI_FAKE_FRAME_HEADER_SIZE, &received_msg); if (result != TSI_OK) { impl->result = result; @@ -640,12 +640,12 @@ static tsi_result fake_handshaker_process_bytes_from_peer( } static tsi_result fake_handshaker_get_result(tsi_handshaker* self) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast(self); return impl->result; } static void fake_handshaker_destroy(tsi_handshaker* self) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast(self); tsi_fake_frame_destruct(&impl->incoming_frame); tsi_fake_frame_destruct(&impl->outgoing_frame); gpr_free(impl->outgoing_bytes_buffer); @@ -663,7 +663,7 @@ static tsi_result fake_handshaker_next( handshaker_result == nullptr) { return TSI_INVALID_ARGUMENT; } - tsi_fake_handshaker* handshaker = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* handshaker = reinterpret_cast(self); tsi_result result = TSI_OK; /* Decode and process a handshake frame from the peer. */ @@ -685,8 +685,8 @@ static tsi_result fake_handshaker_next( if (result == TSI_INCOMPLETE_DATA) { handshaker->outgoing_bytes_buffer_size *= 2; handshaker->outgoing_bytes_buffer = - (unsigned char*)gpr_realloc(handshaker->outgoing_bytes_buffer, - handshaker->outgoing_bytes_buffer_size); + static_cast(gpr_realloc(handshaker->outgoing_bytes_buffer, + handshaker->outgoing_bytes_buffer_size)); } } while (result == TSI_INCOMPLETE_DATA); if (result != TSI_OK) return result; @@ -727,14 +727,14 @@ static const tsi_handshaker_vtable handshaker_vtable = { }; tsi_handshaker* tsi_create_fake_handshaker(int is_client) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)gpr_zalloc(sizeof(*impl)); + tsi_fake_handshaker* impl = static_cast(gpr_zalloc(sizeof(*impl))); impl->base.vtable = &handshaker_vtable; impl->is_client = is_client; impl->result = TSI_HANDSHAKE_IN_PROGRESS; impl->outgoing_bytes_buffer_size = TSI_FAKE_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE; impl->outgoing_bytes_buffer = - (unsigned char*)gpr_malloc(impl->outgoing_bytes_buffer_size); + static_cast(gpr_malloc(impl->outgoing_bytes_buffer_size)); if (is_client) { impl->needs_incoming_message = 0; impl->next_message_to_send = TSI_FAKE_CLIENT_INIT; @@ -748,7 +748,7 @@ tsi_handshaker* tsi_create_fake_handshaker(int is_client) { tsi_frame_protector* tsi_create_fake_frame_protector( size_t* max_protected_frame_size) { tsi_fake_frame_protector* impl = - (tsi_fake_frame_protector*)gpr_zalloc(sizeof(*impl)); + static_cast(gpr_zalloc(sizeof(*impl))); impl->max_frame_size = (max_protected_frame_size == nullptr) ? TSI_FAKE_DEFAULT_FRAME_SIZE : *max_protected_frame_size; @@ -759,7 +759,7 @@ tsi_frame_protector* tsi_create_fake_frame_protector( tsi_zero_copy_grpc_protector* tsi_create_fake_zero_copy_grpc_protector( size_t* max_protected_frame_size) { tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)gpr_zalloc(sizeof(*impl)); + static_cast(gpr_zalloc(sizeof(*impl))); grpc_slice_buffer_init(&impl->header_sb); grpc_slice_buffer_init(&impl->protected_sb); impl->max_frame_size = (max_protected_frame_size == nullptr) diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 6de02d4952..b32649a8b9 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -126,7 +126,7 @@ static void openssl_locking_cb(int mode, int type, const char* file, int line) { } static unsigned long openssl_thread_id_cb(void) { - return (unsigned long)gpr_thd_currentid(); + return static_cast(gpr_thd_currentid()); } static void init_openssl(void) { @@ -137,7 +137,7 @@ static void init_openssl(void) { OpenSSL_add_all_algorithms(); num_locks = CRYPTO_num_locks(); GPR_ASSERT(num_locks > 0); - openssl_mutexes = (gpr_mu*)gpr_malloc((size_t)num_locks * sizeof(gpr_mu)); + openssl_mutexes = static_cast(gpr_malloc(static_cast(num_locks) * sizeof(gpr_mu))); for (i = 0; i < CRYPTO_num_locks(); i++) { gpr_mu_init(&openssl_mutexes[i]); } @@ -254,7 +254,7 @@ static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, gpr_log(GPR_ERROR, "Could not extract utf8 from asn1 string."); return TSI_OUT_OF_RESOURCES; } - *utf8_size = (size_t)utf8_returned_size; + *utf8_size = static_cast(utf8_returned_size); return TSI_OK; } @@ -275,7 +275,7 @@ static tsi_result peer_property_from_x509_common_name( } result = tsi_construct_string_peer_property( TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, - common_name == nullptr ? "" : (const char*)common_name, common_name_size, + common_name == nullptr ? "" : reinterpret_cast(common_name), common_name_size, property); OPENSSL_free(common_name); return result; @@ -295,7 +295,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, (size_t)len, property); + TSI_X509_PEM_CERT_PROPERTY, (const char*)contents, static_cast(len), property); BIO_free(bio); return result; } @@ -324,8 +324,8 @@ static tsi_result add_subject_alt_names_properties_to_peer( break; } result = tsi_construct_string_peer_property( - TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, (const char*)name, - (size_t)name_size, &peer->properties[peer->property_count++]); + TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, reinterpret_cast(name), + static_cast(name_size), &peer->properties[peer->property_count++]); OPENSSL_free(name); } else if (subject_alt_name->type == GEN_IPADD) { char ntop_buf[INET6_ADDRSTRLEN]; @@ -361,17 +361,17 @@ static tsi_result add_subject_alt_names_properties_to_peer( static tsi_result peer_from_x509(X509* cert, int include_certificate_type, tsi_peer* peer) { /* TODO(jboeuf): Maybe add more properties. */ - GENERAL_NAMES* subject_alt_names = (GENERAL_NAMES*)X509_get_ext_d2i( - cert, NID_subject_alt_name, nullptr, nullptr); + GENERAL_NAMES* subject_alt_names = static_cast(X509_get_ext_d2i( + cert, NID_subject_alt_name, nullptr, nullptr)); int subject_alt_name_count = (subject_alt_names != nullptr) - ? (int)sk_GENERAL_NAME_num(subject_alt_names) + ? static_cast(sk_GENERAL_NAME_num(subject_alt_names)) : 0; size_t property_count; tsi_result result; GPR_ASSERT(subject_alt_name_count >= 0); - property_count = (include_certificate_type ? (size_t)1 : 0) + + property_count = (include_certificate_type ? static_cast(1) : 0) + 2 /* common name, certificate */ + - (size_t)subject_alt_name_count; + static_cast(subject_alt_name_count); result = tsi_construct_peer(property_count, peer); if (result != TSI_OK) return result; do { @@ -391,7 +391,7 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, if (subject_alt_name_count != 0) { result = add_subject_alt_names_properties_to_peer( - peer, subject_alt_names, (size_t)subject_alt_name_count); + peer, subject_alt_names, static_cast(subject_alt_name_count)); if (result != TSI_OK) break; } } while (0); @@ -408,7 +408,7 @@ static void log_ssl_error_stack(void) { unsigned long err; while ((err = ERR_get_error()) != 0) { char details[256]; - ERR_error_string_n((uint32_t)err, details, sizeof(details)); + ERR_error_string_n(static_cast(err), details, sizeof(details)); gpr_log(GPR_ERROR, "%s", details); } } @@ -419,7 +419,7 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, int read_from_ssl; GPR_ASSERT(*unprotected_bytes_size <= INT_MAX); read_from_ssl = - SSL_read(ssl, unprotected_bytes, (int)*unprotected_bytes_size); + SSL_read(ssl, unprotected_bytes, static_cast(*unprotected_bytes_size)); if (read_from_ssl <= 0) { read_from_ssl = SSL_get_error(ssl, read_from_ssl); switch (read_from_ssl) { @@ -442,7 +442,7 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, return TSI_PROTOCOL_FAILURE; } } - *unprotected_bytes_size = (size_t)read_from_ssl; + *unprotected_bytes_size = static_cast(read_from_ssl); return TSI_OK; } @@ -452,7 +452,7 @@ static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes, int ssl_write_result; GPR_ASSERT(unprotected_bytes_size <= INT_MAX); ssl_write_result = - SSL_write(ssl, unprotected_bytes, (int)unprotected_bytes_size); + SSL_write(ssl, unprotected_bytes, static_cast(unprotected_bytes_size)); if (ssl_write_result < 0) { ssl_write_result = SSL_get_error(ssl, ssl_write_result); if (ssl_write_result == SSL_ERROR_WANT_READ) { @@ -476,7 +476,7 @@ 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, (int)pem_cert_chain_size); + pem = BIO_new_mem_buf((void*)pem_cert_chain, static_cast(pem_cert_chain_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { @@ -519,7 +519,7 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key, EVP_PKEY* private_key = nullptr; BIO* pem; GPR_ASSERT(pem_key_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_key, (int)pem_key_size); + pem = BIO_new_mem_buf((void*)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*)""); @@ -551,7 +551,7 @@ static tsi_result ssl_ctx_load_verification_certs(SSL_CTX* context, BIO* pem; X509_STORE* root_store; GPR_ASSERT(pem_roots_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_roots, (int)pem_roots_size); + pem = BIO_new_mem_buf((void*)pem_roots, static_cast(pem_roots_size)); root_store = SSL_CTX_get_cert_store(context); if (root_store == nullptr) return TSI_INVALID_ARGUMENT; if (pem == nullptr) return TSI_OUT_OF_RESOURCES; @@ -655,7 +655,7 @@ static tsi_result extract_x509_subject_names_from_pem_cert(const char* pem_cert, tsi_result result = TSI_OK; X509* cert = nullptr; BIO* pem; - pem = BIO_new_mem_buf((void*)pem_cert, (int)strlen(pem_cert)); + pem = BIO_new_mem_buf((void*)pem_cert, static_cast(strlen(pem_cert))); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; cert = PEM_read_bio_X509(pem, nullptr, nullptr, (void*)""); @@ -683,23 +683,23 @@ static tsi_result build_alpn_protocol_name_list( size_t length = alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]); if (length == 0 || length > 255) { - gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", (int)length); + gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", static_cast(length)); return TSI_INVALID_ARGUMENT; } *protocol_name_list_length += length + 1; } - *protocol_name_list = (unsigned char*)gpr_malloc(*protocol_name_list_length); + *protocol_name_list = static_cast(gpr_malloc(*protocol_name_list_length)); if (*protocol_name_list == nullptr) return TSI_OUT_OF_RESOURCES; current = *protocol_name_list; for (i = 0; i < num_alpn_protocols; i++) { size_t length = strlen(alpn_protocols[i]); - *(current++) = (uint8_t)length; /* max checked above. */ + *(current++) = static_cast(length); /* max checked above. */ memcpy(current, alpn_protocols[i], length); current += length; } /* Safety check. */ if ((current < *protocol_name_list) || - ((uintptr_t)(current - *protocol_name_list) != + (static_cast(current - *protocol_name_list) != *protocol_name_list_length)) { return TSI_INTERNAL_ERROR; } @@ -721,24 +721,24 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, size_t* unprotected_bytes_size, unsigned char* protected_output_frames, size_t* protected_output_frames_size) { - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast(self); int read_from_ssl; size_t available; tsi_result result = TSI_OK; /* First see if we have some pending data in the SSL BIO. */ - int pending_in_ssl = (int)BIO_pending(impl->network_io); + int pending_in_ssl = static_cast(BIO_pending(impl->network_io)); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->network_io, protected_output_frames, - (int)*protected_output_frames_size); + static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO even though some data is pending"); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = (size_t)read_from_ssl; + *protected_output_frames_size = static_cast(read_from_ssl); return TSI_OK; } @@ -760,12 +760,12 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->network_io, protected_output_frames, - (int)*protected_output_frames_size); + static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = (size_t)read_from_ssl; + *protected_output_frames_size = static_cast(read_from_ssl); *unprotected_bytes_size = available; impl->buffer_offset = 0; return TSI_OK; @@ -775,7 +775,7 @@ static tsi_result ssl_protector_protect_flush( tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast(self); int read_from_ssl = 0; int pending; @@ -785,22 +785,22 @@ static tsi_result ssl_protector_protect_flush( impl->buffer_offset = 0; } - pending = (int)BIO_pending(impl->network_io); + pending = static_cast(BIO_pending(impl->network_io)); GPR_ASSERT(pending >= 0); - *still_pending_size = (size_t)pending; + *still_pending_size = static_cast(pending); if (*still_pending_size == 0) return TSI_OK; GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->network_io, protected_output_frames, - (int)*protected_output_frames_size); + static_cast(*protected_output_frames_size)); if (read_from_ssl <= 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = (size_t)read_from_ssl; - pending = (int)BIO_pending(impl->network_io); + *protected_output_frames_size = static_cast(read_from_ssl); + pending = static_cast(BIO_pending(impl->network_io)); GPR_ASSERT(pending >= 0); - *still_pending_size = (size_t)pending; + *still_pending_size = static_cast(pending); return TSI_OK; } @@ -812,7 +812,7 @@ static tsi_result ssl_protector_unprotect( int written_into_ssl = 0; size_t output_bytes_size = *unprotected_bytes_size; size_t output_bytes_offset = 0; - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast(self); /* First, try to read remaining data from ssl. */ result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size); @@ -829,13 +829,13 @@ static tsi_result ssl_protector_unprotect( /* Then, try to write some data to ssl. */ GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX); written_into_ssl = BIO_write(impl->network_io, protected_frames_bytes, - (int)*protected_frames_bytes_size); + static_cast(*protected_frames_bytes_size)); if (written_into_ssl < 0) { gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d", written_into_ssl); return TSI_INTERNAL_ERROR; } - *protected_frames_bytes_size = (size_t)written_into_ssl; + *protected_frames_bytes_size = static_cast(written_into_ssl); /* Now try to read some data again. */ result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size); @@ -847,7 +847,7 @@ static tsi_result ssl_protector_unprotect( } static void ssl_protector_destroy(tsi_frame_protector* self) { - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast(self); if (impl->buffer != nullptr) gpr_free(impl->buffer); if (impl->ssl != nullptr) SSL_free(impl->ssl); if (impl->network_io != nullptr) BIO_free(impl->network_io); @@ -907,14 +907,14 @@ static void tsi_ssl_handshaker_factory_init( static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, unsigned char* bytes, size_t* bytes_size) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast(self); int bytes_read_from_ssl = 0; if (bytes == nullptr || bytes_size == nullptr || *bytes_size == 0 || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } GPR_ASSERT(*bytes_size <= INT_MAX); - bytes_read_from_ssl = BIO_read(impl->network_io, bytes, (int)*bytes_size); + bytes_read_from_ssl = BIO_read(impl->network_io, bytes, static_cast(*bytes_size)); if (bytes_read_from_ssl < 0) { *bytes_size = 0; if (!BIO_should_retry(impl->network_io)) { @@ -924,12 +924,12 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, return TSI_OK; } } - *bytes_size = (size_t)bytes_read_from_ssl; + *bytes_size = static_cast(bytes_read_from_ssl); return BIO_pending(impl->network_io) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; } static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast(self); if ((impl->result == TSI_HANDSHAKE_IN_PROGRESS) && SSL_is_init_finished(impl->ssl)) { impl->result = TSI_OK; @@ -939,20 +939,20 @@ static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { static tsi_result ssl_handshaker_process_bytes_from_peer( tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast(self); int bytes_written_into_ssl_size = 0; if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } GPR_ASSERT(*bytes_size <= INT_MAX); bytes_written_into_ssl_size = - BIO_write(impl->network_io, bytes, (int)*bytes_size); + BIO_write(impl->network_io, bytes, static_cast(*bytes_size)); if (bytes_written_into_ssl_size < 0) { gpr_log(GPR_ERROR, "Could not write to memory BIO."); impl->result = TSI_INTERNAL_ERROR; return impl->result; } - *bytes_size = (size_t)bytes_written_into_ssl_size; + *bytes_size = static_cast(bytes_written_into_ssl_size); if (!tsi_handshaker_is_in_progress(self)) { impl->result = TSI_OK; @@ -988,7 +988,7 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, tsi_result result = TSI_OK; const unsigned char* alpn_selected = nullptr; unsigned int alpn_selected_len; - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast(self); X509* peer_cert = SSL_get_peer_certificate(impl->ssl); if (peer_cert != nullptr) { result = peer_from_x509(peer_cert, 1, peer); @@ -1005,13 +1005,13 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, } if (alpn_selected != nullptr) { size_t i; - tsi_peer_property* new_properties = (tsi_peer_property*)gpr_zalloc( - sizeof(*new_properties) * (peer->property_count + 1)); + tsi_peer_property* new_properties = static_cast(gpr_zalloc( + sizeof(*new_properties) * (peer->property_count + 1))); for (i = 0; i < peer->property_count; i++) { new_properties[i] = peer->properties[i]; } result = tsi_construct_string_peer_property( - TSI_SSL_ALPN_SELECTED_PROTOCOL, (const char*)alpn_selected, + TSI_SSL_ALPN_SELECTED_PROTOCOL, reinterpret_cast(alpn_selected), alpn_selected_len, &new_properties[peer->property_count]); if (result != TSI_OK) { gpr_free(new_properties); @@ -1029,9 +1029,9 @@ static tsi_result ssl_handshaker_create_frame_protector( tsi_frame_protector** protector) { size_t actual_max_output_protected_frame_size = TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND; - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast(self); tsi_ssl_frame_protector* protector_impl = - (tsi_ssl_frame_protector*)gpr_zalloc(sizeof(*protector_impl)); + static_cast(gpr_zalloc(sizeof(*protector_impl))); if (max_output_protected_frame_size != nullptr) { if (*max_output_protected_frame_size > @@ -1048,7 +1048,7 @@ static tsi_result ssl_handshaker_create_frame_protector( protector_impl->buffer_size = actual_max_output_protected_frame_size - TSI_SSL_MAX_PROTECTION_OVERHEAD; protector_impl->buffer = - (unsigned char*)gpr_malloc(protector_impl->buffer_size); + static_cast(gpr_malloc(protector_impl->buffer_size)); if (protector_impl->buffer == nullptr) { gpr_log(GPR_ERROR, "Could not allocated buffer for tsi_ssl_frame_protector."); @@ -1070,7 +1070,7 @@ static tsi_result ssl_handshaker_create_frame_protector( } static void ssl_handshaker_destroy(tsi_handshaker* self) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast(self); SSL_free(impl->ssl); BIO_free(impl->network_io); tsi_ssl_handshaker_factory_unref(impl->factory_ref); @@ -1139,7 +1139,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, SSL_set_accept_state(ssl); } - impl = (tsi_ssl_handshaker*)gpr_zalloc(sizeof(*impl)); + impl = static_cast(gpr_zalloc(sizeof(*impl))); impl->ssl = ssl; impl->network_io = network_io; impl->result = TSI_HANDSHAKE_IN_PROGRESS; @@ -1157,11 +1157,11 @@ static int select_protocol_list(const unsigned char** out, const unsigned char* server_list, size_t server_list_len) { const unsigned char* client_current = client_list; - while ((unsigned int)(client_current - client_list) < client_list_len) { + while (static_cast(client_current - client_list) < client_list_len) { unsigned char client_current_len = *(client_current++); const unsigned char* server_current = server_list; while ((server_current >= server_list) && - (uintptr_t)(server_current - server_list) < server_list_len) { + static_cast(server_current - server_list) < server_list_len) { unsigned char server_current_len = *(server_current++); if ((client_current_len == server_current_len) && !memcmp(client_current, server_current, server_current_len)) { @@ -1195,7 +1195,7 @@ static void tsi_ssl_client_handshaker_factory_destroy( tsi_ssl_handshaker_factory* factory) { if (factory == nullptr) return; tsi_ssl_client_handshaker_factory* self = - (tsi_ssl_client_handshaker_factory*)factory; + reinterpret_cast(factory); if (self->ssl_context != nullptr) SSL_CTX_free(self->ssl_context); if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list); gpr_free(self); @@ -1207,7 +1207,7 @@ static int client_handshaker_factory_npn_callback(SSL* ssl, unsigned char** out, unsigned int inlen, void* arg) { tsi_ssl_client_handshaker_factory* factory = - (tsi_ssl_client_handshaker_factory*)arg; + static_cast(arg); return select_protocol_list((const unsigned char**)out, outlen, factory->alpn_protocol_list, factory->alpn_protocol_list_length, in, inlen); @@ -1234,7 +1234,7 @@ static void tsi_ssl_server_handshaker_factory_destroy( tsi_ssl_handshaker_factory* factory) { if (factory == nullptr) return; tsi_ssl_server_handshaker_factory* self = - (tsi_ssl_server_handshaker_factory*)factory; + reinterpret_cast(factory); size_t i; for (i = 0; i < self->ssl_context_count; i++) { if (self->ssl_contexts[i] != nullptr) { @@ -1301,7 +1301,7 @@ static int does_entry_match_name(const char* entry, size_t entry_length, static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, int* ap, void* arg) { tsi_ssl_server_handshaker_factory* impl = - (tsi_ssl_server_handshaker_factory*)arg; + static_cast(arg); size_t i = 0; const char* servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (servername == nullptr || strlen(servername) == 0) { @@ -1324,7 +1324,7 @@ static int server_handshaker_factory_alpn_callback( SSL* ssl, const unsigned char** out, unsigned char* outlen, const unsigned char* in, unsigned int inlen, void* arg) { tsi_ssl_server_handshaker_factory* factory = - (tsi_ssl_server_handshaker_factory*)arg; + static_cast(arg); return select_protocol_list(out, outlen, in, inlen, factory->alpn_protocol_list, factory->alpn_protocol_list_length); @@ -1334,10 +1334,10 @@ static int server_handshaker_factory_alpn_callback( static int server_handshaker_factory_npn_advertised_callback( SSL* ssl, const unsigned char** out, unsigned int* outlen, void* arg) { tsi_ssl_server_handshaker_factory* factory = - (tsi_ssl_server_handshaker_factory*)arg; + static_cast(arg); *out = factory->alpn_protocol_list; GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX); - *outlen = (unsigned int)factory->alpn_protocol_list_length; + *outlen = static_cast(factory->alpn_protocol_list_length); return SSL_TLSEXT_ERR_OK; } @@ -1367,7 +1367,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory( return TSI_INVALID_ARGUMENT; } - impl = (tsi_ssl_client_handshaker_factory*)gpr_zalloc(sizeof(*impl)); + impl = static_cast(gpr_zalloc(sizeof(*impl))); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &client_handshaker_factory_vtable; @@ -1397,7 +1397,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory( GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX); if (SSL_CTX_set_alpn_protos( ssl_context, impl->alpn_protocol_list, - (unsigned int)impl->alpn_protocol_list_length)) { + static_cast(impl->alpn_protocol_list_length))) { gpr_log(GPR_ERROR, "Could not set alpn protocol list to context."); result = TSI_INVALID_ARGUMENT; break; @@ -1452,14 +1452,14 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( return TSI_INVALID_ARGUMENT; } - impl = (tsi_ssl_server_handshaker_factory*)gpr_zalloc(sizeof(*impl)); + impl = static_cast(gpr_zalloc(sizeof(*impl))); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &server_handshaker_factory_vtable; impl->ssl_contexts = - (SSL_CTX**)gpr_zalloc(num_key_cert_pairs * sizeof(SSL_CTX*)); + static_cast(gpr_zalloc(num_key_cert_pairs * sizeof(SSL_CTX*))); impl->ssl_context_x509_subject_names = - (tsi_peer*)gpr_zalloc(num_key_cert_pairs * sizeof(tsi_peer)); + static_cast(gpr_zalloc(num_key_cert_pairs * sizeof(tsi_peer))); if (impl->ssl_contexts == nullptr || impl->ssl_context_x509_subject_names == nullptr) { tsi_ssl_handshaker_factory_unref(&impl->base); diff --git a/src/core/tsi/transport_security.cc b/src/core/tsi/transport_security.cc index 5abd2f0f68..5cfdf6fc32 100644 --- a/src/core/tsi/transport_security.cc +++ b/src/core/tsi/transport_security.cc @@ -288,7 +288,7 @@ tsi_result tsi_construct_allocated_string_peer_property( *property = tsi_init_peer_property(); if (name != nullptr) property->name = gpr_strdup(name); if (value_length > 0) { - property->value.data = (char*)gpr_zalloc(value_length); + property->value.data = static_cast(gpr_zalloc(value_length)); property->value.length = value_length; } return TSI_OK; @@ -316,8 +316,8 @@ tsi_result tsi_construct_string_peer_property(const char* name, tsi_result tsi_construct_peer(size_t property_count, tsi_peer* peer) { memset(peer, 0, sizeof(tsi_peer)); if (property_count > 0) { - peer->properties = (tsi_peer_property*)gpr_zalloc( - property_count * sizeof(tsi_peer_property)); + peer->properties = static_cast(gpr_zalloc( + property_count * sizeof(tsi_peer_property))); peer->property_count = property_count; } return TSI_OK; diff --git a/src/core/tsi/transport_security_adapter.cc b/src/core/tsi/transport_security_adapter.cc index 56dec55494..e57a42ad6c 100644 --- a/src/core/tsi/transport_security_adapter.cc +++ b/src/core/tsi/transport_security_adapter.cc @@ -59,7 +59,7 @@ static tsi_result adapter_result_get_unused_bytes( } static void adapter_result_destroy(tsi_handshaker_result* self) { - tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; + tsi_adapter_handshaker_result* impl = reinterpret_cast(self); tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->unused_bytes); gpr_free(self); @@ -82,12 +82,12 @@ static tsi_result tsi_adapter_create_handshaker_result( return TSI_INVALID_ARGUMENT; } tsi_adapter_handshaker_result* impl = - (tsi_adapter_handshaker_result*)gpr_zalloc(sizeof(*impl)); + static_cast(gpr_zalloc(sizeof(*impl))); impl->base.vtable = &result_vtable; impl->wrapped = wrapped; impl->unused_bytes_size = unused_bytes_size; if (unused_bytes_size > 0) { - impl->unused_bytes = (unsigned char*)gpr_malloc(unused_bytes_size); + impl->unused_bytes = static_cast(gpr_malloc(unused_bytes_size)); memcpy(impl->unused_bytes, unused_bytes, unused_bytes_size); } else { impl->unused_bytes = nullptr; @@ -137,7 +137,7 @@ static tsi_result adapter_create_frame_protector( } static void adapter_destroy(tsi_handshaker* self) { - tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)self; + tsi_adapter_handshaker* impl = reinterpret_cast(self); tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->adapter_buffer); gpr_free(self); @@ -156,7 +156,7 @@ static tsi_result adapter_next( } /* If there are received bytes, process them first. */ - tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)self; + tsi_adapter_handshaker* impl = reinterpret_cast(self); tsi_result status = TSI_OK; size_t bytes_consumed = received_bytes_size; if (received_bytes_size > 0) { @@ -174,8 +174,8 @@ static tsi_result adapter_next( offset += to_send_size; if (status == TSI_INCOMPLETE_DATA) { impl->adapter_buffer_size *= 2; - impl->adapter_buffer = (unsigned char*)gpr_realloc( - impl->adapter_buffer, impl->adapter_buffer_size); + impl->adapter_buffer = static_cast(gpr_realloc( + impl->adapter_buffer, impl->adapter_buffer_size)); } } while (status == TSI_INCOMPLETE_DATA); if (status != TSI_OK) return status; @@ -212,16 +212,16 @@ static const tsi_handshaker_vtable handshaker_vtable = { tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped) { GPR_ASSERT(wrapped != nullptr); tsi_adapter_handshaker* impl = - (tsi_adapter_handshaker*)gpr_zalloc(sizeof(*impl)); + static_cast(gpr_zalloc(sizeof(*impl))); impl->base.vtable = &handshaker_vtable; impl->wrapped = wrapped; impl->adapter_buffer_size = TSI_ADAPTER_INITIAL_BUFFER_SIZE; - impl->adapter_buffer = (unsigned char*)gpr_malloc(impl->adapter_buffer_size); + impl->adapter_buffer = static_cast(gpr_malloc(impl->adapter_buffer_size)); return &impl->base; } tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter) { if (adapter == nullptr) return nullptr; - tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)adapter; + tsi_adapter_handshaker* impl = reinterpret_cast(adapter); return impl->wrapped; } diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index cbe2a209f5..874f31b639 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -72,7 +72,7 @@ std::vector* channel_filters; namespace { bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) { - const FilterRecord& filter = *(FilterRecord*)arg; + const FilterRecord& filter = *static_cast(arg); if (filter.include_filter) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index a1f42c0b32..90b88d41a6 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -201,7 +201,7 @@ class TransportStreamOpBatch { } census_context* get_census_context() const { - return (census_context*)op_->payload->context[GRPC_CONTEXT_TRACING].value; + return static_cast(op_->payload->context[GRPC_CONTEXT_TRACING].value); } private: diff --git a/src/cpp/util/time_cc.cc b/src/cpp/util/time_cc.cc index 3b6e075929..d475c25a5b 100644 --- a/src/cpp/util/time_cc.cc +++ b/src/cpp/util/time_cc.cc @@ -39,8 +39,8 @@ void Timepoint2Timespec(const system_clock::time_point& from, return; } nanoseconds nsecs = duration_cast(deadline - secs); - to->tv_sec = (int64_t)secs.count(); - to->tv_nsec = (int32_t)nsecs.count(); + to->tv_sec = static_cast(secs.count()); + to->tv_nsec = static_cast(nsecs.count()); to->clock_type = GPR_CLOCK_REALTIME; } @@ -55,8 +55,8 @@ void TimepointHR2Timespec(const high_resolution_clock::time_point& from, return; } nanoseconds nsecs = duration_cast(deadline - secs); - to->tv_sec = (int64_t)secs.count(); - to->tv_nsec = (int32_t)nsecs.count(); + to->tv_sec = static_cast(secs.count()); + to->tv_nsec = static_cast(nsecs.count()); to->clock_type = GPR_CLOCK_REALTIME; } diff --git a/test/core/avl/avl_test.cc b/test/core/avl/avl_test.cc index ac1ab5c8e9..563de81a0d 100644 --- a/test/core/avl/avl_test.cc +++ b/test/core/avl/avl_test.cc @@ -34,9 +34,9 @@ static int* box(int x) { } static long int_compare(void* int1, void* int2, void* unused) { - return (*(int*)int1) - (*(int*)int2); + return (*static_cast(int1)) - (*static_cast(int2)); } -static void* int_copy(void* p, void* unused) { return box(*(int*)p); } +static void* int_copy(void* p, void* unused) { return box(*static_cast(p)); } static void destroy(void* p, void* unused) { gpr_free(p); } @@ -3604,17 +3604,17 @@ static void test_stress(int amount_of_stress) { int deletions = 0; grpc_avl avl; - unsigned seed = (unsigned)time(nullptr); + unsigned seed = static_cast(time(nullptr)); gpr_log(GPR_DEBUG, "test_stress amount=%d seed=%u", amount_of_stress, seed); - srand((unsigned)time(nullptr)); + srand(static_cast(time(nullptr))); avl = grpc_avl_create(&int_int_vtable); memset(added, 0, sizeof(added)); for (i = 1; deletions < amount_of_stress; i++) { - int idx = rand() % (int)GPR_ARRAY_SIZE(added); + int idx = rand() % static_castGPR_ARRAY_SIZE(added); GPR_ASSERT(i); if (rand() < RAND_MAX / 2) { added[idx] = i; @@ -3627,7 +3627,7 @@ static void test_stress(int amount_of_stress) { printf("avl = remove_int(avl, %d); /* d=%d */\n", idx, deletions); avl = remove_int(avl, idx); } - for (j = 0; j < (int)GPR_ARRAY_SIZE(added); j++) { + for (j = 0; j < static_castGPR_ARRAY_SIZE(added); j++) { if (added[j] != 0) { check_get(avl, j, added[j]); } else { diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index 53e910eddd..35a3b1459f 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -144,9 +144,9 @@ TEST(BackOffTest, JitterBackOff) { EXPECT_EQ(next - grpc_core::ExecCtx::Get()->Now(), initial_backoff); grpc_millis expected_next_lower_bound = - (grpc_millis)((double)current_backoff * (1 - jitter)); + static_cast(static_cast(current_backoff) * (1 - jitter)); grpc_millis expected_next_upper_bound = - (grpc_millis)((double)current_backoff * (1 + jitter)); + static_cast(static_cast(current_backoff) * (1 + jitter)); for (int i = 0; i < 10000; i++) { next = backoff.NextAttemptTime(); @@ -156,11 +156,11 @@ TEST(BackOffTest, JitterBackOff) { EXPECT_GE(timeout_millis, expected_next_lower_bound); EXPECT_LE(timeout_millis, expected_next_upper_bound); current_backoff = std::min( - (grpc_millis)((double)current_backoff * multiplier), max_backoff); + static_cast(static_cast(current_backoff) * multiplier), max_backoff); expected_next_lower_bound = - (grpc_millis)((double)current_backoff * (1 - jitter)); + static_cast(static_cast(current_backoff) * (1 - jitter)); expected_next_upper_bound = - (grpc_millis)((double)current_backoff * (1 + jitter)); + static_cast(static_cast(current_backoff) * (1 + jitter)); } } diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index df803d16a2..ee55a95e4e 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -49,7 +49,7 @@ typedef struct { /* Run the server side validator and set done_thd once done */ static void thd_func(void* arg) { - thd_args* a = (thd_args*)arg; + thd_args* a = static_cast(arg); if (a->validator != nullptr) { a->validator(a->server, a->cq, a->registered_method); } @@ -58,12 +58,12 @@ static void thd_func(void* arg) { /* Sets the done_write event */ static void set_done_write(void* arg, grpc_error* error) { - gpr_event* done_write = (gpr_event*)arg; + gpr_event* done_write = static_cast(arg); gpr_event_set(done_write, (void*)1); } static void server_setup_transport(void* ts, grpc_transport* transport) { - thd_args* a = (thd_args*)ts; + thd_args* a = static_cast(ts); grpc_core::ExecCtx exec_ctx; grpc_server_setup_transport(a->server, transport, nullptr, grpc_server_get_channel_args(a->server)); @@ -71,7 +71,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 = (gpr_event*)arg; + gpr_event* read_done = static_cast(arg); gpr_event_set(read_done, (void*)1); } diff --git a/test/core/bad_client/tests/duplicate_header.cc b/test/core/bad_client/tests/duplicate_header.cc index 0d689bbb7e..12b9c79ab8 100644 --- a/test/core/bad_client/tests/duplicate_header.cc +++ b/test/core/bad_client/tests/duplicate_header.cc @@ -87,7 +87,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, op->flags = 0; op->reserved = nullptr; 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), 1); @@ -108,7 +108,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, op->flags = 0; op->reserved = nullptr; 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), 1); 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 8668e091b6..427db46446 100644 --- a/test/core/bad_client/tests/head_of_line_blocking.cc +++ b/test/core/bad_client/tests/head_of_line_blocking.cc @@ -117,9 +117,9 @@ int main(int argc, char** argv) { addbuf(prefix, sizeof(prefix) - 1); for (i = 0; i < NUM_FRAMES; i++) { - uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), - (uint8_t)(FRAME_SIZE >> 8), - (uint8_t)FRAME_SIZE, + uint8_t hdr[9] = {static_cast(FRAME_SIZE >> 16), + static_cast(FRAME_SIZE >> 8), + static_cast(FRAME_SIZE), 0, 0, 0, diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc index fe6b05d03a..7c012ac055 100644 --- a/test/core/bad_client/tests/window_overflow.cc +++ b/test/core/bad_client/tests/window_overflow.cc @@ -76,9 +76,9 @@ int main(int argc, char** argv) { addbuf(PFX_STR, sizeof(PFX_STR) - 1); for (i = 0; i < NUM_FRAMES; i++) { - uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), - (uint8_t)(FRAME_SIZE >> 8), - (uint8_t)FRAME_SIZE, + uint8_t hdr[9] = {static_cast(FRAME_SIZE >> 16), + static_cast(FRAME_SIZE >> 8), + static_castFRAME_SIZE, 0, 0, 0, diff --git a/test/core/bad_ssl/bad_ssl_test.cc b/test/core/bad_ssl/bad_ssl_test.cc index e2ab22e014..e2ea7540ef 100644 --- a/test/core/bad_ssl/bad_ssl_test.cc +++ b/test/core/bad_ssl/bad_ssl_test.cc @@ -127,7 +127,7 @@ int main(int argc, char** argv) { gpr_subprocess* svr; /* figure out where we are */ if (lslash) { - memcpy(root, me, (size_t)(lslash - me)); + memcpy(root, me, static_cast(lslash - me)); root[lslash - me] = 0; } else { strcpy(root, "."); @@ -139,7 +139,7 @@ int main(int argc, char** argv) { tmp = lunder - 1; while (*tmp != '_') tmp--; tmp++; - memcpy(test, tmp, (size_t)(lunder - tmp)); + memcpy(test, tmp, static_cast(lunder - tmp)); /* start the server */ gpr_asprintf(&args[0], "%s/bad_ssl_%s_server%s", root, test, gpr_subprocess_binary_extension()); diff --git a/test/core/bad_ssl/servers/cert.cc b/test/core/bad_ssl/servers/cert.cc index 3ed7d029ee..d9ac49823b 100644 --- a/test/core/bad_ssl/servers/cert.cc +++ b/test/core/bad_ssl/servers/cert.cc @@ -45,8 +45,8 @@ int main(int argc, char** argv) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file("src/core/tsi/test_creds/badserver.key", 1, &key_slice))); - pem_key_cert_pair.private_key = (const char*)GRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = (const char*)GRPC_SLICE_START_PTR(cert_slice); + pem_key_cert_pair.private_key = reinterpret_castGRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = reinterpret_castGRPC_SLICE_START_PTR(cert_slice); ssl_creds = grpc_ssl_server_credentials_create(nullptr, &pem_key_cert_pair, 1, 0, nullptr); diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index d232bc02ac..11b280ef29 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -82,7 +82,7 @@ static void test_compression_algorithm_states(void) { ch_args = grpc_channel_args_copy_and_add(nullptr, nullptr, 0); /* by default, all enabled */ states_bitset = - (unsigned)grpc_channel_args_compression_algorithm_get_states(ch_args); + static_cast(grpc_channel_args_compression_algorithm_get_states(ch_args)); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { GPR_ASSERT(GPR_BITGET(states_bitset, i)); @@ -100,8 +100,8 @@ static void test_compression_algorithm_states(void) { &ch_args_wo_gzip_deflate, GRPC_COMPRESS_STREAM_GZIP, 0); GPR_ASSERT(ch_args_wo_gzip_deflate == ch_args_wo_gzip_deflate_gzip); - states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( - ch_args_wo_gzip_deflate); + states_bitset = static_cast(grpc_channel_args_compression_algorithm_get_states( + ch_args_wo_gzip_deflate)); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_GZIP || i == GRPC_COMPRESS_DEFLATE || i == GRPC_COMPRESS_STREAM_GZIP) { @@ -118,8 +118,8 @@ static void test_compression_algorithm_states(void) { &ch_args_wo_gzip, GRPC_COMPRESS_STREAM_GZIP, 1); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate_gzip); - states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( - ch_args_wo_gzip); + states_bitset = static_cast(grpc_channel_args_compression_algorithm_get_states( + ch_args_wo_gzip)); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_DEFLATE) { GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0); diff --git a/test/core/channel/channel_stack_builder_test.cc b/test/core/channel/channel_stack_builder_test.cc index ef6db81b0b..aad6d6eee9 100644 --- a/test/core/channel/channel_stack_builder_test.cc +++ b/test/core/channel/channel_stack_builder_test.cc @@ -116,7 +116,7 @@ static bool add_replacement_filter(grpc_channel_stack_builder* builder, static bool add_original_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, set_arg_once_fn, + builder, static_cast(arg), set_arg_once_fn, &g_original_fn_called); } diff --git a/test/core/channel/channel_stack_test.cc b/test/core/channel/channel_stack_test.cc index ef43facd6e..2f5329a96d 100644 --- a/test/core/channel/channel_stack_test.cc +++ b/test/core/channel/channel_stack_test.cc @@ -35,14 +35,14 @@ static grpc_error* channel_init_func(grpc_channel_element* elem, GPR_ASSERT(args->channel_args->args[0].value.integer == 42); GPR_ASSERT(args->is_first); GPR_ASSERT(args->is_last); - *(int*)(elem->channel_data) = 0; + *static_cast(elem->channel_data) = 0; return GRPC_ERROR_NONE; } static grpc_error* call_init_func(grpc_call_element* elem, const grpc_call_element_args* args) { - ++*(int*)(elem->channel_data); - *(int*)(elem->call_data) = 0; + ++*static_cast(elem->channel_data); + *static_cast(elem->call_data) = 0; return GRPC_ERROR_NONE; } @@ -51,16 +51,16 @@ static void channel_destroy_func(grpc_channel_element* elem) {} static void call_destroy_func(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - ++*(int*)(elem->channel_data); + ++*static_cast(elem->channel_data); } static void call_func(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - ++*(int*)(elem->call_data); + ++*static_cast(elem->call_data); } static void channel_func(grpc_channel_element* elem, grpc_transport_op* op) { - ++*(int*)(elem->channel_data); + ++*static_cast(elem->channel_data); } static void free_channel(void* arg, grpc_error* error) { @@ -111,7 +111,7 @@ static void test_create_channel_stack(void) { &chan_args, nullptr, "test", channel_stack); GPR_ASSERT(channel_stack->count == 1); channel_elem = grpc_channel_stack_element(channel_stack, 0); - channel_data = (int*)channel_elem->channel_data; + channel_data = static_cast(channel_elem->channel_data); GPR_ASSERT(*channel_data == 0); call_stack = @@ -133,7 +133,7 @@ static void test_create_channel_stack(void) { call_elem = grpc_call_stack_element(call_stack, 0); GPR_ASSERT(call_elem->filter == channel_elem->filter); GPR_ASSERT(call_elem->channel_data == channel_elem->channel_data); - call_data = (int*)call_elem->call_data; + call_data = static_cast(call_elem->call_data); GPR_ASSERT(*call_data == 0); GPR_ASSERT(*channel_data == 1); diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 6d56961d84..670ecb4c2f 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -39,7 +39,7 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { grpc_resolved_address addr; GPR_ASSERT(1 == grpc_parse_unix(uri, &addr)); - struct sockaddr_un* addr_un = (struct sockaddr_un*)addr.addr; + struct sockaddr_un* addr_un = reinterpret_cast(addr.addr); GPR_ASSERT(AF_UNIX == addr_un->sun_family); GPR_ASSERT(0 == strcmp(addr_un->sun_path, pathname)); @@ -60,7 +60,7 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, char ntop_buf[INET_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv4(uri, &addr)); - struct sockaddr_in* addr_in = (struct sockaddr_in*)addr.addr; + struct sockaddr_in* addr_in = reinterpret_cast(addr.addr); GPR_ASSERT(AF_INET == addr_in->sin_family); GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET, &addr_in->sin_addr, ntop_buf, sizeof(ntop_buf))); @@ -78,7 +78,7 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, char ntop_buf[INET6_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv6(uri, &addr)); - struct sockaddr_in6* addr_in6 = (struct sockaddr_in6*)addr.addr; + struct sockaddr_in6* addr_in6 = reinterpret_cast(addr.addr); GPR_ASSERT(AF_INET6 == addr_in6->sin6_family); GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET6, &addr_in6->sin6_addr, ntop_buf, sizeof(ntop_buf))); 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 8cafadf05a..966fb1d14b 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -95,7 +95,7 @@ static grpc_core::OrphanablePtr create_resolver( } static void on_done(void* ev, grpc_error* error) { - gpr_event_set((gpr_event*)ev, (void*)1); + gpr_event_set(static_cast(ev), (void*)1); } // interleave waiting for an event with a timer check diff --git a/test/core/compression/stream_compression_test.cc b/test/core/compression/stream_compression_test.cc index 2f30b7fc19..1236529b4a 100644 --- a/test/core/compression/stream_compression_test.cc +++ b/test/core/compression/stream_compression_test.cc @@ -29,7 +29,7 @@ static void generate_random_payload(char* payload, size_t size) { size_t i; static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; for (i = 0; i < size - 1; ++i) { - payload[i] = chars[rand() % (int)(sizeof(chars) - 1)]; + payload[i] = chars[rand() % static_cast(sizeof(chars) - 1)]; } payload[size - 1] = '\0'; } @@ -43,7 +43,7 @@ static bool slice_buffer_equals_string(grpc_slice_buffer* buf, size_t pointer = 0; for (i = 0; i < buf->count; i++) { size_t slice_len = GRPC_SLICE_LENGTH(buf->slices[i]); - if (0 != strncmp(str + pointer, (char*)GRPC_SLICE_START_PTR(buf->slices[i]), + if (0 != strncmp(str + pointer, reinterpret_castGRPC_SLICE_START_PTR(buf->slices[i]), slice_len)) { return false; } @@ -112,7 +112,7 @@ test_stream_compression_simple_compress_decompress_with_output_size_constraint() GPR_ASSERT(output_size == max_output_size); GPR_ASSERT(end_of_context == false); grpc_slice slice_recv = grpc_slice_buffer_take_first(&sink); - char* str_recv = (char*)GRPC_SLICE_START_PTR(slice_recv); + char* str_recv = reinterpret_castGRPC_SLICE_START_PTR(slice_recv); GPR_ASSERT(GRPC_SLICE_LENGTH(slice_recv) == max_output_size); GPR_ASSERT(0 == strncmp(test_str, str_recv, max_output_size)); grpc_slice_unref(slice_recv); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 2b98620164..124d05af47 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -133,7 +133,7 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); - test_tcp_server* server = (test_tcp_server*)arg; + test_tcp_server* server = static_cast(arg); GRPC_CLOSURE_INIT(&on_read, handle_read, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&on_write, done_write, nullptr, grpc_schedule_on_exec_ctx); grpc_slice_buffer_init(&state.temp_incoming_buffer); @@ -196,7 +196,7 @@ static void start_rpc(int target_port, grpc_status_code expected_status, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(state.call, ops, (size_t)(op - ops), tag(1), + error = grpc_call_start_batch(state.call, ops, static_cast(op - ops), tag(1), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); @@ -236,7 +236,7 @@ typedef struct { } poll_args; static void actually_poll_server(void* arg) { - poll_args* pa = (poll_args*)arg; + poll_args* pa = static_cast(arg); gpr_timespec deadline = n_sec_deadline(10); while (true) { bool done = gpr_atm_acq_load(&state.done_atm) != 0; @@ -258,7 +258,7 @@ static void poll_server_until_read_done(test_tcp_server* server, gpr_atm_rel_store(&state.done_atm, 0); state.write_done = 0; gpr_thd_id id; - poll_args* pa = (poll_args*)gpr_malloc(sizeof(*pa)); + poll_args* pa = static_cast(gpr_malloc(sizeof(*pa))); pa->server = server; pa->signal_when_done = signal_when_done; gpr_thd_new(&id, "grpc_poll_server", actually_poll_server, pa, nullptr); diff --git a/test/core/end2end/cq_verifier.cc b/test/core/end2end/cq_verifier.cc index a7b37f3c12..c3a3f43fe1 100644 --- a/test/core/end2end/cq_verifier.cc +++ b/test/core/end2end/cq_verifier.cc @@ -61,7 +61,7 @@ struct cq_verifier { }; cq_verifier* cq_verifier_create(grpc_completion_queue* cq) { - cq_verifier* v = (cq_verifier*)gpr_malloc(sizeof(cq_verifier)); + cq_verifier* v = static_cast(gpr_malloc(sizeof(cq_verifier))); v->cq = cq; v->first_expectation = nullptr; return v; @@ -305,7 +305,7 @@ void cq_verify_empty(cq_verifier* v) { cq_verify_empty_timeout(v, 1); } static void add(cq_verifier* v, const char* file, int line, grpc_completion_type type, void* tag, bool success) { - expectation* e = (expectation*)gpr_malloc(sizeof(expectation)); + expectation* e = static_cast(gpr_malloc(sizeof(expectation))); e->type = type; e->file = file; e->line = line; diff --git a/test/core/end2end/dualstack_socket_test.cc b/test/core/end2end/dualstack_socket_test.cc index 2dc72b885f..a7f10e49bf 100644 --- a/test/core/end2end/dualstack_socket_test.cc +++ b/test/core/end2end/dualstack_socket_test.cc @@ -129,7 +129,7 @@ void test_connect(const char* server_host, const char* client_host, int port, char** hosts_with_port; uri_slice = - grpc_slice_new((char*)client_host, strlen(client_host), do_nothing); + grpc_slice_new(const_cast(client_host), strlen(client_host), do_nothing); grpc_slice_buffer_init(&uri_parts); grpc_slice_split(uri_slice, ",", &uri_parts); hosts_with_port = @@ -199,7 +199,7 @@ void test_connect(const char* server_host, const char* client_host, int port, op->flags = 0; op->reserved = nullptr; 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); if (expect_ok) { @@ -228,7 +228,7 @@ void test_connect(const char* server_host, const char* client_host, int port, op->flags = 0; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + 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), 1); diff --git a/test/core/end2end/fixtures/h2_oauth2.cc b/test/core/end2end/fixtures/h2_oauth2.cc index 795e94a9e8..9453f2f7cb 100644 --- a/test/core/end2end/fixtures/h2_oauth2.cc +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -66,7 +66,7 @@ static void process_oauth2_success(void* state, grpc_auth_context* ctx, test_processor_state* s; GPR_ASSERT(state != nullptr); - s = (test_processor_state*)state; + s = static_cast(state); GPR_ASSERT(s->pseudo_refcount == 1); GPR_ASSERT(oauth2 != nullptr); grpc_auth_context_add_cstring_property(ctx, client_identity_property_name, @@ -84,7 +84,7 @@ static void process_oauth2_failure(void* state, grpc_auth_context* ctx, find_metadata(md, md_count, "authorization", oauth2_md); test_processor_state* s; GPR_ASSERT(state != nullptr); - s = (test_processor_state*)state; + s = static_cast(state); GPR_ASSERT(s->pseudo_refcount == 1); GPR_ASSERT(oauth2 != nullptr); cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr); @@ -177,7 +177,7 @@ static int fail_server_auth_check(grpc_channel_args* server_args) { } static void processor_destroy(void* state) { - test_processor_state* s = (test_processor_state*)state; + test_processor_state* s = static_cast(state); GPR_ASSERT((s->pseudo_refcount--) == 1); gpr_free(s); } diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 2d5e841aea..4776cfbc1b 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -185,7 +185,7 @@ static void proxy_connection_failed(proxy_connection* conn, // Callback for writing proxy data to the client. static void on_client_write_done(void* arg, grpc_error* error) { - proxy_connection* conn = (proxy_connection*)arg; + proxy_connection* conn = static_cast(arg); conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { proxy_connection_failed(conn, CLIENT_WRITE_FAILED, @@ -210,7 +210,7 @@ static void on_client_write_done(void* arg, grpc_error* error) { // Callback for writing proxy data to the backend server. static void on_server_write_done(void* arg, grpc_error* error) { - proxy_connection* conn = (proxy_connection*)arg; + proxy_connection* conn = static_cast(arg); conn->server_is_writing = false; if (error != GRPC_ERROR_NONE) { proxy_connection_failed(conn, SERVER_WRITE_FAILED, @@ -236,7 +236,7 @@ static void on_server_write_done(void* arg, grpc_error* error) { // Callback for reading data from the client, which will be proxied to // the backend server. static void on_client_read_done(void* arg, grpc_error* error) { - proxy_connection* conn = (proxy_connection*)arg; + proxy_connection* conn = static_cast(arg); if (error != GRPC_ERROR_NONE) { proxy_connection_failed(conn, CLIENT_READ_FAILED, "HTTP proxy client read", GRPC_ERROR_REF(error)); @@ -267,7 +267,7 @@ static void on_client_read_done(void* arg, grpc_error* error) { // Callback for reading data from the backend server, which will be // proxied to the client. static void on_server_read_done(void* arg, grpc_error* error) { - proxy_connection* conn = (proxy_connection*)arg; + proxy_connection* conn = static_cast(arg); if (error != GRPC_ERROR_NONE) { proxy_connection_failed(conn, SERVER_READ_FAILED, "HTTP proxy server read", GRPC_ERROR_REF(error)); @@ -297,7 +297,7 @@ static void on_server_read_done(void* arg, grpc_error* error) { // Callback to write the HTTP response for the CONNECT request. static void on_write_response_done(void* arg, grpc_error* error) { - proxy_connection* conn = (proxy_connection*)arg; + proxy_connection* conn = static_cast(arg); conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy write response", @@ -321,7 +321,7 @@ static void on_write_response_done(void* arg, grpc_error* error) { // Callback to connect to the backend server specified by the HTTP // CONNECT request. static void on_server_connect_done(void* arg, grpc_error* error) { - proxy_connection* conn = (proxy_connection*)arg; + proxy_connection* conn = static_cast(arg); if (error != GRPC_ERROR_NONE) { // TODO(roth): Technically, in this case, we should handle the error // by returning an HTTP response to the client indicating that the @@ -370,7 +370,7 @@ static bool proxy_auth_header_matches(char* proxy_auth_header_val, // of this test code, it's fine to pretend this is a client-side error, // which will cause the client connection to be dropped. static void on_read_request_done(void* arg, grpc_error* error) { - proxy_connection* conn = (proxy_connection*)arg; + proxy_connection* conn = static_cast(arg); gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, grpc_error_string(error)); if (error != GRPC_ERROR_NONE) { @@ -456,9 +456,9 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); - grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; + grpc_end2end_http_proxy* proxy = static_cast(arg); // Instantiate proxy_connection. - proxy_connection* conn = (proxy_connection*)gpr_zalloc(sizeof(*conn)); + proxy_connection* conn = static_cast(gpr_zalloc(sizeof(*conn))); gpr_ref(&proxy->users); conn->client_endpoint = endpoint; conn->proxy = proxy; @@ -499,7 +499,7 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, // static void thread_main(void* arg) { - grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; + grpc_end2end_http_proxy* proxy = static_cast(arg); grpc_core::ExecCtx exec_ctx; do { gpr_ref(&proxy->users); @@ -518,7 +518,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_channel_args* args) { grpc_core::ExecCtx exec_ctx; grpc_end2end_http_proxy* proxy = - (grpc_end2end_http_proxy*)gpr_malloc(sizeof(*proxy)); + static_cast(gpr_malloc(sizeof(*proxy))); memset(proxy, 0, sizeof(*proxy)); proxy->combiner = grpc_combiner_create(); gpr_ref_init(&proxy->users, 1); @@ -533,7 +533,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); memset(&resolved_addr, 0, sizeof(resolved_addr)); addr->sin_family = AF_INET; grpc_sockaddr_set_port(&resolved_addr, proxy_port); @@ -542,7 +542,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(port == proxy_port); // Start server. - proxy->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + proxy->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(proxy->pollset, &proxy->mu); grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy); @@ -555,7 +555,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( } static void destroy_pollset(void* arg, grpc_error* error) { - grpc_pollset* pollset = (grpc_pollset*)arg; + grpc_pollset* pollset = static_cast(arg); grpc_pollset_destroy(pollset); gpr_free(pollset); } diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index 7a35796e9c..d0a4bbb96e 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -80,7 +80,7 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, int proxy_port = grpc_pick_unused_port_or_die(); int server_port = grpc_pick_unused_port_or_die(); - grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)gpr_malloc(sizeof(*proxy)); + grpc_end2end_proxy* proxy = static_cast(gpr_malloc(sizeof(*proxy))); memset(proxy, 0, sizeof(*proxy)); gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port); @@ -107,14 +107,14 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, } static closure* new_closure(void (*func)(void* arg, int success), void* arg) { - closure* cl = (closure*)gpr_malloc(sizeof(*cl)); + closure* cl = static_cast(gpr_malloc(sizeof(*cl))); cl->func = func; cl->arg = arg; return cl; } static void shutdown_complete(void* arg, int success) { - grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)arg; + grpc_end2end_proxy* proxy = static_cast(arg); proxy->shutdown = 1; grpc_completion_queue_shutdown(proxy->cq); } @@ -147,12 +147,12 @@ static void unrefpc(proxy_call* pc, const char* reason) { static void refpc(proxy_call* pc, const char* reason) { gpr_ref(&pc->refs); } static void on_c2p_sent_initial_metadata(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); unrefpc(pc, "on_c2p_sent_initial_metadata"); } static void on_p2s_recv_initial_metadata(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); grpc_op op; grpc_call_error err; @@ -174,14 +174,14 @@ static void on_p2s_recv_initial_metadata(void* arg, int success) { } static void on_p2s_sent_initial_metadata(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); unrefpc(pc, "on_p2s_sent_initial_metadata"); } static void on_c2p_recv_msg(void* arg, int success); static void on_p2s_sent_message(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); grpc_op op; grpc_call_error err; @@ -201,12 +201,12 @@ static void on_p2s_sent_message(void* arg, int success) { } static void on_p2s_sent_close(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); unrefpc(pc, "on_p2s_sent_close"); } static void on_c2p_recv_msg(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); grpc_op op; grpc_call_error err; @@ -241,7 +241,7 @@ static void on_c2p_recv_msg(void* arg, int success) { static void on_p2s_recv_msg(void* arg, int success); static void on_c2p_sent_message(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); grpc_op op; grpc_call_error err; @@ -261,7 +261,7 @@ static void on_c2p_sent_message(void* arg, int success) { } static void on_p2s_recv_msg(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); grpc_op op; grpc_call_error err; @@ -281,12 +281,12 @@ static void on_p2s_recv_msg(void* arg, int success) { } static void on_c2p_sent_status(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); unrefpc(pc, "on_c2p_sent_status"); } static void on_p2s_status(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); grpc_op op; grpc_call_error err; @@ -311,18 +311,18 @@ static void on_p2s_status(void* arg, int success) { } static void on_c2p_closed(void* arg, int success) { - proxy_call* pc = (proxy_call*)arg; + proxy_call* pc = static_cast(arg); unrefpc(pc, "on_c2p_closed"); } static void on_new_call(void* arg, int success) { - grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)arg; + grpc_end2end_proxy* proxy = static_cast(arg); grpc_call_error err; if (success) { grpc_op op; memset(&op, 0, sizeof(op)); - proxy_call* pc = (proxy_call*)gpr_malloc(sizeof(*pc)); + proxy_call* pc = static_cast(gpr_malloc(sizeof(*pc))); memset(pc, 0, sizeof(*pc)); pc->proxy = proxy; GPR_SWAP(grpc_metadata_array, pc->c2p_initial_metadata, @@ -412,7 +412,7 @@ static void request_call(grpc_end2end_proxy* proxy) { } static void thread_main(void* arg) { - grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)arg; + grpc_end2end_proxy* proxy = static_cast(arg); closure* cl; for (;;) { grpc_event ev = grpc_completion_queue_next( @@ -424,7 +424,7 @@ static void thread_main(void* arg) { case GRPC_QUEUE_SHUTDOWN: return; case GRPC_OP_COMPLETE: - cl = (closure*)ev.tag; + cl = static_cast(ev.tag); cl->func(cl->arg, ev.success); gpr_free(cl); break; diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 14c155502a..fa50c24ca5 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -93,7 +93,7 @@ static char* read_string(input_stream* inp, bool* special) { cap = GPR_MAX(3 * cap / 2, cap + 8); str = static_cast(gpr_realloc(str, cap)); } - c = (char)next_byte(inp); + c = static_cast(next_byte(inp)); str[sz++] = c; } while (c != 0 && c != 1); if (special != nullptr) { @@ -116,7 +116,7 @@ static void read_buffer(input_stream* inp, char** buffer, size_t* length, } *buffer = static_cast(gpr_malloc(*length)); for (size_t i = 0; i < *length; i++) { - (*buffer)[i] = (char)next_byte(inp); + (*buffer)[i] = static_cast(next_byte(inp)); } } @@ -192,7 +192,7 @@ static grpc_byte_buffer* read_message(input_stream* inp) { return out; } -static int read_int(input_stream* inp) { return (int)read_uint32(inp); } +static int read_int(input_stream* inp) { return static_cast(read_uint32(inp)); } static grpc_channel_args* read_args(input_stream* inp) { size_t n = next_byte(inp); @@ -529,10 +529,10 @@ static validator* create_validator(void (*validate)(void* arg, bool success), static void assert_success_and_decrement(void* counter, bool success) { GPR_ASSERT(success); - --*(int*)counter; + --*static_cast(counter); } -static void decrement(void* counter, bool success) { --*(int*)counter; } +static void decrement(void* counter, bool success) { --*static_cast(counter); } typedef struct connectivity_watch { int* counter; diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index c17d581d8b..16acf8ef28 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*)(uintptr_t)n; } +static void* tag(int n) { return (void*)static_cast(n); } 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 61c55e0afd..5eb83ede7a 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -30,8 +30,8 @@ bool leak_check = true; static void discard_write(grpc_slice slice) {} -static void* tag(int n) { return (void*)(uintptr_t)n; } -static int detag(void* p) { return (int)(uintptr_t)p; } +static void* tag(int n) { return (void*)static_cast(n); } +static int detag(void* p) { return static_cast((uintptr_t)p); } static void dont_log(gpr_log_func_args* args) {} diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index f23d87ea68..20468ad0e5 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -77,10 +77,10 @@ static void my_resolve_address(const char* addr, const char* default_port, (*addrs)->addrs = static_cast( gpr_malloc(sizeof(*(*addrs)->addrs))); memset((*addrs)->addrs, 0, sizeof(*(*addrs)->addrs)); - struct sockaddr_in* sa = (struct sockaddr_in*)(*addrs)->addrs[0].addr; + struct sockaddr_in* sa = reinterpret_cast((*addrs)->addrs[0].addr); sa->sin_family = AF_INET; sa->sin_addr.s_addr = htonl(0x7f000001); - sa->sin_port = htons((uint16_t)g_resolve_port); + sa->sin_port = htons(static_cast(g_resolve_port)); (*addrs)->addrs[0].len = sizeof(*sa); gpr_mu_unlock(&g_mu); } @@ -109,7 +109,7 @@ static grpc_ares_request* my_dns_lookup_ares( gpr_zalloc(sizeof(struct sockaddr_in))); sa->sin_family = AF_INET; sa->sin_addr.s_addr = htonl(0x7f000001); - sa->sin_port = htons((uint16_t)g_resolve_port); + sa->sin_port = htons(static_cast(g_resolve_port)); grpc_lb_addresses_set_address(*lb_addrs, 0, sa, sizeof(*sa), false, nullptr, nullptr); gpr_free(sa); diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index cd62c3f4e2..b4b3462c68 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -333,7 +333,7 @@ static void simple_request_body(grpc_end2end_test_fixture f, op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY; op->reserved = nullptr; 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), expected_result == SUCCESS); diff --git a/test/core/end2end/invalid_call_argument_test.cc b/test/core/end2end/invalid_call_argument_test.cc index d2b26e7131..6cb2e3ee80 100644 --- a/test/core/end2end/invalid_call_argument_test.cc +++ b/test/core/end2end/invalid_call_argument_test.cc @@ -209,7 +209,7 @@ static void test_too_many_metadata() { op = g_state.ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = (size_t)INT_MAX + 1; + op->data.send_initial_metadata.count = static_cast(INT_MAX) + 1; op->flags = 0; op->reserved = nullptr; op++; @@ -499,7 +499,7 @@ static void test_too_many_trailing_metadata() { op = g_state.ops; op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = - (size_t)INT_MAX + 1; + static_cast(INT_MAX) + 1; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; grpc_slice status_details = grpc_slice_from_static_string("xyz"); op->data.send_status_from_server.status_details = &status_details; diff --git a/test/core/end2end/tests/authority_not_supported.cc b/test/core/end2end/tests/authority_not_supported.cc index f2852f772e..498fb5cf35 100644 --- a/test/core/end2end/tests/authority_not_supported.cc +++ b/test/core/end2end/tests/authority_not_supported.cc @@ -154,7 +154,7 @@ static void test_with_authority_header(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/bad_hostname.cc b/test/core/end2end/tests/bad_hostname.cc index 63bfd76120..60097dfa4c 100644 --- a/test/core/end2end/tests/bad_hostname.cc +++ b/test/core/end2end/tests/bad_hostname.cc @@ -133,7 +133,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/bad_ping.cc b/test/core/end2end/tests/bad_ping.cc index 672c2f4c6e..0972e86e9a 100644 --- a/test/core/end2end/tests/bad_ping.cc +++ b/test/core/end2end/tests/bad_ping.cc @@ -144,7 +144,7 @@ static void test_bad_ping(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -188,7 +188,7 @@ static void test_bad_ping(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/binary_metadata.cc b/test/core/end2end/tests/binary_metadata.cc index 8a0d667428..1313ca4bea 100644 --- a/test/core/end2end/tests/binary_metadata.cc +++ b/test/core/end2end/tests/binary_metadata.cc @@ -182,7 +182,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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 = @@ -205,7 +205,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); @@ -246,7 +246,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/call_creds.cc b/test/core/end2end/tests/call_creds.cc index 968dab1995..cb65b18064 100644 --- a/test/core/end2end/tests/call_creds.cc +++ b/test/core/end2end/tests/call_creds.cc @@ -219,7 +219,7 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = nullptr; 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 = @@ -253,7 +253,7 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = nullptr; 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), 1); @@ -279,7 +279,7 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = nullptr; 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), 1); @@ -443,7 +443,7 @@ static void test_request_with_server_rejecting_client_creds( op->flags = 0; op->reserved = nullptr; 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(error == GRPC_CALL_OK); CQ_EXPECT_COMPLETION(cqv, tag(1), 1); diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index 11bf4e79b7..86c91c1580 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -186,7 +186,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = grpc_server_request_call(f.server, &s, &call_details, @@ -217,7 +217,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(3), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(3), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr)); diff --git a/test/core/end2end/tests/cancel_after_client_done.cc b/test/core/end2end/tests/cancel_after_client_done.cc index b0702b7f44..9e92c27f03 100644 --- a/test/core/end2end/tests/cancel_after_client_done.cc +++ b/test/core/end2end/tests/cancel_after_client_done.cc @@ -164,7 +164,7 @@ static void test_cancel_after_accept_and_writes_closed( op->flags = 0; op->reserved = nullptr; 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 = grpc_server_request_call(f.server, &s, &call_details, @@ -195,7 +195,7 @@ static void test_cancel_after_accept_and_writes_closed( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(3), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(3), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr)); diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index 63e6505f0e..88aa63c7af 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -181,7 +181,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 +208,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); @@ -234,7 +234,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr)); @@ -251,7 +251,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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(2), 1); diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index 63bf472906..0879d72368 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -187,7 +187,7 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; 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(101), true); @@ -205,7 +205,7 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; 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), false); @@ -216,7 +216,7 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; 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); @@ -338,7 +338,7 @@ static void request_with_payload_template( op->flags = client_send_flags_bitmask; op->reserved = nullptr; 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); } @@ -367,7 +367,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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 = @@ -403,7 +403,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (int i = 0; i < 2; i++) { @@ -419,7 +419,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + 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), 1); } @@ -432,7 +432,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + 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), 1); @@ -451,7 +451,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -461,7 +461,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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(103), 1); @@ -495,7 +495,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -508,7 +508,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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(1), 1); diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index da65080bc0..56e5189a22 100644 --- a/test/core/end2end/tests/connectivity.cc +++ b/test/core/end2end/tests/connectivity.cc @@ -34,7 +34,7 @@ typedef struct { } child_events; static void child_thread(void* arg) { - child_events* ce = (child_events*)arg; + child_events* ce = static_cast(arg); grpc_event ev; gpr_event_set(&ce->started, (void*)1); gpr_log(GPR_DEBUG, "verifying"); diff --git a/test/core/end2end/tests/default_host.cc b/test/core/end2end/tests/default_host.cc index 33be5f1273..fefb5a58d1 100644 --- a/test/core/end2end/tests/default_host.cc +++ b/test/core/end2end/tests/default_host.cc @@ -140,7 +140,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = nullptr; 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(error == GRPC_CALL_OK); error = @@ -179,7 +179,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = nullptr; 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(error == GRPC_CALL_OK); CQ_EXPECT_COMPLETION(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/disappearing_server.cc b/test/core/end2end/tests/disappearing_server.cc index 1b2f729ba8..9712b9f86e 100644 --- a/test/core/end2end/tests/disappearing_server.cc +++ b/test/core/end2end/tests/disappearing_server.cc @@ -120,7 +120,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -154,7 +154,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/filter_call_init_fails.cc b/test/core/end2end/tests/filter_call_init_fails.cc index f60a47f8ff..c63a5b938d 100644 --- a/test/core/end2end/tests/filter_call_init_fails.cc +++ b/test/core/end2end/tests/filter_call_init_fails.cc @@ -158,7 +158,7 @@ static void test_server_channel_filter(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -253,7 +253,7 @@ static void test_client_channel_filter(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); @@ -344,7 +344,7 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) { op->reserved = nullptr; 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), 1); @@ -368,7 +368,7 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) { nullptr); GPR_ASSERT(c); - 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), 1); diff --git a/test/core/end2end/tests/filter_causes_close.cc b/test/core/end2end/tests/filter_causes_close.cc index 43f20d7cc0..07543f8e74 100644 --- a/test/core/end2end/tests/filter_causes_close.cc +++ b/test/core/end2end/tests/filter_causes_close.cc @@ -152,7 +152,7 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -197,8 +197,8 @@ typedef struct { } channel_data; static void recv_im_ready(void* arg, grpc_error* error) { - grpc_call_element* elem = (grpc_call_element*)arg; - call_data* calld = (call_data*)elem->call_data; + grpc_call_element* elem = static_cast(arg); + call_data* calld = static_cast(elem->call_data); GRPC_CLOSURE_RUN( calld->recv_im_ready, grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( @@ -209,7 +209,7 @@ static void recv_im_ready(void* arg, grpc_error* error) { static void start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - call_data* calld = (call_data*)elem->call_data; + call_data* calld = static_cast(elem->call_data); if (op->recv_initial_metadata) { calld->recv_im_ready = op->payload->recv_initial_metadata.recv_initial_metadata_ready; diff --git a/test/core/end2end/tests/filter_latency.cc b/test/core/end2end/tests/filter_latency.cc index d6cf3b034e..42507ad41a 100644 --- a/test/core/end2end/tests/filter_latency.cc +++ b/test/core/end2end/tests/filter_latency.cc @@ -165,7 +165,7 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -196,7 +196,7 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); @@ -305,7 +305,7 @@ static const grpc_channel_filter test_server_filter = { */ static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { - grpc_channel_filter* filter = (grpc_channel_filter*)arg; + grpc_channel_filter* filter = static_cast(arg); if (g_enable_filter) { // Want to add the filter as close to the end as possible, to make // sure that all of the filters work well together. However, we diff --git a/test/core/end2end/tests/filter_status_code.cc b/test/core/end2end/tests/filter_status_code.cc index ad80f23d6f..389c63b2ac 100644 --- a/test/core/end2end/tests/filter_status_code.cc +++ b/test/core/end2end/tests/filter_status_code.cc @@ -164,7 +164,7 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -199,7 +199,7 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); @@ -250,7 +250,7 @@ typedef struct final_status_data { static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - final_status_data* data = (final_status_data*)elem->call_data; + final_status_data* data = static_cast(elem->call_data); data->call = args->call_stack; return GRPC_ERROR_NONE; } @@ -258,7 +258,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, static void client_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - final_status_data* data = (final_status_data*)elem->call_data; + final_status_data* data = static_cast(elem->call_data); gpr_mu_lock(&g_mu); // Some fixtures, like proxies, will spawn intermidiate calls // We only want the results from our explicit calls @@ -273,7 +273,7 @@ static void client_destroy_call_elem(grpc_call_element* elem, static void server_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - final_status_data* data = (final_status_data*)elem->call_data; + final_status_data* data = static_cast(elem->call_data); gpr_mu_lock(&g_mu); // Some fixtures, like proxies, will spawn intermidiate calls // We only want the results from our explicit calls @@ -323,7 +323,7 @@ static const grpc_channel_filter test_server_filter = { */ static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { - grpc_channel_filter* filter = (grpc_channel_filter*)arg; + grpc_channel_filter* filter = static_cast(arg); if (g_enable_filter) { // Want to add the filter as close to the end as possible, to make // sure that all of the filters work well together. However, we diff --git a/test/core/end2end/tests/graceful_server_shutdown.cc b/test/core/end2end/tests/graceful_server_shutdown.cc index 3b6872bfd7..9a14476df4 100644 --- a/test/core/end2end/tests/graceful_server_shutdown.cc +++ b/test/core/end2end/tests/graceful_server_shutdown.cc @@ -135,7 +135,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; 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 = @@ -169,7 +169,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/high_initial_seqno.cc b/test/core/end2end/tests/high_initial_seqno.cc index 989cd5610f..cb67787e98 100644 --- a/test/core/end2end/tests/high_initial_seqno.cc +++ b/test/core/end2end/tests/high_initial_seqno.cc @@ -139,7 +139,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -169,7 +169,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/hpack_size.cc b/test/core/end2end/tests/hpack_size.cc index 66b3a4019f..8f7f3e6a6c 100644 --- a/test/core/end2end/tests/hpack_size.cc +++ b/test/core/end2end/tests/hpack_size.cc @@ -293,7 +293,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -323,7 +323,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/idempotent_request.cc b/test/core/end2end/tests/idempotent_request.cc index 578510d407..c0eac683c7 100644 --- a/test/core/end2end/tests/idempotent_request.cc +++ b/test/core/end2end/tests/idempotent_request.cc @@ -144,7 +144,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -183,7 +183,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/invoke_large_request.cc b/test/core/end2end/tests/invoke_large_request.cc index b7afa97401..5705094a15 100644 --- a/test/core/end2end/tests/invoke_large_request.cc +++ b/test/core/end2end/tests/invoke_large_request.cc @@ -176,7 +176,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -198,7 +198,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); @@ -224,7 +224,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/keepalive_timeout.cc b/test/core/end2end/tests/keepalive_timeout.cc index 0cdd12e9ca..76beedb1ba 100644 --- a/test/core/end2end/tests/keepalive_timeout.cc +++ b/test/core/end2end/tests/keepalive_timeout.cc @@ -155,7 +155,7 @@ static void test_keepalive_timeout(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(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -172,7 +172,7 @@ static void test_keepalive_timeout(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(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), 1); @@ -186,7 +186,7 @@ static void test_keepalive_timeout(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(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), 1); diff --git a/test/core/end2end/tests/large_metadata.cc b/test/core/end2end/tests/large_metadata.cc index c1343f902d..5e04161e08 100644 --- a/test/core/end2end/tests/large_metadata.cc +++ b/test/core/end2end/tests/large_metadata.cc @@ -96,7 +96,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { grpc_arg arg; arg.type = GRPC_ARG_INTEGER; arg.key = const_cast(GRPC_ARG_MAX_METADATA_SIZE); - arg.value.integer = (int)large_size + 1024; + arg.value.integer = static_cast(large_size) + 1024; grpc_channel_args args = {1, &arg}; grpc_end2end_test_fixture f = begin_test(config, "test_request_with_large_metadata", &args, &args); @@ -160,7 +160,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -184,7 +184,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); @@ -207,7 +207,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index cfe5814755..de6b60c216 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -185,7 +185,7 @@ static void request_response_with_payload( op->flags = 0; op->reserved = nullptr; 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 = @@ -207,7 +207,7 @@ static void request_response_with_payload( op->flags = 0; op->reserved = nullptr; 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), 1); @@ -235,7 +235,7 @@ static void request_response_with_payload( op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/max_concurrent_streams.cc b/test/core/end2end/tests/max_concurrent_streams.cc index 642c0f7ce6..ed658a3507 100644 --- a/test/core/end2end/tests/max_concurrent_streams.cc +++ b/test/core/end2end/tests/max_concurrent_streams.cc @@ -135,7 +135,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -165,7 +165,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); @@ -274,7 +274,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(301), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(301), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -292,7 +292,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(302), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(302), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -306,7 +306,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(401), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(401), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -324,7 +324,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(402), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(402), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); got_client_start = 0; @@ -345,7 +345,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 = ((int)(intptr_t)ev.tag) - 1; + live_call = (static_cast((intptr_t)ev.tag)) - 1; got_client_start = 1; } } @@ -371,7 +371,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s1, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s1, ops, static_cast(op - ops), tag(102), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), 1); @@ -408,7 +408,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s2, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s2, ops, static_cast(op - ops), tag(202), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(live_call + 2), 1); @@ -514,7 +514,7 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(301), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(301), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -532,7 +532,7 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(302), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(302), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(101), 1); @@ -550,7 +550,7 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(401), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(401), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -568,7 +568,7 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(402), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(402), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); grpc_call_details_destroy(&call_details); @@ -603,7 +603,7 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s2, ops, (size_t)(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s2, ops, static_cast(op - ops), tag(202), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(402), 1); @@ -709,7 +709,7 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(301), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(301), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -727,7 +727,7 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(302), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(302), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(101), 1); @@ -745,7 +745,7 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(401), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(401), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -763,7 +763,7 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(402), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(402), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); /* the second request is time out*/ @@ -796,7 +796,7 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s1, ops, (size_t)(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s1, ops, static_cast(op - ops), tag(102), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(302), 1); diff --git a/test/core/end2end/tests/max_connection_age.cc b/test/core/end2end/tests/max_connection_age.cc index df5fd5cc1e..4b498e6bf8 100644 --- a/test/core/end2end/tests/max_connection_age.cc +++ b/test/core/end2end/tests/max_connection_age.cc @@ -145,7 +145,7 @@ static void test_max_age_forcibly_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -156,7 +156,7 @@ static void test_max_age_forcibly_close(grpc_end2end_test_config config) { cq_verify(cqv); gpr_timespec expect_shutdown_time = grpc_timeout_milliseconds_to_deadline( - (int)(MAX_CONNECTION_AGE_MS * MAX_CONNECTION_AGE_JITTER_MULTIPLIER) + + static_cast(MAX_CONNECTION_AGE_MS * MAX_CONNECTION_AGE_JITTER_MULTIPLIER) + MAX_CONNECTION_AGE_GRACE_MS + IMMEDIATE_SHUTDOWN_GRACE_TIME_MS); /* Wait for the channel to reach its max age */ @@ -190,7 +190,7 @@ static void test_max_age_forcibly_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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); @@ -288,7 +288,7 @@ static void test_max_age_gracefully_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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 = @@ -325,7 +325,7 @@ static void test_max_age_gracefully_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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/max_connection_idle.cc b/test/core/end2end/tests/max_connection_idle.cc index 09b4a54df3..beff733593 100644 --- a/test/core/end2end/tests/max_connection_idle.cc +++ b/test/core/end2end/tests/max_connection_idle.cc @@ -100,7 +100,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -139,7 +139,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index b1757a9b0d..987c348c00 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -219,7 +219,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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); if (send_limit) { @@ -247,7 +247,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); @@ -408,7 +408,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -443,7 +443,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/network_status_change.cc b/test/core/end2end/tests/network_status_change.cc index 809f8ffb5c..fe941e8ac8 100644 --- a/test/core/end2end/tests/network_status_change.cc +++ b/test/core/end2end/tests/network_status_change.cc @@ -150,7 +150,7 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -170,7 +170,7 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); @@ -193,7 +193,7 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/no_logging.cc b/test/core/end2end/tests/no_logging.cc index b4908d4926..c4678f461f 100644 --- a/test/core/end2end/tests/no_logging.cc +++ b/test/core/end2end/tests/no_logging.cc @@ -170,7 +170,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -207,7 +207,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/payload.cc b/test/core/end2end/tests/payload.cc index 3535d802e9..0e19e29cb6 100644 --- a/test/core/end2end/tests/payload.cc +++ b/test/core/end2end/tests/payload.cc @@ -90,9 +90,9 @@ static grpc_slice generate_random_slice() { static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; char* output; const size_t output_size = 1024 * 1024; - output = (char*)gpr_malloc(output_size); + output = static_cast(gpr_malloc(output_size)); for (i = 0; i < output_size - 1; ++i) { - output[i] = chars[rand() % (int)(sizeof(chars) - 1)]; + output[i] = chars[rand() % static_cast(sizeof(chars) - 1)]; } output[output_size - 1] = '\0'; grpc_slice out = grpc_slice_from_copied_string(output); @@ -174,7 +174,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -196,7 +196,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); @@ -222,7 +222,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/ping_pong_streaming.cc b/test/core/end2end/tests/ping_pong_streaming.cc index 714a7681b2..9ac4d544f2 100644 --- a/test/core/end2end/tests/ping_pong_streaming.cc +++ b/test/core/end2end/tests/ping_pong_streaming.cc @@ -143,7 +143,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -165,7 +165,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (i = 0; i < messages; i++) { @@ -184,7 +184,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -195,7 +195,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + 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), 1); cq_verify(cqv); @@ -208,7 +208,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + 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), 1); CQ_EXPECT_COMPLETION(cqv, tag(2), 1); @@ -229,7 +229,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -242,7 +242,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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(1), 1); diff --git a/test/core/end2end/tests/proxy_auth.cc b/test/core/end2end/tests/proxy_auth.cc index c34505c878..fd1cbadaf5 100644 --- a/test/core/end2end/tests/proxy_auth.cc +++ b/test/core/end2end/tests/proxy_auth.cc @@ -148,7 +148,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -187,7 +187,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/registered_call.cc b/test/core/end2end/tests/registered_call.cc index d1c37dca20..49a9f88df8 100644 --- a/test/core/end2end/tests/registered_call.cc +++ b/test/core/end2end/tests/registered_call.cc @@ -135,7 +135,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -165,7 +165,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/request_with_flags.cc b/test/core/end2end/tests/request_with_flags.cc index 46023133ba..bfce0a0be1 100644 --- a/test/core/end2end/tests/request_with_flags.cc +++ b/test/core/end2end/tests/request_with_flags.cc @@ -151,7 +151,7 @@ static void test_invoke_request_with_flags( op->reserved = nullptr; op++; expectation = call_start_batch_expected_result; - 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(expectation == error); if (expectation == GRPC_CALL_OK) { diff --git a/test/core/end2end/tests/request_with_payload.cc b/test/core/end2end/tests/request_with_payload.cc index 28818c80e7..fc87f5823e 100644 --- a/test/core/end2end/tests/request_with_payload.cc +++ b/test/core/end2end/tests/request_with_payload.cc @@ -147,7 +147,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -168,7 +168,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); @@ -189,7 +189,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/resource_quota_server.cc b/test/core/end2end/tests/resource_quota_server.cc index 6d35d086aa..c9d8ab7f9f 100644 --- a/test/core/end2end/tests/resource_quota_server.cc +++ b/test/core/end2end/tests/resource_quota_server.cc @@ -91,9 +91,9 @@ static grpc_slice generate_random_slice() { static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; char* output; const size_t output_size = 1024 * 1024; - output = (char*)gpr_malloc(output_size); + output = static_cast(gpr_malloc(output_size)); for (i = 0; i < output_size - 1; ++i) { - output[i] = chars[rand() % (int)(sizeof(chars) - 1)]; + output[i] = chars[rand() % static_cast(sizeof(chars) - 1)]; } output[output_size - 1] = '\0'; grpc_slice out = grpc_slice_from_copied_string(output); @@ -132,25 +132,25 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_slice request_payload_slice = generate_random_slice(); grpc_call** client_calls = - (grpc_call**)malloc(sizeof(grpc_call*) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_call*) * NUM_CALLS)); grpc_call** server_calls = - (grpc_call**)malloc(sizeof(grpc_call*) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_call*) * NUM_CALLS)); grpc_metadata_array* initial_metadata_recv = - (grpc_metadata_array*)malloc(sizeof(grpc_metadata_array) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); grpc_metadata_array* trailing_metadata_recv = - (grpc_metadata_array*)malloc(sizeof(grpc_metadata_array) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); grpc_metadata_array* request_metadata_recv = - (grpc_metadata_array*)malloc(sizeof(grpc_metadata_array) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); grpc_call_details* call_details = - (grpc_call_details*)malloc(sizeof(grpc_call_details) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_call_details) * NUM_CALLS)); grpc_status_code* status = - (grpc_status_code*)malloc(sizeof(grpc_status_code) * NUM_CALLS); - grpc_slice* details = (grpc_slice*)malloc(sizeof(grpc_slice) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_status_code) * NUM_CALLS)); + grpc_slice* details = static_cast(malloc(sizeof(grpc_slice) * NUM_CALLS)); grpc_byte_buffer** request_payload = - (grpc_byte_buffer**)malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS)); grpc_byte_buffer** request_payload_recv = - (grpc_byte_buffer**)malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS); - int* was_cancelled = (int*)malloc(sizeof(int) * NUM_CALLS); + static_cast(malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS)); + int* was_cancelled = static_cast(malloc(sizeof(int) * NUM_CALLS)); grpc_call_error error; int pending_client_calls = 0; int pending_server_start_calls = 0; @@ -220,7 +220,7 @@ void resource_quota_server(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(client_calls[i], ops, (size_t)(op - ops), + error = grpc_call_start_batch(client_calls[i], ops, static_cast(op - ops), tag(CLIENT_BASE_TAG + i), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); @@ -234,7 +234,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 = (int)(intptr_t)ev.tag; + int ev_tag = static_cast((intptr_t)ev.tag); if (ev_tag < CLIENT_BASE_TAG) { abort(); /* illegal tag */ } else if (ev_tag < SERVER_START_BASE_TAG) { @@ -286,7 +286,7 @@ void resource_quota_server(grpc_end2end_test_config config) { op->reserved = nullptr; op++; error = - grpc_call_start_batch(server_calls[call_id], ops, (size_t)(op - ops), + grpc_call_start_batch(server_calls[call_id], ops, static_cast(op - ops), tag(SERVER_RECV_BASE_TAG + call_id), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); @@ -327,7 +327,7 @@ void resource_quota_server(grpc_end2end_test_config config) { op->reserved = nullptr; op++; error = - grpc_call_start_batch(server_calls[call_id], ops, (size_t)(op - ops), + grpc_call_start_batch(server_calls[call_id], ops, static_cast(op - ops), tag(SERVER_END_BASE_TAG + call_id), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); diff --git a/test/core/end2end/tests/server_finishes_request.cc b/test/core/end2end/tests/server_finishes_request.cc index f135851f86..4423ed3cf2 100644 --- a/test/core/end2end/tests/server_finishes_request.cc +++ b/test/core/end2end/tests/server_finishes_request.cc @@ -133,7 +133,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -163,7 +163,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/shutdown_finishes_calls.cc b/test/core/end2end/tests/shutdown_finishes_calls.cc index 2e19e059ae..bdba7a6532 100644 --- a/test/core/end2end/tests/shutdown_finishes_calls.cc +++ b/test/core/end2end/tests/shutdown_finishes_calls.cc @@ -128,7 +128,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; 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 = @@ -145,7 +145,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; 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); /* shutdown and destroy the server */ diff --git a/test/core/end2end/tests/shutdown_finishes_tags.cc b/test/core/end2end/tests/shutdown_finishes_tags.cc index d160647295..55caacb7ff 100644 --- a/test/core/end2end/tests/shutdown_finishes_tags.cc +++ b/test/core/end2end/tests/shutdown_finishes_tags.cc @@ -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*)(uintptr_t)1; + grpc_call* s = (grpc_call*)static_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 b4732aed3f..d7be88713f 100644 --- a/test/core/end2end/tests/simple_cacheable_request.cc +++ b/test/core/end2end/tests/simple_cacheable_request.cc @@ -178,7 +178,7 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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 = @@ -201,7 +201,7 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); @@ -227,7 +227,7 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/simple_delayed_request.cc b/test/core/end2end/tests/simple_delayed_request.cc index 54517fb242..12207f0771 100644 --- a/test/core/end2end/tests/simple_delayed_request.cc +++ b/test/core/end2end/tests/simple_delayed_request.cc @@ -129,7 +129,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -159,7 +159,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/simple_metadata.cc b/test/core/end2end/tests/simple_metadata.cc index 5911834c91..246c8b0d6f 100644 --- a/test/core/end2end/tests/simple_metadata.cc +++ b/test/core/end2end/tests/simple_metadata.cc @@ -176,7 +176,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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 = @@ -199,7 +199,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); @@ -225,7 +225,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/simple_request.cc b/test/core/end2end/tests/simple_request.cc index 6ec4a14959..8bc7fa6e2c 100644 --- a/test/core/end2end/tests/simple_request.cc +++ b/test/core/end2end/tests/simple_request.cc @@ -152,7 +152,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -191,7 +191,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index 637b7b2422..4dea64e9aa 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -187,7 +187,7 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; 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(101), true); @@ -205,7 +205,7 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; 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), false); @@ -216,7 +216,7 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; 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); @@ -345,7 +345,7 @@ static void request_with_payload_template( op->flags = client_send_flags_bitmask; op->reserved = nullptr; 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); } @@ -374,7 +374,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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 = @@ -414,7 +414,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (int i = 0; i < 2; i++) { @@ -430,7 +430,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + 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), 1); } @@ -443,7 +443,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + 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), 1); @@ -460,7 +460,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -470,7 +470,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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(103), 1); @@ -495,7 +495,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -508,7 +508,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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(1), 1); diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index 6abb3bbf5d..f11230f6b2 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -93,9 +93,9 @@ static grpc_slice generate_random_slice() { static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; char* output; const size_t output_size = 1024 * 1024; - output = (char*)gpr_malloc(output_size); + output = static_cast(gpr_malloc(output_size)); for (i = 0; i < output_size - 1; ++i) { - output[i] = chars[rand() % (int)(sizeof(chars) - 1)]; + output[i] = chars[rand() % static_cast(sizeof(chars) - 1)]; } output[output_size - 1] = '\0'; grpc_slice out = grpc_slice_from_copied_string(output); @@ -177,7 +177,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -199,7 +199,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); @@ -225,7 +225,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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), 1); 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 8242c2cdd1..6f57667d5c 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -151,7 +151,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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 = @@ -173,7 +173,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (i = 0; i < messages; i++) { @@ -192,7 +192,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -203,7 +203,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + 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), 1); cq_verify(cqv); @@ -216,7 +216,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + 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), 1); CQ_EXPECT_COMPLETION(cqv, tag(2), 1); @@ -237,7 +237,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -250,7 +250,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; 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(1), 1); diff --git a/test/core/end2end/tests/streaming_error_response.cc b/test/core/end2end/tests/streaming_error_response.cc index 167530a6ae..e67920551a 100644 --- a/test/core/end2end/tests/streaming_error_response.cc +++ b/test/core/end2end/tests/streaming_error_response.cc @@ -148,7 +148,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { 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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -165,7 +165,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = response_payload1; 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), 1); @@ -179,7 +179,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = response_payload2; 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), 1); @@ -190,7 +190,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &response_payload2_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); CQ_EXPECT_COMPLETION(cqv, tag(2), 1); @@ -208,7 +208,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { grpc_slice status_details = grpc_slice_from_static_string("xyz"); 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), 1); @@ -225,7 +225,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { 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(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), 1); diff --git a/test/core/end2end/tests/trailing_metadata.cc b/test/core/end2end/tests/trailing_metadata.cc index 150c1cbd51..134baaaf93 100644 --- a/test/core/end2end/tests/trailing_metadata.cc +++ b/test/core/end2end/tests/trailing_metadata.cc @@ -184,7 +184,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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 = @@ -207,7 +207,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); @@ -234,7 +234,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index edf03d8ffc..3de326bef2 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -191,7 +191,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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 = @@ -227,7 +227,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (int i = 0; i < 2; i++) { @@ -246,7 +246,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -257,7 +257,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + 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), 1); cq_verify(cqv); @@ -275,7 +275,7 @@ static void request_with_payload_template( op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); + 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), 1); CQ_EXPECT_COMPLETION(cqv, tag(2), 1); @@ -308,7 +308,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); @@ -321,7 +321,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; 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(1), 1); diff --git a/test/core/end2end/tests/write_buffering.cc b/test/core/end2end/tests/write_buffering.cc index 7f3d1abc39..35ab72cc53 100644 --- a/test/core/end2end/tests/write_buffering.cc +++ b/test/core/end2end/tests/write_buffering.cc @@ -128,7 +128,7 @@ static void test_invoke_request_with_payload(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(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); memset(ops, 0, sizeof(ops)); @@ -138,7 +138,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -154,7 +154,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.send_message.send_message = request_payload1; op->flags = GRPC_WRITE_BUFFER_HINT; 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); memset(ops, 0, sizeof(ops)); @@ -162,7 +162,7 @@ static void test_invoke_request_with_payload(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); /* recv message should not succeed yet - it's buffered at the client still */ @@ -171,7 +171,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv1; 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(2), true); @@ -186,7 +186,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.send_message.send_message = request_payload2; op->flags = 0; 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); /* now the first send should match up with the first recv */ @@ -200,7 +200,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv2; 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); @@ -219,7 +219,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); op = ops; @@ -236,7 +236,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/end2end/tests/write_buffering_at_end.cc b/test/core/end2end/tests/write_buffering_at_end.cc index a1fbfef3fc..fffb0293a1 100644 --- a/test/core/end2end/tests/write_buffering_at_end.cc +++ b/test/core/end2end/tests/write_buffering_at_end.cc @@ -125,7 +125,7 @@ static void test_invoke_request_with_payload(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(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); memset(ops, 0, sizeof(ops)); @@ -135,7 +135,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -151,7 +151,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.send_message.send_message = request_payload; op->flags = GRPC_WRITE_BUFFER_HINT; 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); memset(ops, 0, sizeof(ops)); @@ -159,7 +159,7 @@ static void test_invoke_request_with_payload(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); /* recv message should not succeed yet - it's buffered at the client still */ @@ -168,7 +168,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv1; 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(2), true); @@ -181,7 +181,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op = ops; 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); /* now the first send should match up with the first recv */ @@ -195,7 +195,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv2; 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); @@ -210,7 +210,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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); memset(ops, 0, sizeof(ops)); op = ops; @@ -227,7 +227,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; 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), 1); diff --git a/test/core/fling/client.cc b/test/core/fling/client.cc index 92f59b7fdb..0141e7e748 100644 --- a/test/core/fling/client.cc +++ b/test/core/fling/client.cc @@ -127,7 +127,7 @@ static void step_ping_pong_stream(void) { static double now(void) { gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME); - return 1e9 * (double)tv.tv_sec + tv.tv_nsec; + return 1e9 * static_cast(tv.tv_sec) + tv.tv_nsec; } typedef struct { @@ -195,7 +195,7 @@ int main(int argc, char** argv) { channel = grpc_insecure_channel_create(target, nullptr, nullptr); cq = grpc_completion_queue_create_for_next(nullptr); - the_buffer = grpc_raw_byte_buffer_create(&slice, (size_t)payload_size); + the_buffer = grpc_raw_byte_buffer_create(&slice, static_cast(payload_size)); histogram = grpc_histogram_create(0.01, 60e9); sc.init(); diff --git a/test/core/fling/fling_stream_test.cc b/test/core/fling/fling_stream_test.cc index d5fd7a8d46..32bc989641 100644 --- a/test/core/fling/fling_stream_test.cc +++ b/test/core/fling/fling_stream_test.cc @@ -37,7 +37,7 @@ int main(int argc, char** argv) { gpr_subprocess *svr, *cli; /* figure out where we are */ if (lslash) { - memcpy(root, me, (size_t)(lslash - me)); + memcpy(root, me, static_cast(lslash - me)); root[lslash - me] = 0; } else { strcpy(root, "."); diff --git a/test/core/fling/fling_test.cc b/test/core/fling/fling_test.cc index d95317b7e6..3587a4acaa 100644 --- a/test/core/fling/fling_test.cc +++ b/test/core/fling/fling_test.cc @@ -37,7 +37,7 @@ int main(int argc, const char** argv) { gpr_subprocess *svr, *cli; /* figure out where we are */ if (lslash) { - memcpy(root, me, (size_t)(lslash - me)); + memcpy(root, me, static_cast(lslash - me)); root[lslash - me] = 0; } else { strcpy(root, "."); diff --git a/test/core/fling/server.cc b/test/core/fling/server.cc index b19a25a185..cad4a8fd8c 100644 --- a/test/core/fling/server.cc +++ b/test/core/fling/server.cc @@ -112,7 +112,7 @@ static void handle_unary_method(void) { op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(call, unary_ops, (size_t)(op - unary_ops), + error = grpc_call_start_batch(call, unary_ops, static_cast(op - unary_ops), tag(FLING_SERVER_BATCH_OPS_FOR_UNARY), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); } @@ -189,7 +189,7 @@ int main(int argc, char** argv) { grpc_test_init(1, fake_argv); grpc_init(); - srand((unsigned)clock()); + srand(static_cast(clock())); cl = gpr_cmdline_create("fling server"); gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr); diff --git a/test/core/gpr/alloc_test.cc b/test/core/gpr/alloc_test.cc index bf4471c36f..1f6d5962ba 100644 --- a/test/core/gpr/alloc_test.cc +++ b/test/core/gpr/alloc_test.cc @@ -27,7 +27,7 @@ static void* fake_malloc(size_t size) { return (void*)size; } static void* fake_realloc(void* addr, size_t size) { return (void*)size; } -static void fake_free(void* addr) { *((intptr_t*)addr) = (intptr_t)0xdeadd00d; } +static void fake_free(void* addr) { *(static_cast(addr)) = static_cast(0xdeadd00d); } static void test_custom_allocs() { const gpr_allocation_functions default_fns = gpr_get_allocation_functions(); diff --git a/test/core/gpr/arena_test.cc b/test/core/gpr/arena_test.cc index 087a800462..c10d7eaff7 100644 --- a/test/core/gpr/arena_test.cc +++ b/test/core/gpr/arena_test.cc @@ -86,7 +86,7 @@ static void concurrent_test_body(void* arg) { concurrent_test_args* a = static_cast(arg); gpr_event_wait(&a->ev_start, gpr_inf_future(GPR_CLOCK_REALTIME)); for (size_t i = 0; i < concurrent_test_iterations(); i++) { - *(char*)gpr_arena_alloc(a->arena, 1) = (char)i; + *static_cast(gpr_arena_alloc(a->arena, 1)) = static_cast(i); } } diff --git a/test/core/gpr/cpu_test.cc b/test/core/gpr/cpu_test.cc index 87cdc0fb50..46a168665c 100644 --- a/test/core/gpr/cpu_test.cc +++ b/test/core/gpr/cpu_test.cc @@ -62,7 +62,7 @@ struct cpu_test { }; static void worker_thread(void* arg) { - struct cpu_test* ct = (struct cpu_test*)arg; + struct cpu_test* ct = static_cast(arg); uint32_t cpu; unsigned r = 12345678; unsigned i, j; @@ -103,7 +103,7 @@ static void cpu_test(void) { gpr_thd_id thd; ct.ncores = gpr_cpu_num_cores(); GPR_ASSERT(ct.ncores > 0); - ct.nthreads = (int)ct.ncores * 3; + ct.nthreads = static_cast(ct.ncores) * 3; ct.used = static_cast(gpr_malloc(ct.ncores * sizeof(int))); memset(ct.used, 0, ct.ncores * sizeof(int)); gpr_mu_init(&ct.mu); diff --git a/test/core/gpr/mpscq_test.cc b/test/core/gpr/mpscq_test.cc index 58df2f14fc..333390e928 100644 --- a/test/core/gpr/mpscq_test.cc +++ b/test/core/gpr/mpscq_test.cc @@ -49,7 +49,7 @@ static void test_serial(void) { gpr_mpscq_push(&q, &new_node(i, nullptr)->node); } for (size_t i = 0; i < 10000000; i++) { - test_node* n = (test_node*)gpr_mpscq_pop(&q); + test_node* n = reinterpret_cast(gpr_mpscq_pop(&q)); GPR_ASSERT(n); GPR_ASSERT(n->i == i); gpr_free(n); @@ -97,7 +97,7 @@ static void test_mt(void) { while ((n = gpr_mpscq_pop(&q)) == nullptr) { spins++; } - test_node* tn = (test_node*)n; + test_node* tn = reinterpret_cast(n); GPR_ASSERT(*tn->ctr == tn->i - 1); *tn->ctr = tn->i; if (tn->i == THREAD_ITERATIONS) num_done++; @@ -134,7 +134,7 @@ static void pull_thread(void* arg) { while ((n = gpr_mpscq_pop(pa->q)) == nullptr) { pa->spins++; } - test_node* tn = (test_node*)n; + test_node* tn = reinterpret_cast(n); GPR_ASSERT(*tn->ctr == tn->i - 1); *tn->ctr = tn->i; if (tn->i == THREAD_ITERATIONS) pa->num_done++; diff --git a/test/core/gpr/murmur_hash_test.cc b/test/core/gpr/murmur_hash_test.cc index d920dd3f95..2d2fa72cfb 100644 --- a/test/core/gpr/murmur_hash_test.cc +++ b/test/core/gpr/murmur_hash_test.cc @@ -42,8 +42,8 @@ static void verification_test(hash_func hash, uint32_t expected) { the seed */ for (i = 0; i < 256; i++) { - key[i] = (uint8_t)i; - hashes[i] = hash(key, i, (uint32_t)(256u - i)); + key[i] = static_cast(i); + hashes[i] = hash(key, i, static_cast(256u - i)); } /* Then hash the result array */ diff --git a/test/core/gpr/spinlock_test.cc b/test/core/gpr/spinlock_test.cc index 77e3dfbede..d443684c92 100644 --- a/test/core/gpr/spinlock_test.cc +++ b/test/core/gpr/spinlock_test.cc @@ -46,7 +46,7 @@ static struct test* test_new(int threads, int64_t iterations, int incr_step) { struct test* m = static_cast(gpr_malloc(sizeof(*m))); m->thread_count = threads; m->threads = static_cast( - gpr_malloc(sizeof(*m->threads) * (size_t)threads)); + gpr_malloc(sizeof(*m->threads) * static_cast(threads))); m->iterations = iterations; m->counter = 0; m->thread_count = 0; @@ -93,27 +93,27 @@ static void test(const char* name, void (*body)(void* m), int timeout_s, gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; gpr_timespec deadline = gpr_time_add( - start, gpr_time_from_micros((int64_t)timeout_s * 1000000, GPR_TIMESPAN)); + start, gpr_time_from_micros(static_cast(timeout_s) * 1000000, GPR_TIMESPAN)); fprintf(stderr, "%s:", name); fflush(stderr); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { if (iterations < INT64_MAX / 2) iterations <<= 1; - fprintf(stderr, " %ld", (long)iterations); + fprintf(stderr, " %ld", static_cast(iterations)); fflush(stderr); m = test_new(10, iterations, incr_step); test_create_threads(m, body); test_wait(m); if (m->counter != m->thread_count * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", - (long)m->counter, m->thread_count, (long)m->iterations); + static_cast(m->counter), m->thread_count, static_cast(m->iterations)); fflush(stderr); GPR_ASSERT(0); } test_destroy(m); } time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start); - fprintf(stderr, " done %lld.%09d s\n", (long long)time_taken.tv_sec, - (int)time_taken.tv_nsec); + fprintf(stderr, " done %lld.%09d s\n", static_cast(time_taken.tv_sec), + static_cast(time_taken.tv_nsec)); fflush(stderr); } diff --git a/test/core/gpr/sync_test.cc b/test/core/gpr/sync_test.cc index 768f96d093..abad930ce6 100644 --- a/test/core/gpr/sync_test.cc +++ b/test/core/gpr/sync_test.cc @@ -236,11 +236,11 @@ static void test(const char* name, void (*body)(void* m), gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; gpr_timespec deadline = gpr_time_add( - start, gpr_time_from_micros((int64_t)timeout_s * 1000000, GPR_TIMESPAN)); + start, gpr_time_from_micros(static_cast(timeout_s) * 1000000, GPR_TIMESPAN)); fprintf(stderr, "%s:", name); fflush(stderr); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { - fprintf(stderr, " %ld", (long)iterations); + fprintf(stderr, " %ld", static_cast(iterations)); fflush(stderr); m = test_new(10, iterations, incr_step); if (extra != nullptr) { @@ -252,7 +252,7 @@ static void test(const char* name, void (*body)(void* m), test_wait(m); if (m->counter != m->threads * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", - (long)m->counter, m->threads, (long)m->iterations); + static_cast(m->counter), m->threads, static_cast(m->iterations)); fflush(stderr); GPR_ASSERT(0); } @@ -260,8 +260,8 @@ static void test(const char* name, void (*body)(void* m), iterations <<= 1; } time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start); - fprintf(stderr, " done %lld.%09d s\n", (long long)time_taken.tv_sec, - (int)time_taken.tv_nsec); + fprintf(stderr, " done %lld.%09d s\n", static_cast(time_taken.tv_sec), + static_cast(time_taken.tv_nsec)); fflush(stderr); } diff --git a/test/core/gpr/time_test.cc b/test/core/gpr/time_test.cc index b2b4dce58e..ef7a961d0a 100644 --- a/test/core/gpr/time_test.cc +++ b/test/core/gpr/time_test.cc @@ -29,7 +29,7 @@ #include "test/core/util/test_config.h" static void to_fp(void* arg, const char* buf, size_t len) { - fwrite(buf, 1, len, (FILE*)arg); + fwrite(buf, 1, len, static_cast(arg)); } /* Convert gpr_intmax x to ascii base b (2..16), and write with diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index 2302e3da2f..d04295a735 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -68,7 +68,7 @@ static int create_socket(int* out_port) { return -1; } - if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) < 0) { + if (bind(s, reinterpret_cast(&addr), sizeof(addr)) < 0) { perror("Unable to bind"); gpr_log(GPR_ERROR, "%s", "Unable to bind to any port"); close(s); @@ -82,7 +82,7 @@ static int create_socket(int* out_port) { } addr_len = sizeof(addr); - if (getsockname(s, (struct sockaddr*)&addr, &addr_len) != 0 || + if (getsockname(s, reinterpret_cast(&addr), &addr_len) != 0 || addr_len > sizeof(addr)) { perror("getsockname"); gpr_log(GPR_ERROR, "%s", "Unable to get socket local address"); @@ -98,19 +98,19 @@ static int create_socket(int* out_port) { // SSL_CTX_set_alpn_select_cb. static int alpn_select_cb(SSL* ssl, const uint8_t** out, uint8_t* out_len, const uint8_t* in, unsigned in_len, void* arg) { - const uint8_t* alpn_preferred = (const uint8_t*)arg; + const uint8_t* alpn_preferred = static_cast(arg); *out = alpn_preferred; - *out_len = (uint8_t)strlen((char*)alpn_preferred); + *out_len = static_cast(strlen((char*)alpn_preferred)); // Validate that the ALPN list includes "h2" and "grpc-exp", that "grpc-exp" // precedes "h2". bool grpc_exp_seen = false; bool h2_seen = false; - const char* inp = (const char*)in; + const char* inp = reinterpret_cast(in); const char* in_end = inp + in_len; while (inp < in_end) { - const size_t length = (size_t)*inp++; + const size_t length = static_cast(*inp++); if (length == strlen("grpc-exp") && strncmp(inp, "grpc-exp", length) == 0) { grpc_exp_seen = true; GPR_ASSERT(!h2_seen); @@ -133,7 +133,7 @@ static int alpn_select_cb(SSL* ssl, const uint8_t** out, uint8_t* out_len, // https://wiki.openssl.org/index.php/Simple_TLS_Server and the gRPC core // internals in src/core/tsi/ssl_transport_security.c. static void server_thread(void* arg) { - const server_args* args = (server_args*)arg; + const server_args* args = static_cast(arg); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); @@ -175,7 +175,7 @@ static void server_thread(void* arg) { gpr_log(GPR_INFO, "Server listening"); struct sockaddr_in addr; socklen_t len = sizeof(addr); - const int client = accept(sock, (struct sockaddr*)&addr, &len); + const int client = accept(sock, reinterpret_cast(&addr), &len); if (client < 0) { perror("Unable to accept"); abort(); @@ -243,9 +243,9 @@ static bool client_ssl_test(char* server_alpn_preferred) { grpc_load_file(SSL_CERT_PATH, 1, &cert_slice))); GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(SSL_KEY_PATH, 1, &key_slice))); - const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); - pem_key_cert_pair.private_key = (const char*)GRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = (const char*)GRPC_SLICE_START_PTR(cert_slice); + const char* ca_cert = reinterpret_castGRPC_SLICE_START_PTR(ca_slice); + pem_key_cert_pair.private_key = reinterpret_castGRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = reinterpret_castGRPC_SLICE_START_PTR(cert_slice); grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(ca_cert, &pem_key_cert_pair, nullptr); diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index 599e0e16e2..a4f182e643 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -67,7 +67,7 @@ const grpc_handshaker_vtable readahead_handshaker_vtable = { readahead_handshaker_do_handshake}; static grpc_handshaker* readahead_handshaker_create() { - grpc_handshaker* h = (grpc_handshaker*)gpr_zalloc(sizeof(grpc_handshaker)); + grpc_handshaker* h = static_cast(gpr_zalloc(sizeof(grpc_handshaker))); grpc_handshaker_init(&readahead_handshaker_vtable, h); return h; } diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index 0bf453a204..6ae2471807 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -48,7 +48,7 @@ static int create_socket(int port) { struct sockaddr_in addr; addr.sin_family = AF_INET; - addr.sin_port = htons((uint16_t)port); + addr.sin_port = htons(static_cast(port)); addr.sin_addr.s_addr = htonl(INADDR_ANY); s = socket(AF_INET, SOCK_STREAM, 0); @@ -57,7 +57,7 @@ static int create_socket(int port) { return -1; } - if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) < 0) { + if (connect(s, reinterpret_cast(&addr), sizeof(addr)) < 0) { perror("Unable to connect"); return -1; } @@ -67,7 +67,7 @@ static int create_socket(int port) { // Simple gRPC server. This listens until client_handshake_complete occurs. static void server_thread(void* arg) { - const int port = *(int*)arg; + const int port = *static_cast(arg); // Load key pair and establish server SSL credentials. grpc_ssl_pem_key_cert_pair pem_key_cert_pair; @@ -78,9 +78,9 @@ static void server_thread(void* arg) { grpc_load_file(SSL_CERT_PATH, 1, &cert_slice))); GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(SSL_KEY_PATH, 1, &key_slice))); - const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); - pem_key_cert_pair.private_key = (const char*)GRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = (const char*)GRPC_SLICE_START_PTR(cert_slice); + const char* ca_cert = reinterpret_castGRPC_SLICE_START_PTR(ca_slice); + pem_key_cert_pair.private_key = reinterpret_castGRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = reinterpret_castGRPC_SLICE_START_PTR(cert_slice); grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create( ca_cert, &pem_key_cert_pair, 1, 0, nullptr); @@ -176,13 +176,13 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, // wire format, see documentation for SSL_CTX_set_alpn_protos. unsigned int alpn_protos_len = alpn_list_len; for (unsigned int i = 0; i < alpn_list_len; ++i) { - alpn_protos_len += (unsigned int)strlen(alpn_list[i]); + alpn_protos_len += static_cast(strlen(alpn_list[i])); } unsigned char* alpn_protos = static_cast(gpr_malloc(alpn_protos_len)); unsigned char* p = alpn_protos; for (unsigned int i = 0; i < alpn_list_len; ++i) { - const uint8_t len = (uint8_t)strlen(alpn_list[i]); + const uint8_t len = static_cast(strlen(alpn_list[i])); *p++ = len; memcpy(p, alpn_list[i], len); p += len; @@ -217,7 +217,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, unsigned int alpn_selected_len; SSL_get0_alpn_selected(ssl, &alpn_selected, &alpn_selected_len); if (strlen(alpn_expected) != alpn_selected_len || - strncmp((const char*)alpn_selected, alpn_expected, alpn_selected_len) != + strncmp(reinterpret_cast(alpn_selected), alpn_expected, alpn_selected_len) != 0) { gpr_log(GPR_ERROR, "Unexpected ALPN protocol preference"); success = false; diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 3d892b939c..346568fcf2 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -157,14 +157,14 @@ int main(int argc, char** argv) { char* root; if (lslash != nullptr) { /* Hack for bazel target */ - if ((unsigned)(lslash - me) >= (sizeof("http") - 1) && + if (static_cast(lslash - me) >= (sizeof("http") - 1) && strncmp(me + (lslash - me) - sizeof("http") + 1, "http", sizeof("http") - 1) == 0) { lslash = me + (lslash - me) - sizeof("http"); } root = static_cast( - gpr_malloc((size_t)(lslash - me + sizeof("/../..")))); - memcpy(root, me, (size_t)(lslash - me)); + gpr_malloc(static_cast(lslash - me + sizeof("/../..")))); + memcpy(root, me, static_cast(lslash - me)); memcpy(root + (lslash - me), "/../..", sizeof("/../..")); } else { root = gpr_strdup("."); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index 7e99ad4249..a38f306ef3 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -157,14 +157,14 @@ int main(int argc, char** argv) { char* root; if (lslash != nullptr) { /* Hack for bazel target */ - if ((unsigned)(lslash - me) >= (sizeof("http") - 1) && + if (static_cast(lslash - me) >= (sizeof("http") - 1) && strncmp(me + (lslash - me) - sizeof("http") + 1, "http", sizeof("http") - 1) == 0) { lslash = me + (lslash - me) - sizeof("http"); } root = static_cast( - gpr_malloc((size_t)(lslash - me + sizeof("/../..")))); - memcpy(root, me, (size_t)(lslash - me)); + gpr_malloc(static_cast(lslash - me + sizeof("/../..")))); + memcpy(root, me, static_cast(lslash - me)); memcpy(root + (lslash - me), "/../..", sizeof("/../..")); } else { root = gpr_strdup("."); diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index 4251f27c81..ad38076b51 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -38,7 +38,7 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair( grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER; - a[0].value.integer = (int)slice_size; + a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; grpc_endpoint_pair p = grpc_iomgr_create_endpoint_pair("test", &args); diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 842be8fc92..9719a90e82 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -77,7 +77,7 @@ static void end_test(grpc_endpoint_test_config config) { config.clean_up(); } static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, size_t* num_blocks, uint8_t* current_data) { size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); - grpc_slice* slices = (grpc_slice*)gpr_malloc(sizeof(grpc_slice) * nslices); + grpc_slice* slices = static_cast(gpr_malloc(sizeof(grpc_slice) * nslices)); size_t num_bytes_left = num_bytes; size_t i; size_t j; @@ -117,7 +117,7 @@ struct read_and_write_test_state { static void read_and_write_test_read_handler(void* data, grpc_error* error) { struct read_and_write_test_state* state = - (struct read_and_write_test_state*)data; + static_cast(data); state->bytes_read += count_slices( state->incoming.slices, state->incoming.count, &state->current_read_data); @@ -134,7 +134,7 @@ static void read_and_write_test_read_handler(void* data, grpc_error* error) { static void read_and_write_test_write_handler(void* data, grpc_error* error) { struct read_and_write_test_state* state = - (struct read_and_write_test_state*)data; + static_cast(data); grpc_slice* slices = nullptr; size_t nslices; @@ -246,7 +246,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, static void inc_on_failure(void* arg, grpc_error* error) { gpr_mu_lock(g_mu); - *(int*)arg += (error != GRPC_ERROR_NONE); + *static_cast(arg) += (error != GRPC_ERROR_NONE); GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index 07a69a27c7..5ae68d2e47 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -98,7 +98,7 @@ static void test_pollset_init(test_pollset* pollsets, int num_pollsets) { } static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy((grpc_pollset*)p); + grpc_pollset_destroy(static_cast(p)); } static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index cf75517538..092c880bfa 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -78,7 +78,7 @@ static void create_test_socket(int port, int* socket_fd, sin->sin_family = AF_INET; sin->sin_addr.s_addr = htonl(0x7f000001); GPR_ASSERT(port >= 0 && port < 65536); - sin->sin_port = htons((uint16_t)port); + sin->sin_port = htons(static_cast(port)); } /* Dummy gRPC callback */ @@ -196,7 +196,7 @@ static void listen_cb(void* arg, /*=sv_arg*/ return; } - fd = accept(grpc_fd_wrapped_fd(listen_em_fd), (struct sockaddr*)&ss, &slen); + fd = accept(grpc_fd_wrapped_fd(listen_em_fd), reinterpret_cast(&ss), &slen); GPR_ASSERT(fd >= 0); GPR_ASSERT(fd < FD_SETSIZE); flags = fcntl(fd, F_GETFL, 0); @@ -335,7 +335,7 @@ static void client_start(client* cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); - if (connect(fd, (struct sockaddr*)&sin, sizeof(sin)) == -1) { + if (connect(fd, reinterpret_cast(&sin), sizeof(sin)) == -1) { if (errno == EINPROGRESS) { struct pollfd pfd; pfd.fd = fd; diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index 114f39726d..0dc75a5f3f 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -103,7 +103,7 @@ typedef struct test_fd { } test_fd; void on_readable(void* tfd, grpc_error* error) { - ((test_fd*)tfd)->is_on_readable_called = true; + (static_cast(tfd))->is_on_readable_called = true; } static void reset_test_fd(test_fd* tfd) { diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index 07682d2630..921a24ebf2 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -29,7 +29,7 @@ gpr_cv g_cv; static void inc_int_cb(void* a, grpc_error* error) { gpr_mu_lock(&g_mu); - ++*(int*)a; + ++*static_cast(a); gpr_cv_signal(&g_cv); gpr_mu_unlock(&g_mu); } @@ -44,7 +44,7 @@ static void assert_counter_becomes(int* ctr, int value) { } static void set_event_cb(void* a, grpc_error* error) { - gpr_event_set((gpr_event*)a, (void*)1); + gpr_event_set(static_cast(a), (void*)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/sockaddr_utils_test.cc b/test/core/iomgr/sockaddr_utils_test.cc index a445714851..51ac66685a 100644 --- a/test/core/iomgr/sockaddr_utils_test.cc +++ b/test/core/iomgr/sockaddr_utils_test.cc @@ -33,7 +33,7 @@ static grpc_resolved_address make_addr4(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr4; - struct sockaddr_in* addr4 = (struct sockaddr_in*)resolved_addr4.addr; + struct sockaddr_in* addr4 = reinterpret_cast(resolved_addr4.addr); memset(&resolved_addr4, 0, sizeof(resolved_addr4)); addr4->sin_family = AF_INET; GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr)); @@ -45,7 +45,7 @@ static grpc_resolved_address make_addr4(const uint8_t* data, size_t data_len) { static grpc_resolved_address make_addr6(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr6; - struct sockaddr_in6* addr6 = (struct sockaddr_in6*)resolved_addr6.addr; + struct sockaddr_in6* addr6 = reinterpret_cast(resolved_addr6.addr); memset(&resolved_addr6, 0, sizeof(resolved_addr6)); addr6->sin6_family = AF_INET6; GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr)); @@ -56,7 +56,7 @@ static grpc_resolved_address make_addr6(const uint8_t* data, size_t data_len) { } static void set_addr6_scope_id(grpc_resolved_address* addr, uint32_t scope_id) { - struct sockaddr_in6* addr6 = (struct sockaddr_in6*)addr->addr; + struct sockaddr_in6* addr6 = reinterpret_cast(addr->addr); GPR_ASSERT(addr6->sin6_family == AF_INET6); addr6->sin6_scope_id = scope_id; } @@ -143,7 +143,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild4, &port)); GPR_ASSERT(port == 555); - wild4_addr = (struct sockaddr_in*)&wild4.addr; + wild4_addr = reinterpret_cast(&wild4.addr); memset(&wild4_addr->sin_addr.s_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild4, &port)); @@ -151,7 +151,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild6, &port)); GPR_ASSERT(port == 555); - wild6_addr = (struct sockaddr_in6*)&wild6.addr; + wild6_addr = reinterpret_cast(&wild6.addr); memset(&wild6_addr->sin6_addr.s6_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild6, &port)); @@ -159,7 +159,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild_mapped, &port)); GPR_ASSERT(port == 555); - wild_mapped_addr = (struct sockaddr_in6*)&wild_mapped.addr; + wild_mapped_addr = reinterpret_cast(&wild_mapped.addr); memset(&wild_mapped_addr->sin6_addr.s6_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild_mapped, &port)); @@ -234,7 +234,7 @@ static void test_sockaddr_to_string(void) { expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6); memset(&dummy, 0, sizeof(dummy)); - dummy_addr = (struct sockaddr*)dummy.addr; + dummy_addr = reinterpret_cast(dummy.addr); dummy_addr->sa_family = 123; expect_sockaddr_str("(sockaddr family=123)", &dummy, 0); expect_sockaddr_str("(sockaddr family=123)", &dummy, 1); @@ -260,7 +260,7 @@ static void test_sockaddr_set_get_port(void) { GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 54321); memset(&dummy, 0, sizeof(dummy)); - dummy_addr = (struct sockaddr*)dummy.addr; + dummy_addr = reinterpret_cast(dummy.addr); dummy_addr->sa_family = 123; GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0); GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0); diff --git a/test/core/iomgr/socket_utils_test.cc b/test/core/iomgr/socket_utils_test.cc index 67391a547d..852370485a 100644 --- a/test/core/iomgr/socket_utils_test.cc +++ b/test/core/iomgr/socket_utils_test.cc @@ -43,7 +43,7 @@ struct test_socket_mutator { static bool mutate_fd(int fd, grpc_socket_mutator* mutator) { int newval; socklen_t intlen = sizeof(newval); - struct test_socket_mutator* m = (struct test_socket_mutator*)mutator; + struct test_socket_mutator* m = reinterpret_cast(mutator); if (0 != setsockopt(fd, IPPROTO_IP, IP_TOS, &m->option_value, sizeof(m->option_value))) { @@ -59,14 +59,14 @@ static bool mutate_fd(int fd, grpc_socket_mutator* mutator) { } static void destroy_test_mutator(grpc_socket_mutator* mutator) { - struct test_socket_mutator* m = (struct test_socket_mutator*)mutator; + struct test_socket_mutator* m = reinterpret_cast(mutator); gpr_free(m); } static int compare_test_mutator(grpc_socket_mutator* a, grpc_socket_mutator* b) { - struct test_socket_mutator* ma = (struct test_socket_mutator*)a; - struct test_socket_mutator* mb = (struct test_socket_mutator*)b; + struct test_socket_mutator* ma = reinterpret_cast(a); + struct test_socket_mutator* mb = reinterpret_cast(b); return GPR_ICMP(ma->option_value, mb->option_value); } @@ -117,7 +117,7 @@ int main(int argc, char** argv) { grpc_set_socket_with_mutator(sock, (grpc_socket_mutator*)&mutator))); mutator.option_value = -1; - err = grpc_set_socket_with_mutator(sock, (grpc_socket_mutator*)&mutator); + err = grpc_set_socket_with_mutator(sock, reinterpret_cast(&mutator)); GPR_ASSERT(err != GRPC_ERROR_NONE); GRPC_ERROR_UNREF(err); diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index 40a050ed9f..7ce30ca7f4 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -78,7 +78,7 @@ static void must_fail(void* arg, grpc_error* error) { void test_succeeds(void) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); int svr_fd; int r; int connections_complete_before; @@ -112,7 +112,7 @@ void test_succeeds(void) { /* await the connection */ do { resolved_addr.len = sizeof(addr); - r = accept(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr.len); + r = accept(svr_fd, reinterpret_cast(addr), reinterpret_cast(&resolved_addr.len)); } while (r == -1 && errno == EINTR); GPR_ASSERT(r >= 0); close(r); @@ -136,7 +136,7 @@ void test_succeeds(void) { void test_fails(void) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); int connections_complete_before; grpc_closure done; grpc_core::ExecCtx exec_ctx; diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index 3a79b9b430..b059ac44a1 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -74,7 +74,7 @@ static ssize_t fill_socket(int fd) { int i; unsigned char buf[256]; for (i = 0; i < 256; ++i) { - buf[i] = (uint8_t)i; + buf[i] = static_cast(i); } do { write_bytes = write(fd, buf, 256); @@ -89,16 +89,16 @@ static ssize_t fill_socket(int fd) { static size_t fill_socket_partial(int fd, size_t bytes) { ssize_t write_bytes; size_t total_bytes = 0; - unsigned char* buf = (unsigned char*)gpr_malloc(bytes); + unsigned char* buf = static_cast(gpr_malloc(bytes)); unsigned i; for (i = 0; i < bytes; ++i) { - buf[i] = (uint8_t)(i % 256); + buf[i] = static_cast(i % 256); } do { write_bytes = write(fd, buf, bytes - total_bytes); if (write_bytes > 0) { - total_bytes += (size_t)write_bytes; + total_bytes += static_cast(write_bytes); } } while ((write_bytes >= 0 || errno == EINTR) && bytes > total_bytes); @@ -132,7 +132,7 @@ static size_t count_slices(grpc_slice* slices, size_t nslices, } static void read_cb(void* user_data, grpc_error* error) { - struct read_socket_state* state = (struct read_socket_state*)user_data; + struct read_socket_state* state = static_cast(user_data); size_t read_bytes; int current_data; @@ -172,7 +172,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); - a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; + a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); grpc_endpoint_add_to_pollset(ep, g_pollset); @@ -222,7 +222,7 @@ static void large_read_test(size_t slice_size) { grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER; - a[0].value.integer = (int)slice_size; + a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), &args, "test"); grpc_endpoint_add_to_pollset(ep, g_pollset); @@ -232,7 +232,7 @@ static void large_read_test(size_t slice_size) { state.ep = ep; state.read_bytes = 0; - state.target_read_bytes = (size_t)written_bytes; + state.target_read_bytes = static_cast(written_bytes); grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); @@ -262,7 +262,7 @@ struct write_socket_state { static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, size_t* num_blocks, uint8_t* current_data) { size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u); - grpc_slice* slices = (grpc_slice*)gpr_malloc(sizeof(grpc_slice) * nslices); + grpc_slice* slices = static_cast(gpr_malloc(sizeof(grpc_slice) * nslices)); size_t num_bytes_left = num_bytes; unsigned i, j; unsigned char* buf; @@ -284,7 +284,7 @@ static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, static void write_done(void* user_data /* write_socket_state */, grpc_error* error) { - struct write_socket_state* state = (struct write_socket_state*)user_data; + struct write_socket_state* state = static_cast(user_data); gpr_log(GPR_INFO, "Write done callback called"); gpr_mu_lock(g_mu); gpr_log(GPR_INFO, "Signalling write done"); @@ -295,7 +295,7 @@ static void write_done(void* user_data /* write_socket_state */, } void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { - unsigned char* buf = (unsigned char*)gpr_malloc(read_size); + unsigned char* buf = static_cast(gpr_malloc(read_size)); ssize_t bytes_read; size_t bytes_left = num_bytes; int flags; @@ -325,7 +325,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { GPR_ASSERT(buf[i] == current); current = (current + 1) % 256; } - bytes_left -= (size_t)bytes_read; + bytes_left -= static_cast(bytes_read); if (bytes_left == 0) break; } flags = fcntl(fd, F_GETFL, 0); @@ -358,7 +358,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); - a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; + a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), &args, "test"); grpc_endpoint_add_to_pollset(ep, g_pollset); @@ -395,7 +395,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { } void on_fd_released(void* arg, grpc_error* errors) { - int* done = (int*)arg; + int* done = static_cast(arg); *done = 1; GPR_ASSERT( GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); @@ -426,7 +426,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER; - a[0].value.integer = (int)slice_size; + a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); GPR_ASSERT(grpc_tcp_fd(ep) == sv[1] && sv[1] >= 0); @@ -515,7 +515,7 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER; - a[0].value.integer = (int)slice_size; + a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; f.client_ep = grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), &args, "test"); @@ -533,7 +533,7 @@ static grpc_endpoint_test_config configs[] = { }; static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy((grpc_pollset*)p); + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { @@ -542,7 +542,7 @@ int main(int argc, char** argv) { grpc_init(); { grpc_core::ExecCtx exec_ctx; - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); grpc_endpoint_tests(configs[0], g_pollset, g_mu); run_tests(); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 3c9ca2109e..c1b4f36290 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -181,7 +181,7 @@ static void test_no_op_with_start(void) { static void test_no_op_with_port(void) { grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port"); @@ -200,7 +200,7 @@ static void test_no_op_with_port(void) { static void test_no_op_with_port_and_start(void) { grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port_and_start"); @@ -225,7 +225,7 @@ static grpc_error* tcp_connect(const test_addr* remote, int clifd; int nconnects_before; const struct sockaddr* remote_addr = - (const struct sockaddr*)remote->addr.addr; + reinterpret_cast(remote->addr.addr); gpr_log(GPR_INFO, "Connecting to %s", remote->str); gpr_mu_lock(g_mu); @@ -237,7 +237,7 @@ static grpc_error* tcp_connect(const test_addr* remote, return GRPC_OS_ERROR(errno, "Failed to create socket"); } gpr_log(GPR_DEBUG, "start connect to %s", remote->str); - if (connect(clifd, remote_addr, (socklen_t)remote->addr.len) != 0) { + if (connect(clifd, remote_addr, static_cast(remote->addr.len)) != 0) { gpr_mu_unlock(g_mu); close(clifd); return GRPC_OS_ERROR(errno, "connect"); @@ -286,9 +286,9 @@ static void test_connect(size_t num_connects, grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* const addr = - (struct sockaddr_storage*)resolved_addr.addr; + reinterpret_cast(resolved_addr.addr); struct sockaddr_storage* const addr1 = - (struct sockaddr_storage*)resolved_addr1.addr; + reinterpret_cast(resolved_addr1.addr); unsigned svr_fd_count; int port; int svr_port; @@ -305,8 +305,8 @@ static void test_connect(size_t num_connects, LOG_TEST("test_connect"); gpr_log(GPR_INFO, "clients=%lu, num chan args=%lu, remote IP=%s, test_dst_addrs=%d", - (unsigned long)num_connects, - (unsigned long)(channel_args != nullptr ? channel_args->num_args : 0), + static_cast(num_connects), + (channel_args != nullptr ? channel_args->num_args : 0), dst_addrs != nullptr ? "" : "::", test_dst_addrs); memset(&resolved_addr, 0, sizeof(resolved_addr)); memset(&resolved_addr1, 0, sizeof(resolved_addr1)); diff --git a/test/core/iomgr/timer_heap_test.cc b/test/core/iomgr/timer_heap_test.cc index ed66b7df8d..08f5d632e3 100644 --- a/test/core/iomgr/timer_heap_test.cc +++ b/test/core/iomgr/timer_heap_test.cc @@ -102,7 +102,7 @@ static void test1(void) { check_valid(&pq); for (i = 0; i < num_test_operations; ++i) { - size_t elem_num = (size_t)rand() % num_test_elements; + size_t elem_num = static_cast(rand()) % num_test_elements; grpc_timer* el = &test_elements[elem_num]; if (!inpq[elem_num]) { /* not in pq */ GPR_ASSERT(!contains(&pq, el)); @@ -142,8 +142,8 @@ static elem_struct* search_elems(elem_struct* elems, size_t count, search_order[i] = i; } for (size_t i = 0; i < count * 2; i++) { - size_t a = (size_t)rand() % count; - size_t b = (size_t)rand() % count; + size_t a = static_cast(rand()) % count; + size_t b = static_cast(rand()) % count; GPR_SWAP(size_t, search_order[a], search_order[b]); } elem_struct* out = nullptr; @@ -235,7 +235,7 @@ static void shrink_test(void) { size_t expected_size; /* A large random number to allow for multiple shrinkages, at least 512. */ - const size_t num_elements = (size_t)rand() % 2000 + 512; + const size_t num_elements = static_cast(rand()) % 2000 + 512; grpc_timer_heap_init(&pq); @@ -265,7 +265,7 @@ static void shrink_test(void) { 4 times the Size and not less than 2 times, but never goes below 16. */ expected_size = pq.timer_count; while (pq.timer_count > 0) { - const size_t which = (size_t)rand() % pq.timer_count; + const size_t which = static_cast(rand()) % pq.timer_count; grpc_timer* te = pq.timers[which]; grpc_timer_heap_remove(&pq, te); gpr_free(te); diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 4c92a6b69e..f21af5d401 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -65,7 +65,7 @@ static bool on_read(grpc_fd* emfd) { recv(grpc_fd_wrapped_fd(emfd), read_buffer, sizeof(read_buffer), 0); g_number_of_reads++; - g_number_of_bytes_read += (int)byte_count; + g_number_of_bytes_read += static_cast(byte_count); GPR_ASSERT( GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); @@ -100,16 +100,16 @@ typedef struct test_socket_factory test_socket_factory; static int test_socket_factory_socket(grpc_socket_factory* factory, int domain, int type, int protocol) { - test_socket_factory* f = (test_socket_factory*)factory; + test_socket_factory* f = reinterpret_cast(factory); f->number_of_socket_calls++; return socket(domain, type, protocol); } static int test_socket_factory_bind(grpc_socket_factory* factory, int sockfd, const grpc_resolved_address* addr) { - test_socket_factory* f = (test_socket_factory*)factory; + test_socket_factory* f = reinterpret_cast(factory); f->number_of_bind_calls++; - return bind(sockfd, (struct sockaddr*)addr->addr, (socklen_t)addr->len); + return bind(sockfd, reinterpret_cast(addr->addr), static_cast(addr->len)); } static int test_socket_factory_compare(grpc_socket_factory* a, @@ -118,7 +118,7 @@ static int test_socket_factory_compare(grpc_socket_factory* a, } static void test_socket_factory_destroy(grpc_socket_factory* factory) { - test_socket_factory* f = (test_socket_factory*)factory; + test_socket_factory* f = reinterpret_cast(factory); gpr_free(f); } @@ -173,7 +173,7 @@ static void test_no_op_with_port(void) { g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_port"); @@ -196,7 +196,7 @@ static void test_no_op_with_port_and_socket_factory(void) { g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); test_socket_factory* socket_factory = test_socket_factory_create(); grpc_arg socket_factory_arg = @@ -231,7 +231,7 @@ static void test_no_op_with_port_and_start(void) { g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_port_and_start"); @@ -256,7 +256,7 @@ static void test_receive(int number_of_clients) { grpc_pollset_init(g_pollset, &g_mu); grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; + struct sockaddr_storage* addr = reinterpret_cast(resolved_addr.addr); int clifd, svrfd; grpc_udp_server* s = grpc_udp_server_create(nullptr); int i; diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index 2d64520b92..a3f3f2008b 100644 --- a/test/core/iomgr/wakeup_fd_cv_test.cc +++ b/test/core/iomgr/wakeup_fd_cv_test.cc @@ -84,7 +84,7 @@ int mock_poll(struct pollfd* fds, nfds_t nfds, int timeout) { } void background_poll(void* args) { - poll_args* pargs = (poll_args*)args; + poll_args* pargs = static_cast(args); pargs->result = grpc_poll_function(pargs->fds, pargs->nfds, pargs->timeout); } diff --git a/test/core/json/json_rewrite.cc b/test/core/json/json_rewrite.cc index 0319d15024..da2f50ec59 100644 --- a/test/core/json/json_rewrite.cc +++ b/test/core/json/json_rewrite.cc @@ -86,7 +86,7 @@ static void json_reader_string_add_char(void* userdata, uint32_t c) { json_reader_userdata* state = static_cast(userdata); check_string(state, 1); GPR_ASSERT(c < 256); - state->scratchpad[state->string_len++] = (char)c; + state->scratchpad[state->string_len++] = static_cast(c); } static void json_reader_string_add_utf32(void* userdata, uint32_t c) { @@ -122,7 +122,7 @@ static uint32_t json_reader_read_char(void* userdata) { r = fgetc(state->in); if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; - return (uint32_t)r; + return static_cast(r); } static void json_reader_container_begins(void* userdata, grpc_json_type type) { diff --git a/test/core/json/json_rewrite_test.cc b/test/core/json/json_rewrite_test.cc index 8846d4612b..2fade12e13 100644 --- a/test/core/json/json_rewrite_test.cc +++ b/test/core/json/json_rewrite_test.cc @@ -97,7 +97,7 @@ static void json_reader_string_add_char(void* userdata, uint32_t c) { json_reader_userdata* state = static_cast(userdata); check_string(state, 1); GPR_ASSERT(c <= 256); - state->scratchpad[state->string_len++] = (char)c; + state->scratchpad[state->string_len++] = static_cast(c); } static void json_reader_string_add_utf32(void* userdata, uint32_t c) { @@ -140,7 +140,7 @@ static uint32_t json_reader_read_char(void* userdata) { r = fgetc(state->in); if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; - return (uint32_t)r; + return static_cast(r); } static void json_reader_container_begins(void* userdata, grpc_json_type type) { diff --git a/test/core/memory_usage/client.cc b/test/core/memory_usage/client.cc index 4f2ca9e937..96ff7ca721 100644 --- a/test/core/memory_usage/client.cc +++ b/test/core/memory_usage/client.cc @@ -155,16 +155,16 @@ static struct grpc_memory_counters send_snapshot_request(int call_idx, struct grpc_memory_counters snapshot; snapshot.total_size_absolute = - ((struct grpc_memory_counters*)GRPC_SLICE_START_PTR(response)) + (reinterpret_castGRPC_SLICE_START_PTR(response)) ->total_size_absolute; snapshot.total_allocs_absolute = - ((struct grpc_memory_counters*)GRPC_SLICE_START_PTR(response)) + (reinterpret_castGRPC_SLICE_START_PTR(response)) ->total_allocs_absolute; snapshot.total_size_relative = - ((struct grpc_memory_counters*)GRPC_SLICE_START_PTR(response)) + (reinterpret_castGRPC_SLICE_START_PTR(response)) ->total_size_relative; snapshot.total_allocs_relative = - ((struct grpc_memory_counters*)GRPC_SLICE_START_PTR(response)) + (reinterpret_castGRPC_SLICE_START_PTR(response)) ->total_allocs_relative; grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv); @@ -285,7 +285,7 @@ int main(int argc, char** argv) { gpr_log(GPR_INFO, "---------client stats--------"); gpr_log(GPR_INFO, "client call memory usage: %f bytes per call", - (double)(client_calls_inflight.total_size_relative - + static_cast(client_calls_inflight.total_size_relative - client_benchmark_calls_start.total_size_relative) / benchmark_iterations); gpr_log(GPR_INFO, "client channel memory usage %zi bytes", @@ -297,7 +297,7 @@ int main(int argc, char** argv) { after_server_create.total_size_relative - before_server_create.total_size_relative); gpr_log(GPR_INFO, "server call memory usage: %f bytes per call", - (double)(server_calls_inflight.total_size_relative - + static_cast(server_calls_inflight.total_size_relative - server_benchmark_calls_start.total_size_relative) / benchmark_iterations); gpr_log(GPR_INFO, "server channel memory usage %zi bytes", @@ -310,14 +310,14 @@ int main(int argc, char** argv) { char* env_build = gpr_getenv("BUILD_NUMBER"); char* env_job = gpr_getenv("JOB_NAME"); fprintf(csv, "%f,%zi,%zi,%f,%zi,%s,%s\n", - (double)(client_calls_inflight.total_size_relative - + static_cast(client_calls_inflight.total_size_relative - client_benchmark_calls_start.total_size_relative) / benchmark_iterations, client_channel_end.total_size_relative - client_channel_start.total_size_relative, after_server_create.total_size_relative - before_server_create.total_size_relative, - (double)(server_calls_inflight.total_size_relative - + static_cast(server_calls_inflight.total_size_relative - server_benchmark_calls_start.total_size_relative) / benchmark_iterations, server_calls_end.total_size_relative - diff --git a/test/core/memory_usage/memory_usage_test.cc b/test/core/memory_usage/memory_usage_test.cc index cc3528b060..c170f5ad26 100644 --- a/test/core/memory_usage/memory_usage_test.cc +++ b/test/core/memory_usage/memory_usage_test.cc @@ -37,7 +37,7 @@ int main(int argc, char** argv) { gpr_subprocess *svr, *cli; /* figure out where we are */ if (lslash) { - memcpy(root, me, (size_t)(lslash - me)); + memcpy(root, me, static_cast(lslash - me)); root[lslash - me] = 0; } else { strcpy(root, "."); diff --git a/test/core/memory_usage/server.cc b/test/core/memory_usage/server.cc index a276102e83..f016fb248d 100644 --- a/test/core/memory_usage/server.cc +++ b/test/core/memory_usage/server.cc @@ -73,7 +73,7 @@ typedef struct { static fling_call calls[100006]; static void request_call_unary(int call_idx) { - if (call_idx == (int)(sizeof(calls) / sizeof(fling_call))) { + if (call_idx == static_cast(sizeof(calls) / sizeof(fling_call))) { gpr_log(GPR_INFO, "Used all call slots (10000) on server. Server exit."); _exit(0); } @@ -84,7 +84,7 @@ static void request_call_unary(int call_idx) { } static void send_initial_metadata_unary(void* tag) { - grpc_metadata_array_init(&(*(fling_call*)tag).initial_metadata_send); + grpc_metadata_array_init(&(*static_cast(tag)).initial_metadata_send); metadata_ops[0].op = GRPC_OP_SEND_INITIAL_METADATA; metadata_ops[0].data.send_initial_metadata.count = 0; @@ -111,7 +111,7 @@ static void send_snapshot(void* tag, struct grpc_memory_counters* snapshot) { grpc_slice snapshot_slice = grpc_slice_new(snapshot, sizeof(*snapshot), gpr_free); payload_buffer = grpc_raw_byte_buffer_create(&snapshot_slice, 1); - grpc_metadata_array_init(&(*(fling_call*)tag).initial_metadata_send); + grpc_metadata_array_init(&(*static_cast(tag)).initial_metadata_send); op = snapshot_ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; @@ -163,7 +163,7 @@ int main(int argc, char** argv) { grpc_test_init(1, fake_argv); grpc_init(); - srand((unsigned)clock()); + srand(static_cast(clock())); cl = gpr_cmdline_create("fling server"); gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr); @@ -204,7 +204,7 @@ int main(int argc, char** argv) { addr = addr_buf = nullptr; // initialize call instances - for (int i = 0; i < (int)(sizeof(calls) / sizeof(fling_call)); i++) { + for (int i = 0; i < static_cast(sizeof(calls) / sizeof(fling_call)); i++) { grpc_call_details_init(&calls[i].call_details); calls[i].state = FLING_SERVER_NEW_REQUEST; } @@ -281,7 +281,7 @@ int main(int argc, char** argv) { grpc_metadata_array_destroy(&s->request_metadata_recv); break; case FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL: - for (int k = 0; k < (int)(sizeof(calls) / sizeof(fling_call)); + for (int k = 0; k < static_cast(sizeof(calls) / sizeof(fling_call)); ++k) { if (calls[k].state == FLING_SERVER_WAIT_FOR_DESTROY) { calls[k].state = FLING_SERVER_SEND_STATUS_FLING_CALL; diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 8fd2c75438..52c423b14a 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -84,7 +84,7 @@ static int read_bytes(int fd, char* buf, size_t read_size, int spin) { return -1; } } else { - bytes_read += (size_t)err; + bytes_read += static_cast(err); } } while (bytes_read < read_size); return 0; @@ -127,7 +127,7 @@ static int poll_read_bytes(int fd, char* buf, size_t read_size, int spin) { gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno)); return -1; } - bytes_read += (size_t)err2; + bytes_read += static_cast(err2); } while (bytes_read < read_size); return 0; } @@ -166,7 +166,7 @@ static int epoll_read_bytes(struct thread_args* args, char* buf, int spin) { read(args->fds.read_fd, buf + bytes_read, read_size - bytes_read); } while (err2 < 0 && errno == EINTR); if (errno == EAGAIN) break; - bytes_read += (size_t)err2; + bytes_read += static_cast(err2); /* TODO(klempner): This should really be doing an extra call after we are done to ensure we see an EAGAIN */ } while (bytes_read < read_size); @@ -203,7 +203,7 @@ static int blocking_write_bytes(struct thread_args* args, char* buf) { return -1; } } else { - bytes_written += (size_t)err; + bytes_written += static_cast(err); } } while (bytes_written < write_size); return 0; @@ -288,7 +288,7 @@ static void print_histogram(grpc_histogram* histogram) { static double now(void) { gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME); - return 1e9 * (double)tv.tv_sec + (double)tv.tv_nsec; + return 1e9 * static_cast(tv.tv_sec) + static_cast(tv.tv_nsec); } static void client_thread(thread_args* args) { @@ -420,7 +420,7 @@ static int create_sockets_tcp(fd_pair* client_fds, fd_pair* server_fds) { int server_fd = -1; struct sockaddr_in port; - struct sockaddr* sa_port = (struct sockaddr*)&port; + struct sockaddr* sa_port = reinterpret_cast(&port); port.sin_family = AF_INET; port.sin_port = 0; @@ -652,7 +652,7 @@ int main(int argc, char** argv) { if (read_strategy == nullptr) { gpr_log(GPR_INFO, "No strategy specified, running all benchmarks"); - return run_all_benchmarks((size_t)msg_size); + return run_all_benchmarks(static_cast(msg_size)); } if (socket_type == nullptr) { @@ -679,12 +679,12 @@ int main(int argc, char** argv) { client_args->read_bytes = strategy->read_strategy; client_args->write_bytes = blocking_write_bytes; client_args->setup = strategy->setup; - client_args->msg_size = (size_t)msg_size; + client_args->msg_size = static_cast(msg_size); client_args->strategy_name = read_strategy; server_args->read_bytes = strategy->read_strategy; server_args->write_bytes = blocking_write_bytes; server_args->setup = strategy->setup; - server_args->msg_size = (size_t)msg_size; + server_args->msg_size = static_cast(msg_size); server_args->strategy_name = read_strategy; error = run_benchmark(socket_type, client_args, server_args); diff --git a/test/core/security/create_jwt.cc b/test/core/security/create_jwt.cc index bb8227f08f..7be4ba08e1 100644 --- a/test/core/security/create_jwt.cc +++ b/test/core/security/create_jwt.cc @@ -36,7 +36,7 @@ void create_jwt(const char* json_key_file_path, const char* service_url, GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file(json_key_file_path, 1, &json_key_data))); key = grpc_auth_json_key_create_from_string( - (const char*)GRPC_SLICE_START_PTR(json_key_data)); + reinterpret_castGRPC_SLICE_START_PTR(json_key_data)); grpc_slice_unref(json_key_data); if (!grpc_auth_json_key_is_valid(&key)) { fprintf(stderr, "Could not parse json key.\n"); diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 90310469aa..77f450b1a3 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -140,7 +140,7 @@ static grpc_httpcli_response http_response(int status, const char* body) { grpc_httpcli_response response; memset(&response, 0, sizeof(grpc_httpcli_response)); response.status = status; - response.body = gpr_strdup((char*)body); + response.body = gpr_strdup(const_cast(body)); response.body_length = strlen(body); return response; } @@ -324,7 +324,7 @@ static void check_metadata(const expected_md* expected, } static void check_request_metadata(void* arg, grpc_error* error) { - request_metadata_state* state = (request_metadata_state*)arg; + request_metadata_state* state = static_cast(arg); gpr_log(GPR_INFO, "expected_error: %s", grpc_error_string(state->expected_error)); gpr_log(GPR_INFO, "actual_error: %s", grpc_error_string(error)); @@ -754,7 +754,7 @@ static grpc_service_account_jwt_access_credentials* creds_as_jwt( grpc_call_credentials* creds) { GPR_ASSERT(creds != nullptr); GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_JWT) == 0); - return (grpc_service_account_jwt_access_credentials*)creds; + return reinterpret_cast(creds); } static void test_jwt_creds_lifetime(void) { @@ -873,10 +873,9 @@ static void test_google_default_creds_auth_key(void) { set_google_default_creds_env_var_with_file_contents( "json_key_google_default_creds", json_key); gpr_free(json_key); - creds = (grpc_composite_channel_credentials*) - grpc_google_default_credentials_create(); + creds = reinterpret_cast(grpc_google_default_credentials_create()); GPR_ASSERT(creds != nullptr); - jwt = (grpc_service_account_jwt_access_credentials*)creds->call_creds; + jwt = reinterpret_cast(creds->call_creds); GPR_ASSERT( strcmp(jwt->key.client_id, "777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") == @@ -892,10 +891,9 @@ static void test_google_default_creds_refresh_token(void) { grpc_flush_cached_google_default_credentials(); set_google_default_creds_env_var_with_file_contents( "refresh_token_google_default_creds", test_refresh_token_str); - creds = (grpc_composite_channel_credentials*) - grpc_google_default_credentials_create(); + creds = reinterpret_cast(grpc_google_default_credentials_create()); GPR_ASSERT(creds != nullptr); - refresh = (grpc_google_refresh_token_credentials*)creds->call_creds; + refresh = reinterpret_cast(creds->call_creds); GPR_ASSERT(strcmp(refresh->refresh_token.client_id, "32555999999.apps.googleusercontent.com") == 0); grpc_channel_credentials_unref(&creds->base); @@ -938,8 +936,7 @@ static void test_google_default_creds_gce(void) { default_creds_gce_detection_httpcli_get_success_override, httpcli_post_should_not_be_called); grpc_composite_channel_credentials* creds = - (grpc_composite_channel_credentials*) - grpc_google_default_credentials_create(); + reinterpret_cast(grpc_google_default_credentials_create()); /* Verify that the default creds actually embeds a GCE creds. */ GPR_ASSERT(creds != nullptr); @@ -1018,7 +1015,7 @@ static int plugin_get_metadata_success( GPR_ASSERT(context.reserved == nullptr); GPR_ASSERT(GPR_ARRAY_SIZE(plugin_md) < GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX); - plugin_state* s = (plugin_state*)state; + plugin_state* s = static_cast(state); *s = PLUGIN_GET_METADATA_CALLED_STATE; for (size_t i = 0; i < GPR_ARRAY_SIZE(plugin_md); ++i) { memset(&creds_md[i], 0, sizeof(grpc_metadata)); @@ -1041,7 +1038,7 @@ static int plugin_get_metadata_failure( GPR_ASSERT(strcmp(context.method_name, test_method) == 0); GPR_ASSERT(context.channel_auth_context == nullptr); GPR_ASSERT(context.reserved == nullptr); - plugin_state* s = (plugin_state*)state; + plugin_state* s = static_cast(state); *s = PLUGIN_GET_METADATA_CALLED_STATE; *status = GRPC_STATUS_UNAUTHENTICATED; *error_details = gpr_strdup(plugin_error_details); @@ -1049,7 +1046,7 @@ static int plugin_get_metadata_failure( } static void plugin_destroy(void* state) { - plugin_state* s = (plugin_state*)state; + plugin_state* s = static_cast(state); *s = PLUGIN_DESTROY_CALLED_STATE; } diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc index b0fa514400..70a92d773d 100644 --- a/test/core/security/fetch_oauth2.cc +++ b/test/core/security/fetch_oauth2.cc @@ -38,7 +38,7 @@ static grpc_call_credentials* create_refresh_token_creds( "load_file", grpc_load_file(json_refresh_token_file_path, 1, &refresh_token))); return grpc_google_refresh_token_credentials_create( - (const char*)GRPC_SLICE_START_PTR(refresh_token), nullptr); + reinterpret_castGRPC_SLICE_START_PTR(refresh_token), nullptr); } int main(int argc, char** argv) { diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index aac9cc0029..80bfe45ab3 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -218,7 +218,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, slice = grpc_base64_decode(b64, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(slice)); decoded = static_cast(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1)); - strncpy(decoded, (const char*)GRPC_SLICE_START_PTR(slice), + strncpy(decoded, reinterpret_castGRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); decoded[GRPC_SLICE_LENGTH(slice)] = '\0'; json = grpc_json_parse_string(decoded); @@ -386,20 +386,20 @@ static void test_jwt_encode_and_sign( const char* dot = strchr(jwt, '.'); GPR_ASSERT(dot != nullptr); parsed_header = - parse_json_part_from_jwt(jwt, (size_t)(dot - jwt), &scratchpad); + parse_json_part_from_jwt(jwt, static_cast(dot - jwt), &scratchpad); GPR_ASSERT(parsed_header != nullptr); check_jwt_header(parsed_header); - offset = (size_t)(dot - jwt) + 1; + offset = static_cast(dot - jwt) + 1; grpc_json_destroy(parsed_header); gpr_free(scratchpad); dot = strchr(jwt + offset, '.'); GPR_ASSERT(dot != nullptr); parsed_claim = parse_json_part_from_jwt( - jwt + offset, (size_t)(dot - (jwt + offset)), &scratchpad); + jwt + offset, static_cast(dot - (jwt + offset)), &scratchpad); GPR_ASSERT(parsed_claim != nullptr); check_jwt_claim_func(parsed_claim); - offset = (size_t)(dot - jwt) + 1; + offset = static_cast(dot - jwt) + 1; grpc_json_destroy(parsed_claim); gpr_free(scratchpad); diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index e219260b1d..2c454c1395 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -207,7 +207,7 @@ static void test_claims_success(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(claims_without_time_constraint); grpc_json* json = grpc_json_parse_string_with_len( - (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); @@ -226,7 +226,7 @@ static void test_expired_claims_failure(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(expired_claims); grpc_json* json = grpc_json_parse_string_with_len( - (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); gpr_timespec exp_iat = {100, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; @@ -251,7 +251,7 @@ static void test_expired_claims_failure(void) { static void test_invalid_claims_failure(void) { grpc_slice s = grpc_slice_from_copied_string(invalid_claims); grpc_json* json = grpc_json_parse_string_with_len( - (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == nullptr); } @@ -260,7 +260,7 @@ static void test_bad_audience_claims_failure(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(claims_without_time_constraint); grpc_json* json = grpc_json_parse_string_with_len( - (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); @@ -274,7 +274,7 @@ static void test_bad_subject_claims_failure(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(claims_with_bad_subject); grpc_json* json = grpc_json_parse_string_with_len( - (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index 0d3a1279af..b18fa455fe 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -40,7 +40,7 @@ typedef struct { } oauth2_request; static void on_oauth2_response(void* arg, grpc_error* error) { - oauth2_request* request = (oauth2_request*)arg; + oauth2_request* request = static_cast(arg); char* token = nullptr; grpc_slice token_slice; if (error != GRPC_ERROR_NONE) { @@ -48,7 +48,7 @@ static void on_oauth2_response(void* arg, grpc_error* error) { } else { GPR_ASSERT(request->md_array.size == 1); token_slice = GRPC_MDVALUE(request->md_array.md[0]); - token = (char*)gpr_malloc(GRPC_SLICE_LENGTH(token_slice) + 1); + token = static_cast(gpr_malloc(GRPC_SLICE_LENGTH(token_slice) + 1)); memcpy(token, GRPC_SLICE_START_PTR(token_slice), GRPC_SLICE_LENGTH(token_slice)); token[GRPC_SLICE_LENGTH(token_slice)] = '\0'; @@ -73,7 +73,7 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", nullptr, nullptr}; - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &request.mu); request.pops = grpc_polling_entity_create_from_pollset(pollset); request.is_done = false; diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index 828694afd1..00e0783089 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -88,7 +88,7 @@ int main(int argc, char** argv) { } memset(&sync, 0, sizeof(sync)); - pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &sync.mu); sync.pops = grpc_polling_entity_create_from_pollset(pollset); sync.is_done = false; @@ -97,7 +97,7 @@ int main(int argc, char** argv) { error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - ((grpc_composite_channel_credentials*)creds)->call_creds, &sync.pops, + (reinterpret_cast(creds))->call_creds, &sync.pops, context, &sync.md_array, &sync.on_request_metadata, &error)) { // Synchronous response. Invoke callback directly. on_metadata_response(&sync, error); diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index 8e92a21e5d..bacadec950 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -57,7 +57,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER; - a[0].value.integer = (int)slice_size; + a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; tcp = grpc_iomgr_create_endpoint_pair("fixture", &args); grpc_endpoint_add_to_pollset(tcp.client, g_pollset); @@ -73,7 +73,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t still_pending_size; size_t total_buffer_size = 8192; size_t buffer_size = total_buffer_size; - uint8_t* encrypted_buffer = (uint8_t*)gpr_malloc(buffer_size); + uint8_t* encrypted_buffer = static_cast(gpr_malloc(buffer_size)); uint8_t* cur = encrypted_buffer; grpc_slice encrypted_leftover; for (i = 0; i < leftover_nslices; i++) { @@ -106,7 +106,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( buffer_size -= protected_buffer_size_to_send; } while (still_pending_size > 0); encrypted_leftover = grpc_slice_from_copied_buffer( - (const char*)encrypted_buffer, total_buffer_size - buffer_size); + reinterpret_cast(encrypted_buffer), total_buffer_size - buffer_size); f.client_ep = grpc_secure_endpoint_create( fake_read_protector, fake_read_zero_copy_protector, tcp.client, &encrypted_leftover, 1); @@ -165,7 +165,7 @@ static grpc_endpoint_test_config configs[] = { clean_up}, }; -static void inc_call_ctr(void* arg, grpc_error* error) { ++*(int*)arg; } +static void inc_call_ctr(void* arg, grpc_error* error) { ++*static_cast(arg); } static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_endpoint_test_fixture f = config.create_fixture(slice_size); @@ -200,7 +200,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { } static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy((grpc_pollset*)p); + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { @@ -210,7 +210,7 @@ int main(int argc, char** argv) { { grpc_core::ExecCtx exec_ctx; - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); grpc_endpoint_tests(configs[0], g_pollset, g_mu); grpc_endpoint_tests(configs[1], g_pollset, g_mu); diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index 747508f6f6..2a4e7c73d3 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -55,7 +55,7 @@ static void on_jwt_verification_done(void* user_data, char* claims_str; GPR_ASSERT(claims != nullptr); claims_str = - grpc_json_dump_to_string((grpc_json*)grpc_jwt_claims_json(claims), 2); + grpc_json_dump_to_string(const_cast(grpc_jwt_claims_json(claims)), 2); printf("Claims: \n\n%s\n", claims_str); gpr_free(claims_str); grpc_jwt_claims_destroy(claims); diff --git a/test/core/slice/b64_test.cc b/test/core/slice/b64_test.cc index 94785fd1e2..6b29443ba1 100644 --- a/test/core/slice/b64_test.cc +++ b/test/core/slice/b64_test.cc @@ -34,7 +34,7 @@ static int buffers_are_equal(const unsigned char* buf1, for (i = 0; i < size; i++) { if (buf1[i] != buf2[i]) { gpr_log(GPR_ERROR, "buf1 and buf2 differ: buf1[%d] = %x vs buf2[%d] = %x", - (int)i, buf1[i], (int)i, buf2[i]); + static_cast(i), buf1[i], static_cast(i), buf2[i]); return 0; } } @@ -61,7 +61,7 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { size_t i; char* b64; grpc_slice orig_decoded; - for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i; + for (i = 0; i < sizeof(orig); i++) orig[i] = static_cast(i); /* Try all the different paddings. */ for (i = 0; i < 3; i++) { @@ -114,7 +114,7 @@ static void test_url_safe_unsafe_mismatch_failure(void) { char* b64; grpc_slice orig_decoded; int url_safe = 1; - for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i; + for (i = 0; i < sizeof(orig); i++) orig[i] = static_cast(i); grpc_core::ExecCtx exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0); diff --git a/test/core/slice/percent_encode_fuzzer.cc b/test/core/slice/percent_encode_fuzzer.cc index 201ae2790e..1e4e95d97e 100644 --- a/test/core/slice/percent_encode_fuzzer.cc +++ b/test/core/slice/percent_encode_fuzzer.cc @@ -34,7 +34,7 @@ static void test(const uint8_t* data, size_t size, const uint8_t* dict) { struct grpc_memory_counters counters; grpc_init(); grpc_memory_counters_init(); - grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size); + grpc_slice input = grpc_slice_from_copied_buffer(reinterpret_cast(data), size); grpc_slice output = grpc_percent_encode_slice(input, dict); grpc_slice decoded_output; // encoder must always produce decodable output diff --git a/test/core/slice/slice_test.cc b/test/core/slice/slice_test.cc index e40154dd0e..5a49793a9e 100644 --- a/test/core/slice/slice_test.cc +++ b/test/core/slice/slice_test.cc @@ -57,7 +57,7 @@ static void test_slice_malloc_returns_something_sensible(void) { } /* We must be able to write to every byte of the data */ for (i = 0; i < length; i++) { - GRPC_SLICE_START_PTR(slice)[i] = (uint8_t)i; + GRPC_SLICE_START_PTR(slice)[i] = static_cast(i); } /* And finally we must succeed in destroying the slice */ grpc_slice_unref(slice); @@ -77,7 +77,7 @@ static void test_slice_new_returns_something_sensible(void) { } /* destroy function that sets a mark to indicate it was called. */ -static void set_mark(void* p) { *((int*)p) = 1; } +static void set_mark(void* p) { *(static_cast(p)) = 1; } static void test_slice_new_with_user_data(void) { int marker = 0; @@ -143,7 +143,7 @@ static void test_slice_sub_works(unsigned length) { beginning of the slice. */ slice = grpc_slice_malloc(length); for (i = 0; i < length; i++) { - GRPC_SLICE_START_PTR(slice)[i] = (uint8_t)i; + GRPC_SLICE_START_PTR(slice)[i] = static_cast(i); } /* Ensure that for all subsets length is correct and that we start on the @@ -183,7 +183,7 @@ static void test_slice_split_head_works(size_t length) { beginning of the slice. */ slice = grpc_slice_malloc(length); for (i = 0; i < length; i++) { - GRPC_SLICE_START_PTR(slice)[i] = (uint8_t)i; + GRPC_SLICE_START_PTR(slice)[i] = static_cast(i); } /* Ensure that for all subsets length is correct and that we start on the @@ -211,7 +211,7 @@ static void test_slice_split_tail_works(size_t length) { beginning of the slice. */ slice = grpc_slice_malloc(length); for (i = 0; i < length; i++) { - GRPC_SLICE_START_PTR(slice)[i] = (uint8_t)i; + GRPC_SLICE_START_PTR(slice)[i] = static_cast(i); } /* Ensure that for all subsets length is correct and that we start on the diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index d97e98b7a4..e5015723f7 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -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*)(intptr_t)1); + gpr_event_set(&opt->on_started, (void*)static_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*)(intptr_t)1); + gpr_event_set(&opt->on_phase1_done, (void*)static_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*)(intptr_t)1, GRPC_ERROR_NONE, + grpc_cq_end_op(opt->cc, (void*)static_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*)(intptr_t)1); + gpr_event_set(&opt->on_finished, (void*)static_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*)(intptr_t)1); + gpr_event_set(&opt->on_started, (void*)static_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*)(intptr_t)1); + gpr_event_set(&opt->on_phase1_done, (void*)static_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*)(intptr_t)1); + gpr_event_set(&opt->on_finished, (void*)static_cast(1)); return; case GRPC_QUEUE_TIMEOUT: gpr_log(GPR_ERROR, "Invalid timeout received"); @@ -240,7 +240,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*)(intptr_t)1); + gpr_event_set(&phase1, (void*)static_cast(1)); gpr_log(GPR_INFO, "wait phase 1"); for (i = 0; i < producers + consumers; i++) { @@ -250,7 +250,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*)(intptr_t)1); + gpr_event_set(&phase2, (void*)static_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 235d136376..ffef966d86 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -55,14 +55,14 @@ // it should never take longer that this to shutdown the server #define SERVER_SHUTDOWN_TIMEOUT 30000 -static void* tag(int n) { return (void*)(uintptr_t)n; } -static int detag(void* p) { return (int)(uintptr_t)p; } +static void* tag(int n) { return (void*)static_cast(n); } +static int detag(void* p) { return static_cast((uintptr_t)p); } void create_loop_destroy(void* addr) { for (int i = 0; i < NUM_OUTER_LOOPS; ++i) { grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* chan = - grpc_insecure_channel_create((char*)addr, nullptr, nullptr); + grpc_insecure_channel_create(static_cast(addr), nullptr, nullptr); for (int j = 0; j < NUM_INNER_LOOPS; ++j) { gpr_timespec later_time = @@ -94,7 +94,7 @@ struct server_thread_args { }; void server_thread(void* vargs) { - struct server_thread_args* args = (struct server_thread_args*)vargs; + struct server_thread_args* args = static_cast(vargs); grpc_event ev; gpr_timespec deadline = grpc_timeout_milliseconds_to_deadline(SERVER_SHUTDOWN_TIMEOUT); @@ -107,7 +107,7 @@ static void on_connect(void* vargs, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); - struct server_thread_args* args = (struct server_thread_args*)vargs; + struct server_thread_args* args = static_cast(vargs); grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); grpc_endpoint_destroy(tcp); @@ -117,11 +117,11 @@ static void on_connect(void* vargs, grpc_endpoint* tcp, } void bad_server_thread(void* vargs) { - struct server_thread_args* args = (struct server_thread_args*)vargs; + struct server_thread_args* args = static_cast(vargs); grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; + struct sockaddr_storage* addr = reinterpret_cast(resolved_addr.addr); int port; grpc_tcp_server* s; grpc_error* error = grpc_tcp_server_create(nullptr, nullptr, &s); @@ -245,7 +245,7 @@ void watches_with_short_timeouts(void* addr) { for (int i = 0; i < NUM_OUTER_LOOPS_SHORT_TIMEOUTS; ++i) { grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* chan = - grpc_insecure_channel_create((char*)addr, nullptr, nullptr); + grpc_insecure_channel_create(static_cast(addr), nullptr, nullptr); for (int j = 0; j < NUM_INNER_LOOPS_SHORT_TIMEOUTS; ++j) { gpr_timespec later_time = diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 4bf40569e6..0ff17ba8d0 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -112,7 +112,7 @@ int main(int argc, char** argv) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(call, ops, static_cast(op - ops), tag(1), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); /* the call should immediately fail */ @@ -128,7 +128,7 @@ int main(int argc, char** argv) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(2), nullptr); + error = grpc_call_start_batch(call, ops, static_cast(op - ops), tag(2), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); /* the call should immediately fail */ diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index a40bd643ec..d3ba50a91c 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -152,10 +152,10 @@ static void test_basic_headers() { } static void encode_int_to_str(int i, char* p) { - p[0] = (char)('a' + i % 26); + p[0] = static_cast('a' + i % 26); i /= 26; GPR_ASSERT(i < 26); - p[1] = (char)('a' + i); + p[1] = static_cast('a' + i); p[2] = 0; } diff --git a/test/core/transport/chttp2/settings_timeout_test.cc b/test/core/transport/chttp2/settings_timeout_test.cc index 7fb395d4b6..39ae587bae 100644 --- a/test/core/transport/chttp2/settings_timeout_test.cc +++ b/test/core/transport/chttp2/settings_timeout_test.cc @@ -104,7 +104,7 @@ class Client { grpc_blocking_resolve_address(server_address_, "80", &server_addresses); ASSERT_EQ(GRPC_ERROR_NONE, error) << grpc_error_string(error); ASSERT_GE(server_addresses->naddrs, 1UL); - pollset_ = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + pollset_ = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset_, &mu_); grpc_pollset_set* pollset_set = grpc_pollset_set_create(); grpc_pollset_set_add_pollset(pollset_set, pollset_); @@ -177,7 +177,7 @@ class Client { private: static void OnEventDone(void* arg, grpc_error* error) { gpr_log(GPR_INFO, "OnEventDone(): %s", grpc_error_string(error)); - EventState* state = (EventState*)arg; + EventState* state = static_cast(arg); state->error_ = GRPC_ERROR_REF(error); gpr_atm_rel_store(&state->done_atm_, 1); } @@ -203,7 +203,7 @@ class Client { } static void PollsetDestroy(void* arg, grpc_error* error) { - grpc_pollset* pollset = (grpc_pollset*)arg; + grpc_pollset* pollset = static_cast(arg); grpc_pollset_destroy(pollset); gpr_free(pollset); } diff --git a/test/core/transport/chttp2/stream_map_test.cc b/test/core/transport/chttp2/stream_map_test.cc index 9b21cb2364..773eb3a35f 100644 --- a/test/core/transport/chttp2/stream_map_test.cc +++ b/test/core/transport/chttp2/stream_map_test.cc @@ -78,7 +78,7 @@ 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*)(uintptr_t)i); + grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); } GPR_ASSERT(n == grpc_chttp2_stream_map_size(&map)); GPR_ASSERT(nullptr == grpc_chttp2_stream_map_find(&map, 0)); @@ -133,7 +133,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*)(uintptr_t)i); + grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); } for (i = 1; i <= n; i++) { if ((i & 1) == 0) { @@ -155,7 +155,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*)(uintptr_t)i); + grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); if ((i & 1) == 0) { grpc_chttp2_stream_map_delete(&map, i); } @@ -177,7 +177,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*)(uintptr_t)i); + grpc_chttp2_stream_map_add(&map, i, (void*)static_cast(i)); if (i > 8) { del = i - 8; GPR_ASSERT((void*)(uintptr_t)del == diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index 7d943fd5c7..84029dc87c 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -240,8 +240,8 @@ static void test_things_stick_around(void) { } for (i = 0; i < nstrs; i++) { - size_t p = (size_t)rand() % nstrs; - size_t q = (size_t)rand() % nstrs; + size_t p = static_cast(rand()) % nstrs; + size_t q = static_cast(rand()) % nstrs; size_t temp = shuf[p]; shuf[p] = shuf[q]; shuf[q] = temp; @@ -308,7 +308,7 @@ static void verify_binary_header_size(const char* key, const uint8_t* value, GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, false); grpc_slice value_slice = - grpc_slice_from_copied_buffer((const char*)value, value_len); + grpc_slice_from_copied_buffer(reinterpret_cast(value), value_len); grpc_slice base64_encoded = grpc_chttp2_base64_encode(value_slice); size_t expected_size = 32 + strlen(key) + GRPC_SLICE_LENGTH(base64_encoded); GPR_ASSERT(expected_size == elem_size); diff --git a/test/core/transport/timeout_encoding_test.cc b/test/core/transport/timeout_encoding_test.cc index 26e0785488..8e4e566a3e 100644 --- a/test/core/transport/timeout_encoding_test.cc +++ b/test/core/transport/timeout_encoding_test.cc @@ -103,20 +103,20 @@ void decode_suite(char ext, grpc_millis (*answer)(int64_t x)) { } static grpc_millis millis_from_nanos(int64_t x) { - return (grpc_millis)(x / GPR_NS_PER_MS + (x % GPR_NS_PER_MS != 0)); + return static_cast(x / GPR_NS_PER_MS + (x % GPR_NS_PER_MS != 0)); } static grpc_millis millis_from_micros(int64_t x) { - return (grpc_millis)(x / GPR_US_PER_MS + (x % GPR_US_PER_MS != 0)); + return static_cast(x / GPR_US_PER_MS + (x % GPR_US_PER_MS != 0)); } -static grpc_millis millis_from_millis(int64_t x) { return (grpc_millis)x; } +static grpc_millis millis_from_millis(int64_t x) { return static_cast(x); } static grpc_millis millis_from_seconds(int64_t x) { - return (grpc_millis)(x * GPR_MS_PER_SEC); + return static_cast(x * GPR_MS_PER_SEC); } static grpc_millis millis_from_minutes(int64_t x) { - return (grpc_millis)(x * 60 * GPR_MS_PER_SEC); + return static_cast(x * 60 * GPR_MS_PER_SEC); } static grpc_millis millis_from_hours(int64_t x) { - return (grpc_millis)(x * 3600 * GPR_MS_PER_SEC); + return static_cast(x * 3600 * GPR_MS_PER_SEC); } void test_decoding(void) { diff --git a/test/core/tsi/fake_transport_security_test.cc b/test/core/tsi/fake_transport_security_test.cc index 73643fc9fd..d709077c2f 100644 --- a/test/core/tsi/fake_transport_security_test.cc +++ b/test/core/tsi/fake_transport_security_test.cc @@ -102,7 +102,7 @@ void fake_tsi_test_do_round_trip_for_all_configs() { v <<= 1; } tsi_test_fixture* fixture = fake_tsi_test_fixture_create(); - fake_tsi_test_fixture* fake_fixture = (fake_tsi_test_fixture*)fixture; + fake_tsi_test_fixture* fake_fixture = reinterpret_cast(fixture); tsi_test_frame_protector_config_destroy(fake_fixture->base.config); fake_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], @@ -123,7 +123,7 @@ void fake_tsi_test_do_round_trip_odd_buffer_size() { for (size_t ind5 = 0; ind5 < size; ind5++) { tsi_test_fixture* fixture = fake_tsi_test_fixture_create(); fake_tsi_test_fixture* fake_fixture = - (fake_tsi_test_fixture*)fixture; + reinterpret_cast(fixture); tsi_test_frame_protector_config_set_buffer_size( fake_fixture->base.config, odd_sizes[ind1], odd_sizes[ind2], odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]); diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index bf54383c54..06780f03e1 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -81,7 +81,7 @@ typedef struct ssl_tsi_test_fixture { } ssl_tsi_test_fixture; static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); GPR_ASSERT(ssl_fixture != nullptr); GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr); GPR_ASSERT(ssl_fixture->alpn_lib != nullptr); @@ -244,7 +244,7 @@ static void check_client_peer(ssl_tsi_test_fixture* ssl_fixture, } static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); GPR_ASSERT(ssl_fixture != nullptr); GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr); ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib; @@ -281,7 +281,7 @@ static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp) { } static void ssl_test_destruct(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); if (ssl_fixture == nullptr) { return; } @@ -425,7 +425,7 @@ void ssl_tsi_test_do_handshake() { void ssl_tsi_test_do_handshake_with_client_authentication() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->force_client_auth = true; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -434,7 +434,7 @@ void ssl_tsi_test_do_handshake_with_client_authentication() { void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain() { /* server1 cert contains "waterzooi.test.google.be" in SAN. */ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->server_name_indication = const_cast("waterzooi.test.google.be"); tsi_test_do_handshake(fixture); @@ -444,7 +444,7 @@ void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain() { void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain() { /* server1 cert contains "*.test.google.fr" in SAN. */ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->server_name_indication = const_cast("juju.test.google.fr"); tsi_test_do_handshake(fixture); @@ -453,7 +453,7 @@ void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain() { void ssl_tsi_test_do_handshake_with_bad_server_cert() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->key_cert_lib->use_bad_server_cert = true; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -461,7 +461,7 @@ void ssl_tsi_test_do_handshake_with_bad_server_cert() { void ssl_tsi_test_do_handshake_with_bad_client_cert() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->key_cert_lib->use_bad_client_cert = true; ssl_fixture->force_client_auth = true; tsi_test_do_handshake(fixture); @@ -470,7 +470,7 @@ void ssl_tsi_test_do_handshake_with_bad_client_cert() { void ssl_tsi_test_do_handshake_alpn_client_no_server() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_NO_SERVER; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -478,7 +478,7 @@ void ssl_tsi_test_do_handshake_alpn_client_no_server() { void ssl_tsi_test_do_handshake_alpn_server_no_client() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_SERVER_NO_CLIENT; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -486,7 +486,7 @@ void ssl_tsi_test_do_handshake_alpn_server_no_client() { void ssl_tsi_test_do_handshake_alpn_client_server_mismatch() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_MISMATCH; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -494,7 +494,7 @@ void ssl_tsi_test_do_handshake_alpn_client_server_mismatch() { void ssl_tsi_test_do_handshake_alpn_client_server_ok() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_OK; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -511,7 +511,7 @@ void ssl_tsi_test_do_round_trip_for_all_configs() { v <<= 1; } tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); tsi_test_frame_protector_config_destroy(ssl_fixture->base.config); ssl_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], @@ -531,7 +531,7 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() { for (size_t ind4 = 0; ind4 < size; ind4++) { for (size_t ind5 = 0; ind5 < size; ind5++) { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; + ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); tsi_test_frame_protector_config_set_buffer_size( ssl_fixture->base.config, odd_sizes[ind1], odd_sizes[ind2], odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]); @@ -571,7 +571,7 @@ void test_tsi_ssl_client_handshaker_factory_refcounting() { handshaker_factory_destructor_called = false; original_vtable = tsi_ssl_handshaker_factory_swap_vtable( - (tsi_ssl_handshaker_factory*)client_handshaker_factory, + reinterpret_cast(client_handshaker_factory), &test_handshaker_factory_vtable); tsi_handshaker* handshaker[3]; @@ -615,7 +615,7 @@ void test_tsi_ssl_server_handshaker_factory_refcounting() { handshaker_factory_destructor_called = false; original_vtable = tsi_ssl_handshaker_factory_swap_vtable( - (tsi_ssl_handshaker_factory*)server_handshaker_factory, + reinterpret_cast(server_handshaker_factory), &test_handshaker_factory_vtable); for (i = 0; i < 3; ++i) { diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index 3537366de9..ef3b6307db 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -144,7 +144,7 @@ static void maybe_append_unused_bytes(handshaker_args* args) { tsi_test_fixture* fixture = args->fixture; if (fixture->test_unused_bytes && !args->appended_unused_bytes) { args->appended_unused_bytes = true; - send_bytes_to_peer(fixture, (const unsigned char*)TSI_TEST_UNUSED_BYTES, + send_bytes_to_peer(fixture, reinterpret_cast(TSI_TEST_UNUSED_BYTES), strlen(TSI_TEST_UNUSED_BYTES), args->is_client); if (fixture->client_result != nullptr && fixture->server_result == nullptr) { @@ -288,7 +288,7 @@ grpc_error* on_handshake_next_done(tsi_result result, void* user_data, const unsigned char* bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) { - handshaker_args* args = (handshaker_args*)user_data; + handshaker_args* args = static_cast(user_data); GPR_ASSERT(args != nullptr); GPR_ASSERT(args->fixture != nullptr); tsi_test_fixture* fixture = args->fixture; @@ -327,7 +327,7 @@ grpc_error* on_handshake_next_done(tsi_result result, void* user_data, static void on_handshake_next_done_wrapper( tsi_result result, void* user_data, const unsigned char* bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) { - handshaker_args* args = (handshaker_args*)user_data; + handshaker_args* args = static_cast(user_data); args->error = on_handshake_next_done(result, user_data, bytes_to_send, bytes_to_send_size, handshaker_result); } @@ -471,7 +471,7 @@ static unsigned char* generate_random_message(size_t size) { unsigned char* output = static_cast(gpr_zalloc(sizeof(unsigned char) * size)); for (i = 0; i < size - 1; ++i) { - output[i] = chars[rand() % (int)(sizeof(chars) - 1)]; + output[i] = chars[rand() % static_cast(sizeof(chars) - 1)]; } return output; } diff --git a/test/core/util/cmdline.cc b/test/core/util/cmdline.cc index 20bce273cd..fd3959bfe9 100644 --- a/test/core/util/cmdline.cc +++ b/test/core/util/cmdline.cc @@ -56,7 +56,7 @@ struct gpr_cmdline { static int normal_state(gpr_cmdline* cl, char* arg); gpr_cmdline* gpr_cmdline_create(const char* description) { - gpr_cmdline* cl = (gpr_cmdline*)gpr_zalloc(sizeof(gpr_cmdline)); + gpr_cmdline* cl = static_cast(gpr_zalloc(sizeof(gpr_cmdline))); cl->description = description; cl->state = normal_state; @@ -85,7 +85,7 @@ static void add_arg(gpr_cmdline* cl, const char* name, const char* help, GPR_ASSERT(0 != strcmp(a->name, name)); } - a = (arg*)gpr_zalloc(sizeof(arg)); + a = static_cast(gpr_zalloc(sizeof(arg))); a->name = name; a->help = help; a->type = type; @@ -223,13 +223,13 @@ static int value_state(gpr_cmdline* cl, char* str) { cl->cur_arg->name); return print_usage_and_die(cl); } - *(int*)cl->cur_arg->value = (int)intval; + *static_cast(cl->cur_arg->value) = static_cast(intval); break; case ARGTYPE_BOOL: if (0 == strcmp(str, "1") || 0 == strcmp(str, "true")) { - *(int*)cl->cur_arg->value = 1; + *static_cast(cl->cur_arg->value) = 1; } else if (0 == strcmp(str, "0") || 0 == strcmp(str, "false")) { - *(int*)cl->cur_arg->value = 0; + *static_cast(cl->cur_arg->value) = 0; } else { fprintf(stderr, "expected boolean, got '%s' for %s\n", str, cl->cur_arg->name); @@ -237,7 +237,7 @@ static int value_state(gpr_cmdline* cl, char* str) { } break; case ARGTYPE_STRING: - *(char**)cl->cur_arg->value = str; + *static_cast(cl->cur_arg->value) = str; break; } @@ -281,14 +281,14 @@ static int normal_state(gpr_cmdline* cl, char* str) { fprintf(stderr, "%s is not a flag argument\n", str); return print_usage_and_die(cl); } - *(int*)cl->cur_arg->value = 0; + *static_cast(cl->cur_arg->value) = 0; return 1; /* early out */ } eq = strchr(str, '='); if (eq != nullptr) { /* copy the string into a temp buffer and extract the name */ - tmp = arg_name = (char*)gpr_malloc((size_t)(eq - str + 1)); - memcpy(arg_name, str, (size_t)(eq - str)); + tmp = arg_name = static_cast(gpr_malloc(static_cast(eq - str + 1))); + memcpy(arg_name, str, static_cast(eq - str)); arg_name[eq - str] = 0; } else { arg_name = str; @@ -305,7 +305,7 @@ static int normal_state(gpr_cmdline* cl, char* str) { cl->state = value_state; } else { /* flag parameter: just set the value */ - *(int*)cl->cur_arg->value = 1; + *static_cast(cl->cur_arg->value) = 1; } } else { r = extra_state(cl, str); diff --git a/test/core/util/debugger_macros.cc b/test/core/util/debugger_macros.cc index bb96fc7054..0ec5f1db6b 100644 --- a/test/core/util/debugger_macros.cc +++ b/test/core/util/debugger_macros.cc @@ -54,5 +54,5 @@ grpc_stream* grpc_transport_stream_from_call(grpc_call* call) { } grpc_chttp2_stream* grpc_chttp2_stream_from_call(grpc_call* call) { - return (grpc_chttp2_stream*)grpc_transport_stream_from_call(call); + return reinterpret_cast(grpc_transport_stream_from_call(call)); } diff --git a/test/core/util/histogram.cc b/test/core/util/histogram.cc index b2518279ac..6eb0342ede 100644 --- a/test/core/util/histogram.cc +++ b/test/core/util/histogram.cc @@ -57,7 +57,7 @@ struct grpc_histogram { /* determine a bucket index given a value - does no bounds checking */ static size_t bucket_for_unchecked(grpc_histogram* h, double x) { - return (size_t)(log(x) * h->one_on_log_multiplier); + return static_cast(log(x) * h->one_on_log_multiplier); } /* bounds checked version of the above */ @@ -74,7 +74,7 @@ static double bucket_start(grpc_histogram* h, double x) { grpc_histogram* grpc_histogram_create(double resolution, double max_bucket_start) { - grpc_histogram* h = (grpc_histogram*)gpr_malloc(sizeof(grpc_histogram)); + grpc_histogram* h = static_cast(gpr_malloc(sizeof(grpc_histogram))); GPR_ASSERT(resolution > 0.0); GPR_ASSERT(max_bucket_start > resolution); h->sum = 0.0; @@ -88,7 +88,7 @@ grpc_histogram* grpc_histogram_create(double resolution, h->num_buckets = bucket_for_unchecked(h, max_bucket_start) + 1; GPR_ASSERT(h->num_buckets > 1); GPR_ASSERT(h->num_buckets < 100000000); - h->buckets = (uint32_t*)gpr_zalloc(sizeof(uint32_t) * h->num_buckets); + h->buckets = static_cast(gpr_zalloc(sizeof(uint32_t) * h->num_buckets)); return h; } @@ -176,14 +176,14 @@ static double threshold_for_count_below(grpc_histogram* h, double count_below) { break; } } - return (bucket_start(h, (double)lower_idx) + - bucket_start(h, (double)upper_idx)) / + return (bucket_start(h, static_cast(lower_idx)) + + bucket_start(h, static_cast(upper_idx))) / 2.0; } else { /* treat values as uniform throughout the bucket, and find where this value should lie */ - lower_bound = bucket_start(h, (double)lower_idx); - upper_bound = bucket_start(h, (double)(lower_idx + 1)); + lower_bound = bucket_start(h, static_cast(lower_idx)); + upper_bound = bucket_start(h, static_cast(lower_idx + 1)); return GPR_CLAMP(upper_bound - (upper_bound - lower_bound) * (count_so_far - count_below) / h->buckets[lower_idx], diff --git a/test/core/util/memory_counters.cc b/test/core/util/memory_counters.cc index 32d7b89c9a..4960fe0757 100644 --- a/test/core/util/memory_counters.cc +++ b/test/core/util/memory_counters.cc @@ -48,13 +48,13 @@ static void* guard_malloc(size_t size) { NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, (gpr_atm)size); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_allocs_absolute, (gpr_atm)1); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_allocs_relative, (gpr_atm)1); - ptr = (size_t*)g_old_allocs.malloc_fn(size + sizeof(size)); + ptr = static_cast(g_old_allocs.malloc_fn(size + sizeof(size))); *ptr++ = size; return ptr; } static void* guard_realloc(void* vptr, size_t size) { - size_t* ptr = (size_t*)vptr; + size_t* ptr = static_cast(vptr); if (vptr == nullptr) { return guard_malloc(size); } @@ -67,13 +67,13 @@ static void* guard_realloc(void* vptr, size_t size) { NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, -(gpr_atm)*ptr); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, (gpr_atm)size); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_allocs_absolute, (gpr_atm)1); - ptr = (size_t*)g_old_allocs.realloc_fn(ptr, size + sizeof(size)); + ptr = static_cast(g_old_allocs.realloc_fn(ptr, size + sizeof(size))); *ptr++ = size; return ptr; } static void guard_free(void* vptr) { - size_t* ptr = (size_t*)vptr; + size_t* ptr = static_cast(vptr); if (!vptr) return; --ptr; NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, -(gpr_atm)*ptr); diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc index 4b35a581b1..37a1b622e4 100644 --- a/test/core/util/mock_endpoint.cc +++ b/test/core/util/mock_endpoint.cc @@ -42,7 +42,7 @@ typedef struct grpc_mock_endpoint { static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); gpr_mu_lock(&m->mu); if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); @@ -56,7 +56,7 @@ static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); for (size_t i = 0; i < slices->count; i++) { m->on_write(slices->slices[i]); } @@ -72,7 +72,7 @@ static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); gpr_mu_lock(&m->mu); if (m->on_read) { GRPC_CLOSURE_SCHED(m->on_read, @@ -86,7 +86,7 @@ static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { } static void me_destroy(grpc_endpoint* ep) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); grpc_slice_buffer_destroy(&m->read_buffer); grpc_resource_user_unref(m->resource_user); gpr_free(m); @@ -97,7 +97,7 @@ static char* me_get_peer(grpc_endpoint* ep) { } static grpc_resource_user* me_get_resource_user(grpc_endpoint* ep) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); return m->resource_user; } @@ -118,7 +118,7 @@ static const grpc_endpoint_vtable vtable = { grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)gpr_malloc(sizeof(*m)); + grpc_mock_endpoint* m = static_cast(gpr_malloc(sizeof(*m))); m->base.vtable = &vtable; char* name; gpr_asprintf(&name, "mock_endpoint_%" PRIxPTR, (intptr_t)m); @@ -132,7 +132,7 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), } void grpc_mock_endpoint_put_read(grpc_endpoint* ep, grpc_slice slice) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); gpr_mu_lock(&m->mu); if (m->on_read != nullptr) { grpc_slice_buffer_add(m->on_read_out, slice); diff --git a/test/core/util/parse_hexstring.cc b/test/core/util/parse_hexstring.cc index 622642a298..7ba6776bc2 100644 --- a/test/core/util/parse_hexstring.cc +++ b/test/core/util/parse_hexstring.cc @@ -39,10 +39,10 @@ grpc_slice parse_hexstring(const char* hexstring) { temp = 0; for (p = hexstring; *p; p++) { if (*p >= '0' && *p <= '9') { - temp = (uint8_t)(temp << 4) | (uint8_t)(*p - '0'); + temp = static_cast(temp << 4) | static_cast(*p - '0'); nibbles++; } else if (*p >= 'a' && *p <= 'f') { - temp = (uint8_t)(temp << 4) | (uint8_t)(*p - 'a' + 10); + temp = static_cast(temp << 4) | static_cast(*p - 'a' + 10); nibbles++; } if (nibbles == 2) { diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc index 0da0765979..38c23aa978 100644 --- a/test/core/util/passthru_endpoint.cc +++ b/test/core/util/passthru_endpoint.cc @@ -55,7 +55,7 @@ struct passthru_endpoint { static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - half* m = (half*)ep; + half* m = reinterpret_cast(ep); gpr_mu_lock(&m->parent->mu); if (m->parent->shutdown) { GRPC_CLOSURE_SCHED( @@ -77,7 +77,7 @@ static half* other_half(half* h) { static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - half* m = other_half((half*)ep); + half* m = other_half(reinterpret_cast(ep)); gpr_mu_lock(&m->parent->mu); grpc_error* error = GRPC_ERROR_NONE; gpr_atm_no_barrier_fetch_add(&m->parent->stats->num_writes, (gpr_atm)1); @@ -108,7 +108,7 @@ static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { - half* m = (half*)ep; + half* m = reinterpret_cast(ep); gpr_mu_lock(&m->parent->mu); m->parent->shutdown = true; if (m->on_read) { @@ -130,7 +130,7 @@ static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { } static void me_destroy(grpc_endpoint* ep) { - passthru_endpoint* p = ((half*)ep)->parent; + passthru_endpoint* p = (reinterpret_cast(ep))->parent; gpr_mu_lock(&p->mu); if (0 == --p->halves) { gpr_mu_unlock(&p->mu); @@ -147,15 +147,15 @@ static void me_destroy(grpc_endpoint* ep) { } static char* me_get_peer(grpc_endpoint* ep) { - passthru_endpoint* p = ((half*)ep)->parent; - return ((half*)ep) == &p->client ? gpr_strdup("fake:mock_client_endpoint") + passthru_endpoint* p = (reinterpret_cast(ep))->parent; + return (reinterpret_cast(ep)) == &p->client ? gpr_strdup("fake:mock_client_endpoint") : gpr_strdup("fake:mock_server_endpoint"); } static int me_get_fd(grpc_endpoint* ep) { return -1; } static grpc_resource_user* me_get_resource_user(grpc_endpoint* ep) { - half* m = (half*)ep; + half* m = reinterpret_cast(ep); return m->resource_user; } @@ -190,7 +190,7 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client, grpc_endpoint** server, grpc_resource_quota* resource_quota, grpc_passthru_endpoint_stats* stats) { - passthru_endpoint* m = (passthru_endpoint*)gpr_malloc(sizeof(*m)); + passthru_endpoint* m = static_cast(gpr_malloc(sizeof(*m))); m->halves = 2; m->shutdown = 0; if (stats == nullptr) { @@ -208,8 +208,8 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client, grpc_passthru_endpoint_stats* grpc_passthru_endpoint_stats_create() { grpc_passthru_endpoint_stats* stats = - (grpc_passthru_endpoint_stats*)gpr_malloc( - sizeof(grpc_passthru_endpoint_stats)); + static_cast(gpr_malloc( + sizeof(grpc_passthru_endpoint_stats))); memset(stats, 0, sizeof(*stats)); gpr_ref_init(&stats->refs, 1); return stats; diff --git a/test/core/util/port.cc b/test/core/util/port.cc index 9d02b673ed..4690727337 100644 --- a/test/core/util/port.cc +++ b/test/core/util/port.cc @@ -76,7 +76,7 @@ static void chose_port(int port) { } num_chosen_ports++; chosen_ports = - (int*)gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports); + static_cast(gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports)); chosen_ports[num_chosen_ports - 1] = port; } diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 7e76c8063f..886951c20d 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -41,13 +41,13 @@ typedef struct freereq { } freereq; static void destroy_pops_and_shutdown(void* p, grpc_error* error) { - grpc_pollset* pollset = grpc_polling_entity_pollset((grpc_polling_entity*)p); + grpc_pollset* pollset = grpc_polling_entity_pollset(static_cast(p)); grpc_pollset_destroy(pollset); gpr_free(pollset); } static void freed_port_from_server(void* arg, grpc_error* error) { - freereq* pr = (freereq*)arg; + freereq* pr = static_cast(arg); gpr_mu_lock(pr->mu); pr->done = 1; GRPC_LOG_IF_ERROR( @@ -71,7 +71,7 @@ void grpc_free_port_using_server(int port) { memset(&req, 0, sizeof(req)); memset(&rsp, 0, sizeof(rsp)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, @@ -127,7 +127,7 @@ typedef struct portreq { static void got_port_from_server(void* arg, grpc_error* error) { size_t i; int port = 0; - portreq* pr = (portreq*)arg; + portreq* pr = static_cast(arg); int failed = 0; grpc_httpcli_response* response = &pr->response; @@ -158,7 +158,7 @@ static void got_port_from_server(void* arg, grpc_error* error) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis( - (int64_t)(1000.0 * (1 + pow(1.3, pr->retries) * rand() / RAND_MAX)), + static_cast(1000.0 * (1 + pow(1.3, pr->retries) * rand() / RAND_MAX)), GPR_TIMESPAN))); pr->retries++; req.host = pr->server; @@ -201,7 +201,7 @@ int grpc_pick_port_using_server(void) { grpc_core::ExecCtx exec_ctx; memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, diff --git a/test/core/util/reconnect_server.cc b/test/core/util/reconnect_server.cc index b5a7749385..ea8fee499c 100644 --- a/test/core/util/reconnect_server.cc +++ b/test/core/util/reconnect_server.cc @@ -62,7 +62,7 @@ static void on_connect(void* arg, grpc_endpoint* tcp, gpr_free(acceptor); char* peer; char* last_colon; - reconnect_server* server = (reconnect_server*)arg; + reconnect_server* server = static_cast(arg); gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); timestamp_list* new_tail; peer = grpc_endpoint_get_peer(tcp); @@ -76,7 +76,7 @@ static void on_connect(void* arg, grpc_endpoint* tcp, } else { if (last_colon == nullptr) { gpr_log(GPR_ERROR, "peer does not contain a ':'"); - } else if (strncmp(server->peer, peer, (size_t)(last_colon - peer)) != + } else if (strncmp(server->peer, peer, static_cast(last_colon - peer)) != 0) { gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer, peer); } diff --git a/test/core/util/slice_splitter.cc b/test/core/util/slice_splitter.cc index c92fc0affe..e766c1982c 100644 --- a/test/core/util/slice_splitter.cc +++ b/test/core/util/slice_splitter.cc @@ -46,7 +46,7 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, case GRPC_SLICE_SPLIT_IDENTITY: *dst_slice_count = src_slice_count; *dst_slices = - (grpc_slice*)gpr_malloc(sizeof(grpc_slice) * src_slice_count); + static_cast(gpr_malloc(sizeof(grpc_slice) * src_slice_count)); for (i = 0; i < src_slice_count; i++) { (*dst_slices)[i] = src_slices[i]; grpc_slice_ref((*dst_slices)[i]); @@ -58,7 +58,7 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, for (i = 0; i < src_slice_count; i++) { length += GRPC_SLICE_LENGTH(src_slices[i]); } - *dst_slices = (grpc_slice*)gpr_malloc(sizeof(grpc_slice)); + *dst_slices = static_cast(gpr_malloc(sizeof(grpc_slice))); **dst_slices = grpc_slice_malloc(length); length = 0; for (i = 0; i < src_slice_count; i++) { @@ -74,7 +74,7 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, length += GRPC_SLICE_LENGTH(src_slices[i]); } *dst_slice_count = length; - *dst_slices = (grpc_slice*)gpr_malloc(sizeof(grpc_slice) * length); + *dst_slices = static_cast(gpr_malloc(sizeof(grpc_slice) * length)); length = 0; for (i = 0; i < src_slice_count; i++) { for (j = 0; j < GRPC_SLICE_LENGTH(src_slices[i]); j++) { @@ -114,7 +114,7 @@ grpc_slice grpc_slice_merge(grpc_slice* slices, size_t nslices) { for (i = 0; i < nslices; i++) { if (GRPC_SLICE_LENGTH(slices[i]) + length > capacity) { capacity = GPR_MAX(capacity * 2, GRPC_SLICE_LENGTH(slices[i]) + length); - out = (uint8_t*)gpr_realloc(out, capacity); + out = static_cast(gpr_realloc(out, capacity)); } memcpy(out + length, GRPC_SLICE_START_PTR(slices[i]), GRPC_SLICE_LENGTH(slices[i])); diff --git a/test/core/util/subprocess_posix.cc b/test/core/util/subprocess_posix.cc index 0f6c99731f..bb42ccbdeb 100644 --- a/test/core/util/subprocess_posix.cc +++ b/test/core/util/subprocess_posix.cc @@ -52,8 +52,8 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) { if (pid == -1) { return nullptr; } else if (pid == 0) { - exec_args = (char**)gpr_malloc(((size_t)argc + 1) * sizeof(char*)); - memcpy(exec_args, argv, (size_t)argc * sizeof(char*)); + exec_args = static_cast(gpr_malloc((static_cast(argc) + 1) * sizeof(char*))); + memcpy(exec_args, argv, static_cast(argc) * sizeof(char*)); exec_args[argc] = nullptr; execv(exec_args[0], exec_args); /* if we reach here, an error has occurred */ @@ -61,7 +61,7 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) { _exit(1); return nullptr; } else { - r = (gpr_subprocess*)gpr_zalloc(sizeof(gpr_subprocess)); + r = static_cast(gpr_zalloc(sizeof(gpr_subprocess))); r->pid = pid; return r; } diff --git a/test/core/util/test_config.cc b/test/core/util/test_config.cc index e381be6842..5c01cfd070 100644 --- a/test/core/util/test_config.cc +++ b/test/core/util/test_config.cc @@ -36,7 +36,7 @@ int64_t g_poller_slowdown_factor = 1; #if GPR_GETPID_IN_UNISTD_H #include -static unsigned seed(void) { return (unsigned)getpid(); } +static unsigned seed(void) { return static_cast(getpid()); } #endif #if GPR_GETPID_IN_PROCESS_H @@ -264,7 +264,7 @@ static void install_crash_handler() { ss.ss_size = sizeof(g_alt_stack); ss.ss_sp = g_alt_stack; GPR_ASSERT(sigaltstack(&ss, nullptr) == 0); - sa.sa_flags = (int)(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND); + sa.sa_flags = static_cast(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND); sa.sa_sigaction = crash_handler; GPR_ASSERT(sigaction(SIGILL, &sa, nullptr) == 0); GPR_ASSERT(sigaction(SIGABRT, &sa, nullptr) == 0); @@ -365,14 +365,14 @@ int64_t grpc_test_slowdown_factor() { gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s) { return gpr_time_add( gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_millis(grpc_test_slowdown_factor() * (int64_t)1e3 * time_s, + gpr_time_from_millis(grpc_test_slowdown_factor() * static_cast(1e3) * time_s, GPR_TIMESPAN)); } gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms) { return gpr_time_add( gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_micros(grpc_test_slowdown_factor() * (int64_t)1e3 * time_ms, + gpr_time_from_micros(grpc_test_slowdown_factor() * static_cast(1e3) * time_ms, GPR_TIMESPAN)); } diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index b1b5297f29..1216934630 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -54,12 +54,12 @@ void test_tcp_server_init(test_tcp_server* server, void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); int port_added; grpc_core::ExecCtx exec_ctx; addr->sin_family = AF_INET; - addr->sin_port = htons((uint16_t)port); + addr->sin_port = htons(static_cast(port)); memset(&addr->sin_addr, 0, sizeof(addr->sin_addr)); grpc_error* error = grpc_tcp_server_create(&server->shutdown_complete, diff --git a/test/core/util/trickle_endpoint.cc b/test/core/util/trickle_endpoint.cc index 54e1cf19c9..87a8d9c216 100644 --- a/test/core/util/trickle_endpoint.cc +++ b/test/core/util/trickle_endpoint.cc @@ -48,7 +48,7 @@ typedef struct { static void te_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_read(te->wrapped, slices, cb); } @@ -63,7 +63,7 @@ static void maybe_call_write_cb_locked(trickle_endpoint* te) { static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); GPR_ASSERT(te->write_cb == nullptr); if (te->write_buffer.length == 0) { @@ -79,24 +79,24 @@ static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, } static void te_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_add_to_pollset(te->wrapped, pollset); } static void te_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_add_to_pollset_set(te->wrapped, pollset_set); } static void te_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_delete_from_pollset_set(te->wrapped, pollset_set); } static void te_shutdown(grpc_endpoint* ep, grpc_error* why) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); if (te->error == GRPC_ERROR_NONE) { te->error = GRPC_ERROR_REF(why); @@ -107,7 +107,7 @@ static void te_shutdown(grpc_endpoint* ep, grpc_error* why) { } static void te_destroy(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_destroy(te->wrapped); gpr_mu_destroy(&te->mu); grpc_slice_buffer_destroy_internal(&te->write_buffer); @@ -117,22 +117,22 @@ static void te_destroy(grpc_endpoint* ep) { } static grpc_resource_user* te_get_resource_user(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); return grpc_endpoint_get_resource_user(te->wrapped); } static char* te_get_peer(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); return grpc_endpoint_get_peer(te->wrapped); } static int te_get_fd(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); return grpc_endpoint_get_fd(te->wrapped); } static void te_finish_write(void* arg, grpc_error* error) { - trickle_endpoint* te = (trickle_endpoint*)arg; + trickle_endpoint* te = static_cast(arg); gpr_mu_lock(&te->mu); te->writing = false; grpc_slice_buffer_reset_and_unref(&te->writing_buffer); @@ -152,7 +152,7 @@ static const grpc_endpoint_vtable vtable = {te_read, grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, double bytes_per_second) { - trickle_endpoint* te = (trickle_endpoint*)gpr_malloc(sizeof(*te)); + trickle_endpoint* te = static_cast(gpr_malloc(sizeof(*te))); te->base.vtable = &vtable; te->wrapped = wrap; te->bytes_per_second = bytes_per_second; @@ -166,16 +166,16 @@ grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, } static double ts2dbl(gpr_timespec s) { - return (double)s.tv_sec + 1e-9 * (double)s.tv_nsec; + return static_cast(s.tv_sec) + 1e-9 * static_cast(s.tv_nsec); } size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); if (!te->writing && te->write_buffer.length > 0) { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); double elapsed = ts2dbl(gpr_time_sub(now, te->last_write)); - size_t bytes = (size_t)(te->bytes_per_second * elapsed); + size_t bytes = static_cast(te->bytes_per_second * elapsed); // gpr_log(GPR_DEBUG, "%lf elapsed --> %" PRIdPTR " bytes", elapsed, bytes); if (bytes > 0) { grpc_slice_buffer_move_first(&te->write_buffer, @@ -195,7 +195,7 @@ size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { } size_t grpc_trickle_get_backlog(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); size_t backlog = te->write_buffer.length; gpr_mu_unlock(&te->mu); diff --git a/test/cpp/codegen/proto_utils_test.cc b/test/cpp/codegen/proto_utils_test.cc index cc355bb24a..d714e59b5d 100644 --- a/test/cpp/codegen/proto_utils_test.cc +++ b/test/cpp/codegen/proto_utils_test.cc @@ -103,7 +103,7 @@ void BufferWriterTest(int block_size, int total_size, int backup_size) { ASSERT_GT(backup_size, 0); } for (int i = 0; i < write_size; i++) { - ((uint8_t*)data)[i] = written_size % 128; + (static_cast(data))[i] = written_size % 128; written_size++; } if (should_backup) { @@ -130,7 +130,7 @@ void BufferWriterTest(int block_size, int total_size, int backup_size) { } TEST(WriterTest, TinyBlockTinyBackup) { - for (int i = 2; i < (int)GRPC_SLICE_INLINED_SIZE; i++) { + for (int i = 2; i < static_castGRPC_SLICE_INLINED_SIZE; i++) { BufferWriterTest(i, 256, 1); } } diff --git a/test/cpp/common/alarm_test.cc b/test/cpp/common/alarm_test.cc index 2a933a84c4..2dc2e4b36c 100644 --- a/test/cpp/common/alarm_test.cc +++ b/test/cpp/common/alarm_test.cc @@ -36,7 +36,7 @@ TEST(AlarmTest, RegularExpiry) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -56,7 +56,7 @@ TEST(AlarmTest, MultithreadedRegularExpiry) { }); std::thread t2([&cq, &ok, &output_tag, &status] { - status = cq.AsyncNext((void**)&output_tag, &ok, + status = cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); }); @@ -75,7 +75,7 @@ TEST(AlarmTest, DeprecatedRegularExpiry) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -91,7 +91,7 @@ TEST(AlarmTest, MoveConstructor) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); EXPECT_EQ(junk, output_tag); @@ -108,7 +108,7 @@ TEST(AlarmTest, MoveAssignment) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -126,7 +126,7 @@ TEST(AlarmTest, RegularExpiryChrono) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -142,7 +142,7 @@ TEST(AlarmTest, ZeroExpiry) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -158,7 +158,7 @@ TEST(AlarmTest, NegativeExpiry) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -175,7 +175,7 @@ TEST(AlarmTest, Cancellation) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_FALSE(ok); @@ -193,7 +193,7 @@ TEST(AlarmTest, SetDestruction) { void* output_tag; bool ok; const CompletionQueue::NextStatus status = cq.AsyncNext( - (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_FALSE(ok); diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 482f0cb24f..7a4555edac 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -62,7 +62,7 @@ namespace testing { namespace { -void* tag(int i) { return (void*)(intptr_t)i; } +void* tag(int i) { return (void*)static_cast(i); } int detag(void* p) { return static_cast(reinterpret_cast(p)); } #ifdef GRPC_POSIX_SOCKET diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 967db4c57c..b658e7731a 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -347,7 +347,7 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs, for (int i = 0; i < num_rpcs; ++i) { ClientContext context; if (with_binary_metadata) { - char bytes[8] = {'\0', '\1', '\2', '\3', '\4', '\5', '\6', (char)i}; + char bytes[8] = {'\0', '\1', '\2', '\3', '\4', '\5', '\6', static_cast(i)}; context.AddMetadata("custom-bin", grpc::string(bytes, 8)); } context.set_compression_algorithm(GRPC_COMPRESS_GZIP); diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index 53e86addef..d11df3a143 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -50,7 +50,7 @@ namespace grpc { namespace testing { namespace { -void* tag(int i) { return (void*)(intptr_t)i; } +void* tag(int i) { return (void*)static_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 dac5faed8f..c778b205e0 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -47,7 +47,7 @@ namespace grpc { namespace testing { namespace { -void* tag(int i) { return (void*)(intptr_t)i; } +void* tag(int i) { return (void*)static_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 cb515533ed..38d6bfa83b 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -42,7 +42,7 @@ namespace testing { namespace { -void* tag(int i) { return (void*)(intptr_t)i; } +void* tag(int i) { return (void*)static_cast(i); } bool VerifyReturnSuccess(CompletionQueue* cq, int i) { void* got_tag; diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 90b2eddbbb..79074d8e70 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -265,7 +265,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*)(intptr_t)i); + cq_.get(), (void*)static_cast(i)); } } struct Context { diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 06ab8c3ff8..e47842e526 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -198,7 +198,7 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->flags = 0; op->reserved = nullptr; 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), 1); cq_verify(cqv); @@ -230,7 +230,7 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(201), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(201), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); gpr_log(GPR_INFO, "LB Server[%s](%s) after tag 201", sf->servers_hostport, sf->balancer_name); @@ -256,7 +256,7 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(203), nullptr); + 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), 1); cq_verify(cqv); @@ -278,7 +278,7 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->flags = 0; op->reserved = nullptr; 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(201), 1); @@ -351,7 +351,7 @@ static void start_backend_server(server_fixture* sf) { op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), nullptr); + grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); gpr_log(GPR_INFO, "Server[%s] after tag 101", sf->servers_hostport); @@ -365,7 +365,7 @@ static void start_backend_server(server_fixture* sf) { op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); ev = grpc_completion_queue_next( sf->cq, grpc_timeout_seconds_to_deadline(3), nullptr); @@ -394,7 +394,7 @@ static void start_backend_server(server_fixture* sf) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(103), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); ev = grpc_completion_queue_next( @@ -429,7 +429,7 @@ static void start_backend_server(server_fixture* sf) { op->reserved = nullptr; op++; error = - grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), nullptr); + grpc_call_start_batch(s, ops, static_cast(op - ops), tag(104), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(101), 1); @@ -493,7 +493,7 @@ static void perform_request(client_fixture* cf) { op->flags = 0; op->reserved = nullptr; 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); for (i = 0; i < 4; i++) { @@ -510,7 +510,7 @@ static void perform_request(client_fixture* cf) { op->flags = 0; op->reserved = nullptr; 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), 1); @@ -529,7 +529,7 @@ static void perform_request(client_fixture* cf) { op->flags = 0; op->reserved = nullptr; 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(1), 1); diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 3051afa86b..2ea1d3f79a 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -875,7 +875,7 @@ bool InteropClient::DoCacheableUnary() { // Create request with current timestamp 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(static_cast(ts.tv_nsec)); SimpleRequest request; request.mutable_payload()->set_body(timestamp.c_str(), timestamp.size()); @@ -914,7 +914,7 @@ bool InteropClient::DoCacheableUnary() { // Request 3 // Modify the request body so it will not get a cache hit ts = gpr_now(GPR_CLOCK_PRECISE); - timestamp = std::to_string((long long unsigned)ts.tv_nsec); + timestamp = std::to_string(static_cast(ts.tv_nsec)); SimpleRequest request1; request1.mutable_payload()->set_body(timestamp.c_str(), timestamp.size()); ClientContext context3; diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index 4b7310389c..3fe709ff83 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -82,7 +82,7 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { static_cast(state.iterations()), true, false, - (size_t)1024, + static_cast(1024), &stats, }; grpc_chttp2_encode_header(&c, nullptr, 0, &b, &hopt, &outbuf); @@ -131,7 +131,7 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { static_cast(state.iterations()), state.range(0) != 0, Fixture::kEnableTrueBinary, - (size_t)state.range(1), + static_cast(state.range(1)), &stats, }; grpc_chttp2_encode_header(&c, nullptr, 0, &b, &hopt, &outbuf); @@ -777,7 +777,7 @@ static void OnHeaderNew(void* user_data, grpc_mdelem md) { if (GRPC_MDELEM_IS_INTERNED(md)) { /* not already parsed: parse it now, and store the * result away */ - cached_timeout = (grpc_millis*)gpr_malloc(sizeof(grpc_millis)); + cached_timeout = static_cast(gpr_malloc(sizeof(grpc_millis))); *cached_timeout = timeout; grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 874c834931..7b236d94b6 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -38,7 +38,7 @@ namespace testing { auto& force_library_initialization = Library::get(); -static void* g_tag = (void*)(intptr_t)10; // Some random number +static void* g_tag = (void*)static_cast(10); // Some random number static grpc_completion_queue* g_cq; static grpc_event_engine_vtable g_vtable; static const grpc_event_engine_vtable* g_old_vtable; @@ -75,7 +75,7 @@ static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker, gpr_mu_unlock(&ps->mu); GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag)); grpc_cq_end_op(g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, - (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); + static_cast(gpr_malloc(sizeof(grpc_cq_completion)))); grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&ps->mu); return GRPC_ERROR_NONE; diff --git a/test/cpp/microbenchmarks/fullstack_context_mutators.h b/test/cpp/microbenchmarks/fullstack_context_mutators.h index cafbeffdbe..3584280c48 100644 --- a/test/cpp/microbenchmarks/fullstack_context_mutators.h +++ b/test/cpp/microbenchmarks/fullstack_context_mutators.h @@ -72,7 +72,7 @@ class RandomBinaryMetadata { grpc::string s; s.reserve(length + 1); for (int i = 0; i < length; i++) { - s += (char)rand(); + s += static_cast(rand()); } return s; } @@ -95,7 +95,7 @@ class RandomAsciiMetadata { grpc::string s; s.reserve(length + 1); for (int i = 0; i < length; i++) { - s += (char)(rand() % 26 + 'a'); + s += static_cast(rand() % 26 + 'a'); } return s; } diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index fdc04e51c6..ce9731b7a6 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -108,7 +108,7 @@ class FullstackFixture : public BaseFixture { void AddToLabel(std::ostream& out, benchmark::State& state) { BaseFixture::AddToLabel(out, state); out << " polls/iter:" - << (double)grpc_get_cq_poll_num(this->cq()->cq()) / state.iterations(); + << static_cast(grpc_get_cq_poll_num(this->cq()->cq())) / state.iterations(); } ServerCompletionQueue* cq() { return cq_.get(); } @@ -236,7 +236,7 @@ class EndpointPairFixture : public BaseFixture { void AddToLabel(std::ostream& out, benchmark::State& state) { BaseFixture::AddToLabel(out, state); out << " polls/iter:" - << (double)grpc_get_cq_poll_num(this->cq()->cq()) / state.iterations(); + << static_cast(grpc_get_cq_poll_num(this->cq()->cq())) / state.iterations(); } ServerCompletionQueue* cq() { return cq_.get(); } diff --git a/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h b/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h index 0763d07855..f399949a32 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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 ((int)(intptr_t)t != 0) { + while (static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 ((int)(intptr_t)t != 0) { - int i = (int)(intptr_t)t; + while (static_cast((intptr_t)t) != 0) { + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 9e826091ec..3623e373f6 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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)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 = (int)(intptr_t)t; + int i = static_cast((intptr_t)t); GPR_ASSERT(need_tags & (1 << i)); need_tags &= ~(1 << i); } diff --git a/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h b/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h index d448938295..a85c33c320 100644 --- a/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h +++ b/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h @@ -91,7 +91,7 @@ static void BM_UnaryPingPong(benchmark::State& state) { for (int i = (1 << 3) | (1 << 4); i != 0;) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); 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/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index a4c0a3a0ce..25a033f104 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -44,17 +44,17 @@ void TrackCounters::AddToLabel(std::ostream& out, benchmark::State& state) { grpc_stats_diff(&stats_end, &stats_begin_, &stats); for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { out << " " << grpc_stats_counter_name[i] - << "/iter:" << ((double)stats.counters[i] / (double)state.iterations()); + << "/iter:" << (static_cast(stats.counters[i]) / static_cast(state.iterations())); } for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { std::ostringstream median_ss; median_ss << grpc_stats_histogram_name[i] << "-median"; state.counters[median_ss.str()] = benchmark::Counter( - grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 50.0)); + grpc_stats_histo_percentile(&stats, static_cast(i), 50.0)); std::ostringstream tail_ss; tail_ss << grpc_stats_histogram_name[i] << "-99p"; state.counters[tail_ss.str()] = benchmark::Counter( - grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 99.0)); + grpc_stats_histo_percentile(&stats, static_cast(i), 99.0)); } #ifdef GPR_LOW_LEVEL_COUNTERS grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index b7d951a86e..0d0ab1891a 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -217,7 +217,7 @@ static double UnaryPingPong(int request_size, int response_size) { for (int i = (1 << 3) | (1 << 4); i != 0;) { GPR_ASSERT(fixture->cq()->Next(&t, &ok)); GPR_ASSERT(ok); - int tagnum = (int)reinterpret_cast(t); + int tagnum = static_cast(reinterpret_cast(t)); GPR_ASSERT(i & (1 << tagnum)); i -= 1 << tagnum; } @@ -230,7 +230,7 @@ static double UnaryPingPong(int request_size, int response_size) { } double writes_per_iteration = - (double)fixture->writes_performed() / (double)kIterations; + static_cast(fixture->writes_performed()) / static_cast(kIterations); fixture.reset(); server_env[0]->~ServerEnv(); diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 42ebeff41d..863be40f2a 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -109,9 +109,9 @@ void GprLogReporter::ReportCoreStats(const char* name, int idx, for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { gpr_log(GPR_DEBUG, "%s[%d].%s = %.1lf/%.1lf/%.1lf (50/95/99%%-ile)", name, idx, grpc_stats_histogram_name[i], - grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 50), - grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 95), - grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 99)); + grpc_stats_histo_percentile(&data, static_cast(i), 50), + grpc_stats_histo_percentile(&data, static_cast(i), 95), + grpc_stats_histo_percentile(&data, static_cast(i), 99)); } } diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index 9da33566dd..d772e709de 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -84,7 +84,7 @@ class Server { } payload->set_type(type); // Don't waste time creating a new payload of identical size. - if (payload->body().length() != (size_t)size) { + if (payload->body().length() != static_cast(size)) { std::unique_ptr body(new char[size]()); payload->set_body(body.get(), size); } diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc index 3b0bb9eeba..6fc22f35ca 100644 --- a/test/cpp/util/cli_call.cc +++ b/test/cpp/util/cli_call.cc @@ -30,7 +30,7 @@ namespace grpc { namespace testing { namespace { -void* tag(int i) { return (void*)(intptr_t)i; } +void* tag(int i) { return (void*)static_cast(i); } } // namespace Status CliCall::Call(std::shared_ptr channel, diff --git a/test/cpp/util/proto_reflection_descriptor_database.cc b/test/cpp/util/proto_reflection_descriptor_database.cc index 42b1f4e75c..5c0bfb3727 100644 --- a/test/cpp/util/proto_reflection_descriptor_database.cc +++ b/test/cpp/util/proto_reflection_descriptor_database.cc @@ -50,7 +50,7 @@ ProtoReflectionDescriptorDatabase::~ProtoReflectionDescriptorDatabase() { } gpr_log(GPR_INFO, "ServerReflectionInfo rpc failed. Error code: %d, details: %s", - (int)status.error_code(), status.error_message().c_str()); + static_cast(status.error_code()), status.error_message().c_str()); } } } -- cgit v1.2.3 From 4d20a666850b732cf1562487fb5f46ab9654105f Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Fri, 9 Feb 2018 09:34:04 -0800 Subject: Run clang fmt --- src/core/ext/census/grpc_context.cc | 3 +- .../ext/filters/client_channel/backup_poller.cc | 3 +- .../filters/client_channel/channel_connectivity.cc | 4 +- .../ext/filters/client_channel/client_channel.cc | 28 ++++--- .../client_channel/client_channel_factory.cc | 6 +- .../client_channel/http_connect_handshaker.cc | 19 +++-- .../grpclb/client_load_reporting_filter.cc | 6 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 34 ++++++--- .../lb_policy/grpclb/grpclb_client_stats.cc | 12 +-- .../lb_policy/grpclb/load_balancer_api.cc | 39 +++++----- .../lb_policy/pick_first/pick_first.cc | 6 +- .../lb_policy/round_robin/round_robin.cc | 18 +++-- .../client_channel/lb_policy/subchannel_list.cc | 18 +++-- .../filters/client_channel/lb_policy_factory.cc | 3 +- .../ext/filters/client_channel/parse_address.cc | 3 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 3 +- .../dns/c_ares/grpc_ares_ev_driver_posix.cc | 3 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 37 +++++---- .../ext/filters/client_channel/retry_throttle.cc | 24 +++--- src/core/ext/filters/client_channel/subchannel.cc | 19 +++-- .../ext/filters/client_channel/subchannel_index.cc | 18 +++-- src/core/ext/filters/deadline/deadline_filter.cc | 27 ++++--- .../ext/filters/http/client/http_client_filter.cc | 14 ++-- src/core/ext/filters/http/http_filters_plugin.cc | 3 +- .../message_compress/message_compress_filter.cc | 7 +- .../ext/filters/http/server/http_server_filter.cc | 16 ++-- .../load_reporting/server_load_reporting_plugin.cc | 3 +- src/core/ext/filters/max_age/max_age_filter.cc | 4 +- .../filters/message_size/message_size_filter.cc | 12 +-- .../ext/filters/workarounds/workaround_utils.cc | 8 +- .../chttp2/client/secure/secure_channel_create.cc | 7 +- .../ext/transport/chttp2/server/chttp2_server.cc | 12 ++- .../ext/transport/chttp2/transport/bin_decoder.cc | 11 +-- .../ext/transport/chttp2/transport/bin_encoder.cc | 15 ++-- .../transport/chttp2/transport/chttp2_transport.cc | 89 ++++++++++++---------- .../ext/transport/chttp2/transport/flow_control.cc | 19 +++-- .../ext/transport/chttp2/transport/flow_control.h | 7 +- .../ext/transport/chttp2/transport/frame_data.cc | 41 +++++----- .../ext/transport/chttp2/transport/frame_goaway.cc | 8 +- .../transport/chttp2/transport/frame_rst_stream.cc | 3 +- .../transport/chttp2/transport/frame_settings.cc | 7 +- .../transport/chttp2/transport/hpack_encoder.cc | 22 +++--- .../ext/transport/chttp2/transport/hpack_parser.cc | 19 +++-- .../ext/transport/chttp2/transport/hpack_table.cc | 13 ++-- .../chttp2/transport/incoming_metadata.cc | 4 +- src/core/ext/transport/chttp2/transport/parsing.cc | 30 ++++---- .../ext/transport/chttp2/transport/stream_map.cc | 10 ++- src/core/ext/transport/chttp2/transport/writing.cc | 24 +++--- .../transport/cronet/transport/cronet_transport.cc | 30 ++++---- src/core/ext/transport/inproc/inproc_transport.cc | 18 +++-- src/core/lib/backoff/backoff.cc | 9 ++- src/core/lib/channel/channel_args.cc | 9 ++- src/core/lib/channel/channel_stack.cc | 15 ++-- src/core/lib/channel/channel_stack_builder.cc | 13 ++-- src/core/lib/channel/connected_channel.cc | 3 +- src/core/lib/channel/handshaker.cc | 8 +- src/core/lib/channel/handshaker_registry.cc | 3 +- src/core/lib/compression/compression_internal.cc | 3 +- src/core/lib/compression/message_compress.cc | 6 +- .../lib/compression/stream_compression_gzip.cc | 6 +- src/core/lib/debug/stats.cc | 10 ++- src/core/lib/gpr/arena.cc | 20 +++-- src/core/lib/gpr/log.cc | 3 +- src/core/lib/gpr/string.cc | 6 +- src/core/lib/gpr/thd_posix.cc | 8 +- src/core/lib/gpr/time.cc | 8 +- src/core/lib/http/format_request.cc | 3 +- src/core/lib/http/httpcli_security_connector.cc | 4 +- src/core/lib/http/parser.cc | 13 ++-- src/core/lib/iomgr/call_combiner.cc | 15 ++-- src/core/lib/iomgr/combiner.cc | 3 +- src/core/lib/iomgr/error.cc | 38 +++++---- src/core/lib/iomgr/ev_epoll1_linux.cc | 4 +- src/core/lib/iomgr/ev_epollex_linux.cc | 24 +++--- src/core/lib/iomgr/ev_epollsig_linux.cc | 10 ++- src/core/lib/iomgr/ev_poll_posix.cc | 47 +++++++----- src/core/lib/iomgr/exec_ctx.cc | 7 +- src/core/lib/iomgr/executor.cc | 13 ++-- src/core/lib/iomgr/is_epollexclusive_available.cc | 3 +- src/core/lib/iomgr/load_file.cc | 4 +- src/core/lib/iomgr/resolve_address_posix.cc | 8 +- src/core/lib/iomgr/resource_quota.cc | 10 ++- src/core/lib/iomgr/sockaddr_utils.cc | 48 ++++++++---- src/core/lib/iomgr/socket_utils_common_posix.cc | 6 +- src/core/lib/iomgr/socket_utils_linux.cc | 3 +- src/core/lib/iomgr/tcp_client_posix.cc | 7 +- src/core/lib/iomgr/tcp_posix.cc | 29 ++++--- src/core/lib/iomgr/tcp_server_posix.cc | 9 ++- .../lib/iomgr/tcp_server_utils_posix_common.cc | 4 +- .../lib/iomgr/tcp_server_utils_posix_ifaddrs.cc | 7 +- src/core/lib/iomgr/timer_generic.cc | 11 +-- src/core/lib/iomgr/timer_heap.cc | 8 +- src/core/lib/iomgr/timer_manager.cc | 3 +- src/core/lib/iomgr/udp_server.cc | 24 ++++-- src/core/lib/iomgr/unix_sockets_posix.cc | 20 +++-- src/core/lib/iomgr/wakeup_fd_cv.cc | 4 +- src/core/lib/json/json_reader.cc | 6 +- src/core/lib/json/json_string.cc | 3 +- src/core/lib/json/json_writer.cc | 6 +- src/core/lib/security/context/security_context.cc | 24 +++--- .../credentials/composite/composite_credentials.cc | 17 +++-- src/core/lib/security/credentials/credentials.cc | 7 +- .../security/credentials/credentials_metadata.cc | 4 +- .../security/credentials/fake/fake_credentials.cc | 19 +++-- .../google_default/google_default_credentials.cc | 9 ++- .../security/credentials/iam/iam_credentials.cc | 6 +- .../lib/security/credentials/jwt/json_token.cc | 3 +- .../security/credentials/jwt/jwt_credentials.cc | 4 +- .../lib/security/credentials/jwt/jwt_verifier.cc | 22 +++--- .../credentials/oauth2/oauth2_credentials.cc | 29 ++++--- .../credentials/plugin/plugin_credentials.cc | 16 ++-- .../security/credentials/ssl/ssl_credentials.cc | 39 +++++----- .../lib/security/transport/client_auth_filter.cc | 20 ++--- src/core/lib/security/transport/lb_targets_info.cc | 8 +- src/core/lib/security/transport/secure_endpoint.cc | 10 ++- .../lib/security/transport/security_connector.cc | 37 ++++----- .../lib/security/transport/security_handshaker.cc | 19 ++--- src/core/lib/slice/b64.cc | 9 ++- src/core/lib/slice/slice.cc | 20 ++--- src/core/lib/slice/slice_buffer.cc | 18 +++-- src/core/lib/slice/slice_hash_table.cc | 3 +- src/core/lib/slice/slice_intern.cc | 21 ++--- src/core/lib/slice/slice_string_helpers.cc | 9 ++- src/core/lib/surface/call.cc | 34 +++++---- src/core/lib/surface/channel.cc | 12 ++- src/core/lib/surface/channel_init.cc | 9 ++- src/core/lib/surface/completion_queue.cc | 67 +++++++++------- src/core/lib/surface/server.cc | 54 +++++++------ src/core/lib/transport/bdp_estimator.cc | 7 +- src/core/lib/transport/byte_stream.cc | 24 ++++-- src/core/lib/transport/connectivity_state.cc | 8 +- src/core/lib/transport/error_utils.cc | 13 ++-- src/core/lib/transport/metadata.cc | 31 +++++--- src/core/lib/transport/service_config.cc | 4 +- src/core/lib/transport/timeout_encoding.cc | 3 +- src/core/lib/transport/transport.cc | 3 +- src/core/tsi/fake_transport_security.cc | 51 ++++++++----- src/core/tsi/ssl_transport_security.cc | 82 ++++++++++++-------- src/core/tsi/transport_security.cc | 4 +- src/core/tsi/transport_security_adapter.cc | 22 ++++-- src/cpp/common/channel_filter.h | 3 +- test/core/avl/avl_test.cc | 8 +- test/core/backoff/backoff_test.cc | 22 +++--- test/core/bad_client/tests/duplicate_header.cc | 6 +- test/core/bad_client/tests/window_overflow.cc | 3 +- test/core/bad_ssl/servers/cert.cc | 6 +- test/core/channel/channel_args_test.cc | 13 ++-- test/core/client_channel/parse_address_test.cc | 9 ++- test/core/compression/stream_compression_test.cc | 8 +- test/core/end2end/bad_server_response_test.cc | 4 +- test/core/end2end/dualstack_socket_test.cc | 11 +-- test/core/end2end/fixtures/http_proxy_fixture.cc | 6 +- test/core/end2end/fixtures/proxy.cc | 3 +- test/core/end2end/fuzzers/api_fuzzer.cc | 8 +- test/core/end2end/goaway_server_test.cc | 3 +- test/core/end2end/h2_ssl_cert_test.cc | 3 +- test/core/end2end/tests/authority_not_supported.cc | 3 +- test/core/end2end/tests/bad_hostname.cc | 3 +- test/core/end2end/tests/bad_ping.cc | 6 +- test/core/end2end/tests/binary_metadata.cc | 9 ++- test/core/end2end/tests/call_creds.cc | 12 ++- test/core/end2end/tests/cancel_after_accept.cc | 6 +- .../core/end2end/tests/cancel_after_client_done.cc | 6 +- test/core/end2end/tests/cancel_after_round_trip.cc | 12 ++- test/core/end2end/tests/compressed_payload.cc | 39 ++++++---- test/core/end2end/tests/default_host.cc | 6 +- test/core/end2end/tests/disappearing_server.cc | 6 +- test/core/end2end/tests/filter_call_init_fails.cc | 12 ++- test/core/end2end/tests/filter_causes_close.cc | 3 +- test/core/end2end/tests/filter_latency.cc | 6 +- test/core/end2end/tests/filter_status_code.cc | 6 +- .../core/end2end/tests/graceful_server_shutdown.cc | 6 +- test/core/end2end/tests/high_initial_seqno.cc | 6 +- test/core/end2end/tests/hpack_size.cc | 6 +- test/core/end2end/tests/idempotent_request.cc | 6 +- test/core/end2end/tests/invoke_large_request.cc | 9 ++- test/core/end2end/tests/keepalive_timeout.cc | 9 ++- test/core/end2end/tests/large_metadata.cc | 9 ++- test/core/end2end/tests/load_reporting_hook.cc | 9 ++- test/core/end2end/tests/max_concurrent_streams.cc | 54 ++++++++----- test/core/end2end/tests/max_connection_age.cc | 15 ++-- test/core/end2end/tests/max_connection_idle.cc | 6 +- test/core/end2end/tests/max_message_length.cc | 12 ++- test/core/end2end/tests/network_status_change.cc | 9 ++- test/core/end2end/tests/no_logging.cc | 6 +- test/core/end2end/tests/payload.cc | 9 ++- test/core/end2end/tests/ping_pong_streaming.cc | 23 +++--- test/core/end2end/tests/proxy_auth.cc | 6 +- test/core/end2end/tests/registered_call.cc | 6 +- test/core/end2end/tests/request_with_flags.cc | 3 +- test/core/end2end/tests/request_with_payload.cc | 9 ++- test/core/end2end/tests/resource_quota_server.cc | 43 ++++++----- test/core/end2end/tests/server_finishes_request.cc | 6 +- test/core/end2end/tests/shutdown_finishes_calls.cc | 6 +- .../core/end2end/tests/simple_cacheable_request.cc | 9 ++- test/core/end2end/tests/simple_delayed_request.cc | 6 +- test/core/end2end/tests/simple_metadata.cc | 9 ++- test/core/end2end/tests/simple_request.cc | 6 +- .../tests/stream_compression_compressed_payload.cc | 39 ++++++---- .../end2end/tests/stream_compression_payload.cc | 9 ++- .../stream_compression_ping_pong_streaming.cc | 23 +++--- .../core/end2end/tests/streaming_error_response.cc | 18 +++-- test/core/end2end/tests/trailing_metadata.cc | 9 ++- .../end2end/tests/workaround_cronet_compression.cc | 23 +++--- test/core/end2end/tests/write_buffering.cc | 27 ++++--- test/core/end2end/tests/write_buffering_at_end.cc | 27 ++++--- test/core/fling/client.cc | 3 +- test/core/fling/server.cc | 3 +- test/core/gpr/alloc_test.cc | 4 +- test/core/gpr/spinlock_test.cc | 9 ++- test/core/gpr/sync_test.cc | 9 ++- test/core/handshake/client_ssl.cc | 15 ++-- .../handshake/readahead_handshaker_server_ssl.cc | 3 +- test/core/handshake/server_ssl_common.cc | 13 ++-- test/core/iomgr/endpoint_tests.cc | 3 +- test/core/iomgr/fd_posix_test.cc | 6 +- test/core/iomgr/sockaddr_utils_test.cc | 9 ++- test/core/iomgr/socket_utils_test.cc | 15 ++-- test/core/iomgr/tcp_client_posix_test.cc | 9 ++- test/core/iomgr/tcp_posix_test.cc | 15 ++-- test/core/iomgr/tcp_server_posix_test.cc | 9 ++- test/core/iomgr/udp_server_test.cc | 16 ++-- test/core/memory_usage/client.cc | 61 ++++++++------- test/core/memory_usage/server.cc | 12 ++- test/core/security/create_jwt.cc | 2 +- test/core/security/credentials_test.cc | 15 ++-- test/core/security/fetch_oauth2.cc | 3 +- test/core/security/json_token_test.cc | 6 +- test/core/security/jwt_verifier_test.cc | 10 +-- test/core/security/oauth2_utils.cc | 3 +- .../security/print_google_default_creds_token.cc | 6 +- test/core/security/secure_endpoint_test.cc | 7 +- test/core/security/verify_jwt.cc | 4 +- test/core/slice/percent_encode_fuzzer.cc | 3 +- test/core/surface/concurrent_connectivity_test.cc | 20 +++-- test/core/surface/lame_client_test.cc | 6 +- test/core/transport/metadata_test.cc | 4 +- test/core/transport/timeout_encoding_test.cc | 4 +- test/core/tsi/fake_transport_security_test.cc | 3 +- test/core/tsi/ssl_transport_security_test.cc | 42 ++++++---- test/core/tsi/transport_security_test_lib.cc | 5 +- test/core/util/cmdline.cc | 3 +- test/core/util/debugger_macros.cc | 3 +- test/core/util/histogram.cc | 6 +- test/core/util/mock_endpoint.cc | 3 +- test/core/util/parse_hexstring.cc | 3 +- test/core/util/passthru_endpoint.cc | 12 +-- test/core/util/port.cc | 4 +- test/core/util/port_server_client.cc | 12 ++- test/core/util/reconnect_server.cc | 4 +- test/core/util/slice_splitter.cc | 7 +- test/core/util/subprocess_posix.cc | 3 +- test/core/util/test_config.cc | 10 ++- test/core/util/test_tcp_server.cc | 3 +- test/core/util/trickle_endpoint.cc | 3 +- test/cpp/codegen/proto_utils_test.cc | 2 +- test/cpp/common/alarm_test.cc | 40 +++++----- test/cpp/end2end/end2end_test.cc | 3 +- test/cpp/grpclb/grpclb_test.cc | 38 +++++---- test/cpp/interop/interop_client.cc | 3 +- test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 3 +- test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 5 +- test/cpp/microbenchmarks/fullstack_fixtures.h | 6 +- test/cpp/microbenchmarks/helpers.cc | 15 ++-- test/cpp/performance/writes_per_rpc_test.cc | 3 +- test/cpp/qps/report.cc | 9 ++- .../util/proto_reflection_descriptor_database.cc | 3 +- 267 files changed, 2061 insertions(+), 1355 deletions(-) (limited to 'test/core/end2end/tests/large_metadata.cc') diff --git a/src/core/ext/census/grpc_context.cc b/src/core/ext/census/grpc_context.cc index 5cd3b18614..069e8f1486 100644 --- a/src/core/ext/census/grpc_context.cc +++ b/src/core/ext/census/grpc_context.cc @@ -31,5 +31,6 @@ void grpc_census_call_set_context(grpc_call* call, census_context* context) { census_context* grpc_census_call_get_context(grpc_call* call) { GRPC_API_TRACE("grpc_census_call_get_context(call=%p)", 1, (call)); - return static_cast(grpc_call_context_get(call, GRPC_CONTEXT_TRACING)); + return static_cast( + grpc_call_context_get(call, GRPC_CONTEXT_TRACING)); } diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index 35f1b97b77..ee90b499eb 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -134,7 +134,8 @@ void grpc_client_channel_start_backup_polling( gpr_mu_lock(&g_poller_mu); if (g_poller == nullptr) { g_poller = static_cast(gpr_zalloc(sizeof(backup_poller))); - g_poller->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + g_poller->pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); g_poller->shutting_down = false; grpc_pollset_init(g_poller->pollset, &g_poller->pollset_mu); gpr_ref_init(&g_poller->refs, 0); diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 74c6cfe93c..31a5c31124 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -227,8 +227,8 @@ void grpc_channel_watch_connectivity_state( w->channel = channel; w->error = nullptr; - watcher_timer_init_arg* wa = - static_cast(gpr_malloc(sizeof(watcher_timer_init_arg))); + watcher_timer_init_arg* wa = static_cast( + gpr_malloc(sizeof(watcher_timer_init_arg))); wa->w = w; wa->deadline = deadline; GRPC_CLOSURE_INIT(&w->watcher_timer_init, watcher_timer_init, wa, diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index ee2f21a064..50d562f946 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -260,7 +260,8 @@ static void set_channel_connectivity_state_locked(channel_data* chand, } static void on_lb_policy_state_changed_locked(void* arg, grpc_error* error) { - lb_policy_connectivity_watcher* w = static_cast(arg); + lb_policy_connectivity_watcher* w = + static_cast(arg); /* check if the notification is for the latest policy */ if (w->lb_policy == w->chand->lb_policy) { if (grpc_client_channel_trace.enabled()) { @@ -353,7 +354,8 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { &whole_value)) { return; } - milli_token_ratio = static_cast((whole_value * multiplier) + decimal_value); + milli_token_ratio = + static_cast((whole_value * multiplier) + decimal_value); if (milli_token_ratio <= 0) return; } } @@ -364,7 +366,8 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { } static void request_reresolution_locked(void* arg, grpc_error* error) { - reresolution_request_args* args = static_cast(arg); + reresolution_request_args* args = + static_cast(arg); channel_data* chand = args->chand; // If this invocation is for a stale LB policy, treat it as an LB shutdown // signal. @@ -458,7 +461,8 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { lb_policy_name); } else { reresolution_request_args* args = - static_cast(gpr_zalloc(sizeof(*args))); + static_cast( + gpr_zalloc(sizeof(*args))); args->chand = chand; args->lb_policy = new_lb_policy; GRPC_CLOSURE_INIT(&args->closure, request_reresolution_locked, args, @@ -973,8 +977,8 @@ static void apply_service_config_to_call_locked(grpc_call_element* elem) { grpc_server_retry_throttle_data_ref(chand->retry_throttle_data); } if (chand->method_params_table != nullptr) { - calld->method_params = static_cast(grpc_method_config_table_get( - chand->method_params_table, calld->path)); + calld->method_params = static_cast( + grpc_method_config_table_get(chand->method_params_table, calld->path)); if (calld->method_params != nullptr) { method_parameters_ref(calld->method_params); // If the deadline from the service config is shorter than the one @@ -1161,7 +1165,8 @@ typedef struct { // holding the call combiner. static void pick_after_resolver_result_cancel_locked(void* arg, grpc_error* error) { - pick_after_resolver_result_args* args = static_cast(arg); + pick_after_resolver_result_args* args = + static_cast(arg); if (args->finished) { gpr_free(args); return; @@ -1195,7 +1200,8 @@ static void pick_after_resolver_result_start_locked(grpc_call_element* elem); static void pick_after_resolver_result_done_locked(void* arg, grpc_error* error) { - pick_after_resolver_result_args* args = static_cast(arg); + pick_after_resolver_result_args* args = + static_cast(arg); if (args->finished) { /* cancelled, do nothing */ if (grpc_client_channel_trace.enabled()) { @@ -1595,7 +1601,8 @@ int grpc_client_channel_num_external_connectivity_watchers( } static void on_external_watch_complete_locked(void* arg, grpc_error* error) { - external_connectivity_watcher* w = static_cast(arg); + external_connectivity_watcher* w = + static_cast(arg); grpc_closure* follow_up = w->on_complete; grpc_polling_entity_del_from_pollset_set(&w->pollent, w->chand->interested_parties); @@ -1608,7 +1615,8 @@ static void on_external_watch_complete_locked(void* arg, grpc_error* error) { static void watch_connectivity_state_locked(void* arg, grpc_error* error_ignored) { - external_connectivity_watcher* w = static_cast(arg); + external_connectivity_watcher* w = + static_cast(arg); external_connectivity_watcher* found = nullptr; if (w->state != nullptr) { external_connectivity_watcher_list_append(w->chand, w); diff --git a/src/core/ext/filters/client_channel/client_channel_factory.cc b/src/core/ext/filters/client_channel/client_channel_factory.cc index a21db1ff69..3baf5b31ab 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.cc +++ b/src/core/ext/filters/client_channel/client_channel_factory.cc @@ -39,12 +39,14 @@ grpc_channel* grpc_client_channel_factory_create_channel( } static void* factory_arg_copy(void* factory) { - grpc_client_channel_factory_ref(static_cast(factory)); + grpc_client_channel_factory_ref( + static_cast(factory)); return factory; } static void factory_arg_destroy(void* factory) { - grpc_client_channel_factory_unref(static_cast(factory)); + grpc_client_channel_factory_unref( + static_cast(factory)); } static int factory_arg_cmp(void* factory1, void* factory2) { 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 b4684a81dc..6bb4cefe73 100644 --- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc +++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc @@ -119,7 +119,8 @@ static void handshake_failed_locked(http_connect_handshaker* handshaker, // Callback invoked when finished writing HTTP CONNECT request. static void on_write_done(void* arg, grpc_error* error) { - http_connect_handshaker* handshaker = static_cast(arg); + http_connect_handshaker* handshaker = + static_cast(arg); gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the write failed or we're shutting down, clean up and invoke the @@ -139,7 +140,8 @@ static void on_write_done(void* arg, grpc_error* error) { // Callback invoked for reading HTTP CONNECT response. static void on_read_done(void* arg, grpc_error* error) { - http_connect_handshaker* handshaker = static_cast(arg); + http_connect_handshaker* handshaker = + static_cast(arg); gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the read failed or we're shutting down, clean up and invoke the @@ -224,13 +226,15 @@ done: // static void http_connect_handshaker_destroy(grpc_handshaker* handshaker_in) { - http_connect_handshaker* handshaker = reinterpret_cast(handshaker_in); + http_connect_handshaker* handshaker = + reinterpret_cast(handshaker_in); http_connect_handshaker_unref(handshaker); } static void http_connect_handshaker_shutdown(grpc_handshaker* handshaker_in, grpc_error* why) { - http_connect_handshaker* handshaker = reinterpret_cast(handshaker_in); + http_connect_handshaker* handshaker = + reinterpret_cast(handshaker_in); gpr_mu_lock(&handshaker->mu); if (!handshaker->shutdown) { handshaker->shutdown = true; @@ -244,7 +248,8 @@ static void http_connect_handshaker_shutdown(grpc_handshaker* handshaker_in, static void http_connect_handshaker_do_handshake( grpc_handshaker* handshaker_in, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - http_connect_handshaker* handshaker = reinterpret_cast(handshaker_in); + http_connect_handshaker* handshaker = + reinterpret_cast(handshaker_in); // Check for HTTP CONNECT channel arg. // If not found, invoke on_handshake_done without doing anything. const grpc_arg* arg = @@ -270,8 +275,8 @@ static void http_connect_handshaker_do_handshake( GPR_ASSERT(arg->type == GRPC_ARG_STRING); gpr_string_split(arg->value.string, "\n", &header_strings, &num_header_strings); - headers = static_cast(gpr_malloc(sizeof(grpc_http_header) * - num_header_strings)); + headers = static_cast( + gpr_malloc(sizeof(grpc_http_header) * num_header_strings)); for (size_t i = 0; i < num_header_strings; ++i) { char* sep = strchr(header_strings[i], ':'); if (sep == nullptr) { diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc index b048989d4e..1a3a1f029c 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -70,9 +70,9 @@ static grpc_error* init_call_elem(grpc_call_element* elem, // Get stats object from context and take a ref. GPR_ASSERT(args->context != nullptr); if (args->context[GRPC_GRPCLB_CLIENT_STATS].value != nullptr) { - calld->client_stats = grpc_grpclb_client_stats_ref( - static_cast(args->context[GRPC_GRPCLB_CLIENT_STATS] - .value)); + calld->client_stats = + grpc_grpclb_client_stats_ref(static_cast( + args->context[GRPC_GRPCLB_CLIENT_STATS].value)); // Record call started. grpc_grpclb_client_stats_add_call_started(calld->client_stats); } 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 9ebc15d985..04bf798267 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 @@ -320,7 +320,8 @@ static void glb_lb_call_data_ref(glb_lb_call_data* lb_calld, const gpr_atm count = gpr_atm_acq_load(&lb_calld->refs.count); gpr_log(GPR_DEBUG, "[%s %p] lb_calld %p REF %lu->%lu (%s)", grpc_lb_glb_trace.name(), lb_calld->glb_policy, lb_calld, - static_cast(count - 1), static_cast(count), reason); + static_cast(count - 1), + static_cast(count), reason); } } @@ -331,7 +332,8 @@ static void glb_lb_call_data_unref(glb_lb_call_data* lb_calld, const gpr_atm count = gpr_atm_acq_load(&lb_calld->refs.count); gpr_log(GPR_DEBUG, "[%s %p] lb_calld %p UNREF %lu->%lu (%s)", grpc_lb_glb_trace.name(), lb_calld->glb_policy, lb_calld, - static_cast(count + 1), static_cast(count), reason); + static_cast(count + 1), + static_cast(count), reason); } if (done) { GPR_ASSERT(lb_calld->lb_call != nullptr); @@ -493,13 +495,15 @@ static void parse_server(const grpc_grpclb_server* server, const grpc_grpclb_ip_address* ip = &server->ip_address; if (ip->size == 4) { addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in* addr4 = reinterpret_cast(&addr->addr); + struct sockaddr_in* addr4 = + reinterpret_cast(&addr->addr); addr4->sin_family = AF_INET; memcpy(&addr4->sin_addr, ip->bytes, ip->size); addr4->sin_port = netorder_port; } else if (ip->size == 16) { addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6* addr6 = reinterpret_cast(&addr->addr); + struct sockaddr_in6* addr6 = + reinterpret_cast(&addr->addr); addr6->sin6_family = AF_INET6; memcpy(&addr6->sin6_addr, ip->bytes, ip->size); addr6->sin6_port = netorder_port; @@ -716,7 +720,8 @@ static grpc_lb_policy_args* lb_policy_args_create(glb_lb_policy* glb_policy) { addresses = grpc_lb_addresses_copy(glb_policy->fallback_backend_addresses); } GPR_ASSERT(addresses != nullptr); - grpc_lb_policy_args* args = static_cast(gpr_zalloc(sizeof(*args))); + grpc_lb_policy_args* args = + static_cast(gpr_zalloc(sizeof(*args))); args->client_channel_factory = glb_policy->cc_factory; args->combiner = glb_policy->base.combiner; // Replace the LB addresses in the channel args that we pass down to @@ -887,8 +892,8 @@ static grpc_channel_args* build_lb_channel_args( grpc_lb_addresses* lb_addresses = grpc_lb_addresses_create(num_grpclb_addrs, nullptr); grpc_slice_hash_table_entry* targets_info_entries = - static_cast(gpr_zalloc(sizeof(*targets_info_entries) * - num_grpclb_addrs)); + static_cast( + gpr_zalloc(sizeof(*targets_info_entries) * num_grpclb_addrs)); size_t lb_addresses_idx = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { @@ -1257,7 +1262,8 @@ static void client_load_report_done_locked(void* arg, grpc_error* error) { static bool load_report_counters_are_zero(grpc_grpclb_request* request) { grpc_grpclb_dropped_call_counts* drop_entries = - static_cast(request->client_stats.calls_finished_with_drop.arg); + static_cast( + request->client_stats.calls_finished_with_drop.arg); return request->client_stats.num_calls_started == 0 && request->client_stats.num_calls_finished == 0 && request->client_stats.num_calls_finished_with_client_failed_to_send == @@ -1338,7 +1344,8 @@ static glb_lb_call_data* lb_call_data_create_locked(glb_lb_policy* glb_policy) { glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE : grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; - glb_lb_call_data* lb_calld = static_cast(gpr_zalloc(sizeof(*lb_calld))); + glb_lb_call_data* lb_calld = + static_cast(gpr_zalloc(sizeof(*lb_calld))); lb_calld->lb_call = grpc_channel_create_pollset_set_call( glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, @@ -1809,14 +1816,16 @@ static grpc_lb_policy* glb_create(grpc_lb_policy_factory* factory, if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { return nullptr; } - grpc_lb_addresses* addresses = static_cast(arg->value.pointer.p); + grpc_lb_addresses* addresses = + 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; } if (num_grpclb_addrs == 0) return nullptr; - glb_lb_policy* glb_policy = static_cast(gpr_zalloc(sizeof(*glb_policy))); + glb_lb_policy* glb_policy = + static_cast(gpr_zalloc(sizeof(*glb_policy))); /* Get server name. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); @@ -1920,7 +1929,8 @@ static bool maybe_add_client_load_reporting_filter( if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING && strcmp(channel_arg->value.string, "grpclb") == 0) { return grpc_channel_stack_builder_append_filter( - builder, static_cast(arg), nullptr, nullptr); + builder, static_cast(arg), nullptr, + nullptr); } return true; } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc index f9ffea6c39..3929ed0843 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc @@ -88,8 +88,8 @@ void grpc_grpclb_client_stats_add_call_dropped_locked( // Record the drop. if (client_stats->drop_token_counts == nullptr) { client_stats->drop_token_counts = - static_cast(gpr_zalloc( - sizeof(grpc_grpclb_dropped_call_counts))); + static_cast( + gpr_zalloc(sizeof(grpc_grpclb_dropped_call_counts))); } grpc_grpclb_dropped_call_counts* drop_token_counts = client_stats->drop_token_counts; @@ -104,9 +104,9 @@ void grpc_grpclb_client_stats_add_call_dropped_locked( while (new_num_entries < drop_token_counts->num_entries + 1) { new_num_entries *= 2; } - drop_token_counts->token_counts = static_cast(gpr_realloc( - drop_token_counts->token_counts, - new_num_entries * sizeof(grpc_grpclb_drop_token_count))); + drop_token_counts->token_counts = static_cast( + gpr_realloc(drop_token_counts->token_counts, + new_num_entries * sizeof(grpc_grpclb_drop_token_count))); grpc_grpclb_drop_token_count* new_entry = &drop_token_counts->token_counts[drop_token_counts->num_entries++]; new_entry->token = gpr_strdup(token); @@ -114,7 +114,7 @@ void grpc_grpclb_client_stats_add_call_dropped_locked( } static void atomic_get_and_reset_counter(int64_t* value, gpr_atm* counter) { - *value = static_castgpr_atm_acq_load(counter); + *value = static_cast gpr_atm_acq_load(counter); gpr_atm_full_fetch_add(counter, (gpr_atm)(-*value)); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc index ee6dd27eb5..c388b6ba77 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc @@ -60,8 +60,8 @@ static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field, } grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name) { - grpc_grpclb_request* req = - static_cast(gpr_malloc(sizeof(grpc_grpclb_request))); + grpc_grpclb_request* req = static_cast( + gpr_malloc(sizeof(grpc_grpclb_request))); req->has_client_stats = false; req->has_initial_request = true; req->initial_request.has_name = true; @@ -107,8 +107,8 @@ static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field, grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked( grpc_grpclb_client_stats* client_stats) { - grpc_grpclb_request* req = - static_cast(gpr_zalloc(sizeof(grpc_grpclb_request))); + grpc_grpclb_request* req = static_cast( + gpr_zalloc(sizeof(grpc_grpclb_request))); req->has_client_stats = true; req->client_stats.has_timestamp = true; populate_timestamp(gpr_now(GPR_CLOCK_REALTIME), &req->client_stats.timestamp); @@ -123,8 +123,8 @@ grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked( &req->client_stats.num_calls_finished, &req->client_stats.num_calls_finished_with_client_failed_to_send, &req->client_stats.num_calls_finished_known_received, - reinterpret_cast(&req->client_stats - .calls_finished_with_drop.arg)); + reinterpret_cast( + &req->client_stats.calls_finished_with_drop.arg)); return req; } @@ -148,7 +148,8 @@ grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request) { void grpc_grpclb_request_destroy(grpc_grpclb_request* request) { if (request->has_client_stats) { grpc_grpclb_dropped_call_counts* drop_entries = - static_cast(request->client_stats.calls_finished_with_drop.arg); + static_cast( + request->client_stats.calls_finished_with_drop.arg); grpc_grpclb_dropped_call_counts_destroy(drop_entries); } gpr_free(request); @@ -170,8 +171,8 @@ grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( if (!res.has_initial_response) return nullptr; grpc_grpclb_initial_response* initial_res = - static_cast(gpr_malloc( - sizeof(grpc_grpclb_initial_response))); + static_cast( + gpr_malloc(sizeof(grpc_grpclb_initial_response))); memcpy(initial_res, &res.initial_response, sizeof(grpc_grpclb_initial_response)); @@ -184,8 +185,8 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( pb_istream_from_buffer(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response), GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); pb_istream_t stream_at_start = stream; - grpc_grpclb_serverlist* sl = - static_cast(gpr_zalloc(sizeof(grpc_grpclb_serverlist))); + grpc_grpclb_serverlist* sl = static_cast( + gpr_zalloc(sizeof(grpc_grpclb_serverlist))); grpc_grpclb_response res; memset(&res, 0, sizeof(grpc_grpclb_response)); // First pass: count number of servers. @@ -199,8 +200,8 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( } // Second pass: populate servers. if (sl->num_servers > 0) { - sl->servers = static_cast(gpr_zalloc(sizeof(grpc_grpclb_server*) * - sl->num_servers)); + sl->servers = static_cast( + gpr_zalloc(sizeof(grpc_grpclb_server*) * sl->num_servers)); decode_serverlist_arg decode_arg; memset(&decode_arg, 0, sizeof(decode_arg)); decode_arg.serverlist = sl; @@ -230,14 +231,14 @@ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) { grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy( const grpc_grpclb_serverlist* sl) { - grpc_grpclb_serverlist* copy = - static_cast(gpr_zalloc(sizeof(grpc_grpclb_serverlist))); + grpc_grpclb_serverlist* copy = static_cast( + gpr_zalloc(sizeof(grpc_grpclb_serverlist))); copy->num_servers = sl->num_servers; - copy->servers = static_cast(gpr_malloc(sizeof(grpc_grpclb_server*) * - sl->num_servers)); + copy->servers = static_cast( + gpr_malloc(sizeof(grpc_grpclb_server*) * sl->num_servers)); for (size_t i = 0; i < sl->num_servers; i++) { - copy->servers[i] = - static_cast(gpr_malloc(sizeof(grpc_grpclb_server))); + copy->servers[i] = static_cast( + gpr_malloc(sizeof(grpc_grpclb_server))); memcpy(copy->servers[i], sl->servers[i], sizeof(grpc_grpclb_server)); } return copy; 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 7e957e082c..1485f7caf5 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 @@ -348,7 +348,8 @@ static void pf_update_locked(grpc_lb_policy* policy, static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { grpc_lb_subchannel_data* sd = static_cast(arg); - pick_first_lb_policy* p = reinterpret_cast(sd->subchannel_list->policy); + pick_first_lb_policy* p = + reinterpret_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 @@ -547,7 +548,8 @@ static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* create_pick_first(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); - pick_first_lb_policy* p = static_cast(gpr_zalloc(sizeof(*p))); + pick_first_lb_policy* p = + static_cast(gpr_zalloc(sizeof(*p))); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p); } 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 b0e1c79500..f657a2af10 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 @@ -82,7 +82,8 @@ static size_t get_next_ready_subchannel_index_locked( gpr_log(GPR_INFO, "[RR %p] getting next ready subchannel (out of %lu), " "last_ready_subchannel_index=%lu", - (void*)p, static_cast(p->subchannel_list->num_subchannels), + (void*)p, + static_cast(p->subchannel_list->num_subchannels), static_cast(p->last_ready_subchannel_index)); } for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { @@ -334,7 +335,8 @@ static void update_lb_connectivity_status_locked(grpc_lb_subchannel_data* sd, * subchannel_list->num_subchannels. */ grpc_lb_subchannel_list* subchannel_list = sd->subchannel_list; - round_robin_lb_policy* p = reinterpret_cast(subchannel_list->policy); + round_robin_lb_policy* p = + reinterpret_cast(subchannel_list->policy); GPR_ASSERT(sd->curr_connectivity_state != GRPC_CHANNEL_IDLE); if (subchannel_list->num_ready > 0) { /* 1) READY */ @@ -426,7 +428,8 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { if (grpc_lb_round_robin_trace.enabled()) { const unsigned long num_subchannels = p->subchannel_list != nullptr - ? static_cast(p->subchannel_list->num_subchannels) + ? static_cast( + p->subchannel_list->num_subchannels) : 0; gpr_log(GPR_DEBUG, "[RR %p] phasing out subchannel list %p (size %lu) in favor " @@ -467,7 +470,8 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { "[RR %p] Fulfilling pending pick. Target <-- subchannel %p " "(subchannel_list %p, index %lu)", (void*)p, (void*)selected->subchannel, - (void*)p->subchannel_list, static_cast(next_ready_index)); + (void*)p->subchannel_list, + static_cast(next_ready_index)); } GRPC_CLOSURE_SCHED(pick->on_complete, GRPC_ERROR_NONE); } @@ -537,7 +541,8 @@ static void rr_update_locked(grpc_lb_policy* policy, } return; } - grpc_lb_addresses* addresses = static_cast(arg->value.pointer.p); + grpc_lb_addresses* addresses = + static_cast(arg->value.pointer.p); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] received update with %" PRIuPTR " addresses", p, addresses->num_addresses); @@ -643,7 +648,8 @@ static void round_robin_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* round_robin_create(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); - round_robin_lb_policy* p = static_cast(gpr_zalloc(sizeof(*p))); + round_robin_lb_policy* p = + static_cast(gpr_zalloc(sizeof(*p))); grpc_lb_policy_init(&p->base, &round_robin_lb_policy_vtable, args->combiner); grpc_subchannel_index_ref(); grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc index b671b2ae39..e35c5e8db3 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -60,7 +60,8 @@ void grpc_lb_subchannel_data_start_connectivity_watch( " (subchannel %p): requesting connectivity change " "notification (from %s)", sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, - sd->subchannel_list, static_cast(sd - sd->subchannel_list->subchannels), + sd->subchannel_list, + static_cast(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, grpc_connectivity_state_name(sd->pending_connectivity_state_unsafe)); } @@ -91,7 +92,8 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb) { grpc_lb_subchannel_list* subchannel_list = - static_cast(gpr_zalloc(sizeof(*subchannel_list))); + static_cast( + gpr_zalloc(sizeof(*subchannel_list))); if (tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Creating subchannel list %p for %" PRIuPTR " subchannels", @@ -100,8 +102,8 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( subchannel_list->policy = p; subchannel_list->tracer = tracer; gpr_ref_init(&subchannel_list->refcount, 1); - subchannel_list->subchannels = static_cast(gpr_zalloc( - sizeof(grpc_lb_subchannel_data) * addresses->num_addresses)); + subchannel_list->subchannels = static_cast( + gpr_zalloc(sizeof(grpc_lb_subchannel_data) * addresses->num_addresses)); // We need to remove the LB addresses in order to be able to compare the // subchannel keys of subchannels from a different batch of addresses. static const char* keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS, @@ -190,8 +192,8 @@ void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); gpr_log(GPR_DEBUG, "[%s %p] subchannel_list %p REF %lu->%lu (%s)", subchannel_list->tracer->name(), subchannel_list->policy, - subchannel_list, static_cast(count - 1), static_cast(count), - reason); + subchannel_list, static_cast(count - 1), + static_cast(count), reason); } } @@ -202,8 +204,8 @@ void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); gpr_log(GPR_DEBUG, "[%s %p] subchannel_list %p UNREF %lu->%lu (%s)", subchannel_list->tracer->name(), subchannel_list->policy, - subchannel_list, static_cast(count + 1), static_cast(count), - reason); + subchannel_list, static_cast(count + 1), + static_cast(count), reason); } if (done) { subchannel_list_destroy(subchannel_list); diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.cc b/src/core/ext/filters/client_channel/lb_policy_factory.cc index b9b9e298a5..f2a800b221 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.cc +++ b/src/core/ext/filters/client_channel/lb_policy_factory.cc @@ -33,7 +33,8 @@ grpc_lb_addresses* grpc_lb_addresses_create( addresses->num_addresses = num_addresses; addresses->user_data_vtable = user_data_vtable; const size_t addresses_size = sizeof(grpc_lb_address) * num_addresses; - addresses->addresses = static_cast(gpr_zalloc(addresses_size)); + addresses->addresses = + static_cast(gpr_zalloc(addresses_size)); return addresses; } diff --git a/src/core/ext/filters/client_channel/parse_address.cc b/src/core/ext/filters/client_channel/parse_address.cc index c95560dd82..473c7542df 100644 --- a/src/core/ext/filters/client_channel/parse_address.cc +++ b/src/core/ext/filters/client_channel/parse_address.cc @@ -40,7 +40,8 @@ bool grpc_parse_unix(const grpc_uri* uri, gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme); return false; } - struct sockaddr_un* un = reinterpret_cast(resolved_addr->addr); + struct sockaddr_un* un = + reinterpret_cast(resolved_addr->addr); const size_t maxlen = sizeof(un->sun_path); const size_t path_len = strnlen(uri->path, maxlen); if (path_len == maxlen) return false; diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 9e3a8c891e..0442b1e496 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -312,7 +312,8 @@ void AresDnsResolver::OnResolvedLocked(void* arg, grpc_error* error) { if (lb_policy_name != nullptr) { args_to_remove[num_args_to_remove++] = GRPC_ARG_LB_POLICY_NAME; new_args[num_args_to_add++] = grpc_channel_arg_string_create( - (char*)GRPC_ARG_LB_POLICY_NAME, const_cast(lb_policy_name)); + (char*)GRPC_ARG_LB_POLICY_NAME, + const_cast(lb_policy_name)); } } } 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 3b23b53e60..10bc8f6074 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 @@ -124,7 +124,8 @@ static void fd_node_shutdown(fd_node* fdn) { grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, grpc_pollset_set* pollset_set) { - *ev_driver = static_cast(gpr_malloc(sizeof(grpc_ares_ev_driver))); + *ev_driver = static_cast( + gpr_malloc(sizeof(grpc_ares_ev_driver))); int status = ares_init(&(*ev_driver)->channel); gpr_log(GPR_DEBUG, "grpc_ares_ev_driver_create"); if (status != ARES_SUCCESS) { 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 93f5f44fa6..82b5545601 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 @@ -110,8 +110,8 @@ static void grpc_ares_request_unref(grpc_ares_request* r) { static grpc_ares_hostbyname_request* create_hostbyname_request( grpc_ares_request* parent_request, char* host, uint16_t port, bool is_balancer) { - grpc_ares_hostbyname_request* hr = static_cast(gpr_zalloc( - sizeof(grpc_ares_hostbyname_request))); + grpc_ares_hostbyname_request* hr = static_cast( + gpr_zalloc(sizeof(grpc_ares_hostbyname_request))); hr->parent_request = parent_request; hr->host = gpr_strdup(host); hr->port = port; @@ -128,7 +128,8 @@ static void destroy_hostbyname_request(grpc_ares_hostbyname_request* hr) { static void on_hostbyname_done_cb(void* arg, int status, int timeouts, struct hostent* hostent) { - grpc_ares_hostbyname_request* hr = static_cast(arg); + grpc_ares_hostbyname_request* hr = + static_cast(arg); grpc_ares_request* r = hr->parent_request; gpr_mu_lock(&r->mu); if (status == ARES_SUCCESS) { @@ -144,9 +145,9 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, for (i = 0; hostent->h_addr_list[i] != nullptr; i++) { } (*lb_addresses)->num_addresses += i; - (*lb_addresses)->addresses = static_cast(gpr_realloc( - (*lb_addresses)->addresses, - sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses)); + (*lb_addresses)->addresses = static_cast( + gpr_realloc((*lb_addresses)->addresses, + sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses)); for (i = prev_naddr; i < (*lb_addresses)->num_addresses; i++) { switch (hostent->h_addrtype) { case AF_INET6: { @@ -279,13 +280,15 @@ static void on_txt_done_cb(void* arg, int status, int timeouts, // Found a service config record. if (result != nullptr) { size_t service_config_len = result->length - prefix_len; - *r->service_config_json_out = static_cast(gpr_malloc(service_config_len + 1)); + *r->service_config_json_out = + static_cast(gpr_malloc(service_config_len + 1)); memcpy(*r->service_config_json_out, result->txt + prefix_len, service_config_len); for (result = result->next; result != nullptr && !result->record_start; result = result->next) { - *r->service_config_json_out = static_cast(gpr_realloc( - *r->service_config_json_out, service_config_len + result->length + 1)); + *r->service_config_json_out = static_cast( + gpr_realloc(*r->service_config_json_out, + service_config_len + result->length + 1)); memcpy(*r->service_config_json_out + service_config_len, result->txt, result->length); service_config_len += result->length; @@ -372,7 +375,8 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( } else if (grpc_parse_ipv6_hostport(dns_server, &addr, false /* log_errors */)) { r->dns_server_addr.family = AF_INET6; - struct sockaddr_in6* in6 = reinterpret_cast(addr.addr); + struct sockaddr_in6* in6 = + reinterpret_cast(addr.addr); memcpy(&r->dns_server_addr.addr.addr6, &in6->sin6_addr, sizeof(struct in6_addr)); r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr); @@ -492,11 +496,12 @@ static void on_dns_lookup_done_cb(void* arg, grpc_error* error) { if (r->lb_addrs == nullptr || r->lb_addrs->num_addresses == 0) { *resolved_addresses = nullptr; } else { - *resolved_addresses = - static_cast(gpr_zalloc(sizeof(grpc_resolved_addresses))); + *resolved_addresses = static_cast( + gpr_zalloc(sizeof(grpc_resolved_addresses))); (*resolved_addresses)->naddrs = r->lb_addrs->num_addresses; - (*resolved_addresses)->addrs = static_cast(gpr_zalloc( - sizeof(grpc_resolved_address) * (*resolved_addresses)->naddrs)); + (*resolved_addresses)->addrs = + static_cast(gpr_zalloc( + sizeof(grpc_resolved_address) * (*resolved_addresses)->naddrs)); for (size_t i = 0; i < (*resolved_addresses)->naddrs; i++) { GPR_ASSERT(!r->lb_addrs->addresses[i].is_balancer); memcpy(&(*resolved_addresses)->addrs[i], @@ -514,8 +519,8 @@ static void grpc_resolve_address_ares_impl(const char* name, grpc_closure* on_done, grpc_resolved_addresses** addrs) { grpc_resolve_address_ares_request* r = - static_cast(gpr_zalloc( - sizeof(grpc_resolve_address_ares_request))); + static_cast( + gpr_zalloc(sizeof(grpc_resolve_address_ares_request))); r->addrs_out = addrs; r->on_resolve_address_done = on_done; GRPC_CLOSURE_INIT(&r->on_dns_lookup_done, on_dns_lookup_done_cb, r, diff --git a/src/core/ext/filters/client_channel/retry_throttle.cc b/src/core/ext/filters/client_channel/retry_throttle.cc index d1e0820560..dd33b69102 100644 --- a/src/core/ext/filters/client_channel/retry_throttle.cc +++ b/src/core/ext/filters/client_channel/retry_throttle.cc @@ -60,7 +60,8 @@ bool grpc_server_retry_throttle_data_record_failure( get_replacement_throttle_data_if_needed(&throttle_data); // We decrement milli_tokens by 1000 (1 token) for each failure. const int new_value = static_cast(gpr_atm_no_barrier_clamped_add( - &throttle_data->milli_tokens, static_cast(-1000), static_cast(0), + &throttle_data->milli_tokens, static_cast(-1000), + static_cast(0), static_cast(throttle_data->max_milli_tokens))); // Retries are allowed as long as the new value is above the threshold // (max_milli_tokens / 2). @@ -73,8 +74,10 @@ void grpc_server_retry_throttle_data_record_success( get_replacement_throttle_data_if_needed(&throttle_data); // We increment milli_tokens by milli_token_ratio for each success. gpr_atm_no_barrier_clamped_add( - &throttle_data->milli_tokens, static_cast(throttle_data->milli_token_ratio), - static_cast(0), static_cast(throttle_data->max_milli_tokens)); + &throttle_data->milli_tokens, + static_cast(throttle_data->milli_token_ratio), + static_cast(0), + static_cast(throttle_data->max_milli_tokens)); } grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_ref( @@ -100,7 +103,8 @@ static grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_create( int max_milli_tokens, int milli_token_ratio, grpc_server_retry_throttle_data* old_throttle_data) { grpc_server_retry_throttle_data* throttle_data = - static_cast(gpr_malloc(sizeof(*throttle_data))); + static_cast( + gpr_malloc(sizeof(*throttle_data))); memset(throttle_data, 0, sizeof(*throttle_data)); gpr_ref_init(&throttle_data->refs, 1); throttle_data->max_milli_tokens = max_milli_tokens; @@ -112,7 +116,7 @@ static grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_create( // we will start out doing the same thing on the new one. if (old_throttle_data != nullptr) { double token_fraction = - static_castgpr_atm_acq_load(&old_throttle_data->milli_tokens) / + static_cast gpr_atm_acq_load(&old_throttle_data->milli_tokens) / static_cast(old_throttle_data->max_milli_tokens); initial_milli_tokens = static_cast(token_fraction * max_milli_tokens); } @@ -178,13 +182,14 @@ grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server( const char* server_name, int max_milli_tokens, int milli_token_ratio) { gpr_mu_lock(&g_mu); grpc_server_retry_throttle_data* throttle_data = - static_cast(grpc_avl_get(g_avl, const_cast(server_name), - nullptr)); + static_cast( + grpc_avl_get(g_avl, const_cast(server_name), nullptr)); if (throttle_data == nullptr) { // Entry not found. Create a new one. throttle_data = grpc_server_retry_throttle_data_create( max_milli_tokens, milli_token_ratio, nullptr); - g_avl = grpc_avl_add(g_avl, const_cast(server_name), throttle_data, nullptr); + g_avl = grpc_avl_add(g_avl, const_cast(server_name), throttle_data, + nullptr); } else { if (throttle_data->max_milli_tokens != max_milli_tokens || throttle_data->milli_token_ratio != milli_token_ratio) { @@ -192,7 +197,8 @@ grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server( // the original one. throttle_data = grpc_server_retry_throttle_data_create( max_milli_tokens, milli_token_ratio, throttle_data); - g_avl = grpc_avl_add(g_avl, const_cast(server_name), throttle_data, nullptr); + g_avl = grpc_avl_add(g_avl, const_cast(server_name), throttle_data, + nullptr); } else { // Entry found. Increase refcount. grpc_server_retry_throttle_data_ref(throttle_data); diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 55b11b89d9..179e3f27ac 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -241,8 +241,9 @@ static void disconnect(grpc_subchannel* c) { void grpc_subchannel_unref(grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; // add a weak ref and subtract a strong ref (atomically) - old_refs = ref_mutate(c, static_cast(1) - static_cast(1 << INTERNAL_REF_BITS), - 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); + old_refs = ref_mutate( + c, static_cast(1) - static_cast(1 << INTERNAL_REF_BITS), + 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) { disconnect(c); } @@ -252,7 +253,8 @@ void grpc_subchannel_unref(grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { void grpc_subchannel_weak_unref( grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; - old_refs = ref_mutate(c, -static_cast(1), 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); + old_refs = ref_mutate(c, -static_cast(1), + 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); if (old_refs == 1) { GRPC_CLOSURE_SCHED( GRPC_CLOSURE_CREATE(subchannel_destroy, c, grpc_schedule_on_exec_ctx), @@ -325,8 +327,8 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, grpc_connector_ref(c->connector); c->num_filters = args->filter_count; if (c->num_filters > 0) { - c->filters = static_cast(gpr_malloc( - sizeof(grpc_channel_filter*) * c->num_filters)); + c->filters = static_cast( + gpr_malloc(sizeof(grpc_channel_filter*) * c->num_filters)); memcpy((void*)c->filters, args->filters, sizeof(grpc_channel_filter*) * c->num_filters); } else { @@ -570,7 +572,8 @@ static bool publish_transport_locked(grpc_subchannel* c) { } grpc_channel_stack* stk; grpc_error* error = grpc_channel_stack_builder_finish( - builder, 0, 1, connection_destroy, nullptr, reinterpret_cast(&stk)); + builder, 0, 1, connection_destroy, nullptr, + reinterpret_cast(&stk)); if (error != GRPC_ERROR_NONE) { grpc_transport_destroy(c->connecting_result.transport); gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", @@ -581,8 +584,8 @@ static bool publish_transport_locked(grpc_subchannel* c) { memset(&c->connecting_result, 0, sizeof(c->connecting_result)); /* initialize state watcher */ - state_watcher* connected_subchannel_watcher = - static_cast(gpr_zalloc(sizeof(*connected_subchannel_watcher))); + state_watcher* connected_subchannel_watcher = static_cast( + gpr_zalloc(sizeof(*connected_subchannel_watcher))); connected_subchannel_watcher->subchannel = c; connected_subchannel_watcher->connectivity_state = GRPC_CHANNEL_READY; GRPC_CLOSURE_INIT(&connected_subchannel_watcher->closure, diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index 2deafb380b..d1dc5ee970 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -45,13 +45,14 @@ static bool g_force_creation = false; static grpc_subchannel_key* create_key( const grpc_subchannel_args* args, grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args)) { - grpc_subchannel_key* k = static_cast(gpr_malloc(sizeof(*k))); + grpc_subchannel_key* k = + static_cast(gpr_malloc(sizeof(*k))); k->args.filter_count = args->filter_count; if (k->args.filter_count > 0) { - k->args.filters = static_cast(gpr_malloc( - sizeof(*k->args.filters) * k->args.filter_count)); - memcpy(reinterpret_cast(k->args.filters), args->filters, - sizeof(*k->args.filters) * k->args.filter_count); + k->args.filters = static_cast( + gpr_malloc(sizeof(*k->args.filters) * k->args.filter_count)); + memcpy(reinterpret_cast(k->args.filters), + args->filters, sizeof(*k->args.filters) * k->args.filter_count); } else { k->args.filters = nullptr; } @@ -170,7 +171,8 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = static_cast(grpc_avl_get(index, key, grpc_core::ExecCtx::Get())); + c = static_cast( + grpc_avl_get(index, key, grpc_core::ExecCtx::Get())); if (c != nullptr) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -220,8 +222,8 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, // Check to see if this key still refers to the previously // registered subchannel - grpc_subchannel* c = - static_cast(grpc_avl_get(index, key, grpc_core::ExecCtx::Get())); + grpc_subchannel* c = static_cast( + grpc_avl_get(index, key, grpc_core::ExecCtx::Get())); if (c != constructed) { grpc_avl_unref(index, grpc_core::ExecCtx::Get()); break; diff --git a/src/core/ext/filters/deadline/deadline_filter.cc b/src/core/ext/filters/deadline/deadline_filter.cc index a936d17e8d..76c1204090 100644 --- a/src/core/ext/filters/deadline/deadline_filter.cc +++ b/src/core/ext/filters/deadline/deadline_filter.cc @@ -47,7 +47,8 @@ static void yield_call_combiner(void* arg, grpc_error* ignored) { // synchronized. static void send_cancel_op_in_call_combiner(void* arg, grpc_error* error) { grpc_call_element* elem = static_cast(arg); - grpc_deadline_state* deadline_state = static_cast(elem->call_data); + grpc_deadline_state* deadline_state = + static_cast(elem->call_data); grpc_transport_stream_op_batch* batch = grpc_make_transport_stream_op( GRPC_CLOSURE_INIT(&deadline_state->timer_callback, yield_call_combiner, deadline_state, grpc_schedule_on_exec_ctx)); @@ -59,7 +60,8 @@ static void send_cancel_op_in_call_combiner(void* arg, grpc_error* error) { // Timer callback. static void timer_callback(void* arg, grpc_error* error) { grpc_call_element* elem = static_cast(arg); - grpc_deadline_state* deadline_state = static_cast(elem->call_data); + grpc_deadline_state* deadline_state = + static_cast(elem->call_data); if (error != GRPC_ERROR_CANCELLED) { error = grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Deadline Exceeded"), @@ -85,7 +87,8 @@ static void start_timer_if_needed(grpc_call_element* elem, if (deadline == GRPC_MILLIS_INF_FUTURE) { return; } - grpc_deadline_state* deadline_state = static_cast(elem->call_data); + grpc_deadline_state* deadline_state = + static_cast(elem->call_data); grpc_closure* closure = nullptr; switch (deadline_state->timer_state) { case GRPC_DEADLINE_STATE_PENDING: @@ -173,7 +176,8 @@ void grpc_deadline_state_init(grpc_call_element* elem, grpc_call_stack* call_stack, grpc_call_combiner* call_combiner, grpc_millis deadline) { - grpc_deadline_state* deadline_state = static_cast(elem->call_data); + grpc_deadline_state* deadline_state = + static_cast(elem->call_data); deadline_state->call_stack = call_stack; deadline_state->call_combiner = call_combiner; // Deadline will always be infinite on servers, so the timer will only be @@ -187,7 +191,8 @@ void grpc_deadline_state_init(grpc_call_element* elem, // create a closure to start the timer, and we schedule that closure // to be run after call stack initialization is done. struct start_timer_after_init_state* state = - static_cast(gpr_zalloc(sizeof(*state))); + static_cast( + gpr_zalloc(sizeof(*state))); state->elem = elem; state->deadline = deadline; GRPC_CLOSURE_INIT(&state->closure, start_timer_after_init, state, @@ -197,20 +202,23 @@ void grpc_deadline_state_init(grpc_call_element* elem, } void grpc_deadline_state_destroy(grpc_call_element* elem) { - grpc_deadline_state* deadline_state = static_cast(elem->call_data); + grpc_deadline_state* deadline_state = + static_cast(elem->call_data); cancel_timer_if_needed(deadline_state); } void grpc_deadline_state_reset(grpc_call_element* elem, grpc_millis new_deadline) { - grpc_deadline_state* deadline_state = static_cast(elem->call_data); + grpc_deadline_state* deadline_state = + static_cast(elem->call_data); cancel_timer_if_needed(deadline_state); start_timer_if_needed(elem, new_deadline); } void grpc_deadline_state_client_start_transport_stream_op_batch( grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - grpc_deadline_state* deadline_state = static_cast(elem->call_data); + grpc_deadline_state* deadline_state = + static_cast(elem->call_data); if (op->cancel_stream) { cancel_timer_if_needed(deadline_state); } else { @@ -360,7 +368,8 @@ static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder, return grpc_deadline_checking_enabled( grpc_channel_stack_builder_get_channel_arguments(builder)) ? grpc_channel_stack_builder_prepend_filter( - builder, static_cast(arg), nullptr, nullptr) + builder, static_cast(arg), + nullptr, nullptr) : true; } diff --git a/src/core/ext/filters/http/client/http_client_filter.cc b/src/core/ext/filters/http/client/http_client_filter.cc index aabc405bec..80643f8584 100644 --- a/src/core/ext/filters/http/client/http_client_filter.cc +++ b/src/core/ext/filters/http/client/http_client_filter.cc @@ -189,7 +189,8 @@ static grpc_error* pull_slice_from_send_message(call_data* calld) { // and on_send_message_next_done() will be invoked when it is complete. static grpc_error* read_all_available_send_message_data(call_data* calld) { while (grpc_byte_stream_next(&calld->send_message_caching_stream.base, - ~static_cast(0), &calld->on_send_message_next_done)) { + ~static_cast(0), + &calld->on_send_message_next_done)) { grpc_error* error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) return error; if (calld->send_message_bytes_read == @@ -224,7 +225,8 @@ static void on_send_message_next_done(void* arg, grpc_error* error) { } static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { - char* payload_bytes = static_cast(gpr_malloc(slice_buffer->length + 1)); + char* payload_bytes = + static_cast(gpr_malloc(slice_buffer->length + 1)); size_t offset = 0; for (size_t i = 0; i < slice_buffer->count; ++i) { memcpy(payload_bytes + offset, @@ -253,8 +255,10 @@ static grpc_error* update_path_for_get(grpc_call_element* elem, false /* multi_line */); grpc_slice path_with_query_slice = GRPC_SLICE_MALLOC(estimated_len); /* memcopy individual pieces into this slice */ - char* write_ptr = reinterpret_castGRPC_SLICE_START_PTR(path_with_query_slice); - char* original_path = reinterpret_castGRPC_SLICE_START_PTR(path_slice); + char* write_ptr = + reinterpret_cast GRPC_SLICE_START_PTR(path_with_query_slice); + char* original_path = + reinterpret_cast GRPC_SLICE_START_PTR(path_slice); memcpy(write_ptr, original_path, GRPC_SLICE_LENGTH(path_slice)); write_ptr += GRPC_SLICE_LENGTH(path_slice); *write_ptr++ = '?'; @@ -265,7 +269,7 @@ static grpc_error* update_path_for_get(grpc_call_element* elem, true /* url_safe */, false /* multi_line */); gpr_free(payload_bytes); /* remove trailing unused memory and add trailing 0 to terminate string */ - char* t = reinterpret_castGRPC_SLICE_START_PTR(path_with_query_slice); + char* t = reinterpret_cast GRPC_SLICE_START_PTR(path_with_query_slice); /* safe to use strlen since base64_encode will always add '\0' */ path_with_query_slice = grpc_slice_sub_no_ref(path_with_query_slice, 0, strlen(t)); diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index b89cb028ea..56fe1e5c24 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -58,7 +58,8 @@ static bool maybe_add_required_filter(grpc_channel_stack_builder* builder, void* arg) { return is_building_http_like_transport(builder) ? grpc_channel_stack_builder_prepend_filter( - builder, static_cast(arg), nullptr, nullptr) + builder, static_cast(arg), + nullptr, nullptr) : true; } diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index 223548d3bf..73220a0ea1 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -226,7 +226,8 @@ static void finish_send_message(grpc_call_element* elem) { const char* algo_name; const size_t before_size = calld->slices.length; const size_t after_size = tmp.length; - const float savings_ratio = 1.0f - static_cast(after_size) / static_cast(before_size); + const float savings_ratio = 1.0f - static_cast(after_size) / + static_cast(before_size); GPR_ASSERT(grpc_message_compression_algorithm_name( calld->message_compression_algorithm, &algo_name)); gpr_log(GPR_DEBUG, @@ -291,8 +292,8 @@ static grpc_error* pull_slice_from_send_message(call_data* calld) { static void continue_reading_send_message(grpc_call_element* elem) { call_data* calld = static_cast(elem->call_data); while (grpc_byte_stream_next( - calld->send_message_batch->payload->send_message.send_message, ~static_cast(0), - &calld->on_send_message_next_done)) { + calld->send_message_batch->payload->send_message.send_message, + ~static_cast(0), &calld->on_send_message_next_done)) { grpc_error* error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. diff --git a/src/core/ext/filters/http/server/http_server_filter.cc b/src/core/ext/filters/http/server/http_server_filter.cc index 560b5795e3..63bc2bd59f 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -224,10 +224,11 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, /* decode payload from query and add to the slice buffer to be returned */ const int k_url_safe = 1; - grpc_slice_buffer_add(&calld->read_slice_buffer, - grpc_base64_decode_with_len( - reinterpret_castGRPC_SLICE_START_PTR(query_slice), - GRPC_SLICE_LENGTH(query_slice), k_url_safe)); + grpc_slice_buffer_add( + &calld->read_slice_buffer, + grpc_base64_decode_with_len( + reinterpret_cast GRPC_SLICE_START_PTR(query_slice), + GRPC_SLICE_LENGTH(query_slice), k_url_safe)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); calld->seen_path_with_query = true; @@ -277,9 +278,10 @@ static void hs_on_complete(void* user_data, grpc_error* err) { call_data* calld = static_cast(elem->call_data); /* Call recv_message_ready if we got the payload via the path field */ if (calld->seen_path_with_query && calld->recv_message_ready != nullptr) { - *calld->pp_recv_message = calld->payload_bin_delivered - ? nullptr - : reinterpret_cast(&calld->read_stream); + *calld->pp_recv_message = + calld->payload_bin_delivered + ? nullptr + : reinterpret_cast(&calld->read_stream); // Re-enter call combiner for recv_message_ready, since the surface // code will release the call combiner for each callback it receives. GRPC_CALL_COMBINER_START(calld->call_combiner, calld->recv_message_ready, diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc index 4255a77ea0..667c0c56ef 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc @@ -41,7 +41,8 @@ static bool maybe_add_server_load_reporting_filter( grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); - const grpc_channel_filter* filter = static_cast(arg); + const grpc_channel_filter* filter = + static_cast(arg); grpc_channel_stack_builder_iterator* it = grpc_channel_stack_builder_iterator_find(builder, filter->name); const bool already_has_load_reporting_filter = diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index ba41e4674b..415a90959d 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -285,7 +285,7 @@ static void max_idle_timer_cb(void* arg, grpc_error* error) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer"); grpc_timer_init(&chand->max_idle_timer, - static_castgpr_atm_no_barrier_load( + static_cast gpr_atm_no_barrier_load( &chand->last_enter_idle_time_millis) + chand->max_connection_idle, &chand->max_idle_timer_cb); @@ -384,7 +384,7 @@ add_random_max_connection_age_jitter_and_convert_to_grpc_millis(int value) { double result = multiplier * value; /* INT_MAX - 0.5 converts the value to float, so that result will not be cast to int implicitly before the comparison. */ - return result > (static_castGRPC_MILLIS_INF_FUTURE) - 0.5 + return result > (static_cast GRPC_MILLIS_INF_FUTURE) - 0.5 ? GRPC_MILLIS_INF_FUTURE : static_cast(result); } 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 a2406a24dd..49d9ae60ae 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -78,8 +78,8 @@ static void* refcounted_message_size_limits_create_from_json( } } refcounted_message_size_limits* value = - static_cast(gpr_malloc( - sizeof(refcounted_message_size_limits))); + static_cast( + gpr_malloc(sizeof(refcounted_message_size_limits))); gpr_ref_init(&value->refs, 1); value->limits.max_send_size = max_request_message_bytes; value->limits.max_recv_size = max_response_message_bytes; @@ -113,7 +113,8 @@ static void recv_message_ready(void* user_data, grpc_error* error) { grpc_call_element* elem = static_cast(user_data); call_data* calld = static_cast(elem->call_data); if (*calld->recv_message != nullptr && calld->limits.max_recv_size >= 0 && - (*calld->recv_message)->length > static_cast(calld->limits.max_recv_size)) { + (*calld->recv_message)->length > + static_cast(calld->limits.max_recv_size)) { char* message_string; gpr_asprintf(&message_string, "Received message larger than max (%u vs. %d)", @@ -183,8 +184,9 @@ static grpc_error* init_call_elem(grpc_call_element* elem, calld->limits = chand->limits; if (chand->method_limit_table != nullptr) { refcounted_message_size_limits* limits = - static_cast(grpc_method_config_table_get( - chand->method_limit_table, args->path)); + static_cast( + grpc_method_config_table_get(chand->method_limit_table, + args->path)); if (limits != nullptr) { if (limits->limits.max_send_size >= 0 && (limits->limits.max_send_size < calld->limits.max_send_size || diff --git a/src/core/ext/filters/workarounds/workaround_utils.cc b/src/core/ext/filters/workarounds/workaround_utils.cc index b94c7536d0..850ed75ec9 100644 --- a/src/core/ext/filters/workarounds/workaround_utils.cc +++ b/src/core/ext/filters/workarounds/workaround_utils.cc @@ -27,14 +27,14 @@ static void destroy_user_agent_md(void* user_agent_md) { grpc_workaround_user_agent_md* grpc_parse_user_agent(grpc_mdelem md) { grpc_workaround_user_agent_md* user_agent_md = - static_cast(grpc_mdelem_get_user_data( - md, destroy_user_agent_md)); + static_cast( + grpc_mdelem_get_user_data(md, destroy_user_agent_md)); if (nullptr != user_agent_md) { return user_agent_md; } - user_agent_md = static_cast(gpr_malloc( - sizeof(grpc_workaround_user_agent_md))); + user_agent_md = static_cast( + gpr_malloc(sizeof(grpc_workaround_user_agent_md))); for (int i = 0; i < GRPC_MAX_WORKAROUND_ID; i++) { if (ua_parser[i]) { user_agent_md->workaround_active[i] = ua_parser[i](md); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index 322fcb23e1..8c4025ed13 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -86,8 +86,8 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( if (target_uri->path[0] != '\0') { // "path" may be empty const grpc_slice key = grpc_slice_from_static_string( target_uri->path[0] == '/' ? target_uri->path + 1 : target_uri->path); - const char* value = - static_cast(grpc_slice_hash_table_get(targets_info, key)); + const char* value = static_cast( + grpc_slice_hash_table_get(targets_info, key)); if (value != nullptr) target_name_to_check = gpr_strdup(value); grpc_slice_unref_internal(key); } @@ -148,7 +148,8 @@ static grpc_subchannel* client_channel_factory_create_subchannel( grpc_connector* connector = grpc_chttp2_connector_create(); grpc_subchannel* s = grpc_subchannel_create(connector, subchannel_args); grpc_connector_unref(connector); - grpc_channel_args_destroy(const_cast(subchannel_args->args)); + grpc_channel_args_destroy( + const_cast(subchannel_args->args)); gpr_free(subchannel_args); return s; } diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index c1e7946f5f..90b2ee1af9 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -79,7 +79,8 @@ static void server_connection_state_unref( } static void on_timeout(void* arg, grpc_error* error) { - server_connection_state* connection_state = static_cast(arg); + server_connection_state* connection_state = + static_cast(arg); // Note that we may be called with GRPC_ERROR_NONE when the timer fires // or with an error indicating that the timer system is being shut down. if (error != GRPC_ERROR_CANCELLED) { @@ -92,7 +93,8 @@ static void on_timeout(void* arg, grpc_error* error) { } static void on_receive_settings(void* arg, grpc_error* error) { - server_connection_state* connection_state = static_cast(arg); + server_connection_state* connection_state = + static_cast(arg); if (error == GRPC_ERROR_NONE) { grpc_timer_cancel(&connection_state->timer); } @@ -132,7 +134,8 @@ static void on_handshake_done(void* arg, grpc_error* error) { connection_state->accepting_pollset, args->args); // Use notify_on_receive_settings callback to enforce the // handshake deadline. - connection_state->transport = reinterpret_cast(transport); + connection_state->transport = + reinterpret_cast(transport); gpr_ref(&connection_state->refs); GRPC_CLOSURE_INIT(&connection_state->on_receive_settings, on_receive_settings, connection_state, @@ -177,7 +180,8 @@ static void on_accept(void* arg, grpc_endpoint* tcp, gpr_mu_unlock(&state->mu); grpc_tcp_server_ref(state->tcp_server); server_connection_state* connection_state = - static_cast(gpr_zalloc(sizeof(*connection_state))); + static_cast( + gpr_zalloc(sizeof(*connection_state))); gpr_ref_init(&connection_state->refs, 1); connection_state->svr_state = state; connection_state->accepting_pollset = accepting_pollset; diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 0e5e4d0535..91980e6974 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -192,11 +192,12 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, } if (output_length > input_length / 4 * 3 + tail_xtra[input_length % 4]) { - gpr_log(GPR_ERROR, - "Base64 decoding failed, output_length %d is longer " - "than the max possible output length %d.\n", - static_cast(output_length), - static_cast(input_length / 4 * 3 + tail_xtra[input_length % 4])); + gpr_log( + GPR_ERROR, + "Base64 decoding failed, output_length %d is longer " + "than the max possible output length %d.\n", + static_cast(output_length), + static_cast(input_length / 4 * 3 + tail_xtra[input_length % 4])); grpc_slice_unref_internal(output); return grpc_empty_slice(); } diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.cc b/src/core/ext/transport/chttp2/transport/bin_encoder.cc index d9c095ede7..e3b8adbe73 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -53,7 +53,7 @@ grpc_slice grpc_chttp2_base64_encode(grpc_slice input) { size_t output_length = input_triplets * 4 + tail_xtra[tail_case]; grpc_slice output = GRPC_SLICE_MALLOC(output_length); uint8_t* in = GRPC_SLICE_START_PTR(input); - char* out = reinterpret_castGRPC_SLICE_START_PTR(output); + char* out = reinterpret_cast GRPC_SLICE_START_PTR(output); size_t i; /* encode full triplets */ @@ -124,8 +124,9 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) { * expanded form due to the "integral promotion" performed (see section * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type * is then required to avoid the compiler warning */ - *out++ = static_cast(static_cast(temp << (8u - temp_length)) | - static_cast(0xffu >> temp_length)); + *out++ = + static_cast(static_cast(temp << (8u - temp_length)) | + static_cast(0xffu >> temp_length)); } GPR_ASSERT(out == GRPC_SLICE_END_PTR(output)); @@ -151,7 +152,8 @@ static void enc_add2(huff_out* out, uint8_t a, uint8_t b) { b64_huff_sym sb = huff_alphabet[b]; out->temp = (out->temp << (sa.length + sb.length)) | (static_cast(sa.bits) << sb.length) | sb.bits; - out->temp_length += static_cast(sa.length) + static_cast(sb.length); + out->temp_length += + static_cast(sa.length) + static_cast(sb.length); enc_flush_some(out); } @@ -214,8 +216,9 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { * expanded form due to the "integral promotion" performed (see section * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type * is then required to avoid the compiler warning */ - *out.out++ = static_cast(static_cast(out.temp << (8u - out.temp_length)) | - static_cast(0xffu >> out.temp_length)); + *out.out++ = static_cast( + static_cast(out.temp << (8u - out.temp_length)) | + static_cast(0xffu >> out.temp_length)); } GPR_ASSERT(out.out <= GRPC_SLICE_END_PTR(output)); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index ec5431bb00..ad8da94cb3 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -387,8 +387,8 @@ static void init_transport(grpc_chttp2_transport* t, const int value = grpc_channel_arg_get_integer(&channel_args->args[i], options); if (value >= 0) { - grpc_chttp2_hpack_compressor_set_max_usable_size(&t->hpack_compressor, - static_cast(value)); + grpc_chttp2_hpack_compressor_set_max_usable_size( + &t->hpack_compressor, static_cast(value)); } } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) { @@ -421,8 +421,9 @@ static void init_transport(grpc_chttp2_transport* t, INT_MAX}); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) { - t->write_buffer_size = static_cast(grpc_channel_arg_get_integer( - &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE})); + t->write_buffer_size = + static_cast(grpc_channel_arg_get_integer( + &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE})); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_BDP_PROBE)) { enable_bdp = grpc_channel_arg_get_bool(&channel_args->args[i], true); @@ -447,9 +448,8 @@ static void init_transport(grpc_chttp2_transport* t, value == INT_MAX ? GRPC_MILLIS_INF_FUTURE : value; } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) { - t->keepalive_permit_without_calls = - static_cast(grpc_channel_arg_get_integer(&channel_args->args[i], - {0, 0, 1})); + t->keepalive_permit_without_calls = static_cast( + grpc_channel_arg_get_integer(&channel_args->args[i], {0, 0, 1})); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_OPTIMIZATION_TARGET)) { if (channel_args->args[i].type != GRPC_ARG_STRING) { @@ -498,7 +498,7 @@ static void init_transport(grpc_chttp2_transport* t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, {-1, 5, INT32_MAX}, {true, true}}}; - for (j = 0; j < static_castGPR_ARRAY_SIZE(settings_map); j++) { + for (j = 0; j < static_cast GPR_ARRAY_SIZE(settings_map); j++) { if (0 == strcmp(channel_args->args[i].key, settings_map[j].channel_arg_name)) { if (!settings_map[j].availability[is_client]) { @@ -774,7 +774,8 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, uint32_t id) { - return static_cast(grpc_chttp2_stream_map_find(&t->stream_map, id)); + return static_cast( + grpc_chttp2_stream_map_find(&t->stream_map, id)); } grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, @@ -786,7 +787,8 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data, - &t->base, (void*)static_cast(id)); + &t->base, + (void*)static_cast(id)); t->accepting_stream = nullptr; return accepting; } @@ -1100,7 +1102,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, current_keepalive_time_ms > INT_MAX / KEEPALIVE_TIME_BACKOFF_MULTIPLIER ? GRPC_MILLIS_INF_FUTURE : static_cast(current_keepalive_time_ms * - KEEPALIVE_TIME_BACKOFF_MULTIPLIER); + KEEPALIVE_TIME_BACKOFF_MULTIPLIER); } /* lie: use transient failure from the transport to indicate goaway has been @@ -1189,9 +1191,11 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, "complete_closure_step: t=%p %p refs=%d flags=0x%04x desc=%s err=%s " "write_state=%s", t, closure, - static_cast(closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT), - static_cast(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT), desc, - errstr, write_state_name(t->write_state)); + static_cast(closure->next_data.scratch / + CLOSURE_BARRIER_FIRST_REF_BIT), + static_cast(closure->next_data.scratch % + CLOSURE_BARRIER_FIRST_REF_BIT), + desc, errstr, write_state_name(t->write_state)); } if (error != GRPC_ERROR_NONE) { if (closure->error_data.error == GRPC_ERROR_NONE) { @@ -1239,7 +1243,7 @@ static void maybe_become_writable_due_to_send_msg(grpc_chttp2_transport* t, static void add_fetched_slice_locked(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { s->fetched_send_message_length += - static_castGRPC_SLICE_LENGTH(s->fetching_slice); + static_cast GRPC_SLICE_LENGTH(s->fetching_slice); grpc_slice_buffer_add(&s->flow_controlled_buffer, s->fetching_slice); maybe_become_writable_due_to_send_msg(t, s); } @@ -1329,7 +1333,8 @@ static void perform_stream_op_locked(void* stream_op, grpc_transport_stream_op_batch* op = static_cast(stream_op); - grpc_chttp2_stream* s = static_cast(op->handler_private.extra_arg); + grpc_chttp2_stream* s = + static_cast(op->handler_private.extra_arg); grpc_transport_stream_op_batch_payload* op_payload = op->payload; grpc_chttp2_transport* t = s->t; @@ -1409,7 +1414,8 @@ static void perform_stream_op_locked(void* stream_op, "exceeds peer limit"), GRPC_ERROR_INT_SIZE, static_cast(metadata_size)), - GRPC_ERROR_INT_LIMIT, static_cast(metadata_peer_limit)), + GRPC_ERROR_INT_LIMIT, + static_cast(metadata_peer_limit)), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); } else { if (contains_non_ok_status(s->send_initial_metadata)) { @@ -1488,9 +1494,10 @@ static void perform_stream_op_locked(void* stream_op, frame_hdr[4] = static_cast(len); s->fetching_send_message = op_payload->send_message.send_message; s->fetched_send_message_length = 0; - s->next_message_end_offset = s->flow_controlled_bytes_written + - static_cast(s->flow_controlled_buffer.length) + - static_cast(len); + s->next_message_end_offset = + s->flow_controlled_bytes_written + + static_cast(s->flow_controlled_buffer.length) + + static_cast(len); if (flags & GRPC_WRITE_BUFFER_HINT) { s->next_message_end_offset -= t->write_buffer_size; s->write_buffering = true; @@ -1525,7 +1532,8 @@ static void perform_stream_op_locked(void* stream_op, "exceeds peer limit"), GRPC_ERROR_INT_SIZE, static_cast(metadata_size)), - GRPC_ERROR_INT_LIMIT, static_cast(metadata_peer_limit)), + GRPC_ERROR_INT_LIMIT, + static_cast(metadata_peer_limit)), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); } else { if (contains_non_ok_status(s->send_trailing_metadata)) { @@ -1690,7 +1698,8 @@ static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) { grpc_slice slice; grpc_error_get_status(error, GRPC_MILLIS_INF_FUTURE, nullptr, &slice, &http_error, nullptr); - grpc_chttp2_goaway_append(t->last_new_stream_id, static_cast(http_error), + grpc_chttp2_goaway_append(t->last_new_stream_id, + static_cast(http_error), grpc_slice_ref_internal(slice), &t->qbuf); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT); GRPC_ERROR_UNREF(error); @@ -1925,8 +1934,8 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, static void remove_stream(grpc_chttp2_transport* t, uint32_t id, grpc_error* error) { - grpc_chttp2_stream* s = - static_cast(grpc_chttp2_stream_map_delete(&t->stream_map, id)); + grpc_chttp2_stream* s = static_cast( + grpc_chttp2_stream_map_delete(&t->stream_map, id)); GPR_ASSERT(s); if (t->incoming_stream == s) { t->incoming_stream = nullptr; @@ -1978,8 +1987,9 @@ void grpc_chttp2_cancel_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error_get_status(due_to_error, s->deadline, nullptr, nullptr, &http_error, nullptr); grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, static_cast(http_error), - &s->stats.outgoing)); + &t->qbuf, + grpc_chttp2_rst_stream_create( + s->id, static_cast(http_error), &s->stats.outgoing)); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); } } @@ -2180,7 +2190,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = '0'; *p++ = '0'; GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr)); - len += static_castGRPC_SLICE_LENGTH(http_status_hdr); + len += static_cast GRPC_SLICE_LENGTH(http_status_hdr); content_type_hdr = GRPC_SLICE_MALLOC(31); p = GRPC_SLICE_START_PTR(content_type_hdr); @@ -2216,7 +2226,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = 'p'; *p++ = 'c'; GPR_ASSERT(p == GRPC_SLICE_END_PTR(content_type_hdr)); - len += static_castGRPC_SLICE_LENGTH(content_type_hdr); + len += static_cast GRPC_SLICE_LENGTH(content_type_hdr); } status_hdr = GRPC_SLICE_MALLOC(15 + (grpc_status >= 10)); @@ -2243,7 +2253,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = static_cast('0' + (grpc_status % 10)); } GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); - len += static_castGRPC_SLICE_LENGTH(status_hdr); + len += static_cast GRPC_SLICE_LENGTH(status_hdr); size_t msg_len = GRPC_SLICE_LENGTH(slice); GPR_ASSERT(msg_len <= UINT32_MAX); @@ -2267,7 +2277,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 1, 0, p, (uint32_t)msg_len_len); p += msg_len_len; GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); - len += static_castGRPC_SLICE_LENGTH(message_pfx); + len += static_cast GRPC_SLICE_LENGTH(message_pfx); len += static_cast(msg_len); hdr = GRPC_SLICE_MALLOC(9); @@ -2411,7 +2421,7 @@ static void read_action_locked(void* tp, grpc_error* error) { grpc_core::BdpEstimator* bdp_est = t->flow_control->bdp_estimator(); if (bdp_est) { bdp_est->AddIncomingBytes( - static_castGRPC_SLICE_LENGTH(t->read_buffer.slices[i])); + static_cast GRPC_SLICE_LENGTH(t->read_buffer.slices[i])); } errors[1] = grpc_chttp2_perform_read(t, t->read_buffer.slices[i]); } @@ -2876,7 +2886,7 @@ grpc_error* grpc_chttp2_incoming_byte_stream_push( grpc_slice_unref_internal(slice); return error; } else { - bs->remaining_bytes -= static_castGRPC_SLICE_LENGTH(slice); + bs->remaining_bytes -= static_cast GRPC_SLICE_LENGTH(slice); if (slice_out != nullptr) { *slice_out = slice; } @@ -2931,8 +2941,8 @@ grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, uint32_t flags) { grpc_chttp2_incoming_byte_stream* incoming_byte_stream = - static_cast(gpr_malloc( - sizeof(*incoming_byte_stream))); + static_cast( + gpr_malloc(sizeof(*incoming_byte_stream))); incoming_byte_stream->base.length = frame_size; incoming_byte_stream->remaining_bytes = frame_size; incoming_byte_stream->base.flags = flags; @@ -3000,8 +3010,8 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) { size_t n = grpc_chttp2_stream_map_size(&t->stream_map); t->destructive_reclaimer_registered = false; if (error == GRPC_ERROR_NONE && n > 0) { - grpc_chttp2_stream* s = - static_cast(grpc_chttp2_stream_map_rand(&t->stream_map)); + grpc_chttp2_stream* s = static_cast( + grpc_chttp2_stream_map_rand(&t->stream_map)); if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "HTTP2: %s - abandon stream id %d", t->peer_string, s->id); @@ -3096,8 +3106,8 @@ static const grpc_transport_vtable* get_vtable(void) { return &vtable; } grpc_transport* grpc_create_chttp2_transport( const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) { - grpc_chttp2_transport* t = - static_cast(gpr_zalloc(sizeof(grpc_chttp2_transport))); + grpc_chttp2_transport* t = static_cast( + gpr_zalloc(sizeof(grpc_chttp2_transport))); init_transport(t, channel_args, ep, is_client); return &t->base; } @@ -3105,7 +3115,8 @@ grpc_transport* grpc_create_chttp2_transport( void grpc_chttp2_transport_start_reading( grpc_transport* transport, grpc_slice_buffer* read_buffer, grpc_closure* notify_on_receive_settings) { - grpc_chttp2_transport* t = reinterpret_cast(transport); + grpc_chttp2_transport* t = + reinterpret_cast(transport); GRPC_CHTTP2_REF_TRANSPORT( t, "reading_action"); /* matches unref inside reading_action */ if (read_buffer != nullptr) { diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index e9014d8234..45b6f97b05 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -184,10 +184,11 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t, uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) { FlowControlTrace trace("t updt sent", this, nullptr); - const uint32_t target_announced_window = static_cast(target_window()); + const uint32_t target_announced_window = + static_cast(target_window()); if ((writing_anyway || announced_window_ <= target_announced_window / 2) && announced_window_ != target_announced_window) { - const uint32_t announce = static_castGPR_CLAMP( + const uint32_t announce = static_cast GPR_CLAMP( target_announced_window - announced_window_, 0, UINT32_MAX); announced_window_ += announce; return announce; @@ -261,7 +262,7 @@ grpc_error* StreamFlowControl::RecvData(int64_t incoming_frame_size) { uint32_t StreamFlowControl::MaybeSendUpdate() { FlowControlTrace trace("s updt sent", tfc_, this); if (local_window_delta_ > announced_window_delta_) { - uint32_t announce = static_castGPR_CLAMP( + uint32_t announce = static_cast GPR_CLAMP( local_window_delta_ - announced_window_delta_, 0, UINT32_MAX); UpdateAnnouncedWindowDelta(tfc_, announce); return announce; @@ -337,8 +338,8 @@ double TransportFlowControl::SmoothLogBdp(double value) { FlowControlAction::Urgency TransportFlowControl::DeltaUrgency( int64_t value, grpc_chttp2_setting_id setting_id) { - int64_t delta = - value - static_cast(t_->settings[GRPC_LOCAL_SETTINGS][setting_id]); + int64_t delta = value - static_cast( + t_->settings[GRPC_LOCAL_SETTINGS][setting_id]); // TODO(ncteisen): tune this if (delta != 0 && (delta <= -value / 5 || delta >= value / 5)) { return FlowControlAction::Urgency::QUEUE_UPDATE; @@ -357,7 +358,8 @@ FlowControlAction TransportFlowControl::PeriodicUpdate() { const double target = pow(2, SmoothLogBdp(TargetLogBdp())); // Though initial window 'could' drop to 0, we keep the floor at 128 - target_initial_window_size_ = static_castGPR_CLAMP(target, 128, INT32_MAX); + target_initial_window_size_ = + static_cast GPR_CLAMP(target, 128, INT32_MAX); action.set_send_initial_window_update( DeltaUrgency(target_initial_window_size_, @@ -367,12 +369,13 @@ FlowControlAction TransportFlowControl::PeriodicUpdate() { // get bandwidth estimate and update max_frame accordingly. double bw_dbl = bdp_estimator_.EstimateBandwidth(); // we target the max of BDP or bandwidth in microseconds. - int32_t frame_size = static_castGPR_CLAMP( + int32_t frame_size = static_cast GPR_CLAMP( GPR_MAX((int32_t)GPR_CLAMP(bw_dbl, 0, INT_MAX) / 1000, target_initial_window_size_), 16384, 16777215); action.set_send_max_frame_size_update( - DeltaUrgency(static_cast(frame_size), GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE), + DeltaUrgency(static_cast(frame_size), + GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE), frame_size); } return UpdateAction(action); diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 7800a55d40..b58027790d 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -271,9 +271,10 @@ class TransportFlowControl final : public TransportFlowControlBase { // See comment above announced_stream_total_over_incoming_window_ for the // logic behind this decision. int64_t target_window() const override { - return static_castGPR_MIN((int64_t)((1u << 31) - 1), - announced_stream_total_over_incoming_window_ + - target_initial_window_size_); + return static_cast GPR_MIN( + (int64_t)((1u << 31) - 1), + announced_stream_total_over_incoming_window_ + + target_initial_window_size_); } const grpc_chttp2_transport* transport() const { return t_; } diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index dd4830cc17..721f0a55a1 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -51,9 +51,9 @@ grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) { char* msg; gpr_asprintf(&msg, "unsupported data flags: 0x%02x", flags); - grpc_error* err = - grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg), - GRPC_ERROR_INT_STREAM_ID, static_cast(stream_id)); + grpc_error* err = grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg), GRPC_ERROR_INT_STREAM_ID, + static_cast(stream_id)); gpr_free(msg); return err; } @@ -208,8 +208,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (cur != end) { grpc_slice_buffer_undo_take_first( - slices, - grpc_slice_sub(slice, static_cast(cur - beg), static_cast(end - beg))); + slices, grpc_slice_sub(slice, static_cast(cur - beg), + static_cast(end - beg))); } grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; @@ -223,11 +223,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( uint32_t remaining = static_cast(end - cur); if (remaining == p->frame_size) { s->stats.incoming.data_bytes += remaining; - if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - p->parsing_frame, - grpc_slice_sub(slice, static_cast(cur - beg), - static_cast(end - beg)), - slice_out))) { + if (GRPC_ERROR_NONE != + (error = grpc_chttp2_incoming_byte_stream_push( + p->parsing_frame, + grpc_slice_sub(slice, static_cast(cur - beg), + static_cast(end - beg)), + slice_out))) { grpc_slice_unref_internal(slice); return error; } @@ -243,11 +244,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( return GRPC_ERROR_NONE; } else if (remaining < p->frame_size) { s->stats.incoming.data_bytes += remaining; - if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - p->parsing_frame, - grpc_slice_sub(slice, static_cast(cur - beg), - static_cast(end - beg)), - slice_out))) { + if (GRPC_ERROR_NONE != + (error = grpc_chttp2_incoming_byte_stream_push( + p->parsing_frame, + grpc_slice_sub(slice, static_cast(cur - beg), + static_cast(end - beg)), + slice_out))) { return error; } p->frame_size -= remaining; @@ -259,8 +261,9 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (GRPC_ERROR_NONE != (grpc_chttp2_incoming_byte_stream_push( p->parsing_frame, - grpc_slice_sub(slice, static_cast(cur - beg), - static_cast(cur + p->frame_size - beg)), + grpc_slice_sub( + slice, static_cast(cur - beg), + static_cast(cur + p->frame_size - beg)), slice_out))) { grpc_slice_unref_internal(slice); return error; @@ -275,8 +278,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->state = GRPC_CHTTP2_DATA_FH_0; cur += p->frame_size; grpc_slice_buffer_undo_take_first( - slices, - grpc_slice_sub(slice, static_cast(cur - beg), static_cast(end - beg))); + slices, grpc_slice_sub(slice, static_cast(cur - beg), + static_cast(end - beg))); grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; } diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index d712bc657e..70931ed22d 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -59,7 +59,8 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_goaway_parser* p = static_cast(parser); + grpc_chttp2_goaway_parser* p = + static_cast(parser); switch (p->state) { case GRPC_CHTTP2_GOAWAY_LSI0: @@ -128,7 +129,8 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: if (end != cur) - memcpy(p->debug_data + p->debug_pos, cur, static_cast(end - cur)); + memcpy(p->debug_data + p->debug_pos, cur, + static_cast(end - cur)); GPR_ASSERT((size_t)(end - cur) < UINT32_MAX - p->debug_pos); p->debug_pos += static_cast(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; @@ -151,7 +153,7 @@ void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, uint8_t* p = GRPC_SLICE_START_PTR(header); uint32_t frame_length; GPR_ASSERT(GRPC_SLICE_LENGTH(debug_data) < UINT32_MAX - 4 - 4); - frame_length = 4 + 4 + static_castGRPC_SLICE_LENGTH(debug_data); + frame_length = 4 + 4 + static_cast GRPC_SLICE_LENGTH(debug_data); /* frame header: length */ *p++ = static_cast(frame_length >> 16); diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc index 0b2bc4baed..79528762e0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -76,7 +76,8 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_rst_stream_parser* p = static_cast(parser); + grpc_chttp2_rst_stream_parser* p = + static_cast(parser); while (p->byte != 4 && cur != end) { p->reason_bytes[p->byte] = *cur; diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index 2501ad9397..737a9382e0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -110,7 +110,8 @@ grpc_error* grpc_chttp2_settings_parser_begin_frame( grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { - grpc_chttp2_settings_parser* parser = static_cast(p); + grpc_chttp2_settings_parser* parser = + static_cast(p); const uint8_t* cur = GRPC_SLICE_START_PTR(slice); const uint8_t* end = GRPC_SLICE_END_PTR(slice); char* msg; @@ -211,8 +212,8 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, } if (id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE && parser->incoming_settings[id] != parser->value) { - t->initial_window_update += - static_cast(parser->value) - parser->incoming_settings[id]; + t->initial_window_update += static_cast(parser->value) - + parser->incoming_settings[id]; if (grpc_http_trace.enabled() || grpc_flowctl_trace.enabled()) { gpr_log(GPR_DEBUG, "%p[%s] adding %d for initial_window change", t, t->is_client ? "cli" : "svr", diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index dc0e475aa1..4855455130 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -98,8 +98,9 @@ static void finish_frame(framer_state* st, int is_header_boundary, fill_header( GRPC_SLICE_START_PTR(st->output->slices[st->header_idx]), type, st->stream_id, st->output->length - st->output_length_at_start_of_frame, - static_cast((is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | - (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); + static_cast( + (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | + (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); st->stats->framing_bytes += 9; st->is_first_frame = 0; } @@ -169,9 +170,9 @@ static void evict_entry(grpc_chttp2_hpack_compressor* c) { GPR_ASSERT(c->table_size >= c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); GPR_ASSERT(c->table_elems > 0); - c->table_size = - static_cast(c->table_size - - c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); + c->table_size = static_cast( + c->table_size - + c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); c->table_elems--; } @@ -197,7 +198,8 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c, evict_entry(c); } GPR_ASSERT(c->table_elems < c->max_table_size); - c->table_elem_size[new_index % c->cap_table_elems] = static_cast(elem_size); + c->table_elem_size[new_index % c->cap_table_elems] = + static_cast(elem_size); c->table_size = static_cast(c->table_size + elem_size); c->table_elems++; @@ -394,7 +396,7 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor* c, GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); - uint32_t len_key = static_castGRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + uint32_t len_key = static_cast GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); wire_value value = get_wire_value(elem, st->use_true_binary_metadata); uint32_t len_val = static_cast(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); @@ -416,7 +418,7 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor* c, GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); - uint32_t len_key = static_castGRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + uint32_t len_key = static_cast GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); wire_value value = get_wire_value(elem, st->use_true_binary_metadata); uint32_t len_val = static_cast(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); @@ -583,8 +585,8 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c) { c->cap_table_elems = elems_for_bytes(c->max_table_size); c->max_table_elems = c->cap_table_elems; c->max_usable_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE; - c->table_elem_size = - static_cast(gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems)); + c->table_elem_size = static_cast( + gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems)); memset(c->table_elem_size, 0, sizeof(*c->table_elem_size) * c->cap_table_elems); for (size_t i = 0; i < GPR_ARRAY_SIZE(c->entries_keys); i++) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 4b512b6439..26a38e3f87 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -757,7 +757,8 @@ static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p, return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Invalid HPACK index received"), - GRPC_ERROR_INT_INDEX, static_cast(p->index)), + GRPC_ERROR_INT_INDEX, + static_cast(p->index)), GRPC_ERROR_INT_SIZE, static_cast(p->table.num_ents)); } GRPC_MDELEM_REF(md); @@ -1227,9 +1228,10 @@ static void append_bytes(grpc_chttp2_hpack_parser_string* str, if (length == 0) return; if (length + str->data.copied.length > str->data.copied.capacity) { GPR_ASSERT(str->data.copied.length + length <= UINT32_MAX); - str->data.copied.capacity = static_cast(str->data.copied.length + length); - str->data.copied.str = - static_cast(gpr_realloc(str->data.copied.str, str->data.copied.capacity)); + str->data.copied.capacity = + static_cast(str->data.copied.length + length); + str->data.copied.str = static_cast( + gpr_realloc(str->data.copied.str, str->data.copied.capacity)); } memcpy(str->data.copied.str + str->data.copied.length, data, length); GPR_ASSERT(length <= UINT32_MAX - str->data.copied.length); @@ -1448,7 +1450,8 @@ static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, uint8_t binary, grpc_chttp2_hpack_parser_string* str) { - if (!p->huff && binary == NOT_BINARY && (end - cur) >= static_cast(p->strlen) && + if (!p->huff && binary == NOT_BINARY && + (end - cur) >= static_cast(p->strlen) && p->current_slice_refcount != nullptr) { GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(); str->copied = false; @@ -1503,7 +1506,8 @@ static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p, return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Invalid HPACK index received"), - GRPC_ERROR_INT_INDEX, static_cast(p->index)), + GRPC_ERROR_INT_INDEX, + static_cast(p->index)), GRPC_ERROR_INT_SIZE, static_cast(p->table.num_ents)); } *is = grpc_is_binary_header(GRPC_MDKEY(elem)); @@ -1618,7 +1622,8 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { GPR_TIMER_SCOPE("grpc_chttp2_hpack_parser_parse", 0); - grpc_chttp2_hpack_parser* parser = static_cast(hpack_parser); + grpc_chttp2_hpack_parser* parser = + static_cast(hpack_parser); if (s != nullptr) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index e8c44e35ab..d7cabbde04 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -173,7 +173,8 @@ void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl) { GRPC_CHTTP2_INITIAL_HPACK_TABLE_SIZE; tbl->max_entries = tbl->cap_entries = entries_for_bytes(tbl->current_table_bytes); - tbl->ents = static_cast(gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries)); + tbl->ents = static_cast( + gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries)); memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { tbl->static_ents[i - 1] = grpc_mdelem_from_slices( @@ -225,7 +226,8 @@ static void evict1(grpc_chttp2_hptbl* tbl) { } static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { - grpc_mdelem* ents = static_cast(gpr_malloc(sizeof(*ents) * new_cap)); + grpc_mdelem* ents = + static_cast(gpr_malloc(sizeof(*ents) * new_cap)); uint32_t i; for (i = 0; i < tbl->num_ents; i++) { @@ -320,7 +322,8 @@ grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { } /* evict entries to ensure no overflow */ - while (elem_bytes > static_cast(tbl->current_table_bytes) - tbl->mem_used) { + while (elem_bytes > + static_cast(tbl->current_table_bytes) - tbl->mem_used) { evict1(tbl); } @@ -350,8 +353,8 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( /* Scan the dynamic table */ for (i = 0; i < tbl->num_ents; i++) { - uint32_t idx = - static_cast(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); + uint32_t idx = static_cast(tbl->num_ents - i + + GRPC_CHTTP2_LAST_STATIC_ENTRY); grpc_mdelem ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; r.index = idx; diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index 2d06bb5038..18d89f06d8 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc @@ -42,8 +42,8 @@ grpc_error* grpc_chttp2_incoming_metadata_buffer_add( buffer->size += GRPC_MDELEM_LENGTH(elem); return grpc_metadata_batch_add_tail( &buffer->batch, - static_cast(gpr_arena_alloc(buffer->arena, - sizeof(grpc_linked_mdelem))), + static_cast( + gpr_arena_alloc(buffer->arena, sizeof(grpc_linked_mdelem))), elem); } diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index d720397de5..9357fedb5c 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -88,15 +88,16 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " "at byte %d", GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state], - static_cast(static_cast(GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state])), + static_cast(static_cast( + GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state])), *cur, static_cast(*cur), t->deframe_state); err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } ++cur; - t->deframe_state = - static_cast(1 + static_cast(t->deframe_state)); + t->deframe_state = static_cast( + 1 + static_cast(t->deframe_state)); } if (cur == end) { return GRPC_ERROR_NONE; @@ -206,11 +207,11 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); if (static_cast(end - cur) == t->incoming_frame_size) { - err = - parse_frame_slice(t, - grpc_slice_sub_no_ref(slice, static_cast(cur - beg), - static_cast(end - beg)), - 1); + err = parse_frame_slice( + t, + grpc_slice_sub_no_ref(slice, static_cast(cur - beg), + static_cast(end - beg)), + 1); if (err != GRPC_ERROR_NONE) { return err; } @@ -231,11 +232,11 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, t->incoming_stream = nullptr; goto dts_fh_0; /* loop */ } else { - err = - parse_frame_slice(t, - grpc_slice_sub_no_ref(slice, static_cast(cur - beg), - static_cast(end - beg)), - 0); + err = parse_frame_slice( + t, + grpc_slice_sub_no_ref(slice, static_cast(cur - beg), + static_cast(end - beg)), + 0); if (err != GRPC_ERROR_NONE) { return err; } @@ -429,7 +430,8 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (GRPC_MDELEM_IS_INTERNED(md)) { /* store the result */ - cached_timeout = static_cast(gpr_malloc(sizeof(grpc_millis))); + cached_timeout = + static_cast(gpr_malloc(sizeof(grpc_millis))); *cached_timeout = timeout; grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } diff --git a/src/core/ext/transport/chttp2/transport/stream_map.cc b/src/core/ext/transport/chttp2/transport/stream_map.cc index 045f868430..a40eaffd5f 100644 --- a/src/core/ext/transport/chttp2/transport/stream_map.cc +++ b/src/core/ext/transport/chttp2/transport/stream_map.cc @@ -26,8 +26,10 @@ void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map* map, size_t initial_capacity) { GPR_ASSERT(initial_capacity > 1); - map->keys = static_cast(gpr_malloc(sizeof(uint32_t) * initial_capacity)); - map->values = static_cast(gpr_malloc(sizeof(void*) * initial_capacity)); + map->keys = + static_cast(gpr_malloc(sizeof(uint32_t) * initial_capacity)); + map->values = + static_cast(gpr_malloc(sizeof(void*) * initial_capacity)); map->count = 0; map->free = 0; map->capacity = initial_capacity; @@ -71,8 +73,8 @@ void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map* map, uint32_t key, /* resize when less than 25% of the table is free, because compaction won't help much */ map->capacity = capacity = 3 * capacity / 2; - map->keys = keys = - static_cast(gpr_realloc(keys, capacity * sizeof(uint32_t))); + map->keys = keys = static_cast( + gpr_realloc(keys, capacity * sizeof(uint32_t))); map->values = values = static_cast(gpr_realloc(values, capacity * sizeof(void*))); } diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index b5970fd646..42cba9ae60 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -147,7 +147,7 @@ static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s, t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE], t->flow_control->remote_window(), - static_castGPR_MAX( + static_cast GPR_MAX( 0, s->flow_control->remote_window_delta() + (int64_t)t->settings[GRPC_PEER_SETTINGS] @@ -310,14 +310,14 @@ class DataSendContext { sending_bytes_before_(s_->sending_bytes) {} uint32_t stream_remote_window() const { - return static_castGPR_MAX( + return static_cast GPR_MAX( 0, s_->flow_control->remote_window_delta() + (int64_t)t_->settings[GRPC_PEER_SETTINGS] [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]); } uint32_t max_outgoing() const { - return static_castGPR_MIN( + return static_cast GPR_MIN( t_->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], GPR_MIN(stream_remote_window(), t_->flow_control->remote_window())); } @@ -325,8 +325,8 @@ class DataSendContext { bool AnyOutgoing() const { return max_outgoing() > 0; } void FlushCompressedBytes() { - uint32_t send_bytes = - static_castGPR_MIN(max_outgoing(), s_->compressed_data_buffer.length); + uint32_t send_bytes = static_cast GPR_MIN( + max_outgoing(), s_->compressed_data_buffer.length); bool is_last_data_frame = (send_bytes == s_->compressed_data_buffer.length && s_->flow_controlled_buffer.length == 0 && @@ -375,10 +375,11 @@ class DataSendContext { bool is_last_frame() const { return is_last_frame_; } void CallCallbacks() { - if (update_list(t_, s_, - static_cast(s_->sending_bytes - sending_bytes_before_), - &s_->on_flow_controlled_cbs, - &s_->flow_controlled_bytes_flowed, GRPC_ERROR_NONE)) { + if (update_list( + t_, s_, + static_cast(s_->sending_bytes - sending_bytes_before_), + &s_->on_flow_controlled_cbs, &s_->flow_controlled_bytes_flowed, + GRPC_ERROR_NONE)) { write_context_->NoteScheduledResults(); } } @@ -624,8 +625,9 @@ void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error) { while (grpc_chttp2_list_pop_writing_stream(t, &s)) { if (s->sending_bytes != 0) { - update_list(t, s, static_cast(s->sending_bytes), &s->on_write_finished_cbs, - &s->flow_controlled_bytes_written, GRPC_ERROR_REF(error)); + update_list(t, s, static_cast(s->sending_bytes), + &s->on_write_finished_cbs, &s->flow_controlled_bytes_written, + GRPC_ERROR_REF(error)); s->sending_bytes = 0; } GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:end"); diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index 3111b6db43..8904c122a7 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -284,7 +284,8 @@ static void maybe_flush_read(stream_obj* s) { CRONET_LOG(GPR_DEBUG, "%p: Flush read", s); s->state.flush_read = true; null_and_maybe_free_read_buffer(s); - s->state.rs.read_buffer = static_cast(gpr_malloc(GRPC_FLUSH_READ_SIZE)); + s->state.rs.read_buffer = + static_cast(gpr_malloc(GRPC_FLUSH_READ_SIZE)); if (!s->state.pending_read_from_cronet) { CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); bidirectional_stream_read(s->cbs, s->state.rs.read_buffer, @@ -309,8 +310,8 @@ static void add_to_storage(struct stream_obj* s, struct op_storage* storage = &s->storage; /* add new op at the beginning of the linked list. The memory is freed in remove_from_storage */ - struct op_and_state* new_op = - static_cast(gpr_malloc(sizeof(struct op_and_state))); + struct op_and_state* new_op = static_cast( + gpr_malloc(sizeof(struct op_and_state))); memcpy(&new_op->op, op, sizeof(grpc_transport_stream_op_batch)); memset(&new_op->state, 0, sizeof(new_op->state)); new_op->s = s; @@ -671,7 +672,8 @@ static void create_grpc_frame(grpc_slice_buffer* write_slice_buffer, size_t length = GRPC_SLICE_LENGTH(slice); *p_write_buffer_size = length + GRPC_HEADER_SIZE_IN_BYTES; /* This is freed in the on_write_completed callback */ - char* write_buffer = static_cast(gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES)); + char* write_buffer = + static_cast(gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES)); *pp_write_buffer = write_buffer; uint8_t* p = reinterpret_cast(write_buffer); /* Append 5 byte header */ @@ -1151,14 +1153,14 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { stream_state->rs.remaining_bytes == 0) { /* Start a read operation for data */ stream_state->rs.length_field_received = true; - parse_grpc_header(reinterpret_cast(stream_state->rs.read_buffer), - &stream_state->rs.length_field, - &stream_state->rs.compressed); + parse_grpc_header( + reinterpret_cast(stream_state->rs.read_buffer), + &stream_state->rs.length_field, &stream_state->rs.compressed); CRONET_LOG(GPR_DEBUG, "length field = %d", stream_state->rs.length_field); if (stream_state->rs.length_field > 0) { - stream_state->rs.read_buffer = - static_cast(gpr_malloc(static_cast(stream_state->rs.length_field))); + stream_state->rs.read_buffer = static_cast( + gpr_malloc(static_cast(stream_state->rs.length_field))); GPR_ASSERT(stream_state->rs.read_buffer); stream_state->rs.remaining_bytes = stream_state->rs.length_field; stream_state->rs.received_bytes = 0; @@ -1181,7 +1183,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags |= GRPC_WRITE_INTERNAL_COMPRESS; } - *(reinterpret_cast(stream_op->payload->recv_message.recv_message)) = + *(reinterpret_cast( + stream_op->payload->recv_message.recv_message)) = reinterpret_cast(&stream_state->rs.sbs); GRPC_CLOSURE_SCHED( stream_op->payload->recv_message.recv_message_ready, @@ -1237,7 +1240,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags = GRPC_WRITE_INTERNAL_COMPRESS; } - *(reinterpret_cast(stream_op->payload->recv_message.recv_message)) = + *(reinterpret_cast( + stream_op->payload->recv_message.recv_message)) = reinterpret_cast(&stream_state->rs.sbs); GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); @@ -1417,8 +1421,8 @@ static const grpc_transport_vtable grpc_cronet_vtable = { grpc_transport* grpc_create_cronet_transport(void* engine, const char* target, const grpc_channel_args* args, void* reserved) { - grpc_cronet_transport* ct = - static_cast(gpr_malloc(sizeof(grpc_cronet_transport))); + grpc_cronet_transport* ct = static_cast( + gpr_malloc(sizeof(grpc_cronet_transport))); if (!ct) { goto error; } diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 97d908fa5d..2022eaffe5 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -208,8 +208,8 @@ static grpc_error* fill_in_metadata(inproc_stream* s, grpc_error* error = GRPC_ERROR_NONE; for (grpc_linked_mdelem* elem = metadata->list.head; (elem != nullptr) && (error == GRPC_ERROR_NONE); elem = elem->next) { - grpc_linked_mdelem* nelem = - static_cast(gpr_arena_alloc(s->arena, sizeof(*nelem))); + grpc_linked_mdelem* nelem = static_cast( + gpr_arena_alloc(s->arena, sizeof(*nelem))); nelem->md = grpc_mdelem_from_slices(grpc_slice_intern(GRPC_MDKEY(elem->md)), grpc_slice_intern(GRPC_MDVALUE(elem->md))); @@ -425,13 +425,13 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { // since it expects that as well as no error yet grpc_metadata_batch fake_md; grpc_metadata_batch_init(&fake_md); - grpc_linked_mdelem* path_md = - static_cast(gpr_arena_alloc(s->arena, sizeof(*path_md))); + grpc_linked_mdelem* path_md = static_cast( + gpr_arena_alloc(s->arena, sizeof(*path_md))); path_md->md = grpc_mdelem_from_slices(g_fake_path_key, g_fake_path_value); GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, path_md) == GRPC_ERROR_NONE); - grpc_linked_mdelem* auth_md = - static_cast(gpr_arena_alloc(s->arena, sizeof(*auth_md))); + grpc_linked_mdelem* auth_md = static_cast( + gpr_arena_alloc(s->arena, sizeof(*auth_md))); auth_md->md = grpc_mdelem_from_slices(g_fake_auth_key, g_fake_auth_value); GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, auth_md) == GRPC_ERROR_NONE); @@ -1151,8 +1151,10 @@ static void inproc_transports_create(grpc_transport** server_transport, grpc_transport** client_transport, const grpc_channel_args* client_args) { INPROC_LOG(GPR_DEBUG, "inproc_transports_create"); - inproc_transport* st = static_cast(gpr_zalloc(sizeof(*st))); - inproc_transport* ct = static_cast(gpr_zalloc(sizeof(*ct))); + inproc_transport* st = + static_cast(gpr_zalloc(sizeof(*st))); + inproc_transport* ct = + static_cast(gpr_zalloc(sizeof(*ct))); // Share one lock between both sides since both sides get affected st->mu = ct->mu = static_cast(gpr_malloc(sizeof(*st->mu))); gpr_mu_init(&st->mu->mu); diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc index 81ea429a6a..4b74afc244 100644 --- a/src/core/lib/backoff/backoff.cc +++ b/src/core/lib/backoff/backoff.cc @@ -55,13 +55,14 @@ grpc_millis BackOff::NextAttemptTime() { initial_ = false; return current_backoff_ + grpc_core::ExecCtx::Get()->Now(); } - current_backoff_ = - static_cast(std::min(current_backoff_ * options_.multiplier(), - static_cast(options_.max_backoff()))); + current_backoff_ = static_cast( + std::min(current_backoff_ * options_.multiplier(), + static_cast(options_.max_backoff()))); const double jitter = generate_uniform_random_number_between( &rng_state_, -options_.jitter() * current_backoff_, options_.jitter() * current_backoff_); - const grpc_millis next_timeout = static_cast(current_backoff_ + jitter); + const grpc_millis next_timeout = + static_cast(current_backoff_ + jitter); return next_timeout + grpc_core::ExecCtx::Get()->Now(); } diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 8f448bfd91..98fdfa6b9a 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -93,7 +93,8 @@ grpc_channel_args* grpc_channel_args_copy_and_add_and_remove( dst->args = nullptr; return dst; } - dst->args = static_cast(gpr_malloc(sizeof(grpc_arg) * dst->num_args)); + dst->args = + static_cast(gpr_malloc(sizeof(grpc_arg) * dst->num_args)); // Copy args from src that are not being removed. size_t dst_idx = 0; if (src != nullptr) { @@ -118,7 +119,8 @@ grpc_channel_args* grpc_channel_args_copy(const grpc_channel_args* src) { grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a, const grpc_channel_args* b) { const size_t max_out = (a->num_args + b->num_args); - grpc_arg* uniques = static_cast(gpr_malloc(sizeof(*uniques) * max_out)); + grpc_arg* uniques = + static_cast(gpr_malloc(sizeof(*uniques) * max_out)); for (size_t i = 0; i < a->num_args; ++i) uniques[i] = a->args[i]; size_t uniques_idx = a->num_args; @@ -169,7 +171,8 @@ static int cmp_key_stable(const void* ap, const void* bp) { } grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) { - grpc_arg** args = static_cast(gpr_malloc(sizeof(grpc_arg*) * a->num_args)); + grpc_arg** args = + static_cast(gpr_malloc(sizeof(grpc_arg*) * a->num_args)); for (size_t i = 0; i < a->num_args; i++) { args[i] = &a->args[i]; } diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index c311c73b85..737d828e4b 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -104,8 +104,9 @@ grpc_error* grpc_channel_stack_init( GRPC_STREAM_REF_INIT(&stack->refcount, initial_refs, destroy, destroy_arg, name); elems = CHANNEL_ELEMS_FROM_STACK(stack); - user_data = (reinterpret_cast(elems)) + ROUND_UP_TO_ALIGNMENT_SIZE( - filter_count * sizeof(grpc_channel_element)); + user_data = + (reinterpret_cast(elems)) + + ROUND_UP_TO_ALIGNMENT_SIZE(filter_count * sizeof(grpc_channel_element)); /* init per-filter data */ grpc_error* first_error = GRPC_ERROR_NONE; @@ -243,11 +244,13 @@ void grpc_channel_next_op(grpc_channel_element* elem, grpc_transport_op* op) { grpc_channel_stack* grpc_channel_stack_from_top_element( grpc_channel_element* elem) { - return reinterpret_cast(reinterpret_cast(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( - sizeof(grpc_channel_stack))); + return reinterpret_cast( + reinterpret_cast(elem) - + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_channel_stack))); } grpc_call_stack* grpc_call_stack_from_top_element(grpc_call_element* elem) { - return reinterpret_cast(reinterpret_cast(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( - sizeof(grpc_call_stack))); + return reinterpret_cast( + reinterpret_cast(elem) - + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call_stack))); } diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index c04f4c603a..cae862ec0e 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -78,7 +78,8 @@ const char* grpc_channel_stack_builder_get_target( static grpc_channel_stack_builder_iterator* create_iterator_at_filter_node( grpc_channel_stack_builder* builder, filter_node* node) { grpc_channel_stack_builder_iterator* it = - static_cast(gpr_malloc(sizeof(*it))); + static_cast( + gpr_malloc(sizeof(*it))); it->builder = builder; it->node = node; return it; @@ -213,7 +214,8 @@ bool grpc_channel_stack_builder_prepend_filter( static void add_after(filter_node* before, const grpc_channel_filter* filter, grpc_post_filter_create_init_func post_init_func, void* user_data) { - filter_node* new_node = static_cast(gpr_malloc(sizeof(*new_node))); + filter_node* new_node = + static_cast(gpr_malloc(sizeof(*new_node))); new_node->next = before->next; new_node->prev = before; new_node->next->prev = new_node->prev->next = new_node; @@ -265,7 +267,8 @@ grpc_error* grpc_channel_stack_builder_finish( // create an array of filters const grpc_channel_filter** filters = - static_cast(gpr_malloc(sizeof(*filters) * num_filters)); + static_cast( + gpr_malloc(sizeof(*filters) * num_filters)); size_t i = 0; for (filter_node* p = builder->begin.next; p != &builder->end; p = p->next) { filters[i++] = p->filter; @@ -277,8 +280,8 @@ grpc_error* grpc_channel_stack_builder_finish( // allocate memory, with prefix_bytes followed by channel_stack_size *result = gpr_zalloc(prefix_bytes + channel_stack_size); // fetch a pointer to the channel stack - grpc_channel_stack* channel_stack = - reinterpret_cast(static_cast(*result) + prefix_bytes); + grpc_channel_stack* channel_stack = reinterpret_cast( + static_cast(*result) + prefix_bytes); // and initialize it grpc_error* error = grpc_channel_stack_init( initial_refs, destroy, destroy_arg == nullptr ? *result : destroy_arg, diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index 516d49e4d3..a16e89ce00 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -115,7 +115,8 @@ static void con_start_transport_stream_op_batch( // calld->on_complete like we can for the other ops. However, // cancellation isn't in the fast path, so we just allocate a new // closure for each one. - callback_state* state = static_cast(gpr_malloc(sizeof(*state))); + callback_state* state = + static_cast(gpr_malloc(sizeof(*state))); intercept_callback(calld, state, true, "on_complete (cancel_stream)", &batch->on_complete); } else { diff --git a/src/core/lib/channel/handshaker.cc b/src/core/lib/channel/handshaker.cc index daacbdebd3..518e880c15 100644 --- a/src/core/lib/channel/handshaker.cc +++ b/src/core/lib/channel/handshaker.cc @@ -81,8 +81,8 @@ struct grpc_handshake_manager { }; grpc_handshake_manager* grpc_handshake_manager_create() { - grpc_handshake_manager* mgr = - static_cast(gpr_zalloc(sizeof(grpc_handshake_manager))); + grpc_handshake_manager* mgr = static_cast( + gpr_zalloc(sizeof(grpc_handshake_manager))); gpr_mu_init(&mgr->mu); gpr_ref_init(&mgr->refs, 1); return mgr; @@ -233,8 +233,8 @@ void grpc_handshake_manager_do_handshake( mgr->args.endpoint = endpoint; mgr->args.args = grpc_channel_args_copy(channel_args); mgr->args.user_data = user_data; - mgr->args.read_buffer = - static_cast(gpr_malloc(sizeof(*mgr->args.read_buffer))); + mgr->args.read_buffer = static_cast( + gpr_malloc(sizeof(*mgr->args.read_buffer))); grpc_slice_buffer_init(mgr->args.read_buffer); // Initialize state needed for calling handshakers. mgr->acceptor = acceptor; diff --git a/src/core/lib/channel/handshaker_registry.cc b/src/core/lib/channel/handshaker_registry.cc index f23f009275..5464cc42f4 100644 --- a/src/core/lib/channel/handshaker_registry.cc +++ b/src/core/lib/channel/handshaker_registry.cc @@ -35,7 +35,8 @@ static void grpc_handshaker_factory_list_register( grpc_handshaker_factory_list* list, bool at_start, grpc_handshaker_factory* factory) { list->list = static_cast(gpr_realloc( - list->list, (list->num_factories + 1) * sizeof(grpc_handshaker_factory*))); + list->list, + (list->num_factories + 1) * sizeof(grpc_handshaker_factory*))); if (at_start) { memmove(list->list + 1, list->list, sizeof(grpc_handshaker_factory*) * list->num_factories); diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc index e49c67f784..36829c8adf 100644 --- a/src/core/lib/compression/compression_internal.cc +++ b/src/core/lib/compression/compression_internal.cc @@ -190,7 +190,8 @@ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level( GRPC_API_TRACE("grpc_message_compression_algorithm_for_level(level=%d)", 1, ((int)level)); if (level > GRPC_COMPRESS_LEVEL_HIGH) { - gpr_log(GPR_ERROR, "Unknown message compression level %d.", static_cast(level)); + gpr_log(GPR_ERROR, "Unknown message compression level %d.", + static_cast(level)); abort(); } diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc index 238eff780c..2e44551935 100644 --- a/src/core/lib/compression/message_compress.cc +++ b/src/core/lib/compression/message_compress.cc @@ -39,20 +39,20 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input, const uInt uint_max = ~static_cast(0); GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max); - zs->avail_out = static_castGRPC_SLICE_LENGTH(outbuf); + zs->avail_out = static_cast GRPC_SLICE_LENGTH(outbuf); zs->next_out = GRPC_SLICE_START_PTR(outbuf); flush = Z_NO_FLUSH; for (i = 0; i < input->count; i++) { if (i == input->count - 1) flush = Z_FINISH; GPR_ASSERT(GRPC_SLICE_LENGTH(input->slices[i]) <= uint_max); - zs->avail_in = static_castGRPC_SLICE_LENGTH(input->slices[i]); + zs->avail_in = static_cast GRPC_SLICE_LENGTH(input->slices[i]); zs->next_in = GRPC_SLICE_START_PTR(input->slices[i]); do { if (zs->avail_out == 0) { grpc_slice_buffer_add_indexed(output, outbuf); outbuf = GRPC_SLICE_MALLOC(OUTPUT_BLOCK_SIZE); GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max); - zs->avail_out = static_castGRPC_SLICE_LENGTH(outbuf); + zs->avail_out = static_cast GRPC_SLICE_LENGTH(outbuf); zs->next_out = GRPC_SLICE_START_PTR(outbuf); } r = flate(zs, flush); diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index c48fe9305d..48fe99b69f 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -52,7 +52,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out); while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) { grpc_slice slice = grpc_slice_buffer_take_first(in); - ctx->zs.avail_in = static_castGRPC_SLICE_LENGTH(slice); + ctx->zs.avail_in = static_cast GRPC_SLICE_LENGTH(slice); ctx->zs.next_in = GRPC_SLICE_START_PTR(slice); r = ctx->flate(&ctx->zs, Z_NO_FLUSH); if (r < 0 && r != Z_BUF_ERROR) { @@ -184,8 +184,8 @@ grpc_stream_compression_context_create_gzip( GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_GZIP_COMPRESS || method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS); grpc_stream_compression_context_gzip* gzip_ctx = - static_cast(gpr_zalloc( - sizeof(grpc_stream_compression_context_gzip))); + static_cast( + gpr_zalloc(sizeof(grpc_stream_compression_context_gzip))); int r; if (gzip_ctx == nullptr) { return nullptr; diff --git a/src/core/lib/debug/stats.cc b/src/core/lib/debug/stats.cc index f4de6a82a9..09a86287e4 100644 --- a/src/core/lib/debug/stats.cc +++ b/src/core/lib/debug/stats.cc @@ -32,8 +32,8 @@ static size_t g_num_cores; void grpc_stats_init(void) { g_num_cores = GPR_MAX(1, gpr_cpu_num_cores()); - grpc_stats_per_cpu_storage = - static_cast(gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores)); + grpc_stats_per_cpu_storage = static_cast( + gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores)); } void grpc_stats_shutdown(void) { gpr_free(grpc_stats_per_cpu_storage); } @@ -83,7 +83,8 @@ size_t grpc_stats_histo_count(const grpc_stats_data* stats, grpc_stats_histograms histogram) { size_t sum = 0; for (int i = 0; i < grpc_stats_histo_buckets[histogram]; i++) { - sum += static_cast(stats->histograms[grpc_stats_histo_start[histogram] + i]); + sum += static_cast( + stats->histograms[grpc_stats_histo_start[histogram] + i]); } return sum; } @@ -133,7 +134,8 @@ double grpc_stats_histo_percentile(const grpc_stats_data* stats, return threshold_for_count_below( stats->histograms + grpc_stats_histo_start[histogram], grpc_stats_histo_bucket_boundaries[histogram], - grpc_stats_histo_buckets[histogram], static_cast(count) * percentile / 100.0); + grpc_stats_histo_buckets[histogram], + static_cast(count) * percentile / 100.0); } char* grpc_stats_data_as_json(const grpc_stats_data* data) { diff --git a/src/core/lib/gpr/arena.cc b/src/core/lib/gpr/arena.cc index a1eefa56bc..5bc575f711 100644 --- a/src/core/lib/gpr/arena.cc +++ b/src/core/lib/gpr/arena.cc @@ -71,18 +71,20 @@ size_t gpr_arena_destroy(gpr_arena* arena) { void* gpr_arena_alloc(gpr_arena* arena, size_t size) { size = ROUND_UP_TO_ALIGNMENT_SIZE(size); - size_t start = - static_cast(gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size)); + size_t start = static_cast( + gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size)); zone* z = &arena->initial_zone; while (start > z->size_end) { zone* next_z = (zone*)gpr_atm_acq_load(&z->next_atm); if (next_z == nullptr) { - size_t next_z_size = static_castgpr_atm_no_barrier_load(&arena->size_so_far); - next_z = static_cast(zalloc_aligned(ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) + - next_z_size)); + size_t next_z_size = + static_cast gpr_atm_no_barrier_load(&arena->size_so_far); + next_z = static_cast(zalloc_aligned( + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) + next_z_size)); next_z->size_begin = z->size_end; next_z->size_end = z->size_end + next_z_size; - if (!gpr_atm_rel_cas(&z->next_atm, static_cast(NULL), (gpr_atm)next_z)) { + if (!gpr_atm_rel_cas(&z->next_atm, static_cast(NULL), + (gpr_atm)next_z)) { gpr_free_aligned(next_z); next_z = (zone*)gpr_atm_acq_load(&z->next_atm); } @@ -95,7 +97,9 @@ void* gpr_arena_alloc(gpr_arena* arena, size_t size) { GPR_ASSERT(start >= z->size_begin); GPR_ASSERT(start + size <= z->size_end); char* ptr = (z == &arena->initial_zone) - ? reinterpret_cast(arena) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) - : reinterpret_cast(z) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)); + ? reinterpret_cast(arena) + + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + : reinterpret_cast(z) + + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)); return ptr + start - z->size_begin; } diff --git a/src/core/lib/gpr/log.cc b/src/core/lib/gpr/log.cc index 9211a00a69..410096c0f7 100644 --- a/src/core/lib/gpr/log.cc +++ b/src/core/lib/gpr/log.cc @@ -45,7 +45,8 @@ const char* gpr_log_severity_string(gpr_log_severity severity) { void gpr_log_message(const char* file, int line, gpr_log_severity severity, const char* message) { - if (static_cast(severity) < gpr_atm_no_barrier_load(&g_min_severity_to_print)) { + if (static_cast(severity) < + gpr_atm_no_barrier_load(&g_min_severity_to_print)) { return; } diff --git a/src/core/lib/gpr/string.cc b/src/core/lib/gpr/string.cc index 9c07f43cae..5a16377e49 100644 --- a/src/core/lib/gpr/string.cc +++ b/src/core/lib/gpr/string.cc @@ -243,7 +243,8 @@ void gpr_strvec_destroy(gpr_strvec* sv) { void gpr_strvec_add(gpr_strvec* sv, char* str) { if (sv->count == sv->capacity) { sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2); - sv->strs = static_cast(gpr_realloc(sv->strs, sizeof(char*) * sv->capacity)); + sv->strs = static_cast( + gpr_realloc(sv->strs, sizeof(char*) * sv->capacity)); } sv->strs[sv->count++] = str; } @@ -265,7 +266,8 @@ int gpr_stricmp(const char* a, const char* b) { static void add_string_to_split(const char* beg, const char* end, char*** strs, size_t* nstrs, size_t* capstrs) { - char* out = static_cast(gpr_malloc(static_cast(end - beg) + 1)); + char* out = + static_cast(gpr_malloc(static_cast(end - beg) + 1)); memcpy(out, beg, static_cast(end - beg)); out[end - beg] = 0; if (*nstrs == *capstrs) { diff --git a/src/core/lib/gpr/thd_posix.cc b/src/core/lib/gpr/thd_posix.cc index e8e61ca396..ce268e1fbc 100644 --- a/src/core/lib/gpr/thd_posix.cc +++ b/src/core/lib/gpr/thd_posix.cc @@ -103,9 +103,13 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name, return thread_started; } -gpr_thd_id gpr_thd_currentid(void) { return static_cast(pthread_self()); } +gpr_thd_id gpr_thd_currentid(void) { + return static_cast(pthread_self()); +} -void gpr_thd_join(gpr_thd_id t) { pthread_join(static_cast(t), nullptr); } +void gpr_thd_join(gpr_thd_id t) { + pthread_join(static_cast(t), nullptr); +} /***************************************** * Only used when fork support is enabled diff --git a/src/core/lib/gpr/time.cc b/src/core/lib/gpr/time.cc index 9ebfaa7525..39ebeb4339 100644 --- a/src/core/lib/gpr/time.cc +++ b/src/core/lib/gpr/time.cc @@ -81,8 +81,9 @@ static gpr_timespec to_seconds_from_sub_second_time(int64_t time_in_units, units_per_sec) - 1; } - out.tv_nsec = static_cast((time_in_units - out.tv_sec * units_per_sec) * - GPR_NS_PER_SEC / units_per_sec); + out.tv_nsec = + static_cast((time_in_units - out.tv_sec * units_per_sec) * + GPR_NS_PER_SEC / units_per_sec); out.clock_type = type; } return out; @@ -216,7 +217,8 @@ int32_t gpr_time_to_millis(gpr_timespec t) { care?) */ return -2147483647; } else { - return static_cast(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS); + return static_cast(t.tv_sec * GPR_MS_PER_SEC + + t.tv_nsec / GPR_NS_PER_MS); } } diff --git a/src/core/lib/http/format_request.cc b/src/core/lib/http/format_request.cc index ff273ffc1a..6581bef7cd 100644 --- a/src/core/lib/http/format_request.cc +++ b/src/core/lib/http/format_request.cc @@ -89,7 +89,8 @@ grpc_slice grpc_httpcli_format_post_request(const grpc_httpcli_request* request, if (!has_content_type) { gpr_strvec_add(&out, gpr_strdup("Content-Type: text/plain\r\n")); } - gpr_asprintf(&tmp, "Content-Length: %lu\r\n", static_cast(body_size)); + gpr_asprintf(&tmp, "Content-Length: %lu\r\n", + static_cast(body_size)); gpr_strvec_add(&out, tmp); } gpr_strvec_add(&out, gpr_strdup("\r\n")); diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index ab684f6093..d754558060 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -111,8 +111,8 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( return GRPC_SECURITY_ERROR; } - c = static_cast(gpr_zalloc( - sizeof(grpc_httpcli_ssl_channel_security_connector))); + c = static_cast( + gpr_zalloc(sizeof(grpc_httpcli_ssl_channel_security_connector))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.vtable = &httpcli_ssl_vtable; diff --git a/src/core/lib/http/parser.cc b/src/core/lib/http/parser.cc index 74689a6671..724b6d1885 100644 --- a/src/core/lib/http/parser.cc +++ b/src/core/lib/http/parser.cc @@ -88,7 +88,8 @@ static grpc_error* handle_request_line(grpc_http_parser* parser) { if (cur == end) return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "No method on HTTP request line"); - parser->http.request->method = buf2str(beg, static_cast(cur - beg - 1)); + parser->http.request->method = + buf2str(beg, static_cast(cur - beg - 1)); beg = cur; while (cur != end && *cur++ != ' ') @@ -182,7 +183,8 @@ static grpc_error* add_header(grpc_http_parser* parser) { cur++; } GPR_ASSERT((size_t)(end - cur) >= parser->cur_line_end_length); - hdr.value = buf2str(cur, static_cast(end - cur) - parser->cur_line_end_length); + hdr.value = buf2str( + cur, static_cast(end - cur) - parser->cur_line_end_length); switch (parser->type) { case GRPC_HTTP_RESPONSE: @@ -198,8 +200,8 @@ static grpc_error* add_header(grpc_http_parser* parser) { if (*hdr_count == parser->hdr_capacity) { parser->hdr_capacity = GPR_MAX(parser->hdr_capacity + 1, parser->hdr_capacity * 3 / 2); - *hdrs = static_cast(gpr_realloc( - *hdrs, parser->hdr_capacity * sizeof(**hdrs))); + *hdrs = static_cast( + gpr_realloc(*hdrs, parser->hdr_capacity * sizeof(**hdrs))); } (*hdrs)[(*hdr_count)++] = hdr; @@ -257,7 +259,8 @@ 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((void*)*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 f180594545..3b11e0266d 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -68,8 +68,8 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner, call_combiner, closure DEBUG_FMT_ARGS, reason, grpc_error_string(error)); } - size_t prev_size = - static_cast(gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1)); + size_t prev_size = static_cast( + gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1)); if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, prev_size + 1); @@ -90,7 +90,8 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner, } // Queue was not empty, so add closure to queue. closure->error_data.error = error; - gpr_mpscq_push(&call_combiner->queue, reinterpret_cast(closure)); + gpr_mpscq_push(&call_combiner->queue, + reinterpret_cast(closure)); } } @@ -102,8 +103,8 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, "==> grpc_call_combiner_stop() [%p] [" DEBUG_FMT_STR "%s]", call_combiner DEBUG_FMT_ARGS, reason); } - size_t prev_size = - static_cast(gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1)); + size_t prev_size = static_cast( + gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1)); if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, prev_size - 1); @@ -115,8 +116,8 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, gpr_log(GPR_DEBUG, " checking queue"); } bool empty; - grpc_closure* closure = reinterpret_cast(gpr_mpscq_pop_and_check_end( - &call_combiner->queue, &empty)); + grpc_closure* closure = reinterpret_cast( + gpr_mpscq_pop_and_check_end(&call_combiner->queue, &empty)); if (closure == nullptr) { // This can happen either due to a race condition within the mpscq // code or because of a race with grpc_call_combiner_start(). diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 6ff6fccf03..a7edf17e9b 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -342,7 +342,8 @@ static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) { } static void enqueue_finally(void* closure, grpc_error* error) { - combiner_finally_exec(static_cast(closure), GRPC_ERROR_REF(error)); + combiner_finally_exec(static_cast(closure), + GRPC_ERROR_REF(error)); } grpc_closure_scheduler* grpc_combiner_scheduler(grpc_combiner* combiner) { diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 0ba0617f75..4088cf612e 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -148,7 +148,8 @@ grpc_error* grpc_error_ref(grpc_error* err) { static void unref_errs(grpc_error* err) { uint8_t slot = err->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = reinterpret_cast(err->arena + slot); + grpc_linked_error* lerr = + reinterpret_cast(err->arena + slot); GRPC_ERROR_UNREF(lerr->err); GPR_ASSERT(err->last_err == slot ? lerr->next == UINT8_MAX : lerr->next != UINT8_MAX); @@ -200,8 +201,8 @@ static uint8_t get_placement(grpc_error** err, size_t size) { GPR_ASSERT(*err); uint8_t slots = static_cast(size / sizeof(intptr_t)); if ((*err)->arena_size + slots > (*err)->arena_capacity) { - (*err)->arena_capacity = - static_castGPR_MIN(UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2)); + (*err)->arena_capacity = static_cast GPR_MIN( + UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2)); if ((*err)->arena_size + slots > (*err)->arena_capacity) { return UINT8_MAX; } @@ -317,9 +318,10 @@ grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc, GPR_TIMER_SCOPE("grpc_error_create", 0); uint8_t initial_arena_capacity = static_cast( DEFAULT_ERROR_CAPACITY + - static_cast(num_referencing * SLOTS_PER_LINKED_ERROR) + SURPLUS_CAPACITY); - grpc_error* err = static_cast(gpr_malloc( - sizeof(*err) + initial_arena_capacity * sizeof(intptr_t))); + static_cast(num_referencing * SLOTS_PER_LINKED_ERROR) + + SURPLUS_CAPACITY); + grpc_error* err = static_cast( + gpr_malloc(sizeof(*err) + initial_arena_capacity * sizeof(intptr_t))); if (err == nullptr) { // TODO(ctiller): make gpr_malloc return NULL return GRPC_ERROR_OOM; } @@ -362,7 +364,8 @@ static void ref_strs(grpc_error* err) { for (size_t i = 0; i < GRPC_ERROR_STR_MAX; ++i) { uint8_t slot = err->strs[i]; if (slot != UINT8_MAX) { - grpc_slice_ref_internal(*reinterpret_cast(err->arena + slot)); + grpc_slice_ref_internal( + *reinterpret_cast(err->arena + slot)); } } } @@ -370,7 +373,8 @@ static void ref_strs(grpc_error* err) { static void ref_errs(grpc_error* err) { uint8_t slot = err->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = reinterpret_cast(err->arena + slot); + grpc_linked_error* lerr = + reinterpret_cast(err->arena + slot); GRPC_ERROR_REF(lerr->err); slot = lerr->next; } @@ -399,11 +403,12 @@ static grpc_error* copy_error_and_unref(grpc_error* in) { uint8_t new_arena_capacity = in->arena_capacity; // the returned err will be added to, so we ensure this is room to avoid // unneeded allocations. - if (in->arena_capacity - in->arena_size < static_castSLOTS_PER_STR) { + if (in->arena_capacity - in->arena_size < + static_cast SLOTS_PER_STR) { new_arena_capacity = static_cast(3 * new_arena_capacity / 2); } - out = static_cast(gpr_malloc(sizeof(*in) + - new_arena_capacity * sizeof(intptr_t))); + out = static_cast( + gpr_malloc(sizeof(*in) + new_arena_capacity * sizeof(intptr_t))); #ifndef NDEBUG if (grpc_trace_error_refcount.enabled()) { gpr_log(GPR_DEBUG, "%p create copying %p", out, in); @@ -571,8 +576,8 @@ static void append_esc_str(const uint8_t* str, size_t len, char** s, size_t* sz, static void append_kv(kv_pairs* kvs, char* key, char* value) { if (kvs->num_kvs == kvs->cap_kvs) { kvs->cap_kvs = GPR_MAX(3 * kvs->cap_kvs / 2, 4); - kvs->kvs = - static_cast(gpr_realloc(kvs->kvs, sizeof(*kvs->kvs) * kvs->cap_kvs)); + kvs->kvs = static_cast( + gpr_realloc(kvs->kvs, sizeof(*kvs->kvs) * kvs->cap_kvs)); } kvs->kvs[kvs->num_kvs].key = key; kvs->kvs[kvs->num_kvs].value = value; @@ -662,7 +667,8 @@ static void add_errs(grpc_error* err, char** s, size_t* sz, size_t* cap) { uint8_t slot = err->first_err; bool first = true; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = reinterpret_cast(err->arena + slot); + grpc_linked_error* lerr = + reinterpret_cast(err->arena + slot); if (!first) append_chr(',', s, sz, cap); first = false; const char* e = grpc_error_string(lerr->err); @@ -698,8 +704,8 @@ static char* finish_kvs(kv_pairs* kvs) { append_chr('{', &s, &sz, &cap); for (size_t i = 0; i < kvs->num_kvs; i++) { if (i != 0) append_chr(',', &s, &sz, &cap); - append_esc_str(reinterpret_cast(kvs->kvs[i].key), strlen(kvs->kvs[i].key), &s, - &sz, &cap); + append_esc_str(reinterpret_cast(kvs->kvs[i].key), + strlen(kvs->kvs[i].key), &s, &sz, &cap); gpr_free(kvs->kvs[i].key); append_chr(':', &s, &sz, &cap); append_str(kvs->kvs[i].value, &s, &sz, &cap); diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index ad013c01b6..f84f3f8205 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -458,8 +458,8 @@ static grpc_error* pollset_global_init(void) { return GRPC_OS_ERROR(errno, "epoll_ctl"); } g_num_neighborhoods = GPR_CLAMP(gpr_cpu_num_cores(), 1, MAX_NEIGHBORHOODS); - g_neighborhoods = static_cast(gpr_zalloc(sizeof(*g_neighborhoods) * - g_num_neighborhoods)); + g_neighborhoods = static_cast( + gpr_zalloc(sizeof(*g_neighborhoods) * g_num_neighborhoods)); for (size_t i = 0; i < g_num_neighborhoods; i++) { gpr_mu_init(&g_neighborhoods[i].mu); } diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index e201845cd2..8bce34b2fd 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -479,7 +479,7 @@ static pollable* pollable_ref(pollable* p) { #else static pollable* pollable_ref(pollable* p, int line, const char* reason) { if (grpc_trace_pollable_refcount.enabled()) { - int r = static_castgpr_atm_no_barrier_load(&p->refs.count); + int r = static_cast gpr_atm_no_barrier_load(&p->refs.count); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason); } @@ -494,7 +494,7 @@ static void pollable_unref(pollable* p) { static void pollable_unref(pollable* p, int line, const char* reason) { if (p == nullptr) return; if (grpc_trace_pollable_refcount.enabled()) { - int r = static_castgpr_atm_no_barrier_load(&p->refs.count); + int r = static_cast gpr_atm_no_barrier_load(&p->refs.count); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason); } @@ -516,7 +516,8 @@ static grpc_error* pollable_add_fd(pollable* p, grpc_fd* fd) { } struct epoll_event ev_fd; - ev_fd.events = static_cast(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE); + ev_fd.events = + static_cast(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE); ev_fd.data.ptr = fd; if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd->fd, &ev_fd) != 0) { switch (errno) { @@ -768,7 +769,8 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset, } append_error(&error, grpc_wakeup_fd_consume_wakeup( - (grpc_wakeup_fd*)((~static_cast(1)) & (intptr_t)data_ptr)), + (grpc_wakeup_fd*)((~static_cast(1)) & + (intptr_t)data_ptr)), err_desc); } else { grpc_fd* fd = static_cast(data_ptr); @@ -1170,7 +1172,8 @@ static grpc_pollset_set* pss_lock_adam(grpc_pollset_set* pss) { } static grpc_pollset_set* pollset_set_create(void) { - grpc_pollset_set* pss = static_cast(gpr_zalloc(sizeof(*pss))); + grpc_pollset_set* pss = + static_cast(gpr_zalloc(sizeof(*pss))); gpr_mu_init(&pss->mu); gpr_ref_init(&pss->refs, 1); return pss; @@ -1210,8 +1213,8 @@ static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { } if (pss->fd_count == pss->fd_capacity) { pss->fd_capacity = GPR_MAX(pss->fd_capacity * 2, 8); - pss->fds = - static_cast(gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds))); + pss->fds = static_cast( + gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds))); } REF_BY(fd, 2, "pollset_set"); pss->fds[pss->fd_count++] = fd; @@ -1373,7 +1376,8 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a, b->parent = a; if (a->fd_capacity < a->fd_count + b->fd_count) { a->fd_capacity = GPR_MAX(2 * a->fd_capacity, a->fd_count + b->fd_count); - a->fds = static_cast(gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds))); + a->fds = static_cast( + gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds))); } size_t initial_a_fd_count = a->fd_count; a->fd_count = 0; @@ -1390,8 +1394,8 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a, if (a->pollset_capacity < a->pollset_count + b->pollset_count) { a->pollset_capacity = GPR_MAX(2 * a->pollset_capacity, a->pollset_count + b->pollset_count); - a->pollsets = static_cast(gpr_realloc( - a->pollsets, a->pollset_capacity * sizeof(*a->pollsets))); + a->pollsets = static_cast( + gpr_realloc(a->pollsets, a->pollset_capacity * sizeof(*a->pollsets))); } if (b->pollset_count > 0) { memcpy(a->pollsets + a->pollset_count, b->pollsets, diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 438b4c8c09..5c99c72aa5 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -368,8 +368,8 @@ static void polling_island_add_fds_locked(polling_island* pi, grpc_fd** fds, if (pi->fd_cnt == pi->fd_capacity) { pi->fd_capacity = GPR_MAX(pi->fd_capacity + 8, pi->fd_cnt * 3 / 2); - pi->fds = - static_cast(gpr_realloc(pi->fds, sizeof(grpc_fd*) * pi->fd_capacity)); + pi->fds = static_cast( + gpr_realloc(pi->fds, sizeof(grpc_fd*) * pi->fd_capacity)); } pi->fds[pi->fd_cnt++] = fds[i]; @@ -976,7 +976,8 @@ static grpc_error* pollset_worker_kick(grpc_pollset_worker* worker) { grpc_error* err = GRPC_ERROR_NONE; /* Kick the worker only if it was not already kicked */ - if (gpr_atm_no_barrier_cas(&worker->is_kicked, static_cast(0), static_cast(1))) { + if (gpr_atm_no_barrier_cas(&worker->is_kicked, static_cast(0), + static_cast(1))) { GRPC_POLLING_TRACE( "pollset_worker_kick: Kicking worker: %p (thread id: %ld)", (void*)worker, (long int)worker->pt_id); @@ -1538,7 +1539,8 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { */ static grpc_pollset_set* pollset_set_create(void) { - grpc_pollset_set* pss = static_cast(gpr_malloc(sizeof(*pss))); + grpc_pollset_set* pss = + static_cast(gpr_malloc(sizeof(*pss))); gpr_mu_init(&pss->po.mu); pss->po.pi = nullptr; #ifndef NDEBUG diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 769fdbc299..e92163322f 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -835,8 +835,8 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { if (pollset->fd_count == pollset->fd_capacity) { pollset->fd_capacity = GPR_MAX(pollset->fd_capacity + 8, pollset->fd_count * 3 / 2); - pollset->fds = static_cast(gpr_realloc( - pollset->fds, sizeof(grpc_fd*) * pollset->fd_capacity)); + pollset->fds = static_cast( + gpr_realloc(pollset->fds, sizeof(grpc_fd*) * pollset->fd_capacity)); } pollset->fds[pollset->fd_count++] = fd; GRPC_FD_REF(fd, "multipoller"); @@ -889,8 +889,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset, worker.wakeup_fd = pollset->local_wakeup_cache; pollset->local_wakeup_cache = worker.wakeup_fd->next; } else { - worker.wakeup_fd = - static_cast(gpr_malloc(sizeof(*worker.wakeup_fd))); + worker.wakeup_fd = static_cast( + gpr_malloc(sizeof(*worker.wakeup_fd))); error = grpc_wakeup_fd_init(&worker.wakeup_fd->fd); if (error != GRPC_ERROR_NONE) { GRPC_LOG_IF_ERROR("pollset_work", GRPC_ERROR_REF(error)); @@ -946,7 +946,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset, const size_t watch_size = sizeof(*watchers) * (pollset->fd_count + 2); void* buf = gpr_malloc(pfd_size + watch_size); pfds = static_cast(buf); - watchers = static_cast((void*)(static_cast(buf) + pfd_size)); + watchers = static_cast( + (void*)(static_cast(buf) + pfd_size)); } fd_count = 0; @@ -972,8 +973,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset, for (i = 1; i < pfd_count; i++) { grpc_fd* fd = watchers[i].fd; - pfds[i].events = static_cast(fd_begin_poll(fd, pollset, &worker, POLLIN, - POLLOUT, &watchers[i])); + pfds[i].events = static_cast( + fd_begin_poll(fd, pollset, &worker, POLLIN, POLLOUT, &watchers[i])); GRPC_FD_UNREF(fd, "multipoller_start"); } @@ -1222,9 +1223,9 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* bag, gpr_mu_lock(&bag->mu); if (bag->pollset_set_count == bag->pollset_set_capacity) { bag->pollset_set_capacity = GPR_MAX(8, 2 * bag->pollset_set_capacity); - bag->pollset_sets = static_cast(gpr_realloc( - bag->pollset_sets, - bag->pollset_set_capacity * sizeof(*bag->pollset_sets))); + bag->pollset_sets = static_cast( + gpr_realloc(bag->pollset_sets, + bag->pollset_set_capacity * sizeof(*bag->pollset_sets))); } bag->pollset_sets[bag->pollset_set_count++] = item; for (i = 0, j = 0; i < bag->fd_count; i++) { @@ -1259,8 +1260,9 @@ static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { gpr_mu_lock(&pollset_set->mu); if (pollset_set->fd_count == pollset_set->fd_capacity) { pollset_set->fd_capacity = GPR_MAX(8, 2 * pollset_set->fd_capacity); - pollset_set->fds = static_cast(gpr_realloc( - pollset_set->fds, pollset_set->fd_capacity * sizeof(*pollset_set->fds))); + pollset_set->fds = static_cast( + gpr_realloc(pollset_set->fds, + pollset_set->fd_capacity * sizeof(*pollset_set->fds))); } GRPC_FD_REF(fd, "pollset_set"); pollset_set->fds[pollset_set->fd_count++] = fd; @@ -1316,8 +1318,8 @@ static void init_result(poll_args* pargs) { gpr_ref_init(&pargs->result->refcount, 1); pargs->result->watchers = nullptr; pargs->result->watchcount = 0; - pargs->result->fds = - static_cast(gpr_malloc(sizeof(struct pollfd) * pargs->nfds)); + pargs->result->fds = static_cast( + gpr_malloc(sizeof(struct pollfd) * pargs->nfds)); memcpy(pargs->result->fds, pargs->fds, sizeof(struct pollfd) * pargs->nfds); pargs->result->nfds = pargs->nfds; pargs->result->retval = 0; @@ -1356,7 +1358,8 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) { return pargs; } - poll_args* pargs = static_cast(gpr_malloc(sizeof(struct poll_args))); + poll_args* pargs = + static_cast(gpr_malloc(sizeof(struct poll_args))); gpr_cv_init(&pargs->trigger); pargs->fds = fds; pargs->nfds = count; @@ -1514,7 +1517,8 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { gpr_cv pollcv_cv; gpr_cv_init(&pollcv_cv); pollcv->cv = &pollcv_cv; - grpc_cv_node* fd_cvs = static_cast(gpr_malloc(nfds * sizeof(grpc_cv_node))); + grpc_cv_node* fd_cvs = + static_cast(gpr_malloc(nfds * sizeof(grpc_cv_node))); for (i = 0; i < nfds; i++) { fds[i].revents = 0; @@ -1546,8 +1550,8 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { res = 0; if (!skip_poll && nsockfds > 0) { - struct pollfd* pollfds = - static_cast(gpr_malloc(sizeof(struct pollfd) * nsockfds)); + struct pollfd* pollfds = static_cast( + gpr_malloc(sizeof(struct pollfd) * nsockfds)); idx = 0; for (i = 0; i < nfds; i++) { if (fds[i].fd >= 0) { @@ -1610,8 +1614,8 @@ static void global_cv_fd_table_init() { gpr_cv_init(&g_cvfds.shutdown_cv); gpr_ref_init(&g_cvfds.pollcount, 1); g_cvfds.size = CV_DEFAULT_TABLE_SIZE; - g_cvfds.cvfds = - static_cast(gpr_malloc(sizeof(grpc_fd_node) * CV_DEFAULT_TABLE_SIZE)); + g_cvfds.cvfds = static_cast( + gpr_malloc(sizeof(grpc_fd_node) * CV_DEFAULT_TABLE_SIZE)); g_cvfds.free_fds = nullptr; thread_grace = gpr_time_from_millis(POLLCV_THREAD_GRACE_MS, GPR_TIMESPAN); for (int i = 0; i < CV_DEFAULT_TABLE_SIZE; i++) { @@ -1628,7 +1632,8 @@ static void global_cv_fd_table_init() { poll_cache.size = 32; poll_cache.count = 0; poll_cache.free_pollers = nullptr; - poll_cache.active_pollers = static_cast(gpr_malloc(sizeof(void*) * 32)); + poll_cache.active_pollers = + static_cast(gpr_malloc(sizeof(void*) * 32)); for (unsigned int i = 0; i < poll_cache.size; i++) { poll_cache.active_pollers[i] = nullptr; } diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 89c6a873e6..5401a94dd3 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -53,8 +53,8 @@ static gpr_timespec g_start_time; static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time); - double x = - GPR_MS_PER_SEC * static_cast(ts.tv_sec) + static_cast(ts.tv_nsec) / GPR_NS_PER_MS; + double x = GPR_MS_PER_SEC * static_cast(ts.tv_sec) + + static_cast(ts.tv_nsec) / GPR_NS_PER_MS; if (x < 0) return 0; if (x > GPR_ATM_MAX) return GPR_ATM_MAX; return static_cast(x); @@ -64,7 +64,8 @@ static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time); double x = GPR_MS_PER_SEC * static_cast(ts.tv_sec) + static_cast(ts.tv_nsec) / GPR_NS_PER_MS + - static_cast(GPR_NS_PER_SEC - 1) / static_cast(GPR_NS_PER_SEC); + static_cast(GPR_NS_PER_SEC - 1) / + static_cast(GPR_NS_PER_SEC); if (x < 0) return 0; if (x > GPR_ATM_MAX) return GPR_ATM_MAX; return static_cast(x); diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 901bbdd4df..16782dacc5 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -94,8 +94,8 @@ void grpc_executor_set_threading(bool threading) { g_max_threads = GPR_MAX(1, 2 * gpr_cpu_num_cores()); gpr_atm_no_barrier_store(&g_cur_threads, 1); gpr_tls_init(&g_this_thread_state); - g_thread_state = - static_cast(gpr_zalloc(sizeof(thread_state) * g_max_threads)); + g_thread_state = static_cast( + gpr_zalloc(sizeof(thread_state) * g_max_threads)); for (size_t i = 0; i < g_max_threads; i++) { gpr_mu_init(&g_thread_state[i].mu); gpr_cv_init(&g_thread_state[i].cv); @@ -170,7 +170,8 @@ static void executor_thread(void* arg) { ts->elems = GRPC_CLOSURE_LIST_INIT; gpr_mu_unlock(&ts->mu); if (executor_trace.enabled()) { - gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", static_cast(ts - g_thread_state)); + gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", + static_cast(ts - g_thread_state)); } grpc_core::ExecCtx::Get()->InvalidateNow(); @@ -188,7 +189,8 @@ static void executor_push(grpc_closure* closure, grpc_error* error, } do { retry_push = false; - size_t cur_thread_count = static_castgpr_atm_no_barrier_load(&g_cur_threads); + size_t cur_thread_count = + static_cast gpr_atm_no_barrier_load(&g_cur_threads); if (cur_thread_count == 0) { if (executor_trace.enabled()) { #ifndef NDEBUG @@ -255,7 +257,8 @@ static void executor_push(grpc_closure* closure, grpc_error* error, break; } if (try_new_thread && gpr_spinlock_trylock(&g_adding_thread_lock)) { - cur_thread_count = static_castgpr_atm_no_barrier_load(&g_cur_threads); + cur_thread_count = + static_cast gpr_atm_no_barrier_load(&g_cur_threads); if (cur_thread_count < g_max_threads) { gpr_atm_no_barrier_store(&g_cur_threads, cur_thread_count + 1); diff --git a/src/core/lib/iomgr/is_epollexclusive_available.cc b/src/core/lib/iomgr/is_epollexclusive_available.cc index a58a5775d3..542cc41e8f 100644 --- a/src/core/lib/iomgr/is_epollexclusive_available.cc +++ b/src/core/lib/iomgr/is_epollexclusive_available.cc @@ -61,7 +61,8 @@ bool grpc_is_epollexclusive_available(void) { /* choose events that should cause an error on EPOLLEXCLUSIVE enabled kernels - specifically the combination of EPOLLONESHOT and EPOLLEXCLUSIVE */ - ev.events = static_cast(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT); + ev.events = + static_cast(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT); ev.data.ptr = nullptr; if (epoll_ctl(fd, EPOLL_CTL_ADD, evfd, &ev) != 0) { if (errno != EINVAL) { diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc index 5e637ff8b5..7f5f642c98 100644 --- a/src/core/lib/iomgr/load_file.cc +++ b/src/core/lib/iomgr/load_file.cc @@ -47,8 +47,8 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator, /* Converting to size_t on the assumption that it will not fail */ contents_size = static_cast(ftell(file)); fseek(file, 0, SEEK_SET); - contents = - static_cast(gpr_malloc(contents_size + (add_null_terminator ? 1 : 0))); + contents = static_cast( + gpr_malloc(contents_size + (add_null_terminator ? 1 : 0))); bytes_read = fread(contents, 1, contents_size, file); if (bytes_read < contents_size) { error = GRPC_OS_ERROR(errno, "fread"); diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index b49b080c12..dd5363dc0a 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -114,14 +114,14 @@ static grpc_error* blocking_resolve_address_impl( } /* Success path: set addrs non-NULL, fill it in */ - *addresses = - static_cast(gpr_malloc(sizeof(grpc_resolved_addresses))); + *addresses = static_cast( + gpr_malloc(sizeof(grpc_resolved_addresses))); (*addresses)->naddrs = 0; for (resp = result; resp != nullptr; resp = resp->ai_next) { (*addresses)->naddrs++; } - (*addresses)->addrs = static_cast(gpr_malloc( - sizeof(grpc_resolved_address) * (*addresses)->naddrs)); + (*addresses)->addrs = static_cast( + gpr_malloc(sizeof(grpc_resolved_address) * (*addresses)->naddrs)); i = 0; for (resp = result; resp != nullptr; resp = resp->ai_next) { memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index 40dd29b6a4..da310694ef 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -419,8 +419,8 @@ static const grpc_slice_refcount_vtable ru_slice_vtable = { static grpc_slice ru_slice_create(grpc_resource_user* resource_user, size_t size) { - ru_slice_refcount* rc = - static_cast(gpr_malloc(sizeof(ru_slice_refcount) + size)); + ru_slice_refcount* rc = static_cast( + gpr_malloc(sizeof(ru_slice_refcount) + size)); rc->base.vtable = &ru_slice_vtable; rc->base.sub_refcount = &rc->base; gpr_ref_init(&rc->refs, 1); @@ -659,7 +659,8 @@ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, } size_t grpc_resource_quota_peek_size(grpc_resource_quota* resource_quota) { - return static_castgpr_atm_no_barrier_load(&resource_quota->last_size); + return static_cast gpr_atm_no_barrier_load( + &resource_quota->last_size); } /******************************************************************************* @@ -672,7 +673,8 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args( if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { if (channel_args->args[i].type == GRPC_ARG_POINTER) { return grpc_resource_quota_ref_internal( - static_cast(channel_args->args[i].value.pointer.p)); + static_cast( + channel_args->args[i].value.pointer.p)); } else { gpr_log(GPR_DEBUG, GRPC_ARG_RESOURCE_QUOTA " should be a pointer"); } diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc index 06f080376a..69be87168e 100644 --- a/src/core/lib/iomgr/sockaddr_utils.cc +++ b/src/core/lib/iomgr/sockaddr_utils.cc @@ -39,13 +39,15 @@ static const uint8_t kV4MappedPrefix[] = {0, 0, 0, 0, 0, 0, int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr4_out) { GPR_ASSERT(resolved_addr != resolved_addr4_out); - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); struct sockaddr_in* addr4_out = resolved_addr4_out == nullptr ? nullptr : reinterpret_cast(resolved_addr4_out->addr); if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = reinterpret_cast(addr); + const struct sockaddr_in6* addr6 = + reinterpret_cast(addr); if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix, sizeof(kV4MappedPrefix)) == 0) { if (resolved_addr4_out != nullptr) { @@ -66,11 +68,13 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, int grpc_sockaddr_to_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr6_out) { GPR_ASSERT(resolved_addr != resolved_addr6_out); - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); struct sockaddr_in6* addr6_out = reinterpret_cast(resolved_addr6_out->addr); if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = reinterpret_cast(addr); + const struct sockaddr_in* addr4 = + reinterpret_cast(addr); memset(resolved_addr6_out, 0, sizeof(*resolved_addr6_out)); addr6_out->sin6_family = AF_INET6; memcpy(&addr6_out->sin6_addr.s6_addr[0], kV4MappedPrefix, 12); @@ -92,7 +96,8 @@ int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr, addr = reinterpret_cast(resolved_addr->addr); if (addr->sa_family == AF_INET) { /* Check for 0.0.0.0 */ - const struct sockaddr_in* addr4 = reinterpret_cast(addr); + const struct sockaddr_in* addr4 = + reinterpret_cast(addr); if (addr4->sin_addr.s_addr != 0) { return 0; } @@ -100,7 +105,8 @@ int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr, return 1; } else if (addr->sa_family == AF_INET6) { /* Check for :: */ - const struct sockaddr_in6* addr6 = reinterpret_cast(addr); + const struct sockaddr_in6* addr6 = + reinterpret_cast(addr); int i; for (i = 0; i < 16; i++) { if (addr6->sin6_addr.s6_addr[i] != 0) { @@ -122,7 +128,8 @@ void grpc_sockaddr_make_wildcards(int port, grpc_resolved_address* wild4_out, void grpc_sockaddr_make_wildcard4(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in* wild_out = reinterpret_cast(resolved_wild_out->addr); + struct sockaddr_in* wild_out = + reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); wild_out->sin_family = AF_INET; @@ -132,7 +139,8 @@ void grpc_sockaddr_make_wildcard4(int port, void grpc_sockaddr_make_wildcard6(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in6* wild_out = reinterpret_cast(resolved_wild_out->addr); + struct sockaddr_in6* wild_out = + reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); wild_out->sin6_family = AF_INET6; @@ -158,11 +166,13 @@ int grpc_sockaddr_to_string(char** out, } addr = reinterpret_cast(resolved_addr->addr); if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = reinterpret_cast(addr); + const struct sockaddr_in* addr4 = + reinterpret_cast(addr); ip = &addr4->sin_addr; port = ntohs(addr4->sin_port); } else if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = reinterpret_cast(addr); + const struct sockaddr_in6* addr6 = + reinterpret_cast(addr); ip = &addr6->sin6_addr; port = ntohs(addr6->sin6_port); sin6_scope_id = addr6->sin6_scope_id; @@ -208,7 +218,8 @@ char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) { const char* grpc_sockaddr_get_uri_scheme( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case AF_INET: return "ipv4"; @@ -221,12 +232,14 @@ const char* grpc_sockaddr_get_uri_scheme( } int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); return addr->sa_family; } int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case AF_INET: return ntohs(((struct sockaddr_in*)addr)->sin_port); @@ -244,15 +257,18 @@ int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { int grpc_sockaddr_set_port(const grpc_resolved_address* resolved_addr, int port) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { case AF_INET: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in*)addr)->sin_port = htons(static_cast(port)); + ((struct sockaddr_in*)addr)->sin_port = + htons(static_cast(port)); return 1; case AF_INET6: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in6*)addr)->sin6_port = htons(static_cast(port)); + ((struct sockaddr_in6*)addr)->sin6_port = + htons(static_cast(port)); return 1; default: gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 2668aa6d10..a0cca6195b 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -218,7 +218,8 @@ static void probe_ipv6_once(void) { memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr[15] = 1; /* [::1]:0 */ - if (bind(fd, reinterpret_cast(&addr), sizeof(addr)) == 0) { + if (bind(fd, reinterpret_cast(&addr), sizeof(addr)) == + 0) { g_ipv6_loopback_available = 1; } else { gpr_log(GPR_INFO, @@ -278,7 +279,8 @@ static int create_socket(grpc_socket_factory* factory, int domain, int type, grpc_error* grpc_create_dualstack_socket_using_factory( grpc_socket_factory* factory, const grpc_resolved_address* resolved_addr, int type, int protocol, grpc_dualstack_mode* dsmode, int* newfd) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); int family = addr->sa_family; if (family == AF_INET6) { if (grpc_ipv6_loopback_available()) { diff --git a/src/core/lib/iomgr/socket_utils_linux.cc b/src/core/lib/iomgr/socket_utils_linux.cc index edb5274e0e..e8bf05c3a8 100644 --- a/src/core/lib/iomgr/socket_utils_linux.cc +++ b/src/core/lib/iomgr/socket_utils_linux.cc @@ -35,7 +35,8 @@ int grpc_accept4(int sockfd, grpc_resolved_address* resolved_addr, int nonblock, GPR_ASSERT(resolved_addr->len <= (socklen_t)-1); flags |= nonblock ? SOCK_NONBLOCK : 0; flags |= cloexec ? SOCK_CLOEXEC : 0; - return accept4(sockfd, reinterpret_cast(resolved_addr->addr), + return accept4(sockfd, + reinterpret_cast(resolved_addr->addr), reinterpret_cast(&resolved_addr->len), flags); } diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 8d08127915..33a0b0404d 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -79,8 +79,8 @@ static grpc_error* prepare_socket(const grpc_resolved_address* addr, int fd, for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_SOCKET_MUTATOR)) { GPR_ASSERT(channel_args->args[i].type == GRPC_ARG_POINTER); - grpc_socket_mutator* mutator = - static_cast(channel_args->args[i].value.pointer.p); + grpc_socket_mutator* mutator = static_cast( + channel_args->args[i].value.pointer.p); err = grpc_set_socket_with_mutator(fd, mutator); if (err != GRPC_ERROR_NONE) goto error; } @@ -291,7 +291,8 @@ void grpc_tcp_client_create_from_prepared_fd( async_connect* ac; do { GPR_ASSERT(addr->len < ~(socklen_t)0); - err = connect(fd, reinterpret_cast(addr->addr), static_cast(addr->len)); + err = connect(fd, reinterpret_cast(addr->addr), + static_cast(addr->len)); } while (err < 0 && errno == EINTR); if (err >= 0) { char* addr_str = grpc_sockaddr_to_uri(addr); diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 71819adaba..50efd04382 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -165,8 +165,8 @@ static void drop_uncovered(grpc_tcp* tcp) { gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1); if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, static_cast(old_count), - static_cast(old_count) - 1); + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, + static_cast(old_count), static_cast(old_count) - 1); } GPR_ASSERT(old_count != 1); } @@ -176,12 +176,13 @@ static void cover_self(grpc_tcp* tcp) { gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2); if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", static_cast(old_count), - 2 + static_cast(old_count)); + gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", + static_cast(old_count), 2 + static_cast(old_count)); } if (old_count == 0) { GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(); - p = static_cast(gpr_zalloc(sizeof(*p) + grpc_pollset_size())); + p = static_cast( + gpr_zalloc(sizeof(*p) + grpc_pollset_size())); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p); } @@ -257,8 +258,8 @@ static size_t get_target_read_size(grpc_tcp* tcp) { double pressure = grpc_resource_quota_get_memory_pressure(rq); double target = tcp->target_length * (pressure > 0.8 ? (1.0 - pressure) / 0.2 : 1.0); - size_t sz = ((static_castGPR_CLAMP(target, tcp->min_read_chunk_size, - tcp->max_read_chunk_size)) + + size_t sz = ((static_cast GPR_CLAMP(target, tcp->min_read_chunk_size, + tcp->max_read_chunk_size)) + 255) & ~static_cast(255); /* don't use more than 1/16th of the overall resource quota for a single read @@ -733,27 +734,25 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) { - grpc_integer_options options = {tcp_read_chunk_size, 1, - MAX_CHUNK_SIZE}; + grpc_integer_options options = {tcp_read_chunk_size, 1, MAX_CHUNK_SIZE}; tcp_read_chunk_size = grpc_channel_arg_get_integer(&channel_args->args[i], options); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE)) { - grpc_integer_options options = {tcp_read_chunk_size, 1, - MAX_CHUNK_SIZE}; + grpc_integer_options options = {tcp_read_chunk_size, 1, MAX_CHUNK_SIZE}; tcp_min_read_chunk_size = grpc_channel_arg_get_integer(&channel_args->args[i], options); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE)) { - grpc_integer_options options = {tcp_read_chunk_size, 1, - MAX_CHUNK_SIZE}; + grpc_integer_options options = {tcp_read_chunk_size, 1, MAX_CHUNK_SIZE}; tcp_max_read_chunk_size = grpc_channel_arg_get_integer(&channel_args->args[i], options); } else 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( - static_cast(channel_args->args[i].value.pointer.p)); + resource_quota = + grpc_resource_quota_ref_internal(static_cast( + channel_args->args[i].value.pointer.p)); } } } diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index f8f94e3fbb..fe6108e4ac 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -72,7 +72,8 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, grpc_tcp_server** server) { gpr_once_init(&check_init, init); - grpc_tcp_server* s = static_cast(gpr_zalloc(sizeof(grpc_tcp_server))); + grpc_tcp_server* s = + static_cast(gpr_zalloc(sizeof(grpc_tcp_server))); s->so_reuseport = has_so_reuseport; s->expand_wildcard_addrs = false; for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) { @@ -410,8 +411,10 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, if (requested_port == 0) { for (sp = s->head; sp; sp = sp->next) { sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == getsockname(sp->fd, reinterpret_cast(&sockname_temp.addr), - reinterpret_cast(&sockname_temp.len))) { + if (0 == + getsockname(sp->fd, + reinterpret_cast(&sockname_temp.addr), + reinterpret_cast(&sockname_temp.len))) { int used_port = grpc_sockaddr_get_port(&sockname_temp); if (used_port > 0) { memcpy(&sockname_temp, addr, sizeof(grpc_resolved_address)); diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index e98ebb7813..be2a00a9dc 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -169,7 +169,9 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd, if (err != GRPC_ERROR_NONE) goto error; GPR_ASSERT(addr->len < ~(socklen_t)0); - if (bind(fd, reinterpret_cast(const_cast(addr->addr)), static_cast(addr->len)) < 0) { + if (bind(fd, + reinterpret_cast(const_cast(addr->addr)), + static_cast(addr->len)) < 0) { err = GRPC_OS_ERROR(errno, "bind"); goto error; } diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index 5470dbcff7..612c2584bc 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -66,13 +66,14 @@ static grpc_error* get_unused_port(int* port) { if (dsmode == GRPC_DSMODE_IPV4) { grpc_sockaddr_make_wildcard4(0, &wild); } - if (bind(fd, reinterpret_cast(wild.addr), static_cast(wild.len)) != 0) { + if (bind(fd, reinterpret_cast(wild.addr), + static_cast(wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "bind"); close(fd); return err; } - if (getsockname(fd, reinterpret_cast(wild.addr), reinterpret_cast(&wild.len)) != - 0) { + if (getsockname(fd, reinterpret_cast(wild.addr), + reinterpret_cast(&wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "getsockname"); close(fd); return err; diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index b47c12b689..697162f7a8 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -240,9 +240,10 @@ void grpc_timer_list_init() { uint32_t i; g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores()); - g_shards = static_cast(gpr_zalloc(g_num_shards * sizeof(*g_shards))); - g_shard_queue = - static_cast(gpr_zalloc(g_num_shards * sizeof(*g_shard_queue))); + g_shards = + static_cast(gpr_zalloc(g_num_shards * sizeof(*g_shards))); + g_shard_queue = static_cast( + gpr_zalloc(g_num_shards * sizeof(*g_shard_queue))); g_shared_mutables.initialized = true; g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER; @@ -359,8 +360,8 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, return; } - grpc_time_averaged_stats_add_sample(&shard->stats, - static_cast(deadline - now) / 1000.0); + grpc_time_averaged_stats_add_sample( + &shard->stats, static_cast(deadline - now) / 1000.0); ADD_TO_HASH_TABLE(timer); diff --git a/src/core/lib/iomgr/timer_heap.cc b/src/core/lib/iomgr/timer_heap.cc index 9aedfd3755..c26896ee4a 100644 --- a/src/core/lib/iomgr/timer_heap.cc +++ b/src/core/lib/iomgr/timer_heap.cc @@ -74,8 +74,8 @@ static void maybe_shrink(grpc_timer_heap* heap) { if (heap->timer_count >= 8 && heap->timer_count <= heap->timer_capacity / SHRINK_FULLNESS_FACTOR / 2) { heap->timer_capacity = heap->timer_count * SHRINK_FULLNESS_FACTOR; - heap->timers = static_cast(gpr_realloc( - heap->timers, heap->timer_capacity * sizeof(grpc_timer*))); + heap->timers = static_cast( + gpr_realloc(heap->timers, heap->timer_capacity * sizeof(grpc_timer*))); } } @@ -99,8 +99,8 @@ int grpc_timer_heap_add(grpc_timer_heap* heap, grpc_timer* timer) { if (heap->timer_count == heap->timer_capacity) { heap->timer_capacity = GPR_MAX(heap->timer_capacity + 1, heap->timer_capacity * 3 / 2); - heap->timers = static_cast(gpr_realloc( - heap->timers, heap->timer_capacity * sizeof(grpc_timer*))); + heap->timers = static_cast( + gpr_realloc(heap->timers, heap->timer_capacity * sizeof(grpc_timer*))); } timer->heap_index = heap->timer_count; adjust_upwards(heap->timers, heap->timer_count, timer); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 4cefb7fc9f..a528c22264 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -86,7 +86,8 @@ static void start_timer_thread_and_unlock(void) { } gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - completed_thread* ct = static_cast(gpr_malloc(sizeof(*ct))); + completed_thread* ct = + static_cast(gpr_malloc(sizeof(*ct))); // The call to gpr_thd_new() has to be under the same lock used by // gc_completed_threads(), particularly due to ct->t, which is written here // (internally by gpr_thd_new) and read there. Otherwise it's possible for ct diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index 9fabb898de..eecb3b09d9 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -139,7 +139,8 @@ static grpc_socket_factory* get_socket_factory(const grpc_channel_args* args) { } grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { - grpc_udp_server* s = static_cast(gpr_malloc(sizeof(grpc_udp_server))); + grpc_udp_server* s = + static_cast(gpr_malloc(sizeof(grpc_udp_server))); gpr_mu_init(&s->mu); s->socket_factory = get_socket_factory(args); if (s->socket_factory) { @@ -156,7 +157,8 @@ grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { } static void shutdown_fd(void* args, grpc_error* error) { - struct shutdown_fd_args* shutdown_args = static_cast(args); + struct shutdown_fd_args* shutdown_args = + static_cast(args); grpc_udp_listener* sp = shutdown_args->sp; gpr_log(GPR_DEBUG, "shutdown fd %d", sp->fd); gpr_mu_lock(shutdown_args->server_mu); @@ -279,7 +281,10 @@ static int bind_socket(grpc_socket_factory* socket_factory, int sockfd, const grpc_resolved_address* addr) { return (socket_factory != nullptr) ? grpc_socket_factory_bind(socket_factory, sockfd, addr) - : bind(sockfd, reinterpret_cast(const_cast(addr->addr)), static_cast(addr->len)); + : bind(sockfd, + reinterpret_cast( + const_cast(addr->addr)), + static_cast(addr->len)); } /* Prepare a recently-created socket for listening. */ @@ -287,7 +292,8 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, const grpc_resolved_address* addr, int rcv_buf_size, int snd_buf_size) { grpc_resolved_address sockname_temp; - struct sockaddr* addr_ptr = reinterpret_cast(const_cast(addr->addr)); + struct sockaddr* addr_ptr = + reinterpret_cast(const_cast(addr->addr)); if (fd < 0) { goto error; @@ -530,12 +536,14 @@ int grpc_udp_server_add_port(grpc_udp_server* s, if (grpc_sockaddr_get_port(addr) == 0) { for (sp = s->head; sp; sp = sp->next) { sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == getsockname(sp->fd, reinterpret_cast(sockname_temp.addr), - reinterpret_cast(&sockname_temp.len))) { + if (0 == + getsockname(sp->fd, + reinterpret_cast(sockname_temp.addr), + reinterpret_cast(&sockname_temp.len))) { port = grpc_sockaddr_get_port(&sockname_temp); if (port > 0) { - allocated_addr = - static_cast(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; diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 90ed06b7d5..b603916c47 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -51,11 +51,11 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name, gpr_free(err_msg); return err; } - *addrs = - static_cast(gpr_malloc(sizeof(grpc_resolved_addresses))); + *addrs = static_cast( + gpr_malloc(sizeof(grpc_resolved_addresses))); (*addrs)->naddrs = 1; - (*addrs)->addrs = - static_cast(gpr_malloc(sizeof(grpc_resolved_address))); + (*addrs)->addrs = static_cast( + gpr_malloc(sizeof(grpc_resolved_address))); un = reinterpret_cast((*addrs)->addrs->addr); un->sun_family = AF_UNIX; strncpy(un->sun_path, name, sizeof(un->sun_path)); @@ -64,17 +64,20 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name, } int grpc_is_unix_socket(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); return addr->sa_family == AF_UNIX; } void grpc_unlink_if_unix_domain_socket( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return; } - struct sockaddr_un* un = reinterpret_cast(const_cast(resolved_addr->addr)); + struct sockaddr_un* un = reinterpret_cast( + const_cast(resolved_addr->addr)); struct stat st; if (stat(un->sun_path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) { @@ -84,7 +87,8 @@ void grpc_unlink_if_unix_domain_socket( char* grpc_sockaddr_to_uri_unix_if_possible( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = reinterpret_cast(resolved_addr->addr); + const struct sockaddr* addr = + reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return nullptr; } diff --git a/src/core/lib/iomgr/wakeup_fd_cv.cc b/src/core/lib/iomgr/wakeup_fd_cv.cc index 80f07ccf23..59718243e0 100644 --- a/src/core/lib/iomgr/wakeup_fd_cv.cc +++ b/src/core/lib/iomgr/wakeup_fd_cv.cc @@ -43,8 +43,8 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) { gpr_mu_lock(&g_cvfds.mu); if (!g_cvfds.free_fds) { newsize = GPR_MIN(g_cvfds.size * 2, g_cvfds.size + MAX_TABLE_RESIZE); - g_cvfds.cvfds = static_cast(gpr_realloc(g_cvfds.cvfds, - sizeof(grpc_fd_node) * newsize)); + g_cvfds.cvfds = static_cast( + gpr_realloc(g_cvfds.cvfds, sizeof(grpc_fd_node) * newsize)); for (i = g_cvfds.size; i < newsize; i++) { g_cvfds.cvfds[i].is_set = 0; g_cvfds.cvfds[i].cvs = nullptr; diff --git a/src/core/lib/json/json_reader.cc b/src/core/lib/json/json_reader.cc index 019214a167..6dadea5006 100644 --- a/src/core/lib/json/json_reader.cc +++ b/src/core/lib/json/json_reader.cc @@ -417,8 +417,10 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { } else { return GRPC_JSON_PARSE_ERROR; } - reader->unicode_char = static_cast(reader->unicode_char << 4); - reader->unicode_char = static_cast(reader->unicode_char | c); + reader->unicode_char = + static_cast(reader->unicode_char << 4); + reader->unicode_char = + static_cast(reader->unicode_char | c); switch (reader->state) { case GRPC_JSON_STATE_STRING_ESCAPE_U1: diff --git a/src/core/lib/json/json_string.cc b/src/core/lib/json/json_string.cc index dcaf11d0c9..8200900956 100644 --- a/src/core/lib/json/json_string.cc +++ b/src/core/lib/json/json_string.cc @@ -68,7 +68,8 @@ static void json_writer_output_check(void* userdata, size_t needed) { needed -= state->free_space; /* Round up by 256 bytes. */ needed = (needed + 0xff) & ~0xffU; - state->output = static_cast(gpr_realloc(state->output, state->allocated + needed)); + state->output = + static_cast(gpr_realloc(state->output, state->allocated + needed)); state->free_space += needed; state->allocated += needed; } diff --git a/src/core/lib/json/json_writer.cc b/src/core/lib/json/json_writer.cc index df49cbe4dc..6d442b8716 100644 --- a/src/core/lib/json/json_writer.cc +++ b/src/core/lib/json/json_writer.cc @@ -179,8 +179,10 @@ static void json_writer_escape_string(grpc_json_writer* writer, * That range is exactly 20 bits. */ utf32 -= 0x10000; - json_writer_escape_utf16(writer, static_cast(0xd800 | (utf32 >> 10))); - json_writer_escape_utf16(writer, static_cast(0xdc00 | (utf32 & 0x3ff))); + json_writer_escape_utf16(writer, + static_cast(0xd800 | (utf32 >> 10))); + json_writer_escape_utf16( + writer, static_cast(0xdc00 | (utf32 & 0x3ff))); } else { json_writer_escape_utf16(writer, static_cast(utf32)); } diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index cd8fabea28..c7e212bb21 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -44,8 +44,8 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, gpr_log(GPR_ERROR, "Method is client-side only."); return GRPC_CALL_ERROR_NOT_ON_SERVER; } - ctx = static_cast(grpc_call_context_get( - call, GRPC_CONTEXT_SECURITY)); + ctx = static_cast( + grpc_call_context_get(call, GRPC_CONTEXT_SECURITY)); if (ctx == nullptr) { ctx = grpc_client_security_context_create(); ctx->creds = grpc_call_credentials_ref(creds); @@ -80,13 +80,14 @@ void grpc_auth_context_release(grpc_auth_context* context) { /* --- grpc_client_security_context --- */ grpc_client_security_context* grpc_client_security_context_create(void) { - return static_cast(gpr_zalloc( - sizeof(grpc_client_security_context))); + return static_cast( + gpr_zalloc(sizeof(grpc_client_security_context))); } void grpc_client_security_context_destroy(void* ctx) { grpc_core::ExecCtx exec_ctx; - grpc_client_security_context* c = static_cast(ctx); + grpc_client_security_context* c = + static_cast(ctx); grpc_call_credentials_unref(c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { @@ -98,12 +99,13 @@ void grpc_client_security_context_destroy(void* ctx) { /* --- grpc_server_security_context --- */ grpc_server_security_context* grpc_server_security_context_create(void) { - return static_cast(gpr_zalloc( - sizeof(grpc_server_security_context))); + return static_cast( + gpr_zalloc(sizeof(grpc_server_security_context))); } void grpc_server_security_context_destroy(void* ctx) { - grpc_server_security_context* c = static_cast(ctx); + grpc_server_security_context* c = + static_cast(ctx); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context"); if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); @@ -258,9 +260,9 @@ static void ensure_auth_context_capacity(grpc_auth_context* ctx) { if (ctx->properties.count == ctx->properties.capacity) { ctx->properties.capacity = GPR_MAX(ctx->properties.capacity + 8, ctx->properties.capacity * 2); - ctx->properties.array = static_cast(gpr_realloc( - ctx->properties.array, - ctx->properties.capacity * sizeof(grpc_auth_property))); + ctx->properties.array = static_cast( + gpr_realloc(ctx->properties.array, + ctx->properties.capacity * sizeof(grpc_auth_property))); } } diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc index 248177a178..ea2c4e208f 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.cc +++ b/src/core/lib/security/credentials/composite/composite_credentials.cc @@ -40,7 +40,8 @@ typedef struct { } grpc_composite_call_credentials_metadata_context; static void composite_call_destruct(grpc_call_credentials* creds) { - grpc_composite_call_credentials* c = reinterpret_cast(creds); + grpc_composite_call_credentials* c = + reinterpret_cast(creds); for (size_t i = 0; i < c->inner.num_creds; i++) { grpc_call_credentials_unref(c->inner.creds_array[i]); } @@ -75,10 +76,11 @@ static bool composite_call_get_request_metadata( grpc_auth_metadata_context auth_md_context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_composite_call_credentials* c = reinterpret_cast(creds); + grpc_composite_call_credentials* c = + reinterpret_cast(creds); grpc_composite_call_credentials_metadata_context* ctx; - ctx = static_cast(gpr_zalloc( - sizeof(grpc_composite_call_credentials_metadata_context))); + ctx = static_cast( + gpr_zalloc(sizeof(grpc_composite_call_credentials_metadata_context))); ctx->composite_creds = c; ctx->pollent = pollent; ctx->auth_md_context = auth_md_context; @@ -106,7 +108,8 @@ static bool composite_call_get_request_metadata( static void composite_call_cancel_get_request_metadata( grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_error* error) { - grpc_composite_call_credentials* c = reinterpret_cast(creds); + grpc_composite_call_credentials* c = + reinterpret_cast(creds); for (size_t i = 0; i < c->inner.num_creds; ++i) { grpc_call_credentials_cancel_get_request_metadata( c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error)); @@ -145,8 +148,8 @@ grpc_call_credentials* grpc_composite_call_credentials_create( GPR_ASSERT(reserved == nullptr); GPR_ASSERT(creds1 != nullptr); GPR_ASSERT(creds2 != nullptr); - c = static_cast(gpr_zalloc( - sizeof(grpc_composite_call_credentials))); + c = static_cast( + gpr_zalloc(sizeof(grpc_composite_call_credentials))); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE; c->base.vtable = &composite_call_credentials_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index c1ca881292..17f7de58be 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -40,8 +40,8 @@ grpc_credentials_metadata_request* grpc_credentials_metadata_request_create( grpc_call_credentials* creds) { grpc_credentials_metadata_request* r = - static_cast(gpr_zalloc( - sizeof(grpc_credentials_metadata_request))); + static_cast( + gpr_zalloc(sizeof(grpc_credentials_metadata_request))); r->creds = grpc_call_credentials_ref(creds); return r; } @@ -149,7 +149,8 @@ static void credentials_pointer_arg_destroy(void* p) { } static void* credentials_pointer_arg_copy(void* p) { - return grpc_channel_credentials_ref(static_cast(p)); + return grpc_channel_credentials_ref( + static_cast(p)); } static int credentials_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); } diff --git a/src/core/lib/security/credentials/credentials_metadata.cc b/src/core/lib/security/credentials/credentials_metadata.cc index 76e856f48e..250e384155 100644 --- a/src/core/lib/security/credentials/credentials_metadata.cc +++ b/src/core/lib/security/credentials/credentials_metadata.cc @@ -33,8 +33,8 @@ static void mdelem_list_ensure_capacity(grpc_credentials_mdelem_array* list, while (new_size < target_size) { new_size *= 2; } - list->md = - static_cast(gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size)); + list->md = static_cast( + gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size)); } void grpc_credentials_mdelem_array_add(grpc_credentials_mdelem_array* list, diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc index b4f0dfdbdc..3b29db2efa 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.cc +++ b/src/core/lib/security/credentials/fake/fake_credentials.cc @@ -59,8 +59,8 @@ static grpc_server_credentials_vtable grpc_channel_credentials* grpc_fake_transport_security_credentials_create( void) { - grpc_channel_credentials* c = - static_cast(gpr_zalloc(sizeof(grpc_channel_credentials))); + grpc_channel_credentials* c = static_cast( + gpr_zalloc(sizeof(grpc_channel_credentials))); c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY; c->vtable = &fake_transport_security_credentials_vtable; gpr_ref_init(&c->refcount, 1); @@ -69,8 +69,8 @@ grpc_channel_credentials* grpc_fake_transport_security_credentials_create( grpc_server_credentials* grpc_fake_transport_security_server_credentials_create( void) { - grpc_server_credentials* c = - static_cast(gpr_malloc(sizeof(grpc_server_credentials))); + grpc_server_credentials* c = static_cast( + gpr_malloc(sizeof(grpc_server_credentials))); memset(c, 0, sizeof(grpc_server_credentials)); c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY; gpr_ref_init(&c->refcount, 1); @@ -97,7 +97,8 @@ const char* grpc_fake_transport_get_expected_targets( /* -- Metadata-only test credentials. -- */ static void md_only_test_destruct(grpc_call_credentials* creds) { - grpc_md_only_test_credentials* c = reinterpret_cast(creds); + grpc_md_only_test_credentials* c = + reinterpret_cast(creds); GRPC_MDELEM_UNREF(c->md); } @@ -105,7 +106,8 @@ static bool md_only_test_get_request_metadata( grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_md_only_test_credentials* c = reinterpret_cast(creds); + grpc_md_only_test_credentials* c = + reinterpret_cast(creds); grpc_credentials_mdelem_array_add(md_array, c->md); if (c->is_async) { GRPC_CLOSURE_SCHED(on_request_metadata, GRPC_ERROR_NONE); @@ -126,8 +128,9 @@ static grpc_call_credentials_vtable md_only_test_vtable = { grpc_call_credentials* grpc_md_only_test_credentials_create( const char* md_key, const char* md_value, bool is_async) { - grpc_md_only_test_credentials* c = static_cast(gpr_zalloc( - sizeof(grpc_md_only_test_credentials))); + grpc_md_only_test_credentials* c = + static_cast( + gpr_zalloc(sizeof(grpc_md_only_test_credentials))); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2; c->base.vtable = &md_only_test_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index dd7d52d750..65455f94b3 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -60,7 +60,8 @@ typedef struct { static void on_compute_engine_detection_http_response(void* user_data, grpc_error* error) { - compute_engine_detector* detector = static_cast(user_data); + compute_engine_detector* detector = + static_cast(user_data); if (error == GRPC_ERROR_NONE && detector->response.status == 200 && detector->response.hdr_count > 0) { /* Internet providers can return a generic response to all requests, so @@ -98,7 +99,8 @@ static int is_stack_running_on_compute_engine() { on compute engine. */ grpc_millis max_detection_delay = GPR_MS_PER_SEC; - grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset* pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &g_polling_mu); detector.pollent = grpc_polling_entity_create_from_pollset(pollset); detector.is_done = 0; @@ -171,7 +173,8 @@ static grpc_error* create_default_creds_from_path( goto end; } json = grpc_json_parse_string_with_len( - reinterpret_castGRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data)); + reinterpret_cast GRPC_SLICE_START_PTR(creds_data), + GRPC_SLICE_LENGTH(creds_data)); if (json == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"), diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 20f4ff95f5..7f19fbc785 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -28,7 +28,8 @@ #include static void iam_destruct(grpc_call_credentials* creds) { - grpc_google_iam_credentials* c = reinterpret_cast(creds); + grpc_google_iam_credentials* c = + reinterpret_cast(creds); grpc_credentials_mdelem_array_destroy(&c->md_array); } @@ -38,7 +39,8 @@ static bool iam_get_request_metadata(grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_google_iam_credentials* c = reinterpret_cast(creds); + grpc_google_iam_credentials* c = + reinterpret_cast(creds); grpc_credentials_mdelem_array_append(md_array, &c->md_array); return true; } diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc index eae1be17fd..f7c9f57808 100644 --- a/src/core/lib/security/credentials/jwt/json_token.cc +++ b/src/core/lib/security/credentials/jwt/json_token.cc @@ -219,7 +219,8 @@ static char* dot_concat_and_free_strings(char* str1, char* str2) { size_t str1_len = strlen(str1); size_t str2_len = strlen(str2); size_t result_len = str1_len + 1 /* dot */ + str2_len; - char* result = static_cast(gpr_malloc(result_len + 1 /* NULL terminated */)); + char* result = + static_cast(gpr_malloc(result_len + 1 /* NULL terminated */)); char* current = result; memcpy(current, str1, str1_len); current += str1_len; diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index 44101acd78..05c08a68b0 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -123,8 +123,8 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key( gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); return nullptr; } - c = static_cast(gpr_zalloc( - sizeof(grpc_service_account_jwt_access_credentials))); + c = static_cast( + gpr_zalloc(sizeof(grpc_service_account_jwt_access_credentials))); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_JWT; gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &jwt_vtable; diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 3d7541f4c9..f5c1ada6ca 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -82,8 +82,9 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, gpr_log(GPR_ERROR, "Invalid base64."); return nullptr; } - json = grpc_json_parse_string_with_len(reinterpret_castGRPC_SLICE_START_PTR(*buffer), - GRPC_SLICE_LENGTH(*buffer)); + json = grpc_json_parse_string_with_len( + reinterpret_cast GRPC_SLICE_START_PTR(*buffer), + GRPC_SLICE_LENGTH(*buffer)); if (json == nullptr) { grpc_slice_unref_internal(*buffer); gpr_log(GPR_ERROR, "JSON parsing error."); @@ -347,7 +348,8 @@ static verifier_cb_ctx* verifier_cb_ctx_create( const char* signed_jwt, size_t signed_jwt_len, void* user_data, grpc_jwt_verification_done_cb cb) { grpc_core::ExecCtx exec_ctx; - verifier_cb_ctx* ctx = static_cast(gpr_zalloc(sizeof(verifier_cb_ctx))); + verifier_cb_ctx* ctx = + static_cast(gpr_zalloc(sizeof(verifier_cb_ctx))); ctx->verifier = verifier; ctx->pollent = grpc_polling_entity_create_from_pollset(pollset); ctx->header = header; @@ -754,8 +756,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( + (void*)email_domain, '.', static_cast(dot - email_domain))); if (dot == nullptr) return email_domain; return dot + 1; } @@ -861,7 +863,8 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, cb != nullptr); dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(cur, static_cast(dot - cur), &header_buffer); + json = parse_json_part_from_jwt(cur, static_cast(dot - cur), + &header_buffer); if (json == nullptr) goto error; header = jose_header_from_json(json, header_buffer); if (header == nullptr) goto error; @@ -869,7 +872,8 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, cur = dot + 1; dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(cur, static_cast(dot - cur), &claims_buffer); + json = parse_json_part_from_jwt(cur, static_cast(dot - cur), + &claims_buffer); if (json == nullptr) goto error; claims = grpc_jwt_claims_from_json(json, claims_buffer); if (claims == nullptr) goto error; @@ -898,8 +902,8 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( /* We know at least of one mapping. */ v->allocated_mappings = 1 + num_mappings; - v->mappings = static_cast(gpr_malloc(v->allocated_mappings * - sizeof(email_key_mapping))); + v->mappings = static_cast( + gpr_malloc(v->allocated_mappings * sizeof(email_key_mapping))); verifier_put_mapping(v, GRPC_GOOGLE_SERVICE_ACCOUNTS_EMAIL_DOMAIN, GRPC_GOOGLE_SERVICE_ACCOUNTS_KEY_URL_PREFIX); /* User-Provided mappings. */ diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index b4fb9a43e7..afae7d8f2f 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -128,7 +128,8 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( } if (response->body_length > 0) { - null_terminated_body = static_cast(gpr_malloc(response->body_length + 1)); + null_terminated_body = + static_cast(gpr_malloc(response->body_length + 1)); null_terminated_body[response->body_length] = '\0'; memcpy(null_terminated_body, response->body, response->body_length); } @@ -269,8 +270,8 @@ static bool oauth2_token_fetcher_get_request_metadata( // Couldn't get the token from the cache. // Add request to c->pending_requests and start a new fetch if needed. grpc_oauth2_pending_get_request_metadata* pending_request = - static_cast(gpr_malloc( - sizeof(*pending_request))); + static_cast( + gpr_malloc(sizeof(*pending_request))); pending_request->md_array = md_array; pending_request->on_request_metadata = on_request_metadata; pending_request->pollent = pollent; @@ -371,8 +372,8 @@ static void compute_engine_fetch_oauth2( grpc_call_credentials* grpc_google_compute_engine_credentials_create( void* reserved) { grpc_oauth2_token_fetcher_credentials* c = - static_cast(gpr_malloc( - sizeof(grpc_oauth2_token_fetcher_credentials))); + static_cast( + gpr_malloc(sizeof(grpc_oauth2_token_fetcher_credentials))); GRPC_API_TRACE("grpc_compute_engine_credentials_create(reserved=%p)", 1, (reserved)); GPR_ASSERT(reserved == nullptr); @@ -401,7 +402,8 @@ static void refresh_token_fetch_oauth2( grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, grpc_millis deadline) { grpc_google_refresh_token_credentials* c = - reinterpret_cast(metadata_req->creds); + reinterpret_cast( + metadata_req->creds); grpc_http_header header = {(char*)"Content-Type", (char*)"application/x-www-form-urlencoded"}; grpc_httpcli_request request; @@ -437,8 +439,8 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token( gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation"); return nullptr; } - c = static_cast(gpr_zalloc( - sizeof(grpc_google_refresh_token_credentials))); + c = static_cast( + gpr_zalloc(sizeof(grpc_google_refresh_token_credentials))); init_oauth2_token_fetcher(&c->base, refresh_token_fetch_oauth2); c->base.base.vtable = &refresh_token_vtable; c->refresh_token = refresh_token; @@ -478,7 +480,8 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create( // static void access_token_destruct(grpc_call_credentials* creds) { - grpc_access_token_credentials* c = reinterpret_cast(creds); + grpc_access_token_credentials* c = + reinterpret_cast(creds); GRPC_MDELEM_UNREF(c->access_token_md); } @@ -486,7 +489,8 @@ static bool access_token_get_request_metadata( grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_access_token_credentials* c = reinterpret_cast(creds); + grpc_access_token_credentials* c = + reinterpret_cast(creds); grpc_credentials_mdelem_array_add(md_array, c->access_token_md); return true; } @@ -503,8 +507,9 @@ static grpc_call_credentials_vtable access_token_vtable = { grpc_call_credentials* grpc_access_token_credentials_create( const char* access_token, void* reserved) { - grpc_access_token_credentials* c = static_cast(gpr_zalloc( - sizeof(grpc_access_token_credentials))); + grpc_access_token_credentials* c = + static_cast( + gpr_zalloc(sizeof(grpc_access_token_credentials))); GRPC_API_TRACE( "grpc_access_token_credentials_create(access_token=, " "reserved=%p)", diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 89f94f9e6d..ddb86e153b 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -34,7 +34,8 @@ grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials"); static void plugin_destruct(grpc_call_credentials* creds) { - grpc_plugin_credentials* c = reinterpret_cast(creds); + grpc_plugin_credentials* c = + reinterpret_cast(creds); gpr_mu_destroy(&c->mu); if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) { c->plugin.destroy(c->plugin.state); @@ -147,13 +148,14 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - grpc_plugin_credentials* c = reinterpret_cast(creds); + grpc_plugin_credentials* c = + reinterpret_cast(creds); bool retval = true; // Synchronous return. if (c->plugin.get_metadata != nullptr) { // Create pending_request object. grpc_plugin_credentials_pending_request* pending_request = - static_cast(gpr_zalloc( - sizeof(*pending_request))); + static_cast( + gpr_zalloc(sizeof(*pending_request))); pending_request->creds = c; pending_request->md_array = md_array; pending_request->on_request_metadata = on_request_metadata; @@ -225,7 +227,8 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds, static void plugin_cancel_get_request_metadata( grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_error* error) { - grpc_plugin_credentials* c = reinterpret_cast(creds); + grpc_plugin_credentials* c = + reinterpret_cast(creds); gpr_mu_lock(&c->mu); for (grpc_plugin_credentials_pending_request* pending_request = c->pending_requests; @@ -252,7 +255,8 @@ static grpc_call_credentials_vtable plugin_vtable = { grpc_call_credentials* grpc_metadata_credentials_create_from_plugin( grpc_metadata_credentials_plugin plugin, void* reserved) { - grpc_plugin_credentials* c = static_cast(gpr_zalloc(sizeof(*c))); + grpc_plugin_credentials* c = + static_cast(gpr_zalloc(sizeof(*c))); GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1, (reserved)); GPR_ASSERT(reserved == nullptr); diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 4237039274..a4fce25f3a 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -85,8 +85,8 @@ static void ssl_build_config(const char* pem_root_certs, if (pem_key_cert_pair != nullptr) { GPR_ASSERT(pem_key_cert_pair->private_key != nullptr); GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr); - config->pem_key_cert_pair = static_cast(gpr_zalloc( - sizeof(tsi_ssl_pem_key_cert_pair))); + config->pem_key_cert_pair = static_cast( + gpr_zalloc(sizeof(tsi_ssl_pem_key_cert_pair))); config->pem_key_cert_pair->cert_chain = gpr_strdup(pem_key_cert_pair->cert_chain); config->pem_key_cert_pair->private_key = @@ -97,8 +97,8 @@ static void ssl_build_config(const char* pem_root_certs, grpc_channel_credentials* grpc_ssl_credentials_create( const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair, void* reserved) { - grpc_ssl_credentials* c = - static_cast(gpr_zalloc(sizeof(grpc_ssl_credentials))); + grpc_ssl_credentials* c = static_cast( + gpr_zalloc(sizeof(grpc_ssl_credentials))); GRPC_API_TRACE( "grpc_ssl_credentials_create(pem_root_certs=%s, " "pem_key_cert_pair=%p, " @@ -123,7 +123,8 @@ struct grpc_ssl_server_credentials_options { }; static void ssl_server_destruct(grpc_server_credentials* creds) { - grpc_ssl_server_credentials* c = reinterpret_cast(creds); + grpc_ssl_server_credentials* c = + reinterpret_cast(creds); grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pairs, c->config.num_key_cert_pairs); gpr_free(c->config.pem_root_certs); @@ -143,8 +144,8 @@ tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs( tsi_ssl_pem_key_cert_pair* tsi_pairs = nullptr; if (num_key_cert_pairs > 0) { GPR_ASSERT(pem_key_cert_pairs != nullptr); - tsi_pairs = static_cast(gpr_zalloc( - num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair))); + tsi_pairs = static_cast( + gpr_zalloc(num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair))); } for (size_t i = 0; i < num_key_cert_pairs; i++) { GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr); @@ -174,15 +175,15 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create( const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs, size_t num_key_cert_pairs) { grpc_ssl_server_certificate_config* config = - static_cast(gpr_zalloc( - sizeof(grpc_ssl_server_certificate_config))); + static_cast( + gpr_zalloc(sizeof(grpc_ssl_server_certificate_config))); if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } if (num_key_cert_pairs > 0) { GPR_ASSERT(pem_key_cert_pairs != nullptr); - config->pem_key_cert_pairs = static_cast(gpr_zalloc( - num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair))); + config->pem_key_cert_pairs = static_cast( + gpr_zalloc(num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair))); } config->num_key_cert_pairs = num_key_cert_pairs; for (size_t i = 0; i < num_key_cert_pairs; i++) { @@ -217,8 +218,8 @@ grpc_ssl_server_credentials_create_options_using_config( gpr_log(GPR_ERROR, "Certificate config must not be NULL."); goto done; } - options = static_cast(gpr_zalloc( - sizeof(grpc_ssl_server_credentials_options))); + options = static_cast( + gpr_zalloc(sizeof(grpc_ssl_server_credentials_options))); options->client_certificate_request = client_certificate_request; options->certificate_config = config; done: @@ -235,14 +236,14 @@ grpc_ssl_server_credentials_create_options_using_config_fetcher( } grpc_ssl_server_certificate_config_fetcher* fetcher = - static_cast(gpr_zalloc( - sizeof(grpc_ssl_server_certificate_config_fetcher))); + static_cast( + gpr_zalloc(sizeof(grpc_ssl_server_certificate_config_fetcher))); fetcher->cb = cb; fetcher->user_data = user_data; grpc_ssl_server_credentials_options* options = - static_cast(gpr_zalloc( - sizeof(grpc_ssl_server_credentials_options))); + static_cast( + gpr_zalloc(sizeof(grpc_ssl_server_credentials_options))); options->client_certificate_request = client_certificate_request; options->certificate_config_fetcher = fetcher; @@ -307,8 +308,8 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options( goto done; } - c = static_cast(gpr_zalloc( - sizeof(grpc_ssl_server_credentials))); + c = static_cast( + gpr_zalloc(sizeof(grpc_ssl_server_credentials))); c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL; gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &ssl_server_vtable; diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc index b5171acc87..d2313807ff 100644 --- a/src/core/lib/security/transport/client_auth_filter.cc +++ b/src/core/lib/security/transport/client_auth_filter.cc @@ -93,7 +93,8 @@ static void add_error(grpc_error** combined, grpc_error* error) { } static void on_credentials_metadata(void* arg, grpc_error* input_error) { - grpc_transport_stream_op_batch* batch = static_cast(arg); + grpc_transport_stream_op_batch* batch = + static_cast(arg); grpc_call_element* elem = static_cast(batch->handler_private.extra_arg); call_data* calld = static_cast(elem->call_data); @@ -173,9 +174,8 @@ static void send_security_metadata(grpc_call_element* elem, call_data* calld = static_cast(elem->call_data); channel_data* chand = static_cast(elem->channel_data); grpc_client_security_context* ctx = - static_cast(batch->payload - ->context[GRPC_CONTEXT_SECURITY] - .value); + static_cast( + batch->payload->context[GRPC_CONTEXT_SECURITY].value); grpc_call_credentials* channel_call_creds = chand->security_connector->request_metadata_creds; int call_creds_has_md = (ctx != nullptr) && (ctx->creds != nullptr); @@ -231,7 +231,8 @@ static void send_security_metadata(grpc_call_element* elem, } static void on_host_checked(void* arg, grpc_error* error) { - grpc_transport_stream_op_batch* batch = static_cast(arg); + grpc_transport_stream_op_batch* batch = + static_cast(arg); grpc_call_element* elem = static_cast(batch->handler_private.extra_arg); call_data* calld = static_cast(elem->call_data); @@ -283,9 +284,8 @@ static void auth_start_transport_stream_op_batch( grpc_client_security_context_destroy; } grpc_client_security_context* sec_ctx = - static_cast(batch->payload - ->context[GRPC_CONTEXT_SECURITY] - .value); + static_cast( + batch->payload->context[GRPC_CONTEXT_SECURITY].value); GRPC_AUTH_CONTEXT_UNREF(sec_ctx->auth_context, "client auth filter"); sec_ctx->auth_context = GRPC_AUTH_CONTEXT_REF(chand->auth_context, "client_auth_filter"); @@ -400,8 +400,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, /* initialize members */ chand->security_connector = - reinterpret_cast(GRPC_SECURITY_CONNECTOR_REF( - sc, "client_auth_filter")); + reinterpret_cast( + GRPC_SECURITY_CONNECTOR_REF(sc, "client_auth_filter")); chand->auth_context = GRPC_AUTH_CONTEXT_REF(auth_context, "client_auth_filter"); return GRPC_ERROR_NONE; diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc index 84a72731c9..67a3c7449d 100644 --- a/src/core/lib/security/transport/lb_targets_info.cc +++ b/src/core/lib/security/transport/lb_targets_info.cc @@ -32,8 +32,9 @@ static void targets_info_destroy(void* p) { grpc_slice_hash_table_unref(static_cast(p)); } static int targets_info_cmp(void* a, void* b) { - return grpc_slice_hash_table_cmp(static_cast(a), - static_cast(b)); + return grpc_slice_hash_table_cmp( + static_cast(a), + static_cast(b)); } static const grpc_arg_pointer_vtable server_to_balancer_names_vtable = { targets_info_copy, targets_info_destroy, targets_info_cmp}; @@ -51,7 +52,8 @@ grpc_slice_hash_table* grpc_lb_targets_info_find_in_args( grpc_channel_args_find(args, GRPC_ARG_LB_SECURE_NAMING_MAP); if (targets_info_arg != nullptr) { GPR_ASSERT(targets_info_arg->type == GRPC_ARG_POINTER); - return static_cast(targets_info_arg->value.pointer.p); + return static_cast( + targets_info_arg->value.pointer.p); } return nullptr; } diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index a63dbc07c8..f72f8b6121 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -205,7 +205,8 @@ static void on_read(void* user_data, grpc_error* error) { ep->read_buffer, grpc_slice_split_head( &ep->read_staging_buffer, - static_cast(cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer)))); + static_cast( + cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer)))); } } @@ -324,8 +325,8 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, &ep->output_buffer, grpc_slice_split_head( &ep->write_staging_buffer, - static_cast(cur - - GRPC_SLICE_START_PTR(ep->write_staging_buffer)))); + static_cast( + cur - GRPC_SLICE_START_PTR(ep->write_staging_buffer)))); } } } @@ -403,7 +404,8 @@ grpc_endpoint* grpc_secure_endpoint_create( grpc_endpoint* transport, grpc_slice* leftover_slices, size_t leftover_nslices) { size_t i; - secure_endpoint* ep = static_cast(gpr_malloc(sizeof(secure_endpoint))); + secure_endpoint* ep = + static_cast(gpr_malloc(sizeof(secure_endpoint))); ep->base.vtable = &vtable; ep->wrapped_ep = transport; ep->protector = protector; diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index e9a2d23535..bd5da1bbd2 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -498,7 +498,8 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create( grpc_call_credentials* request_metadata_creds, const char* target, const grpc_channel_args* args) { grpc_fake_channel_security_connector* c = - static_cast(gpr_zalloc(sizeof(*c))); + static_cast( + gpr_zalloc(sizeof(*c))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME; c->base.base.vtable = &fake_channel_vtable; @@ -518,8 +519,8 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create( grpc_server_security_connector* grpc_fake_server_security_connector_create( grpc_server_credentials* server_creds) { grpc_server_security_connector* c = - static_cast(gpr_zalloc( - sizeof(grpc_server_security_connector))); + static_cast( + gpr_zalloc(sizeof(grpc_server_security_connector))); gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &fake_server_vtable; c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME; @@ -597,8 +598,8 @@ static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc, static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { GPR_ASSERT(num_alpn_protocols != nullptr); *num_alpn_protocols = grpc_chttp2_num_alpn_versions(); - const char** alpn_protocol_strings = - static_cast(gpr_malloc(sizeof(const char*) * (*num_alpn_protocols))); + const char** alpn_protocol_strings = static_cast( + gpr_malloc(sizeof(const char*) * (*num_alpn_protocols))); for (size_t i = 0; i < *num_alpn_protocols; i++) { alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i); } @@ -632,8 +633,8 @@ static bool try_replace_server_handshaker_factory( cert_pairs, config->num_key_cert_pairs, config->pem_root_certs, get_tsi_client_certificate_request_type( server_creds->config.client_certificate_request), - ssl_cipher_suites(), alpn_protocol_strings, static_cast(num_alpn_protocols), - &new_handshaker_factory); + ssl_cipher_suites(), alpn_protocol_strings, + static_cast(num_alpn_protocols), &new_handshaker_factory); gpr_free(cert_pairs); gpr_free((void*)alpn_protocol_strings); @@ -850,8 +851,8 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context( while (grpc_auth_property_iterator_next(&it) != nullptr) max_num_props++; if (max_num_props > 0) { - peer.properties = static_cast(gpr_malloc(max_num_props * - sizeof(tsi_peer_property))); + peer.properties = static_cast( + gpr_malloc(max_num_props * sizeof(tsi_peer_property))); it = grpc_auth_context_property_iterator(auth_context); while ((prop = grpc_auth_property_iterator_next(&it)) != nullptr) { if (strcmp(prop->name, GRPC_X509_SAN_PROPERTY_NAME) == 0) { @@ -963,7 +964,8 @@ const char* grpc_get_default_ssl_roots(void) { gpr_once_init(&once, init_default_pem_root_certs); return GRPC_SLICE_IS_EMPTY(default_pem_root_certs) ? nullptr - : reinterpret_castGRPC_SLICE_START_PTR(default_pem_root_certs); + : reinterpret_cast + GRPC_SLICE_START_PTR(default_pem_root_certs); } grpc_security_status grpc_ssl_channel_security_connector_create( @@ -994,8 +996,8 @@ grpc_security_status grpc_ssl_channel_security_connector_create( pem_root_certs = config->pem_root_certs; } - c = static_cast(gpr_zalloc( - sizeof(grpc_ssl_channel_security_connector))); + c = static_cast( + gpr_zalloc(sizeof(grpc_ssl_channel_security_connector))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.vtable = &ssl_channel_vtable; @@ -1017,8 +1019,8 @@ grpc_security_status grpc_ssl_channel_security_connector_create( config->pem_key_cert_pair->cert_chain != nullptr; result = tsi_create_ssl_client_handshaker_factory( has_key_cert_pair ? config->pem_key_cert_pair : nullptr, pem_root_certs, - ssl_cipher_suites(), alpn_protocol_strings, static_cast(num_alpn_protocols), - &c->client_handshaker_factory); + ssl_cipher_suites(), alpn_protocol_strings, + static_cast(num_alpn_protocols), &c->client_handshaker_factory); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); @@ -1039,8 +1041,8 @@ static grpc_ssl_server_security_connector* grpc_ssl_server_security_connector_initialize( grpc_server_credentials* server_creds) { grpc_ssl_server_security_connector* c = - static_cast(gpr_zalloc( - sizeof(grpc_ssl_server_security_connector))); + static_cast( + gpr_zalloc(sizeof(grpc_ssl_server_security_connector))); gpr_ref_init(&c->base.base.refcount, 1); c->base.base.url_scheme = GRPC_SSL_URL_SCHEME; c->base.base.vtable = &ssl_server_vtable; @@ -1078,7 +1080,8 @@ grpc_security_status grpc_ssl_server_security_connector_create( get_tsi_client_certificate_request_type( server_credentials->config.client_certificate_request), ssl_cipher_suites(), alpn_protocol_strings, - static_cast(num_alpn_protocols), &c->server_handshaker_factory); + static_cast(num_alpn_protocols), + &c->server_handshaker_factory); gpr_free((void*)alpn_protocol_strings); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 2e7c3570b6..b37392ab81 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -68,8 +68,8 @@ typedef struct { static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) { size_t bytes_in_read_buffer = h->args->read_buffer->length; if (h->handshake_buffer_size < bytes_in_read_buffer) { - h->handshake_buffer = - static_cast(gpr_realloc(h->handshake_buffer, bytes_in_read_buffer)); + h->handshake_buffer = static_cast( + gpr_realloc(h->handshake_buffer, bytes_in_read_buffer)); h->handshake_buffer_size = bytes_in_read_buffer; } size_t offset = 0; @@ -408,15 +408,16 @@ static const grpc_handshaker_vtable security_handshaker_vtable = { static grpc_handshaker* security_handshaker_create( tsi_handshaker* handshaker, grpc_security_connector* connector) { - security_handshaker* h = - static_cast(gpr_zalloc(sizeof(security_handshaker))); + security_handshaker* h = static_cast( + gpr_zalloc(sizeof(security_handshaker))); grpc_handshaker_init(&security_handshaker_vtable, &h->base); h->handshaker = handshaker; h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake"); gpr_mu_init(&h->mu); gpr_ref_init(&h->refs, 1); h->handshake_buffer_size = GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE; - h->handshake_buffer = static_cast(gpr_malloc(h->handshake_buffer_size)); + h->handshake_buffer = + static_cast(gpr_malloc(h->handshake_buffer_size)); GRPC_CLOSURE_INIT(&h->on_handshake_data_sent_to_peer, on_handshake_data_sent_to_peer, h, grpc_schedule_on_exec_ctx); @@ -469,8 +470,8 @@ static void client_handshaker_factory_add_handshakers( grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_channel_security_connector* security_connector = - reinterpret_cast(grpc_security_connector_find_in_args( - args)); + reinterpret_cast( + grpc_security_connector_find_in_args(args)); grpc_channel_security_connector_add_handshakers(security_connector, handshake_mgr); } @@ -479,8 +480,8 @@ static void server_handshaker_factory_add_handshakers( grpc_handshaker_factory* hf, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_server_security_connector* security_connector = - reinterpret_cast(grpc_security_connector_find_in_args( - args)); + reinterpret_cast( + grpc_security_connector_find_in_args(args)); grpc_server_security_connector_add_handshakers(security_connector, handshake_mgr); } diff --git a/src/core/lib/slice/b64.cc b/src/core/lib/slice/b64.cc index 1d938be11c..3e19b7197f 100644 --- a/src/core/lib/slice/b64.cc +++ b/src/core/lib/slice/b64.cc @@ -128,13 +128,15 @@ grpc_slice grpc_base64_decode(const char* b64, int url_safe) { static void decode_one_char(const unsigned char* codes, unsigned char* result, size_t* result_offset) { - uint32_t packed = (static_cast(codes[0]) << 2) | (static_cast(codes[1]) >> 4); + uint32_t packed = (static_cast(codes[0]) << 2) | + (static_cast(codes[1]) >> 4); result[(*result_offset)++] = static_cast(packed); } static void decode_two_chars(const unsigned char* codes, unsigned char* result, size_t* result_offset) { - uint32_t packed = (static_cast(codes[0]) << 10) | (static_cast(codes[1]) << 4) | + uint32_t packed = (static_cast(codes[0]) << 10) | + (static_cast(codes[1]) << 4) | (static_cast(codes[2]) >> 2); result[(*result_offset)++] = static_cast(packed >> 8); result[(*result_offset)++] = static_cast(packed); @@ -175,7 +177,8 @@ static int decode_group(const unsigned char* codes, size_t num_codes, decode_two_chars(codes, result, result_offset); } else { /* No padding. */ - uint32_t packed = (static_cast(codes[0]) << 18) | (static_cast(codes[1]) << 12) | + uint32_t packed = (static_cast(codes[0]) << 18) | + (static_cast(codes[1]) << 12) | (static_cast(codes[2]) << 6) | codes[3]; result[(*result_offset)++] = static_cast(packed >> 16); result[(*result_offset)++] = static_cast(packed >> 8); diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 136cce1d1e..476d941fbb 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -173,8 +173,8 @@ static const grpc_slice_refcount_vtable new_with_len_vtable = { grpc_slice grpc_slice_new_with_len(void* p, size_t len, void (*destroy)(void*, size_t)) { grpc_slice slice; - new_with_len_slice_refcount* rc = static_cast(gpr_malloc( - sizeof(new_with_len_slice_refcount))); + new_with_len_slice_refcount* rc = static_cast( + gpr_malloc(sizeof(new_with_len_slice_refcount))); gpr_ref_init(&rc->refs, 1); rc->rc.vtable = &new_with_len_vtable; rc->rc.sub_refcount = &rc->rc; @@ -232,8 +232,8 @@ grpc_slice grpc_slice_malloc_large(size_t length) { refcount is a malloc_refcount bytes is an array of bytes of the requested length Both parts are placed in the same allocation returned from gpr_malloc */ - malloc_refcount* rc = - static_cast(gpr_malloc(sizeof(malloc_refcount) + length)); + malloc_refcount* rc = static_cast( + gpr_malloc(sizeof(malloc_refcount) + length)); /* Initial refcount on rc is 1 - and it's up to the caller to release this reference. */ @@ -314,7 +314,8 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split, /* inlined data, copy it out */ GPR_ASSERT(source->data.inlined.length >= split); tail.refcount = nullptr; - tail.data.inlined.length = static_cast(source->data.inlined.length - split); + tail.data.inlined.length = + static_cast(source->data.inlined.length - split); memcpy(tail.data.inlined.bytes, source->data.inlined.bytes + split, tail.data.inlined.length); source->data.inlined.length = static_cast(split); @@ -443,15 +444,15 @@ int grpc_slice_buf_start_eq(grpc_slice a, const void* b, size_t len) { } int grpc_slice_rchr(grpc_slice s, char c) { - const char* b = reinterpret_castGRPC_SLICE_START_PTR(s); + const char* b = reinterpret_cast GRPC_SLICE_START_PTR(s); int i; - for (i = static_castGRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) + for (i = static_cast GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) ; return i; } int grpc_slice_chr(grpc_slice s, char c) { - const char* b = reinterpret_castGRPC_SLICE_START_PTR(s); + const char* b = reinterpret_cast GRPC_SLICE_START_PTR(s); const char* p = static_cast(memchr(b, c, GRPC_SLICE_LENGTH(s))); return p == nullptr ? -1 : static_cast(p - b); } @@ -466,7 +467,8 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { if (haystack_len < needle_len) return -1; if (haystack_len == needle_len) return grpc_slice_eq(haystack, needle) ? 0 : -1; - if (needle_len == 1) return grpc_slice_chr(haystack, static_cast(*needle_bytes)); + if (needle_len == 1) + return grpc_slice_chr(haystack, static_cast(*needle_bytes)); const uint8_t* last = haystack_bytes + haystack_len - needle_len; for (const uint8_t* cur = haystack_bytes; cur != last; ++cur) { diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 84a2b5f6d9..0416c9d371 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -45,12 +45,12 @@ static void maybe_embiggen(grpc_slice_buffer* sb) { sb->capacity = GROW(sb->capacity); GPR_ASSERT(sb->capacity > slice_count); if (sb->base_slices == sb->inlined) { - sb->base_slices = - static_cast(gpr_malloc(sb->capacity * sizeof(grpc_slice))); + sb->base_slices = static_cast( + gpr_malloc(sb->capacity * sizeof(grpc_slice))); memcpy(sb->base_slices, sb->inlined, slice_count * sizeof(grpc_slice)); } else { - sb->base_slices = static_cast(gpr_realloc( - sb->base_slices, sb->capacity * sizeof(grpc_slice))); + sb->base_slices = static_cast( + gpr_realloc(sb->base_slices, sb->capacity * sizeof(grpc_slice))); } sb->slices = sb->base_slices + slice_offset; @@ -89,7 +89,8 @@ uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t n) { if ((back->data.inlined.length + n) > sizeof(back->data.inlined.bytes)) goto add_new; out = back->data.inlined.bytes + back->data.inlined.length; - back->data.inlined.length = static_cast(back->data.inlined.length + n); + back->data.inlined.length = + static_cast(back->data.inlined.length + n); return out; add_new: @@ -125,8 +126,8 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) { GRPC_SLICE_INLINED_SIZE) { memcpy(back->data.inlined.bytes + back->data.inlined.length, s.data.inlined.bytes, s.data.inlined.length); - back->data.inlined.length = - static_cast(back->data.inlined.length + s.data.inlined.length); + back->data.inlined.length = static_cast( + back->data.inlined.length + s.data.inlined.length); } else { size_t cp1 = GRPC_SLICE_INLINED_SIZE - back->data.inlined.length; memcpy(back->data.inlined.bytes + back->data.inlined.length, @@ -136,7 +137,8 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) { back = &sb->slices[n]; sb->count = n + 1; back->refcount = nullptr; - back->data.inlined.length = static_cast(s.data.inlined.length - cp1); + back->data.inlined.length = + static_cast(s.data.inlined.length - cp1); memcpy(back->data.inlined.bytes, s.data.inlined.bytes + cp1, s.data.inlined.length - cp1); } diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc index 1818b126ca..2342e90485 100644 --- a/src/core/lib/slice/slice_hash_table.cc +++ b/src/core/lib/slice/slice_hash_table.cc @@ -67,7 +67,8 @@ grpc_slice_hash_table* grpc_slice_hash_table_create( // Keep load factor low to improve performance of lookups. table->size = num_entries * 2; const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size; - table->entries = static_cast(gpr_zalloc(entry_size)); + table->entries = + static_cast(gpr_zalloc(entry_size)); for (size_t i = 0; i < num_entries; ++i) { grpc_slice_hash_table_entry* entry = &entries[i]; grpc_slice_hash_table_add(table, entry->key, entry->value); diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index f4aad73e0f..2d633c4903 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -98,15 +98,18 @@ static void interned_slice_unref(void* p) { } static void interned_slice_sub_ref(void* p) { - interned_slice_ref((static_cast(p)) - offsetof(interned_slice_refcount, sub)); + interned_slice_ref((static_cast(p)) - + offsetof(interned_slice_refcount, sub)); } static void interned_slice_sub_unref(void* p) { - interned_slice_unref((static_cast(p)) - offsetof(interned_slice_refcount, sub)); + interned_slice_unref((static_cast(p)) - + offsetof(interned_slice_refcount, sub)); } static uint32_t interned_slice_hash(grpc_slice slice) { - interned_slice_refcount* s = reinterpret_cast(slice.refcount); + interned_slice_refcount* s = + reinterpret_cast(slice.refcount); return s->hash; } @@ -129,8 +132,8 @@ static void grow_shard(slice_shard* shard) { interned_slice_refcount** strtab; interned_slice_refcount *s, *next; - strtab = static_cast(gpr_zalloc( - sizeof(interned_slice_refcount*) * capacity)); + strtab = static_cast( + gpr_zalloc(sizeof(interned_slice_refcount*) * capacity)); for (i = 0; i < shard->capacity; i++) { for (s = shard->strs[i]; s; s = next) { @@ -237,8 +240,8 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { /* not found: create a new string */ /* string data goes after the internal_string header */ - s = static_cast(gpr_malloc(sizeof(*s) + - GRPC_SLICE_LENGTH(slice))); + s = static_cast( + gpr_malloc(sizeof(*s) + GRPC_SLICE_LENGTH(slice))); gpr_atm_rel_store(&s->refcnt, 1); s->length = GRPC_SLICE_LENGTH(slice); s->hash = hash; @@ -275,8 +278,8 @@ void grpc_slice_intern_init(void) { gpr_mu_init(&shard->mu); shard->count = 0; shard->capacity = INITIAL_SHARD_CAPACITY; - shard->strs = static_cast(gpr_zalloc(sizeof(*shard->strs) * - shard->capacity)); + shard->strs = static_cast( + gpr_zalloc(sizeof(*shard->strs) * shard->capacity)); } for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) { static_metadata_hash[i].hash = 0; diff --git a/src/core/lib/slice/slice_string_helpers.cc b/src/core/lib/slice/slice_string_helpers.cc index 2015040c12..f91ece3b98 100644 --- a/src/core/lib/slice/slice_string_helpers.cc +++ b/src/core/lib/slice/slice_string_helpers.cc @@ -26,8 +26,8 @@ #include "src/core/lib/slice/slice_internal.h" char* grpc_dump_slice(grpc_slice s, uint32_t flags) { - return gpr_dump(reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), - flags); + return gpr_dump(reinterpret_cast GRPC_SLICE_START_PTR(s), + GRPC_SLICE_LENGTH(s), flags); } /** Finds the initial (\a begin) and final (\a end) offsets of the next @@ -110,6 +110,7 @@ void grpc_slice_split_without_space(grpc_slice str, const char* sep, } bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t* result) { - return gpr_parse_bytes_to_uint32(reinterpret_castGRPC_SLICE_START_PTR(str), - GRPC_SLICE_LENGTH(str), result) != 0; + return gpr_parse_bytes_to_uint32( + reinterpret_cast GRPC_SLICE_START_PTR(str), + GRPC_SLICE_LENGTH(str), result) != 0; } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index d6949103c7..db7c01cc33 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -360,7 +360,8 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, GRPC_MDVALUE(args->add_initial_metadata[i])); } } - call->send_extra_metadata_count = static_cast(args->add_initial_metadata_count); + call->send_extra_metadata_count = + static_cast(args->add_initial_metadata_count); } else { GPR_ASSERT(args->add_initial_metadata_count == 0); call->send_extra_metadata_count = 0; @@ -608,7 +609,8 @@ grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { // the filter stack. static void execute_batch_in_call_combiner(void* arg, grpc_error* ignored) { GPR_TIMER_SCOPE("execute_batch", 0); - grpc_transport_stream_op_batch* batch = static_cast(arg); + grpc_transport_stream_op_batch* batch = + static_cast(arg); grpc_call* call = static_cast(batch->handler_private.extra_arg); grpc_call_element* elem = CALL_ELEM_FROM_CALL(call, 0); GRPC_CALL_LOG_OP(GPR_INFO, elem, batch); @@ -991,8 +993,9 @@ static uint32_t decode_status(grpc_mdelem md) { 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, + (void*)static_cast(status + STATUS_OFFSET)); } return status; } @@ -1040,8 +1043,8 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, if (dest->count + b->list.count > dest->capacity) { dest->capacity = GPR_MAX(dest->capacity + b->list.count, dest->capacity * 3 / 2); - dest->metadata = static_cast(gpr_realloc( - dest->metadata, sizeof(grpc_metadata) * dest->capacity)); + dest->metadata = static_cast( + gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity)); } for (grpc_linked_mdelem* l = b->list.head; l != nullptr; l = l->next) { mdusr = &dest->metadata[dest->count++]; @@ -1170,8 +1173,8 @@ static batch_control* allocate_batch_control(grpc_call* call, int slot = batch_slot_for_op(ops[0].op); batch_control** pslot = &call->active_batches[slot]; if (*pslot == nullptr) { - *pslot = - static_cast(gpr_arena_alloc(call->arena, sizeof(batch_control))); + *pslot = static_cast( + gpr_arena_alloc(call->arena, sizeof(batch_control))); } batch_control* bctl = *pslot; if (bctl->call != nullptr) { @@ -1192,7 +1195,7 @@ static void finish_batch_completion(void* user_data, } static grpc_error* consolidate_batch_errors(batch_control* bctl) { - size_t n = static_castgpr_atm_acq_load(&bctl->num_errors); + size_t n = static_cast gpr_atm_acq_load(&bctl->num_errors); if (n == 0) { return GRPC_ERROR_NONE; } else if (n == 1) { @@ -1584,9 +1587,10 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, if (nops == 0) { if (!is_notify_tag_closure) { GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag)); - grpc_cq_end_op( - call->cq, notify_tag, GRPC_ERROR_NONE, free_no_op_completion, nullptr, - static_cast(gpr_malloc(sizeof(grpc_cq_completion)))); + grpc_cq_end_op(call->cq, notify_tag, GRPC_ERROR_NONE, + free_no_op_completion, nullptr, + static_cast( + gpr_malloc(sizeof(grpc_cq_completion)))); } else { GRPC_CLOSURE_SCHED((grpc_closure*)notify_tag, GRPC_ERROR_NONE); } @@ -1662,7 +1666,8 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, if (!prepare_application_metadata( call, static_cast(op->data.send_initial_metadata.count), op->data.send_initial_metadata.metadata, 0, call->is_client, - &call->compression_md, static_cast(additional_metadata_count))) { + &call->compression_md, + static_cast(additional_metadata_count))) { error = GRPC_CALL_ERROR_INVALID_METADATA; goto done_with_error; } @@ -1779,7 +1784,8 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, } if (!prepare_application_metadata( call, - static_cast(op->data.send_status_from_server.trailing_metadata_count), + static_cast( + op->data.send_status_from_server.trailing_metadata_count), op->data.send_status_from_server.trailing_metadata, 1, 1, nullptr, 0)) { for (int n = 0; n < call->send_extra_metadata_count; n++) { diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 06dbfdcb49..6c73c2cd76 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -190,17 +190,20 @@ size_t grpc_channel_get_call_size_estimate(grpc_channel* channel) { (which is common) - which tends to help most allocators reuse memory 2. a small amount of allowed growth over the estimate without hitting the arena size doubling case, reducing overall memory usage */ - return (static_castgpr_atm_no_barrier_load(&channel->call_size_estimate) + + return (static_cast gpr_atm_no_barrier_load( + &channel->call_size_estimate) + 2 * ROUND_UP_SIZE) & ~static_cast(ROUND_UP_SIZE - 1); } void grpc_channel_update_call_size_estimate(grpc_channel* channel, size_t size) { - size_t cur = static_castgpr_atm_no_barrier_load(&channel->call_size_estimate); + size_t cur = + static_cast gpr_atm_no_barrier_load(&channel->call_size_estimate); if (cur < size) { /* size grew: update estimate */ - gpr_atm_no_barrier_cas(&channel->call_size_estimate, static_cast(cur), + gpr_atm_no_barrier_cas(&channel->call_size_estimate, + static_cast(cur), static_cast(size)); /* if we lose: never mind, something else will likely update soon enough */ } else if (cur == size) { @@ -297,7 +300,8 @@ grpc_call* grpc_channel_create_pollset_set_call( void* grpc_channel_register_call(grpc_channel* channel, const char* method, const char* host, void* reserved) { - registered_call* rc = static_cast(gpr_malloc(sizeof(registered_call))); + registered_call* rc = + static_cast(gpr_malloc(sizeof(registered_call))); GRPC_API_TRACE( "grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)", 4, (channel, method, host, reserved)); diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index 6b63195272..b1e1dceed3 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -52,9 +52,9 @@ void grpc_channel_init_register_stage(grpc_channel_stack_type type, GPR_ASSERT(!g_finalized); if (g_slots[type].cap_slots == g_slots[type].num_slots) { g_slots[type].cap_slots = GPR_MAX(8, 3 * g_slots[type].cap_slots / 2); - g_slots[type].slots = static_cast(gpr_realloc( - g_slots[type].slots, - g_slots[type].cap_slots * sizeof(*g_slots[type].slots))); + g_slots[type].slots = static_cast( + gpr_realloc(g_slots[type].slots, + g_slots[type].cap_slots * sizeof(*g_slots[type].slots))); } stage_slot* s = &g_slots[type].slots[g_slots[type].num_slots++]; s->insertion_order = g_slots[type].num_slots; @@ -84,7 +84,8 @@ void grpc_channel_init_finalize(void) { void grpc_channel_init_shutdown(void) { for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) { gpr_free(g_slots[i].slots); - g_slots[i].slots = static_cast((void*)static_cast(0xdeadbeef)); + g_slots[i].slots = + static_cast((void*)static_cast(0xdeadbeef)); } } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 2f4bcc357c..d1f3276257 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -142,7 +142,8 @@ static grpc_error* non_polling_poller_kick( if (specific_worker == nullptr) specific_worker = reinterpret_cast(p->root); if (specific_worker != nullptr) { - non_polling_worker* w = reinterpret_cast(specific_worker); + non_polling_worker* w = + reinterpret_cast(specific_worker); if (!w->kicked) { w->kicked = true; gpr_cv_signal(&w->cv); @@ -357,7 +358,7 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, *ok = (storage->next & static_cast(1)) == 1; storage->done(storage->done_arg, storage); ret = 1; - cq_next_data* cqd = static_castDATA_FROM_CQ(cq); + cq_next_data* cqd = static_cast DATA_FROM_CQ(cq); if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_mu_lock(cq->mu); @@ -395,7 +396,8 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(); bool is_empty = false; - c = reinterpret_cast(gpr_mpscq_pop_and_check_end(&q->queue, &is_empty)); + c = reinterpret_cast( + gpr_mpscq_pop_and_check_end(&q->queue, &is_empty)); gpr_spinlock_unlock(&q->queue_lock); if (c == nullptr && !is_empty) { @@ -415,7 +417,7 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { /* Note: The counter is not incremented/decremented atomically with push/pop. * The count is only eventually consistent */ static long cq_event_queue_num_items(grpc_cq_event_queue* q) { - return static_castgpr_atm_no_barrier_load(&q->num_queue_items); + return static_cast gpr_atm_no_barrier_load(&q->num_queue_items); } grpc_completion_queue* grpc_completion_queue_create_internal( @@ -437,9 +439,9 @@ grpc_completion_queue* grpc_completion_queue_create_internal( grpc_core::ExecCtx exec_ctx; GRPC_STATS_INC_CQS_CREATED(); - cq = static_cast(gpr_zalloc(sizeof(grpc_completion_queue) + - vtable->data_size + - poller_vtable->size())); + cq = static_cast( + gpr_zalloc(sizeof(grpc_completion_queue) + vtable->data_size + + poller_vtable->size())); cq->vtable = vtable; cq->poller_vtable = poller_vtable; @@ -587,12 +589,12 @@ static bool atm_inc_if_nonzero(gpr_atm* counter) { } static bool cq_begin_op_for_next(grpc_completion_queue* cq, void* tag) { - cq_next_data* cqd = static_castDATA_FROM_CQ(cq); + cq_next_data* cqd = static_cast DATA_FROM_CQ(cq); return atm_inc_if_nonzero(&cqd->pending_events); } static bool cq_begin_op_for_pluck(grpc_completion_queue* cq, void* tag) { - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); return atm_inc_if_nonzero(&cqd->pending_events); } @@ -632,7 +634,7 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } } - cq_next_data* cqd = static_castDATA_FROM_CQ(cq); + cq_next_data* cqd = static_cast DATA_FROM_CQ(cq); int is_success = (error == GRPC_ERROR_NONE); storage->tag = tag; @@ -701,7 +703,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, void* done_arg, grpc_cq_completion* storage) { GPR_TIMER_SCOPE("cq_end_op_for_pluck", 0); - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); int is_success = (error == GRPC_ERROR_NONE); if (grpc_api_trace.enabled() || @@ -719,7 +721,8 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, storage->tag = tag; storage->done = done; storage->done_arg = done_arg; - storage->next = ((uintptr_t)&cqd->completed_head) | (static_cast(is_success)); + storage->next = + ((uintptr_t)&cqd->completed_head) | (static_cast(is_success)); gpr_mu_lock(cq->mu); cq_check_tag(cq, tag, false); /* Used in debug builds only */ @@ -778,9 +781,10 @@ class ExecCtxNext : public grpc_core::ExecCtx { ExecCtxNext(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} bool CheckReadyToFinish() override { - cq_is_finished_arg* a = static_cast(check_ready_to_finish_arg_); + cq_is_finished_arg* a = + static_cast(check_ready_to_finish_arg_); grpc_completion_queue* cq = a->cq; - cq_next_data* cqd = static_castDATA_FROM_CQ(cq); + cq_next_data* cqd = static_cast DATA_FROM_CQ(cq); GPR_ASSERT(a->stolen_completion == nullptr); gpr_atm current_last_seen_things_queued_ever = @@ -836,7 +840,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, GPR_TIMER_SCOPE("grpc_completion_queue_next", 0); grpc_event ret; - cq_next_data* cqd = static_castDATA_FROM_CQ(cq); + cq_next_data* cqd = static_cast DATA_FROM_CQ(cq); GRPC_API_TRACE( "grpc_completion_queue_next(" @@ -961,7 +965,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, - grpc_completion_queue_shutdown() MUST have been called before calling this function */ static void cq_finish_shutdown_next(grpc_completion_queue* cq) { - cq_next_data* cqd = static_castDATA_FROM_CQ(cq); + cq_next_data* cqd = static_cast DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(gpr_atm_no_barrier_load(&cqd->pending_events) == 0); @@ -970,7 +974,7 @@ static void cq_finish_shutdown_next(grpc_completion_queue* cq) { } static void cq_shutdown_next(grpc_completion_queue* cq) { - cq_next_data* cqd = static_castDATA_FROM_CQ(cq); + cq_next_data* cqd = static_cast DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: * We call cq_finish_shutdown_next() below, that would call pollset shutdown. @@ -1003,7 +1007,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue* cq, static int add_plucker(grpc_completion_queue* cq, void* tag, grpc_pollset_worker** worker) { - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); if (cqd->num_pluckers == GRPC_MAX_COMPLETION_QUEUE_PLUCKERS) { return 0; } @@ -1015,7 +1019,7 @@ static int add_plucker(grpc_completion_queue* cq, void* tag, static void del_plucker(grpc_completion_queue* cq, void* tag, grpc_pollset_worker** worker) { - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); for (int i = 0; i < cqd->num_pluckers; i++) { if (cqd->pluckers[i].tag == tag && cqd->pluckers[i].worker == worker) { cqd->num_pluckers--; @@ -1031,9 +1035,10 @@ class ExecCtxPluck : public grpc_core::ExecCtx { ExecCtxPluck(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} bool CheckReadyToFinish() override { - cq_is_finished_arg* a = static_cast(check_ready_to_finish_arg_); + cq_is_finished_arg* a = + static_cast(check_ready_to_finish_arg_); grpc_completion_queue* cq = a->cq; - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); GPR_ASSERT(a->stolen_completion == nullptr); gpr_atm current_last_seen_things_queued_ever = @@ -1045,10 +1050,12 @@ class ExecCtxPluck : public grpc_core::ExecCtx { gpr_atm_no_barrier_load(&cqd->things_queued_ever); grpc_cq_completion* c; grpc_cq_completion* prev = &cqd->completed_head; - while ((c = (grpc_cq_completion*)(prev->next & ~static_cast(1))) != + while ((c = (grpc_cq_completion*)(prev->next & + ~static_cast(1))) != &cqd->completed_head) { if (c->tag == a->tag) { - prev->next = (prev->next & static_cast(1)) | (c->next & ~static_cast(1)); + prev->next = (prev->next & static_cast(1)) | + (c->next & ~static_cast(1)); if (c == cqd->completed_tail) { cqd->completed_tail = prev; } @@ -1075,7 +1082,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, grpc_cq_completion* c; grpc_cq_completion* prev; grpc_pollset_worker* worker = nullptr; - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); if (grpc_cq_pluck_trace.enabled()) { GRPC_API_TRACE( @@ -1115,10 +1122,12 @@ 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 = (grpc_cq_completion*)(prev->next & ~static_cast(1))) != + &cqd->completed_head) { if (c->tag == tag) { - prev->next = (prev->next & static_cast(1)) | (c->next & ~static_cast(1)); + prev->next = (prev->next & static_cast(1)) | + (c->next & ~static_cast(1)); if (c == cqd->completed_tail) { cqd->completed_tail = prev; } @@ -1191,7 +1200,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, } static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) { - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(!gpr_atm_no_barrier_load(&cqd->shutdown)); @@ -1203,7 +1212,7 @@ static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) { /* NOTE: This function is almost exactly identical to cq_shutdown_next() but * merging them is a bit tricky and probably not worth it */ static void cq_shutdown_pluck(grpc_completion_queue* cq) { - cq_pluck_data* cqd = static_castDATA_FROM_CQ(cq); + cq_pluck_data* cqd = static_cast DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: * We call cq_finish_shutdown_pluck() below, that would call pollset shutdown. diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index ad3ee62ad8..d71a23a5d7 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -241,8 +241,8 @@ static void channel_broadcaster_init(grpc_server* s, channel_broadcaster* cb) { count++; } cb->num_channels = count; - cb->channels = - static_cast(gpr_malloc(sizeof(*cb->channels) * cb->num_channels)); + cb->channels = static_cast( + gpr_malloc(sizeof(*cb->channels) * cb->num_channels)); count = 0; for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) { cb->channels[count++] = c->channel; @@ -256,7 +256,8 @@ struct shutdown_cleanup_args { }; static void shutdown_cleanup(void* arg, grpc_error* error) { - struct shutdown_cleanup_args* a = static_cast(arg); + struct shutdown_cleanup_args* a = + static_cast(arg); grpc_slice_unref_internal(a->slice); gpr_free(a); } @@ -304,8 +305,8 @@ static void channel_broadcaster_shutdown(channel_broadcaster* cb, static void request_matcher_init(request_matcher* rm, grpc_server* server) { memset(rm, 0, sizeof(*rm)); rm->server = server; - rm->requests_per_cq = static_cast(gpr_malloc( - sizeof(*rm->requests_per_cq) * server->cq_count)); + rm->requests_per_cq = static_cast( + gpr_malloc(sizeof(*rm->requests_per_cq) * server->cq_count)); for (size_t i = 0; i < server->cq_count; i++) { gpr_locked_mpscq_init(&rm->requests_per_cq[i]); } @@ -320,7 +321,8 @@ static void request_matcher_destroy(request_matcher* rm) { } static void kill_zombie(void* elem, grpc_error* error) { - grpc_call_unref(grpc_call_from_top_element(static_cast(elem))); + grpc_call_unref( + grpc_call_from_top_element(static_cast(elem))); } static void request_matcher_zombify_all_pending_calls(request_matcher* rm) { @@ -341,8 +343,8 @@ static void request_matcher_kill_requests(grpc_server* server, grpc_error* error) { requested_call* rc; for (size_t i = 0; i < server->cq_count; i++) { - while ((rc = reinterpret_cast(gpr_locked_mpscq_pop( - &rm->requests_per_cq[i]))) != nullptr) { + while ((rc = reinterpret_cast( + gpr_locked_mpscq_pop(&rm->requests_per_cq[i]))) != nullptr) { fail_call(server, i, rc, GRPC_ERROR_REF(error)); } } @@ -487,8 +489,8 @@ static void publish_new_rpc(void* arg, grpc_error* error) { for (size_t i = 0; i < server->cq_count; i++) { size_t cq_idx = (chand->cq_idx + i) % server->cq_count; - requested_call* rc = - reinterpret_cast(gpr_locked_mpscq_try_pop(&rm->requests_per_cq[cq_idx])); + requested_call* rc = reinterpret_cast( + gpr_locked_mpscq_try_pop(&rm->requests_per_cq[cq_idx])); if (rc == nullptr) { continue; } else { @@ -509,8 +511,8 @@ static void publish_new_rpc(void* arg, grpc_error* error) { // added to the pending list. for (size_t i = 0; i < server->cq_count; i++) { size_t cq_idx = (chand->cq_idx + i) % server->cq_count; - requested_call* rc = - reinterpret_cast(gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx])); + requested_call* rc = reinterpret_cast( + gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx])); if (rc == nullptr) { continue; } else { @@ -939,7 +941,8 @@ void grpc_server_register_completion_queue(grpc_server* server, grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) { GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved)); - grpc_server* server = static_cast(gpr_zalloc(sizeof(grpc_server))); + grpc_server* server = + static_cast(gpr_zalloc(sizeof(grpc_server))); gpr_mu_init(&server->mu_global); gpr_mu_init(&server->mu_call); @@ -1020,8 +1023,8 @@ void grpc_server_start(grpc_server* server) { server->started = true; server->pollset_count = 0; - server->pollsets = - static_cast(gpr_malloc(sizeof(grpc_pollset*) * server->cq_count)); + server->pollsets = static_cast( + gpr_malloc(sizeof(grpc_pollset*) * server->cq_count)); for (i = 0; i < server->cq_count; i++) { if (grpc_cq_can_listen(server->cqs[i])) { server->pollsets[server->pollset_count++] = @@ -1063,9 +1066,9 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, grpc_transport_op* op = nullptr; channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport); - chand = static_cast(grpc_channel_stack_element( - grpc_channel_get_channel_stack(channel), 0) - ->channel_data); + chand = static_cast( + grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0) + ->channel_data); chand->server = s; server_ref(s); chand->channel = channel; @@ -1089,7 +1092,8 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, if (num_registered_methods > 0) { slots = 2 * num_registered_methods; alloc = sizeof(channel_registered_method) * slots; - chand->registered_methods = static_cast(gpr_zalloc(alloc)); + chand->registered_methods = + static_cast(gpr_zalloc(alloc)); for (rm = s->registered_methods; rm; rm = rm->next) { grpc_slice host; bool has_host; @@ -1176,13 +1180,14 @@ void grpc_server_shutdown_and_notify(grpc_server* server, GPR_ASSERT(grpc_cq_begin_op(cq, tag)); if (server->shutdown_published) { grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, nullptr, - static_cast(gpr_malloc(sizeof(grpc_cq_completion)))); + static_cast( + gpr_malloc(sizeof(grpc_cq_completion)))); gpr_mu_unlock(&server->mu_global); return; } - server->shutdown_tags = static_cast(gpr_realloc( - server->shutdown_tags, - sizeof(shutdown_tag) * (server->num_shutdown_tags + 1))); + server->shutdown_tags = static_cast( + gpr_realloc(server->shutdown_tags, + sizeof(shutdown_tag) * (server->num_shutdown_tags + 1))); sdt = &server->shutdown_tags[server->num_shutdown_tags++]; sdt->tag = tag; sdt->cq = cq; @@ -1289,7 +1294,8 @@ static grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx, matching calls */ gpr_mu_lock(&server->mu_call); while ((calld = rm->pending_head) != nullptr) { - rc = reinterpret_cast(gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx])); + rc = reinterpret_cast( + gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx])); if (rc == nullptr) break; rm->pending_head = calld->pending_next; gpr_mu_unlock(&server->mu_call); diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 044183e8fd..70b308230b 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -40,7 +40,8 @@ BdpEstimator::BdpEstimator(const char* name) grpc_millis BdpEstimator::CompletePing() { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec dt_ts = gpr_time_sub(now, ping_start_time_); - double dt = static_cast(dt_ts.tv_sec) + 1e-9 * static_cast(dt_ts.tv_nsec); + double dt = static_cast(dt_ts.tv_sec) + + 1e-9 * static_cast(dt_ts.tv_nsec); double bw = dt > 0 ? (static_cast(accumulator_) / dt) : 0; int start_inter_ping_delay = inter_ping_delay_; if (grpc_bdp_estimator_trace.enabled()) { @@ -64,8 +65,8 @@ grpc_millis BdpEstimator::CompletePing() { stable_estimate_count_++; if (stable_estimate_count_ >= 2) { inter_ping_delay_ += - 100 + - static_cast(rand() * 100.0 / RAND_MAX); // if the ping estimate is steady, + 100 + static_cast(rand() * 100.0 / + RAND_MAX); // if the ping estimate is steady, // slowly ramp down the probe time } } diff --git a/src/core/lib/transport/byte_stream.cc b/src/core/lib/transport/byte_stream.cc index 2ae0b8298a..afb55b2f20 100644 --- a/src/core/lib/transport/byte_stream.cc +++ b/src/core/lib/transport/byte_stream.cc @@ -49,14 +49,16 @@ void grpc_byte_stream_destroy(grpc_byte_stream* byte_stream) { static bool slice_buffer_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { - grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); + grpc_slice_buffer_stream* stream = + reinterpret_cast(byte_stream); GPR_ASSERT(stream->cursor < stream->backing_buffer->count); return true; } static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { - grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); + grpc_slice_buffer_stream* stream = + reinterpret_cast(byte_stream); if (stream->shutdown_error != GRPC_ERROR_NONE) { return GRPC_ERROR_REF(stream->shutdown_error); } @@ -69,13 +71,15 @@ static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream, static void slice_buffer_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { - grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); + grpc_slice_buffer_stream* stream = + reinterpret_cast(byte_stream); GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = error; } static void slice_buffer_stream_destroy(grpc_byte_stream* byte_stream) { - grpc_slice_buffer_stream* stream = reinterpret_cast(byte_stream); + grpc_slice_buffer_stream* stream = + reinterpret_cast(byte_stream); grpc_slice_buffer_reset_and_unref_internal(stream->backing_buffer); GRPC_ERROR_UNREF(stream->shutdown_error); } @@ -112,7 +116,8 @@ void grpc_byte_stream_cache_destroy(grpc_byte_stream_cache* cache) { static bool caching_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { - grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); + grpc_caching_byte_stream* stream = + reinterpret_cast(byte_stream); if (stream->shutdown_error != GRPC_ERROR_NONE) return true; if (stream->cursor < stream->cache->cache_buffer.count) return true; return grpc_byte_stream_next(stream->cache->underlying_stream, max_size_hint, @@ -121,7 +126,8 @@ static bool caching_byte_stream_next(grpc_byte_stream* byte_stream, static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { - grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); + grpc_caching_byte_stream* stream = + reinterpret_cast(byte_stream); if (stream->shutdown_error != GRPC_ERROR_NONE) { return GRPC_ERROR_REF(stream->shutdown_error); } @@ -143,14 +149,16 @@ static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, static void caching_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { - grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); + grpc_caching_byte_stream* stream = + reinterpret_cast(byte_stream); GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = GRPC_ERROR_REF(error); grpc_byte_stream_shutdown(stream->cache->underlying_stream, error); } static void caching_byte_stream_destroy(grpc_byte_stream* byte_stream) { - grpc_caching_byte_stream* stream = reinterpret_cast(byte_stream); + grpc_caching_byte_stream* stream = + reinterpret_cast(byte_stream); GRPC_ERROR_UNREF(stream->shutdown_error); } diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index 183d5987ee..a5b7bb508f 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -74,7 +74,7 @@ void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) { grpc_connectivity_state grpc_connectivity_state_check( grpc_connectivity_state_tracker* tracker) { grpc_connectivity_state cur = - static_castgpr_atm_no_barrier_load( + static_cast gpr_atm_no_barrier_load( &tracker->current_state_atm); if (grpc_connectivity_state_trace.enabled()) { gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, @@ -86,7 +86,7 @@ grpc_connectivity_state grpc_connectivity_state_check( grpc_connectivity_state grpc_connectivity_state_get( grpc_connectivity_state_tracker* tracker, grpc_error** error) { grpc_connectivity_state cur = - static_castgpr_atm_no_barrier_load( + static_cast gpr_atm_no_barrier_load( &tracker->current_state_atm); if (grpc_connectivity_state_trace.enabled()) { gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, @@ -107,7 +107,7 @@ bool grpc_connectivity_state_notify_on_state_change( grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, grpc_closure* notify) { grpc_connectivity_state cur = - static_castgpr_atm_no_barrier_load( + static_cast gpr_atm_no_barrier_load( &tracker->current_state_atm); if (grpc_connectivity_state_trace.enabled()) { if (current == nullptr) { @@ -158,7 +158,7 @@ void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, grpc_connectivity_state state, grpc_error* error, const char* reason) { grpc_connectivity_state cur = - static_castgpr_atm_no_barrier_load( + static_cast gpr_atm_no_barrier_load( &tracker->current_state_atm); grpc_connectivity_state_watcher* w; if (grpc_connectivity_state_trace.enabled()) { diff --git a/src/core/lib/transport/error_utils.cc b/src/core/lib/transport/error_utils.cc index b968383eda..79d904315e 100644 --- a/src/core/lib/transport/error_utils.cc +++ b/src/core/lib/transport/error_utils.cc @@ -32,7 +32,8 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error, // Otherwise, search through its children. uint8_t slot = error->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = reinterpret_cast(error->arena + slot); + grpc_linked_error* lerr = + reinterpret_cast(error->arena + slot); grpc_error* result = recursively_find_error_with_field(lerr->err, which); if (result) return result; slot = lerr->next; @@ -65,8 +66,8 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline, status = static_cast(integer); } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { - status = grpc_http2_error_to_grpc_status(static_cast(integer), - deadline); + status = grpc_http2_error_to_grpc_status( + static_cast(integer), deadline); } if (code != nullptr) *code = status; @@ -79,7 +80,8 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline, *http_error = static_cast(integer); } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) { - *http_error = grpc_status_to_http2_error(static_cast(integer)); + *http_error = + grpc_status_to_http2_error(static_cast(integer)); } else { *http_error = found_error == GRPC_ERROR_NONE ? GRPC_HTTP2_NO_ERROR : GRPC_HTTP2_INTERNAL_ERROR; @@ -103,7 +105,8 @@ bool grpc_error_has_clear_grpc_status(grpc_error* error) { } uint8_t slot = error->first_err; while (slot != UINT8_MAX) { - grpc_linked_error* lerr = reinterpret_cast(error->arena + slot); + grpc_linked_error* lerr = + reinterpret_cast(error->arena + slot); if (grpc_error_has_clear_grpc_status(lerr->err)) { return true; } diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 418224bc97..e06e0b5313 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -118,8 +118,8 @@ void grpc_mdctx_global_init(void) { shard->count = 0; gpr_atm_no_barrier_store(&shard->free_estimate, 0); shard->capacity = INITIAL_SHARD_CAPACITY; - shard->elems = static_cast(gpr_zalloc(sizeof(*shard->elems) * - shard->capacity)); + shard->elems = static_cast( + gpr_zalloc(sizeof(*shard->elems) * shard->capacity)); } } @@ -206,8 +206,8 @@ static void grow_mdtab(mdtab_shard* shard) { interned_metadata *md, *next; uint32_t hash; - mdtab = - static_cast(gpr_zalloc(sizeof(interned_metadata*) * capacity)); + mdtab = static_cast( + gpr_zalloc(sizeof(interned_metadata*) * capacity)); for (i = 0; i < shard->capacity; i++) { for (md = shard->elems[i]; md; md = next) { @@ -335,8 +335,9 @@ grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata) { grpc_slice_maybe_static_intern(metadata->key, &changed); grpc_slice value_slice = grpc_slice_maybe_static_intern(metadata->value, &changed); - return grpc_mdelem_create(key_slice, value_slice, - changed ? nullptr : reinterpret_cast(metadata)); + return grpc_mdelem_create( + key_slice, value_slice, + changed ? nullptr : reinterpret_cast(metadata)); } static size_t get_base64_encoded_size(size_t raw_length) { @@ -363,7 +364,8 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_STATIC: break; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); + interned_metadata* md = + reinterpret_cast GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -385,7 +387,8 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { break; } case GRPC_MDELEM_STORAGE_ALLOCATED: { - allocated_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); + allocated_metadata* md = + reinterpret_cast GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -415,7 +418,8 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_STATIC: break; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); + interned_metadata* md = + reinterpret_cast GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -441,7 +445,8 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) { break; } case GRPC_MDELEM_STORAGE_ALLOCATED: { - allocated_metadata* md = reinterpret_castGRPC_MDELEM_DATA(gmd); + allocated_metadata* md = + reinterpret_cast GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); @@ -475,7 +480,8 @@ void* grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void*)) { return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - grpc_static_mdelem_table]; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* im = reinterpret_castGRPC_MDELEM_DATA(md); + interned_metadata* im = + reinterpret_cast GRPC_MDELEM_DATA(md); void* result; if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { return (void*)gpr_atm_no_barrier_load(&im->user_data); @@ -500,7 +506,8 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - grpc_static_mdelem_table]; case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata* im = reinterpret_castGRPC_MDELEM_DATA(md); + interned_metadata* im = + reinterpret_cast GRPC_MDELEM_DATA(md); GPR_ASSERT(!is_mdelem_static(md)); GPR_ASSERT((user_data == nullptr) == (destroy_func == nullptr)); gpr_mu_lock(&im->mu_user_data); diff --git a/src/core/lib/transport/service_config.cc b/src/core/lib/transport/service_config.cc index f5805b2fa4..75196c5f88 100644 --- a/src/core/lib/transport/service_config.cc +++ b/src/core/lib/transport/service_config.cc @@ -209,8 +209,8 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( num_entries += count; } // Populate method config table entries. - entries = static_cast(gpr_malloc( - num_entries * sizeof(grpc_slice_hash_table_entry))); + entries = static_cast( + gpr_malloc(num_entries * sizeof(grpc_slice_hash_table_entry))); size_t idx = 0; for (grpc_json* method = field->child; method != nullptr; method = method->next) { diff --git a/src/core/lib/transport/timeout_encoding.cc b/src/core/lib/transport/timeout_encoding.cc index f47f3fa44b..6800255be2 100644 --- a/src/core/lib/transport/timeout_encoding.cc +++ b/src/core/lib/transport/timeout_encoding.cc @@ -138,5 +138,6 @@ int grpc_http2_decode_timeout(grpc_slice text, grpc_millis* timeout) { return 0; } p++; - return is_all_whitespace(reinterpret_cast(p), reinterpret_cast(end)); + return is_all_whitespace(reinterpret_cast(p), + reinterpret_cast(end)); } diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 56fc1ce13e..d71d4fdd76 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -239,7 +239,8 @@ static void destroy_made_transport_op(void* arg, grpc_error* error) { } grpc_transport_op* grpc_make_transport_op(grpc_closure* on_complete) { - made_transport_op* op = static_cast(gpr_malloc(sizeof(*op))); + made_transport_op* op = + static_cast(gpr_malloc(sizeof(*op))); GRPC_CLOSURE_INIT(&op->outer_on_complete, destroy_made_transport_op, op, grpc_schedule_on_exec_ctx); op->inner_on_complete = on_complete; diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index c7eb750a5b..b5b7203d20 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -112,7 +112,8 @@ static tsi_result tsi_fake_handshake_message_from_string( static uint32_t load32_little_endian(const unsigned char* buf) { return (static_cast(buf[0]) | static_cast(buf[1] << 8) | - static_cast(buf[2] << 16) | static_cast(buf[3] << 24)); + static_cast(buf[2] << 16) | + static_cast(buf[3] << 24)); } static void store32_little_endian(uint32_t value, unsigned char* buf) { @@ -155,7 +156,8 @@ static void tsi_fake_frame_reset(tsi_fake_frame* frame, int needs_draining) { static void tsi_fake_frame_ensure_size(tsi_fake_frame* frame) { if (frame->data == nullptr) { frame->allocated_size = frame->size; - frame->data = static_cast(gpr_malloc(frame->allocated_size)); + frame->data = + static_cast(gpr_malloc(frame->allocated_size)); } else if (frame->size > frame->allocated_size) { unsigned char* new_data = static_cast(gpr_realloc(frame->data, frame->size)); @@ -177,7 +179,8 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, if (frame->needs_draining) return TSI_INTERNAL_ERROR; if (frame->data == nullptr) { frame->allocated_size = TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE; - frame->data = static_cast(gpr_malloc(frame->allocated_size)); + frame->data = + static_cast(gpr_malloc(frame->allocated_size)); } if (frame->offset < TSI_FAKE_FRAME_HEADER_SIZE) { @@ -258,7 +261,8 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = reinterpret_cast(self); + tsi_fake_frame_protector* impl = + reinterpret_cast(self); unsigned char frame_header[TSI_FAKE_FRAME_HEADER_SIZE]; tsi_fake_frame* frame = &impl->protect_frame; size_t saved_output_size = *protected_output_frames_size; @@ -287,7 +291,8 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, if (frame->size == 0) { /* New frame, create a header. */ size_t written_in_frame_size = 0; - store32_little_endian(static_cast(impl->max_frame_size), frame_header); + store32_little_endian(static_cast(impl->max_frame_size), + frame_header); written_in_frame_size = TSI_FAKE_FRAME_HEADER_SIZE; result = tsi_fake_frame_decode(frame_header, &written_in_frame_size, frame); if (result != TSI_INCOMPLETE_DATA) { @@ -317,7 +322,8 @@ static tsi_result fake_protector_protect_flush( tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = reinterpret_cast(self); + tsi_fake_frame_protector* impl = + reinterpret_cast(self); tsi_fake_frame* frame = &impl->protect_frame; if (!frame->needs_draining) { /* Create a short frame. */ @@ -339,7 +345,8 @@ static tsi_result fake_protector_unprotect( size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = reinterpret_cast(self); + tsi_fake_frame_protector* impl = + reinterpret_cast(self); tsi_fake_frame* frame = &impl->unprotect_frame; size_t saved_output_size = *unprotected_bytes_size; size_t drained_size = 0; @@ -384,7 +391,8 @@ static tsi_result fake_protector_unprotect( } static void fake_protector_destroy(tsi_frame_protector* self) { - tsi_fake_frame_protector* impl = reinterpret_cast(self); + tsi_fake_frame_protector* impl = + reinterpret_cast(self); tsi_fake_frame_destruct(&impl->protect_frame); tsi_fake_frame_destruct(&impl->unprotect_frame); gpr_free(self); @@ -414,7 +422,8 @@ static tsi_result fake_zero_copy_grpc_protector_protect( GPR_MIN(impl->max_frame_size, unprotected_slices->length + TSI_FAKE_FRAME_HEADER_SIZE); grpc_slice slice = GRPC_SLICE_MALLOC(TSI_FAKE_FRAME_HEADER_SIZE); - store32_little_endian(static_cast(frame_length), GRPC_SLICE_START_PTR(slice)); + store32_little_endian(static_cast(frame_length), + GRPC_SLICE_START_PTR(slice)); grpc_slice_buffer_add(protected_slices, slice); size_t data_length = frame_length - TSI_FAKE_FRAME_HEADER_SIZE; grpc_slice_buffer_move_first(unprotected_slices, data_length, @@ -520,7 +529,8 @@ static tsi_result fake_handshaker_result_get_unused_bytes( } static void fake_handshaker_result_destroy(tsi_handshaker_result* self) { - fake_handshaker_result* result = reinterpret_cast(self); + fake_handshaker_result* result = + reinterpret_cast(self); gpr_free(result->unused_bytes); gpr_free(self); } @@ -544,7 +554,8 @@ static tsi_result fake_handshaker_result_create( static_cast(gpr_zalloc(sizeof(*result))); result->base.vtable = &handshaker_result_vtable; if (unused_bytes_size > 0) { - result->unused_bytes = static_cast(gpr_malloc(unused_bytes_size)); + result->unused_bytes = + static_cast(gpr_malloc(unused_bytes_size)); memcpy(result->unused_bytes, unused_bytes, unused_bytes_size); } result->unused_bytes_size = unused_bytes_size; @@ -612,7 +623,8 @@ static tsi_result fake_handshaker_process_bytes_from_peer( /* We now have a complete frame. */ result = tsi_fake_handshake_message_from_string( - reinterpret_cast(impl->incoming_frame.data) + TSI_FAKE_FRAME_HEADER_SIZE, + reinterpret_cast(impl->incoming_frame.data) + + TSI_FAKE_FRAME_HEADER_SIZE, &received_msg); if (result != TSI_OK) { impl->result = result; @@ -663,7 +675,8 @@ static tsi_result fake_handshaker_next( handshaker_result == nullptr) { return TSI_INVALID_ARGUMENT; } - tsi_fake_handshaker* handshaker = reinterpret_cast(self); + tsi_fake_handshaker* handshaker = + reinterpret_cast(self); tsi_result result = TSI_OK; /* Decode and process a handshake frame from the peer. */ @@ -684,9 +697,9 @@ static tsi_result fake_handshaker_next( offset += sent_bytes_size; if (result == TSI_INCOMPLETE_DATA) { handshaker->outgoing_bytes_buffer_size *= 2; - handshaker->outgoing_bytes_buffer = - static_cast(gpr_realloc(handshaker->outgoing_bytes_buffer, - handshaker->outgoing_bytes_buffer_size)); + handshaker->outgoing_bytes_buffer = static_cast( + gpr_realloc(handshaker->outgoing_bytes_buffer, + handshaker->outgoing_bytes_buffer_size)); } } while (result == TSI_INCOMPLETE_DATA); if (result != TSI_OK) return result; @@ -727,7 +740,8 @@ static const tsi_handshaker_vtable handshaker_vtable = { }; tsi_handshaker* tsi_create_fake_handshaker(int is_client) { - tsi_fake_handshaker* impl = static_cast(gpr_zalloc(sizeof(*impl))); + tsi_fake_handshaker* impl = + static_cast(gpr_zalloc(sizeof(*impl))); impl->base.vtable = &handshaker_vtable; impl->is_client = is_client; impl->result = TSI_HANDSHAKE_IN_PROGRESS; @@ -759,7 +773,8 @@ tsi_frame_protector* tsi_create_fake_frame_protector( tsi_zero_copy_grpc_protector* tsi_create_fake_zero_copy_grpc_protector( size_t* max_protected_frame_size) { tsi_fake_zero_copy_grpc_protector* impl = - static_cast(gpr_zalloc(sizeof(*impl))); + static_cast( + gpr_zalloc(sizeof(*impl))); grpc_slice_buffer_init(&impl->header_sb); grpc_slice_buffer_init(&impl->protected_sb); impl->max_frame_size = (max_protected_frame_size == nullptr) diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index b32649a8b9..643b5a5c79 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -137,7 +137,8 @@ static void init_openssl(void) { OpenSSL_add_all_algorithms(); num_locks = CRYPTO_num_locks(); GPR_ASSERT(num_locks > 0); - openssl_mutexes = static_cast(gpr_malloc(static_cast(num_locks) * sizeof(gpr_mu))); + openssl_mutexes = static_cast( + gpr_malloc(static_cast(num_locks) * sizeof(gpr_mu))); for (i = 0; i < CRYPTO_num_locks(); i++) { gpr_mu_init(&openssl_mutexes[i]); } @@ -275,8 +276,8 @@ static tsi_result peer_property_from_x509_common_name( } result = tsi_construct_string_peer_property( TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, - common_name == nullptr ? "" : reinterpret_cast(common_name), common_name_size, - property); + common_name == nullptr ? "" : reinterpret_cast(common_name), + common_name_size, property); OPENSSL_free(common_name); return result; } @@ -295,7 +296,8 @@ 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, (const char*)contents, + static_cast(len), property); BIO_free(bio); return result; } @@ -324,8 +326,9 @@ static tsi_result add_subject_alt_names_properties_to_peer( break; } result = tsi_construct_string_peer_property( - TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, reinterpret_cast(name), - static_cast(name_size), &peer->properties[peer->property_count++]); + TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, + reinterpret_cast(name), static_cast(name_size), + &peer->properties[peer->property_count++]); OPENSSL_free(name); } else if (subject_alt_name->type == GEN_IPADD) { char ntop_buf[INET6_ADDRSTRLEN]; @@ -361,11 +364,12 @@ static tsi_result add_subject_alt_names_properties_to_peer( static tsi_result peer_from_x509(X509* cert, int include_certificate_type, tsi_peer* peer) { /* TODO(jboeuf): Maybe add more properties. */ - GENERAL_NAMES* subject_alt_names = static_cast(X509_get_ext_d2i( - cert, NID_subject_alt_name, nullptr, nullptr)); - int subject_alt_name_count = (subject_alt_names != nullptr) - ? static_cast(sk_GENERAL_NAME_num(subject_alt_names)) - : 0; + GENERAL_NAMES* subject_alt_names = static_cast( + X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr)); + int subject_alt_name_count = + (subject_alt_names != nullptr) + ? static_cast(sk_GENERAL_NAME_num(subject_alt_names)) + : 0; size_t property_count; tsi_result result; GPR_ASSERT(subject_alt_name_count >= 0); @@ -418,8 +422,8 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { int read_from_ssl; GPR_ASSERT(*unprotected_bytes_size <= INT_MAX); - read_from_ssl = - SSL_read(ssl, unprotected_bytes, static_cast(*unprotected_bytes_size)); + read_from_ssl = SSL_read(ssl, unprotected_bytes, + static_cast(*unprotected_bytes_size)); if (read_from_ssl <= 0) { read_from_ssl = SSL_get_error(ssl, read_from_ssl); switch (read_from_ssl) { @@ -451,8 +455,8 @@ static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes, size_t unprotected_bytes_size) { int ssl_write_result; GPR_ASSERT(unprotected_bytes_size <= INT_MAX); - ssl_write_result = - SSL_write(ssl, unprotected_bytes, static_cast(unprotected_bytes_size)); + ssl_write_result = SSL_write(ssl, unprotected_bytes, + static_cast(unprotected_bytes_size)); if (ssl_write_result < 0) { ssl_write_result = SSL_get_error(ssl, ssl_write_result); if (ssl_write_result == SSL_ERROR_WANT_READ) { @@ -476,7 +480,8 @@ 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((void*)pem_cert_chain, + static_cast(pem_cert_chain_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { @@ -683,12 +688,14 @@ static tsi_result build_alpn_protocol_name_list( size_t length = alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]); if (length == 0 || length > 255) { - gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", static_cast(length)); + gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", + static_cast(length)); return TSI_INVALID_ARGUMENT; } *protocol_name_list_length += length + 1; } - *protocol_name_list = static_cast(gpr_malloc(*protocol_name_list_length)); + *protocol_name_list = + static_cast(gpr_malloc(*protocol_name_list_length)); if (*protocol_name_list == nullptr) return TSI_OUT_OF_RESOURCES; current = *protocol_name_list; for (i = 0; i < num_alpn_protocols; i++) { @@ -721,7 +728,8 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, size_t* unprotected_bytes_size, unsigned char* protected_output_frames, size_t* protected_output_frames_size) { - tsi_ssl_frame_protector* impl = reinterpret_cast(self); + tsi_ssl_frame_protector* impl = + reinterpret_cast(self); int read_from_ssl; size_t available; tsi_result result = TSI_OK; @@ -775,7 +783,8 @@ static tsi_result ssl_protector_protect_flush( tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_ssl_frame_protector* impl = reinterpret_cast(self); + tsi_ssl_frame_protector* impl = + reinterpret_cast(self); int read_from_ssl = 0; int pending; @@ -812,7 +821,8 @@ static tsi_result ssl_protector_unprotect( int written_into_ssl = 0; size_t output_bytes_size = *unprotected_bytes_size; size_t output_bytes_offset = 0; - tsi_ssl_frame_protector* impl = reinterpret_cast(self); + tsi_ssl_frame_protector* impl = + reinterpret_cast(self); /* First, try to read remaining data from ssl. */ result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size); @@ -847,7 +857,8 @@ static tsi_result ssl_protector_unprotect( } static void ssl_protector_destroy(tsi_frame_protector* self) { - tsi_ssl_frame_protector* impl = reinterpret_cast(self); + tsi_ssl_frame_protector* impl = + reinterpret_cast(self); if (impl->buffer != nullptr) gpr_free(impl->buffer); if (impl->ssl != nullptr) SSL_free(impl->ssl); if (impl->network_io != nullptr) BIO_free(impl->network_io); @@ -914,7 +925,8 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, return TSI_INVALID_ARGUMENT; } GPR_ASSERT(*bytes_size <= INT_MAX); - bytes_read_from_ssl = BIO_read(impl->network_io, bytes, static_cast(*bytes_size)); + bytes_read_from_ssl = + BIO_read(impl->network_io, bytes, static_cast(*bytes_size)); if (bytes_read_from_ssl < 0) { *bytes_size = 0; if (!BIO_should_retry(impl->network_io)) { @@ -1005,14 +1017,15 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, } if (alpn_selected != nullptr) { size_t i; - tsi_peer_property* new_properties = static_cast(gpr_zalloc( - sizeof(*new_properties) * (peer->property_count + 1))); + tsi_peer_property* new_properties = static_cast( + gpr_zalloc(sizeof(*new_properties) * (peer->property_count + 1))); for (i = 0; i < peer->property_count; i++) { new_properties[i] = peer->properties[i]; } result = tsi_construct_string_peer_property( - TSI_SSL_ALPN_SELECTED_PROTOCOL, reinterpret_cast(alpn_selected), - alpn_selected_len, &new_properties[peer->property_count]); + TSI_SSL_ALPN_SELECTED_PROTOCOL, + reinterpret_cast(alpn_selected), alpn_selected_len, + &new_properties[peer->property_count]); if (result != TSI_OK) { gpr_free(new_properties); return result; @@ -1031,7 +1044,8 @@ static tsi_result ssl_handshaker_create_frame_protector( TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND; tsi_ssl_handshaker* impl = reinterpret_cast(self); tsi_ssl_frame_protector* protector_impl = - static_cast(gpr_zalloc(sizeof(*protector_impl))); + static_cast( + gpr_zalloc(sizeof(*protector_impl))); if (max_output_protected_frame_size != nullptr) { if (*max_output_protected_frame_size > @@ -1157,11 +1171,13 @@ static int select_protocol_list(const unsigned char** out, const unsigned char* server_list, size_t server_list_len) { const unsigned char* client_current = client_list; - while (static_cast(client_current - client_list) < client_list_len) { + while (static_cast(client_current - client_list) < + client_list_len) { unsigned char client_current_len = *(client_current++); const unsigned char* server_current = server_list; while ((server_current >= server_list) && - static_cast(server_current - server_list) < server_list_len) { + static_cast(server_current - server_list) < + server_list_len) { unsigned char server_current_len = *(server_current++); if ((client_current_len == server_current_len) && !memcmp(client_current, server_current, server_current_len)) { @@ -1367,7 +1383,8 @@ tsi_result tsi_create_ssl_client_handshaker_factory( return TSI_INVALID_ARGUMENT; } - impl = static_cast(gpr_zalloc(sizeof(*impl))); + impl = static_cast( + gpr_zalloc(sizeof(*impl))); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &client_handshaker_factory_vtable; @@ -1452,7 +1469,8 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( return TSI_INVALID_ARGUMENT; } - impl = static_cast(gpr_zalloc(sizeof(*impl))); + impl = static_cast( + gpr_zalloc(sizeof(*impl))); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &server_handshaker_factory_vtable; diff --git a/src/core/tsi/transport_security.cc b/src/core/tsi/transport_security.cc index 5cfdf6fc32..0c8e3e9dcc 100644 --- a/src/core/tsi/transport_security.cc +++ b/src/core/tsi/transport_security.cc @@ -316,8 +316,8 @@ tsi_result tsi_construct_string_peer_property(const char* name, tsi_result tsi_construct_peer(size_t property_count, tsi_peer* peer) { memset(peer, 0, sizeof(tsi_peer)); if (property_count > 0) { - peer->properties = static_cast(gpr_zalloc( - property_count * sizeof(tsi_peer_property))); + peer->properties = static_cast( + gpr_zalloc(property_count * sizeof(tsi_peer_property))); peer->property_count = property_count; } return TSI_OK; diff --git a/src/core/tsi/transport_security_adapter.cc b/src/core/tsi/transport_security_adapter.cc index e57a42ad6c..5f094b3201 100644 --- a/src/core/tsi/transport_security_adapter.cc +++ b/src/core/tsi/transport_security_adapter.cc @@ -59,7 +59,8 @@ static tsi_result adapter_result_get_unused_bytes( } static void adapter_result_destroy(tsi_handshaker_result* self) { - tsi_adapter_handshaker_result* impl = reinterpret_cast(self); + tsi_adapter_handshaker_result* impl = + reinterpret_cast(self); tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->unused_bytes); gpr_free(self); @@ -87,7 +88,8 @@ static tsi_result tsi_adapter_create_handshaker_result( impl->wrapped = wrapped; impl->unused_bytes_size = unused_bytes_size; if (unused_bytes_size > 0) { - impl->unused_bytes = static_cast(gpr_malloc(unused_bytes_size)); + impl->unused_bytes = + static_cast(gpr_malloc(unused_bytes_size)); memcpy(impl->unused_bytes, unused_bytes, unused_bytes_size); } else { impl->unused_bytes = nullptr; @@ -137,7 +139,8 @@ static tsi_result adapter_create_frame_protector( } static void adapter_destroy(tsi_handshaker* self) { - tsi_adapter_handshaker* impl = reinterpret_cast(self); + tsi_adapter_handshaker* impl = + reinterpret_cast(self); tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->adapter_buffer); gpr_free(self); @@ -156,7 +159,8 @@ static tsi_result adapter_next( } /* If there are received bytes, process them first. */ - tsi_adapter_handshaker* impl = reinterpret_cast(self); + tsi_adapter_handshaker* impl = + reinterpret_cast(self); tsi_result status = TSI_OK; size_t bytes_consumed = received_bytes_size; if (received_bytes_size > 0) { @@ -174,8 +178,8 @@ static tsi_result adapter_next( offset += to_send_size; if (status == TSI_INCOMPLETE_DATA) { impl->adapter_buffer_size *= 2; - impl->adapter_buffer = static_cast(gpr_realloc( - impl->adapter_buffer, impl->adapter_buffer_size)); + impl->adapter_buffer = static_cast( + gpr_realloc(impl->adapter_buffer, impl->adapter_buffer_size)); } } while (status == TSI_INCOMPLETE_DATA); if (status != TSI_OK) return status; @@ -216,12 +220,14 @@ tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped) { impl->base.vtable = &handshaker_vtable; impl->wrapped = wrapped; impl->adapter_buffer_size = TSI_ADAPTER_INITIAL_BUFFER_SIZE; - impl->adapter_buffer = static_cast(gpr_malloc(impl->adapter_buffer_size)); + impl->adapter_buffer = + static_cast(gpr_malloc(impl->adapter_buffer_size)); return &impl->base; } tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter) { if (adapter == nullptr) return nullptr; - tsi_adapter_handshaker* impl = reinterpret_cast(adapter); + tsi_adapter_handshaker* impl = + reinterpret_cast(adapter); return impl->wrapped; } diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index 90b88d41a6..a1d22085bf 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -201,7 +201,8 @@ class TransportStreamOpBatch { } census_context* get_census_context() const { - return static_cast(op_->payload->context[GRPC_CONTEXT_TRACING].value); + return static_cast( + op_->payload->context[GRPC_CONTEXT_TRACING].value); } private: diff --git a/test/core/avl/avl_test.cc b/test/core/avl/avl_test.cc index 563de81a0d..ecebe833b3 100644 --- a/test/core/avl/avl_test.cc +++ b/test/core/avl/avl_test.cc @@ -36,7 +36,9 @@ static int* box(int x) { static long int_compare(void* int1, void* int2, void* unused) { return (*static_cast(int1)) - (*static_cast(int2)); } -static void* int_copy(void* p, void* unused) { return box(*static_cast(p)); } +static void* int_copy(void* p, void* unused) { + return box(*static_cast(p)); +} static void destroy(void* p, void* unused) { gpr_free(p); } @@ -3614,7 +3616,7 @@ static void test_stress(int amount_of_stress) { memset(added, 0, sizeof(added)); for (i = 1; deletions < amount_of_stress; i++) { - int idx = rand() % static_castGPR_ARRAY_SIZE(added); + int idx = rand() % static_cast GPR_ARRAY_SIZE(added); GPR_ASSERT(i); if (rand() < RAND_MAX / 2) { added[idx] = i; @@ -3627,7 +3629,7 @@ static void test_stress(int amount_of_stress) { printf("avl = remove_int(avl, %d); /* d=%d */\n", idx, deletions); avl = remove_int(avl, idx); } - for (j = 0; j < static_castGPR_ARRAY_SIZE(added); j++) { + for (j = 0; j < static_cast GPR_ARRAY_SIZE(added); j++) { if (added[j] != 0) { check_get(avl, j, added[j]); } else { diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index 35a3b1459f..1998a83977 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -143,10 +143,10 @@ TEST(BackOffTest, JitterBackOff) { grpc_millis next = backoff.NextAttemptTime(); EXPECT_EQ(next - grpc_core::ExecCtx::Get()->Now(), initial_backoff); - grpc_millis expected_next_lower_bound = - static_cast(static_cast(current_backoff) * (1 - jitter)); - grpc_millis expected_next_upper_bound = - static_cast(static_cast(current_backoff) * (1 + jitter)); + grpc_millis expected_next_lower_bound = static_cast( + static_cast(current_backoff) * (1 - jitter)); + grpc_millis expected_next_upper_bound = static_cast( + static_cast(current_backoff) * (1 + jitter)); for (int i = 0; i < 10000; i++) { next = backoff.NextAttemptTime(); @@ -155,12 +155,14 @@ TEST(BackOffTest, JitterBackOff) { const grpc_millis timeout_millis = next - grpc_core::ExecCtx::Get()->Now(); EXPECT_GE(timeout_millis, expected_next_lower_bound); EXPECT_LE(timeout_millis, expected_next_upper_bound); - current_backoff = std::min( - static_cast(static_cast(current_backoff) * multiplier), max_backoff); - expected_next_lower_bound = - static_cast(static_cast(current_backoff) * (1 - jitter)); - expected_next_upper_bound = - static_cast(static_cast(current_backoff) * (1 + jitter)); + current_backoff = + std::min(static_cast(static_cast(current_backoff) * + multiplier), + max_backoff); + expected_next_lower_bound = static_cast( + static_cast(current_backoff) * (1 - jitter)); + expected_next_upper_bound = static_cast( + static_cast(current_backoff) * (1 + jitter)); } } diff --git a/test/core/bad_client/tests/duplicate_header.cc b/test/core/bad_client/tests/duplicate_header.cc index 12b9c79ab8..e3cae8b595 100644 --- a/test/core/bad_client/tests/duplicate_header.cc +++ b/test/core/bad_client/tests/duplicate_header.cc @@ -87,7 +87,8 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -108,7 +109,8 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc index 7c012ac055..b552704e9c 100644 --- a/test/core/bad_client/tests/window_overflow.cc +++ b/test/core/bad_client/tests/window_overflow.cc @@ -78,7 +78,8 @@ int main(int argc, char** argv) { for (i = 0; i < NUM_FRAMES; i++) { uint8_t hdr[9] = {static_cast(FRAME_SIZE >> 16), static_cast(FRAME_SIZE >> 8), - static_castFRAME_SIZE, + static_cast + FRAME_SIZE, 0, 0, 0, diff --git a/test/core/bad_ssl/servers/cert.cc b/test/core/bad_ssl/servers/cert.cc index d9ac49823b..0722d6b57c 100644 --- a/test/core/bad_ssl/servers/cert.cc +++ b/test/core/bad_ssl/servers/cert.cc @@ -45,8 +45,10 @@ int main(int argc, char** argv) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file("src/core/tsi/test_creds/badserver.key", 1, &key_slice))); - pem_key_cert_pair.private_key = reinterpret_castGRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = reinterpret_castGRPC_SLICE_START_PTR(cert_slice); + pem_key_cert_pair.private_key = + reinterpret_cast GRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = + reinterpret_cast GRPC_SLICE_START_PTR(cert_slice); ssl_creds = grpc_ssl_server_credentials_create(nullptr, &pem_key_cert_pair, 1, 0, nullptr); diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index 11b280ef29..57ff7370ad 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -81,8 +81,8 @@ static void test_compression_algorithm_states(void) { ch_args = grpc_channel_args_copy_and_add(nullptr, nullptr, 0); /* by default, all enabled */ - states_bitset = - static_cast(grpc_channel_args_compression_algorithm_get_states(ch_args)); + states_bitset = static_cast( + grpc_channel_args_compression_algorithm_get_states(ch_args)); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { GPR_ASSERT(GPR_BITGET(states_bitset, i)); @@ -100,8 +100,9 @@ static void test_compression_algorithm_states(void) { &ch_args_wo_gzip_deflate, GRPC_COMPRESS_STREAM_GZIP, 0); GPR_ASSERT(ch_args_wo_gzip_deflate == ch_args_wo_gzip_deflate_gzip); - states_bitset = static_cast(grpc_channel_args_compression_algorithm_get_states( - ch_args_wo_gzip_deflate)); + states_bitset = + static_cast(grpc_channel_args_compression_algorithm_get_states( + ch_args_wo_gzip_deflate)); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_GZIP || i == GRPC_COMPRESS_DEFLATE || i == GRPC_COMPRESS_STREAM_GZIP) { @@ -118,8 +119,8 @@ static void test_compression_algorithm_states(void) { &ch_args_wo_gzip, GRPC_COMPRESS_STREAM_GZIP, 1); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate_gzip); - states_bitset = static_cast(grpc_channel_args_compression_algorithm_get_states( - ch_args_wo_gzip)); + states_bitset = static_cast( + grpc_channel_args_compression_algorithm_get_states(ch_args_wo_gzip)); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_DEFLATE) { GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0); diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 670ecb4c2f..373ed76cbe 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -39,7 +39,8 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { grpc_resolved_address addr; GPR_ASSERT(1 == grpc_parse_unix(uri, &addr)); - struct sockaddr_un* addr_un = reinterpret_cast(addr.addr); + struct sockaddr_un* addr_un = + reinterpret_cast(addr.addr); GPR_ASSERT(AF_UNIX == addr_un->sun_family); GPR_ASSERT(0 == strcmp(addr_un->sun_path, pathname)); @@ -60,7 +61,8 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, char ntop_buf[INET_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv4(uri, &addr)); - struct sockaddr_in* addr_in = reinterpret_cast(addr.addr); + struct sockaddr_in* addr_in = + reinterpret_cast(addr.addr); GPR_ASSERT(AF_INET == addr_in->sin_family); GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET, &addr_in->sin_addr, ntop_buf, sizeof(ntop_buf))); @@ -78,7 +80,8 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, char ntop_buf[INET6_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv6(uri, &addr)); - struct sockaddr_in6* addr_in6 = reinterpret_cast(addr.addr); + struct sockaddr_in6* addr_in6 = + reinterpret_cast(addr.addr); GPR_ASSERT(AF_INET6 == addr_in6->sin6_family); GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET6, &addr_in6->sin6_addr, ntop_buf, sizeof(ntop_buf))); diff --git a/test/core/compression/stream_compression_test.cc b/test/core/compression/stream_compression_test.cc index 1236529b4a..0b84366198 100644 --- a/test/core/compression/stream_compression_test.cc +++ b/test/core/compression/stream_compression_test.cc @@ -43,8 +43,10 @@ static bool slice_buffer_equals_string(grpc_slice_buffer* buf, size_t pointer = 0; for (i = 0; i < buf->count; i++) { size_t slice_len = GRPC_SLICE_LENGTH(buf->slices[i]); - if (0 != strncmp(str + pointer, reinterpret_castGRPC_SLICE_START_PTR(buf->slices[i]), - slice_len)) { + if (0 != + strncmp(str + pointer, + reinterpret_cast GRPC_SLICE_START_PTR(buf->slices[i]), + slice_len)) { return false; } pointer += slice_len; @@ -112,7 +114,7 @@ test_stream_compression_simple_compress_decompress_with_output_size_constraint() GPR_ASSERT(output_size == max_output_size); GPR_ASSERT(end_of_context == false); grpc_slice slice_recv = grpc_slice_buffer_take_first(&sink); - char* str_recv = reinterpret_castGRPC_SLICE_START_PTR(slice_recv); + char* str_recv = reinterpret_cast GRPC_SLICE_START_PTR(slice_recv); GPR_ASSERT(GRPC_SLICE_LENGTH(slice_recv) == max_output_size); GPR_ASSERT(0 == strncmp(test_str, str_recv, max_output_size)); grpc_slice_unref(slice_recv); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 124d05af47..79331bca6f 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -196,8 +196,8 @@ static void start_rpc(int target_port, grpc_status_code expected_status, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(state.call, ops, static_cast(op - ops), tag(1), - nullptr); + error = grpc_call_start_batch(state.call, ops, static_cast(op - ops), + tag(1), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); diff --git a/test/core/end2end/dualstack_socket_test.cc b/test/core/end2end/dualstack_socket_test.cc index a7f10e49bf..411d0f2308 100644 --- a/test/core/end2end/dualstack_socket_test.cc +++ b/test/core/end2end/dualstack_socket_test.cc @@ -128,8 +128,8 @@ void test_connect(const char* server_host, const char* client_host, int port, grpc_slice_buffer uri_parts; char** hosts_with_port; - uri_slice = - grpc_slice_new(const_cast(client_host), strlen(client_host), do_nothing); + uri_slice = grpc_slice_new(const_cast(client_host), + strlen(client_host), do_nothing); grpc_slice_buffer_init(&uri_parts); grpc_slice_split(uri_slice, ",", &uri_parts); hosts_with_port = @@ -199,7 +199,8 @@ void test_connect(const char* server_host, const char* client_host, int port, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); if (expect_ok) { @@ -227,8 +228,8 @@ void test_connect(const char* server_host, const char* client_host, int port, op->data.recv_close_on_server.cancelled = &was_cancelled; op->flags = 0; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 4776cfbc1b..63a15753a4 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -458,7 +458,8 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, gpr_free(acceptor); grpc_end2end_http_proxy* proxy = static_cast(arg); // Instantiate proxy_connection. - proxy_connection* conn = static_cast(gpr_zalloc(sizeof(*conn))); + proxy_connection* conn = + static_cast(gpr_zalloc(sizeof(*conn))); gpr_ref(&proxy->users); conn->client_endpoint = endpoint; conn->proxy = proxy; @@ -533,7 +534,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); memset(&resolved_addr, 0, sizeof(resolved_addr)); addr->sin_family = AF_INET; grpc_sockaddr_set_port(&resolved_addr, proxy_port); diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index d0a4bbb96e..918988d9dc 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -80,7 +80,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, int proxy_port = grpc_pick_unused_port_or_die(); int server_port = grpc_pick_unused_port_or_die(); - grpc_end2end_proxy* proxy = static_cast(gpr_malloc(sizeof(*proxy))); + grpc_end2end_proxy* proxy = + static_cast(gpr_malloc(sizeof(*proxy))); memset(proxy, 0, sizeof(*proxy)); gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port); diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index fa50c24ca5..dc1183b9a0 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -192,7 +192,9 @@ static grpc_byte_buffer* read_message(input_stream* inp) { return out; } -static int read_int(input_stream* inp) { return static_cast(read_uint32(inp)); } +static int read_int(input_stream* inp) { + return static_cast(read_uint32(inp)); +} static grpc_channel_args* read_args(input_stream* inp) { size_t n = next_byte(inp); @@ -532,7 +534,9 @@ static void assert_success_and_decrement(void* counter, bool success) { --*static_cast(counter); } -static void decrement(void* counter, bool success) { --*static_cast(counter); } +static void decrement(void* counter, bool success) { + --*static_cast(counter); +} typedef struct connectivity_watch { int* counter; diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 20468ad0e5..09f0301c44 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -77,7 +77,8 @@ static void my_resolve_address(const char* addr, const char* default_port, (*addrs)->addrs = static_cast( gpr_malloc(sizeof(*(*addrs)->addrs))); memset((*addrs)->addrs, 0, sizeof(*(*addrs)->addrs)); - struct sockaddr_in* sa = reinterpret_cast((*addrs)->addrs[0].addr); + struct sockaddr_in* sa = + reinterpret_cast((*addrs)->addrs[0].addr); sa->sin_family = AF_INET; sa->sin_addr.s_addr = htonl(0x7f000001); sa->sin_port = htons(static_cast(g_resolve_port)); diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index b4b3462c68..9e2082ce9d 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -333,7 +333,8 @@ static void simple_request_body(grpc_end2end_test_fixture f, op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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), expected_result == SUCCESS); diff --git a/test/core/end2end/tests/authority_not_supported.cc b/test/core/end2end/tests/authority_not_supported.cc index 498fb5cf35..01a95e4e10 100644 --- a/test/core/end2end/tests/authority_not_supported.cc +++ b/test/core/end2end/tests/authority_not_supported.cc @@ -154,7 +154,8 @@ static void test_with_authority_header(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/bad_hostname.cc b/test/core/end2end/tests/bad_hostname.cc index 60097dfa4c..b6f06a20d6 100644 --- a/test/core/end2end/tests/bad_hostname.cc +++ b/test/core/end2end/tests/bad_hostname.cc @@ -133,7 +133,8 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/bad_ping.cc b/test/core/end2end/tests/bad_ping.cc index 0972e86e9a..ddab3faa27 100644 --- a/test/core/end2end/tests/bad_ping.cc +++ b/test/core/end2end/tests/bad_ping.cc @@ -144,7 +144,8 @@ static void test_bad_ping(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -188,7 +189,8 @@ static void test_bad_ping(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/binary_metadata.cc b/test/core/end2end/tests/binary_metadata.cc index 1313ca4bea..e66b4da6cc 100644 --- a/test/core/end2end/tests/binary_metadata.cc +++ b/test/core/end2end/tests/binary_metadata.cc @@ -182,7 +182,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -205,7 +206,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -246,7 +248,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/call_creds.cc b/test/core/end2end/tests/call_creds.cc index cb65b18064..e9cbaa3088 100644 --- a/test/core/end2end/tests/call_creds.cc +++ b/test/core/end2end/tests/call_creds.cc @@ -219,7 +219,8 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -253,7 +254,8 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -279,7 +281,8 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -443,7 +446,8 @@ static void test_request_with_server_rejecting_client_creds( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(error == GRPC_CALL_OK); CQ_EXPECT_COMPLETION(cqv, tag(1), 1); diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index 86c91c1580..ee1a0bbccc 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -186,7 +186,8 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = grpc_server_request_call(f.server, &s, &call_details, @@ -217,7 +218,8 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(3), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(3), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr)); diff --git a/test/core/end2end/tests/cancel_after_client_done.cc b/test/core/end2end/tests/cancel_after_client_done.cc index 9e92c27f03..31c3ea6f74 100644 --- a/test/core/end2end/tests/cancel_after_client_done.cc +++ b/test/core/end2end/tests/cancel_after_client_done.cc @@ -164,7 +164,8 @@ static void test_cancel_after_accept_and_writes_closed( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = grpc_server_request_call(f.server, &s, &call_details, @@ -195,7 +196,8 @@ static void test_cancel_after_accept_and_writes_closed( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(3), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(3), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr)); diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index 88aa63c7af..bf3be1c8b7 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -181,7 +181,8 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -234,7 +236,8 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, nullptr)); @@ -251,7 +254,8 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(2), 1); diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index 0879d72368..85cfe16508 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -187,7 +187,8 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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(101), true); @@ -205,7 +206,8 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), false); @@ -216,7 +218,8 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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); @@ -338,7 +341,8 @@ static void request_with_payload_template( op->flags = client_send_flags_bitmask; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); } @@ -367,7 +371,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -403,7 +408,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (int i = 0; i < 2; i++) { @@ -418,8 +424,8 @@ static void request_with_payload_template( op->flags = client_send_flags_bitmask; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(c, ops, static_cast(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), 1); } @@ -431,8 +437,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -450,8 +456,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -461,7 +467,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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(103), 1); @@ -495,7 +502,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -508,7 +516,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(1), 1); diff --git a/test/core/end2end/tests/default_host.cc b/test/core/end2end/tests/default_host.cc index fefb5a58d1..3191f76688 100644 --- a/test/core/end2end/tests/default_host.cc +++ b/test/core/end2end/tests/default_host.cc @@ -140,7 +140,8 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(error == GRPC_CALL_OK); error = @@ -179,7 +180,8 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(102), + nullptr); GPR_ASSERT(error == GRPC_CALL_OK); CQ_EXPECT_COMPLETION(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/disappearing_server.cc b/test/core/end2end/tests/disappearing_server.cc index 9712b9f86e..d5b6f8fbf0 100644 --- a/test/core/end2end/tests/disappearing_server.cc +++ b/test/core/end2end/tests/disappearing_server.cc @@ -120,7 +120,8 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -154,7 +155,8 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/filter_call_init_fails.cc b/test/core/end2end/tests/filter_call_init_fails.cc index c63a5b938d..6f72a1843a 100644 --- a/test/core/end2end/tests/filter_call_init_fails.cc +++ b/test/core/end2end/tests/filter_call_init_fails.cc @@ -158,7 +158,8 @@ static void test_server_channel_filter(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -253,7 +254,8 @@ static void test_client_channel_filter(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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), 1); @@ -344,7 +346,8 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) { op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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), 1); @@ -368,7 +371,8 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) { nullptr); GPR_ASSERT(c); - error = grpc_call_start_batch(c, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/filter_causes_close.cc b/test/core/end2end/tests/filter_causes_close.cc index 07543f8e74..bc4cb8633d 100644 --- a/test/core/end2end/tests/filter_causes_close.cc +++ b/test/core/end2end/tests/filter_causes_close.cc @@ -152,7 +152,8 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = diff --git a/test/core/end2end/tests/filter_latency.cc b/test/core/end2end/tests/filter_latency.cc index 42507ad41a..51f54c9742 100644 --- a/test/core/end2end/tests/filter_latency.cc +++ b/test/core/end2end/tests/filter_latency.cc @@ -165,7 +165,8 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -196,7 +197,8 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/filter_status_code.cc b/test/core/end2end/tests/filter_status_code.cc index 389c63b2ac..32cd95410e 100644 --- a/test/core/end2end/tests/filter_status_code.cc +++ b/test/core/end2end/tests/filter_status_code.cc @@ -164,7 +164,8 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -199,7 +200,8 @@ static void test_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/graceful_server_shutdown.cc b/test/core/end2end/tests/graceful_server_shutdown.cc index 9a14476df4..3ef414f83c 100644 --- a/test/core/end2end/tests/graceful_server_shutdown.cc +++ b/test/core/end2end/tests/graceful_server_shutdown.cc @@ -135,7 +135,8 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -169,7 +170,8 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/high_initial_seqno.cc b/test/core/end2end/tests/high_initial_seqno.cc index cb67787e98..8767437802 100644 --- a/test/core/end2end/tests/high_initial_seqno.cc +++ b/test/core/end2end/tests/high_initial_seqno.cc @@ -139,7 +139,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -169,7 +170,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/hpack_size.cc b/test/core/end2end/tests/hpack_size.cc index 8f7f3e6a6c..b49736841e 100644 --- a/test/core/end2end/tests/hpack_size.cc +++ b/test/core/end2end/tests/hpack_size.cc @@ -293,7 +293,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -323,7 +324,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/idempotent_request.cc b/test/core/end2end/tests/idempotent_request.cc index c0eac683c7..56be2d6afe 100644 --- a/test/core/end2end/tests/idempotent_request.cc +++ b/test/core/end2end/tests/idempotent_request.cc @@ -144,7 +144,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -183,7 +184,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/invoke_large_request.cc b/test/core/end2end/tests/invoke_large_request.cc index 5705094a15..1aab34c2ce 100644 --- a/test/core/end2end/tests/invoke_large_request.cc +++ b/test/core/end2end/tests/invoke_large_request.cc @@ -176,7 +176,8 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -198,7 +199,8 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -224,7 +226,8 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/keepalive_timeout.cc b/test/core/end2end/tests/keepalive_timeout.cc index 76beedb1ba..f0dd061e33 100644 --- a/test/core/end2end/tests/keepalive_timeout.cc +++ b/test/core/end2end/tests/keepalive_timeout.cc @@ -155,7 +155,8 @@ static void test_keepalive_timeout(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, static_cast(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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -172,7 +173,8 @@ static void test_keepalive_timeout(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, static_cast(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), 1); @@ -186,7 +188,8 @@ static void test_keepalive_timeout(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, static_cast(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), 1); diff --git a/test/core/end2end/tests/large_metadata.cc b/test/core/end2end/tests/large_metadata.cc index 5e04161e08..da0615bf6e 100644 --- a/test/core/end2end/tests/large_metadata.cc +++ b/test/core/end2end/tests/large_metadata.cc @@ -160,7 +160,8 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -184,7 +185,8 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -207,7 +209,8 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index de6b60c216..9e79d02be4 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -185,7 +185,8 @@ static void request_response_with_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -207,7 +208,8 @@ static void request_response_with_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -235,7 +237,8 @@ static void request_response_with_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/max_concurrent_streams.cc b/test/core/end2end/tests/max_concurrent_streams.cc index ed658a3507..789b3d4b77 100644 --- a/test/core/end2end/tests/max_concurrent_streams.cc +++ b/test/core/end2end/tests/max_concurrent_streams.cc @@ -135,7 +135,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -165,7 +166,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -274,7 +276,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(301), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), + tag(301), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -292,7 +295,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(302), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), + tag(302), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -306,7 +310,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(401), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), + tag(401), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -324,7 +329,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(402), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), + tag(402), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); got_client_start = 0; @@ -371,7 +377,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s1, ops, static_cast(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s1, ops, static_cast(op - ops), + tag(102), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(102), 1); @@ -408,7 +415,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s2, ops, static_cast(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s2, ops, static_cast(op - ops), + tag(202), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(live_call + 2), 1); @@ -514,7 +522,8 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(301), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), + tag(301), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -532,7 +541,8 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(302), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), + tag(302), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(101), 1); @@ -550,7 +560,8 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(401), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), + tag(401), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -568,7 +579,8 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(402), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), + tag(402), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); grpc_call_details_destroy(&call_details); @@ -603,7 +615,8 @@ static void test_max_concurrent_streams_with_timeout_on_first( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s2, ops, static_cast(op - ops), tag(202), nullptr); + error = grpc_call_start_batch(s2, ops, static_cast(op - ops), + tag(202), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(402), 1); @@ -709,7 +722,8 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(301), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), + tag(301), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -727,7 +741,8 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c1, ops, static_cast(op - ops), tag(302), nullptr); + error = grpc_call_start_batch(c1, ops, static_cast(op - ops), + tag(302), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(101), 1); @@ -745,7 +760,8 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(401), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), + tag(401), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); memset(ops, 0, sizeof(ops)); @@ -763,7 +779,8 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c2, ops, static_cast(op - ops), tag(402), nullptr); + error = grpc_call_start_batch(c2, ops, static_cast(op - ops), + tag(402), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); /* the second request is time out*/ @@ -796,7 +813,8 @@ static void test_max_concurrent_streams_with_timeout_on_second( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s1, ops, static_cast(op - ops), tag(102), nullptr); + error = grpc_call_start_batch(s1, ops, static_cast(op - ops), + tag(102), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); CQ_EXPECT_COMPLETION(cqv, tag(302), 1); diff --git a/test/core/end2end/tests/max_connection_age.cc b/test/core/end2end/tests/max_connection_age.cc index 4b498e6bf8..e494dad19c 100644 --- a/test/core/end2end/tests/max_connection_age.cc +++ b/test/core/end2end/tests/max_connection_age.cc @@ -145,7 +145,8 @@ static void test_max_age_forcibly_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -156,7 +157,8 @@ static void test_max_age_forcibly_close(grpc_end2end_test_config config) { cq_verify(cqv); gpr_timespec expect_shutdown_time = grpc_timeout_milliseconds_to_deadline( - static_cast(MAX_CONNECTION_AGE_MS * MAX_CONNECTION_AGE_JITTER_MULTIPLIER) + + static_cast(MAX_CONNECTION_AGE_MS * + MAX_CONNECTION_AGE_JITTER_MULTIPLIER) + MAX_CONNECTION_AGE_GRACE_MS + IMMEDIATE_SHUTDOWN_GRACE_TIME_MS); /* Wait for the channel to reach its max age */ @@ -190,7 +192,8 @@ static void test_max_age_forcibly_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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); @@ -288,7 +291,8 @@ static void test_max_age_gracefully_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -325,7 +329,8 @@ static void test_max_age_gracefully_close(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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/max_connection_idle.cc b/test/core/end2end/tests/max_connection_idle.cc index beff733593..2f212b965f 100644 --- a/test/core/end2end/tests/max_connection_idle.cc +++ b/test/core/end2end/tests/max_connection_idle.cc @@ -100,7 +100,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -139,7 +140,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index 987c348c00..3dd1737793 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -219,7 +219,8 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); if (send_limit) { @@ -247,7 +248,8 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -408,7 +410,8 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -443,7 +446,8 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/network_status_change.cc b/test/core/end2end/tests/network_status_change.cc index fe941e8ac8..83cb172f26 100644 --- a/test/core/end2end/tests/network_status_change.cc +++ b/test/core/end2end/tests/network_status_change.cc @@ -150,7 +150,8 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -170,7 +171,8 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -193,7 +195,8 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/no_logging.cc b/test/core/end2end/tests/no_logging.cc index c4678f461f..b357e3b0ad 100644 --- a/test/core/end2end/tests/no_logging.cc +++ b/test/core/end2end/tests/no_logging.cc @@ -170,7 +170,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -207,7 +208,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/payload.cc b/test/core/end2end/tests/payload.cc index 0e19e29cb6..340c76e173 100644 --- a/test/core/end2end/tests/payload.cc +++ b/test/core/end2end/tests/payload.cc @@ -174,7 +174,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -196,7 +197,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -222,7 +224,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/ping_pong_streaming.cc b/test/core/end2end/tests/ping_pong_streaming.cc index 9ac4d544f2..9ca880481f 100644 --- a/test/core/end2end/tests/ping_pong_streaming.cc +++ b/test/core/end2end/tests/ping_pong_streaming.cc @@ -143,7 +143,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -165,7 +166,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (i = 0; i < messages; i++) { @@ -184,7 +186,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -194,8 +197,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); cq_verify(cqv); @@ -207,8 +210,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); CQ_EXPECT_COMPLETION(cqv, tag(2), 1); @@ -229,7 +232,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -242,7 +246,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(1), 1); diff --git a/test/core/end2end/tests/proxy_auth.cc b/test/core/end2end/tests/proxy_auth.cc index fd1cbadaf5..5a2e0ef414 100644 --- a/test/core/end2end/tests/proxy_auth.cc +++ b/test/core/end2end/tests/proxy_auth.cc @@ -148,7 +148,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -187,7 +188,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/registered_call.cc b/test/core/end2end/tests/registered_call.cc index 49a9f88df8..d4ca146707 100644 --- a/test/core/end2end/tests/registered_call.cc +++ b/test/core/end2end/tests/registered_call.cc @@ -135,7 +135,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -165,7 +166,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/request_with_flags.cc b/test/core/end2end/tests/request_with_flags.cc index bfce0a0be1..4a54318d0f 100644 --- a/test/core/end2end/tests/request_with_flags.cc +++ b/test/core/end2end/tests/request_with_flags.cc @@ -151,7 +151,8 @@ static void test_invoke_request_with_flags( op->reserved = nullptr; op++; expectation = call_start_batch_expected_result; - error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(1), + nullptr); GPR_ASSERT(expectation == error); if (expectation == GRPC_CALL_OK) { diff --git a/test/core/end2end/tests/request_with_payload.cc b/test/core/end2end/tests/request_with_payload.cc index fc87f5823e..44398df52d 100644 --- a/test/core/end2end/tests/request_with_payload.cc +++ b/test/core/end2end/tests/request_with_payload.cc @@ -147,7 +147,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -168,7 +169,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -189,7 +191,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/resource_quota_server.cc b/test/core/end2end/tests/resource_quota_server.cc index c9d8ab7f9f..33d6b4ef31 100644 --- a/test/core/end2end/tests/resource_quota_server.cc +++ b/test/core/end2end/tests/resource_quota_server.cc @@ -136,20 +136,24 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_call** server_calls = static_cast(malloc(sizeof(grpc_call*) * NUM_CALLS)); grpc_metadata_array* initial_metadata_recv = - static_cast(malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); + static_cast( + malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); grpc_metadata_array* trailing_metadata_recv = - static_cast(malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); + static_cast( + malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); grpc_metadata_array* request_metadata_recv = - static_cast(malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); - grpc_call_details* call_details = - static_cast(malloc(sizeof(grpc_call_details) * NUM_CALLS)); - grpc_status_code* status = - static_cast(malloc(sizeof(grpc_status_code) * NUM_CALLS)); - grpc_slice* details = static_cast(malloc(sizeof(grpc_slice) * NUM_CALLS)); - grpc_byte_buffer** request_payload = - static_cast(malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS)); - grpc_byte_buffer** request_payload_recv = - static_cast(malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS)); + static_cast( + malloc(sizeof(grpc_metadata_array) * NUM_CALLS)); + grpc_call_details* call_details = static_cast( + malloc(sizeof(grpc_call_details) * NUM_CALLS)); + grpc_status_code* status = static_cast( + malloc(sizeof(grpc_status_code) * NUM_CALLS)); + grpc_slice* details = + static_cast(malloc(sizeof(grpc_slice) * NUM_CALLS)); + grpc_byte_buffer** request_payload = static_cast( + malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS)); + grpc_byte_buffer** request_payload_recv = static_cast( + malloc(sizeof(grpc_byte_buffer*) * NUM_CALLS)); int* was_cancelled = static_cast(malloc(sizeof(int) * NUM_CALLS)); grpc_call_error error; int pending_client_calls = 0; @@ -220,7 +224,8 @@ void resource_quota_server(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(client_calls[i], ops, static_cast(op - ops), + error = grpc_call_start_batch(client_calls[i], ops, + static_cast(op - ops), tag(CLIENT_BASE_TAG + i), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); @@ -285,9 +290,9 @@ void resource_quota_server(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(server_calls[call_id], ops, static_cast(op - ops), - tag(SERVER_RECV_BASE_TAG + call_id), nullptr); + error = grpc_call_start_batch( + server_calls[call_id], ops, static_cast(op - ops), + tag(SERVER_RECV_BASE_TAG + call_id), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(pending_server_start_calls > 0); @@ -326,9 +331,9 @@ void resource_quota_server(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(server_calls[call_id], ops, static_cast(op - ops), - tag(SERVER_END_BASE_TAG + call_id), nullptr); + error = grpc_call_start_batch( + server_calls[call_id], ops, static_cast(op - ops), + tag(SERVER_END_BASE_TAG + call_id), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(pending_server_recv_calls > 0); diff --git a/test/core/end2end/tests/server_finishes_request.cc b/test/core/end2end/tests/server_finishes_request.cc index 4423ed3cf2..6fc06cfaa1 100644 --- a/test/core/end2end/tests/server_finishes_request.cc +++ b/test/core/end2end/tests/server_finishes_request.cc @@ -133,7 +133,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -163,7 +164,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/shutdown_finishes_calls.cc b/test/core/end2end/tests/shutdown_finishes_calls.cc index bdba7a6532..34c4ebbf0a 100644 --- a/test/core/end2end/tests/shutdown_finishes_calls.cc +++ b/test/core/end2end/tests/shutdown_finishes_calls.cc @@ -128,7 +128,8 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -145,7 +146,8 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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); /* shutdown and destroy the server */ diff --git a/test/core/end2end/tests/simple_cacheable_request.cc b/test/core/end2end/tests/simple_cacheable_request.cc index d7be88713f..4ae8398a6e 100644 --- a/test/core/end2end/tests/simple_cacheable_request.cc +++ b/test/core/end2end/tests/simple_cacheable_request.cc @@ -178,7 +178,8 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -201,7 +202,8 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -227,7 +229,8 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/simple_delayed_request.cc b/test/core/end2end/tests/simple_delayed_request.cc index 12207f0771..f8a1ddfdc3 100644 --- a/test/core/end2end/tests/simple_delayed_request.cc +++ b/test/core/end2end/tests/simple_delayed_request.cc @@ -129,7 +129,8 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -159,7 +160,8 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/simple_metadata.cc b/test/core/end2end/tests/simple_metadata.cc index 246c8b0d6f..1f39f8983b 100644 --- a/test/core/end2end/tests/simple_metadata.cc +++ b/test/core/end2end/tests/simple_metadata.cc @@ -176,7 +176,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -199,7 +200,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -225,7 +227,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/simple_request.cc b/test/core/end2end/tests/simple_request.cc index 8bc7fa6e2c..926e2c7452 100644 --- a/test/core/end2end/tests/simple_request.cc +++ b/test/core/end2end/tests/simple_request.cc @@ -152,7 +152,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -191,7 +192,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index 4dea64e9aa..e90d54f054 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -187,7 +187,8 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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(101), true); @@ -205,7 +206,8 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), false); @@ -216,7 +218,8 @@ static void request_for_disabled_algorithm( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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); @@ -345,7 +348,8 @@ static void request_with_payload_template( op->flags = client_send_flags_bitmask; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); } @@ -374,7 +378,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -414,7 +419,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (int i = 0; i < 2; i++) { @@ -429,8 +435,8 @@ static void request_with_payload_template( op->flags = client_send_flags_bitmask; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(c, ops, static_cast(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), 1); } @@ -442,8 +448,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -459,8 +465,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -470,7 +476,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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(103), 1); @@ -495,7 +502,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -508,7 +516,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(1), 1); diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index f11230f6b2..9eace97afd 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -177,7 +177,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -199,7 +200,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -225,7 +227,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); 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 6f57667d5c..5b033292b0 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -151,7 +151,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -173,7 +174,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (i = 0; i < messages; i++) { @@ -192,7 +194,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -202,8 +205,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); cq_verify(cqv); @@ -215,8 +218,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); CQ_EXPECT_COMPLETION(cqv, tag(2), 1); @@ -237,7 +240,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -250,7 +254,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(1), 1); diff --git a/test/core/end2end/tests/streaming_error_response.cc b/test/core/end2end/tests/streaming_error_response.cc index e67920551a..7c7d778d1e 100644 --- a/test/core/end2end/tests/streaming_error_response.cc +++ b/test/core/end2end/tests/streaming_error_response.cc @@ -148,7 +148,8 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->data.recv_status_on_client.status_details = &details; op++; } - error = grpc_call_start_batch(c, ops, static_cast(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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -165,7 +166,8 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = response_payload1; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -179,7 +181,8 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = response_payload2; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -190,7 +193,8 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &response_payload2_recv; op++; - error = grpc_call_start_batch(c, ops, static_cast(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), 1); @@ -208,7 +212,8 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { grpc_slice status_details = grpc_slice_from_static_string("xyz"); op->data.send_status_from_server.status_details = &status_details; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -225,7 +230,8 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { 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, static_cast(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), 1); diff --git a/test/core/end2end/tests/trailing_metadata.cc b/test/core/end2end/tests/trailing_metadata.cc index 134baaaf93..24069854ac 100644 --- a/test/core/end2end/tests/trailing_metadata.cc +++ b/test/core/end2end/tests/trailing_metadata.cc @@ -184,7 +184,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -207,7 +208,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); @@ -234,7 +236,8 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index 3de326bef2..4d4c369a42 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -191,7 +191,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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 = @@ -227,7 +228,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); for (int i = 0; i < 2; i++) { @@ -246,7 +248,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -256,8 +259,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); cq_verify(cqv); @@ -274,8 +277,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); CQ_EXPECT_COMPLETION(cqv, tag(2), 1); @@ -308,7 +311,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -321,7 +325,8 @@ static void request_with_payload_template( op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(1), 1); diff --git a/test/core/end2end/tests/write_buffering.cc b/test/core/end2end/tests/write_buffering.cc index 35ab72cc53..5d76d238b9 100644 --- a/test/core/end2end/tests/write_buffering.cc +++ b/test/core/end2end/tests/write_buffering.cc @@ -128,7 +128,8 @@ static void test_invoke_request_with_payload(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(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -138,7 +139,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -154,7 +156,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.send_message.send_message = request_payload1; op->flags = GRPC_WRITE_BUFFER_HINT; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -162,7 +165,8 @@ static void test_invoke_request_with_payload(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, static_cast(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); /* recv message should not succeed yet - it's buffered at the client still */ @@ -171,7 +175,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv1; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(2), true); @@ -186,7 +191,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.send_message.send_message = request_payload2; op->flags = 0; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); /* now the first send should match up with the first recv */ @@ -200,7 +206,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv2; op++; - error = grpc_call_start_batch(s, ops, static_cast(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); @@ -219,7 +226,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(4), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(4), + nullptr); memset(ops, 0, sizeof(ops)); op = ops; @@ -236,7 +244,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/end2end/tests/write_buffering_at_end.cc b/test/core/end2end/tests/write_buffering_at_end.cc index fffb0293a1..bd046ef9cc 100644 --- a/test/core/end2end/tests/write_buffering_at_end.cc +++ b/test/core/end2end/tests/write_buffering_at_end.cc @@ -125,7 +125,8 @@ static void test_invoke_request_with_payload(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(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -135,7 +136,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -151,7 +153,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.send_message.send_message = request_payload; op->flags = GRPC_WRITE_BUFFER_HINT; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); memset(ops, 0, sizeof(ops)); @@ -159,7 +162,8 @@ static void test_invoke_request_with_payload(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, static_cast(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); /* recv message should not succeed yet - it's buffered at the client still */ @@ -168,7 +172,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv1; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(2), true); @@ -181,7 +186,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op = ops; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); /* now the first send should match up with the first recv */ @@ -195,7 +201,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &request_payload_recv2; op++; - error = grpc_call_start_batch(s, ops, static_cast(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); @@ -210,7 +217,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(4), nullptr); + error = grpc_call_start_batch(c, ops, static_cast(op - ops), tag(4), + nullptr); memset(ops, 0, sizeof(ops)); op = ops; @@ -227,7 +235,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); diff --git a/test/core/fling/client.cc b/test/core/fling/client.cc index 0141e7e748..05dc3052d1 100644 --- a/test/core/fling/client.cc +++ b/test/core/fling/client.cc @@ -195,7 +195,8 @@ int main(int argc, char** argv) { channel = grpc_insecure_channel_create(target, nullptr, nullptr); cq = grpc_completion_queue_create_for_next(nullptr); - the_buffer = grpc_raw_byte_buffer_create(&slice, static_cast(payload_size)); + the_buffer = + grpc_raw_byte_buffer_create(&slice, static_cast(payload_size)); histogram = grpc_histogram_create(0.01, 60e9); sc.init(); diff --git a/test/core/fling/server.cc b/test/core/fling/server.cc index cad4a8fd8c..cf7e2465d9 100644 --- a/test/core/fling/server.cc +++ b/test/core/fling/server.cc @@ -112,7 +112,8 @@ static void handle_unary_method(void) { op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(call, unary_ops, static_cast(op - unary_ops), + error = grpc_call_start_batch(call, unary_ops, + static_cast(op - unary_ops), tag(FLING_SERVER_BATCH_OPS_FOR_UNARY), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); } diff --git a/test/core/gpr/alloc_test.cc b/test/core/gpr/alloc_test.cc index 1f6d5962ba..36cdc02ff2 100644 --- a/test/core/gpr/alloc_test.cc +++ b/test/core/gpr/alloc_test.cc @@ -27,7 +27,9 @@ static void* fake_malloc(size_t size) { return (void*)size; } static void* fake_realloc(void* addr, size_t size) { return (void*)size; } -static void fake_free(void* addr) { *(static_cast(addr)) = static_cast(0xdeadd00d); } +static void fake_free(void* addr) { + *(static_cast(addr)) = static_cast(0xdeadd00d); +} static void test_custom_allocs() { const gpr_allocation_functions default_fns = gpr_get_allocation_functions(); diff --git a/test/core/gpr/spinlock_test.cc b/test/core/gpr/spinlock_test.cc index d443684c92..cd6de69126 100644 --- a/test/core/gpr/spinlock_test.cc +++ b/test/core/gpr/spinlock_test.cc @@ -93,7 +93,8 @@ static void test(const char* name, void (*body)(void* m), int timeout_s, gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; gpr_timespec deadline = gpr_time_add( - start, gpr_time_from_micros(static_cast(timeout_s) * 1000000, GPR_TIMESPAN)); + start, gpr_time_from_micros(static_cast(timeout_s) * 1000000, + GPR_TIMESPAN)); fprintf(stderr, "%s:", name); fflush(stderr); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { @@ -105,14 +106,16 @@ static void test(const char* name, void (*body)(void* m), int timeout_s, test_wait(m); if (m->counter != m->thread_count * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", - static_cast(m->counter), m->thread_count, static_cast(m->iterations)); + static_cast(m->counter), m->thread_count, + static_cast(m->iterations)); fflush(stderr); GPR_ASSERT(0); } test_destroy(m); } time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start); - fprintf(stderr, " done %lld.%09d s\n", static_cast(time_taken.tv_sec), + fprintf(stderr, " done %lld.%09d s\n", + static_cast(time_taken.tv_sec), static_cast(time_taken.tv_nsec)); fflush(stderr); } diff --git a/test/core/gpr/sync_test.cc b/test/core/gpr/sync_test.cc index abad930ce6..39ff8852b6 100644 --- a/test/core/gpr/sync_test.cc +++ b/test/core/gpr/sync_test.cc @@ -236,7 +236,8 @@ static void test(const char* name, void (*body)(void* m), gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; gpr_timespec deadline = gpr_time_add( - start, gpr_time_from_micros(static_cast(timeout_s) * 1000000, GPR_TIMESPAN)); + start, gpr_time_from_micros(static_cast(timeout_s) * 1000000, + GPR_TIMESPAN)); fprintf(stderr, "%s:", name); fflush(stderr); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { @@ -252,7 +253,8 @@ static void test(const char* name, void (*body)(void* m), test_wait(m); if (m->counter != m->threads * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", - static_cast(m->counter), m->threads, static_cast(m->iterations)); + static_cast(m->counter), m->threads, + static_cast(m->iterations)); fflush(stderr); GPR_ASSERT(0); } @@ -260,7 +262,8 @@ static void test(const char* name, void (*body)(void* m), iterations <<= 1; } time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start); - fprintf(stderr, " done %lld.%09d s\n", static_cast(time_taken.tv_sec), + fprintf(stderr, " done %lld.%09d s\n", + static_cast(time_taken.tv_sec), static_cast(time_taken.tv_nsec)); fflush(stderr); } diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index d04295a735..088df3845e 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -82,7 +82,8 @@ static int create_socket(int* out_port) { } addr_len = sizeof(addr); - if (getsockname(s, reinterpret_cast(&addr), &addr_len) != 0 || + if (getsockname(s, reinterpret_cast(&addr), &addr_len) != + 0 || addr_len > sizeof(addr)) { perror("getsockname"); gpr_log(GPR_ERROR, "%s", "Unable to get socket local address"); @@ -175,7 +176,8 @@ static void server_thread(void* arg) { gpr_log(GPR_INFO, "Server listening"); struct sockaddr_in addr; socklen_t len = sizeof(addr); - const int client = accept(sock, reinterpret_cast(&addr), &len); + const int client = + accept(sock, reinterpret_cast(&addr), &len); if (client < 0) { perror("Unable to accept"); abort(); @@ -243,9 +245,12 @@ static bool client_ssl_test(char* server_alpn_preferred) { grpc_load_file(SSL_CERT_PATH, 1, &cert_slice))); GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(SSL_KEY_PATH, 1, &key_slice))); - const char* ca_cert = reinterpret_castGRPC_SLICE_START_PTR(ca_slice); - pem_key_cert_pair.private_key = reinterpret_castGRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = reinterpret_castGRPC_SLICE_START_PTR(cert_slice); + const char* ca_cert = + reinterpret_cast GRPC_SLICE_START_PTR(ca_slice); + pem_key_cert_pair.private_key = + reinterpret_cast GRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = + reinterpret_cast GRPC_SLICE_START_PTR(cert_slice); grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(ca_cert, &pem_key_cert_pair, nullptr); diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index a4f182e643..fa3ee0bc1e 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -67,7 +67,8 @@ const grpc_handshaker_vtable readahead_handshaker_vtable = { readahead_handshaker_do_handshake}; static grpc_handshaker* readahead_handshaker_create() { - grpc_handshaker* h = static_cast(gpr_zalloc(sizeof(grpc_handshaker))); + grpc_handshaker* h = + static_cast(gpr_zalloc(sizeof(grpc_handshaker))); grpc_handshaker_init(&readahead_handshaker_vtable, h); return h; } diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index 6ae2471807..6f1a097dbd 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -78,9 +78,12 @@ static void server_thread(void* arg) { grpc_load_file(SSL_CERT_PATH, 1, &cert_slice))); GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(SSL_KEY_PATH, 1, &key_slice))); - const char* ca_cert = reinterpret_castGRPC_SLICE_START_PTR(ca_slice); - pem_key_cert_pair.private_key = reinterpret_castGRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = reinterpret_castGRPC_SLICE_START_PTR(cert_slice); + const char* ca_cert = + reinterpret_cast GRPC_SLICE_START_PTR(ca_slice); + pem_key_cert_pair.private_key = + reinterpret_cast GRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = + reinterpret_cast GRPC_SLICE_START_PTR(cert_slice); grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create( ca_cert, &pem_key_cert_pair, 1, 0, nullptr); @@ -217,8 +220,8 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, unsigned int alpn_selected_len; SSL_get0_alpn_selected(ssl, &alpn_selected, &alpn_selected_len); if (strlen(alpn_expected) != alpn_selected_len || - strncmp(reinterpret_cast(alpn_selected), alpn_expected, alpn_selected_len) != - 0) { + strncmp(reinterpret_cast(alpn_selected), alpn_expected, + alpn_selected_len) != 0) { gpr_log(GPR_ERROR, "Unexpected ALPN protocol preference"); success = false; } diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 9719a90e82..8db8ac5ed6 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -77,7 +77,8 @@ static void end_test(grpc_endpoint_test_config config) { config.clean_up(); } static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, size_t* num_blocks, uint8_t* current_data) { size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); - grpc_slice* slices = static_cast(gpr_malloc(sizeof(grpc_slice) * nslices)); + grpc_slice* slices = + static_cast(gpr_malloc(sizeof(grpc_slice) * nslices)); size_t num_bytes_left = num_bytes; size_t i; size_t j; diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index 092c880bfa..b81c73b2c0 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -196,7 +196,8 @@ static void listen_cb(void* arg, /*=sv_arg*/ return; } - fd = accept(grpc_fd_wrapped_fd(listen_em_fd), reinterpret_cast(&ss), &slen); + fd = accept(grpc_fd_wrapped_fd(listen_em_fd), + reinterpret_cast(&ss), &slen); GPR_ASSERT(fd >= 0); GPR_ASSERT(fd < FD_SETSIZE); flags = fcntl(fd, F_GETFL, 0); @@ -335,7 +336,8 @@ static void client_start(client* cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); - if (connect(fd, reinterpret_cast(&sin), sizeof(sin)) == -1) { + if (connect(fd, reinterpret_cast(&sin), sizeof(sin)) == + -1) { if (errno == EINPROGRESS) { struct pollfd pfd; pfd.fd = fd; diff --git a/test/core/iomgr/sockaddr_utils_test.cc b/test/core/iomgr/sockaddr_utils_test.cc index 51ac66685a..32d2a384bd 100644 --- a/test/core/iomgr/sockaddr_utils_test.cc +++ b/test/core/iomgr/sockaddr_utils_test.cc @@ -33,7 +33,8 @@ static grpc_resolved_address make_addr4(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr4; - struct sockaddr_in* addr4 = reinterpret_cast(resolved_addr4.addr); + struct sockaddr_in* addr4 = + reinterpret_cast(resolved_addr4.addr); memset(&resolved_addr4, 0, sizeof(resolved_addr4)); addr4->sin_family = AF_INET; GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr)); @@ -45,7 +46,8 @@ static grpc_resolved_address make_addr4(const uint8_t* data, size_t data_len) { static grpc_resolved_address make_addr6(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr6; - struct sockaddr_in6* addr6 = reinterpret_cast(resolved_addr6.addr); + struct sockaddr_in6* addr6 = + reinterpret_cast(resolved_addr6.addr); memset(&resolved_addr6, 0, sizeof(resolved_addr6)); addr6->sin6_family = AF_INET6; GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr)); @@ -56,7 +58,8 @@ static grpc_resolved_address make_addr6(const uint8_t* data, size_t data_len) { } static void set_addr6_scope_id(grpc_resolved_address* addr, uint32_t scope_id) { - struct sockaddr_in6* addr6 = reinterpret_cast(addr->addr); + struct sockaddr_in6* addr6 = + reinterpret_cast(addr->addr); GPR_ASSERT(addr6->sin6_family == AF_INET6); addr6->sin6_scope_id = scope_id; } diff --git a/test/core/iomgr/socket_utils_test.cc b/test/core/iomgr/socket_utils_test.cc index 852370485a..a21f3fac62 100644 --- a/test/core/iomgr/socket_utils_test.cc +++ b/test/core/iomgr/socket_utils_test.cc @@ -43,7 +43,8 @@ struct test_socket_mutator { static bool mutate_fd(int fd, grpc_socket_mutator* mutator) { int newval; socklen_t intlen = sizeof(newval); - struct test_socket_mutator* m = reinterpret_cast(mutator); + struct test_socket_mutator* m = + reinterpret_cast(mutator); if (0 != setsockopt(fd, IPPROTO_IP, IP_TOS, &m->option_value, sizeof(m->option_value))) { @@ -59,14 +60,17 @@ static bool mutate_fd(int fd, grpc_socket_mutator* mutator) { } static void destroy_test_mutator(grpc_socket_mutator* mutator) { - struct test_socket_mutator* m = reinterpret_cast(mutator); + struct test_socket_mutator* m = + reinterpret_cast(mutator); gpr_free(m); } static int compare_test_mutator(grpc_socket_mutator* a, grpc_socket_mutator* b) { - struct test_socket_mutator* ma = reinterpret_cast(a); - struct test_socket_mutator* mb = reinterpret_cast(b); + struct test_socket_mutator* ma = + reinterpret_cast(a); + struct test_socket_mutator* mb = + reinterpret_cast(b); return GPR_ICMP(ma->option_value, mb->option_value); } @@ -117,7 +121,8 @@ int main(int argc, char** argv) { grpc_set_socket_with_mutator(sock, (grpc_socket_mutator*)&mutator))); mutator.option_value = -1; - err = grpc_set_socket_with_mutator(sock, reinterpret_cast(&mutator)); + err = grpc_set_socket_with_mutator( + sock, reinterpret_cast(&mutator)); GPR_ASSERT(err != GRPC_ERROR_NONE); GRPC_ERROR_UNREF(err); diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index 7ce30ca7f4..8a43170043 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -78,7 +78,8 @@ static void must_fail(void* arg, grpc_error* error) { void test_succeeds(void) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); int svr_fd; int r; int connections_complete_before; @@ -112,7 +113,8 @@ void test_succeeds(void) { /* await the connection */ do { resolved_addr.len = sizeof(addr); - r = accept(svr_fd, reinterpret_cast(addr), reinterpret_cast(&resolved_addr.len)); + r = accept(svr_fd, reinterpret_cast(addr), + reinterpret_cast(&resolved_addr.len)); } while (r == -1 && errno == EINTR); GPR_ASSERT(r >= 0); close(r); @@ -136,7 +138,8 @@ void test_succeeds(void) { void test_fails(void) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); int connections_complete_before; grpc_closure done; grpc_core::ExecCtx exec_ctx; diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index b059ac44a1..f4df6fca23 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -132,7 +132,8 @@ static size_t count_slices(grpc_slice* slices, size_t nslices, } static void read_cb(void* user_data, grpc_error* error) { - struct read_socket_state* state = static_cast(user_data); + struct read_socket_state* state = + static_cast(user_data); size_t read_bytes; int current_data; @@ -172,7 +173,8 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); - a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = static_cast(slice_size); + a[0].type = GRPC_ARG_INTEGER, + a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); grpc_endpoint_add_to_pollset(ep, g_pollset); @@ -262,7 +264,8 @@ struct write_socket_state { static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, size_t* num_blocks, uint8_t* current_data) { size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u); - grpc_slice* slices = static_cast(gpr_malloc(sizeof(grpc_slice) * nslices)); + grpc_slice* slices = + static_cast(gpr_malloc(sizeof(grpc_slice) * nslices)); size_t num_bytes_left = num_bytes; unsigned i, j; unsigned char* buf; @@ -284,7 +287,8 @@ static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, static void write_done(void* user_data /* write_socket_state */, grpc_error* error) { - struct write_socket_state* state = static_cast(user_data); + struct write_socket_state* state = + static_cast(user_data); gpr_log(GPR_INFO, "Write done callback called"); gpr_mu_lock(g_mu); gpr_log(GPR_INFO, "Signalling write done"); @@ -358,7 +362,8 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); - a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = static_cast(slice_size); + a[0].type = GRPC_ARG_INTEGER, + a[0].value.integer = static_cast(slice_size); grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), &args, "test"); grpc_endpoint_add_to_pollset(ep, g_pollset); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index c1b4f36290..221c993fe7 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -181,7 +181,8 @@ static void test_no_op_with_start(void) { static void test_no_op_with_port(void) { grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port"); @@ -200,7 +201,8 @@ static void test_no_op_with_port(void) { static void test_no_op_with_port_and_start(void) { grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port_and_start"); @@ -237,7 +239,8 @@ static grpc_error* tcp_connect(const test_addr* remote, return GRPC_OS_ERROR(errno, "Failed to create socket"); } gpr_log(GPR_DEBUG, "start connect to %s", remote->str); - if (connect(clifd, remote_addr, static_cast(remote->addr.len)) != 0) { + if (connect(clifd, remote_addr, static_cast(remote->addr.len)) != + 0) { gpr_mu_unlock(g_mu); close(clifd); return GRPC_OS_ERROR(errno, "connect"); diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 204a32abf3..13cbf2f6df 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -109,7 +109,9 @@ static int test_socket_factory_bind(grpc_socket_factory* factory, int sockfd, const grpc_resolved_address* addr) { test_socket_factory* f = reinterpret_cast(factory); f->number_of_bind_calls++; - return bind(sockfd, reinterpret_cast(const_cast(addr->addr)), static_cast(addr->len)); + return bind(sockfd, + reinterpret_cast(const_cast(addr->addr)), + static_cast(addr->len)); } static int test_socket_factory_compare(grpc_socket_factory* a, @@ -173,7 +175,8 @@ static void test_no_op_with_port(void) { g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_port"); @@ -196,7 +199,8 @@ static void test_no_op_with_port_and_socket_factory(void) { g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); test_socket_factory* socket_factory = test_socket_factory_create(); grpc_arg socket_factory_arg = @@ -231,7 +235,8 @@ static void test_no_op_with_port_and_start(void) { g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_port_and_start"); @@ -256,7 +261,8 @@ static void test_receive(int number_of_clients) { grpc_pollset_init(g_pollset, &g_mu); grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_storage* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_storage* addr = + reinterpret_cast(resolved_addr.addr); int clifd, svrfd; grpc_udp_server* s = grpc_udp_server_create(nullptr); int i; diff --git a/test/core/memory_usage/client.cc b/test/core/memory_usage/client.cc index 96ff7ca721..3c3fa53b51 100644 --- a/test/core/memory_usage/client.cc +++ b/test/core/memory_usage/client.cc @@ -155,16 +155,20 @@ static struct grpc_memory_counters send_snapshot_request(int call_idx, struct grpc_memory_counters snapshot; snapshot.total_size_absolute = - (reinterpret_castGRPC_SLICE_START_PTR(response)) + (reinterpret_cast GRPC_SLICE_START_PTR( + response)) ->total_size_absolute; snapshot.total_allocs_absolute = - (reinterpret_castGRPC_SLICE_START_PTR(response)) + (reinterpret_cast GRPC_SLICE_START_PTR( + response)) ->total_allocs_absolute; snapshot.total_size_relative = - (reinterpret_castGRPC_SLICE_START_PTR(response)) + (reinterpret_cast GRPC_SLICE_START_PTR( + response)) ->total_size_relative; snapshot.total_allocs_relative = - (reinterpret_castGRPC_SLICE_START_PTR(response)) + (reinterpret_cast GRPC_SLICE_START_PTR( + response)) ->total_allocs_relative; grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv); @@ -284,10 +288,11 @@ int main(int argc, char** argv) { grpc_shutdown(); gpr_log(GPR_INFO, "---------client stats--------"); - gpr_log(GPR_INFO, "client call memory usage: %f bytes per call", - static_cast(client_calls_inflight.total_size_relative - - client_benchmark_calls_start.total_size_relative) / - benchmark_iterations); + gpr_log( + GPR_INFO, "client call memory usage: %f bytes per call", + static_cast(client_calls_inflight.total_size_relative - + client_benchmark_calls_start.total_size_relative) / + benchmark_iterations); gpr_log(GPR_INFO, "client channel memory usage %zi bytes", client_channel_end.total_size_relative - client_channel_start.total_size_relative); @@ -296,10 +301,11 @@ int main(int argc, char** argv) { gpr_log(GPR_INFO, "server create: %zi bytes", after_server_create.total_size_relative - before_server_create.total_size_relative); - gpr_log(GPR_INFO, "server call memory usage: %f bytes per call", - static_cast(server_calls_inflight.total_size_relative - - server_benchmark_calls_start.total_size_relative) / - benchmark_iterations); + gpr_log( + GPR_INFO, "server call memory usage: %f bytes per call", + static_cast(server_calls_inflight.total_size_relative - + server_benchmark_calls_start.total_size_relative) / + benchmark_iterations); gpr_log(GPR_INFO, "server channel memory usage %zi bytes", server_calls_end.total_size_relative - after_server_create.total_size_relative); @@ -309,21 +315,22 @@ int main(int argc, char** argv) { if (csv) { char* env_build = gpr_getenv("BUILD_NUMBER"); char* env_job = gpr_getenv("JOB_NAME"); - fprintf(csv, "%f,%zi,%zi,%f,%zi,%s,%s\n", - static_cast(client_calls_inflight.total_size_relative - - client_benchmark_calls_start.total_size_relative) / - benchmark_iterations, - client_channel_end.total_size_relative - - client_channel_start.total_size_relative, - after_server_create.total_size_relative - - before_server_create.total_size_relative, - static_cast(server_calls_inflight.total_size_relative - - server_benchmark_calls_start.total_size_relative) / - benchmark_iterations, - server_calls_end.total_size_relative - - after_server_create.total_size_relative, - env_build == nullptr ? "" : env_build, - env_job == nullptr ? "" : env_job); + fprintf( + csv, "%f,%zi,%zi,%f,%zi,%s,%s\n", + static_cast(client_calls_inflight.total_size_relative - + client_benchmark_calls_start.total_size_relative) / + benchmark_iterations, + client_channel_end.total_size_relative - + client_channel_start.total_size_relative, + after_server_create.total_size_relative - + before_server_create.total_size_relative, + static_cast(server_calls_inflight.total_size_relative - + server_benchmark_calls_start.total_size_relative) / + benchmark_iterations, + server_calls_end.total_size_relative - + after_server_create.total_size_relative, + env_build == nullptr ? "" : env_build, + env_job == nullptr ? "" : env_job); fclose(csv); gpr_log(GPR_INFO, "Summary written to %s", csv_file); } diff --git a/test/core/memory_usage/server.cc b/test/core/memory_usage/server.cc index f016fb248d..3e7bb7e11f 100644 --- a/test/core/memory_usage/server.cc +++ b/test/core/memory_usage/server.cc @@ -84,7 +84,8 @@ static void request_call_unary(int call_idx) { } static void send_initial_metadata_unary(void* tag) { - grpc_metadata_array_init(&(*static_cast(tag)).initial_metadata_send); + grpc_metadata_array_init( + &(*static_cast(tag)).initial_metadata_send); metadata_ops[0].op = GRPC_OP_SEND_INITIAL_METADATA; metadata_ops[0].data.send_initial_metadata.count = 0; @@ -111,7 +112,8 @@ static void send_snapshot(void* tag, struct grpc_memory_counters* snapshot) { grpc_slice snapshot_slice = grpc_slice_new(snapshot, sizeof(*snapshot), gpr_free); payload_buffer = grpc_raw_byte_buffer_create(&snapshot_slice, 1); - grpc_metadata_array_init(&(*static_cast(tag)).initial_metadata_send); + grpc_metadata_array_init( + &(*static_cast(tag)).initial_metadata_send); op = snapshot_ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; @@ -204,7 +206,8 @@ int main(int argc, char** argv) { addr = addr_buf = nullptr; // initialize call instances - for (int i = 0; i < static_cast(sizeof(calls) / sizeof(fling_call)); i++) { + for (int i = 0; i < static_cast(sizeof(calls) / sizeof(fling_call)); + i++) { grpc_call_details_init(&calls[i].call_details); calls[i].state = FLING_SERVER_NEW_REQUEST; } @@ -281,7 +284,8 @@ int main(int argc, char** argv) { grpc_metadata_array_destroy(&s->request_metadata_recv); break; case FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL: - for (int k = 0; k < static_cast(sizeof(calls) / sizeof(fling_call)); + for (int k = 0; + k < static_cast(sizeof(calls) / sizeof(fling_call)); ++k) { if (calls[k].state == FLING_SERVER_WAIT_FOR_DESTROY) { calls[k].state = FLING_SERVER_SEND_STATUS_FLING_CALL; diff --git a/test/core/security/create_jwt.cc b/test/core/security/create_jwt.cc index 7be4ba08e1..2ea640b605 100644 --- a/test/core/security/create_jwt.cc +++ b/test/core/security/create_jwt.cc @@ -36,7 +36,7 @@ void create_jwt(const char* json_key_file_path, const char* service_url, GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file(json_key_file_path, 1, &json_key_data))); key = grpc_auth_json_key_create_from_string( - reinterpret_castGRPC_SLICE_START_PTR(json_key_data)); + reinterpret_cast GRPC_SLICE_START_PTR(json_key_data)); grpc_slice_unref(json_key_data); if (!grpc_auth_json_key_is_valid(&key)) { fprintf(stderr, "Could not parse json key.\n"); diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 77f450b1a3..ce92e21d73 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -873,9 +873,11 @@ static void test_google_default_creds_auth_key(void) { set_google_default_creds_env_var_with_file_contents( "json_key_google_default_creds", json_key); gpr_free(json_key); - creds = reinterpret_cast(grpc_google_default_credentials_create()); + creds = reinterpret_cast( + grpc_google_default_credentials_create()); GPR_ASSERT(creds != nullptr); - jwt = reinterpret_cast(creds->call_creds); + jwt = reinterpret_cast( + creds->call_creds); GPR_ASSERT( strcmp(jwt->key.client_id, "777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") == @@ -891,9 +893,11 @@ static void test_google_default_creds_refresh_token(void) { grpc_flush_cached_google_default_credentials(); set_google_default_creds_env_var_with_file_contents( "refresh_token_google_default_creds", test_refresh_token_str); - creds = reinterpret_cast(grpc_google_default_credentials_create()); + creds = reinterpret_cast( + grpc_google_default_credentials_create()); GPR_ASSERT(creds != nullptr); - refresh = reinterpret_cast(creds->call_creds); + refresh = reinterpret_cast( + creds->call_creds); GPR_ASSERT(strcmp(refresh->refresh_token.client_id, "32555999999.apps.googleusercontent.com") == 0); grpc_channel_credentials_unref(&creds->base); @@ -936,7 +940,8 @@ static void test_google_default_creds_gce(void) { default_creds_gce_detection_httpcli_get_success_override, httpcli_post_should_not_be_called); grpc_composite_channel_credentials* creds = - reinterpret_cast(grpc_google_default_credentials_create()); + reinterpret_cast( + grpc_google_default_credentials_create()); /* Verify that the default creds actually embeds a GCE creds. */ GPR_ASSERT(creds != nullptr); diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc index 70a92d773d..82efe682be 100644 --- a/test/core/security/fetch_oauth2.cc +++ b/test/core/security/fetch_oauth2.cc @@ -38,7 +38,8 @@ static grpc_call_credentials* create_refresh_token_creds( "load_file", grpc_load_file(json_refresh_token_file_path, 1, &refresh_token))); return grpc_google_refresh_token_credentials_create( - reinterpret_castGRPC_SLICE_START_PTR(refresh_token), nullptr); + reinterpret_cast GRPC_SLICE_START_PTR(refresh_token), + nullptr); } int main(int argc, char** argv) { diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index 80bfe45ab3..7a5b3355fe 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -218,7 +218,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, slice = grpc_base64_decode(b64, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(slice)); decoded = static_cast(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1)); - strncpy(decoded, reinterpret_castGRPC_SLICE_START_PTR(slice), + strncpy(decoded, reinterpret_cast GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); decoded[GRPC_SLICE_LENGTH(slice)] = '\0'; json = grpc_json_parse_string(decoded); @@ -385,8 +385,8 @@ static void test_jwt_encode_and_sign( char* jwt = jwt_encode_and_sign_func(&json_key); const char* dot = strchr(jwt, '.'); GPR_ASSERT(dot != nullptr); - parsed_header = - parse_json_part_from_jwt(jwt, static_cast(dot - jwt), &scratchpad); + parsed_header = parse_json_part_from_jwt(jwt, static_cast(dot - jwt), + &scratchpad); GPR_ASSERT(parsed_header != nullptr); check_jwt_header(parsed_header); offset = static_cast(dot - jwt) + 1; diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index 2c454c1395..9718580a08 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -207,7 +207,7 @@ static void test_claims_success(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(claims_without_time_constraint); grpc_json* json = grpc_json_parse_string_with_len( - reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_cast GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); @@ -226,7 +226,7 @@ static void test_expired_claims_failure(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(expired_claims); grpc_json* json = grpc_json_parse_string_with_len( - reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_cast GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); gpr_timespec exp_iat = {100, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; @@ -251,7 +251,7 @@ static void test_expired_claims_failure(void) { static void test_invalid_claims_failure(void) { grpc_slice s = grpc_slice_from_copied_string(invalid_claims); grpc_json* json = grpc_json_parse_string_with_len( - reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_cast GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == nullptr); } @@ -260,7 +260,7 @@ static void test_bad_audience_claims_failure(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(claims_without_time_constraint); grpc_json* json = grpc_json_parse_string_with_len( - reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_cast GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); @@ -274,7 +274,7 @@ static void test_bad_subject_claims_failure(void) { grpc_jwt_claims* claims; grpc_slice s = grpc_slice_from_copied_string(claims_with_bad_subject); grpc_json* json = grpc_json_parse_string_with_len( - reinterpret_castGRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); + reinterpret_cast GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index b18fa455fe..469129a6d0 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -73,7 +73,8 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", nullptr, nullptr}; - grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset* pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &request.mu); request.pops = grpc_polling_entity_create_from_pollset(pollset); request.is_done = false; diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index 00e0783089..4d251391ff 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -97,8 +97,10 @@ int main(int argc, char** argv) { error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - (reinterpret_cast(creds))->call_creds, &sync.pops, - context, &sync.md_array, &sync.on_request_metadata, &error)) { + (reinterpret_cast(creds)) + ->call_creds, + &sync.pops, context, &sync.md_array, &sync.on_request_metadata, + &error)) { // Synchronous response. Invoke callback directly. on_metadata_response(&sync, error); GRPC_ERROR_UNREF(error); diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index bacadec950..23cef99dfa 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -106,7 +106,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( buffer_size -= protected_buffer_size_to_send; } while (still_pending_size > 0); encrypted_leftover = grpc_slice_from_copied_buffer( - reinterpret_cast(encrypted_buffer), total_buffer_size - buffer_size); + reinterpret_cast(encrypted_buffer), + total_buffer_size - buffer_size); f.client_ep = grpc_secure_endpoint_create( fake_read_protector, fake_read_zero_copy_protector, tcp.client, &encrypted_leftover, 1); @@ -165,7 +166,9 @@ static grpc_endpoint_test_config configs[] = { clean_up}, }; -static void inc_call_ctr(void* arg, grpc_error* error) { ++*static_cast(arg); } +static void inc_call_ctr(void* arg, grpc_error* error) { + ++*static_cast(arg); +} static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_endpoint_test_fixture f = config.create_fixture(slice_size); diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index 2a4e7c73d3..61dde0e7d9 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -54,8 +54,8 @@ static void on_jwt_verification_done(void* user_data, if (sync->success) { char* claims_str; GPR_ASSERT(claims != nullptr); - claims_str = - grpc_json_dump_to_string(const_cast(grpc_jwt_claims_json(claims)), 2); + claims_str = grpc_json_dump_to_string( + const_cast(grpc_jwt_claims_json(claims)), 2); printf("Claims: \n\n%s\n", claims_str); gpr_free(claims_str); grpc_jwt_claims_destroy(claims); diff --git a/test/core/slice/percent_encode_fuzzer.cc b/test/core/slice/percent_encode_fuzzer.cc index 1e4e95d97e..1fd197e180 100644 --- a/test/core/slice/percent_encode_fuzzer.cc +++ b/test/core/slice/percent_encode_fuzzer.cc @@ -34,7 +34,8 @@ static void test(const uint8_t* data, size_t size, const uint8_t* dict) { struct grpc_memory_counters counters; grpc_init(); grpc_memory_counters_init(); - grpc_slice input = grpc_slice_from_copied_buffer(reinterpret_cast(data), size); + grpc_slice input = + grpc_slice_from_copied_buffer(reinterpret_cast(data), size); grpc_slice output = grpc_percent_encode_slice(input, dict); grpc_slice decoded_output; // encoder must always produce decodable output diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index ffef966d86..bbee073c71 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -61,8 +61,8 @@ static int detag(void* p) { return static_cast((uintptr_t)p); } void create_loop_destroy(void* addr) { for (int i = 0; i < NUM_OUTER_LOOPS; ++i) { grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_channel* chan = - grpc_insecure_channel_create(static_cast(addr), nullptr, nullptr); + grpc_channel* chan = grpc_insecure_channel_create(static_cast(addr), + nullptr, nullptr); for (int j = 0; j < NUM_INNER_LOOPS; ++j) { gpr_timespec later_time = @@ -94,7 +94,8 @@ struct server_thread_args { }; void server_thread(void* vargs) { - struct server_thread_args* args = static_cast(vargs); + struct server_thread_args* args = + static_cast(vargs); grpc_event ev; gpr_timespec deadline = grpc_timeout_milliseconds_to_deadline(SERVER_SHUTDOWN_TIMEOUT); @@ -107,7 +108,8 @@ static void on_connect(void* vargs, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); - struct server_thread_args* args = static_cast(vargs); + struct server_thread_args* args = + static_cast(vargs); grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); grpc_endpoint_destroy(tcp); @@ -117,11 +119,13 @@ static void on_connect(void* vargs, grpc_endpoint* tcp, } void bad_server_thread(void* vargs) { - struct server_thread_args* args = static_cast(vargs); + struct server_thread_args* args = + static_cast(vargs); grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_storage* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_storage* addr = + reinterpret_cast(resolved_addr.addr); int port; grpc_tcp_server* s; grpc_error* error = grpc_tcp_server_create(nullptr, nullptr, &s); @@ -244,8 +248,8 @@ int run_concurrent_connectivity_test() { void watches_with_short_timeouts(void* addr) { for (int i = 0; i < NUM_OUTER_LOOPS_SHORT_TIMEOUTS; ++i) { grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_channel* chan = - grpc_insecure_channel_create(static_cast(addr), nullptr, nullptr); + grpc_channel* chan = grpc_insecure_channel_create(static_cast(addr), + nullptr, nullptr); for (int j = 0; j < NUM_INNER_LOOPS_SHORT_TIMEOUTS; ++j) { gpr_timespec later_time = diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 0ff17ba8d0..fac5ca8f7f 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -112,7 +112,8 @@ int main(int argc, char** argv) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(call, ops, static_cast(op - ops), tag(1), nullptr); + error = grpc_call_start_batch(call, ops, static_cast(op - ops), + tag(1), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); /* the call should immediately fail */ @@ -128,7 +129,8 @@ int main(int argc, char** argv) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(call, ops, static_cast(op - ops), tag(2), nullptr); + error = grpc_call_start_batch(call, ops, static_cast(op - ops), + tag(2), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); /* the call should immediately fail */ diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index 84029dc87c..786df97285 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -307,8 +307,8 @@ static void verify_binary_header_size(const char* key, const uint8_t* value, intern_value)); GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, false); - grpc_slice value_slice = - grpc_slice_from_copied_buffer(reinterpret_cast(value), value_len); + grpc_slice value_slice = grpc_slice_from_copied_buffer( + reinterpret_cast(value), value_len); grpc_slice base64_encoded = grpc_chttp2_base64_encode(value_slice); size_t expected_size = 32 + strlen(key) + GRPC_SLICE_LENGTH(base64_encoded); GPR_ASSERT(expected_size == elem_size); diff --git a/test/core/transport/timeout_encoding_test.cc b/test/core/transport/timeout_encoding_test.cc index 8e4e566a3e..2367accc2e 100644 --- a/test/core/transport/timeout_encoding_test.cc +++ b/test/core/transport/timeout_encoding_test.cc @@ -108,7 +108,9 @@ static grpc_millis millis_from_nanos(int64_t x) { static grpc_millis millis_from_micros(int64_t x) { return static_cast(x / GPR_US_PER_MS + (x % GPR_US_PER_MS != 0)); } -static grpc_millis millis_from_millis(int64_t x) { return static_cast(x); } +static grpc_millis millis_from_millis(int64_t x) { + return static_cast(x); +} static grpc_millis millis_from_seconds(int64_t x) { return static_cast(x * GPR_MS_PER_SEC); } diff --git a/test/core/tsi/fake_transport_security_test.cc b/test/core/tsi/fake_transport_security_test.cc index d709077c2f..ea392d347d 100644 --- a/test/core/tsi/fake_transport_security_test.cc +++ b/test/core/tsi/fake_transport_security_test.cc @@ -102,7 +102,8 @@ void fake_tsi_test_do_round_trip_for_all_configs() { v <<= 1; } tsi_test_fixture* fixture = fake_tsi_test_fixture_create(); - fake_tsi_test_fixture* fake_fixture = reinterpret_cast(fixture); + fake_tsi_test_fixture* fake_fixture = + reinterpret_cast(fixture); tsi_test_frame_protector_config_destroy(fake_fixture->base.config); fake_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 06780f03e1..d7a4d747e1 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -81,7 +81,8 @@ typedef struct ssl_tsi_test_fixture { } ssl_tsi_test_fixture; static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); GPR_ASSERT(ssl_fixture != nullptr); GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr); GPR_ASSERT(ssl_fixture->alpn_lib != nullptr); @@ -244,7 +245,8 @@ static void check_client_peer(ssl_tsi_test_fixture* ssl_fixture, } static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); GPR_ASSERT(ssl_fixture != nullptr); GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr); ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib; @@ -281,7 +283,8 @@ static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp) { } static void ssl_test_destruct(tsi_test_fixture* fixture) { - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); if (ssl_fixture == nullptr) { return; } @@ -425,7 +428,8 @@ void ssl_tsi_test_do_handshake() { void ssl_tsi_test_do_handshake_with_client_authentication() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->force_client_auth = true; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -434,7 +438,8 @@ void ssl_tsi_test_do_handshake_with_client_authentication() { void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain() { /* server1 cert contains "waterzooi.test.google.be" in SAN. */ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->server_name_indication = const_cast("waterzooi.test.google.be"); tsi_test_do_handshake(fixture); @@ -444,7 +449,8 @@ void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain() { void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain() { /* server1 cert contains "*.test.google.fr" in SAN. */ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->server_name_indication = const_cast("juju.test.google.fr"); tsi_test_do_handshake(fixture); @@ -453,7 +459,8 @@ void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain() { void ssl_tsi_test_do_handshake_with_bad_server_cert() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->key_cert_lib->use_bad_server_cert = true; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -461,7 +468,8 @@ void ssl_tsi_test_do_handshake_with_bad_server_cert() { void ssl_tsi_test_do_handshake_with_bad_client_cert() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->key_cert_lib->use_bad_client_cert = true; ssl_fixture->force_client_auth = true; tsi_test_do_handshake(fixture); @@ -470,7 +478,8 @@ void ssl_tsi_test_do_handshake_with_bad_client_cert() { void ssl_tsi_test_do_handshake_alpn_client_no_server() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_NO_SERVER; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -478,7 +487,8 @@ void ssl_tsi_test_do_handshake_alpn_client_no_server() { void ssl_tsi_test_do_handshake_alpn_server_no_client() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_SERVER_NO_CLIENT; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -486,7 +496,8 @@ void ssl_tsi_test_do_handshake_alpn_server_no_client() { void ssl_tsi_test_do_handshake_alpn_client_server_mismatch() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_MISMATCH; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -494,7 +505,8 @@ void ssl_tsi_test_do_handshake_alpn_client_server_mismatch() { void ssl_tsi_test_do_handshake_alpn_client_server_ok() { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_OK; tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); @@ -511,7 +523,8 @@ void ssl_tsi_test_do_round_trip_for_all_configs() { v <<= 1; } tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); tsi_test_frame_protector_config_destroy(ssl_fixture->base.config); ssl_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], @@ -531,7 +544,8 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() { for (size_t ind4 = 0; ind4 < size; ind4++) { for (size_t ind5 = 0; ind5 < size; ind5++) { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); - ssl_tsi_test_fixture* ssl_fixture = reinterpret_cast(fixture); + ssl_tsi_test_fixture* ssl_fixture = + reinterpret_cast(fixture); tsi_test_frame_protector_config_set_buffer_size( ssl_fixture->base.config, odd_sizes[ind1], odd_sizes[ind2], odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]); diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index ef3b6307db..080585365f 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -144,8 +144,9 @@ static void maybe_append_unused_bytes(handshaker_args* args) { tsi_test_fixture* fixture = args->fixture; if (fixture->test_unused_bytes && !args->appended_unused_bytes) { args->appended_unused_bytes = true; - send_bytes_to_peer(fixture, reinterpret_cast(TSI_TEST_UNUSED_BYTES), - strlen(TSI_TEST_UNUSED_BYTES), args->is_client); + send_bytes_to_peer( + fixture, reinterpret_cast(TSI_TEST_UNUSED_BYTES), + strlen(TSI_TEST_UNUSED_BYTES), args->is_client); if (fixture->client_result != nullptr && fixture->server_result == nullptr) { fixture->has_client_finished_first = true; diff --git a/test/core/util/cmdline.cc b/test/core/util/cmdline.cc index fd3959bfe9..e76acb5e2b 100644 --- a/test/core/util/cmdline.cc +++ b/test/core/util/cmdline.cc @@ -287,7 +287,8 @@ static int normal_state(gpr_cmdline* cl, char* str) { eq = strchr(str, '='); if (eq != nullptr) { /* copy the string into a temp buffer and extract the name */ - tmp = arg_name = static_cast(gpr_malloc(static_cast(eq - str + 1))); + tmp = arg_name = + static_cast(gpr_malloc(static_cast(eq - str + 1))); memcpy(arg_name, str, static_cast(eq - str)); arg_name[eq - str] = 0; } else { diff --git a/test/core/util/debugger_macros.cc b/test/core/util/debugger_macros.cc index 0ec5f1db6b..05fb146173 100644 --- a/test/core/util/debugger_macros.cc +++ b/test/core/util/debugger_macros.cc @@ -54,5 +54,6 @@ grpc_stream* grpc_transport_stream_from_call(grpc_call* call) { } grpc_chttp2_stream* grpc_chttp2_stream_from_call(grpc_call* call) { - return reinterpret_cast(grpc_transport_stream_from_call(call)); + return reinterpret_cast( + grpc_transport_stream_from_call(call)); } diff --git a/test/core/util/histogram.cc b/test/core/util/histogram.cc index 6eb0342ede..f028ac404e 100644 --- a/test/core/util/histogram.cc +++ b/test/core/util/histogram.cc @@ -74,7 +74,8 @@ static double bucket_start(grpc_histogram* h, double x) { grpc_histogram* grpc_histogram_create(double resolution, double max_bucket_start) { - grpc_histogram* h = static_cast(gpr_malloc(sizeof(grpc_histogram))); + grpc_histogram* h = + static_cast(gpr_malloc(sizeof(grpc_histogram))); GPR_ASSERT(resolution > 0.0); GPR_ASSERT(max_bucket_start > resolution); h->sum = 0.0; @@ -88,7 +89,8 @@ grpc_histogram* grpc_histogram_create(double resolution, h->num_buckets = bucket_for_unchecked(h, max_bucket_start) + 1; GPR_ASSERT(h->num_buckets > 1); GPR_ASSERT(h->num_buckets < 100000000); - h->buckets = static_cast(gpr_zalloc(sizeof(uint32_t) * h->num_buckets)); + h->buckets = + static_cast(gpr_zalloc(sizeof(uint32_t) * h->num_buckets)); return h; } diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc index 37a1b622e4..adeff18ef0 100644 --- a/test/core/util/mock_endpoint.cc +++ b/test/core/util/mock_endpoint.cc @@ -118,7 +118,8 @@ static const grpc_endpoint_vtable vtable = { grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota) { - grpc_mock_endpoint* m = static_cast(gpr_malloc(sizeof(*m))); + grpc_mock_endpoint* m = + static_cast(gpr_malloc(sizeof(*m))); m->base.vtable = &vtable; char* name; gpr_asprintf(&name, "mock_endpoint_%" PRIxPTR, (intptr_t)m); diff --git a/test/core/util/parse_hexstring.cc b/test/core/util/parse_hexstring.cc index 7ba6776bc2..cd64843bd3 100644 --- a/test/core/util/parse_hexstring.cc +++ b/test/core/util/parse_hexstring.cc @@ -42,7 +42,8 @@ grpc_slice parse_hexstring(const char* hexstring) { temp = static_cast(temp << 4) | static_cast(*p - '0'); nibbles++; } else if (*p >= 'a' && *p <= 'f') { - temp = static_cast(temp << 4) | static_cast(*p - 'a' + 10); + temp = + static_cast(temp << 4) | static_cast(*p - 'a' + 10); nibbles++; } if (nibbles == 2) { diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc index 38c23aa978..5958216747 100644 --- a/test/core/util/passthru_endpoint.cc +++ b/test/core/util/passthru_endpoint.cc @@ -148,8 +148,9 @@ static void me_destroy(grpc_endpoint* ep) { static char* me_get_peer(grpc_endpoint* ep) { passthru_endpoint* p = (reinterpret_cast(ep))->parent; - return (reinterpret_cast(ep)) == &p->client ? gpr_strdup("fake:mock_client_endpoint") - : gpr_strdup("fake:mock_server_endpoint"); + return (reinterpret_cast(ep)) == &p->client + ? gpr_strdup("fake:mock_client_endpoint") + : gpr_strdup("fake:mock_server_endpoint"); } static int me_get_fd(grpc_endpoint* ep) { return -1; } @@ -190,7 +191,8 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client, grpc_endpoint** server, grpc_resource_quota* resource_quota, grpc_passthru_endpoint_stats* stats) { - passthru_endpoint* m = static_cast(gpr_malloc(sizeof(*m))); + passthru_endpoint* m = + static_cast(gpr_malloc(sizeof(*m))); m->halves = 2; m->shutdown = 0; if (stats == nullptr) { @@ -208,8 +210,8 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client, grpc_passthru_endpoint_stats* grpc_passthru_endpoint_stats_create() { grpc_passthru_endpoint_stats* stats = - static_cast(gpr_malloc( - sizeof(grpc_passthru_endpoint_stats))); + static_cast( + gpr_malloc(sizeof(grpc_passthru_endpoint_stats))); memset(stats, 0, sizeof(*stats)); gpr_ref_init(&stats->refs, 1); return stats; diff --git a/test/core/util/port.cc b/test/core/util/port.cc index 4690727337..303306de45 100644 --- a/test/core/util/port.cc +++ b/test/core/util/port.cc @@ -75,8 +75,8 @@ static void chose_port(int port) { atexit(free_chosen_ports); } num_chosen_ports++; - chosen_ports = - static_cast(gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports)); + chosen_ports = static_cast( + gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports)); chosen_ports[num_chosen_ports - 1] = port; } diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 886951c20d..9a4159944b 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -41,7 +41,8 @@ typedef struct freereq { } freereq; static void destroy_pops_and_shutdown(void* p, grpc_error* error) { - grpc_pollset* pollset = grpc_polling_entity_pollset(static_cast(p)); + grpc_pollset* pollset = + grpc_polling_entity_pollset(static_cast(p)); grpc_pollset_destroy(pollset); gpr_free(pollset); } @@ -71,7 +72,8 @@ void grpc_free_port_using_server(int port) { memset(&req, 0, sizeof(req)); memset(&rsp, 0, sizeof(rsp)); - grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset* pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, @@ -158,7 +160,8 @@ static void got_port_from_server(void* arg, grpc_error* error) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis( - static_cast(1000.0 * (1 + pow(1.3, pr->retries) * rand() / RAND_MAX)), + static_cast( + 1000.0 * (1 + pow(1.3, pr->retries) * rand() / RAND_MAX)), GPR_TIMESPAN))); pr->retries++; req.host = pr->server; @@ -201,7 +204,8 @@ int grpc_pick_port_using_server(void) { grpc_core::ExecCtx exec_ctx; memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); - grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset* pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, diff --git a/test/core/util/reconnect_server.cc b/test/core/util/reconnect_server.cc index ea8fee499c..ad7cf42f71 100644 --- a/test/core/util/reconnect_server.cc +++ b/test/core/util/reconnect_server.cc @@ -76,8 +76,8 @@ static void on_connect(void* arg, grpc_endpoint* tcp, } else { if (last_colon == nullptr) { gpr_log(GPR_ERROR, "peer does not contain a ':'"); - } else if (strncmp(server->peer, peer, static_cast(last_colon - peer)) != - 0) { + } else if (strncmp(server->peer, peer, + static_cast(last_colon - peer)) != 0) { gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer, peer); } gpr_free(peer); diff --git a/test/core/util/slice_splitter.cc b/test/core/util/slice_splitter.cc index e766c1982c..1f81d03d96 100644 --- a/test/core/util/slice_splitter.cc +++ b/test/core/util/slice_splitter.cc @@ -45,8 +45,8 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, switch (mode) { case GRPC_SLICE_SPLIT_IDENTITY: *dst_slice_count = src_slice_count; - *dst_slices = - static_cast(gpr_malloc(sizeof(grpc_slice) * src_slice_count)); + *dst_slices = static_cast( + gpr_malloc(sizeof(grpc_slice) * src_slice_count)); for (i = 0; i < src_slice_count; i++) { (*dst_slices)[i] = src_slices[i]; grpc_slice_ref((*dst_slices)[i]); @@ -74,7 +74,8 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, length += GRPC_SLICE_LENGTH(src_slices[i]); } *dst_slice_count = length; - *dst_slices = static_cast(gpr_malloc(sizeof(grpc_slice) * length)); + *dst_slices = + static_cast(gpr_malloc(sizeof(grpc_slice) * length)); length = 0; for (i = 0; i < src_slice_count; i++) { for (j = 0; j < GRPC_SLICE_LENGTH(src_slices[i]); j++) { diff --git a/test/core/util/subprocess_posix.cc b/test/core/util/subprocess_posix.cc index bb42ccbdeb..ab288d777f 100644 --- a/test/core/util/subprocess_posix.cc +++ b/test/core/util/subprocess_posix.cc @@ -52,7 +52,8 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) { if (pid == -1) { return nullptr; } else if (pid == 0) { - exec_args = static_cast(gpr_malloc((static_cast(argc) + 1) * sizeof(char*))); + exec_args = static_cast( + gpr_malloc((static_cast(argc) + 1) * sizeof(char*))); memcpy(exec_args, argv, static_cast(argc) * sizeof(char*)); exec_args[argc] = nullptr; execv(exec_args[0], exec_args); diff --git a/test/core/util/test_config.cc b/test/core/util/test_config.cc index 5c01cfd070..53a6297d6e 100644 --- a/test/core/util/test_config.cc +++ b/test/core/util/test_config.cc @@ -365,15 +365,17 @@ int64_t grpc_test_slowdown_factor() { gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s) { return gpr_time_add( gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_millis(grpc_test_slowdown_factor() * static_cast(1e3) * time_s, - GPR_TIMESPAN)); + gpr_time_from_millis( + grpc_test_slowdown_factor() * static_cast(1e3) * time_s, + GPR_TIMESPAN)); } gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms) { return gpr_time_add( gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_micros(grpc_test_slowdown_factor() * static_cast(1e3) * time_ms, - GPR_TIMESPAN)); + gpr_time_from_micros( + grpc_test_slowdown_factor() * static_cast(1e3) * time_ms, + GPR_TIMESPAN)); } void grpc_test_init(int argc, char** argv) { diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index 1216934630..cb2bc701fa 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -54,7 +54,8 @@ void test_tcp_server_init(test_tcp_server* server, void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); + struct sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); int port_added; grpc_core::ExecCtx exec_ctx; diff --git a/test/core/util/trickle_endpoint.cc b/test/core/util/trickle_endpoint.cc index 87a8d9c216..f2efb049b4 100644 --- a/test/core/util/trickle_endpoint.cc +++ b/test/core/util/trickle_endpoint.cc @@ -152,7 +152,8 @@ static const grpc_endpoint_vtable vtable = {te_read, grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, double bytes_per_second) { - trickle_endpoint* te = static_cast(gpr_malloc(sizeof(*te))); + trickle_endpoint* te = + static_cast(gpr_malloc(sizeof(*te))); te->base.vtable = &vtable; te->wrapped = wrap; te->bytes_per_second = bytes_per_second; diff --git a/test/cpp/codegen/proto_utils_test.cc b/test/cpp/codegen/proto_utils_test.cc index d714e59b5d..b64f9a0d17 100644 --- a/test/cpp/codegen/proto_utils_test.cc +++ b/test/cpp/codegen/proto_utils_test.cc @@ -130,7 +130,7 @@ void BufferWriterTest(int block_size, int total_size, int backup_size) { } TEST(WriterTest, TinyBlockTinyBackup) { - for (int i = 2; i < static_castGRPC_SLICE_INLINED_SIZE; i++) { + for (int i = 2; i < static_cast GRPC_SLICE_INLINED_SIZE; i++) { BufferWriterTest(i, 256, 1); } } diff --git a/test/cpp/common/alarm_test.cc b/test/cpp/common/alarm_test.cc index 2dc2e4b36c..376aa3e32e 100644 --- a/test/cpp/common/alarm_test.cc +++ b/test/cpp/common/alarm_test.cc @@ -35,8 +35,8 @@ TEST(AlarmTest, RegularExpiry) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -56,8 +56,8 @@ TEST(AlarmTest, MultithreadedRegularExpiry) { }); std::thread t2([&cq, &ok, &output_tag, &status] { - status = cq.AsyncNext(&output_tag, &ok, - grpc_timeout_seconds_to_deadline(2)); + status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); }); t1.join(); @@ -74,8 +74,8 @@ TEST(AlarmTest, DeprecatedRegularExpiry) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -90,8 +90,8 @@ TEST(AlarmTest, MoveConstructor) { Alarm second(std::move(first)); void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); EXPECT_EQ(junk, output_tag); @@ -107,8 +107,8 @@ TEST(AlarmTest, MoveAssignment) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -125,8 +125,8 @@ TEST(AlarmTest, RegularExpiryChrono) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -141,8 +141,8 @@ TEST(AlarmTest, ZeroExpiry) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -157,8 +157,8 @@ TEST(AlarmTest, NegativeExpiry) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_TRUE(ok); @@ -174,8 +174,8 @@ TEST(AlarmTest, Cancellation) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_FALSE(ok); @@ -192,8 +192,8 @@ TEST(AlarmTest, SetDestruction) { void* output_tag; bool ok; - const CompletionQueue::NextStatus status = cq.AsyncNext( - &output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); + const CompletionQueue::NextStatus status = + cq.AsyncNext(&output_tag, &ok, grpc_timeout_seconds_to_deadline(1)); EXPECT_EQ(status, CompletionQueue::GOT_EVENT); EXPECT_FALSE(ok); diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index b658e7731a..cd8321771a 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -347,7 +347,8 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs, for (int i = 0; i < num_rpcs; ++i) { ClientContext context; if (with_binary_metadata) { - char bytes[8] = {'\0', '\1', '\2', '\3', '\4', '\5', '\6', static_cast(i)}; + char bytes[8] = {'\0', '\1', '\2', '\3', + '\4', '\5', '\6', static_cast(i)}; context.AddMetadata("custom-bin", grpc::string(bytes, 8)); } context.set_compression_algorithm(GRPC_COMPRESS_GZIP); diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index e47842e526..d17c2957a2 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -198,7 +198,8 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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), 1); cq_verify(cqv); @@ -230,7 +231,8 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(201), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), tag(201), + nullptr); GPR_ASSERT(GRPC_CALL_OK == error); gpr_log(GPR_INFO, "LB Server[%s](%s) after tag 201", sf->servers_hostport, sf->balancer_name); @@ -255,8 +257,8 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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), 1); cq_verify(cqv); @@ -278,7 +280,8 @@ static void start_lb_server(server_fixture* sf, int* ports, size_t nports, op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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(201), 1); @@ -350,8 +353,8 @@ static void start_backend_server(server_fixture* sf) { op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(op - ops), tag(101), nullptr); + error = grpc_call_start_batch(s, ops, static_cast(op - ops), + tag(101), nullptr); GPR_ASSERT(GRPC_CALL_OK == error); gpr_log(GPR_INFO, "Server[%s] after tag 101", sf->servers_hostport); @@ -364,8 +367,8 @@ static void start_backend_server(server_fixture* sf) { op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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); ev = grpc_completion_queue_next( sf->cq, grpc_timeout_seconds_to_deadline(3), nullptr); @@ -394,8 +397,8 @@ static void start_backend_server(server_fixture* sf) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(s, ops, static_cast(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); ev = grpc_completion_queue_next( sf->cq, grpc_timeout_seconds_to_deadline(3), nullptr); @@ -428,8 +431,8 @@ static void start_backend_server(server_fixture* sf) { op->flags = 0; op->reserved = nullptr; op++; - error = - grpc_call_start_batch(s, ops, static_cast(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(101), 1); @@ -493,7 +496,8 @@ static void perform_request(client_fixture* cf) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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); for (i = 0; i < 4; i++) { @@ -510,7 +514,8 @@ static void perform_request(client_fixture* cf) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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), 1); @@ -529,7 +534,8 @@ static void perform_request(client_fixture* cf) { op->flags = 0; op->reserved = nullptr; op++; - error = grpc_call_start_batch(c, ops, static_cast(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(1), 1); diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 2ea1d3f79a..865b5c407f 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -875,7 +875,8 @@ bool InteropClient::DoCacheableUnary() { // Create request with current timestamp gpr_timespec ts = gpr_now(GPR_CLOCK_PRECISE); - std::string timestamp = std::to_string(static_cast(ts.tv_nsec)); + std::string timestamp = + std::to_string(static_cast(ts.tv_nsec)); SimpleRequest request; request.mutable_payload()->set_body(timestamp.c_str(), timestamp.size()); diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index 3fe709ff83..07bb3c92ae 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -777,7 +777,8 @@ static void OnHeaderNew(void* user_data, grpc_mdelem md) { if (GRPC_MDELEM_IS_INTERNED(md)) { /* not already parsed: parse it now, and store the * result away */ - cached_timeout = static_cast(gpr_malloc(sizeof(grpc_millis))); + cached_timeout = + static_cast(gpr_malloc(sizeof(grpc_millis))); *cached_timeout = timeout; grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 7b236d94b6..ec79b95cd8 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -74,8 +74,9 @@ static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker, gpr_mu_unlock(&ps->mu); GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag)); - grpc_cq_end_op(g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, - static_cast(gpr_malloc(sizeof(grpc_cq_completion)))); + grpc_cq_end_op( + g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, + static_cast(gpr_malloc(sizeof(grpc_cq_completion)))); grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&ps->mu); return GRPC_ERROR_NONE; diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index ce9731b7a6..ab6c194830 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -108,7 +108,8 @@ class FullstackFixture : public BaseFixture { void AddToLabel(std::ostream& out, benchmark::State& state) { BaseFixture::AddToLabel(out, state); out << " polls/iter:" - << static_cast(grpc_get_cq_poll_num(this->cq()->cq())) / state.iterations(); + << static_cast(grpc_get_cq_poll_num(this->cq()->cq())) / + state.iterations(); } ServerCompletionQueue* cq() { return cq_.get(); } @@ -236,7 +237,8 @@ class EndpointPairFixture : public BaseFixture { void AddToLabel(std::ostream& out, benchmark::State& state) { BaseFixture::AddToLabel(out, state); out << " polls/iter:" - << static_cast(grpc_get_cq_poll_num(this->cq()->cq())) / state.iterations(); + << static_cast(grpc_get_cq_poll_num(this->cq()->cq())) / + state.iterations(); } ServerCompletionQueue* cq() { return cq_.get(); } diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index 25a033f104..e4a31f50a9 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -43,18 +43,21 @@ void TrackCounters::AddToLabel(std::ostream& out, benchmark::State& state) { grpc_stats_data stats; grpc_stats_diff(&stats_end, &stats_begin_, &stats); for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { - out << " " << grpc_stats_counter_name[i] - << "/iter:" << (static_cast(stats.counters[i]) / static_cast(state.iterations())); + out << " " << grpc_stats_counter_name[i] << "/iter:" + << (static_cast(stats.counters[i]) / + static_cast(state.iterations())); } for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { std::ostringstream median_ss; median_ss << grpc_stats_histogram_name[i] << "-median"; - state.counters[median_ss.str()] = benchmark::Counter( - grpc_stats_histo_percentile(&stats, static_cast(i), 50.0)); + state.counters[median_ss.str()] = + benchmark::Counter(grpc_stats_histo_percentile( + &stats, static_cast(i), 50.0)); std::ostringstream tail_ss; tail_ss << grpc_stats_histogram_name[i] << "-99p"; - state.counters[tail_ss.str()] = benchmark::Counter( - grpc_stats_histo_percentile(&stats, static_cast(i), 99.0)); + state.counters[tail_ss.str()] = + benchmark::Counter(grpc_stats_histo_percentile( + &stats, static_cast(i), 99.0)); } #ifdef GPR_LOW_LEVEL_COUNTERS grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index 0d0ab1891a..d0190de172 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -230,7 +230,8 @@ static double UnaryPingPong(int request_size, int response_size) { } double writes_per_iteration = - static_cast(fixture->writes_performed()) / static_cast(kIterations); + static_cast(fixture->writes_performed()) / + static_cast(kIterations); fixture.reset(); server_env[0]->~ServerEnv(); diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 863be40f2a..c5e90bd9a4 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -109,9 +109,12 @@ void GprLogReporter::ReportCoreStats(const char* name, int idx, for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { gpr_log(GPR_DEBUG, "%s[%d].%s = %.1lf/%.1lf/%.1lf (50/95/99%%-ile)", name, idx, grpc_stats_histogram_name[i], - grpc_stats_histo_percentile(&data, static_cast(i), 50), - grpc_stats_histo_percentile(&data, static_cast(i), 95), - grpc_stats_histo_percentile(&data, static_cast(i), 99)); + grpc_stats_histo_percentile( + &data, static_cast(i), 50), + grpc_stats_histo_percentile( + &data, static_cast(i), 95), + grpc_stats_histo_percentile( + &data, static_cast(i), 99)); } } diff --git a/test/cpp/util/proto_reflection_descriptor_database.cc b/test/cpp/util/proto_reflection_descriptor_database.cc index 5c0bfb3727..0adbf20ce6 100644 --- a/test/cpp/util/proto_reflection_descriptor_database.cc +++ b/test/cpp/util/proto_reflection_descriptor_database.cc @@ -50,7 +50,8 @@ ProtoReflectionDescriptorDatabase::~ProtoReflectionDescriptorDatabase() { } gpr_log(GPR_INFO, "ServerReflectionInfo rpc failed. Error code: %d, details: %s", - static_cast(status.error_code()), status.error_message().c_str()); + static_cast(status.error_code()), + status.error_message().c_str()); } } } -- cgit v1.2.3