From 20458806e816f3c01e8a62389bdf6fe612b441e4 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 17 Oct 2019 05:20:41 -0700 Subject: [PATCH] Remove asserts from impl/codegen --- .../grpcpp/impl/codegen/async_stream_impl.h | 52 +++++++++---------- .../impl/codegen/async_unary_call_impl.h | 11 ++-- include/grpcpp/impl/codegen/call_op_set.h | 1 - include/grpcpp/impl/codegen/callback_common.h | 8 +-- .../impl/codegen/client_callback_impl.h | 16 +++--- 5 files changed, 43 insertions(+), 45 deletions(-) diff --git a/include/grpcpp/impl/codegen/async_stream_impl.h b/include/grpcpp/impl/codegen/async_stream_impl.h index d9fa5f9968a..f832f5e457a 100644 --- a/include/grpcpp/impl/codegen/async_stream_impl.h +++ b/include/grpcpp/impl/codegen/async_stream_impl.h @@ -198,7 +198,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) { - assert(size == sizeof(ClientAsyncReader)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientAsyncReader)); } // This operator should never be called as the memory should be freed as part @@ -206,10 +206,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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void StartCall(void* tag) override { - assert(!started_); + GPR_CODEGEN_ASSERT(!started_); started_ = true; StartCallInternal(tag); } @@ -223,7 +223,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { /// calling code can access the received metadata through the /// \a ClientContext. void ReadInitialMetadata(void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); @@ -232,7 +232,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { } void Read(R* msg, void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); read_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { read_ops_.RecvInitialMetadata(context_); @@ -247,7 +247,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 { - assert(started_); + GPR_CODEGEN_ASSERT(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -269,7 +269,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { if (start) { StartCallInternal(tag); } else { - assert(tag == nullptr); + GPR_CODEGEN_ASSERT(tag == nullptr); } } @@ -347,7 +347,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) { - assert(size == sizeof(ClientAsyncWriter)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientAsyncWriter)); } // This operator should never be called as the memory should be freed as part @@ -355,10 +355,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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void StartCall(void* tag) override { - assert(!started_); + GPR_CODEGEN_ASSERT(!started_); started_ = true; StartCallInternal(tag); } @@ -371,7 +371,7 @@ 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 { - assert(started_); + GPR_CODEGEN_ASSERT(started_); GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); @@ -380,7 +380,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { } void Write(const W& msg, void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); write_ops_.set_output_tag(tag); // TODO(ctiller): don't assert GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); @@ -388,7 +388,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { } void Write(const W& msg, ::grpc::WriteOptions options, void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); write_ops_.set_output_tag(tag); if (options.is_last_message()) { options.set_buffer_hint(); @@ -400,7 +400,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { } void WritesDone(void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); write_ops_.set_output_tag(tag); write_ops_.ClientSendClose(); call_.PerformOps(&write_ops_); @@ -414,7 +414,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 { - assert(started_); + GPR_CODEGEN_ASSERT(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -435,7 +435,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { if (start) { StartCallInternal(tag); } else { - assert(tag == nullptr); + GPR_CODEGEN_ASSERT(tag == nullptr); } } @@ -515,7 +515,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) { - assert(size == sizeof(ClientAsyncReaderWriter)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientAsyncReaderWriter)); } // This operator should never be called as the memory should be freed as part @@ -523,10 +523,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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void StartCall(void* tag) override { - assert(!started_); + GPR_CODEGEN_ASSERT(!started_); started_ = true; StartCallInternal(tag); } @@ -539,7 +539,7 @@ 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 { - assert(started_); + GPR_CODEGEN_ASSERT(started_); GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); @@ -548,7 +548,7 @@ class ClientAsyncReaderWriter final } void Read(R* msg, void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); read_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { read_ops_.RecvInitialMetadata(context_); @@ -558,7 +558,7 @@ class ClientAsyncReaderWriter final } void Write(const W& msg, void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); write_ops_.set_output_tag(tag); // TODO(ctiller): don't assert GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); @@ -566,7 +566,7 @@ class ClientAsyncReaderWriter final } void Write(const W& msg, ::grpc::WriteOptions options, void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); write_ops_.set_output_tag(tag); if (options.is_last_message()) { options.set_buffer_hint(); @@ -578,7 +578,7 @@ class ClientAsyncReaderWriter final } void WritesDone(void* tag) override { - assert(started_); + GPR_CODEGEN_ASSERT(started_); write_ops_.set_output_tag(tag); write_ops_.ClientSendClose(); call_.PerformOps(&write_ops_); @@ -589,7 +589,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 { - assert(started_); + GPR_CODEGEN_ASSERT(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -607,7 +607,7 @@ class ClientAsyncReaderWriter final if (start) { StartCallInternal(tag); } else { - assert(tag == nullptr); + GPR_CODEGEN_ASSERT(tag == nullptr); } } diff --git a/include/grpcpp/impl/codegen/async_unary_call_impl.h b/include/grpcpp/impl/codegen/async_unary_call_impl.h index e885a077031..e7a2101226d 100644 --- a/include/grpcpp/impl/codegen/async_unary_call_impl.h +++ b/include/grpcpp/impl/codegen/async_unary_call_impl.h @@ -19,7 +19,6 @@ #ifndef GRPCPP_IMPL_CODEGEN_ASYNC_UNARY_CALL_IMPL_H #define GRPCPP_IMPL_CODEGEN_ASYNC_UNARY_CALL_IMPL_H -#include #include #include #include @@ -97,7 +96,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) { - assert(size == sizeof(ClientAsyncResponseReader)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientAsyncResponseReader)); } // This operator should never be called as the memory should be freed as part @@ -105,10 +104,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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void StartCall() override { - assert(!started_); + GPR_CODEGEN_ASSERT(!started_); started_ = true; StartCallInternal(); } @@ -120,7 +119,7 @@ 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 { - assert(started_); + GPR_CODEGEN_ASSERT(started_); GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); single_buf.set_output_tag(tag); @@ -135,7 +134,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 { - assert(started_); + GPR_CODEGEN_ASSERT(started_); if (initial_metadata_read_) { finish_buf.set_output_tag(tag); finish_buf.RecvMessage(msg); diff --git a/include/grpcpp/impl/codegen/call_op_set.h b/include/grpcpp/impl/codegen/call_op_set.h index 4d56d0b6e59..ac1a76cdb2c 100644 --- a/include/grpcpp/impl/codegen/call_op_set.h +++ b/include/grpcpp/impl/codegen/call_op_set.h @@ -19,7 +19,6 @@ #ifndef GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H #define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H -#include #include #include #include diff --git a/include/grpcpp/impl/codegen/callback_common.h b/include/grpcpp/impl/codegen/callback_common.h index 5adf4596c85..9b6fe4527a5 100644 --- a/include/grpcpp/impl/codegen/callback_common.h +++ b/include/grpcpp/impl/codegen/callback_common.h @@ -70,7 +70,7 @@ class CallbackWithStatusTag public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - assert(size == sizeof(CallbackWithStatusTag)); + GPR_CODEGEN_ASSERT(size == sizeof(CallbackWithStatusTag)); } // This operator should never be called as the memory should be freed as part @@ -78,7 +78,7 @@ class CallbackWithStatusTag // 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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } CallbackWithStatusTag(grpc_call* call, std::function f, CompletionQueueTag* ops) @@ -134,7 +134,7 @@ class CallbackWithSuccessTag public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - assert(size == sizeof(CallbackWithSuccessTag)); + GPR_CODEGEN_ASSERT(size == sizeof(CallbackWithSuccessTag)); } // This operator should never be called as the memory should be freed as part @@ -142,7 +142,7 @@ class CallbackWithSuccessTag // 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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } CallbackWithSuccessTag() : call_(nullptr) {} diff --git a/include/grpcpp/impl/codegen/client_callback_impl.h b/include/grpcpp/impl/codegen/client_callback_impl.h index 34c738ac1e6..e9bec012114 100644 --- a/include/grpcpp/impl/codegen/client_callback_impl.h +++ b/include/grpcpp/impl/codegen/client_callback_impl.h @@ -422,7 +422,7 @@ class ClientCallbackReaderWriterImpl public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - assert(size == sizeof(ClientCallbackReaderWriterImpl)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientCallbackReaderWriterImpl)); } // This operator should never be called as the memory should be freed as part @@ -430,7 +430,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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void MaybeFinish() { if (GPR_UNLIKELY(callbacks_outstanding_.fetch_sub( @@ -634,7 +634,7 @@ class ClientCallbackReaderImpl public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - assert(size == sizeof(ClientCallbackReaderImpl)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientCallbackReaderImpl)); } // This operator should never be called as the memory should be freed as part @@ -642,7 +642,7 @@ class ClientCallbackReaderImpl // 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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void MaybeFinish() { if (GPR_UNLIKELY(callbacks_outstanding_.fetch_sub( @@ -774,7 +774,7 @@ class ClientCallbackWriterImpl public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - assert(size == sizeof(ClientCallbackWriterImpl)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientCallbackWriterImpl)); } // This operator should never be called as the memory should be freed as part @@ -782,7 +782,7 @@ class ClientCallbackWriterImpl // 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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void MaybeFinish() { if (GPR_UNLIKELY(callbacks_outstanding_.fetch_sub( @@ -962,7 +962,7 @@ class ClientCallbackUnaryImpl final : public experimental::ClientCallbackUnary { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - assert(size == sizeof(ClientCallbackUnaryImpl)); + GPR_CODEGEN_ASSERT(size == sizeof(ClientCallbackUnaryImpl)); } // This operator should never be called as the memory should be freed as part @@ -970,7 +970,7 @@ class ClientCallbackUnaryImpl final : public experimental::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*) { assert(0); } + static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } void StartCall() override { // This call initiates two batches, each with a callback