Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion protoc/CppFileGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ void FileGenerator::GenerateImplementation(Printer *printer) {
"#include \"$file$.pb.h\"\n"
"\n"
"#include <google/protobuf/descriptor.h> // NOLINT(build/include)\n"
#if GOOGLE_PROTOBUF_VERSION < 4022000
"#include <google/protobuf/stubs/once.h>\n"
#else
"#include <absl/base/call_once.h>\n"
"#include <absl/log/absl_check.h>\n"
"#include <absl/log/absl_log.h>\n"
#endif
"\n"
"#include \"common/rpc/RpcChannel.h\"\n"
"#include \"common/rpc/RpcController.h\"\n"
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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"
Expand All @@ -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
}
}
Expand Down
33 changes: 33 additions & 0 deletions protoc/ServiceGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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++) {
Expand All @@ -308,17 +322,28 @@ 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"
#else
" ::google::protobuf::internal::DownCast<\n"
" const $input_type$*>(request),\n"
" ::google::protobuf::internal::DownCast<\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"
Expand All @@ -339,7 +364,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++) {
Expand All @@ -358,7 +387,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"
Expand Down
5 changes: 5 additions & 0 deletions protoc/ServiceGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ class ServiceGenerator {
const ServiceDescriptor* descriptor_;
std::map<string, string> vars_;

#if GOOGLE_PROTOBUF_VERSION < 4022000
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator);
#else
ServiceGenerator(const ServiceGenerator&) = delete;
ServiceGenerator& operator=(const ServiceGenerator&) = delete;
#endif
};

} // namespace ola
Expand Down
8 changes: 8 additions & 0 deletions protoc/StrUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
#include <google/protobuf/stubs/stl_util.h>
#endif // HAVE_GOOGLE_PROTOBUF_STUBS_STL_UTIL_H

#if GOOGLE_PROTOBUF_VERSION >= 4022000
#include <absl/log/absl_check.h>
#include <absl/log/absl_log.h>
#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.
//
Expand Down