Skip to content

Commit

Permalink
add support of protobuf 4.22.x
Browse files Browse the repository at this point in the history
after upgrade the protobuf to 4.22.x, the protobuf-c cannot compile anymore (protobuf-c#544) due to following changes:
1.protobuf using c++14, that cause the command_line_interface.h report error
2.protobuf using abseil-cpp library instead the trace API with GOOGLE_ header
3. removed GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
  • Loading branch information
chenxy1988 committed Mar 29, 2023
1 parent abc67a1 commit 66a0b0d
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AM_CPPFLAGS = \
-I${top_builddir} \
-I${top_srcdir}
AM_CFLAGS = ${my_CFLAGS}
AM_LDFLAGS =
AM_LDFLAGS = ${ABSL_LOG_INTERNAL_CHECK_OP_LIBS} ${ABSL_LOG_RAW_HASH_SET_LIBS}

# code coverage

Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ if test "x$enable_protoc" != "xno"; then

AX_CXX_COMPILE_STDCXX(11, noext, mandatory)

# now checking 4.22.x protobuf, if so, set cxx as 14
AS_IF([pkg-config --atleast-version 4.22.0 protobuf],[AX_CXX_COMPILE_STDCXX(14, noext, mandatory)])

AS_IF([pkg-config --atleast-version 4.22.0 protobuf],
[PKG_CHECK_MODULES([ABSL_LOG_INTERNAL_CHECK_OP], [absl_log_internal_check_op],
[PKG_CHECK_MODULES([ABSL_LOG_RAW_HASH_SET], [absl_raw_hash_set], [], [AC_MSG_ERROR([Missing absl_raw_hash_set library.])])],
[AC_MSG_ERROR([Missing absl_log_internal_check_op library.])])])

PKG_CHECK_MODULES([protobuf], [protobuf >= 3.0.0],
[proto3_supported=yes],
[PKG_CHECK_MODULES([protobuf], [protobuf >= 2.6.0])]
Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_bytes_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class BytesFieldGenerator : public FieldGenerator {
private:
std::map<std::string, std::string> variables_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(BytesFieldGenerator);
};


Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class EnumGenerator {
const EnumDescriptor* descriptor_;
std::string dllexport_decl_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
};

} // namespace c
Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_enum_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class EnumFieldGenerator : public FieldGenerator {
private:
std::map<std::string, std::string> variables_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
};


Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class ExtensionGenerator {
std::string type_traits_;
std::string dllexport_decl_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
};

} // namespace c
Expand Down
2 changes: 1 addition & 1 deletion protoc-c/c_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ FieldGeneratorMap::~FieldGeneratorMap() {}

const FieldGenerator& FieldGeneratorMap::get(
const FieldDescriptor* field) const {
GOOGLE_CHECK_EQ(field->containing_type(), descriptor_);
ABSL_CHECK_EQ(field->containing_type(), descriptor_);
return *field_generators_[field->index()];
}

Expand Down
3 changes: 0 additions & 3 deletions protoc-c/c_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ class FieldGenerator {
const std::string &descriptor_addr) const;
const FieldDescriptor *descriptor_;

private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);
};

// Convenience class which constructs FieldGenerators for a Descriptor.
Expand All @@ -122,7 +120,6 @@ class FieldGeneratorMap {

static FieldGenerator* MakeGenerator(const FieldDescriptor* field);

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
};

} // namespace c
Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class FileGenerator {
std::unique_ptr<std::unique_ptr<ServiceGenerator>[]> service_generators_;
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
};

} // namespace c
Expand Down
2 changes: 0 additions & 2 deletions protoc-c/c_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class PROTOC_C_EXPORT CGenerator : public CodeGenerator {
OutputDirectory* output_directory,
std::string* error) const;

