Skip to content

Commit

Permalink
Auto-generate files after cl/587127664
Browse files Browse the repository at this point in the history
  • Loading branch information
protobuf-team-bot committed Dec 1, 2023
1 parent 848a2bf commit 7bdd38e
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 98 deletions.
95 changes: 51 additions & 44 deletions php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -7027,19 +7027,20 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d,
if (!upb_MtDecoder_FieldIsPackable(field)) {
upb_MdDecoder_ErrorJmp(&d->base,
"Cannot flip packed on unpackable field %" PRIu32,
field->number);
upb_MiniTableField_Number(field));
}
field->UPB_PRIVATE(mode) ^= kUpb_LabelFlags_IsPacked;
}

if (field_modifiers & kUpb_EncodedFieldModifier_FlipValidateUtf8) {
if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Bytes ||
!(field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate)) {
upb_MdDecoder_ErrorJmp(
&d->base,
"Cannot flip ValidateUtf8 on field %" PRIu32 ", type=%d, mode=%d",
field->number, (int)field->UPB_PRIVATE(descriptortype),
(int)field->UPB_PRIVATE(mode));
upb_MdDecoder_ErrorJmp(&d->base,
"Cannot flip ValidateUtf8 on field %" PRIu32
", type=%d, mode=%d",
upb_MiniTableField_Number(field),
(int)field->UPB_PRIVATE(descriptortype),
(int)field->UPB_PRIVATE(mode));
}
field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_String;
field->UPB_PRIVATE(mode) &= ~kUpb_LabelFlags_IsAlternate;
Expand All @@ -7052,12 +7053,12 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d,
if ((singular || required) && field->offset != kHasbitPresence) {
upb_MdDecoder_ErrorJmp(&d->base,
"Invalid modifier(s) for repeated field %" PRIu32,
field->number);
upb_MiniTableField_Number(field));
}
if (singular && required) {
upb_MdDecoder_ErrorJmp(
&d->base, "Field %" PRIu32 " cannot be both singular and required",
field->number);
upb_MiniTableField_Number(field));
}

if (singular) field->offset = kNoPresence;
Expand Down Expand Up @@ -7258,7 +7259,7 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr,
upb_MiniTableField* field = fields;
*field_count += 1;
fields = (char*)fields + field_size;
field->number = ++last_field_number;
field->UPB_PRIVATE(number) = ++last_field_number;
last_field = field;
upb_MiniTable_SetField(d, ch, field, msg_modifiers, sub_counts);
} else if (kUpb_EncodedValue_MinModifier <= ch &&
Expand Down Expand Up @@ -7460,10 +7461,11 @@ static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d,
const upb_MiniTableField* f,
uint32_t expected_num) {
const char* name = expected_num == 1 ? "key" : "val";
if (f->number != expected_num) {
const uint32_t f_number = upb_MiniTableField_Number(f);
if (f_number != expected_num) {
upb_MdDecoder_ErrorJmp(&d->base,
"map %s did not have expected number (%d vs %d)",
name, expected_num, (int)f->number);
name, expected_num, f_number);
}

if (!upb_MiniTableField_IsScalar(f)) {
Expand Down Expand Up @@ -8241,7 +8243,7 @@ const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(

// Ideal case: index into dense fields
if (i < m->UPB_PRIVATE(dense_below)) {
UPB_ASSERT(m->UPB_PRIVATE(fields)[i].number == number);
UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number);
return &m->UPB_PRIVATE(fields)[i];
}

Expand All @@ -8250,7 +8252,7 @@ const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
int hi = m->UPB_PRIVATE(field_count) - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
uint32_t num = m->UPB_PRIVATE(fields)[mid].number;
uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number);
if (num < number) {
lo = mid + 1;
continue;
Expand Down Expand Up @@ -12917,7 +12919,8 @@ static const char* _upb_Decoder_DecodeKnownGroup(
const upb_MiniTableSub* subs, const upb_MiniTableField* field) {
const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field);
UPB_ASSERT(subl);
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number);
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl,
field->UPB_PRIVATE(number));
}

