diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index faf65cba4a..0d052088d7 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5928,6 +5928,25 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { } +#include <stddef.h> +#include <stdint.h> + + +// Must be last. + +const upb_Message_Extension* upb_Message_FindExtensionByNumber( + const upb_Message* msg, uint32_t field_number) { + size_t count = 0; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + + while (count--) { + if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; + ext++; + } + return NULL; +} + + #include <string.h> diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index f10d229abd..a485705d7c 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1625,6 +1625,8 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, // Must be last. +typedef struct upb_Message_Extension upb_Message_Extension; + #ifdef __cplusplus extern "C" { #endif @@ -1747,14 +1749,14 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( // This is rather wasteful for scalars (in the extreme case of bool, // it wastes 15 bytes). We accept this because we expect messages to be // the most common extension type. -typedef struct { +struct upb_Message_Extension { const upb_MiniTableExtension* ext; union { upb_StringView str; void* ptr; char scalar_data[8]; } data; -} upb_Message_Extension; +}; #ifdef __cplusplus extern "C" { @@ -12383,6 +12385,34 @@ UPB_INLINE bool _upb_NonAtomic_CompareExchangeStrongP(void* addr, #endif // UPB_PORT_ATOMIC_H_ +#ifndef UPB_MESSAGE_COMPAT_H_ +#define UPB_MESSAGE_COMPAT_H_ + +#include <stdint.h> + + +// Must be last. + +// upb does not support mixing minitables from different sources but these +// functions are still used by some existing users so for now we make them +// available here. This may or may not change in the future so do not add +// them to new code. + +#ifdef __cplusplus +extern "C" { +#endif + +// Returns the extension with the given field number, or NULL on failure. +const upb_Message_Extension* upb_Message_FindExtensionByNumber( + const upb_Message* msg, uint32_t field_number); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MESSAGE_COMPAT_H_ */ + #ifndef UPB_MESSAGE_COPY_H_ #define UPB_MESSAGE_COPY_H_ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 965e40a140..af198bf196 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5442,6 +5442,25 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { } +#include <stddef.h> +#include <stdint.h> + + +// Must be last. + +const upb_Message_Extension* upb_Message_FindExtensionByNumber( + const upb_Message* msg, uint32_t field_number) { + size_t count = 0; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + + while (count--) { + if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; + ext++; + } + return NULL; +} + + #include <string.h> diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index aa54ab7f68..d7540dac43 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1627,6 +1627,8 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, // Must be last. +typedef struct upb_Message_Extension upb_Message_Extension; + #ifdef __cplusplus extern "C" { #endif @@ -1749,14 +1751,14 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( // This is rather wasteful for scalars (in the extreme case of bool, // it wastes 15 bytes). We accept this because we expect messages to be // the most common extension type. -typedef struct { +struct upb_Message_Extension { const upb_MiniTableExtension* ext; union { upb_StringView str; void* ptr; char scalar_data[8]; } data; -} upb_Message_Extension; +}; #ifdef __cplusplus extern "C" { @@ -12155,6 +12157,34 @@ UPB_INLINE bool _upb_NonAtomic_CompareExchangeStrongP(void* addr, #endif // UPB_PORT_ATOMIC_H_ +#ifndef UPB_MESSAGE_COMPAT_H_ +#define UPB_MESSAGE_COMPAT_H_ + +#include <stdint.h> + + +// Must be last. + +// upb does not support mixing minitables from different sources but these +// functions are still used by some existing users so for now we make them +// available here. This may or may not change in the future so do not add +// them to new code. + +#ifdef __cplusplus +extern "C" { +#endif + +// Returns the extension with the given field number, or NULL on failure. +const upb_Message_Extension* upb_Message_FindExtensionByNumber( + const upb_Message* msg, uint32_t field_number); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MESSAGE_COMPAT_H_ */ + #ifndef UPB_MESSAGE_COPY_H_ #define UPB_MESSAGE_COPY_H_