From 7d980e44b255dd067c608726732aaf260da6187a Mon Sep 17 00:00:00 2001 From: vjpai Date: Tue, 14 Jul 2015 10:38:30 -0700 Subject: Remove lambda function with lambda capture to allow building with pre-lambda compilers --- include/grpc++/impl/call.h | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index 64fa5d6efb..2716bfe93a 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -172,17 +172,31 @@ class CallOpRecvMessage { grpc_byte_buffer* recv_buf_; }; +namespace CallOpGenericRecvMessageHelper { +class DeserializeFunc { + public: + virtual Status deser(grpc_byte_buffer* buf,int max_message_size) = 0; +}; + +template class DeserializeFuncType : public DeserializeFunc { + public: + DeserializeFuncType(R *message): message_(message) {} + Status deser(grpc_byte_buffer* buf,int max_message_size) { + return SerializationTraits::Deserialize(buf, message_, + max_message_size); + } + private: + R *message_; // Not a managed pointer because management is external to this +}; +}; // namespace CallOpGenericRecvMessageHelper + class CallOpGenericRecvMessage { public: CallOpGenericRecvMessage() : got_message(false) {} - template - void RecvMessage(R* message) { - deserialize_ = [message](grpc_byte_buffer* buf, - int max_message_size) -> Status { - return SerializationTraits::Deserialize(buf, message, - max_message_size); - }; + template void RecvMessage(R* message) { + deserialize_.reset(new CallOpGenericRecvMessageHelper:: + DeserializeFuncType(message)); } bool got_message; @@ -201,7 +215,7 @@ class CallOpGenericRecvMessage { if (recv_buf_) { if (*status) { got_message = true; - *status = deserialize_(recv_buf_, max_message_size).ok(); + *status = deserialize_->deser(recv_buf_, max_message_size).ok(); } else { got_message = false; grpc_byte_buffer_destroy(recv_buf_); @@ -210,12 +224,11 @@ class CallOpGenericRecvMessage { got_message = false; *status = false; } - deserialize_ = DeserializeFunc(); + deserialize_.reset(); } private: - typedef std::function DeserializeFunc; - DeserializeFunc deserialize_; + std::unique_ptr deserialize_; grpc_byte_buffer* recv_buf_; }; -- cgit v1.2.3 From c7eed74dc4718140a0a61a3cae0473224df84e03 Mon Sep 17 00:00:00 2001 From: vjpai Date: Tue, 14 Jul 2015 10:47:28 -0700 Subject: Remove brace initialization for gcc-4.4 compatibility --- src/compiler/objective_c_generator.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index 79a84b4a7a..08b321152d 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -101,11 +101,13 @@ void PrintAdvancedSignature(Printer *printer, } inline map GetMethodVars(const MethodDescriptor *method) { - return {{ "method_name", method->name() }, - { "request_type", method->input_type()->name() }, - { "response_type", method->output_type()->name() }, - { "request_class", ClassName(method->input_type()) }, - { "response_class", ClassName(method->output_type()) }}; + map res; + res["method_name"] = method->name(); + res["request_type"] = method->input_type()->name(); + res["response_type"] = method->output_type()->name(); + res["request_class"] = ClassName(method->input_type()); + res["response_class"] = ClassName(method->output_type()); + return res; } void PrintMethodDeclarations(Printer *printer, -- cgit v1.2.3 From f77ab15c571e0778a9726b9097c2b68609aef040 Mon Sep 17 00:00:00 2001 From: vjpai Date: Tue, 14 Jul 2015 11:51:39 -0700 Subject: Use rvalue ref return to avoid copy --- src/compiler/objective_c_generator.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index 08b321152d..7d674c5106 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -100,14 +100,14 @@ void PrintAdvancedSignature(Printer *printer, PrintMethodSignature(printer, method, vars); } -inline map GetMethodVars(const MethodDescriptor *method) { +inline map&& GetMethodVars(const MethodDescriptor *method) { map res; res["method_name"] = method->name(); res["request_type"] = method->input_type()->name(); res["response_type"] = method->output_type()->name(); res["request_class"] = ClassName(method->input_type()); res["response_class"] = ClassName(method->output_type()); - return res; + return std::forward>(res); } void PrintMethodDeclarations(Printer *printer, -- cgit v1.2.3 From df551611d482351f3d195ee39909bfa13c681eaf Mon Sep 17 00:00:00 2001 From: vjpai Date: Tue, 14 Jul 2015 13:38:44 -0700 Subject: Remove reference to nullptr to avoid compiler seeing ambiguity in gcc-4.4 build. The issue is that gcc below 4.6 require us to explicitly define nullptr, and our explicit definition allows a potential confusion between nullptr->unique_ptr and nullptr->char *->grpc::string->unique_ptr --- test/cpp/end2end/end2end_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index f0d9f75214..59e1173c5d 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -98,7 +98,7 @@ void CheckAuthContext(T* context) { class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { public: - TestServiceImpl() : signal_client_(false), host_(nullptr) {} + TestServiceImpl() : signal_client_(false), host_() {} explicit TestServiceImpl(const grpc::string& host) : signal_client_(false), host_(new grpc::string(host)) {} Status Echo(ServerContext* context, const EchoRequest* request, -- cgit v1.2.3 From 181ef45f5e33180a093483258979b91b4a8f3a05 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 14 Jul 2015 13:52:48 -0700 Subject: Addressing outstanding typos and comments Clang-format of changed files --- include/grpc++/impl/call.h | 26 +++++++------ src/compiler/objective_c_generator.cc | 70 ++++++++++++++++++----------------- test/cpp/end2end/end2end_test.cc | 6 ++- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index 2716bfe93a..9790349d45 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -175,28 +175,30 @@ class CallOpRecvMessage { namespace CallOpGenericRecvMessageHelper { class DeserializeFunc { public: - virtual Status deser(grpc_byte_buffer* buf,int max_message_size) = 0; + virtual Status Deserialize(grpc_byte_buffer* buf, int max_message_size) = 0; }; -template class DeserializeFuncType : public DeserializeFunc { +template +class DeserializeFuncType : public DeserializeFunc { public: - DeserializeFuncType(R *message): message_(message) {} - Status deser(grpc_byte_buffer* buf,int max_message_size) { - return SerializationTraits::Deserialize(buf, message_, - max_message_size); + DeserializeFuncType(R* message) : message_(message) {} + Status Deserialize(grpc_byte_buffer* buf, int max_message_size) { + return SerializationTraits::Deserialize(buf, message_, max_message_size); } + private: - R *message_; // Not a managed pointer because management is external to this + R* message_; // Not a managed pointer because management is external to this }; -}; // namespace CallOpGenericRecvMessageHelper +} // namespace CallOpGenericRecvMessageHelper class CallOpGenericRecvMessage { public: CallOpGenericRecvMessage() : got_message(false) {} - template void RecvMessage(R* message) { - deserialize_.reset(new CallOpGenericRecvMessageHelper:: - DeserializeFuncType(message)); + template + void RecvMessage(R* message) { + deserialize_.reset( + new CallOpGenericRecvMessageHelper::DeserializeFuncType(message)); } bool got_message; @@ -215,7 +217,7 @@ class CallOpGenericRecvMessage { if (recv_buf_) { if (*status) { got_message = true; - *status = deserialize_->deser(recv_buf_, max_message_size).ok(); + *status = deserialize_->Deserialize(recv_buf_, max_message_size).ok(); } else { got_message = false; grpc_byte_buffer_destroy(recv_buf_); diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index 7d674c5106..2a74a3b340 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -57,13 +57,12 @@ void PrintProtoRpcDeclarationAsPragma(Printer *printer, vars["server_stream"] = method->server_streaming() ? "stream " : ""; printer->Print(vars, - "#pragma mark $method_name$($client_stream$$request_type$)" - " returns ($server_stream$$response_type$)\n\n"); + "#pragma mark $method_name$($client_stream$$request_type$)" + " returns ($server_stream$$response_type$)\n\n"); } -void PrintMethodSignature(Printer *printer, - const MethodDescriptor *method, - const map& vars) { +void PrintMethodSignature(Printer *printer, const MethodDescriptor *method, + const map &vars) { // TODO(jcanizales): Print method comments. printer->Print(vars, "- ($return_type$)$method_name$With"); @@ -75,16 +74,17 @@ void PrintMethodSignature(Printer *printer, // TODO(jcanizales): Put this on a new line and align colons. if (method->server_streaming()) { - printer->Print(vars, " eventHandler:(void(^)(BOOL done, " - "$response_class$ *response, NSError *error))eventHandler"); + printer->Print(vars, + " eventHandler:(void(^)(BOOL done, " + "$response_class$ *response, NSError *error))eventHandler"); } else { - printer->Print(vars, " handler:(void(^)($response_class$ *response, " - "NSError *error))handler"); + printer->Print(vars, + " handler:(void(^)($response_class$ *response, " + "NSError *error))handler"); } } -void PrintSimpleSignature(Printer *printer, - const MethodDescriptor *method, +void PrintSimpleSignature(Printer *printer, const MethodDescriptor *method, map vars) { vars["method_name"] = grpc_generator::LowercaseFirstLetter(vars["method_name"]); @@ -92,26 +92,24 @@ void PrintSimpleSignature(Printer *printer, PrintMethodSignature(printer, method, vars); } -void PrintAdvancedSignature(Printer *printer, - const MethodDescriptor *method, +void PrintAdvancedSignature(Printer *printer, const MethodDescriptor *method, map vars) { vars["method_name"] = "RPCTo" + vars["method_name"]; vars["return_type"] = "ProtoRPC *"; PrintMethodSignature(printer, method, vars); } -inline map&& GetMethodVars(const MethodDescriptor *method) { - map res; +inline map GetMethodVars(const MethodDescriptor *method) { + map res; res["method_name"] = method->name(); res["request_type"] = method->input_type()->name(); res["response_type"] = method->output_type()->name(); res["request_class"] = ClassName(method->input_type()); res["response_class"] = ClassName(method->output_type()); - return std::forward>(res); + return res; } -void PrintMethodDeclarations(Printer *printer, - const MethodDescriptor *method) { +void PrintMethodDeclarations(Printer *printer, const MethodDescriptor *method) { map vars = GetMethodVars(method); PrintProtoRpcDeclarationAsPragma(printer, method, vars); @@ -122,8 +120,7 @@ void PrintMethodDeclarations(Printer *printer, printer->Print(";\n\n\n"); } -void PrintSimpleImplementation(Printer *printer, - const MethodDescriptor *method, +void PrintSimpleImplementation(Printer *printer, const MethodDescriptor *method, map vars) { printer->Print("{\n"); printer->Print(vars, " [[self RPCTo$method_name$With"); @@ -180,7 +177,7 @@ void PrintMethodImplementations(Printer *printer, PrintAdvancedImplementation(printer, method, vars); } -} // namespace +} // namespace string GetHeader(const ServiceDescriptor *service) { string output; @@ -188,7 +185,7 @@ string GetHeader(const ServiceDescriptor *service) { // Scope the output stream so it closes and finalizes output to the string. grpc::protobuf::io::StringOutputStream output_stream(&output); Printer printer(&output_stream, '$'); - + printer.Print("@protocol GRXWriteable;\n"); printer.Print("@protocol GRXWriter;\n\n"); @@ -201,12 +198,15 @@ string GetHeader(const ServiceDescriptor *service) { } printer.Print("@end\n\n"); - printer.Print("// Basic service implementation, over gRPC, that only does" + printer.Print( + "// Basic service implementation, over gRPC, that only does" " marshalling and parsing.\n"); - printer.Print(vars, "@interface $service_class$ :" - " ProtoService<$service_class$>\n"); - printer.Print("- (instancetype)initWithHost:(NSString *)host" - " NS_DESIGNATED_INITIALIZER;\n"); + printer.Print(vars, + "@interface $service_class$ :" + " ProtoService<$service_class$>\n"); + printer.Print( + "- (instancetype)initWithHost:(NSString *)host" + " NS_DESIGNATED_INITIALIZER;\n"); printer.Print("@end\n"); } return output; @@ -224,18 +224,20 @@ string GetSource(const ServiceDescriptor *service) { {"package", service->file()->package()}}; printer.Print(vars, - "static NSString *const kPackageName = @\"$package$\";\n"); - printer.Print(vars, - "static NSString *const kServiceName = @\"$service_name$\";\n\n"); + "static NSString *const kPackageName = @\"$package$\";\n"); + printer.Print( + vars, "static NSString *const kServiceName = @\"$service_name$\";\n\n"); printer.Print(vars, "@implementation $service_class$\n\n"); - + printer.Print("// Designated initializer\n"); printer.Print("- (instancetype)initWithHost:(NSString *)host {\n"); - printer.Print(" return (self = [super initWithHost:host" + printer.Print( + " return (self = [super initWithHost:host" " packageName:kPackageName serviceName:kServiceName]);\n"); printer.Print("}\n\n"); - printer.Print("// Override superclass initializer to disallow different" + printer.Print( + "// Override superclass initializer to disallow different" " package and service names.\n"); printer.Print("- (instancetype)initWithHost:(NSString *)host\n"); printer.Print(" packageName:(NSString *)packageName\n"); @@ -252,4 +254,4 @@ string GetSource(const ServiceDescriptor *service) { return output; } -} // namespace grpc_objective_c_generator +} // namespace grpc_objective_c_generator diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 59e1173c5d..207dad5282 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -99,7 +99,8 @@ void CheckAuthContext(T* context) { class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { public: TestServiceImpl() : signal_client_(false), host_() {} - explicit TestServiceImpl(const grpc::string& host) : signal_client_(false), host_(new grpc::string(host)) {} + explicit TestServiceImpl(const grpc::string& host) + : signal_client_(false), host_(new grpc::string(host)) {} Status Echo(ServerContext* context, const EchoRequest* request, EchoResponse* response) GRPC_OVERRIDE { @@ -224,7 +225,8 @@ class TestServiceImplDupPkg class End2endTest : public ::testing::Test { protected: - End2endTest() : kMaxMessageSize_(8192), special_service_("special"), thread_pool_(2) {} + End2endTest() + : kMaxMessageSize_(8192), special_service_("special"), thread_pool_(2) {} void SetUp() GRPC_OVERRIDE { int port = grpc_pick_unused_port_or_die(); -- cgit v1.2.3 From 94fd462df84b6b3395c91c45f5f838a374e8a18e Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 14 Jul 2015 16:18:41 -0700 Subject: override and final --- include/grpc++/impl/call.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index 9790349d45..da8ee5dd18 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -179,10 +179,11 @@ class DeserializeFunc { }; template -class DeserializeFuncType : public DeserializeFunc { +class DeserializeFuncType GRPC_FINAL : public DeserializeFunc { public: DeserializeFuncType(R* message) : message_(message) {} - Status Deserialize(grpc_byte_buffer* buf, int max_message_size) { + Status Deserialize(grpc_byte_buffer* buf, + int max_message_size) GRPC_OVERRIDE { return SerializationTraits::Deserialize(buf, message_, max_message_size); } -- cgit v1.2.3