private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CGenerator);
};

} // namespace c
Expand Down
4 changes: 2 additions & 2 deletions protoc-c/c_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const char* const kKeywordList[] = {

std::set<std::string> MakeKeywordsMap() {
std::set<std::string> result;
for (int i = 0; i < GOOGLE_ARRAYSIZE(kKeywordList); i++) {
for (int i = 0; i < ABSL_ARRAYSIZE(kKeywordList); i++) {
result.insert(kKeywordList[i]);
}
return result;
Expand Down Expand Up @@ -548,7 +548,7 @@ std::string CEscape(const std::string& src) {
std::unique_ptr<char[]> dest(new char[dest_length]);
const int len = CEscapeInternal(src.data(), src.size(),
dest.get(), dest_length, false);
GOOGLE_DCHECK_GE(len, 0);
ABSL_DCHECK_GE(len, 0);
return std::string(dest.get(), len);
}

Expand Down
4 changes: 2 additions & 2 deletions protoc-c/c_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ GenerateMessageDescriptor(io::Printer* printer, bool gen_init) {
// NOTE: not supported by protobuf
vars["maybe_static"] = "";
vars["field_dv_ctype"] = "{ ... }";
GOOGLE_LOG(DFATAL) << "Messages can't have default values!";
ABSL_LOG(FATAL) << "Messages can't have default values!";
break;
case FieldDescriptor::CPPTYPE_STRING:
if (fd->type() == FieldDescriptor::TYPE_BYTES || opt.string_as_bytes())
Expand All @@ -521,7 +521,7 @@ GenerateMessageDescriptor(io::Printer* printer, bool gen_init) {
break;
}
default:
GOOGLE_LOG(DFATAL) << "Unknown CPPTYPE";
ABSL_LOG(FATAL) << "Unknown CPPTYPE";
break;
}
if (!already_defined)
Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class MessageGenerator {
std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_;
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
};

} // namespace c
Expand Down
3 changes: 0 additions & 3 deletions protoc-c/c_message_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ class MessageFieldGenerator : public FieldGenerator {
std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const;

private:

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
};


Expand Down
6 changes: 3 additions & 3 deletions protoc-c/c_primitive_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const
case FieldDescriptor::TYPE_STRING :
case FieldDescriptor::TYPE_BYTES :
case FieldDescriptor::TYPE_GROUP :
case FieldDescriptor::TYPE_MESSAGE : GOOGLE_LOG(FATAL) << "not a primitive type"; break;
case FieldDescriptor::TYPE_MESSAGE : ABSL_LOG(FATAL) << "not a primitive type"; break;

// No default because we want the compiler to complain if any new
// types are added.
Expand Down Expand Up @@ -143,7 +143,7 @@ std::string PrimitiveFieldGenerator::GetDefaultValue() const
case FieldDescriptor::CPPTYPE_BOOL:
return descriptor_->default_value_bool() ? "1" : "0";
default:
GOOGLE_LOG(DFATAL) << "unexpected CPPTYPE in c_primitive_field";
ABSL_LOG(FATAL) << "unexpected CPPTYPE in c_primitive_field";
return "UNEXPECTED_CPPTYPE";
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer
case FieldDescriptor::TYPE_STRING :
case FieldDescriptor::TYPE_BYTES :
case FieldDescriptor::TYPE_GROUP :
case FieldDescriptor::TYPE_MESSAGE : GOOGLE_LOG(FATAL) << "not a primitive type"; break;
case FieldDescriptor::TYPE_MESSAGE : ABSL_LOG(FATAL) << "not a primitive type"; break;

// No default because we want the compiler to complain if any new
// types are added.
Expand Down
3 changes: 0 additions & 3 deletions protoc-c/c_primitive_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ class PrimitiveFieldGenerator : public FieldGenerator {
std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const;

private:

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator);
};

} // namespace c
Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class ServiceGenerator {
const ServiceDescriptor* descriptor_;
std::map<std::string, std::string> vars_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator);
};

} // namespace c
Expand Down
1 change: 0 additions & 1 deletion protoc-c/c_string_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class StringFieldGenerator : public FieldGenerator {
private:
std::map<std::string, std::string> variables_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator);
};


Expand Down

0 comments on commit 66a0b0d

Please sign in to comment.