From 0093eb8354f7ca023d915af4da8d0cd435d32d15 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 31 Jan 2023 13:11:17 -0800 Subject: [PATCH] Internal changes to extensions. PiperOrigin-RevId: 506091325 --- src/google/protobuf/descriptor.cc | 13 +++++++++++-- src/google/protobuf/descriptor.h | 5 +++++ src/google/protobuf/descriptor_unittest.cc | 3 +++ src/google/protobuf/port_def.inc | 4 ++++ src/google/protobuf/port_undef.inc | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 63236f4a15..a7b33fc247 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -62,8 +63,11 @@ #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" +#include "absl/strings/strip.h" #include "absl/strings/substitute.h" #include "absl/synchronization/mutex.h" +#include "absl/types/optional.h" #include "google/protobuf/any.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor_database.h" @@ -1872,6 +1876,7 @@ void DescriptorPool::AddUnusedImportTrackFile(absl::string_view file_name, unused_import_track_files_[file_name] = is_error; } + void DescriptorPool::ClearUnusedImportTrackFiles() { unused_import_track_files_.clear(); } @@ -1912,7 +1917,10 @@ DescriptorPool* DescriptorPool::internal_generated_pool() { const DescriptorPool* DescriptorPool::generated_pool() { const DescriptorPool* pool = internal_generated_pool(); - // Ensure that descriptor.proto has been registered in the generated pool. + // Ensure that descriptor.proto gets registered in the generated pool. It is a + // special case because it is included in the full runtime. We have to avoid + // registering it pre-main, because we need to ensure that the linker + // --gc-sections step can strip out the full runtime if it is unused. DescriptorProto::descriptor(); return pool; } @@ -6473,6 +6481,7 @@ void DescriptorBuilder::CrossLinkExtensionRange( } } + void DescriptorBuilder::CrossLinkField(FieldDescriptor* field, const FieldDescriptorProto& proto) { if (field->options_ == nullptr) { @@ -7111,7 +7120,7 @@ void DescriptorBuilder::ValidateFieldOptions( // determine whether the json_name option is set on the field. Here we // compare it against the default calculated json_name value and consider // the option set if they are different. This won't catch the case when - // an user explicitly sets json_name to the default value, but should be + // a user explicitly sets json_name to the default value, but should be // good enough to catch common misuses. if (field->is_extension() && (field->has_json_name() && diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 21a97cb4c9..1caf5c194b 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -70,6 +70,7 @@ #include "absl/log/absl_log.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" +#include "absl/types/optional.h" #include "google/protobuf/port.h" // Must be included last. @@ -116,6 +117,7 @@ class MethodOptions; class FileOptions; class UninterpretedOption; class SourceCodeInfo; +class ExtensionMetadata; // Defined in message.h class Message; @@ -140,6 +142,7 @@ class Formatter; namespace descriptor_unittest { class DescriptorTest; +class ValidationErrorTest; } // namespace descriptor_unittest // Defined in printer.h @@ -2087,6 +2090,7 @@ class PROTOBUF_EXPORT DescriptorPool { friend class FileDescriptor; friend class DescriptorBuilder; friend class FileDescriptorTables; + friend class google::protobuf::descriptor_unittest::ValidationErrorTest; // Return true if the given name is a sub-symbol of any non-package // descriptor that already exists in the descriptor pool. (The full @@ -2162,6 +2166,7 @@ class PROTOBUF_EXPORT DescriptorPool { // Set of files to track for unused imports. The bool value when true means // unused imports are treated as errors (and as warnings when false). absl::flat_hash_map unused_import_track_files_; + }; diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 88661a0f1e..51f34753fb 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -47,6 +47,7 @@ #include "absl/log/die_if_null.h" #include "absl/log/scoped_mock_log.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_custom_options.pb.h" #include "google/protobuf/stubs/common.h" @@ -3937,6 +3938,7 @@ class ValidationErrorTest : public testing::Test { return ABSL_DIE_IF_NULL(pool_.BuildFile(file_proto)); } + // Parse file_text as a FileDescriptorProto in text format and add it // to the DescriptorPool. Expect errors to be produced which match the // given error text. @@ -7078,6 +7080,7 @@ TEST_F(ValidationErrorTest, UnusedImportWithOtherError) { } + TEST_F(ValidationErrorTest, PackageTooLong) { BuildFileWithErrors( "name: \"foo.proto\" " diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index a8a75766ec..adf67d55ab 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -208,6 +208,10 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and // Owner: mkruskal@ #define PROTOBUF_FUTURE_REMOVE_CLEARED_API 1 +// Used for descriptor proto extension declarations. +// Owner: shaod@, gberg@ +#define PROTOBUF_FUTURE_DESCRIPTOR_EXTENSION_DECL 1 + #endif #ifdef PROTOBUF_VERSION diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index cc945eb9a0..fa75fda26d 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -119,6 +119,7 @@ #ifdef PROTOBUF_FUTURE_BREAKING_CHANGES #undef PROTOBUF_FUTURE_BREAKING_CHANGES #undef PROTOBUF_FUTURE_REMOVE_CLEARED_API +#undef PROTOBUF_FUTURE_DESCRIPTOR_EXTENSION_DECL #endif // Restore macros that may have been #undef'd in port_def.inc.