Patch-Source: https://github.com/protobuf-c/protobuf-c/pull/556 -- From 66a0b0d205224f63f19dd8f96abf9dcdc2112331 Mon Sep 17 00:00:00 2001 From: Xiangyu Chen Date: Wed, 29 Mar 2023 14:25:17 +0800 Subject: [PATCH 1/3] add support of protobuf 4.22.x after upgrade the protobuf to 4.22.x, the protobuf-c cannot compile anymore (#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 --- Makefile.am | 2 +- configure.ac | 8 ++++++++ protoc-c/c_bytes_field.h | 1 - protoc-c/c_enum.h | 1 - protoc-c/c_enum_field.h | 1 - protoc-c/c_extension.h | 1 - protoc-c/c_field.cc | 2 +- protoc-c/c_field.h | 3 --- protoc-c/c_file.h | 1 - protoc-c/c_generator.h | 2 -- protoc-c/c_helpers.cc | 4 ++-- protoc-c/c_message.cc | 4 ++-- protoc-c/c_message.h | 1 - protoc-c/c_message_field.h | 3 --- protoc-c/c_primitive_field.cc | 6 +++--- protoc-c/c_primitive_field.h | 3 --- protoc-c/c_service.h | 1 - protoc-c/c_string_field.h | 1 - 18 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Makefile.am b/Makefile.am index c7339efe..3b0d1d66 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index f5a0261e..8ed549ac 100644 --- a/configure.ac +++ b/configure.ac @@ -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])] diff --git a/protoc-c/c_bytes_field.h b/protoc-c/c_bytes_field.h index bf873f0f..8fc63d35 100644 --- a/protoc-c/c_bytes_field.h +++ b/protoc-c/c_bytes_field.h @@ -88,7 +88,6 @@ class BytesFieldGenerator : public FieldGenerator { private: std::map variables_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(BytesFieldGenerator); }; diff --git a/protoc-c/c_enum.h b/protoc-c/c_enum.h index 9c34b697..d5e58f0a 100644 --- a/protoc-c/c_enum.h +++ b/protoc-c/c_enum.h @@ -107,7 +107,6 @@ class EnumGenerator { const EnumDescriptor* descriptor_; std::string dllexport_decl_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); }; } // namespace c diff --git a/protoc-c/c_enum_field.h b/protoc-c/c_enum_field.h index 3f8c005d..03eb4028 100644 --- a/protoc-c/c_enum_field.h +++ b/protoc-c/c_enum_field.h @@ -86,7 +86,6 @@ class EnumFieldGenerator : public FieldGenerator { private: std::map variables_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); }; diff --git a/protoc-c/c_extension.h b/protoc-c/c_extension.h index 95413885..9c5797d6 100644 --- a/protoc-c/c_extension.h +++ b/protoc-c/c_extension.h @@ -99,7 +99,6 @@ class ExtensionGenerator { std::string type_traits_; std::string dllexport_decl_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); }; } // namespace c diff --git a/protoc-c/c_field.cc b/protoc-c/c_field.cc index 0716744a..4abdc6d3 100644 --- a/protoc-c/c_field.cc +++ b/protoc-c/c_field.cc @@ -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()]; } diff --git a/protoc-c/c_field.h b/protoc-c/c_field.h index 3cad35d3..76d3b0bc 100644 --- a/protoc-c/c_field.h +++ b/protoc-c/c_field.h @@ -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. @@ -122,7 +120,6 @@ class FieldGeneratorMap { static FieldGenerator* MakeGenerator(const FieldDescriptor* field); - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); }; } // namespace c diff --git a/protoc-c/c_file.h b/protoc-c/c_file.h index 8dfd8ba0..ec55906e 100644 --- a/protoc-c/c_file.h +++ b/protoc-c/c_file.h @@ -104,7 +104,6 @@ class FileGenerator { std::unique_ptr[]> service_generators_; std::unique_ptr[]> extension_generators_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); }; } // namespace c diff --git a/protoc-c/c_generator.h b/protoc-c/c_generator.h index ac1ffafe..92601164 100644 --- a/protoc-c/c_generator.h +++ b/protoc-c/c_generator.h @@ -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 diff --git a/protoc-c/c_helpers.cc b/protoc-c/c_helpers.cc index 6fd0cd3a..1eaeeb42 100644 --- a/protoc-c/c_helpers.cc +++ b/protoc-c/c_helpers.cc @@ -286,7 +286,7 @@ const char* const kKeywordList[] = { std::set MakeKeywordsMap() { std::set 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; @@ -548,7 +548,7 @@ std::string CEscape(const std::string& src) { std::unique_ptr 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); } diff --git a/protoc-c/c_message.cc b/protoc-c/c_message.cc index 37e8bf8b..c7e85155 100755 --- a/protoc-c/c_message.cc +++ b/protoc-c/c_message.cc @@ -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()) @@ -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) diff --git a/protoc-c/c_message.h b/protoc-c/c_message.h index ea1c3ab3..e90782bf 100644 --- a/protoc-c/c_message.h +++ b/protoc-c/c_message.h @@ -137,7 +137,6 @@ class MessageGenerator { std::unique_ptr[]> enum_generators_; std::unique_ptr[]> extension_generators_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); }; } // namespace c diff --git a/protoc-c/c_message_field.h b/protoc-c/c_message_field.h index 39b8d999..42efe368 100644 --- a/protoc-c/c_message_field.h +++ b/protoc-c/c_message_field.h @@ -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); }; diff --git a/protoc-c/c_primitive_field.cc b/protoc-c/c_primitive_field.cc index 6990893f..d5a7b60c 100644 --- a/protoc-c/c_primitive_field.cc +++ b/protoc-c/c_primitive_field.cc @@ -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. @@ -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"; } } @@ -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. diff --git a/protoc-c/c_primitive_field.h b/protoc-c/c_primitive_field.h index a9eb893b..d2bb7243 100644 --- a/protoc-c/c_primitive_field.h +++ b/protoc-c/c_primitive_field.h @@ -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 diff --git a/protoc-c/c_service.h b/protoc-c/c_service.h index 27125a60..4737ff3b 100644 --- a/protoc-c/c_service.h +++ b/protoc-c/c_service.h @@ -101,7 +101,6 @@ class ServiceGenerator { const ServiceDescriptor* descriptor_; std::map vars_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); }; } // namespace c diff --git a/protoc-c/c_string_field.h b/protoc-c/c_string_field.h index 513cea75..ba258e44 100644 --- a/protoc-c/c_string_field.h +++ b/protoc-c/c_string_field.h @@ -88,7 +88,6 @@ class StringFieldGenerator : public FieldGenerator { private: std::map variables_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator); }; From 7706c95d4835e75f182ab56d9dad5c8cd8517e0a Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Sat, 24 Jun 2023 22:13:35 -0700 Subject: [PATCH 2/3] Use cxx17 instead of cxx14 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 8ed549ac..c8d894e0 100644 --- a/configure.ac +++ b/configure.ac @@ -78,8 +78,8 @@ 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)]) +# now checking 4.22.x protobuf, if so, set cxx as 17 + AS_IF([pkg-config --atleast-version 4.22.0 protobuf],[AX_CXX_COMPILE_STDCXX(17, 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], From 66574f3fd85a205eb7c90b790477d5415364209e Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Sat, 24 Jun 2023 22:15:42 -0700 Subject: [PATCH 3/3] Use FileDescriptorLegacy for deprecated syntax() --- protoc-c/c_file.cc | 2 +- protoc-c/c_helpers.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/protoc-c/c_file.cc b/protoc-c/c_file.cc index 59c1824e..4b60b889 100644 --- a/protoc-c/c_file.cc +++ b/protoc-c/c_file.cc @@ -119,7 +119,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { int min_header_version = 1000000; #if defined(HAVE_PROTO3) - if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) { + if (FileDescriptorLegacy(file_).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3) { min_header_version = 1003000; } #endif diff --git a/protoc-c/c_helpers.h b/protoc-c/c_helpers.h index 7598a4e1..87deea24 100644 --- a/protoc-c/c_helpers.h +++ b/protoc-c/c_helpers.h @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -172,7 +173,7 @@ int compare_name_indices_by_name(const void*, const void*); // This wrapper is needed to be able to compile against protobuf2. inline int FieldSyntax(const FieldDescriptor* field) { #ifdef HAVE_PROTO3 - return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2; + return FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3 ? 3 : 2; #else return 2; #endif