diff --git a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs b/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs deleted file mode 100644 index 208ce1fcb6..0000000000 --- a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs +++ /dev/null @@ -1,17 +0,0 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd -#endregion - -namespace Google.Protobuf.Reflection; - -internal sealed partial class FeatureSetDescriptor -{ - // Canonical serialized form of the edition defaults, generated by embed_edition_defaults. - private const string DefaultsBase64 = - "ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH"; -} diff --git a/hpb/extension.h b/hpb/extension.h index 0fa0272768..6dea740af9 100644 --- a/hpb/extension.h +++ b/hpb/extension.h @@ -127,18 +127,16 @@ upb_ExtensionRegistry* GetUpbExtensions( class ExtensionRegistry { public: - ExtensionRegistry( - const std::vector& extensions, - const upb::Arena& arena) - : registry_(upb_ExtensionRegistry_New(arena.ptr())) { + explicit ExtensionRegistry(const upb::Arena& arena) + : registry_(upb_ExtensionRegistry_New(arena.ptr())) {} + + template + void AddExtension(const ExtensionIdentifier& id) { if (registry_) { - for (const auto extension : extensions) { - const auto* ext = extension; - bool success = upb_ExtensionRegistry_AddArray(registry_, &ext, 1); - if (!success) { - registry_ = nullptr; - break; - } + auto* extension = id.mini_table_ext(); + bool success = upb_ExtensionRegistry_AddArray(registry_, &extension, 1); + if (!success) { + registry_ = nullptr; } } } diff --git a/hpb/internal/message_lock_test.cc b/hpb/internal/message_lock_test.cc index cd82386a8b..a05e4a7bc7 100644 --- a/hpb/internal/message_lock_test.cc +++ b/hpb/internal/message_lock_test.cc @@ -18,6 +18,7 @@ #include "absl/hash/hash.h" #include "absl/log/absl_check.h" #include "google/protobuf/compiler/hpb/tests/test_model.upb.proto.h" +#include "google/protobuf/hpb/extension.h" #include "google/protobuf/hpb/hpb.h" #include "upb/mem/arena.hpp" #include "upb/mini_table/extension.h" @@ -105,24 +106,27 @@ void TestConcurrentExtensionAccess(::hpb::ExtensionRegistry registry) { } TEST(CppGeneratedCode, ConcurrentAccessDoesNotRaceBothLazy) { - ::upb::Arena arena; - TestConcurrentExtensionAccess({{}, arena}); + upb::Arena arena; + hpb::ExtensionRegistry registry(arena); + TestConcurrentExtensionAccess(registry); } TEST(CppGeneratedCode, ConcurrentAccessDoesNotRaceOneLazyOneEager) { - ::upb::Arena arena; - std::vector e1{theme.mini_table_ext()}; - TestConcurrentExtensionAccess({e1, arena}); - std::vector e2{ - ThemeExtension::theme_extension.mini_table_ext()}; - TestConcurrentExtensionAccess({e2, arena}); + upb::Arena arena; + hpb::ExtensionRegistry r1(arena); + r1.AddExtension(theme); + TestConcurrentExtensionAccess(r1); + hpb::ExtensionRegistry r2(arena); + r2.AddExtension(ThemeExtension::theme_extension); + TestConcurrentExtensionAccess(r2); } TEST(CppGeneratedCode, ConcurrentAccessDoesNotRaceBothEager) { ::upb::Arena arena; - std::vector exts{ - theme.mini_table_ext(), ThemeExtension::theme_extension.mini_table_ext()}; - TestConcurrentExtensionAccess({exts, arena}); + hpb::ExtensionRegistry registry(arena); + registry.AddExtension(theme); + registry.AddExtension(ThemeExtension::theme_extension); + TestConcurrentExtensionAccess(registry); } } // namespace diff --git a/hpb_generator/tests/test_generated.cc b/hpb_generator/tests/test_generated.cc index d42a49c147..6aa436646d 100644 --- a/hpb_generator/tests/test_generated.cc +++ b/hpb_generator/tests/test_generated.cc @@ -1019,11 +1019,11 @@ TEST(CppGeneratedCode, ParseWithExtensionRegistry) { ::upb::Arena arena; auto bytes = ::hpb::Serialize(&model, arena); EXPECT_EQ(true, bytes.ok()); - std::vector exts{ - theme.mini_table_ext(), other_ext.mini_table_ext(), - ThemeExtension::theme_extension.mini_table_ext()}; - ::hpb::ExtensionRegistry extensions(exts, arena); + hpb::ExtensionRegistry extensions(arena); + extensions.AddExtension(theme); + extensions.AddExtension(other_ext); + extensions.AddExtension(ThemeExtension::theme_extension); TestModel parsed_model = ::hpb::Parse(bytes.value(), extensions).value(); EXPECT_EQ("Test123", parsed_model.str1()); @@ -1287,8 +1287,8 @@ TEST(CppGeneratedCode, HasExtensionAndRegistry) { std::string data = std::string(::hpb::Serialize(&source, arena).value()); // Test with ExtensionRegistry - std::vector exts{theme.mini_table_ext()}; - hpb::ExtensionRegistry extensions(exts, arena); + hpb::ExtensionRegistry extensions(arena); + extensions.AddExtension(theme); TestModel parsed_model = ::hpb::Parse(data, extensions).value(); EXPECT_TRUE(::hpb::HasExtension(&parsed_model, theme)); }