diff --git a/BUILD b/BUILD index 9872dc58e5e..4d04c8d518e 100644 --- a/BUILD +++ b/BUILD @@ -897,6 +897,7 @@ grpc_cc_library( name = "grpc++_public_hdrs", hdrs = GRPCXX_PUBLIC_HDRS, external_deps = [ + "absl/log:check", "absl/strings:cord", "absl/synchronization", "protobuf_headers", diff --git a/CMakeLists.txt b/CMakeLists.txt index e0513ca023a..5c077beadd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,7 @@ set(gRPC_ABSL_USED_TARGETS absl_bind_front absl_bits absl_charset + absl_check absl_city absl_civil_time absl_cleanup @@ -169,6 +170,8 @@ set(gRPC_ABSL_USED_TARGETS absl_log_entry absl_log_globals absl_log_internal_append_truncated + absl_log_internal_check_impl + absl_log_internal_check_op absl_log_internal_conditions absl_log_internal_config absl_log_internal_fnmatch @@ -4146,6 +4149,7 @@ target_include_directories(grpc++ ) target_link_libraries(grpc++ ${_gRPC_ALLTARGETS_LIBRARIES} + absl::check grpc ${_gRPC_PROTOBUF_LIBRARIES} ) @@ -4887,6 +4891,7 @@ target_include_directories(grpc++_unsecure ) target_link_libraries(grpc++_unsecure ${_gRPC_ALLTARGETS_LIBRARIES} + absl::check grpc_unsecure ${_gRPC_PROTOBUF_LIBRARIES} ) @@ -15350,7 +15355,6 @@ target_include_directories(grpc_cli target_link_libraries(grpc_cli ${_gRPC_ALLTARGETS_LIBRARIES} - absl::check grpc++ ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} grpc++_test_config @@ -36971,7 +36975,7 @@ generate_pkgconfig( "gRPC++" "C++ wrapper for gRPC" "${gRPC_CPP_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc" "libcares openssl re2 zlib" "-lgrpc++" "-laddress_sorting -lupb_textformat_lib -lupb_json_lib -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" @@ -36982,7 +36986,7 @@ generate_pkgconfig( "gRPC++ unsecure" "C++ wrapper for gRPC without SSL" "${gRPC_CPP_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc_unsecure" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc_unsecure" "libcares zlib" "-lgrpc++_unsecure" "-laddress_sorting -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 29961e016c9..e1fa1842c2b 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -3937,6 +3937,7 @@ libs: - src/cpp/util/string_ref.cc - src/cpp/util/time_cc.cc deps: + - absl/log:check - grpc - protobuf baselib: true @@ -4310,6 +4311,7 @@ libs: - src/cpp/util/string_ref.cc - src/cpp/util/time_cc.cc deps: + - absl/log:check - grpc_unsecure - protobuf baselib: true @@ -10524,7 +10526,6 @@ targets: - test/cpp/util/proto_reflection_descriptor_database.cc - test/cpp/util/service_describer.cc deps: - - absl/log:check - grpc++ - protoc - grpc++_test_config diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index a22f9661f96..0f4908c8e2b 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -242,6 +242,7 @@ Pod::Spec.new do |s| ss.dependency 'abseil/functional/bind_front', abseil_version ss.dependency 'abseil/functional/function_ref', abseil_version ss.dependency 'abseil/hash/hash', abseil_version + ss.dependency 'abseil/log/check', abseil_version ss.dependency 'abseil/log/log', abseil_version ss.dependency 'abseil/memory/memory', abseil_version ss.dependency 'abseil/meta/type_traits', abseil_version diff --git a/include/grpcpp/client_context.h b/include/grpcpp/client_context.h index 7493f6a8601..2328e3e6fc6 100644 --- a/include/grpcpp/client_context.h +++ b/include/grpcpp/client_context.h @@ -38,6 +38,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -246,7 +248,7 @@ class ClientContext { /// \return A multimap of initial metadata key-value pairs from the server. const std::multimap& GetServerInitialMetadata() const { - GPR_ASSERT(initial_metadata_received_); + CHECK(initial_metadata_received_); return *recv_initial_metadata_.map(); } diff --git a/include/grpcpp/completion_queue.h b/include/grpcpp/completion_queue.h index 23c98e09749..bfd138b5945 100644 --- a/include/grpcpp/completion_queue.h +++ b/include/grpcpp/completion_queue.h @@ -34,6 +34,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -323,7 +325,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary { bool ok = ev.success != 0; void* ignored = tag; if (tag->FinalizeResult(&ignored, &ok)) { - GPR_ASSERT(ignored == tag); + CHECK(ignored == tag); return ok; } } @@ -344,7 +346,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary { bool ok = ev.success != 0; void* ignored = tag; // the tag must be swallowed if using TryPluck - GPR_ASSERT(!tag->FinalizeResult(&ignored, &ok)); + CHECK(!tag->FinalizeResult(&ignored, &ok)); } /// Performs a single polling pluck on \a tag. Calls tag->FinalizeResult if @@ -361,7 +363,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary { bool ok = ev.success != 0; void* ignored = tag; - GPR_ASSERT(!tag->FinalizeResult(&ignored, &ok)); + CHECK(!tag->FinalizeResult(&ignored, &ok)); } /// Manage state of avalanching operations : completion queue tags that diff --git a/include/grpcpp/impl/call_op_set.h b/include/grpcpp/impl/call_op_set.h index 48c958a96f6..56ce6289082 100644 --- a/include/grpcpp/impl/call_op_set.h +++ b/include/grpcpp/impl/call_op_set.h @@ -23,6 +23,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -316,7 +318,7 @@ class CallOpSendMessage { return; } if (msg_ != nullptr) { - GPR_ASSERT(serializer_(msg_).ok()); + CHECK(serializer_(msg_).ok()); } serializer_ = nullptr; grpc_op* op = &ops[(*nops)++]; @@ -795,7 +797,7 @@ class CallOpClientRecvStatus { if (recv_status_ == nullptr || hijacked_) return; if (static_cast(status_code_) == StatusCode::OK) { *recv_status_ = Status(); - GPR_DEBUG_ASSERT(debug_error_string_ == nullptr); + DCHECK_EQ(debug_error_string_, nullptr); } else { *recv_status_ = Status(static_cast(status_code_), @@ -974,7 +976,7 @@ class CallOpSet : public CallOpSetInterface, // WritesDone multiple times gpr_log(GPR_ERROR, "API misuse of type %s observed", grpc_call_error_to_string(err)); - GPR_ASSERT(false); + CHECK(false); } } @@ -984,8 +986,8 @@ class CallOpSet : public CallOpSetInterface, done_intercepting_ = true; // The following call_start_batch is internally-generated so no need for an // explanatory log on failure. - GPR_ASSERT(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag(), - nullptr) == GRPC_CALL_OK); + CHECK(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag(), + nullptr) == GRPC_CALL_OK); } private: diff --git a/include/grpcpp/impl/interceptor_common.h b/include/grpcpp/impl/interceptor_common.h index 81e66df4095..f8b104ba89c 100644 --- a/include/grpcpp/impl/interceptor_common.h +++ b/include/grpcpp/impl/interceptor_common.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -56,16 +58,15 @@ class InterceptorBatchMethodsImpl if (call_->client_rpc_info() != nullptr) { return ProceedClient(); } - GPR_ASSERT(call_->server_rpc_info() != nullptr); + CHECK_NE(call_->server_rpc_info(), nullptr); ProceedServer(); } void Hijack() override { // Only the client can hijack when sending down initial metadata - GPR_ASSERT(!reverse_ && ops_ != nullptr && - call_->client_rpc_info() != nullptr); + CHECK(!reverse_ && ops_ != nullptr && call_->client_rpc_info() != nullptr); // It is illegal to call Hijack twice - GPR_ASSERT(!ran_hijacking_interceptor_); + CHECK(!ran_hijacking_interceptor_); auto* rpc_info = call_->client_rpc_info(); rpc_info->hijacked_ = true; rpc_info->hijacked_interceptor_ = current_interceptor_index_; @@ -80,21 +81,21 @@ class InterceptorBatchMethodsImpl } ByteBuffer* GetSerializedSendMessage() override { - GPR_ASSERT(orig_send_message_ != nullptr); + CHECK_NE(orig_send_message_, nullptr); if (*orig_send_message_ != nullptr) { - GPR_ASSERT(serializer_(*orig_send_message_).ok()); + CHECK(serializer_(*orig_send_message_).ok()); *orig_send_message_ = nullptr; } return send_message_; } const void* GetSendMessage() override { - GPR_ASSERT(orig_send_message_ != nullptr); + CHECK_NE(orig_send_message_, nullptr); return *orig_send_message_; } void ModifySendMessage(const void* message) override { - GPR_ASSERT(orig_send_message_ != nullptr); + CHECK_NE(orig_send_message_, nullptr); *orig_send_message_ = message; } @@ -129,7 +130,7 @@ class InterceptorBatchMethodsImpl Status* GetRecvStatus() override { return recv_status_; } void FailHijackedSendMessage() override { - GPR_ASSERT(hooks_[static_cast( + CHECK(hooks_[static_cast( experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]); *fail_send_message_ = true; } @@ -192,7 +193,7 @@ class InterceptorBatchMethodsImpl } void FailHijackedRecvMessage() override { - GPR_ASSERT(hooks_[static_cast( + CHECK(hooks_[static_cast( experimental::InterceptionHookPoints::PRE_RECV_MESSAGE)]); *hijacked_recv_message_failed_ = true; } @@ -236,7 +237,7 @@ class InterceptorBatchMethodsImpl // ContinueFinalizeOpsAfterInterception will be called. Note that neither of // them is invoked if there were no interceptors registered. bool RunInterceptors() { - GPR_ASSERT(ops_); + CHECK(ops_); auto* client_rpc_info = call_->client_rpc_info(); if (client_rpc_info != nullptr) { if (client_rpc_info->interceptors_.empty()) { @@ -261,8 +262,8 @@ class InterceptorBatchMethodsImpl // SyncRequest. bool RunInterceptors(std::function f) { // This is used only by the server for initial call request - GPR_ASSERT(reverse_ == true); - GPR_ASSERT(call_->client_rpc_info() == nullptr); + CHECK_EQ(reverse_, true); + CHECK_EQ(call_->client_rpc_info(), nullptr); auto* server_rpc_info = call_->server_rpc_info(); if (server_rpc_info == nullptr || server_rpc_info->interceptors_.empty()) { return true; @@ -356,7 +357,7 @@ class InterceptorBatchMethodsImpl return ops_->ContinueFinalizeResultAfterInterception(); } } - GPR_ASSERT(callback_); + CHECK(callback_); callback_(); } @@ -422,112 +423,98 @@ class CancelInterceptorBatchMethods void Hijack() override { // Only the client can hijack when sending down initial metadata - GPR_ASSERT(false && - "It is illegal to call Hijack on a method which has a " - "Cancel notification"); + CHECK(false) << "It is illegal to call Hijack on a method which has a " + "Cancel notification"; } ByteBuffer* GetSerializedSendMessage() override { - GPR_ASSERT(false && - "It is illegal to call GetSendMessage on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendMessage on a method which " + "has a Cancel notification"; return nullptr; } bool GetSendMessageStatus() override { - GPR_ASSERT(false && - "It is illegal to call GetSendMessageStatus on a method which " - "has a Cancel notification"); + CHECK(false) + << "It is illegal to call GetSendMessageStatus on a method which " + "has a Cancel notification"; return false; } const void* GetSendMessage() override { - GPR_ASSERT(false && - "It is illegal to call GetOriginalSendMessage on a method which " - "has a Cancel notification"); + CHECK(false) + << "It is illegal to call GetOriginalSendMessage on a method which " + "has a Cancel notification"; return nullptr; } void ModifySendMessage(const void* /*message*/) override { - GPR_ASSERT(false && - "It is illegal to call ModifySendMessage on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call ModifySendMessage on a method which " + "has a Cancel notification"; } std::multimap* GetSendInitialMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetSendInitialMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendInitialMetadata on a " + "method which has a Cancel notification"; return nullptr; } Status GetSendStatus() override { - GPR_ASSERT(false && - "It is illegal to call GetSendStatus on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendStatus on a method which " + "has a Cancel notification"; return Status(); } void ModifySendStatus(const Status& /*status*/) override { - GPR_ASSERT(false && - "It is illegal to call ModifySendStatus on a method " - "which has a Cancel notification"); + CHECK(false) << "It is illegal to call ModifySendStatus on a method " + "which has a Cancel notification"; } std::multimap* GetSendTrailingMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetSendTrailingMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendTrailingMetadata on a " + "method which has a Cancel notification"; return nullptr; } void* GetRecvMessage() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvMessage on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvMessage on a method which " + "has a Cancel notification"; return nullptr; } std::multimap* GetRecvInitialMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvInitialMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvInitialMetadata on a " + "method which has a Cancel notification"; return nullptr; } Status* GetRecvStatus() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvStatus on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvStatus on a method which " + "has a Cancel notification"; return nullptr; } std::multimap* GetRecvTrailingMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvTrailingMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvTrailingMetadata on a " + "method which has a Cancel notification"; return nullptr; } std::unique_ptr GetInterceptedChannel() override { - GPR_ASSERT(false && - "It is illegal to call GetInterceptedChannel on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetInterceptedChannel on a " + "method which has a Cancel notification"; return std::unique_ptr(nullptr); } void FailHijackedRecvMessage() override { - GPR_ASSERT(false && - "It is illegal to call FailHijackedRecvMessage on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call FailHijackedRecvMessage on a " + "method which has a Cancel notification"; } void FailHijackedSendMessage() override { - GPR_ASSERT(false && - "It is illegal to call FailHijackedSendMessage on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call FailHijackedSendMessage on a " + "method which has a Cancel notification"; } }; } // namespace internal diff --git a/include/grpcpp/impl/proto_utils.h b/include/grpcpp/impl/proto_utils.h index c6240ffa84d..0cd4d1bdb4b 100644 --- a/include/grpcpp/impl/proto_utils.h +++ b/include/grpcpp/impl/proto_utils.h @@ -21,6 +21,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -51,8 +53,8 @@ Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb, if (static_cast(byte_size) <= GRPC_SLICE_INLINED_SIZE) { Slice slice(byte_size); // We serialize directly into the allocated slices memory - GPR_ASSERT(slice.end() == msg.SerializeWithCachedSizesToArray( - const_cast(slice.begin()))); + CHECK(slice.end() == msg.SerializeWithCachedSizesToArray( + const_cast(slice.begin()))); ByteBuffer tmp(&slice, 1); bb->Swap(&tmp); diff --git a/include/grpcpp/impl/rpc_service_method.h b/include/grpcpp/impl/rpc_service_method.h index 73694263cdd..0ce7d7b96fb 100644 --- a/include/grpcpp/impl/rpc_service_method.h +++ b/include/grpcpp/impl/rpc_service_method.h @@ -25,6 +25,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -75,7 +77,7 @@ class MethodHandler { // retained by the handler. Returns nullptr if deserialization failed. virtual void* Deserialize(grpc_call* /*call*/, grpc_byte_buffer* req, Status* /*status*/, void** /*handler_data*/) { - GPR_ASSERT(req == nullptr); + CHECK_EQ(req, nullptr); return nullptr; } }; diff --git a/include/grpcpp/impl/server_callback_handlers.h b/include/grpcpp/impl/server_callback_handlers.h index b49e17a2c16..f9839973fe9 100644 --- a/include/grpcpp/impl/server_callback_handlers.h +++ b/include/grpcpp/impl/server_callback_handlers.h @@ -18,6 +18,8 @@ #ifndef GRPCPP_IMPL_SERVER_CALLBACK_HANDLERS_H #define GRPCPP_IMPL_SERVER_CALLBACK_HANDLERS_H +#include "absl/log/check.h" + #include #include #include @@ -147,7 +149,7 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be marked inline because it // is directly invoking a user-controlled reaction @@ -335,7 +337,7 @@ class CallbackClientStreamingHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be inlined because it invokes // a user-controlled reaction, but any resulting OnDone can be inlined in @@ -539,7 +541,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be inlined because it invokes // a user-controlled reaction, but any resulting OnDone can be inlined in @@ -577,7 +579,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler { ctx_->sent_initial_metadata_ = true; } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(resp, options).ok()); + CHECK(write_ops_.SendMessagePtr(resp, options).ok()); call_.PerformOps(&write_ops_); } @@ -585,7 +587,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler { grpc::Status s) override { // This combines the write into the finish callback // TODO(vjpai): don't assert - GPR_ASSERT(finish_ops_.SendMessagePtr(resp, options).ok()); + CHECK(finish_ops_.SendMessagePtr(resp, options).ok()); Finish(std::move(s)); } @@ -751,7 +753,7 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be inlined because it invokes // a user-controlled reaction, but any resulting OnDone can be inlined in @@ -789,14 +791,14 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler { ctx_->sent_initial_metadata_ = true; } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(resp, options).ok()); + CHECK(write_ops_.SendMessagePtr(resp, options).ok()); call_.PerformOps(&write_ops_); } void WriteAndFinish(const ResponseType* resp, grpc::WriteOptions options, grpc::Status s) override { // TODO(vjpai): don't assert - GPR_ASSERT(finish_ops_.SendMessagePtr(resp, options).ok()); + CHECK(finish_ops_.SendMessagePtr(resp, options).ok()); Finish(std::move(s)); } diff --git a/include/grpcpp/impl/service_type.h b/include/grpcpp/impl/service_type.h index 9699e2328d4..c284026a0f6 100644 --- a/include/grpcpp/impl/service_type.h +++ b/include/grpcpp/impl/service_type.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_IMPL_SERVICE_TYPE_H #define GRPCPP_IMPL_SERVICE_TYPE_H +#include "absl/log/check.h" + #include #include #include @@ -150,9 +152,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT(methods_[idx].get() != nullptr && - "Cannot mark the method as 'async' because it has already been " - "marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'async' because it has already been " + "marked as 'generic'."; methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); } @@ -160,9 +162,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT(methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw' because it has already " - "been marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'raw' because it has already " + "been marked as 'generic'."; methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); } @@ -170,10 +172,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT( - methods_[idx]->handler() != nullptr && - "Cannot mark the method as 'generic' because it has already been " - "marked as 'async' or 'raw'."); + CHECK_NE(methods_[idx]->handler(), nullptr) + << "Cannot mark the method as 'generic' because it has already been " + "marked as 'async' or 'raw'."; methods_[idx].reset(); } @@ -181,8 +182,8 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT(methods_[idx] && methods_[idx]->handler() && - "Cannot mark an async or generic method Streamed"); + CHECK(methods_[idx] && methods_[idx]->handler()) + << "Cannot mark an async or generic method Streamed"; methods_[idx]->SetHandler(streamed_method); // From the server's point of view, streamed unary is a special @@ -196,10 +197,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT( - methods_[idx].get() != nullptr && - "Cannot mark the method as 'callback' because it has already been " - "marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'callback' because it has already been " + "marked as 'generic'."; methods_[idx]->SetHandler(handler); methods_[idx]->SetServerApiType( internal::RpcServiceMethod::ApiType::CALL_BACK); @@ -209,10 +209,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT( - methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw callback' because it has already " - "been marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'raw callback' because it has already " + "been marked as 'generic'."; methods_[idx]->SetHandler(handler); methods_[idx]->SetServerApiType( internal::RpcServiceMethod::ApiType::RAW_CALL_BACK); diff --git a/include/grpcpp/impl/sync.h b/include/grpcpp/impl/sync.h index 2fadf6fab1c..9288459196a 100644 --- a/include/grpcpp/impl/sync.h +++ b/include/grpcpp/impl/sync.h @@ -27,6 +27,7 @@ #include +#include "absl/log/check.h" #include "absl/synchronization/mutex.h" #include @@ -105,7 +106,7 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock { ReleasableMutexLock& operator=(const ReleasableMutexLock&) = delete; void Release() ABSL_UNLOCK_FUNCTION() { - GPR_DEBUG_ASSERT(!released_); + DCHECK(!released_); released_ = true; mu_->Unlock(); } diff --git a/include/grpcpp/server_interface.h b/include/grpcpp/server_interface.h index 5f8f8b54b0f..129562016ac 100644 --- a/include/grpcpp/server_interface.h +++ b/include/grpcpp/server_interface.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SERVER_INTERFACE_H #define GRPCPP_SERVER_INTERFACE_H +#include "absl/log/check.h" + #include #include #include @@ -318,7 +320,7 @@ class ServerInterface : public internal::CallHook { grpc::CompletionQueue* call_cq, grpc::ServerCompletionQueue* notification_cq, void* tag, Message* message) { - GPR_ASSERT(method); + CHECK(method); new PayloadAsyncRequest(method, this, context, stream, call_cq, notification_cq, tag, message); } @@ -329,7 +331,7 @@ class ServerInterface : public internal::CallHook { grpc::CompletionQueue* call_cq, grpc::ServerCompletionQueue* notification_cq, void* tag) { - GPR_ASSERT(method); + CHECK(method); new NoPayloadAsyncRequest(method, this, context, stream, call_cq, notification_cq, tag); } diff --git a/include/grpcpp/support/async_stream.h b/include/grpcpp/support/async_stream.h index 1bf67d301d5..ebc7aebcf51 100644 --- a/include/grpcpp/support/async_stream.h +++ b/include/grpcpp/support/async_stream.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_ASYNC_STREAM_H #define GRPCPP_SUPPORT_ASYNC_STREAM_H +#include "absl/log/check.h" + #include #include #include @@ -200,7 +202,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncReader)); + CHECK_EQ(size, sizeof(ClientAsyncReader)); } // This operator should never be called as the memory should be freed as part @@ -208,10 +210,10 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall(void* tag) override { - GPR_ASSERT(!started_); + CHECK(!started_); started_ = true; StartCallInternal(tag); } @@ -225,8 +227,8 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { /// calling code can access the received metadata through the /// \a ClientContext. void ReadInitialMetadata(void* tag) override { - GPR_ASSERT(started_); - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(started_); + CHECK(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); meta_ops_.RecvInitialMetadata(context_); @@ -234,7 +236,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { } void Read(R* msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); read_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { read_ops_.RecvInitialMetadata(context_); @@ -249,7 +251,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata received from the server. void Finish(grpc::Status* status, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -265,12 +267,12 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { const W& request, bool start, void* tag) : context_(context), call_(call), started_(start) { // TODO(ctiller): don't assert - GPR_ASSERT(init_ops_.SendMessage(request).ok()); + CHECK(init_ops_.SendMessage(request).ok()); init_ops_.ClientSendClose(); if (start) { StartCallInternal(tag); } else { - GPR_ASSERT(tag == nullptr); + CHECK(tag == nullptr); } } @@ -348,7 +350,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncWriter)); + CHECK_EQ(size, sizeof(ClientAsyncWriter)); } // This operator should never be called as the memory should be freed as part @@ -356,10 +358,10 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall(void* tag) override { - GPR_ASSERT(!started_); + CHECK(!started_); started_ = true; StartCallInternal(tag); } @@ -372,8 +374,8 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { /// associated with this call is updated, and the calling code can access /// the received metadata through the \a ClientContext. void ReadInitialMetadata(void* tag) override { - GPR_ASSERT(started_); - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(started_); + CHECK(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); meta_ops_.RecvInitialMetadata(context_); @@ -381,27 +383,27 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { } void Write(const W& msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); if (options.is_last_message()) { options.set_buffer_hint(); write_ops_.ClientSendClose(); } // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } void WritesDone(void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); write_ops_.ClientSendClose(); call_.PerformOps(&write_ops_); @@ -415,7 +417,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { /// - attempts to fill in the \a response parameter passed to this class's /// constructor with the server's response message. void Finish(grpc::Status* status, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -435,7 +437,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { if (start) { StartCallInternal(tag); } else { - GPR_ASSERT(tag == nullptr); + CHECK(tag == nullptr); } } @@ -515,7 +517,7 @@ class ClientAsyncReaderWriter final public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncReaderWriter)); + CHECK_EQ(size, sizeof(ClientAsyncReaderWriter)); } // This operator should never be called as the memory should be freed as part @@ -523,10 +525,10 @@ class ClientAsyncReaderWriter final // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall(void* tag) override { - GPR_ASSERT(!started_); + CHECK(!started_); started_ = true; StartCallInternal(tag); } @@ -539,8 +541,8 @@ class ClientAsyncReaderWriter final /// is updated with it, and then the receiving initial metadata can /// be accessed through this \a ClientContext. void ReadInitialMetadata(void* tag) override { - GPR_ASSERT(started_); - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(started_); + CHECK(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); meta_ops_.RecvInitialMetadata(context_); @@ -548,7 +550,7 @@ class ClientAsyncReaderWriter final } void Read(R* msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); read_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { read_ops_.RecvInitialMetadata(context_); @@ -558,27 +560,27 @@ class ClientAsyncReaderWriter final } void Write(const W& msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); if (options.is_last_message()) { options.set_buffer_hint(); write_ops_.ClientSendClose(); } // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } void WritesDone(void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); write_ops_.ClientSendClose(); call_.PerformOps(&write_ops_); @@ -589,7 +591,7 @@ class ClientAsyncReaderWriter final /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata sent from the server. void Finish(grpc::Status* status, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -606,7 +608,7 @@ class ClientAsyncReaderWriter final if (start) { StartCallInternal(tag); } else { - GPR_ASSERT(tag == nullptr); + CHECK(tag == nullptr); } } @@ -706,7 +708,7 @@ class ServerAsyncReader final : public ServerAsyncReaderInterface { /// - The initial metadata that will be sent to the client from this op will /// be taken from the \a ServerContext associated with the call. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -765,7 +767,7 @@ class ServerAsyncReader final : public ServerAsyncReaderInterface { /// gRPC doesn't take ownership or a reference to \a status, so it is safe to /// to deallocate once FinishWithError returns. void FinishWithError(const grpc::Status& status, void* tag) override { - GPR_ASSERT(!status.ok()); + CHECK(!status.ok()); finish_ops_.set_output_tag(tag); if (!ctx_->sent_initial_metadata_) { finish_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -855,7 +857,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { /// /// \param[in] tag Tag identifying this request. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -871,7 +873,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } @@ -883,7 +885,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { EnsureInitialMetadataSent(&write_ops_); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } @@ -902,7 +904,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); options.set_buffer_hint(); - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); call_.PerformOps(&write_ops_); } @@ -1021,7 +1023,7 @@ class ServerAsyncReaderWriter final /// /// \param[in] tag Tag identifying this request. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -1043,7 +1045,7 @@ class ServerAsyncReaderWriter final write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } @@ -1053,7 +1055,7 @@ class ServerAsyncReaderWriter final options.set_buffer_hint(); } EnsureInitialMetadataSent(&write_ops_); - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } @@ -1073,7 +1075,7 @@ class ServerAsyncReaderWriter final write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); options.set_buffer_hint(); - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); call_.PerformOps(&write_ops_); } diff --git a/include/grpcpp/support/async_unary_call.h b/include/grpcpp/support/async_unary_call.h index a831d73f72f..787d3a56e3d 100644 --- a/include/grpcpp/support/async_unary_call.h +++ b/include/grpcpp/support/async_unary_call.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H #define GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H +#include "absl/log/check.h" + #include #include #include @@ -130,7 +132,7 @@ class ClientAsyncResponseReaderHelper { new (grpc_call_arena_alloc(call, sizeof(SingleBufType))) SingleBufType; *single_buf_ptr = single_buf; // TODO(ctiller): don't assert - GPR_ASSERT(single_buf->SendMessage(request).ok()); + CHECK(single_buf->SendMessage(request).ok()); single_buf->ClientSendClose(); // The purpose of the following functions is to type-erase the actual @@ -220,7 +222,7 @@ class ClientAsyncResponseReader final public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncResponseReader)); + CHECK_EQ(size, sizeof(ClientAsyncResponseReader)); } // This operator should never be called as the memory should be freed as part @@ -228,10 +230,10 @@ class ClientAsyncResponseReader final // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() override { - GPR_DEBUG_ASSERT(!started_); + DCHECK(!started_); started_ = true; internal::ClientAsyncResponseReaderHelper::StartCall(context_, single_buf_); } @@ -243,8 +245,8 @@ class ClientAsyncResponseReader final /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata sent from the server. void ReadInitialMetadata(void* tag) override { - GPR_DEBUG_ASSERT(started_); - GPR_DEBUG_ASSERT(!context_->initial_metadata_received_); + DCHECK(started_); + DCHECK(!context_->initial_metadata_received_); read_initial_metadata_(context_, &call_, single_buf_, tag); initial_metadata_read_ = true; } @@ -255,7 +257,7 @@ class ClientAsyncResponseReader final /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata sent from the server. void Finish(R* msg, grpc::Status* status, void* tag) override { - GPR_DEBUG_ASSERT(started_); + DCHECK(started_); finish_(context_, &call_, initial_metadata_read_, single_buf_, &finish_buf_, static_cast(msg), status, tag); } @@ -304,7 +306,7 @@ class ServerAsyncResponseWriter final /// /// \param[in] tag Tag identifying this request. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_buf_.set_output_tag(tag); meta_buf_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -373,7 +375,7 @@ class ServerAsyncResponseWriter final /// deallocate them once the Finish operation is complete (i.e. a result /// arrives in the completion queue). void FinishWithError(const grpc::Status& status, void* tag) { - GPR_ASSERT(!status.ok()); + CHECK(!status.ok()); finish_buf_.set_output_tag(tag); if (!ctx_->sent_initial_metadata_) { finish_buf_.SendInitialMetadata(&ctx_->initial_metadata_, diff --git a/include/grpcpp/support/callback_common.h b/include/grpcpp/support/callback_common.h index 6ae8cfb946a..2868de0bd4d 100644 --- a/include/grpcpp/support/callback_common.h +++ b/include/grpcpp/support/callback_common.h @@ -21,6 +21,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -71,7 +73,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(CallbackWithStatusTag)); + CHECK_EQ(size, sizeof(CallbackWithStatusTag)); } // This operator should never be called as the memory should be freed as part @@ -79,7 +81,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } CallbackWithStatusTag(grpc_call* call, std::function f, CompletionQueueTag* ops) @@ -118,7 +120,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor { // The tag was swallowed return; } - GPR_ASSERT(ignored == ops_); + CHECK(ignored == ops_); // Last use of func_ or status_, so ok to move them out auto func = std::move(func_); @@ -137,7 +139,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(CallbackWithSuccessTag)); + CHECK_EQ(size, sizeof(CallbackWithSuccessTag)); } // This operator should never be called as the memory should be freed as part @@ -145,7 +147,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } CallbackWithSuccessTag() : call_(nullptr) {} @@ -162,7 +164,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { // callbacks. void Set(grpc_call* call, std::function f, CompletionQueueTag* ops, bool can_inline) { - GPR_ASSERT(call_ == nullptr); + CHECK_EQ(call_, nullptr); grpc_call_ref(call); call_ = call; func_ = std::move(f); @@ -208,7 +210,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { #endif bool do_callback = ops_->FinalizeResult(&ignored, &ok); #ifndef NDEBUG - GPR_DEBUG_ASSERT(ignored == ops); + DCHECK(ignored == ops); #endif if (do_callback) { diff --git a/include/grpcpp/support/client_callback.h b/include/grpcpp/support/client_callback.h index 1c420815de4..49e52bb37aa 100644 --- a/include/grpcpp/support/client_callback.h +++ b/include/grpcpp/support/client_callback.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -70,7 +72,7 @@ class CallbackUnaryCallImpl { const InputMessage* request, OutputMessage* result, std::function on_completion) { grpc::CompletionQueue* cq = channel->CallbackCQ(); - GPR_ASSERT(cq != nullptr); + CHECK_NE(cq, nullptr); grpc::internal::Call call(channel->CreateCall(method, context, cq)); using FullCallOpSet = grpc::internal::CallOpSet< @@ -304,7 +306,7 @@ class ClientBidiReactor : public internal::ClientReactor { /// The argument to AddMultipleHolds must be positive. void AddHold() { AddMultipleHolds(1); } void AddMultipleHolds(int holds) { - GPR_DEBUG_ASSERT(holds > 0); + DCHECK_GT(holds, 0); stream_->AddHold(holds); } void RemoveHold() { stream_->RemoveHold(); } @@ -368,7 +370,7 @@ class ClientReadReactor : public internal::ClientReactor { void AddHold() { AddMultipleHolds(1); } void AddMultipleHolds(int holds) { - GPR_DEBUG_ASSERT(holds > 0); + DCHECK_GT(holds, 0); reader_->AddHold(holds); } void RemoveHold() { reader_->RemoveHold(); } @@ -400,7 +402,7 @@ class ClientWriteReactor : public internal::ClientReactor { void AddHold() { AddMultipleHolds(1); } void AddMultipleHolds(int holds) { - GPR_DEBUG_ASSERT(holds > 0); + DCHECK_GT(holds, 0); writer_->AddHold(holds); } void RemoveHold() { writer_->RemoveHold(); } @@ -461,7 +463,7 @@ class ClientCallbackReaderWriterImpl public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackReaderWriterImpl)); + CHECK_EQ(size, sizeof(ClientCallbackReaderWriterImpl)); } // This operator should never be called as the memory should be freed as part @@ -469,7 +471,7 @@ class ClientCallbackReaderWriterImpl // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() ABSL_LOCKS_EXCLUDED(start_mu_) override { // This call initiates two batches, plus any backlog, each with a callback @@ -527,7 +529,7 @@ class ClientCallbackReaderWriterImpl write_ops_.ClientSendClose(); } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(msg, options).ok()); + CHECK(write_ops_.SendMessagePtr(msg, options).ok()); callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed); if (GPR_UNLIKELY(corked_write_needed_)) { write_ops_.SendInitialMetadata(&context_->send_initial_metadata_, @@ -719,7 +721,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackReaderImpl)); + CHECK_EQ(size, sizeof(ClientCallbackReaderImpl)); } // This operator should never be called as the memory should be freed as part @@ -727,7 +729,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() override { // This call initiates two batches, plus any backlog, each with a callback @@ -804,7 +806,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader { : context_(context), call_(call), reactor_(reactor) { this->BindReactor(reactor); // TODO(vjpai): don't assert - GPR_ASSERT(start_ops_.SendMessagePtr(request).ok()); + CHECK(start_ops_.SendMessagePtr(request).ok()); start_ops_.ClientSendClose(); } @@ -880,7 +882,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackWriterImpl)); + CHECK_EQ(size, sizeof(ClientCallbackWriterImpl)); } // This operator should never be called as the memory should be freed as part @@ -888,7 +890,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() ABSL_LOCKS_EXCLUDED(start_mu_) override { // This call initiates two batches, plus any backlog, each with a callback @@ -929,7 +931,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter { write_ops_.ClientSendClose(); } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(msg, options).ok()); + CHECK(write_ops_.SendMessagePtr(msg, options).ok()); callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed); if (GPR_UNLIKELY(corked_write_needed_)) { @@ -1110,7 +1112,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackUnaryImpl)); + CHECK_EQ(size, sizeof(ClientCallbackUnaryImpl)); } // This operator should never be called as the memory should be freed as part @@ -1118,7 +1120,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() override { // This call initiates two batches, each with a callback @@ -1157,7 +1159,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary { : context_(context), call_(call), reactor_(reactor) { this->BindReactor(reactor); // TODO(vjpai): don't assert - GPR_ASSERT(start_ops_.SendMessagePtr(request).ok()); + CHECK(start_ops_.SendMessagePtr(request).ok()); start_ops_.ClientSendClose(); finish_ops_.RecvMessage(response); finish_ops_.AllowNoMessage(); diff --git a/include/grpcpp/support/client_interceptor.h b/include/grpcpp/support/client_interceptor.h index b2b9dc76917..3bcb2f16256 100644 --- a/include/grpcpp/support/client_interceptor.h +++ b/include/grpcpp/support/client_interceptor.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -139,7 +141,7 @@ class ClientRpcInfo { // Runs interceptor at pos \a pos. void RunInterceptor( experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_ASSERT(pos < interceptors_.size()); + CHECK_LT(pos, interceptors_.size()); interceptors_[pos]->Intercept(interceptor_methods); } diff --git a/include/grpcpp/support/method_handler.h b/include/grpcpp/support/method_handler.h index def30a0ad8c..51821c6da38 100644 --- a/include/grpcpp/support/method_handler.h +++ b/include/grpcpp/support/method_handler.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_METHOD_HANDLER_H #define GRPCPP_SUPPORT_METHOD_HANDLER_H +#include "absl/log/check.h" + #include #include #include @@ -57,7 +59,7 @@ template template void UnaryRunHandlerHelper(const MethodHandler::HandlerParameter& param, ResponseType* rsp, grpc::Status& status) { - GPR_ASSERT(!param.server_context->sent_initial_metadata_); + CHECK(!param.server_context->sent_initial_metadata_); grpc::internal::CallOpSet diff --git a/include/grpcpp/support/proto_buffer_reader.h b/include/grpcpp/support/proto_buffer_reader.h index ffec8d76416..f5431d462e4 100644 --- a/include/grpcpp/support/proto_buffer_reader.h +++ b/include/grpcpp/support/proto_buffer_reader.h @@ -21,6 +21,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/cord.h" #include @@ -75,7 +76,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { if (backup_count_ > 0) { *data = GRPC_SLICE_START_PTR(*slice_) + GRPC_SLICE_LENGTH(*slice_) - backup_count_; - GPR_ASSERT(backup_count_ <= INT_MAX); + CHECK_LE(backup_count_, INT_MAX); *size = static_cast(backup_count_); backup_count_ = 0; return true; @@ -86,7 +87,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { } *data = GRPC_SLICE_START_PTR(*slice_); // On win x64, int is only 32bit - GPR_ASSERT(GRPC_SLICE_LENGTH(*slice_) <= INT_MAX); + CHECK_LE(GRPC_SLICE_LENGTH(*slice_), static_cast(INT_MAX)); byte_count_ += * size = static_cast(GRPC_SLICE_LENGTH(*slice_)); return true; } @@ -98,7 +99,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { /// bytes that have already been returned by the last call of Next. /// So do the backup and have that ready for a later Next. void BackUp(int count) override { - GPR_ASSERT(count <= static_cast(GRPC_SLICE_LENGTH(*slice_))); + CHECK_LE(count, static_cast(GRPC_SLICE_LENGTH(*slice_))); backup_count_ = count; } @@ -174,7 +175,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { return true; } } - GPR_ASSERT(count == 0); + CHECK_EQ(count, 0); return true; } #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED diff --git a/include/grpcpp/support/proto_buffer_writer.h b/include/grpcpp/support/proto_buffer_writer.h index 83d81060e87..351b2b826d9 100644 --- a/include/grpcpp/support/proto_buffer_writer.h +++ b/include/grpcpp/support/proto_buffer_writer.h @@ -21,6 +21,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/cord.h" #include @@ -64,7 +65,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { total_size_(total_size), byte_count_(0), have_backup_(false) { - GPR_ASSERT(!byte_buffer->Valid()); + CHECK(!byte_buffer->Valid()); /// Create an empty raw byte buffer and look at its underlying slice buffer grpc_byte_buffer* bp = grpc_raw_byte_buffer_create(nullptr, 0); byte_buffer->set_buffer(bp); @@ -81,7 +82,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { /// safe for the caller to write from data[0, size - 1]. bool Next(void** data, int* size) override { // Protobuf should not ask for more memory than total_size_. - GPR_ASSERT(byte_count_ < total_size_); + CHECK_LT(byte_count_, total_size_); // 1. Use the remaining backup slice if we have one // 2. Otherwise allocate a slice, up to the remaining length needed // or our maximum allocation size @@ -106,7 +107,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { } *data = GRPC_SLICE_START_PTR(slice_); // On win x64, int is only 32bit - GPR_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); + CHECK(GRPC_SLICE_LENGTH(slice_) <= static_cast(INT_MAX)); byte_count_ += * size = static_cast(GRPC_SLICE_LENGTH(slice_)); // Using grpc_slice_buffer_add could modify slice_ and merge it with the // previous slice. Therefore, use grpc_slice_buffer_add_indexed method to @@ -131,7 +132,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { /// 2. Split it into the needed (if any) and unneeded part /// 3. Add the needed part back to the slice buffer /// 4. Mark that we still have the remaining part (for later use/unref) - GPR_ASSERT(count <= static_cast(GRPC_SLICE_LENGTH(slice_))); + CHECK_LE(count, static_cast(GRPC_SLICE_LENGTH(slice_))); grpc_slice_buffer_pop(slice_buffer_); if (static_cast(count) == GRPC_SLICE_LENGTH(slice_)) { backup_slice_ = slice_; diff --git a/include/grpcpp/support/server_interceptor.h b/include/grpcpp/support/server_interceptor.h index ecb4e342598..c30d0aee495 100644 --- a/include/grpcpp/support/server_interceptor.h +++ b/include/grpcpp/support/server_interceptor.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -100,7 +102,7 @@ class ServerRpcInfo { // Runs interceptor at pos \a pos. void RunInterceptor( experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_ASSERT(pos < interceptors_.size()); + CHECK_LT(pos, interceptors_.size()); interceptors_[pos]->Intercept(interceptor_methods); } diff --git a/include/grpcpp/support/sync_stream.h b/include/grpcpp/support/sync_stream.h index ce583f6ed7c..ab6ced7343b 100644 --- a/include/grpcpp/support/sync_stream.h +++ b/include/grpcpp/support/sync_stream.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_SYNC_STREAM_H #define GRPCPP_SUPPORT_SYNC_STREAM_H +#include "absl/log/check.h" + #include #include #include @@ -184,7 +186,7 @@ class ClientReader final : public ClientReaderInterface { /// the server will be accessible through the \a ClientContext used to /// construct this object. void WaitForInitialMetadata() override { - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(!context_->initial_metadata_received_); grpc::internal::CallOpSet ops; ops.RecvInitialMetadata(context_); @@ -230,7 +232,7 @@ class ClientReader final : public ClientReaderInterface { grpc::Status status; ops.ClientRecvStatus(context_, &status); call_.PerformOps(&ops); - GPR_ASSERT(cq_.Pluck(&ops)); + CHECK(cq_.Pluck(&ops)); return status; } @@ -259,7 +261,7 @@ class ClientReader final : public ClientReaderInterface { ops.SendInitialMetadata(&context->send_initial_metadata_, context->initial_metadata_flags()); // TODO(ctiller): don't assert - GPR_ASSERT(ops.SendMessagePtr(&request).ok()); + CHECK(ops.SendMessagePtr(&request).ok()); ops.ClientSendClose(); call_.PerformOps(&ops); cq_.Pluck(&ops); @@ -306,7 +308,7 @@ class ClientWriter : public ClientWriterInterface { /// Once complete, the initial metadata read from the server will be /// accessible through the \a ClientContext used to construct this object. void WaitForInitialMetadata() { - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(!context_->initial_metadata_received_); grpc::internal::CallOpSet ops; ops.RecvInitialMetadata(context_); @@ -364,7 +366,7 @@ class ClientWriter : public ClientWriterInterface { } finish_ops_.ClientRecvStatus(context_, &status); call_.PerformOps(&finish_ops_); - GPR_ASSERT(cq_.Pluck(&finish_ops_)); + CHECK(cq_.Pluck(&finish_ops_)); return status; } @@ -455,7 +457,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface { /// Once complete, the initial metadata read from the server will be /// accessible through the \a ClientContext used to construct this object. void WaitForInitialMetadata() override { - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(!context_->initial_metadata_received_); grpc::internal::CallOpSet ops; ops.RecvInitialMetadata(context_); @@ -536,7 +538,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface { grpc::Status status; ops.ClientRecvStatus(context_, &status); call_.PerformOps(&ops); - GPR_ASSERT(cq_.Pluck(&ops)); + CHECK(cq_.Pluck(&ops)); return status; } @@ -583,7 +585,7 @@ class ServerReader final : public ServerReaderInterface { /// for semantics. Note that initial metadata will be affected by the /// \a ServerContext associated with this call. void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); grpc::internal::CallOpSet ops; ops.SendInitialMetadata(&ctx_->initial_metadata_, @@ -640,7 +642,7 @@ class ServerWriter final : public ServerWriterInterface { /// Note that initial metadata will be affected by the /// \a ServerContext associated with this call. void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); grpc::internal::CallOpSet ops; ops.SendInitialMetadata(&ctx_->initial_metadata_, @@ -713,7 +715,7 @@ class ServerReaderWriterBody final { : call_(call), ctx_(ctx) {} void SendInitialMetadata() { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); grpc::internal::CallOpSet ops; ops.SendInitialMetadata(&ctx_->initial_metadata_,