upb: add upb_MiniTableExtension_CType()

PiperOrigin-RevId: 599313198
pull/15472/head
Eric Salo 10 months ago committed by Copybara-Service
parent 8eb7c63ee7
commit 7c5ff29979
  1. 3
      upb/message/promote.c
  2. 8
      upb/mini_table/extension.h
  3. 6
      upb/mini_table/internal/extension.h
  4. 3
      upb/test/fuzz_util.cc
  5. 12
      upb/wire/decode.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;

@ -10,7 +10,7 @@
#include <stdint.h>
#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

@ -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)(

@ -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;

@ -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);

Loading…
Cancel
Save