diff --git a/include/grpcpp/impl/codegen/message_allocator.h b/include/grpcpp/impl/codegen/message_allocator.h index 8f37d36eb8b..28702a4500f 100644 --- a/include/grpcpp/impl/codegen/message_allocator.h +++ b/include/grpcpp/impl/codegen/message_allocator.h @@ -16,8 +16,8 @@ * */ -#ifndef GRPCPP_IMPL_CODEGEN_MESSAGE_ALLOCATOR_H_ -#define GRPCPP_IMPL_CODEGEN_MESSAGE_ALLOCATOR_H_ +#ifndef GRPCPP_IMPL_CODEGEN_MESSAGE_ALLOCATOR_H +#define GRPCPP_IMPL_CODEGEN_MESSAGE_ALLOCATOR_H namespace grpc { @@ -50,4 +50,4 @@ class MessageAllocator { } // namespace grpc -#endif // GRPCPP_IMPL_CODEGEN_MESSAGE_ALLOCATOR_H_ +#endif // GRPCPP_IMPL_CODEGEN_MESSAGE_ALLOCATOR_H diff --git a/include/grpcpp/impl/codegen/server_callback.h b/include/grpcpp/impl/codegen/server_callback.h index 030e4aea92a..359472bc392 100644 --- a/include/grpcpp/impl/codegen/server_callback.h +++ b/include/grpcpp/impl/codegen/server_callback.h @@ -604,8 +604,6 @@ class CallbackUnaryHandler : public MethodHandler { ctx_->BeginCompletionOp(call, [this](bool) { MaybeDone(); }, nullptr); } - ~ServerCallbackRpcControllerImpl() {} - const RequestType* request() { return allocator_info_->request; } ResponseType* response() { return allocator_info_->response; } @@ -613,7 +611,6 @@ class CallbackUnaryHandler : public MethodHandler { if (--callbacks_outstanding_ == 0) { grpc_call* call = call_.call(); auto call_requester = std::move(call_requester_); - this->~ServerCallbackRpcControllerImpl(); // explicitly call destructor if (allocator_ != nullptr) { allocator_->DeallocateMessages(allocator_info_); } else { @@ -624,6 +621,7 @@ class CallbackUnaryHandler : public MethodHandler { allocator_info_->response->~ResponseType(); } } + this->~ServerCallbackRpcControllerImpl(); // explicitly call destructor g_core_codegen_interface->grpc_call_unref(call); call_requester(); } diff --git a/include/grpcpp/support/message_allocator.h b/include/grpcpp/support/message_allocator.h index eb1dbb14764..20ce072b901 100644 --- a/include/grpcpp/support/message_allocator.h +++ b/include/grpcpp/support/message_allocator.h @@ -16,9 +16,9 @@ * */ -#ifndef GRPCPP_SUPPORT_MESSAGE_ALLOCATOR_H_ -#define GRPCPP_SUPPORT_MESSAGE_ALLOCATOR_H_ +#ifndef GRPCPP_SUPPORT_MESSAGE_ALLOCATOR_H +#define GRPCPP_SUPPORT_MESSAGE_ALLOCATOR_H #include -#endif // GRPCPP_SUPPORT_MESSAGE_ALLOCATOR_H_ +#endif // GRPCPP_SUPPORT_MESSAGE_ALLOCATOR_H diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index 7f9fd29026e..175ab821858 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -41,6 +41,8 @@ #include namespace grpc { +template +class MessageAllocator; class CompletionQueue; class Channel; class ServerCompletionQueue; @@ -330,7 +332,18 @@ class ServiceA final { ::grpc::testing::Response* response, ::grpc::experimental::ServerCallbackRpcController* controller) { return this->MethodA1(context, request, response, controller); - })); + }, nullptr)); + } + void SetMessageAllocatorFor_MethodA1( + ::grpc::MessageAllocator<::grpc::testing::Request, ::grpc::testing::Response>* allocator) { + ::grpc::Service::experimental().MarkMethodCallback(0, + new ::grpc::internal::CallbackUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>( + [this](::grpc::ServerContext* context, + const ::grpc::testing::Request* request, + ::grpc::testing::Response* response, + ::grpc::experimental::ServerCallbackRpcController* controller) { + return this->MethodA1(context, request, response, controller); + }, allocator)); } ~ExperimentalWithCallbackMethod_MethodA1() override { BaseClassMustBeDerivedFromService(this); @@ -798,7 +811,18 @@ class ServiceB final { ::grpc::testing::Response* response, ::grpc::experimental::ServerCallbackRpcController* controller) { return this->MethodB1(context, request, response, controller); - })); + }, nullptr)); + } + void SetMessageAllocatorFor_MethodB1( + ::grpc::MessageAllocator<::grpc::testing::Request, ::grpc::testing::Response>* allocator) { + ::grpc::Service::experimental().MarkMethodCallback(0, + new ::grpc::internal::CallbackUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>( + [this](::grpc::ServerContext* context, + const ::grpc::testing::Request* request, + ::grpc::testing::Response* response, + ::grpc::experimental::ServerCallbackRpcController* controller) { + return this->MethodB1(context, request, response, controller); + }, allocator)); } ~ExperimentalWithCallbackMethod_MethodB1() override { BaseClassMustBeDerivedFromService(this);