static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) {
Expand Down Expand Up @@ -12954,7 +12957,8 @@ static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr,
// Unrecognized enum goes into unknown fields.
// For packed fields the tag could be arbitrarily far in the past,
// so we just re-encode the tag and value here.
const uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint;
const uint32_t tag =
((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint;
upb_Message* unknown_msg =
field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension ? d->unknown_msg
: msg;
Expand Down Expand Up @@ -13214,7 +13218,8 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
if (size != 0) {
char* buf;
size_t size;
uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited;
uint32_t tag =
((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited;
upb_EncodeStatus status =
upb_Encode(&ent.data, entry, 0, &d->arena, &buf, &size);
if (status != kUpb_EncodeStatus_Ok) {
Expand Down Expand Up @@ -13254,10 +13259,11 @@ static const char* _upb_Decoder_DecodeToSubMessage(
} else if (field->presence < 0) {
/* Oneof case */
uint32_t* oneof_case = _upb_Message_OneofCasePtr(msg, field);
if (op == kUpb_DecodeOp_SubMessage && *oneof_case != field->number) {
if (op == kUpb_DecodeOp_SubMessage &&
*oneof_case != field->UPB_PRIVATE(number)) {
memset(mem, 0, sizeof(void*));
}
*oneof_case = field->number;
*oneof_case = field->UPB_PRIVATE(number);
}

/* Store into message. */
Expand Down Expand Up @@ -13490,13 +13496,13 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d,
* 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].number == field_number) {
if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) {
goto found;
}
}

for (idx = t->UPB_PRIVATE(dense_below); idx < last; idx++) {
if (t->UPB_PRIVATE(fields)[idx].number == field_number) {
if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) {
goto found;
}
}
Expand All @@ -13523,7 +13529,7 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d,
return &none; /* Unknown field. */

found:
UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].number == field_number);
UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number);
*last_field_index = idx;
return &t->UPB_PRIVATE(fields)[idx];
}
Expand Down Expand Up @@ -13681,7 +13687,7 @@ static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
*op = _upb_Decoder_GetDelimitedOp(d, mt, field);
return ptr;
case kUpb_WireType_StartGroup:
val->uint32_val = field->number;
val->uint32_val = field->UPB_PRIVATE(number);
if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group) {
*op = kUpb_DecodeOp_SubMessage;
_upb_Decoder_CheckUnlinked(d, mt, field, op);
Expand Down Expand Up @@ -15175,7 +15181,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem,
return;
}
if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded);
encode_tag(e, f->number, kUpb_WireType_EndGroup);
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup);
encode_TaggedMessagePtr(e, submsg, subm, &size);
wire_type = kUpb_WireType_StartGroup;
e->depth++;
Expand All @@ -15201,7 +15207,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem,
}
#undef CASE

encode_tag(e, f->number, wire_type);
encode_tag(e, f->UPB_PRIVATE(number), wire_type);
}

static void encode_array(upb_encstate* e, const upb_Message* msg,
Expand All @@ -15215,20 +15221,21 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
return;
}

#define VARINT_CASE(ctype, encode) \
{ \
const ctype* start = _upb_array_constptr(arr); \
const ctype* ptr = start + arr->size; \
uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \
do { \
ptr--; \
encode_varint(e, encode); \
if (tag) encode_varint(e, tag); \
} while (ptr != start); \
} \
#define VARINT_CASE(ctype, encode) \
{ \
const ctype* start = _upb_array_constptr(arr); \
const ctype* ptr = start + arr->size; \
uint32_t tag = \
packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \
do { \
ptr--; \
encode_varint(e, encode); \
if (tag) encode_varint(e, tag); \
} while (ptr != start); \
} \
break;

#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type))
#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type))

switch (f->UPB_PRIVATE(descriptortype)) {
case kUpb_FieldType_Double:
Expand Down Expand Up @@ -15267,7 +15274,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
ptr--;
encode_bytes(e, ptr->data, ptr->size);
encode_varint(e, ptr->size);
encode_tag(e, f->number, kUpb_WireType_Delimited);
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited);
} while (ptr != start);
return;
}
Expand All @@ -15280,9 +15287,9 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
do {
size_t size;
ptr--;
encode_tag(e, f->number, kUpb_WireType_EndGroup);
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup);
encode_TaggedMessagePtr(e, *ptr, subm, &size);
encode_tag(e, f->number, kUpb_WireType_StartGroup);
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup);
} while (ptr != start);
e->depth++;
return;
Expand All @@ -15298,7 +15305,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
ptr--;
encode_TaggedMessagePtr(e, *ptr, subm, &size);
encode_varint(e, size);
encode_tag(e, f->number, kUpb_WireType_Delimited);
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited);
} while (ptr != start);
e->depth++;
return;
Expand All @@ -15308,7 +15315,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,

