diff --git a/protoc/CppFileGenerator.cpp b/protoc/CppFileGenerator.cpp index a0eb51d0ce..77642f6e1d 100644 --- a/protoc/CppFileGenerator.cpp +++ b/protoc/CppFileGenerator.cpp @@ -59,7 +59,7 @@ FileGenerator::FileGenerator(const FileDescriptor *file, const string &output_name) : m_file(file), m_output_name(output_name) { - SplitStringUsing(file->package(), ".", &package_parts_); + SplitStringUsing(string(file->package()), ".", &package_parts_); ServiceGenerator::Options options; for (int i = 0; i < file->service_count(); i++) { @@ -79,7 +79,7 @@ void FileGenerator::GenerateHeader(Printer *printer) { const string filename_identifier = FilenameIdentifier(m_output_name); std::map var_map; - var_map["basename"] = StripProto(m_file->name()); + var_map["basename"] = StripProto(string(m_file->name())); var_map["filename"] = m_file->name(); var_map["filename_identifier"] = filename_identifier; @@ -130,7 +130,13 @@ void FileGenerator::GenerateImplementation(Printer *printer) { "#include \"$file$.pb.h\"\n" "\n" "#include // NOLINT(build/include)\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 "#include \n" +#else + "#include \n" + "#include \n" + "#include \n" +#endif "\n" "#include \"common/rpc/RpcChannel.h\"\n" "#include \"common/rpc/RpcController.h\"\n" @@ -215,7 +221,11 @@ void FileGenerator::GenerateBuildDescriptors(Printer* printer) { " \"$filename$\");\n" // Note that this GOOGLE_CHECK is necessary to prevent a warning about // "file" being unused when compiling an empty .proto file. +#if GOOGLE_PROTOBUF_VERSION < 4022000 "GOOGLE_CHECK(file != NULL);\n", +#else + "ABSL_CHECK(file != NULL);\n", +#endif "filename", m_file->name()); for (int i = 0; i < m_file->service_count(); i++) { @@ -248,7 +258,7 @@ void FileGenerator::GenerateBuildDescriptors(Printer* printer) { "assigndescriptorsname", GlobalAssignDescriptorsName(m_output_name)); printer->Print("} // namespace\n"); -#else +#elif GOOGLE_PROTOBUF_VERSION < 4022000 printer->Print( "namespace {\n" "\n" @@ -260,6 +270,17 @@ void FileGenerator::GenerateBuildDescriptors(Printer* printer) { "\n", "assigndescriptorsname", GlobalAssignDescriptorsName(m_output_name)); printer->Print("} // namespace\n"); +#else + printer->Print( + "namespace {\n" + "\n" + "inline void protobuf_AssignDescriptorsOnce() {\n" + " static ::absl::once_flag once;\n" + " ::absl::call_once(once, &$assigndescriptorsname$);\n" + "}\n" + "\n", + "assigndescriptorsname", GlobalAssignDescriptorsName(m_output_name)); + printer->Print("} // namespace\n"); #endif } } diff --git a/protoc/CppGenerator.cpp b/protoc/CppGenerator.cpp index 2730f5de11..a66abd3b4a 100644 --- a/protoc/CppGenerator.cpp +++ b/protoc/CppGenerator.cpp @@ -43,7 +43,7 @@ bool CppGenerator::Generate(const FileDescriptor *file, const string&, OutputDirectory *generator_context, string*) const { - string basename = StripProto(file->name()) + "Service"; + string basename = StripProto(string(file->name())) + "Service"; string header_name = basename + ".pb.h"; string code_name = basename + ".pb.cpp"; diff --git a/protoc/GeneratorHelpers.cpp b/protoc/GeneratorHelpers.cpp index 28f8bd40cf..b71d9f4907 100644 --- a/protoc/GeneratorHelpers.cpp +++ b/protoc/GeneratorHelpers.cpp @@ -69,13 +69,13 @@ string ClassName(const Descriptor* descriptor, bool qualified) { const Descriptor* outer = descriptor; while (outer->containing_type() != NULL) outer = outer->containing_type(); - const string& outer_name = outer->full_name(); - string inner_name = descriptor->full_name().substr(outer_name.size()); + const string& outer_name = string(outer->full_name()); + string inner_name = string(descriptor->full_name()).substr(outer_name.size()); if (qualified) { return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name); } else { - return outer->name() + DotsToUnderscores(inner_name); + return string(outer->name()) + DotsToUnderscores(inner_name); } } diff --git a/protoc/ServiceGenerator.cpp b/protoc/ServiceGenerator.cpp index 47c1d6735f..d67c95aa4c 100644 --- a/protoc/ServiceGenerator.cpp +++ b/protoc/ServiceGenerator.cpp @@ -130,7 +130,12 @@ void ServiceGenerator::GenerateInterface(Printer* printer) { printer->Print(vars_, "\n" " private:\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$);\n" +#else + " $classname$(const $classname$&) = delete;\n" + " $classname$& operator=(const $classname$&) = delete;\n" +#endif "};\n" "\n"); } @@ -178,7 +183,12 @@ void ServiceGenerator::GenerateStubDefinition(Printer* printer) { " private:\n" " ola::rpc::RpcChannel* channel_;\n" " bool owns_channel_;\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$_Stub);\n" +#else + " $classname$_Stub(const $classname$_Stub&) = delete;\n" + " $classname$_Stub& operator=(const $classname$_Stub&) = delete;\n" +#endif "};\n" "\n"); } @@ -291,7 +301,11 @@ void ServiceGenerator::GenerateCallMethod(Printer* printer) { " const ::google::protobuf::Message* request,\n" " ::google::protobuf::Message* response,\n" " ola::rpc::RpcService::CompletionCallback* done) {\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DCHECK_EQ(method->service(), $classname$_descriptor_);\n" +#else + " ABSL_DCHECK_EQ(method->service(), $classname$_descriptor_);\n" +#endif " switch (method->index()) {\n"); for (int i = 0; i < descriptor_->method_count(); i++) { @@ -308,17 +322,33 @@ void ServiceGenerator::GenerateCallMethod(Printer* printer) { " case $index$:\n" " $name$(\n" " controller,\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " ::google::protobuf::down_cast<\n" " const $input_type$*>(request),\n" " ::google::protobuf::down_cast<\n" " $output_type$*>(response),\n" +#elif GOOGLE_PROTOBUF_VERSION < 6030000 + " ::google::protobuf::internal::DownCast<\n" + " const $input_type$*>(request),\n" + " ::google::protobuf::internal::DownCast<\n" + " $output_type$*>(response),\n" +#else + " ::google::protobuf::DownCastMessage<\n" + " $input_type$>(request),\n" + " ::google::protobuf::DownCastMessage<\n" + " $output_type$>(response),\n" +#endif " done);\n" " break;\n"); } printer->Print(vars_, " default:\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_LOG(FATAL) << \"Bad method index; this should never " +#else + " ABSL_LOG(FATAL) << \"Bad method index; this should never " +#endif "happen.\";\n" " break;\n" " }\n" @@ -339,7 +369,11 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, printer->Print(vars_, " const ::google::protobuf::MethodDescriptor* method) const {\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DCHECK_EQ(method->service(), descriptor());\n" +#else + " ABSL_DCHECK_EQ(method->service(), descriptor());\n" +#endif " switch (method->index()) {\n"); for (int i = 0; i < descriptor_->method_count(); i++) { @@ -358,7 +392,11 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, printer->Print(vars_, " default:\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen." +#else + " ABSL_LOG(FATAL) << \"Bad method index; this should never happen." +#endif "\";\n" " return *static_cast< ::google::protobuf::Message*>(NULL);\n" " }\n" diff --git a/protoc/ServiceGenerator.h b/protoc/ServiceGenerator.h index d6be12abfb..e9f2b12eec 100644 --- a/protoc/ServiceGenerator.h +++ b/protoc/ServiceGenerator.h @@ -114,7 +114,12 @@ class ServiceGenerator { const ServiceDescriptor* descriptor_; std::map vars_; +#if GOOGLE_PROTOBUF_VERSION < 4022000 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); +#else + ServiceGenerator(const ServiceGenerator&) = delete; + ServiceGenerator& operator=(const ServiceGenerator&) = delete; +#endif }; } // namespace ola diff --git a/protoc/StrUtil.cpp b/protoc/StrUtil.cpp index 6c6c338ee2..31e73d6dff 100644 --- a/protoc/StrUtil.cpp +++ b/protoc/StrUtil.cpp @@ -56,6 +56,14 @@ #include #endif // HAVE_GOOGLE_PROTOBUF_STUBS_STL_UTIL_H +#if GOOGLE_PROTOBUF_VERSION >= 4022000 +#include +#include +#define GOOGLE_CHECK ABSL_CHECK +#define GOOGLE_DCHECK_LT ABSL_CHECK_LT +#define GOOGLE_LOG_IF(LEVEL, VECTOR) ABSL_LOG_IF(LEVEL, VECTOR) +#endif + #ifdef _WIN32 // MSVC has only _snprintf, not snprintf. //