diff options
author | Yang Gao <yangg@google.com> | 2015-10-13 10:11:07 -0700 |
---|---|---|
committer | Yang Gao <yangg@google.com> | 2015-10-13 10:11:07 -0700 |
commit | a538c40b54abed273cdcc11f2ba4ea9c9f55d6a7 (patch) | |
tree | 94f4c0e6905a6d2d5df9c0fa76c4a2deb4eed98c | |
parent | 041d90ada9301d73be4c2daf291b56df547f826e (diff) | |
parent | 7f715707aabc2e0a9a4b85b51eab98ef9cf61050 (diff) |
Merge pull request #3806 from vjpai/plugin_nullptr
C++ code generator plugin: eliminate use of nullptr
-rw-r--r-- | src/compiler/cpp_generator.cc | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 1bf2b16ed6..3c8ca8ab45 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -585,7 +585,7 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, "class Service : public ::grpc::SynchronousService {\n" " public:\n"); printer->Indent(); - printer->Print("Service() : service_(nullptr) {}\n"); + printer->Print("Service();\n"); printer->Print("virtual ~Service();\n"); for (int i = 0; i < service->method_count(); ++i) { PrintHeaderServerMethodSync(printer, service->method(i), vars); @@ -594,7 +594,7 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, printer->Outdent(); printer->Print( " private:\n" - " ::grpc::RpcService* service_;\n"); + " std::unique_ptr< ::grpc::RpcService> service_;\n"); printer->Print("};\n"); // Server side - Asynchronous @@ -1014,8 +1014,10 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, "{}\n\n"); printer->Print(*vars, + "$ns$$Service$::Service::Service() {\n" + "}\n\n"); + printer->Print(*vars, "$ns$$Service$::Service::~Service() {\n" - " delete service_;\n" "}\n\n"); for (int i = 0; i < service->method_count(); ++i) { (*vars)["Idx"] = as_string(i); @@ -1026,10 +1028,10 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, "::grpc::RpcService* $ns$$Service$::Service::service() {\n"); printer->Indent(); printer->Print( - "if (service_ != nullptr) {\n" - " return service_;\n" + "if (service_) {\n" + " return service_.get();\n" "}\n"); - printer->Print("service_ = new ::grpc::RpcService();\n"); + printer->Print("service_ = std::unique_ptr< ::grpc::RpcService>(new ::grpc::RpcService());\n"); for (int i = 0; i < service->method_count(); ++i) { const grpc::protobuf::MethodDescriptor *method = service->method(i); (*vars)["Idx"] = as_string(i); @@ -1077,7 +1079,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, " std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); } } - printer->Print("return service_;\n"); + printer->Print("return service_.get();\n"); printer->Outdent(); printer->Print("}\n\n"); } |