if (packed) {
encode_varint(e, e->limit - e->ptr - pre_len);
encode_tag(e, f->number, kUpb_WireType_Delimited);
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited);
}
}

Expand Down Expand Up @@ -15343,7 +15350,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
map, &sorted);
upb_MapEntry ent;
while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) {
encode_mapentry(e, f->number, layout, &ent);
encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent);
}
_upb_mapsorter_popmap(&e->sorter, &sorted);
} else {
Expand All @@ -15354,7 +15361,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
upb_MapEntry ent;
_upb_map_fromkey(key, &ent.data.k, map->key_size);
_upb_map_fromvalue(val, &ent.data.v, map->val_size);
encode_mapentry(e, f->number, layout, &ent);
encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent);
}
}
}
Expand Down Expand Up @@ -15393,7 +15400,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg,
return _upb_Message_GetHasbitByField(msg, f);
} else {
// Field is in a oneof.
return _upb_Message_GetOneofCase(msg, f) == f->number;
return _upb_Message_GetOneofCase(msg, f) == f->UPB_PRIVATE(number);
}
}

Expand Down
22 changes: 17 additions & 5 deletions php/ext/google/protobuf/php-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e,
#ifndef UPB_MINI_TABLE_FIELD_H_
#define UPB_MINI_TABLE_FIELD_H_

#include <stdint.h>


#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_
#define UPB_MINI_TABLE_INTERNAL_FIELD_H_
Expand Down Expand Up @@ -1088,7 +1090,7 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) {

// LINT.IfChange(struct_definition)
struct upb_MiniTableField {
uint32_t number;
uint32_t UPB_ONLYBITS(number);
uint16_t offset;
int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index

Expand Down Expand Up @@ -1224,6 +1226,11 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)(
}
}

UPB_INLINE uint32_t
UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) {
return f->UPB_ONLYBITS(number);
}

UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(
const struct upb_MiniTableField* f) {
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
Expand Down Expand Up @@ -1306,6 +1313,10 @@ UPB_API_INLINE bool upb_MiniTableField_IsSubMessage(
return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f);
}

UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) {
return UPB_PRIVATE(_upb_MiniTableField_Number)(f);
}

UPB_API_INLINE upb_FieldType
upb_MiniTableField_Type(const upb_MiniTableField* f) {
return UPB_PRIVATE(_upb_MiniTableField_Type)(f);
Expand Down Expand Up @@ -1629,7 +1640,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(

UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)(
const struct upb_MiniTableExtension* e) {
return e->UPB_PRIVATE(field).number;
return e->UPB_PRIVATE(field).UPB_ONLYBITS(number);
}

UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(
Expand Down Expand Up @@ -2554,7 +2565,7 @@ UPB_INLINE uint32_t _upb_Message_GetOneofCase(const upb_Message* msg,

UPB_INLINE void _upb_Message_SetOneofCase(upb_Message* msg,
const upb_MiniTableField* f) {
*_upb_Message_OneofCasePtr(msg, f) = f->number;
*_upb_Message_OneofCasePtr(msg, f) = upb_MiniTableField_Number(f);
}

// TODO: implement _upb_Message_ClearOneofCase()
Expand Down Expand Up @@ -2662,7 +2673,8 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField(
UPB_ASSERT(upb_MiniTableField_HasPresence(field));
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
if (upb_MiniTableField_IsInOneof(field)) {
return _upb_Message_GetOneofCase(msg, field) == field->number;
return _upb_Message_GetOneofCase(msg, field) ==
upb_MiniTableField_Number(field);
} else {
return _upb_Message_GetHasbitByField(msg, field);
}
Expand Down Expand Up @@ -2760,7 +2772,7 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField(
_upb_Message_ClearHasbitByField(msg, field);
} else if (upb_MiniTableField_IsInOneof(field)) {
uint32_t* ptr = _upb_Message_OneofCasePtr(msg, field);
if (*ptr != field->number) return;
if (*ptr != upb_MiniTableField_Number(field)) return;
*ptr = 0;
}
const char zeros[16] = {0};
Expand Down
Loading

0 comments on commit 7bdd38e

Please sign in to comment.