diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 4a5b7c9286..5597cdedf7 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -2523,7 +2523,7 @@ TEST_F(ParseDescriptorDebugTest, TestCustomOptions) { ASSERT_TRUE(pool_.BuildFile(any_import) != nullptr); const FileDescriptor* actual = pool_.BuildFile(parsed); - ASSERT_TRUE(actual != nullptr); + ASSERT_TRUE(actual != nullptr) << error_collector_.text_; parsed.Clear(); actual->CopyTo(&parsed); diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 26aa6dc3aa..09c5d34f0a 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -1104,6 +1104,7 @@ bool AllowedExtendeeInProto3(const std::string& name) { return allowed_proto3_extendees->find(name) != allowed_proto3_extendees->end(); } + } // anonymous namespace // Contains tables specific to a particular file. These tables are not @@ -2681,6 +2682,7 @@ void Descriptor::CopyTo(DescriptorProto* proto) const { if (&options() != &MessageOptions::default_instance()) { proto->mutable_options()->CopyFrom(options()); } + } void Descriptor::CopyJsonNameTo(DescriptorProto* proto) const { @@ -2753,6 +2755,7 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const { if (&options() != &FieldOptions::default_instance()) { proto->mutable_options()->CopyFrom(options()); } + } void FieldDescriptor::CopyJsonNameTo(FieldDescriptorProto* proto) const { @@ -3948,10 +3951,9 @@ class DescriptorBuilder { internal::FlatAllocator& alloc); - // Allocates an array of two strings, the first one is a copy of `proto_name`, - // and the second one is the full name. - // Full proto name is "scope.proto_name" if scope is non-empty and - // "proto_name" otherwise. + // Allocates an array of two strings, the first one is a copy of + // `proto_name`, and the second one is the full name. Full proto name is + // "scope.proto_name" if scope is non-empty and "proto_name" otherwise. const std::string* AllocateNameStrings(const std::string& scope, const std::string& proto_name, internal::FlatAllocator& alloc); @@ -4208,6 +4210,8 @@ class DescriptorBuilder { const OneofDescriptorProto& proto); void ValidateFieldOptions(const FieldDescriptor* field, const FieldDescriptorProto& proto); + void ValidateFieldFeatures(const FieldDescriptor* field, + const FieldDescriptorProto& proto); void ValidateEnumOptions(const EnumDescriptor* enm, const EnumDescriptorProto& proto); void ValidateEnumValueOptions(const EnumValueDescriptor* enum_value, @@ -5596,9 +5600,12 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, } // Copy options. - result->options_ = - AllocateOptions(proto, result, DescriptorProto::kOptionsFieldNumber, - "google.protobuf.MessageOptions", alloc); + { + MessageOptions* options = + AllocateOptions(proto, result, DescriptorProto::kOptionsFieldNumber, + "google.protobuf.MessageOptions", alloc); + result->options_ = options; // Set to default_instance later if necessary. + } AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result)); @@ -6088,9 +6095,12 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, } // Copy options. - result->options_ = - AllocateOptions(proto, result, FieldDescriptorProto::kOptionsFieldNumber, - "google.protobuf.FieldOptions", alloc); + { + FieldOptions* options = AllocateOptions( + proto, result, FieldDescriptorProto::kOptionsFieldNumber, + "google.protobuf.FieldOptions", alloc); + result->options_ = options; // Set to default_instance later if necessary. + } AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result)); } @@ -7264,6 +7274,8 @@ void DescriptorBuilder::ValidateFieldOptions( return; } + ValidateFieldFeatures(field, proto); + // Only message type fields may be lazy. if (field->options().lazy() || field->options().unverified_lazy()) { if (field->type() != FieldDescriptor::TYPE_MESSAGE) { @@ -7344,6 +7356,10 @@ void DescriptorBuilder::ValidateFieldOptions( } +void DescriptorBuilder::ValidateFieldFeatures( + const FieldDescriptor* field, const FieldDescriptorProto& proto) { +} + void DescriptorBuilder::ValidateEnumOptions(const EnumDescriptor* enm, const EnumDescriptorProto& proto) { VALIDATE_OPTIONS_FROM_ARRAY(enm, value, EnumValue); diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index d191d2b318..034db6dce8 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -299,6 +299,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { // available extensions of that message. const MessageOptions& options() const; + // Write the contents of this Descriptor into the given DescriptorProto. // The target DescriptorProto must be clear before calling this; if it // isn't, the result may be garbage. @@ -874,6 +875,7 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { // descriptor.proto, and any available extensions of that message. const FieldOptions& options() const; + // See Descriptor::CopyTo(). void CopyTo(FieldDescriptorProto* proto) const; diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index eb445af8b7..ded1321720 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -566,7 +566,7 @@ TEST_F(FileDescriptorTest, DebugStringRoundTrip) { ASSERT_EQ("", error_collector.last_error()); proto.set_name(name); const FileDescriptor* descriptor = pool.BuildFile(proto); - ASSERT_TRUE(descriptor != nullptr) << proto.DebugString(); + ASSERT_TRUE(descriptor != nullptr) << error_collector.last_error(); EXPECT_EQ(content, descriptor->DebugString()); } }