From 72111c3b5ab1a52f23cc82d46a16307a27edd178 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 13 Nov 2024 18:47:28 -0800 Subject: [PATCH] Update compat extension APIs to something that does not assume contiguous storage PiperOrigin-RevId: 696346042 --- .../Reflection/FeatureSetDescriptor.g.cs | 17 ----------------- upb/message/compat.c | 16 +++++++++++----- upb/message/compat.h | 6 ++++-- 3 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs 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/upb/message/compat.c b/upb/message/compat.c index ffe758a86f..1bb2adc544 100644 --- a/upb/message/compat.c +++ b/upb/message/compat.c @@ -17,13 +17,19 @@ // Must be last. #include "upb/port/def.inc" -const upb_MiniTableExtension* upb_Message_ExtensionByIndex( - const upb_Message* msg, size_t index) { +bool upb_Message_NextExtension(const upb_Message* msg, + const upb_MiniTableExtension** result, + uintptr_t* iter) { size_t count; const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - - UPB_ASSERT(index < count); - return ext[index].ext; + size_t i = *iter; + if (i >= count) { + return false; + *result = NULL; + } + *result = ext[i].ext; + *iter = i + 1; + return true; } const upb_MiniTableExtension* upb_Message_FindExtensionByNumber( diff --git a/upb/message/compat.h b/upb/message/compat.h index c14484f74b..14ed2fe271 100644 --- a/upb/message/compat.h +++ b/upb/message/compat.h @@ -25,9 +25,11 @@ extern "C" { #endif -const upb_MiniTableExtension* upb_Message_ExtensionByIndex( - const upb_Message* msg, size_t index); +#define kUpb_Message_ExtensionBegin 0; +bool upb_Message_NextExtension(const upb_Message* msg, + const upb_MiniTableExtension** result, + uintptr_t* iter); // Returns the minitable with the given field number, or NULL on failure. const upb_MiniTableExtension* upb_Message_FindExtensionByNumber( const upb_Message* msg, uint32_t field_number);