From 1e25193d242000bebb016ecb986f6a988abf949a Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap <139093547+tanvi-jagtap@users.noreply.github.com> Date: Mon, 29 Apr 2024 22:18:25 -0700 Subject: [PATCH] [grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT (#36470) [grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT Replacing GPR_ASSERT with absl CHECK. These changes have been made using string replacement and regex. Will not be replacing all instances of CHECK with CHECK_EQ , CHECK_NE etc because there are too many callsites. Only ones which are doable using very simple regex with least chance of failure will be replaced. Given that we have 5000+ instances of GPR_ASSERT to edit, Doing it manually is too much work for both the author and reviewer. Closes #36470 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36470 from tanvi-jagtap:tjagtap_src_core_lib_iomgr 1f209b3cf03d70af4a6b5caa556bfbc3aa91d168 PiperOrigin-RevId: 629292757 --- BUILD | 8 +- CMakeLists.txt | 7 ++ build_autogenerated.yaml | 7 ++ src/core/BUILD | 9 ++- src/core/lib/iomgr/call_combiner.cc | 6 +- src/core/lib/iomgr/closure.h | 4 +- src/core/lib/iomgr/combiner.cc | 10 ++- src/core/lib/iomgr/endpoint_cfstream.cc | 12 +-- src/core/lib/iomgr/endpoint_pair_posix.cc | 9 ++- src/core/lib/iomgr/endpoint_pair_windows.cc | 21 ++--- src/core/lib/iomgr/error.cc | 3 +- src/core/lib/iomgr/error.h | 3 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 26 +++--- src/core/lib/iomgr/ev_poll_posix.cc | 17 ++-- .../lib/iomgr/event_engine_shims/endpoint.cc | 3 +- src/core/lib/iomgr/exec_ctx.cc | 7 +- src/core/lib/iomgr/exec_ctx.h | 6 +- src/core/lib/iomgr/executor.cc | 12 +-- src/core/lib/iomgr/iocp_windows.cc | 15 ++-- src/core/lib/iomgr/iomgr_windows.cc | 6 +- src/core/lib/iomgr/lockfree_event.cc | 4 +- src/core/lib/iomgr/polling_entity.cc | 7 +- src/core/lib/iomgr/sockaddr_utils_posix.cc | 4 +- .../lib/iomgr/socket_utils_common_posix.cc | 4 +- src/core/lib/iomgr/socket_windows.cc | 7 +- src/core/lib/iomgr/tcp_client_posix.cc | 9 ++- src/core/lib/iomgr/tcp_client_windows.cc | 8 +- src/core/lib/iomgr/tcp_posix.cc | 80 ++++++++++--------- src/core/lib/iomgr/tcp_server_posix.cc | 43 +++++----- .../iomgr/tcp_server_utils_posix_common.cc | 9 ++- .../iomgr/tcp_server_utils_posix_ifaddrs.cc | 3 +- src/core/lib/iomgr/tcp_server_windows.cc | 29 +++---- src/core/lib/iomgr/tcp_windows.cc | 14 ++-- src/core/lib/iomgr/timer_generic.cc | 3 +- src/core/lib/iomgr/timer_manager.cc | 4 +- src/core/lib/iomgr/unix_sockets_posix.cc | 3 +- src/core/lib/iomgr/unix_sockets_posix_noop.cc | 4 +- 37 files changed, 251 insertions(+), 175 deletions(-) diff --git a/BUILD b/BUILD index c3d119e0916..0467fbb6f6d 100644 --- a/BUILD +++ b/BUILD @@ -1423,6 +1423,7 @@ grpc_cc_library( ], external_deps = [ "absl/container:inlined_vector", + "absl/log:check", ], language = "c++", deps = [ @@ -1624,6 +1625,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/container:flat_hash_set", "absl/functional:any_invocable", + "absl/log:check", "absl/status", "absl/status:statusor", "absl/strings", @@ -3172,7 +3174,10 @@ grpc_cc_library( "//src/core:lib/iomgr/executor.h", "//src/core:lib/iomgr/iomgr_internal.h", ], - external_deps = ["absl/strings:str_format"], + external_deps = [ + "absl/log:check", + "absl/strings:str_format", + ], visibility = [ "@grpc:alt_grpc_base_legacy", "@grpc:exec_ctx", @@ -3234,6 +3239,7 @@ grpc_cc_library( "//src/core:lib/iomgr/iomgr.h", ], external_deps = [ + "absl/log:check", "absl/strings", "absl/strings:str_format", ], diff --git a/CMakeLists.txt b/CMakeLists.txt index 7df7c227294..ba84f779a5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8582,6 +8582,7 @@ target_link_libraries(call_filters_test absl::inlined_vector absl::function_ref absl::hash + absl::check absl::type_traits absl::statusor absl::utility @@ -10242,6 +10243,7 @@ target_link_libraries(chunked_vector_test absl::config absl::function_ref absl::hash + absl::check absl::type_traits absl::statusor gpr @@ -13385,6 +13387,7 @@ target_link_libraries(exec_ctx_wakeup_scheduler_test upb_message_lib absl::config absl::hash + absl::check absl::type_traits absl::statusor gpr @@ -14340,6 +14343,7 @@ target_link_libraries(for_each_test absl::config absl::function_ref absl::hash + absl::check absl::type_traits absl::statusor gpr @@ -18093,6 +18097,7 @@ target_link_libraries(interceptor_list_test absl::config absl::function_ref absl::hash + absl::check absl::type_traits absl::statusor gpr @@ -19286,6 +19291,7 @@ target_link_libraries(map_pipe_test absl::config absl::function_ref absl::hash + absl::check absl::type_traits absl::statusor gpr @@ -21549,6 +21555,7 @@ target_link_libraries(periodic_update_test upb_message_lib absl::function_ref absl::hash + absl::check absl::statusor gpr ) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index dbcec3cf033..e80fe8207be 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -6524,6 +6524,7 @@ targets: - absl/container:inlined_vector - absl/functional:function_ref - absl/hash:hash + - absl/log:check - absl/meta:type_traits - absl/status:statusor - absl/utility:utility @@ -7778,6 +7779,7 @@ targets: - absl/base:config - absl/functional:function_ref - absl/hash:hash + - absl/log:check - absl/meta:type_traits - absl/status:statusor - gpr @@ -9259,6 +9261,7 @@ targets: - upb_message_lib - absl/base:config - absl/hash:hash + - absl/log:check - absl/meta:type_traits - absl/status:statusor - gpr @@ -10037,6 +10040,7 @@ targets: - absl/base:config - absl/functional:function_ref - absl/hash:hash + - absl/log:check - absl/meta:type_traits - absl/status:statusor - gpr @@ -12291,6 +12295,7 @@ targets: - absl/base:config - absl/functional:function_ref - absl/hash:hash + - absl/log:check - absl/meta:type_traits - absl/status:statusor - gpr @@ -12974,6 +12979,7 @@ targets: - absl/base:config - absl/functional:function_ref - absl/hash:hash + - absl/log:check - absl/meta:type_traits - absl/status:statusor - gpr @@ -14174,6 +14180,7 @@ targets: - upb_message_lib - absl/functional:function_ref - absl/hash:hash + - absl/log:check - absl/status:statusor - gpr uses_polling: false diff --git a/src/core/BUILD b/src/core/BUILD index 49e3acb72db..8500fd11b66 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -1564,6 +1564,7 @@ grpc_cc_library( "lib/iomgr/error.h", ], external_deps = [ + "absl/log:check", "absl/status", "absl/strings:str_format", ], @@ -1589,7 +1590,10 @@ grpc_cc_library( hdrs = [ "lib/iomgr/closure.h", ], - external_deps = ["absl/strings:str_format"], + external_deps = [ + "absl/log:check", + "absl/strings:str_format", + ], visibility = ["@grpc:alt_grpc_base_legacy"], deps = [ "error", @@ -1648,6 +1652,9 @@ grpc_cc_library( "lib/iomgr/sockaddr_windows.h", "lib/iomgr/socket_utils.h", ], + external_deps = [ + "absl/log:check", + ], deps = [ "iomgr_port", "//:gpr", diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index cffff2a3979..6c44bdb0650 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -86,7 +88,7 @@ void CallCombiner::TsanClosure(void* arg, grpc_error_handle error) { if (lock != nullptr) { TSAN_ANNOTATE_RWLOCK_RELEASED(&lock->taken, true); bool prev = true; - GPR_ASSERT(lock->taken.compare_exchange_strong(prev, false)); + CHECK(lock->taken.compare_exchange_strong(prev, false)); } } #endif @@ -154,7 +156,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) { gpr_log(GPR_INFO, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, prev_size - 1); } - GPR_ASSERT(prev_size >= 1); + CHECK_GE(prev_size, 1u); if (prev_size > 1) { while (true) { if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) { diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index 674f6c0a2f7..caf84fe30df 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -297,7 +299,7 @@ class Closure { closure, closure->file_created, closure->line_created, location.file(), location.line()); } - GPR_ASSERT(closure->cb != nullptr); + CHECK_NE(closure->cb, nullptr); #endif closure->cb(closure->cb_arg, error); #ifndef NDEBUG diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 9f58920267d..eb36799e215 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -64,7 +66,7 @@ grpc_core::Combiner* grpc_combiner_create( static void really_destroy(grpc_core::Combiner* lock) { GRPC_COMBINER_TRACE(gpr_log(GPR_INFO, "C:%p really_destroy", lock)); - GPR_ASSERT(gpr_atm_no_barrier_load(&lock->state) == 0); + CHECK_EQ(gpr_atm_no_barrier_load(&lock->state), 0); delete lock; } @@ -148,7 +150,7 @@ static void combiner_exec(grpc_core::Combiner* lock, grpc_closure* cl, gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, 0); } } - GPR_ASSERT(last & STATE_UNORPHANED); // ensure lock has not been destroyed + CHECK(last & STATE_UNORPHANED); // ensure lock has not been destroyed assert(cl->cb); cl->error_data.error = grpc_core::internal::StatusAllocHeapPtr(error); lock->queue.Push(cl->next_data.mpscq_node.get()); @@ -230,7 +232,7 @@ bool grpc_combiner_continue_exec_ctx() { cl->cb(cl->cb_arg, std::move(cl_err)); } else { grpc_closure* c = lock->final_list.head; - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); grpc_closure_list_init(&lock->final_list); int loops = 0; while (c != nullptr) { @@ -293,7 +295,7 @@ static void enqueue_finally(void* closure, grpc_error_handle error); static void combiner_finally_exec(grpc_core::Combiner* lock, grpc_closure* closure, grpc_error_handle error) { - GPR_ASSERT(lock != nullptr); + CHECK_NE(lock, nullptr); GRPC_COMBINER_TRACE(gpr_log( GPR_INFO, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, closure, grpc_core::ExecCtx::Get()->combiner_data()->active_combiner)); diff --git a/src/core/lib/iomgr/endpoint_cfstream.cc b/src/core/lib/iomgr/endpoint_cfstream.cc index 673a0b9f368..bdbbfc04861 100644 --- a/src/core/lib/iomgr/endpoint_cfstream.cc +++ b/src/core/lib/iomgr/endpoint_cfstream.cc @@ -24,6 +24,8 @@ #import +#include "absl/log/check.h" + #include #include #include @@ -150,7 +152,7 @@ static void CallWriteCb(CFStreamEndpoint* ep, grpc_error_handle error) { static void ReadAction(void* arg, grpc_error_handle error) { CFStreamEndpoint* ep = static_cast(arg); - GPR_ASSERT(ep->read_cb != nullptr); + CHECK_NE(ep->read_cb, nullptr); if (!error.ok()) { grpc_slice_buffer_reset_and_unref(ep->read_slices); CallReadCb(ep, error); @@ -158,7 +160,7 @@ static void ReadAction(void* arg, grpc_error_handle error) { return; } - GPR_ASSERT(ep->read_slices->count == 1); + CHECK_EQ(ep->read_slices->count, 1); grpc_slice slice = ep->read_slices->slices[0]; size_t len = GRPC_SLICE_LENGTH(slice); CFIndex read_size = @@ -191,7 +193,7 @@ static void ReadAction(void* arg, grpc_error_handle error) { static void WriteAction(void* arg, grpc_error_handle error) { CFStreamEndpoint* ep = static_cast(arg); - GPR_ASSERT(ep->write_cb != nullptr); + CHECK_NE(ep->write_cb, nullptr); if (!error.ok()) { grpc_slice_buffer_reset_and_unref(ep->write_slices); CallWriteCb(ep, error); @@ -247,7 +249,7 @@ static void CFStreamRead(grpc_endpoint* ep, grpc_slice_buffer* slices, gpr_log(GPR_DEBUG, "CFStream endpoint:%p read (%p, %p) length:%zu", ep_impl, slices, cb, slices->length); } - GPR_ASSERT(ep_impl->read_cb == nullptr); + CHECK_EQ(ep_impl->read_cb, nullptr); ep_impl->read_cb = cb; ep_impl->read_slices = slices; grpc_slice_buffer_reset_and_unref(slices); @@ -265,7 +267,7 @@ static void CFStreamWrite(grpc_endpoint* ep, grpc_slice_buffer* slices, gpr_log(GPR_DEBUG, "CFStream endpoint:%p write (%p, %p) length:%zu", ep_impl, slices, cb, slices->length); } - GPR_ASSERT(ep_impl->write_cb == nullptr); + CHECK_EQ(ep_impl->write_cb, nullptr); ep_impl->write_cb = cb; ep_impl->write_slices = slices; EP_REF(ep_impl, "write"); diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index b977c0d9e62..3c45720785e 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -30,6 +30,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include @@ -48,11 +49,11 @@ static void create_sockets(int sv[2]) { int flags; grpc_create_socketpair_if_unix(sv); flags = fcntl(sv[0], F_GETFL, 0); - GPR_ASSERT(fcntl(sv[0], F_SETFL, flags | O_NONBLOCK) == 0); + CHECK_EQ(fcntl(sv[0], F_SETFL, flags | O_NONBLOCK), 0); flags = fcntl(sv[1], F_GETFL, 0); - GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0); - GPR_ASSERT(grpc_set_socket_no_sigpipe_if_possible(sv[0]) == absl::OkStatus()); - GPR_ASSERT(grpc_set_socket_no_sigpipe_if_possible(sv[1]) == absl::OkStatus()); + CHECK_EQ(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK), 0); + CHECK(grpc_set_socket_no_sigpipe_if_possible(sv[0]) == absl::OkStatus()); + CHECK(grpc_set_socket_no_sigpipe_if_possible(sv[1]) == absl::OkStatus()); } grpc_endpoint_pair grpc_iomgr_create_endpoint_pair( diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index 97e46410da2..729ab575c77 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -25,6 +25,8 @@ #include #include +#include "absl/log/check.h" + #include #include "src/core/lib/address_utils/sockaddr_utils.h" @@ -43,25 +45,24 @@ static void create_sockets(SOCKET sv[2]) { lst_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, grpc_get_default_wsa_socket_flags()); - GPR_ASSERT(lst_sock != INVALID_SOCKET); + CHECK(lst_sock != INVALID_SOCKET); memset(&addr, 0, sizeof(addr)); addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_family = AF_INET; - GPR_ASSERT(bind(lst_sock, (grpc_sockaddr*)&addr, sizeof(addr)) != - SOCKET_ERROR); - GPR_ASSERT(listen(lst_sock, SOMAXCONN) != SOCKET_ERROR); - GPR_ASSERT(getsockname(lst_sock, (grpc_sockaddr*)&addr, &addr_len) != - SOCKET_ERROR); + CHECK(bind(lst_sock, (grpc_sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR); + CHECK(listen(lst_sock, SOMAXCONN) != SOCKET_ERROR); + CHECK(getsockname(lst_sock, (grpc_sockaddr*)&addr, &addr_len) != + SOCKET_ERROR); cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, grpc_get_default_wsa_socket_flags()); - GPR_ASSERT(cli_sock != INVALID_SOCKET); + CHECK(cli_sock != INVALID_SOCKET); - GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, - NULL, NULL) == 0); + CHECK(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, NULL, + NULL) == 0); svr_sock = accept(lst_sock, (grpc_sockaddr*)&addr, &addr_len); - GPR_ASSERT(svr_sock != INVALID_SOCKET); + CHECK(svr_sock != INVALID_SOCKET); closesocket(lst_sock); grpc_error_handle error = grpc_tcp_prepare_socket(cli_sock); diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 7e26e3d5c14..95ea6c9c8d0 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include @@ -227,7 +228,7 @@ grpc_error_handle grpc_error_add_child(grpc_error_handle src, bool grpc_log_error(const char* what, grpc_error_handle error, const char* file, int line) { - GPR_DEBUG_ASSERT(!error.ok()); + DCHECK(!error.ok()); gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "%s: %s", what, grpc_core::StatusToString(error).c_str()); return false; diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 887424cbc73..66d7c552211 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -22,6 +22,7 @@ #include #include +#include "absl/log/check.h" #include "absl/status/status.h" #include @@ -74,7 +75,7 @@ absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err, const char* call_name); inline absl::Status grpc_assert_never_ok(absl::Status error) { - GPR_ASSERT(!error.ok()); + CHECK(!error.ok()); return error; } diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index f5fd5fc95fa..c36f3833d9f 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -16,6 +16,8 @@ // // +#include "absl/log/check.h" + #include #include @@ -634,8 +636,8 @@ static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { } static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - GPR_ASSERT(pollset->shutdown_closure == nullptr); - GPR_ASSERT(!pollset->shutting_down); + CHECK_EQ(pollset->shutdown_closure, nullptr); + CHECK(!pollset->shutting_down); pollset->shutdown_closure = closure; pollset->shutting_down = true; GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(pollset)); @@ -806,7 +808,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, } } if (is_reassigning) { - GPR_ASSERT(pollset->reassigning_neighborhood); + CHECK(pollset->reassigning_neighborhood); pollset->reassigning_neighborhood = false; } gpr_mu_unlock(&neighborhood->mu); @@ -815,7 +817,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, worker_insert(pollset, worker); pollset->begin_refs--; if (worker->state == UNKICKED && !pollset->kicked_without_poller) { - GPR_ASSERT(gpr_atm_no_barrier_load(&g_active_poller) != (gpr_atm)worker); + CHECK(gpr_atm_no_barrier_load(&g_active_poller) != (gpr_atm)worker); worker->initialized_cv = true; gpr_cv_init(&worker->cv); while (worker->state == UNKICKED && !pollset->shutting_down) { @@ -870,7 +872,7 @@ static bool check_neighborhood_for_available_poller( break; } gpr_mu_lock(&inspect->mu); - GPR_ASSERT(!inspect->seen_inactive); + CHECK(!inspect->seen_inactive); grpc_pollset_worker* inspect_worker = inspect->root_worker; if (inspect_worker != nullptr) { do { @@ -939,7 +941,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, " .. choose next poller to be peer %p", worker); } - GPR_ASSERT(worker->next->initialized_cv); + CHECK(worker->next->initialized_cv); gpr_atm_no_barrier_store(&g_active_poller, (gpr_atm)worker->next); SET_KICK_STATE(worker->next, DESIGNATED_POLLER); gpr_cv_signal(&worker->next->cv); @@ -993,7 +995,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, if (EMPTIED == worker_remove(pollset, worker)) { pollset_maybe_finish_shutdown(pollset); } - GPR_ASSERT(gpr_atm_no_barrier_load(&g_active_poller) != (gpr_atm)worker); + CHECK(gpr_atm_no_barrier_load(&g_active_poller) != (gpr_atm)worker); } // pollset->po.mu lock must be held by the caller before calling this. @@ -1014,8 +1016,8 @@ static grpc_error_handle pollset_work(grpc_pollset* ps, if (begin_worker(ps, &worker, worker_hdl, deadline)) { g_current_thread_pollset = ps; g_current_thread_worker = &worker; - GPR_ASSERT(!ps->shutting_down); - GPR_ASSERT(!ps->seen_inactive); + CHECK(!ps->shutting_down); + CHECK(!ps->seen_inactive); gpr_mu_unlock(&ps->mu); // unlock // This is the designated polling thread at this point and should ideally do @@ -1111,7 +1113,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) { gpr_log(GPR_INFO, " .. kicked %p", next_worker); } - GPR_ASSERT(next_worker->initialized_cv); + CHECK(next_worker->initialized_cv); SET_KICK_STATE(next_worker, KICKED); gpr_cv_signal(&next_worker->cv); goto done; @@ -1138,7 +1140,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset, goto done; } } else { - GPR_ASSERT(next_worker->state == KICKED); + CHECK(next_worker->state == KICKED); SET_KICK_STATE(next_worker, KICKED); goto done; } @@ -1278,7 +1280,7 @@ const grpc_event_engine_vtable grpc_ev_epoll1_posix = { /* check_engine_available = */ [](bool) { return init_epoll1_linux(); }, /* init_engine = */ - []() { GPR_ASSERT(init_epoll1_linux()); }, + []() { CHECK(init_epoll1_linux()); }, shutdown_background_closure, /* shutdown_engine = */ []() { shutdown_engine(); }, diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 730eda75097..f4c417f7e0a 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -33,6 +33,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -340,7 +341,7 @@ static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, } while (0) static void ref_by(grpc_fd* fd, int n) { #endif - GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0); + CHECK_GT(gpr_atm_no_barrier_fetch_add(&fd->refst, n), 0); } #ifndef NDEBUG @@ -365,14 +366,14 @@ static void unref_by(grpc_fd* fd, int n) { fd->shutdown_error.~Status(); gpr_free(fd); } else { - GPR_ASSERT(old > n); + CHECK(old > n); } } static grpc_fd* fd_create(int fd, const char* name, bool track_err) { // Avoid unused-parameter warning for debug-only parameter (void)track_err; - GPR_DEBUG_ASSERT(track_err == false); + DCHECK(track_err == false); grpc_fd* r = static_cast(gpr_malloc(sizeof(*r))); gpr_mu_init(&r->mu); gpr_atm_rel_store(&r->refst, 1); @@ -402,7 +403,7 @@ static bool fd_is_orphaned(grpc_fd* fd) { static grpc_error_handle pollset_kick_locked(grpc_fd_watcher* watcher) { gpr_mu_lock(&watcher->pollset->mu); - GPR_ASSERT(watcher->worker); + CHECK(watcher->worker); grpc_error_handle err = pollset_kick_ext(watcher->pollset, watcher->worker, GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP); @@ -778,7 +779,7 @@ static grpc_error_handle pollset_kick_ext(grpc_pollset* p, // pollset->mu already held if (specific_worker != nullptr) { if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) { - GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0); + CHECK_EQ((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP), 0u); for (specific_worker = p->root_worker.next; specific_worker != &p->root_worker; specific_worker = specific_worker->next) { @@ -802,7 +803,7 @@ static grpc_error_handle pollset_kick_ext(grpc_pollset* p, grpc_wakeup_fd_wakeup(&specific_worker->wakeup_fd->fd)); } } else if (g_current_thread_poller != p) { - GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0); + CHECK_EQ((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP), 0u); specific_worker = pop_front_worker(p); if (specific_worker != nullptr) { if (g_current_thread_worker == specific_worker) { @@ -855,7 +856,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { } static void pollset_destroy(grpc_pollset* pollset) { - GPR_ASSERT(!pollset_has_workers(pollset)); + CHECK(!pollset_has_workers(pollset)); while (pollset->local_wakeup_cache) { grpc_cached_wakeup_fd* next = pollset->local_wakeup_cache->next; fork_fd_list_remove_node(pollset->local_wakeup_cache->fork_fd_list); @@ -1137,7 +1138,7 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset, } static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - GPR_ASSERT(!pollset->shutting_down); + CHECK(!pollset->shutting_down); pollset->shutting_down = 1; pollset->shutdown_done = closure; (void)pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); diff --git a/src/core/lib/iomgr/event_engine_shims/endpoint.cc b/src/core/lib/iomgr/event_engine_shims/endpoint.cc index 9b64e411f91..42bb4de4ace 100644 --- a/src/core/lib/iomgr/event_engine_shims/endpoint.cc +++ b/src/core/lib/iomgr/event_engine_shims/endpoint.cc @@ -18,6 +18,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" @@ -431,7 +432,7 @@ EventEngineEndpointWrapper::EventEngineEndpointWrapper( grpc_endpoint* grpc_event_engine_endpoint_create( std::unique_ptr ee_endpoint) { - GPR_DEBUG_ASSERT(ee_endpoint != nullptr); + DCHECK(ee_endpoint != nullptr); auto wrapper = new EventEngineEndpointWrapper(std::move(ee_endpoint)); return wrapper->GetGrpcEndpoint(); } diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 3857e9d61d6..66653a0c15c 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -18,6 +18,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include @@ -87,7 +88,7 @@ bool ExecCtx::Flush() { break; } } - GPR_ASSERT(combiner_data_.active_combiner == nullptr); + CHECK_EQ(combiner_data_.active_combiner, nullptr); return did_something; } @@ -110,7 +111,7 @@ void ExecCtx::Run(const DebugLocation& location, grpc_closure* closure, closure->file_initiated = location.file(); closure->line_initiated = location.line(); closure->run = false; - GPR_ASSERT(closure->cb != nullptr); + CHECK_NE(closure->cb, nullptr); #endif closure->error_data.error = internal::StatusAllocHeapPtr(error); exec_ctx_sched(closure); @@ -133,7 +134,7 @@ void ExecCtx::RunList(const DebugLocation& location, grpc_closure_list* list) { c->file_initiated = location.file(); c->line_initiated = location.line(); c->run = false; - GPR_ASSERT(c->cb != nullptr); + CHECK_NE(c->cb, nullptr); #endif exec_ctx_sched(c); c = next; diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index 6f7bdf08323..c4932db76bf 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -28,6 +28,8 @@ #include #endif +#include "absl/log/check.h" + #include #include #include @@ -314,8 +316,8 @@ class GRPC_DLL ApplicationCallbackExecCtx { Fork::DecExecCtxCount(); } } else { - GPR_DEBUG_ASSERT(head_ == nullptr); - GPR_DEBUG_ASSERT(tail_ == nullptr); + DCHECK_EQ(head_, nullptr); + DCHECK_EQ(tail_, nullptr); } } diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index e9baef7c5aa..6144b6128f1 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -146,7 +148,7 @@ void Executor::SetThreading(bool threading) { return; } - GPR_ASSERT(num_threads_ == 0); + CHECK_EQ(num_threads_, 0); gpr_atm_rel_store(&num_threads_, 1); thd_state_ = static_cast( gpr_zalloc(sizeof(ThreadState) * max_threads_)); @@ -370,8 +372,7 @@ void Executor::InitAll() { // Return if Executor::InitAll() is already called earlier if (executors[static_cast(ExecutorType::DEFAULT)] != nullptr) { - GPR_ASSERT(executors[static_cast(ExecutorType::RESOLVER)] != - nullptr); + CHECK(executors[static_cast(ExecutorType::RESOLVER)] != nullptr); return; } @@ -397,8 +398,7 @@ void Executor::ShutdownAll() { // Return if Executor:SshutdownAll() is already called earlier if (executors[static_cast(ExecutorType::DEFAULT)] == nullptr) { - GPR_ASSERT(executors[static_cast(ExecutorType::RESOLVER)] == - nullptr); + CHECK(executors[static_cast(ExecutorType::RESOLVER)] == nullptr); return; } @@ -426,7 +426,7 @@ void Executor::ShutdownAll() { } bool Executor::IsThreaded(ExecutorType executor_type) { - GPR_ASSERT(executor_type < ExecutorType::NUM_EXECUTORS); + CHECK(executor_type < ExecutorType::NUM_EXECUTORS); return executors[static_cast(executor_type)]->IsThreaded(); } diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 5b94fbb334d..0353aa7614a 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -26,6 +26,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -73,7 +75,8 @@ grpc_iocp_work_status grpc_iocp_work(grpc_core::Timestamp deadline) { if (success == 0 && overlapped == NULL) { return GRPC_IOCP_WORK_TIMEOUT; } - GPR_ASSERT(completion_key && overlapped); + CHECK(completion_key); + CHECK(overlapped); if (overlapped == &g_iocp_custom_overlap) { gpr_atm_full_fetch_add(&g_custom_events, -1); if (completion_key == (ULONG_PTR)&g_iocp_kick_token) { @@ -101,7 +104,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_core::Timestamp deadline) { info->bytes_transferred = bytes; info->wsa_error = success ? 0 : WSAGetLastError(); } - GPR_ASSERT(overlapped == &info->overlapped); + CHECK(overlapped == &info->overlapped); bool should_destroy = grpc_socket_become_ready(socket, info); gpr_mu_unlock(&socket->state_mu); if (should_destroy) { @@ -113,7 +116,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_core::Timestamp deadline) { void grpc_iocp_init(void) { g_iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)NULL, 0); - GPR_ASSERT(g_iocp); + CHECK(g_iocp); } void grpc_iocp_kick(void) { @@ -122,7 +125,7 @@ void grpc_iocp_kick(void) { gpr_atm_full_fetch_add(&g_custom_events, 1); success = PostQueuedCompletionStatus(g_iocp, 0, (ULONG_PTR)&g_iocp_kick_token, &g_iocp_custom_overlap); - GPR_ASSERT(success); + CHECK(success); } void grpc_iocp_flush(void) { @@ -144,7 +147,7 @@ void grpc_iocp_shutdown(void) { grpc_core::ExecCtx::Get()->Flush(); } - GPR_ASSERT(CloseHandle(g_iocp)); + CHECK(CloseHandle(g_iocp)); } void grpc_iocp_add_socket(grpc_winsocket* socket) { @@ -160,7 +163,7 @@ void grpc_iocp_add_socket(grpc_winsocket* socket) { abort(); } socket->added_to_iocp = 1; - GPR_ASSERT(ret == g_iocp); + CHECK(ret == g_iocp); } void grpc_iocp_register_socket_shutdown_socket_locked(grpc_winsocket* socket) { diff --git a/src/core/lib/iomgr/iomgr_windows.cc b/src/core/lib/iomgr/iomgr_windows.cc index 29bb9ea4711..21570d9033f 100644 --- a/src/core/lib/iomgr/iomgr_windows.cc +++ b/src/core/lib/iomgr/iomgr_windows.cc @@ -22,6 +22,8 @@ #ifdef GRPC_WINSOCK_SOCKET +#include "absl/log/check.h" + #include #include "src/core/lib/experiments/experiments.h" @@ -51,12 +53,12 @@ extern grpc_pollset_set_vtable grpc_windows_pollset_set_vtable; static void winsock_init(void) { WSADATA wsaData; int status = WSAStartup(MAKEWORD(2, 0), &wsaData); - GPR_ASSERT(status == 0); + CHECK_EQ(status, 0); } static void winsock_shutdown(void) { int status = WSACleanup(); - GPR_ASSERT(status == 0); + CHECK_EQ(status, 0); } static void iomgr_platform_init(void) { diff --git a/src/core/lib/iomgr/lockfree_event.cc b/src/core/lib/iomgr/lockfree_event.cc index 4d84704b6f1..114625e5e79 100644 --- a/src/core/lib/iomgr/lockfree_event.cc +++ b/src/core/lib/iomgr/lockfree_event.cc @@ -18,6 +18,8 @@ #include "src/core/lib/iomgr/lockfree_event.h" +#include "absl/log/check.h" + #include #include @@ -79,7 +81,7 @@ void LockfreeEvent::DestroyEvent() { if (curr & kShutdownBit) { internal::StatusFreeHeapPtr(curr & ~kShutdownBit); } else { - GPR_ASSERT(curr == kClosureNotReady || curr == kClosureReady); + CHECK(curr == kClosureNotReady || curr == kClosureReady); } // we CAS in a shutdown, no error value here. If this event is interacted // with post-deletion (see the note in the constructor) we want the bit diff --git a/src/core/lib/iomgr/polling_entity.cc b/src/core/lib/iomgr/polling_entity.cc index 7bd4d2e1726..42233112c15 100644 --- a/src/core/lib/iomgr/polling_entity.cc +++ b/src/core/lib/iomgr/polling_entity.cc @@ -18,6 +18,7 @@ #include "src/core/lib/iomgr/polling_entity.h" +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include @@ -70,7 +71,7 @@ void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent, grpc_pollset_set_add_pollset(pss_dst, pollent->pollent.pollset); } } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { - GPR_ASSERT(pollent->pollent.pollset_set != nullptr); + CHECK_NE(pollent->pollent.pollset_set, nullptr); grpc_pollset_set_add_pollset_set(pss_dst, pollent->pollent.pollset_set); } else { grpc_core::Crash( @@ -86,11 +87,11 @@ void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent, grpc_pollset_set_del_pollset(pss_dst, pollent->pollent.pollset); } #else - GPR_ASSERT(pollent->pollent.pollset != nullptr); + CHECK_NE(pollent->pollent.pollset, nullptr); grpc_pollset_set_del_pollset(pss_dst, pollent->pollent.pollset); #endif } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { - GPR_ASSERT(pollent->pollent.pollset_set != nullptr); + CHECK_NE(pollent->pollent.pollset_set, nullptr); grpc_pollset_set_del_pollset_set(pss_dst, pollent->pollent.pollset_set); } else { grpc_core::Crash( diff --git a/src/core/lib/iomgr/sockaddr_utils_posix.cc b/src/core/lib/iomgr/sockaddr_utils_posix.cc index f0535f45acf..d1981a43196 100644 --- a/src/core/lib/iomgr/sockaddr_utils_posix.cc +++ b/src/core/lib/iomgr/sockaddr_utils_posix.cc @@ -37,6 +37,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -57,7 +59,7 @@ int grpc_inet_pton(int af, const char* src, void* dst) { } const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { - GPR_ASSERT(size <= (socklen_t)-1); + CHECK(size <= (socklen_t)-1); return inet_ntop(af, src, dst, static_cast(size)); } diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 199eb75f812..2def9576b0c 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -43,6 +43,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -418,7 +420,7 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout( // set a socket using a grpc_socket_mutator grpc_error_handle grpc_set_socket_with_mutator(int fd, grpc_fd_usage usage, grpc_socket_mutator* mutator) { - GPR_ASSERT(mutator); + CHECK(mutator); if (!grpc_socket_mutator_mutate_fd(mutator, fd, usage)) { return GRPC_ERROR_CREATE("grpc_socket_mutator failed."); } diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index a3df988a265..fc2cdc97407 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -27,6 +27,7 @@ // must be included after winsock2.h #include +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include @@ -159,7 +160,7 @@ void grpc_winsocket_finish(grpc_winsocket* winsocket) { void grpc_winsocket_destroy(grpc_winsocket* winsocket) { gpr_mu_lock(&winsocket->state_mu); - GPR_ASSERT(!winsocket->destroy_called); + CHECK(!winsocket->destroy_called); winsocket->destroy_called = true; bool should_destroy = check_destroyable(winsocket); gpr_mu_unlock(&winsocket->state_mu); @@ -174,7 +175,7 @@ void grpc_winsocket_destroy(grpc_winsocket* winsocket) { //-) The IOCP hasn't completed yet, and we're queuing it for later. static void socket_notify_on_iocp(grpc_winsocket* socket, grpc_closure* closure, grpc_winsocket_callback_info* info) { - GPR_ASSERT(info->closure == NULL); + CHECK(info->closure == NULL); gpr_mu_lock(&socket->state_mu); if (info->has_pending_iocp) { info->has_pending_iocp = 0; @@ -196,7 +197,7 @@ void grpc_socket_notify_on_read(grpc_winsocket* socket, grpc_closure* closure) { bool grpc_socket_become_ready(grpc_winsocket* socket, grpc_winsocket_callback_info* info) { - GPR_ASSERT(!info->has_pending_iocp); + CHECK(!info->has_pending_iocp); if (info->closure) { // Only run the closure once at shutdown. if (!info->closure_already_executed_at_shutdown) { diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 60a2cd58144..22ecb3e1ef0 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -29,6 +29,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include @@ -102,7 +103,7 @@ static grpc_error_handle prepare_socket( const grpc_core::PosixTcpOptions& options) { grpc_error_handle err; - GPR_ASSERT(fd >= 0); + CHECK_GE(fd, 0); err = grpc_set_socket_nonblocking(fd, 1); if (!err.ok()) goto error; @@ -187,7 +188,7 @@ static void on_writable(void* acp, grpc_error_handle error) { } gpr_mu_lock(&ac->mu); - GPR_ASSERT(ac->fd); + CHECK(ac->fd); fd = ac->fd; ac->fd = nullptr; bool connect_cancelled = ac->connect_cancelled; @@ -274,7 +275,7 @@ finish: std::string str; bool ret = grpc_error_get_str( error, grpc_core::StatusStrProperty::kDescription, &str); - GPR_ASSERT(ret); + CHECK(ret); std::string description = absl::StrCat("Failed to connect to remote host: ", str); error = grpc_error_set_str( @@ -446,7 +447,7 @@ static bool tcp_cancel_connect(int64_t connection_handle) { auto it = shard->pending_connections.find(connection_handle); if (it != shard->pending_connections.end()) { ac = it->second; - GPR_ASSERT(ac != nullptr); + CHECK_NE(ac, nullptr); // Trying to acquire ac->mu here would could cause a deadlock because // the on_writable method tries to acquire the two mutexes used // here in the reverse order. But we dont need to acquire ac->mu before diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index eb174ac0f87..a0589770aac 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -24,6 +24,8 @@ #ifdef GRPC_WINSOCK_SOCKET +#include "absl/log/check.h" + #include #include #include @@ -83,7 +85,7 @@ static void on_alarm(void* acp, grpc_error_handle /* error */) { static void on_connect(void* acp, grpc_error_handle error) { async_connect* ac = (async_connect*)acp; grpc_endpoint** ep = ac->endpoint; - GPR_ASSERT(*ep == NULL); + CHECK(*ep == NULL); grpc_closure* on_done = ac->on_done; gpr_mu_lock(&ac->mu); @@ -102,7 +104,7 @@ static void on_connect(void* acp, grpc_error_handle error) { BOOL wsa_success = WSAGetOverlappedResult(socket->socket, &socket->write_info.overlapped, &transfered_bytes, FALSE, &flags); - GPR_ASSERT(transfered_bytes == 0); + CHECK_EQ(transfered_bytes, 0); if (!wsa_success) { error = GRPC_WSA_ERROR(WSAGetLastError(), "ConnectEx"); closesocket(socket->socket); @@ -243,7 +245,7 @@ static int64_t tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint, return 0; failure: - GPR_ASSERT(!error.ok()); + CHECK(!error.ok()); grpc_error_handle final_error = grpc_error_set_str( GRPC_ERROR_CREATE_REFERENCING("Failed to connect", &error, 1), grpc_core::StatusStrProperty::kTargetAddress, diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 74e6a729f4a..880b10c1764 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -45,6 +45,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -158,7 +160,7 @@ class TcpZerocopySendRecord { // sendmsg() failed or when tcp_write() is done. bool Unref() { const intptr_t prior = ref_.fetch_sub(1, std::memory_order_acq_rel); - GPR_DEBUG_ASSERT(prior > 0); + DCHECK_GT(prior, 0); if (prior == 1) { AllSendsComplete(); return true; @@ -173,9 +175,9 @@ class TcpZerocopySendRecord { }; void AssertEmpty() { - GPR_DEBUG_ASSERT(buf_.count == 0); - GPR_DEBUG_ASSERT(buf_.length == 0); - GPR_DEBUG_ASSERT(ref_.load(std::memory_order_relaxed) == 0); + DCHECK_EQ(buf_.count, 0u); + DCHECK_EQ(buf_.length, 0u); + DCHECK_EQ(ref_.load(std::memory_order_relaxed), 0); } // When all sendmsg() calls associated with this tcp_write() have been @@ -183,7 +185,7 @@ class TcpZerocopySendRecord { // for each sendmsg()) and all reference counts have been dropped, drop our // reference to the underlying data since we no longer need it. void AllSendsComplete() { - GPR_DEBUG_ASSERT(ref_.load(std::memory_order_relaxed) == 0); + DCHECK_EQ(ref_.load(std::memory_order_relaxed), 0); grpc_slice_buffer_reset_and_unref(&buf_); } @@ -262,7 +264,7 @@ class TcpZerocopySendCtx { --last_send_; if (ReleaseSendRecord(last_send_)->Unref()) { // We should still be holding the ref taken by tcp_write(). - GPR_DEBUG_ASSERT(0); + DCHECK(0); } } @@ -298,8 +300,8 @@ class TcpZerocopySendCtx { // max_sends_ tcp_write() instances with zerocopy enabled in flight at the // same time. void PutSendRecord(TcpZerocopySendRecord* record) { - GPR_DEBUG_ASSERT(record >= send_records_ && - record < send_records_ + max_sends_); + DCHECK(record >= send_records_); + DCHECK(record < send_records_ + max_sends_); MutexLock guard(&lock_); PutSendRecordLocked(record); } @@ -318,7 +320,7 @@ class TcpZerocopySendCtx { bool enabled() const { return enabled_; } void set_enabled(bool enabled) { - GPR_DEBUG_ASSERT(!enabled || !memory_limited()); + DCHECK(!enabled || !memory_limited()); enabled_ = enabled; } @@ -356,7 +358,7 @@ class TcpZerocopySendCtx { zcopy_enobuf_state_ = OMemState::CHECK; return false; } - GPR_DEBUG_ASSERT(zcopy_enobuf_state_ != OMemState::CHECK); + DCHECK(zcopy_enobuf_state_ != OMemState::CHECK); if (zcopy_enobuf_state_ == OMemState::FULL) { // A previous sendmsg attempt was blocked by ENOBUFS. Return true to // mark the fd as writable so the next write attempt could be made. @@ -430,7 +432,7 @@ class TcpZerocopySendCtx { TcpZerocopySendRecord* ReleaseSendRecordLocked(uint32_t seq) { auto iter = ctx_lookup_.find(seq); - GPR_DEBUG_ASSERT(iter != ctx_lookup_.end()); + DCHECK(iter != ctx_lookup_.end()); TcpZerocopySendRecord* record = iter->second; ctx_lookup_.erase(iter); return record; @@ -448,7 +450,7 @@ class TcpZerocopySendCtx { } void PutSendRecordLocked(TcpZerocopySendRecord* record) { - GPR_DEBUG_ASSERT(free_send_records_size_ < max_sends_); + DCHECK(free_send_records_size_ < max_sends_); free_send_records_[free_send_records_size_] = record; free_send_records_size_++; } @@ -640,7 +642,7 @@ static void run_poller(void* bp, grpc_error_handle /*error_ignored*/) { g_backup_poller_mu->Lock(); // last "uncovered" notification is the ref that keeps us polling if (g_uncovered_notifications_pending == 1) { - GPR_ASSERT(g_backup_poller == p); + CHECK(g_backup_poller == p); g_backup_poller = nullptr; g_uncovered_notifications_pending = 0; g_backup_poller_mu->Unlock(); @@ -668,7 +670,7 @@ static void drop_uncovered(grpc_tcp* /*tcp*/) { p = g_backup_poller; old_count = g_uncovered_notifications_pending--; g_backup_poller_mu->Unlock(); - GPR_ASSERT(old_count > 1); + CHECK_GT(old_count, 1); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { gpr_log(GPR_INFO, "BACKUP_POLLER:%p uncover cnt %d->%d", p, old_count, old_count - 1); @@ -949,8 +951,8 @@ static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error) iov[i].iov_len = GRPC_SLICE_LENGTH(tcp->incoming_buffer->slices[i]); } - GPR_ASSERT(tcp->incoming_buffer->length != 0); - GPR_DEBUG_ASSERT(tcp->min_progress_size > 0); + CHECK_NE(tcp->incoming_buffer->length, 0u); + DCHECK_GT(tcp->min_progress_size, 0); do { // Assume there is something on the queue. If we receive TCP_INQ from @@ -1018,12 +1020,12 @@ static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error) grpc_core::global_stats().IncrementTcpReadSize(read_bytes); add_to_estimate(tcp, static_cast(read_bytes)); - GPR_DEBUG_ASSERT((size_t)read_bytes <= - tcp->incoming_buffer->length - total_read_bytes); + DCHECK((size_t)read_bytes <= + tcp->incoming_buffer->length - total_read_bytes); #ifdef GRPC_HAVE_TCP_INQ if (tcp->inq_capable) { - GPR_DEBUG_ASSERT(!(msg.msg_flags & MSG_CTRUNC)); + DCHECK(!(msg.msg_flags & MSG_CTRUNC)); struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); for (; cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg)) { if (cmsg->cmsg_level == SOL_TCP && cmsg->cmsg_type == TCP_CM_INQ && @@ -1066,7 +1068,7 @@ static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error) finish_estimate(tcp); } - GPR_DEBUG_ASSERT(total_read_bytes > 0); + DCHECK_GT(total_read_bytes, 0u); *error = absl::OkStatus(); if (grpc_core::IsTcpFrameSizeTuningEnabled()) { // Update min progress size based on the total number of bytes read in @@ -1186,7 +1188,7 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error_handle error) { static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer, grpc_closure* cb, bool urgent, int min_progress_size) { grpc_tcp* tcp = reinterpret_cast(ep); - GPR_ASSERT(tcp->read_cb == nullptr); + CHECK_EQ(tcp->read_cb, nullptr); tcp->read_cb = cb; tcp->read_mu.Lock(); tcp->incoming_buffer = incoming_buffer; @@ -1267,8 +1269,8 @@ static TcpZerocopySendRecord* tcp_get_send_zerocopy_record( } if (zerocopy_send_record != nullptr) { zerocopy_send_record->PrepareForSends(buf); - GPR_DEBUG_ASSERT(buf->count == 0); - GPR_DEBUG_ASSERT(buf->length == 0); + DCHECK_EQ(buf->count, 0u); + DCHECK_EQ(buf->length, 0u); tcp->outgoing_byte_idx = 0; tcp->outgoing_buffer = nullptr; } @@ -1330,10 +1332,10 @@ static void UnrefMaybePutZerocopySendRecord(grpc_tcp* tcp, uint32_t seq, const char* tag); // Reads \a cmsg to process zerocopy control messages. static void process_zerocopy(grpc_tcp* tcp, struct cmsghdr* cmsg) { - GPR_DEBUG_ASSERT(cmsg); + DCHECK(cmsg); auto serr = reinterpret_cast(CMSG_DATA(cmsg)); - GPR_DEBUG_ASSERT(serr->ee_errno == 0); - GPR_DEBUG_ASSERT(serr->ee_origin == SO_EE_ORIGIN_ZEROCOPY); + DCHECK_EQ(serr->ee_errno, 0u); + DCHECK(serr->ee_origin == SO_EE_ORIGIN_ZEROCOPY); const uint32_t lo = serr->ee_info; const uint32_t hi = serr->ee_data; for (uint32_t seq = lo; seq <= hi; ++seq) { @@ -1343,7 +1345,7 @@ static void process_zerocopy(grpc_tcp* tcp, struct cmsghdr* cmsg) { // both; if so, batch the unref/put. TcpZerocopySendRecord* record = tcp->tcp_zerocopy_send_ctx.ReleaseSendRecord(seq); - GPR_DEBUG_ASSERT(record); + DCHECK(record); UnrefMaybePutZerocopySendRecord(tcp, record, seq, "CALLBACK RCVD"); } if (tcp->tcp_zerocopy_send_ctx.UpdateZeroCopyOMemStateAfterFree()) { @@ -1538,14 +1540,14 @@ static bool tcp_write_with_timestamps(grpc_tcp* /*tcp*/, struct msghdr* /*msg*/, int* /* saved_errno */, int /*additional_flags*/) { gpr_log(GPR_ERROR, "Write with timestamps not supported for this platform"); - GPR_ASSERT(0); + CHECK(0); return false; } static void tcp_handle_error(void* /*arg*/ /* grpc_tcp */, grpc_error_handle /*error*/) { gpr_log(GPR_ERROR, "Error handling is not supported for this platform"); - GPR_ASSERT(0); + CHECK(0); } #endif // GRPC_LINUX_ERRQUEUE @@ -1584,7 +1586,7 @@ msg_iovlen_type TcpZerocopySendRecord::PopulateIovs(size_t* unwind_slice_idx, ++(out_offset_.slice_idx); out_offset_.byte_idx = 0; } - GPR_DEBUG_ASSERT(iov_size > 0); + DCHECK_GT(iov_size, 0u); return iov_size; } @@ -1739,7 +1741,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error_handle* error) { outgoing_slice_idx++; tcp->outgoing_byte_idx = 0; } - GPR_ASSERT(iov_size > 0); + CHECK_GT(iov_size, 0u); msg.msg_name = nullptr; msg.msg_namelen = 0; @@ -1792,7 +1794,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error_handle* error) { } } - GPR_ASSERT(tcp->outgoing_byte_idx == 0); + CHECK_EQ(tcp->outgoing_byte_idx, 0u); grpc_core::EventLog::Append("tcp-write-outstanding", -sent_length); tcp->bytes_counter += sent_length; trailing = sending_length - static_cast(sent_length); @@ -1844,7 +1846,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, } notify_on_write(tcp); // tcp_flush does not populate error if it has returned false. - GPR_DEBUG_ASSERT(error.ok()); + DCHECK(error.ok()); } else { cb = tcp->write_cb; tcp->write_cb = nullptr; @@ -1880,8 +1882,8 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, } } - GPR_ASSERT(tcp->write_cb == nullptr); - GPR_DEBUG_ASSERT(tcp->current_zerocopy_send == nullptr); + CHECK_EQ(tcp->write_cb, nullptr); + DCHECK_EQ(tcp->current_zerocopy_send, nullptr); if (buf->length == 0) { grpc_core::Closure::Run( @@ -1901,7 +1903,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, } tcp->outgoing_buffer_arg = arg; if (arg) { - GPR_ASSERT(grpc_event_engine_can_track_errors()); + CHECK(grpc_event_engine_can_track_errors()); } bool flush_result = @@ -1988,7 +1990,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, tcp->base.vtable = &vtable; tcp->peer_string = std::string(peer_string); tcp->fd = grpc_fd_wrapped_fd(em_fd); - GPR_ASSERT(options.resource_quota != nullptr); + CHECK(options.resource_quota != nullptr); tcp->memory_owner = options.resource_quota->memory_quota()->CreateMemoryOwner(); tcp->self_reservation = tcp->memory_owner.MakeReservation(sizeof(grpc_tcp)); @@ -2079,7 +2081,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, int grpc_tcp_fd(grpc_endpoint* ep) { grpc_tcp* tcp = reinterpret_cast(ep); - GPR_ASSERT(ep->vtable == &vtable); + CHECK(ep->vtable == &vtable); return grpc_fd_wrapped_fd(tcp->em_fd); } @@ -2090,7 +2092,7 @@ void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd, grpc_event_engine_endpoint_destroy_and_release_fd(ep, fd, done); } grpc_tcp* tcp = reinterpret_cast(ep); - GPR_ASSERT(ep->vtable == &vtable); + CHECK(ep->vtable == &vtable); tcp->release_fd = fd; tcp->release_fd_cb = done; grpc_slice_buffer_reset_and_unref(&tcp->last_read_buffer); diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index b90f73057e6..8811eac862b 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -43,6 +43,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -89,7 +90,7 @@ using ::grpc_event_engine::experimental::SliceBuffer; static void finish_shutdown(grpc_tcp_server* s) { gpr_mu_lock(&s->mu); - GPR_ASSERT(s->shutdown); + CHECK(s->shutdown); gpr_mu_unlock(&s->mu); if (s->shutdown_complete != nullptr) { grpc_core::ExecCtx::Run(DEBUG_LOCATION, s->shutdown_complete, @@ -234,7 +235,7 @@ static grpc_error_handle CreateEventEngineListener( listener = engine->CreateListener( std::move(accept_cb), [s, ee = keeper, shutdown_complete](absl::Status status) { - GPR_ASSERT(gpr_atm_no_barrier_load(&s->refs.count) == 0); + CHECK_EQ(gpr_atm_no_barrier_load(&s->refs.count), 0); grpc_event_engine::experimental::RunEventEngineClosure( shutdown_complete, absl_status_to_grpc_error(status)); finish_shutdown(s); @@ -287,8 +288,8 @@ static grpc_error_handle tcp_server_create(grpc_closure* shutdown_complete, s->nports = 0; s->options = ::TcpOptionsFromEndpointConfig(config); s->fd_handler = nullptr; - GPR_ASSERT(s->options.resource_quota != nullptr); - GPR_ASSERT(s->on_accept_cb); + CHECK(s->options.resource_quota != nullptr); + CHECK(s->on_accept_cb); s->memory_quota = s->options.resource_quota->memory_quota(); s->pre_allocated_fd = -1; gpr_atm_no_barrier_store(&s->next_pollset_to_assign, 0); @@ -310,7 +311,7 @@ static void destroyed_port(void* server, grpc_error_handle /*error*/) { gpr_mu_unlock(&s->mu); finish_shutdown(s); } else { - GPR_ASSERT(s->destroyed_ports < s->nports); + CHECK(s->destroyed_ports < s->nports); gpr_mu_unlock(&s->mu); } } @@ -322,7 +323,7 @@ static void deactivated_all_ports(grpc_tcp_server* s) { // delete ALL the things gpr_mu_lock(&s->mu); - GPR_ASSERT(s->shutdown); + CHECK(s->shutdown); if (s->head) { grpc_tcp_listener* sp; @@ -351,7 +352,7 @@ static void deactivated_all_ports(grpc_tcp_server* s) { static void tcp_server_destroy(grpc_tcp_server* s) { gpr_mu_lock(&s->mu); - GPR_ASSERT(!s->shutdown); + CHECK(!s->shutdown); s->shutdown = true; // shutdown all fd's if (s->active_ports) { @@ -563,7 +564,8 @@ static grpc_error_handle add_wildcard_addrs_to_server(grpc_tcp_server* s, } else { grpc_error_handle root_err = GRPC_ERROR_CREATE("Failed to add any wildcard listeners"); - GPR_ASSERT(!v6_err.ok() && !v4_err.ok()); + CHECK(!v6_err.ok()); + CHECK(!v4_err.ok()); root_err = grpc_error_add_child(root_err, v6_err); root_err = grpc_error_add_child(root_err, v4_err); return root_err; @@ -614,7 +616,7 @@ static grpc_error_handle clone_port(grpc_tcp_listener* listener, sp->port = port; sp->port_index = listener->port_index; sp->fd_index = listener->fd_index + count - i; - GPR_ASSERT(sp->emfd); + CHECK(sp->emfd); grpc_tcp_server_listener_initialize_retry_timer(sp); while (listener->server->tail->next != nullptr) { listener->server->tail = listener->server->tail->next; @@ -646,7 +648,7 @@ static grpc_error_handle tcp_server_add_port(grpc_tcp_server* s, if (!listen_fd.ok()) { return; } - GPR_DEBUG_ASSERT(*listen_fd > 0); + DCHECK_GT(*listen_fd, 0); s->listen_fd_to_index_map.insert_or_assign( *listen_fd, std::make_tuple(s->n_bind_ports, fd_index++)); }); @@ -661,7 +663,7 @@ static grpc_error_handle tcp_server_add_port(grpc_tcp_server* s, gpr_mu_unlock(&s->mu); return port.status(); } - GPR_ASSERT(addr->len <= GRPC_MAX_SOCKADDR_SIZE); + CHECK(addr->len <= GRPC_MAX_SOCKADDR_SIZE); grpc_tcp_listener* sp; grpc_resolved_address sockname_temp; grpc_resolved_address addr6_v4mapped; @@ -789,12 +791,12 @@ static void tcp_server_start(grpc_tcp_server* s, size_t i; grpc_tcp_listener* sp; gpr_mu_lock(&s->mu); - GPR_ASSERT(s->on_accept_cb); - GPR_ASSERT(s->active_ports == 0); + CHECK(s->on_accept_cb); + CHECK_EQ(s->active_ports, 0u); s->pollsets = pollsets; if (grpc_event_engine::experimental::UseEventEngineListener()) { - GPR_ASSERT(!s->shutdown_listeners); - GPR_ASSERT(GRPC_LOG_IF_ERROR("listener_start", s->ee_listener->Start())); + CHECK(!s->shutdown_listeners); + CHECK(GRPC_LOG_IF_ERROR("listener_start", s->ee_listener->Start())); gpr_mu_unlock(&s->mu); return; } @@ -802,7 +804,7 @@ static void tcp_server_start(grpc_tcp_server* s, while (sp != nullptr) { if (s->so_reuseport && !grpc_is_unix_socket(&sp->addr) && !grpc_is_vsock(&sp->addr) && pollsets->size() > 1) { - GPR_ASSERT(GRPC_LOG_IF_ERROR( + CHECK(GRPC_LOG_IF_ERROR( "clone_port", clone_port(sp, (unsigned)(pollsets->size() - 1)))); for (i = 0; i < pollsets->size(); i++) { grpc_pollset_add_fd((*pollsets)[i], sp->emfd); @@ -894,17 +896,16 @@ class ExternalConnectionHandler : public grpc_core::TcpServerFdHandler { grpc_event_engine::experimental::QueryExtension< grpc_event_engine::experimental::ListenerSupportsFdExtension>( s_->ee_listener.get()); - GPR_ASSERT(listener_supports_fd != nullptr); + CHECK_NE(listener_supports_fd, nullptr); grpc_event_engine::experimental::SliceBuffer pending_data; if (buf != nullptr) { pending_data = grpc_event_engine::experimental::SliceBuffer::TakeCSliceBuffer( buf->data.raw.slice_buffer); } - GPR_ASSERT( - GRPC_LOG_IF_ERROR("listener_handle_external_connection", - listener_supports_fd->HandleExternalConnection( - listener_fd, fd, &pending_data))); + CHECK(GRPC_LOG_IF_ERROR("listener_handle_external_connection", + listener_supports_fd->HandleExternalConnection( + listener_fd, fd, &pending_data))); return; } grpc_pollset* read_notifier_pollset; 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 59de22cd68c..181ab5b8e25 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -31,6 +31,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include @@ -112,7 +113,7 @@ static grpc_error_handle add_socket_to_server(grpc_tcp_server* s, int fd, grpc_error_handle err = grpc_tcp_server_prepare_socket(s, fd, addr, s->so_reuseport, &port); if (!err.ok()) return err; - GPR_ASSERT(port > 0); + CHECK_GT(port, 0); absl::StatusOr addr_str = grpc_sockaddr_to_string(addr, true); if (!addr_str.ok()) { return GRPC_ERROR_CREATE(addr_str.status().ToString()); @@ -145,7 +146,7 @@ static grpc_error_handle add_socket_to_server(grpc_tcp_server* s, int fd, sp->fd_index = fd_index; sp->is_sibling = 0; sp->sibling = nullptr; - GPR_ASSERT(sp->emfd); + CHECK(sp->emfd); gpr_mu_unlock(&s->mu); *listener = sp; @@ -209,7 +210,7 @@ grpc_error_handle grpc_tcp_server_prepare_socket( grpc_resolved_address sockname_temp; grpc_error_handle err; - GPR_ASSERT(fd >= 0); + CHECK_GE(fd, 0); if (so_reuseport && !grpc_is_unix_socket(addr) && !grpc_is_vsock(addr)) { err = grpc_set_socket_reuse_port(fd, 1); @@ -272,7 +273,7 @@ grpc_error_handle grpc_tcp_server_prepare_socket( return absl::OkStatus(); error: - GPR_ASSERT(!err.ok()); + CHECK(!err.ok()); if (fd >= 0) { close(fd); } 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 39f233a1079..d04dddf8e46 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -30,6 +30,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include @@ -166,7 +167,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, err = grpc_error_add_child(root_err, err); break; } else { - GPR_ASSERT(requested_port == new_sp->port); + CHECK(requested_port == new_sp->port); ++fd_index; if (sp != nullptr) { new_sp->is_sibling = 1; diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 9de6cb0f268..70b4a6a5920 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -27,6 +27,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include @@ -292,7 +293,7 @@ static grpc_error_handle prepare_socket(SOCKET sock, return absl::OkStatus(); failure: - GPR_ASSERT(!error.ok()); + CHECK(!error.ok()); auto addr_uri = grpc_sockaddr_to_uri(addr); error = grpc_error_set_int( grpc_error_set_str( @@ -307,7 +308,7 @@ failure: static void decrement_active_ports_and_notify_locked(grpc_tcp_listener* sp) { sp->shutting_down = 0; - GPR_ASSERT(sp->server->active_ports > 0); + CHECK_GT(sp->server->active_ports, 0u); if (0 == --sp->server->active_ports) { finish_shutdown_locked(sp->server); } @@ -365,7 +366,7 @@ static grpc_error_handle start_accept_locked(grpc_tcp_listener* port) { return error; failure: - GPR_ASSERT(!error.ok()); + CHECK(!error.ok()); if (sock != INVALID_SOCKET) closesocket(sock); return error; } @@ -458,7 +459,7 @@ static void on_accept(void* arg, grpc_error_handle error) { // the former socked we created has now either been destroy or assigned // to the new connection. We need to create a new one for the next // connection. - GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); + CHECK(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); if (0 == --sp->outstanding_calls) { decrement_active_ports_and_notify_locked(sp); } @@ -494,7 +495,7 @@ static grpc_error_handle add_socket_to_server(grpc_tcp_server* s, SOCKET sock, return error; } - GPR_ASSERT(port >= 0); + CHECK_GE(port, 0); gpr_mu_lock(&s->mu); sp = (grpc_tcp_listener*)gpr_malloc(sizeof(grpc_tcp_listener)); sp->next = NULL; @@ -514,7 +515,7 @@ static grpc_error_handle add_socket_to_server(grpc_tcp_server* s, SOCKET sock, sp->port = port; sp->port_index = port_index; GRPC_CLOSURE_INIT(&sp->on_accept, on_accept, sp, grpc_schedule_on_exec_ctx); - GPR_ASSERT(sp->socket); + CHECK(sp->socket); gpr_mu_unlock(&s->mu); *listener = sp; @@ -591,7 +592,7 @@ done: error = error_out; *port = -1; } else { - GPR_ASSERT(sp != NULL); + CHECK(sp != NULL); *port = sp->port; } return error; @@ -601,9 +602,9 @@ static void tcp_server_start(grpc_tcp_server* s, const std::vector* /*pollsets*/) { grpc_tcp_listener* sp; gpr_mu_lock(&s->mu); - GPR_ASSERT(s->active_ports == 0); + CHECK_EQ(s->active_ports, 0u); for (sp = s->head; sp; sp = sp->next) { - GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); + CHECK(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); s->active_ports++; } gpr_mu_unlock(&s->mu); @@ -653,7 +654,7 @@ static grpc_error_handle event_engine_create(grpc_closure* shutdown_complete, WindowsEventEngine* engine_ptr = reinterpret_cast( config.GetVoidPointer(GRPC_INTERNAL_ARG_EVENT_ENGINE)); grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); - GPR_ASSERT(on_accept_cb != nullptr); + CHECK_NE(on_accept_cb, nullptr); auto accept_cb = [s, on_accept_cb, on_accept_cb_arg]( std::unique_ptr endpoint, MemoryAllocator memory_allocator) { @@ -675,7 +676,7 @@ static grpc_error_handle event_engine_create(grpc_closure* shutdown_complete, grpc_core::RefCountedPtr resource_quota; { void* tmp_quota = config.GetVoidPointer(GRPC_ARG_RESOURCE_QUOTA); - GPR_ASSERT(tmp_quota != nullptr); + CHECK_NE(tmp_quota, nullptr); resource_quota = reinterpret_cast(tmp_quota)->Ref(); } @@ -706,13 +707,13 @@ static grpc_error_handle event_engine_create(grpc_closure* shutdown_complete, static void event_engine_start(grpc_tcp_server* s, const std::vector* /*pollsets*/) { - GPR_ASSERT(s->ee_listener->Start().ok()); + CHECK(s->ee_listener->Start().ok()); } static grpc_error_handle event_engine_add_port( grpc_tcp_server* s, const grpc_resolved_address* addr, int* port) { - GPR_ASSERT(addr != nullptr); - GPR_ASSERT(port != nullptr); + CHECK_NE(addr, nullptr); + CHECK_NE(port, nullptr); auto ee_addr = CreateResolvedAddress(*addr); auto out_port = s->ee_listener->Bind(ee_addr); *port = out_port.ok() ? *out_port : -1; diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index 6ad9bb6a310..53174721ba1 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -24,6 +24,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -190,7 +192,7 @@ static void on_read(void* tcpp, grpc_error_handle error) { grpc_slice_buffer_reset_and_unref(tcp->read_slices); } else { if (info->bytes_transferred != 0 && !tcp->shutting_down) { - GPR_ASSERT((size_t)info->bytes_transferred <= tcp->read_slices->length); + CHECK((size_t)info->bytes_transferred <= tcp->read_slices->length); if (static_cast(info->bytes_transferred) != tcp->read_slices->length) { grpc_slice_buffer_trim_end( @@ -199,7 +201,7 @@ static void on_read(void* tcpp, grpc_error_handle error) { static_cast(info->bytes_transferred), &tcp->last_read_buffer); } - GPR_ASSERT((size_t)info->bytes_transferred == tcp->read_slices->length); + CHECK((size_t)info->bytes_transferred == tcp->read_slices->length); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace) && gpr_should_log(GPR_LOG_SEVERITY_INFO)) { @@ -272,7 +274,7 @@ static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, GRPC_SLICE_MALLOC(DEFAULT_TARGET_READ_SIZE)); } - GPR_ASSERT(tcp->read_slices->count <= MAX_WSABUF_COUNT); + CHECK(tcp->read_slices->count <= MAX_WSABUF_COUNT); for (i = 0; i < tcp->read_slices->count; i++) { buffers[i].len = (ULONG)GRPC_SLICE_LENGTH( tcp->read_slices->slices[i]); // we know slice size fits in 32bit. @@ -331,7 +333,7 @@ static void on_write(void* tcpp, grpc_error_handle error) { if (info->wsa_error != 0) { error = GRPC_WSA_ERROR(info->wsa_error, "WSASend"); } else { - GPR_ASSERT(info->bytes_transferred <= tcp->write_slices->length); + CHECK(info->bytes_transferred <= tcp->write_slices->length); } } @@ -378,7 +380,7 @@ static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices, tcp->write_cb = cb; tcp->write_slices = slices; - GPR_ASSERT(tcp->write_slices->count <= UINT_MAX); + CHECK(tcp->write_slices->count <= UINT_MAX); if (tcp->write_slices->count > GPR_ARRAY_SIZE(local_buffers)) { buffers = (WSABUF*)gpr_malloc(sizeof(WSABUF) * tcp->write_slices->count); allocated = buffers; @@ -386,7 +388,7 @@ static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices, for (i = 0; i < tcp->write_slices->count; i++) { len = GRPC_SLICE_LENGTH(tcp->write_slices->slices[i]); - GPR_ASSERT(len <= ULONG_MAX); + CHECK(len <= ULONG_MAX); buffers[i].len = (ULONG)len; buffers[i].buf = (char*)GRPC_SLICE_START_PTR(tcp->write_slices->slices[i]); } diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index 04f0bd654de..bc6f47c2188 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -120,7 +121,7 @@ static bool is_in_ht(grpc_timer* t) { } static void add_to_ht(grpc_timer* t) { - GPR_ASSERT(!t->hash_table_next); + CHECK(!t->hash_table_next); size_t i = grpc_core::HashPointer(t, NUM_HASH_BUCKETS); gpr_mu_lock(&g_hash_mu[i]); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 8221d04ddf3..6e4197a8f83 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -82,7 +84,7 @@ static void gc_completed_threads(void) { } static void start_timer_thread_and_unlock(void) { - GPR_ASSERT(g_threaded); + CHECK(g_threaded); ++g_waiter_count; ++g_thread_count; gpr_mu_unlock(&g_mu); diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 01daa2c90cf..52da21d84b1 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -33,6 +33,7 @@ #include #endif // GPR_WINDOWS +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include @@ -49,7 +50,7 @@ void grpc_create_socketpair_if_unix(int sv[2]) { #ifdef GPR_WINDOWS grpc_core::Crash("AF_UNIX socket pairs are not supported on Windows"); #else - GPR_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0); + CHECK_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0); #endif } diff --git a/src/core/lib/iomgr/unix_sockets_posix_noop.cc b/src/core/lib/iomgr/unix_sockets_posix_noop.cc index c683145668a..8e783c8cb70 100644 --- a/src/core/lib/iomgr/unix_sockets_posix_noop.cc +++ b/src/core/lib/iomgr/unix_sockets_posix_noop.cc @@ -24,6 +24,8 @@ #include +#include "absl/log/check.h" + #include #include "src/core/lib/gprpp/crash.h" @@ -32,7 +34,7 @@ void grpc_create_socketpair_if_unix(int /* sv */[2]) { // TODO: Either implement this for the non-Unix socket case or make // sure that it is never called in any such case. Until then, leave an // assertion to notify if this gets called inadvertently - GPR_ASSERT(0); + CHECK(0); } absl::StatusOr>