From 421697280015127b63748c6df74f6138517788d0 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 29 Nov 2023 03:54:33 +0000 Subject: [PATCH] Auto-generate files after cl/586171362 --- php/ext/google/protobuf/php-upb.c | 39 ++-- php/ext/google/protobuf/php-upb.h | 302 ++++++++++++++++---------- ruby/ext/google/protobuf_c/ruby-upb.c | 39 ++-- ruby/ext/google/protobuf_c/ruby-upb.h | 302 ++++++++++++++++---------- 4 files changed, 420 insertions(+), 262 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index f86e69310e..d18570815c 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5934,10 +5934,6 @@ bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, // Must be last. -static bool upb_MessageField_IsMap(const upb_MiniTableField* field) { - return upb_FieldMode_Get(field) == kUpb_FieldMode_Map; -} - static upb_StringView upb_Clone_StringView(upb_StringView str, upb_Arena* arena) { if (str.size == 0) { @@ -6065,7 +6061,7 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array, const upb_MiniTable* mini_table, const upb_MiniTableField* field, upb_Message* clone, upb_Arena* arena) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* cloned_array = upb_Array_DeepClone( array, upb_MiniTableField_CType(field), upb_MiniTableField_CType(field) == kUpb_CType_Message && @@ -6098,7 +6094,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, memcpy(dst, src, mini_table->size); for (size_t i = 0; i < mini_table->field_count; ++i) { const upb_MiniTableField* field = &mini_table->fields[i]; - if (!upb_MiniTableField_IsRepeatedOrMap(field)) { + if (upb_MiniTableField_IsScalar(field)) { switch (upb_MiniTableField_CType(field)) { case kUpb_CType_Message: { upb_TaggedMessagePtr tagged = @@ -6138,7 +6134,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, break; } } else { - if (upb_MessageField_IsMap(field)) { + if (upb_MiniTableField_IsMap(field)) { const upb_Map* map = upb_Message_GetMap(src, field); if (map != NULL) { if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { @@ -6165,7 +6161,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, upb_Message_Extension* dst_ext = _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); if (!dst_ext) return NULL; - if (!upb_MiniTableField_IsRepeatedOrMap(field)) { + if (upb_MiniTableField_IsScalar(field)) { if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { return NULL; } @@ -7454,7 +7450,7 @@ static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, name, expected_num, (int)f->number); } - if (upb_MiniTableField_IsRepeatedOrMap(f)) { + if (!upb_MiniTableField_IsScalar(f)) { upb_MdDecoder_ErrorJmp( &d->base, "map %s cannot be repeated or map, or be in oneof", name); } @@ -7632,7 +7628,7 @@ static const char* upb_MtDecoder_DoBuildMiniTableExtension( if (!upb_MiniTableField_IsSubMessage(f)) return NULL; // Extensions of MessageSet must be non-repeating. - if ((f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array) return NULL; + if (upb_MiniTableField_IsArray(f)) return NULL; } ext->UPB_PRIVATE(extendee) = extendee; @@ -8210,6 +8206,8 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #include +#include +#include // Must be last. @@ -8243,13 +8241,9 @@ const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( return NULL; } -static bool upb_MiniTable_Is_Oneof(const upb_MiniTableField* f) { - return f->presence < 0; -} - const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, const upb_MiniTableField* f) { - if (UPB_UNLIKELY(!upb_MiniTable_Is_Oneof(f))) { + if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { return NULL; } const upb_MiniTableField* ptr = &m->fields[0]; @@ -11182,6 +11176,7 @@ char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { } +#include #include @@ -11282,7 +11277,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (upb_MiniTableField_HasPresence(field)) { if (!upb_Message_HasFieldByDef(msg, f)) continue; } else { - switch (upb_FieldMode_Get(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { case kUpb_FieldMode_Map: if (!val.map_val || upb_Map_Size(val.map_val) == 0) continue; break; @@ -13133,8 +13128,8 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, UPB_ASSERT(entry); UPB_ASSERT(entry->field_count == 2); - UPB_ASSERT(!upb_MiniTableField_IsRepeatedOrMap(&entry->fields[0])); - UPB_ASSERT(!upb_MiniTableField_IsRepeatedOrMap(&entry->fields[1])); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->fields[0])); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->fields[1])); if (!map) { map = _upb_Decoder_CreateMap(d, entry); @@ -13579,7 +13574,7 @@ int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, }; int ndx = field->UPB_PRIVATE(descriptortype); - if (upb_FieldMode_Get(field) == kUpb_FieldMode_Array) ndx += kRepeatedBase; + if (upb_MiniTableField_IsArray(field)) ndx += kRepeatedBase; int op = kDelimitedOps[ndx]; if (op == kUpb_DecodeOp_SubMessage) { @@ -15150,7 +15145,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); - bool packed = f->mode & kUpb_LabelFlags_IsPacked; + bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; if (arr == NULL || arr->size == 0) { @@ -15304,7 +15299,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, if (f->presence == 0) { // Proto3 presence or map/array. const void* mem = UPB_PTR_AT(msg, f->offset, void); - switch (_upb_MiniTableField_GetRep(f)) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: { char ch; memcpy(&ch, mem, 1); @@ -15339,7 +15334,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, static void encode_field(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - switch (upb_FieldMode_Get(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { case kUpb_FieldMode_Array: encode_array(e, msg, subs, field); break; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 7487b33e0c..b1f2e3d60e 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -998,8 +998,6 @@ UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, #ifndef UPB_MINI_TABLE_FIELD_H_ #define UPB_MINI_TABLE_FIELD_H_ -#include - #ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ #define UPB_MINI_TABLE_INTERNAL_FIELD_H_ @@ -1080,7 +1078,7 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { struct upb_MiniTableField { uint32_t number; uint16_t offset; - int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index + int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index // Indexes into `upb_MiniTable.subs` // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM @@ -1129,38 +1127,110 @@ typedef enum { #define kUpb_FieldRep_Shift 6 -UPB_INLINE upb_FieldRep -_upb_MiniTableField_GetRep(const struct upb_MiniTableField* field) { - return (upb_FieldRep)(field->mode >> kUpb_FieldRep_Shift); -} - #ifdef __cplusplus extern "C" { #endif UPB_INLINE upb_FieldMode -upb_FieldMode_Get(const struct upb_MiniTableField* field) { - return (upb_FieldMode)(field->mode & 3); +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { + return (upb_FieldMode)(f->mode & kUpb_FieldMode_Mask); } -UPB_INLINE void _upb_MiniTableField_CheckIsArray( - const struct upb_MiniTableField* field) { - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_FieldMode_Get(field) == kUpb_FieldMode_Array); - UPB_ASSUME(field->presence == 0); +UPB_INLINE upb_FieldRep +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { + return (upb_FieldRep)(f->mode >> kUpb_FieldRep_Shift); +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array; } -UPB_INLINE void _upb_MiniTableField_CheckIsMap( - const struct upb_MiniTableField* field) { - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_FieldMode_Get(field) == kUpb_FieldMode_Map); - UPB_ASSUME(field->presence == 0); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Map; } -UPB_INLINE size_t -_upb_MiniTableField_ElemSizeLg2(const struct upb_MiniTableField* field) { - return upb_FieldType_SizeLg2( - (upb_FieldType)field->UPB_PRIVATE(descriptortype)); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Scalar; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_LabelFlags_IsAlternate) != 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_LabelFlags_IsExtension) != 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_LabelFlags_IsPacked) != 0; +} + +UPB_INLINE upb_FieldType +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { + const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); + if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { + if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; + if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; + UPB_ASSERT(false); + } + return type; +} + +UPB_INLINE upb_CType +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { + return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( + const struct upb_MiniTableField* f) { + return f->presence < 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || + f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( + const struct upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); + } else { + return f->presence != 0; + } +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { + return upb_FieldType_SizeLg2((upb_FieldType)f->UPB_PRIVATE(descriptortype)); } #ifdef __cplusplus @@ -1178,57 +1248,53 @@ typedef struct upb_MiniTableField upb_MiniTableField; extern "C" { #endif -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - if (f->mode & kUpb_LabelFlags_IsAlternate) { - if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Int32) { - return kUpb_FieldType_Enum; - } else if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bytes) { - return kUpb_FieldType_String; - } else { - UPB_ASSERT(false); - } - } - return (upb_FieldType)f->UPB_PRIVATE(descriptortype); +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); } -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return upb_FieldType_CType(upb_MiniTableField_Type(f)); +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); } UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* field) { - return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); } UPB_API_INLINE bool upb_MiniTableField_IsExtension( const upb_MiniTableField* f) { - return f->mode & kUpb_LabelFlags_IsExtension; + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); } UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return f->presence < 0; + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); } -UPB_API_INLINE bool upb_MiniTableField_IsRepeatedOrMap( - const upb_MiniTableField* f) { - // This works because upb_FieldMode has no value 3. - return !(f->mode & kUpb_FieldMode_Scalar); +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( const upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || - f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); } -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - if (upb_MiniTableField_IsExtension(f)) { - return !upb_MiniTableField_IsRepeatedOrMap(f); - } else { - return f->presence != 0; - } +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); } #ifdef __cplusplus @@ -2415,7 +2481,7 @@ UPB_INLINE void _upb_Message_SetPresence(upb_Message* msg, UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val, const upb_MiniTableField* field) { char zero[16] = {0}; - switch (_upb_MiniTableField_GetRep(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { case kUpb_FieldRep_1Byte: return memcmp(&zero, default_val, 1) != 0; case kUpb_FieldRep_4Byte: @@ -2432,7 +2498,7 @@ UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val, UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from, const upb_MiniTableField* field) { - switch (_upb_MiniTableField_GetRep(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { case kUpb_FieldRep_1Byte: memcpy(to, from, 1); return; @@ -2468,8 +2534,9 @@ UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from, // const upb_MiniTableField* field, // bool value, upb_Arena* a) { // UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool); -// UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); -// UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); +// UPB_ASSUME(upb_MiniTableField_IsScalar(field)); +// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == +// kUpb_FieldRep_1Byte); // upb_Message_SetField(msg, field, &value, a); // } // @@ -2536,7 +2603,7 @@ UPB_INLINE void _upb_Message_GetExtensionField( // is unset (as message fields do have presence). UPB_INLINE upb_MutableMessageValue _upb_Message_GetMutableField( const upb_Message* msg, const upb_MiniTableField* field) { - UPB_ASSUME(upb_MiniTableField_IsRepeatedOrMap(field) || + UPB_ASSUME(!upb_MiniTableField_IsScalar(field) || upb_MiniTableField_IsSubMessage(field)); upb_MutableMessageValue default_val; @@ -2602,7 +2669,7 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField( UPB_INLINE void _upb_Message_AssertMapIsUntagged( const upb_Message* msg, const upb_MiniTableField* field) { UPB_UNUSED(msg); - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); #ifndef NDEBUG upb_TaggedMessagePtr default_val = 0; upb_TaggedMessagePtr tagged; @@ -2614,7 +2681,7 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( upb_Message* msg, const upb_MiniTableField* field, size_t key_size, size_t val_size, upb_Arena* arena) { - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); upb_Map* map = NULL; upb_Map* default_map_value = NULL; @@ -2622,7 +2689,7 @@ UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( if (!map) { map = _upb_Map_New(arena, key_size, val_size); // Check again due to: https://godbolt.org/z/7WfaoKG1r - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_SetNonExtensionField(msg, field, &map); } return map; @@ -2827,8 +2894,9 @@ UPB_API_INLINE bool upb_Message_GetBool(const upb_Message* msg, const upb_MiniTableField* field, bool default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_1Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.bool_val = default_val; return upb_Message_GetField(msg, field, def).bool_val; @@ -2838,8 +2906,9 @@ UPB_API_INLINE bool upb_Message_SetBool(upb_Message* msg, const upb_MiniTableField* field, bool value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_1Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.bool_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2850,8 +2919,9 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const upb_Message* msg, int32_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 || upb_MiniTableField_CType(field) == kUpb_CType_Enum); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.int32_val = default_val; @@ -2863,8 +2933,9 @@ UPB_API_INLINE bool upb_Message_SetInt32(upb_Message* msg, int32_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 || upb_MiniTableField_CType(field) == kUpb_CType_Enum); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.int32_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2874,8 +2945,9 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const upb_Message* msg, const upb_MiniTableField* field, uint32_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.uint32_val = default_val; @@ -2886,8 +2958,9 @@ UPB_API_INLINE bool upb_Message_SetUInt32(upb_Message* msg, const upb_MiniTableField* field, uint32_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.uint32_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2897,8 +2970,9 @@ UPB_API_INLINE void upb_Message_SetClosedEnum( upb_Message* msg, const upb_MiniTable* msg_mini_table, const upb_MiniTableField* field, int32_t value) { UPB_ASSERT(upb_MiniTableField_IsClosedEnum(field)); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); UPB_ASSERT(upb_MiniTableEnum_CheckValue( upb_MiniTable_GetSubEnumTable(msg_mini_table, field), value)); _upb_Message_SetNonExtensionField(msg, field, &value); @@ -2908,8 +2982,9 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg, const upb_MiniTableField* field, int64_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.int64_val = default_val; @@ -2920,8 +2995,9 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg, const upb_MiniTableField* field, int64_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.int64_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2931,8 +3007,9 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const upb_Message* msg, const upb_MiniTableField* field, uint64_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.uint64_val = default_val; @@ -2943,8 +3020,9 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg, const upb_MiniTableField* field, uint64_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.uint64_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2954,8 +3032,9 @@ UPB_API_INLINE float upb_Message_GetFloat(const upb_Message* msg, const upb_MiniTableField* field, float default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.float_val = default_val; @@ -2966,8 +3045,9 @@ UPB_API_INLINE bool upb_Message_SetFloat(upb_Message* msg, const upb_MiniTableField* field, float value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.float_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2977,8 +3057,9 @@ UPB_API_INLINE double upb_Message_GetDouble(const upb_Message* msg, const upb_MiniTableField* field, double default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.double_val = default_val; @@ -2989,8 +3070,9 @@ UPB_API_INLINE bool upb_Message_SetDouble(upb_Message* msg, const upb_MiniTableField* field, double value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.double_val = value; return upb_Message_SetField(msg, field, val, a); @@ -3001,8 +3083,9 @@ upb_Message_GetString(const upb_Message* msg, const upb_MiniTableField* field, upb_StringView default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String || upb_MiniTableField_CType(field) == kUpb_CType_Bytes); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_StringView); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.str_val = default_val; @@ -3014,8 +3097,9 @@ UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg, upb_StringView value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String || upb_MiniTableField_CType(field) == kUpb_CType_Bytes); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_StringView); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.str_val = value; return upb_Message_SetField(msg, field, val, a); @@ -3025,9 +3109,9 @@ UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr( const upb_Message* msg, const upb_MiniTableField* field, upb_Message* default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_TaggedMessagePtr tagged; _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); return tagged; @@ -3048,9 +3132,9 @@ UPB_API_INLINE void _upb_Message_SetTaggedMessagePtr( upb_Message* msg, const upb_MiniTable* mini_table, const upb_MiniTableField* field, upb_TaggedMessagePtr sub_message) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); UPB_ASSERT(mini_table->subs[field->UPB_PRIVATE(submsg_index)].submsg); _upb_Message_SetNonExtensionField(msg, field, &sub_message); } @@ -3082,7 +3166,7 @@ UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( UPB_API_INLINE const upb_Array* upb_Message_GetArray( const upb_Message* msg, const upb_MiniTableField* field) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* ret; const upb_Array* default_val = NULL; _upb_Message_GetNonExtensionField(msg, field, &default_val, &ret); @@ -3091,20 +3175,20 @@ UPB_API_INLINE const upb_Array* upb_Message_GetArray( UPB_API_INLINE upb_Array* upb_Message_GetMutableArray( upb_Message* msg, const upb_MiniTableField* field) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); return (upb_Array*)upb_Message_GetArray(msg, field); } UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( upb_Message* msg, const upb_MiniTableField* field, upb_Arena* arena) { UPB_ASSERT(arena); - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* array = upb_Message_GetMutableArray(msg, field); if (!array) { - array = UPB_PRIVATE(_upb_Array_New)(arena, 4, - _upb_MiniTableField_ElemSizeLg2(field)); + array = UPB_PRIVATE(_upb_Array_New)( + arena, 4, UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(field)); // Check again due to: https://godbolt.org/z/7WfaoKG1r - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_MessageValue val; val.array_val = array; upb_Message_SetField(msg, field, val, arena); @@ -3115,7 +3199,7 @@ UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized( upb_Message* msg, const upb_MiniTableField* field, size_t size, upb_Arena* arena) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, field, arena); if (!arr || !_upb_Array_ResizeUninitialized(arr, size, arena)) return NULL; return _upb_array_ptr(arr); @@ -3123,7 +3207,7 @@ UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized( UPB_API_INLINE const upb_Map* upb_Message_GetMap( const upb_Message* msg, const upb_MiniTableField* field) { - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); upb_Map* ret; const upb_Map* default_val = NULL; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 6dfc0f74da..f6c888226b 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5449,10 +5449,6 @@ bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, // Must be last. -static bool upb_MessageField_IsMap(const upb_MiniTableField* field) { - return upb_FieldMode_Get(field) == kUpb_FieldMode_Map; -} - static upb_StringView upb_Clone_StringView(upb_StringView str, upb_Arena* arena) { if (str.size == 0) { @@ -5580,7 +5576,7 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array, const upb_MiniTable* mini_table, const upb_MiniTableField* field, upb_Message* clone, upb_Arena* arena) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* cloned_array = upb_Array_DeepClone( array, upb_MiniTableField_CType(field), upb_MiniTableField_CType(field) == kUpb_CType_Message && @@ -5613,7 +5609,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, memcpy(dst, src, mini_table->size); for (size_t i = 0; i < mini_table->field_count; ++i) { const upb_MiniTableField* field = &mini_table->fields[i]; - if (!upb_MiniTableField_IsRepeatedOrMap(field)) { + if (upb_MiniTableField_IsScalar(field)) { switch (upb_MiniTableField_CType(field)) { case kUpb_CType_Message: { upb_TaggedMessagePtr tagged = @@ -5653,7 +5649,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, break; } } else { - if (upb_MessageField_IsMap(field)) { + if (upb_MiniTableField_IsMap(field)) { const upb_Map* map = upb_Message_GetMap(src, field); if (map != NULL) { if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { @@ -5680,7 +5676,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, upb_Message_Extension* dst_ext = _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); if (!dst_ext) return NULL; - if (!upb_MiniTableField_IsRepeatedOrMap(field)) { + if (upb_MiniTableField_IsScalar(field)) { if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { return NULL; } @@ -6969,7 +6965,7 @@ static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, name, expected_num, (int)f->number); } - if (upb_MiniTableField_IsRepeatedOrMap(f)) { + if (!upb_MiniTableField_IsScalar(f)) { upb_MdDecoder_ErrorJmp( &d->base, "map %s cannot be repeated or map, or be in oneof", name); } @@ -7147,7 +7143,7 @@ static const char* upb_MtDecoder_DoBuildMiniTableExtension( if (!upb_MiniTableField_IsSubMessage(f)) return NULL; // Extensions of MessageSet must be non-repeating. - if ((f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array) return NULL; + if (upb_MiniTableField_IsArray(f)) return NULL; } ext->UPB_PRIVATE(extendee) = extendee; @@ -7725,6 +7721,8 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #include +#include +#include // Must be last. @@ -7758,13 +7756,9 @@ const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( return NULL; } -static bool upb_MiniTable_Is_Oneof(const upb_MiniTableField* f) { - return f->presence < 0; -} - const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, const upb_MiniTableField* f) { - if (UPB_UNLIKELY(!upb_MiniTable_Is_Oneof(f))) { + if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { return NULL; } const upb_MiniTableField* ptr = &m->fields[0]; @@ -10697,6 +10691,7 @@ char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { } +#include #include @@ -10797,7 +10792,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (upb_MiniTableField_HasPresence(field)) { if (!upb_Message_HasFieldByDef(msg, f)) continue; } else { - switch (upb_FieldMode_Get(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { case kUpb_FieldMode_Map: if (!val.map_val || upb_Map_Size(val.map_val) == 0) continue; break; @@ -12648,8 +12643,8 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, UPB_ASSERT(entry); UPB_ASSERT(entry->field_count == 2); - UPB_ASSERT(!upb_MiniTableField_IsRepeatedOrMap(&entry->fields[0])); - UPB_ASSERT(!upb_MiniTableField_IsRepeatedOrMap(&entry->fields[1])); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->fields[0])); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->fields[1])); if (!map) { map = _upb_Decoder_CreateMap(d, entry); @@ -13094,7 +13089,7 @@ int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, }; int ndx = field->UPB_PRIVATE(descriptortype); - if (upb_FieldMode_Get(field) == kUpb_FieldMode_Array) ndx += kRepeatedBase; + if (upb_MiniTableField_IsArray(field)) ndx += kRepeatedBase; int op = kDelimitedOps[ndx]; if (op == kUpb_DecodeOp_SubMessage) { @@ -14665,7 +14660,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); - bool packed = f->mode & kUpb_LabelFlags_IsPacked; + bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; if (arr == NULL || arr->size == 0) { @@ -14819,7 +14814,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, if (f->presence == 0) { // Proto3 presence or map/array. const void* mem = UPB_PTR_AT(msg, f->offset, void); - switch (_upb_MiniTableField_GetRep(f)) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: { char ch; memcpy(&ch, mem, 1); @@ -14854,7 +14849,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, static void encode_field(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - switch (upb_FieldMode_Get(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { case kUpb_FieldMode_Array: encode_array(e, msg, subs, field); break; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 6d464b31d1..c81b2eff61 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1000,8 +1000,6 @@ UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, #ifndef UPB_MINI_TABLE_FIELD_H_ #define UPB_MINI_TABLE_FIELD_H_ -#include - #ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ #define UPB_MINI_TABLE_INTERNAL_FIELD_H_ @@ -1082,7 +1080,7 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { struct upb_MiniTableField { uint32_t number; uint16_t offset; - int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index + int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index // Indexes into `upb_MiniTable.subs` // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM @@ -1131,38 +1129,110 @@ typedef enum { #define kUpb_FieldRep_Shift 6 -UPB_INLINE upb_FieldRep -_upb_MiniTableField_GetRep(const struct upb_MiniTableField* field) { - return (upb_FieldRep)(field->mode >> kUpb_FieldRep_Shift); -} - #ifdef __cplusplus extern "C" { #endif UPB_INLINE upb_FieldMode -upb_FieldMode_Get(const struct upb_MiniTableField* field) { - return (upb_FieldMode)(field->mode & 3); +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { + return (upb_FieldMode)(f->mode & kUpb_FieldMode_Mask); } -UPB_INLINE void _upb_MiniTableField_CheckIsArray( - const struct upb_MiniTableField* field) { - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_FieldMode_Get(field) == kUpb_FieldMode_Array); - UPB_ASSUME(field->presence == 0); +UPB_INLINE upb_FieldRep +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { + return (upb_FieldRep)(f->mode >> kUpb_FieldRep_Shift); +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array; } -UPB_INLINE void _upb_MiniTableField_CheckIsMap( - const struct upb_MiniTableField* field) { - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_NativePointer); - UPB_ASSUME(upb_FieldMode_Get(field) == kUpb_FieldMode_Map); - UPB_ASSUME(field->presence == 0); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Map; } -UPB_INLINE size_t -_upb_MiniTableField_ElemSizeLg2(const struct upb_MiniTableField* field) { - return upb_FieldType_SizeLg2( - (upb_FieldType)field->UPB_PRIVATE(descriptortype)); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Scalar; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_LabelFlags_IsAlternate) != 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_LabelFlags_IsExtension) != 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( + const struct upb_MiniTableField* f) { + return (f->mode & kUpb_LabelFlags_IsPacked) != 0; +} + +UPB_INLINE upb_FieldType +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { + const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); + if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { + if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; + if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; + UPB_ASSERT(false); + } + return type; +} + +UPB_INLINE upb_CType +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { + return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( + const struct upb_MiniTableField* f) { + return f->presence < 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || + f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( + const struct upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); + } else { + return f->presence != 0; + } +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { + return upb_FieldType_SizeLg2((upb_FieldType)f->UPB_PRIVATE(descriptortype)); } #ifdef __cplusplus @@ -1180,57 +1250,53 @@ typedef struct upb_MiniTableField upb_MiniTableField; extern "C" { #endif -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - if (f->mode & kUpb_LabelFlags_IsAlternate) { - if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Int32) { - return kUpb_FieldType_Enum; - } else if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bytes) { - return kUpb_FieldType_String; - } else { - UPB_ASSERT(false); - } - } - return (upb_FieldType)f->UPB_PRIVATE(descriptortype); +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); } -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return upb_FieldType_CType(upb_MiniTableField_Type(f)); +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); } UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* field) { - return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); } UPB_API_INLINE bool upb_MiniTableField_IsExtension( const upb_MiniTableField* f) { - return f->mode & kUpb_LabelFlags_IsExtension; + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); } UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return f->presence < 0; + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); } -UPB_API_INLINE bool upb_MiniTableField_IsRepeatedOrMap( - const upb_MiniTableField* f) { - // This works because upb_FieldMode has no value 3. - return !(f->mode & kUpb_FieldMode_Scalar); +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( const upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || - f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); } -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - if (upb_MiniTableField_IsExtension(f)) { - return !upb_MiniTableField_IsRepeatedOrMap(f); - } else { - return f->presence != 0; - } +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); } #ifdef __cplusplus @@ -2417,7 +2483,7 @@ UPB_INLINE void _upb_Message_SetPresence(upb_Message* msg, UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val, const upb_MiniTableField* field) { char zero[16] = {0}; - switch (_upb_MiniTableField_GetRep(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { case kUpb_FieldRep_1Byte: return memcmp(&zero, default_val, 1) != 0; case kUpb_FieldRep_4Byte: @@ -2434,7 +2500,7 @@ UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val, UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from, const upb_MiniTableField* field) { - switch (_upb_MiniTableField_GetRep(field)) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { case kUpb_FieldRep_1Byte: memcpy(to, from, 1); return; @@ -2470,8 +2536,9 @@ UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from, // const upb_MiniTableField* field, // bool value, upb_Arena* a) { // UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool); -// UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); -// UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); +// UPB_ASSUME(upb_MiniTableField_IsScalar(field)); +// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == +// kUpb_FieldRep_1Byte); // upb_Message_SetField(msg, field, &value, a); // } // @@ -2538,7 +2605,7 @@ UPB_INLINE void _upb_Message_GetExtensionField( // is unset (as message fields do have presence). UPB_INLINE upb_MutableMessageValue _upb_Message_GetMutableField( const upb_Message* msg, const upb_MiniTableField* field) { - UPB_ASSUME(upb_MiniTableField_IsRepeatedOrMap(field) || + UPB_ASSUME(!upb_MiniTableField_IsScalar(field) || upb_MiniTableField_IsSubMessage(field)); upb_MutableMessageValue default_val; @@ -2604,7 +2671,7 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField( UPB_INLINE void _upb_Message_AssertMapIsUntagged( const upb_Message* msg, const upb_MiniTableField* field) { UPB_UNUSED(msg); - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); #ifndef NDEBUG upb_TaggedMessagePtr default_val = 0; upb_TaggedMessagePtr tagged; @@ -2616,7 +2683,7 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( upb_Message* msg, const upb_MiniTableField* field, size_t key_size, size_t val_size, upb_Arena* arena) { - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); upb_Map* map = NULL; upb_Map* default_map_value = NULL; @@ -2624,7 +2691,7 @@ UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( if (!map) { map = _upb_Map_New(arena, key_size, val_size); // Check again due to: https://godbolt.org/z/7WfaoKG1r - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_SetNonExtensionField(msg, field, &map); } return map; @@ -2829,8 +2896,9 @@ UPB_API_INLINE bool upb_Message_GetBool(const upb_Message* msg, const upb_MiniTableField* field, bool default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_1Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.bool_val = default_val; return upb_Message_GetField(msg, field, def).bool_val; @@ -2840,8 +2908,9 @@ UPB_API_INLINE bool upb_Message_SetBool(upb_Message* msg, const upb_MiniTableField* field, bool value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_1Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.bool_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2852,8 +2921,9 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const upb_Message* msg, int32_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 || upb_MiniTableField_CType(field) == kUpb_CType_Enum); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.int32_val = default_val; @@ -2865,8 +2935,9 @@ UPB_API_INLINE bool upb_Message_SetInt32(upb_Message* msg, int32_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 || upb_MiniTableField_CType(field) == kUpb_CType_Enum); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.int32_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2876,8 +2947,9 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const upb_Message* msg, const upb_MiniTableField* field, uint32_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.uint32_val = default_val; @@ -2888,8 +2960,9 @@ UPB_API_INLINE bool upb_Message_SetUInt32(upb_Message* msg, const upb_MiniTableField* field, uint32_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.uint32_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2899,8 +2972,9 @@ UPB_API_INLINE void upb_Message_SetClosedEnum( upb_Message* msg, const upb_MiniTable* msg_mini_table, const upb_MiniTableField* field, int32_t value) { UPB_ASSERT(upb_MiniTableField_IsClosedEnum(field)); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); UPB_ASSERT(upb_MiniTableEnum_CheckValue( upb_MiniTable_GetSubEnumTable(msg_mini_table, field), value)); _upb_Message_SetNonExtensionField(msg, field, &value); @@ -2910,8 +2984,9 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg, const upb_MiniTableField* field, int64_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.int64_val = default_val; @@ -2922,8 +2997,9 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg, const upb_MiniTableField* field, int64_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.int64_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2933,8 +3009,9 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const upb_Message* msg, const upb_MiniTableField* field, uint64_t default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.uint64_val = default_val; @@ -2945,8 +3022,9 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg, const upb_MiniTableField* field, uint64_t value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.uint64_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2956,8 +3034,9 @@ UPB_API_INLINE float upb_Message_GetFloat(const upb_Message* msg, const upb_MiniTableField* field, float default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.float_val = default_val; @@ -2968,8 +3047,9 @@ UPB_API_INLINE bool upb_Message_SetFloat(upb_Message* msg, const upb_MiniTableField* field, float value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_4Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.float_val = value; return upb_Message_SetField(msg, field, val, a); @@ -2979,8 +3059,9 @@ UPB_API_INLINE double upb_Message_GetDouble(const upb_Message* msg, const upb_MiniTableField* field, double default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.double_val = default_val; @@ -2991,8 +3072,9 @@ UPB_API_INLINE bool upb_Message_SetDouble(upb_Message* msg, const upb_MiniTableField* field, double value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_8Byte); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.double_val = value; return upb_Message_SetField(msg, field, val, a); @@ -3003,8 +3085,9 @@ upb_Message_GetString(const upb_Message* msg, const upb_MiniTableField* field, upb_StringView default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String || upb_MiniTableField_CType(field) == kUpb_CType_Bytes); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_StringView); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue def; def.str_val = default_val; @@ -3016,8 +3099,9 @@ UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg, upb_StringView value, upb_Arena* a) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String || upb_MiniTableField_CType(field) == kUpb_CType_Bytes); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == + kUpb_FieldRep_StringView); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_MessageValue val; val.str_val = value; return upb_Message_SetField(msg, field, val, a); @@ -3027,9 +3111,9 @@ UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr( const upb_Message* msg, const upb_MiniTableField* field, upb_Message* default_val) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); upb_TaggedMessagePtr tagged; _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); return tagged; @@ -3050,9 +3134,9 @@ UPB_API_INLINE void _upb_Message_SetTaggedMessagePtr( upb_Message* msg, const upb_MiniTable* mini_table, const upb_MiniTableField* field, upb_TaggedMessagePtr sub_message) { UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); - UPB_ASSUME(_upb_MiniTableField_GetRep(field) == + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) == UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); - UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field)); + UPB_ASSUME(upb_MiniTableField_IsScalar(field)); UPB_ASSERT(mini_table->subs[field->UPB_PRIVATE(submsg_index)].submsg); _upb_Message_SetNonExtensionField(msg, field, &sub_message); } @@ -3084,7 +3168,7 @@ UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( UPB_API_INLINE const upb_Array* upb_Message_GetArray( const upb_Message* msg, const upb_MiniTableField* field) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* ret; const upb_Array* default_val = NULL; _upb_Message_GetNonExtensionField(msg, field, &default_val, &ret); @@ -3093,20 +3177,20 @@ UPB_API_INLINE const upb_Array* upb_Message_GetArray( UPB_API_INLINE upb_Array* upb_Message_GetMutableArray( upb_Message* msg, const upb_MiniTableField* field) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); return (upb_Array*)upb_Message_GetArray(msg, field); } UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( upb_Message* msg, const upb_MiniTableField* field, upb_Arena* arena) { UPB_ASSERT(arena); - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* array = upb_Message_GetMutableArray(msg, field); if (!array) { - array = UPB_PRIVATE(_upb_Array_New)(arena, 4, - _upb_MiniTableField_ElemSizeLg2(field)); + array = UPB_PRIVATE(_upb_Array_New)( + arena, 4, UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(field)); // Check again due to: https://godbolt.org/z/7WfaoKG1r - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_MessageValue val; val.array_val = array; upb_Message_SetField(msg, field, val, arena); @@ -3117,7 +3201,7 @@ UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized( upb_Message* msg, const upb_MiniTableField* field, size_t size, upb_Arena* arena) { - _upb_MiniTableField_CheckIsArray(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, field, arena); if (!arr || !_upb_Array_ResizeUninitialized(arr, size, arena)) return NULL; return _upb_array_ptr(arr); @@ -3125,7 +3209,7 @@ UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized( UPB_API_INLINE const upb_Map* upb_Message_GetMap( const upb_Message* msg, const upb_MiniTableField* field) { - _upb_MiniTableField_CheckIsMap(field); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); upb_Map* ret; const upb_Map* default_val = NULL;