From 7c5ff299795b1a8210b2a0e2f0b5faeb0625b132 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Wed, 17 Jan 2024 15:51:34 -0800 Subject: [PATCH] upb: add upb_MiniTableExtension_CType() PiperOrigin-RevId: 599313198 --- upb/message/promote.c | 3 +-- upb/mini_table/extension.h | 8 ++++---- upb/mini_table/internal/extension.h | 6 +++--- upb/test/fuzz_util.cc | 3 +-- upb/wire/decode.c | 12 ++++++------ 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/upb/message/promote.c b/upb/message/promote.c index cf7e7fdba7..70d62762ae 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -67,8 +67,7 @@ static upb_UnknownToMessageRet upb_MiniTable_ParseUnknownMessage( upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( upb_Message* msg, const upb_MiniTableExtension* ext_table, int decode_options, upb_Arena* arena, const upb_Extension** extension) { - UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( - ext_table)) == kUpb_CType_Message); + UPB_ASSERT(upb_MiniTableExtension_CType(ext_table) == kUpb_CType_Message); *extension = _upb_Message_Getext(msg, ext_table); if (*extension) { return kUpb_GetExtension_Ok; diff --git a/upb/mini_table/extension.h b/upb/mini_table/extension.h index 58a71b60c4..891f906b69 100644 --- a/upb/mini_table/extension.h +++ b/upb/mini_table/extension.h @@ -10,7 +10,7 @@ #include -#include "upb/mini_table/field.h" +#include "upb/base/descriptor_constants.h" #include "upb/mini_table/internal/extension.h" #include "upb/mini_table/message.h" @@ -23,9 +23,9 @@ typedef struct upb_MiniTableExtension upb_MiniTableExtension; extern "C" { #endif -UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); +UPB_API_INLINE upb_CType +upb_MiniTableExtension_CType(const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_CType)(e); } UPB_API_INLINE uint32_t diff --git a/upb/mini_table/internal/extension.h b/upb/mini_table/internal/extension.h index b46ee76a3c..ed69e4353d 100644 --- a/upb/mini_table/internal/extension.h +++ b/upb/mini_table/internal/extension.h @@ -28,9 +28,9 @@ struct upb_MiniTableExtension { extern "C" { #endif -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { - return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE upb_CType UPB_PRIVATE(_upb_MiniTableExtension_CType)( + const struct upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(&e->UPB_PRIVATE(field)); } UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( diff --git a/upb/test/fuzz_util.cc b/upb/test/fuzz_util.cc index e4612ae008..665df64f8c 100644 --- a/upb/test/fuzz_util.cc +++ b/upb/test/fuzz_util.cc @@ -96,8 +96,7 @@ void Builder::BuildEnums() { } bool Builder::LinkExtension(upb_MiniTableExtension* ext) { - upb_MiniTableField* field = - (upb_MiniTableField*)upb_MiniTableExtension_AsField(ext); + upb_MiniTableField* field = &ext->UPB_PRIVATE(field); if (upb_MiniTableField_CType(field) == kUpb_CType_Message) { auto mt = NextMiniTable(); if (!mt) field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_Int32; diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 4bc0cd9e65..2c7626ea91 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -820,7 +820,7 @@ static void upb_Decoder_AddKnownMessageSetItem( _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } upb_Message* submsg = _upb_Decoder_NewSubMessage( - d, &ext->ext->UPB_PRIVATE(sub), upb_MiniTableExtension_AsField(ext->ext), + d, &ext->ext->UPB_PRIVATE(sub), &ext->ext->UPB_PRIVATE(field), (upb_TaggedMessagePtr*)&ext->data); upb_DecodeStatus status = upb_Decode( data, size, submsg, upb_MiniTableExtension_GetSubMessage(item_mt), @@ -930,13 +930,13 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX if (idx < t->UPB_PRIVATE(dense_below)) { - /* Fastest case: index into dense fields. */ + // Fastest case: index into dense fields. goto found; } if (t->UPB_PRIVATE(dense_below) < t->UPB_PRIVATE(field_count)) { - /* Linear search non-dense fields. Resume scanning from last_field_index - * since fields are usually in order. */ + // Linear search non-dense fields. Resume scanning from last_field_index + // since fields are usually in order. size_t last = *last_field_index; for (idx = last; idx < t->UPB_PRIVATE(field_count); idx++) { if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { @@ -956,7 +956,7 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, case kUpb_ExtMode_Extendable: { const upb_MiniTableExtension* ext = upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); - if (ext) return upb_MiniTableExtension_AsField(ext); + if (ext) return &ext->UPB_PRIVATE(field); break; } case kUpb_ExtMode_IsMessageSet: @@ -969,7 +969,7 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, } } - return &none; /* Unknown field. */ + return &none; // Unknown field. found: UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number);