From c13512aee3b96a5a15d1f6e10c55499e0c708ee4 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 25 Jan 2024 18:53:49 +0000 Subject: [PATCH] Auto-generate files after cl/601494260 --- php/ext/google/protobuf/php-upb.c | 29 ++++++------ php/ext/google/protobuf/php-upb.h | 68 ++++++++++++++++++--------- ruby/ext/google/protobuf_c/ruby-upb.c | 29 ++++++------ ruby/ext/google/protobuf_c/ruby-upb.h | 68 ++++++++++++++++++--------- 4 files changed, 120 insertions(+), 74 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index ffa3075f12..9e8f88934b 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5066,14 +5066,14 @@ const upb_MiniTableExtension* upb_Message_ExtensionByIndex( return ext[index].ext; } -const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, - uint32_t field_number) { +const upb_MiniTableExtension* upb_Message_FindExtensionByNumber( + const upb_Message* msg, uint32_t field_number) { size_t count; const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - while (count--) { - if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; - ext++; + for (; count--; ext++) { + const upb_MiniTableExtension* e = ext->ext; + if (upb_MiniTableExtension_Number(e) == field_number) return e; } return NULL; } @@ -11091,10 +11091,10 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out) { // Must be last. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( const struct upb_Message* msg, const upb_MiniTableExtension* e) { size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -11108,11 +11108,11 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( return NULL; } -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( const struct upb_Message* msg, size_t* count) { upb_Message_Internal* in = msg->internal; if (in) { - *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); + *count = (in->size - in->ext_begin) / sizeof(upb_Extension); return UPB_PTR_AT(in, in->ext_begin, void); } else { *count = 0; @@ -11120,17 +11120,16 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( } } -struct upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( +upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { - struct upb_Extension* ext = - (struct upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); + upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), a)) return NULL; upb_Message_Internal* in = msg->internal; - in->ext_begin -= sizeof(struct upb_Extension); + in->ext_begin -= sizeof(upb_Extension); ext = UPB_PTR_AT(in, in->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); + memset(ext, 0, sizeof(upb_Extension)); ext->ext = e; return ext; } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 743a461e41..b992c4d492 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1984,14 +1984,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. -struct upb_Extension { +typedef struct { const upb_MiniTableExtension* ext; union { upb_StringView str; void* ptr; char scalar_data[8]; } data; -}; +} upb_Extension; #ifdef __cplusplus extern "C" { @@ -2000,18 +2000,18 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -struct upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( +upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( struct upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( const struct upb_Message* msg, size_t* count); // Returns an extension for a message with a given mini table, // or NULL if no extension exists with this mini table. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( const struct upb_Message* msg, const upb_MiniTableExtension* ext); #ifdef __cplusplus @@ -2759,8 +2759,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const struct upb_Extension* ext = - UPB_PRIVATE(_upb_Message_Getext)(msg, mt_ext); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getext)(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -2783,7 +2782,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - struct upb_Extension* ext = + upb_Extension* ext = UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) @@ -2814,13 +2813,11 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearExtension)( struct upb_Message* msg, const upb_MiniTableExtension* e) { upb_Message_Internal* in = msg->internal; if (!in) return; - const struct upb_Extension* base = - UPB_PTR_AT(in, in->ext_begin, struct upb_Extension); - struct upb_Extension* ext = - (struct upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); + const upb_Extension* base = UPB_PTR_AT(in, in->ext_begin, upb_Extension); + upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); if (ext) { *ext = *base; - in->ext_begin += sizeof(struct upb_Extension); + in->ext_begin += sizeof(upb_Extension); } } @@ -2989,7 +2986,6 @@ UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); // Must be last. -typedef struct upb_Extension upb_Extension; typedef struct upb_Message upb_Message; #ifdef __cplusplus @@ -12521,9 +12517,9 @@ extern "C" { const upb_MiniTableExtension* upb_Message_ExtensionByIndex( const upb_Message* msg, size_t index); -// Returns the extension with the given field number, or NULL on failure. -const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, - uint32_t field_number); +// 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); #ifdef __cplusplus } /* extern "C" */ @@ -12618,9 +12614,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const struct upb_Extension** ext) { + const upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const struct upb_Extension*)s->entries[sorted->pos++]; + *ext = (const upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -12632,9 +12628,8 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const struct upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const struct upb_Extension* exts, size_t count, - _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ @@ -12687,6 +12682,35 @@ UPB_API bool upb_Message_IsExactlyEqual(const upb_Message* msg1, const upb_Message* msg2, const upb_MiniTable* m); +// Performs a shallow field comparison. Do not use on message types. +UPB_API_INLINE bool upb_MessageValue_IsEqual(upb_MessageValue val1, + upb_MessageValue val2, + upb_CType ctype) { + switch (ctype) { + case kUpb_CType_Bool: + return val1.bool_val == val2.bool_val; + + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + return val1.int32_val == val2.int32_val; + + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return val1.int64_val == val2.int64_val; + + case kUpb_CType_String: + case kUpb_CType_Bytes: + return upb_StringView_IsEqual(val1.str_val, val2.str_val); + + default: // Note: This includes kUpb_CType_Message + UPB_ASSERT(0); + return false; + } +} + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 0fbb88d98c..80dc1583c9 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -4580,14 +4580,14 @@ const upb_MiniTableExtension* upb_Message_ExtensionByIndex( return ext[index].ext; } -const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, - uint32_t field_number) { +const upb_MiniTableExtension* upb_Message_FindExtensionByNumber( + const upb_Message* msg, uint32_t field_number) { size_t count; const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - while (count--) { - if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; - ext++; + for (; count--; ext++) { + const upb_MiniTableExtension* e = ext->ext; + if (upb_MiniTableExtension_Number(e) == field_number) return e; } return NULL; } @@ -10605,10 +10605,10 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out) { // Must be last. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( const struct upb_Message* msg, const upb_MiniTableExtension* e) { size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -10622,11 +10622,11 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( return NULL; } -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( const struct upb_Message* msg, size_t* count) { upb_Message_Internal* in = msg->internal; if (in) { - *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); + *count = (in->size - in->ext_begin) / sizeof(upb_Extension); return UPB_PTR_AT(in, in->ext_begin, void); } else { *count = 0; @@ -10634,17 +10634,16 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( } } -struct upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( +upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { - struct upb_Extension* ext = - (struct upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); + upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), a)) return NULL; upb_Message_Internal* in = msg->internal; - in->ext_begin -= sizeof(struct upb_Extension); + in->ext_begin -= sizeof(upb_Extension); ext = UPB_PTR_AT(in, in->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); + memset(ext, 0, sizeof(upb_Extension)); ext->ext = e; return ext; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index a784587e34..5f95d20271 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1986,14 +1986,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. -struct upb_Extension { +typedef struct { const upb_MiniTableExtension* ext; union { upb_StringView str; void* ptr; char scalar_data[8]; } data; -}; +} upb_Extension; #ifdef __cplusplus extern "C" { @@ -2002,18 +2002,18 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -struct upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( +upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( struct upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( const struct upb_Message* msg, size_t* count); // Returns an extension for a message with a given mini table, // or NULL if no extension exists with this mini table. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( +const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)( const struct upb_Message* msg, const upb_MiniTableExtension* ext); #ifdef __cplusplus @@ -2761,8 +2761,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const struct upb_Extension* ext = - UPB_PRIVATE(_upb_Message_Getext)(msg, mt_ext); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getext)(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -2785,7 +2784,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - struct upb_Extension* ext = + upb_Extension* ext = UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) @@ -2816,13 +2815,11 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearExtension)( struct upb_Message* msg, const upb_MiniTableExtension* e) { upb_Message_Internal* in = msg->internal; if (!in) return; - const struct upb_Extension* base = - UPB_PTR_AT(in, in->ext_begin, struct upb_Extension); - struct upb_Extension* ext = - (struct upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); + const upb_Extension* base = UPB_PTR_AT(in, in->ext_begin, upb_Extension); + upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); if (ext) { *ext = *base; - in->ext_begin += sizeof(struct upb_Extension); + in->ext_begin += sizeof(upb_Extension); } } @@ -2991,7 +2988,6 @@ UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); // Must be last. -typedef struct upb_Extension upb_Extension; typedef struct upb_Message upb_Message; #ifdef __cplusplus @@ -12293,9 +12289,9 @@ extern "C" { const upb_MiniTableExtension* upb_Message_ExtensionByIndex( const upb_Message* msg, size_t index); -// Returns the extension with the given field number, or NULL on failure. -const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, - uint32_t field_number); +// 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); #ifdef __cplusplus } /* extern "C" */ @@ -12390,9 +12386,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const struct upb_Extension** ext) { + const upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const struct upb_Extension*)s->entries[sorted->pos++]; + *ext = (const upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -12404,9 +12400,8 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const struct upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const struct upb_Extension* exts, size_t count, - _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ @@ -12459,6 +12454,35 @@ UPB_API bool upb_Message_IsExactlyEqual(const upb_Message* msg1, const upb_Message* msg2, const upb_MiniTable* m); +// Performs a shallow field comparison. Do not use on message types. +UPB_API_INLINE bool upb_MessageValue_IsEqual(upb_MessageValue val1, + upb_MessageValue val2, + upb_CType ctype) { + switch (ctype) { + case kUpb_CType_Bool: + return val1.bool_val == val2.bool_val; + + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + return val1.int32_val == val2.int32_val; + + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return val1.int64_val == val2.int64_val; + + case kUpb_CType_String: + case kUpb_CType_Bytes: + return upb_StringView_IsEqual(val1.str_val, val2.str_val); + + default: // Note: This includes kUpb_CType_Message + UPB_ASSERT(0); + return false; + } +} + #ifdef __cplusplus } /* extern "C" */ #endif