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
27 changes: 24 additions & 3 deletions protoc/CppFileGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -79,7 +79,7 @@ void FileGenerator::GenerateHeader(Printer *printer) {
const string filename_identifier = FilenameIdentifier(m_output_name);

std::map<string, string> 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;

Expand Down 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
2 changes: 1 addition & 1 deletion protoc/CppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions protoc/GeneratorHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
38 changes: 38 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,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"
Expand All @@ -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++) {
Expand All @@ -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"
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
Loading