Skip to content

Commit

Permalink
Auto-generate files after cl/698497070
Browse files Browse the repository at this point in the history
  • Loading branch information
protobuf-team-bot committed Nov 20, 2024
1 parent 6ce48c2 commit 36111c2
Show file tree
Hide file tree
Showing 4 changed files with 1,208 additions and 1,158 deletions.
175 changes: 65 additions & 110 deletions php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3612,29 +3612,20 @@ void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m) {

// Must be last.

bool upb_Message_NextExtension(const upb_Message* msg,
const upb_MiniTableExtension** result,
uintptr_t* iter) {
size_t count;
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
size_t i = *iter;
if (i >= count) {
return false;
*result = NULL;
}
*result = ext[i].ext;
*iter = i + 1;
return true;
bool upb_Message_NextExtensionReverse(const upb_Message* msg,
const upb_MiniTableExtension** result,
uintptr_t* iter) {
upb_MessageValue val;
return UPB_PRIVATE(_upb_Message_NextExtensionReverse)(msg, result, &val,
iter);
}

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

for (; count--; ext++) {
const upb_MiniTableExtension* e = ext->ext;
if (upb_MiniTableExtension_Number(e) == field_number) return e;
uintptr_t iter = kUpb_Message_ExtensionBegin;
const upb_MiniTableExtension* result;
while (upb_Message_NextExtensionReverse(msg, &result, &iter)) {
if (upb_MiniTableExtension_Number(result) == field_number) return result;
}
return NULL;
}
Expand Down Expand Up @@ -3897,14 +3888,15 @@ static int _upb_mapsorter_cmpext(const void* _a, const void* _b) {
return a_num < b_num ? -1 : 1;
}

bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts,
bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Message_Internal* in,
size_t count, _upb_sortedmap* sorted) {
if (!_upb_mapsorter_resize(s, sorted, count)) return false;
const upb_Extension* exts =
UPB_PTR_AT(in, in->ext_begin, const upb_Extension);

for (size_t i = 0; i < count; i++) {
s->entries[sorted->start + i] = &exts[i];
}

qsort(&s->entries[sorted->start], count, sizeof(*s->entries),
_upb_mapsorter_cmpext);
return true;
Expand All @@ -3919,8 +3911,6 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts,

// Must be last.

static const size_t message_overhead = sizeof(upb_Message_Internal);

upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) {
return _upb_Message_New(m, a);
}
Expand Down Expand Up @@ -3964,39 +3954,14 @@ void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) {
UPB_ASSERT(!upb_Message_IsFrozen(msg));
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (in) {
in->unknown_end = message_overhead;
in->unknown_end = sizeof(upb_Message_Internal);
}
}

bool upb_Message_NextUnknown(const upb_Message* msg, upb_StringView* data,
uintptr_t* iter) {
const upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (in && *iter == kUpb_Message_UnknownBegin) {
size_t len = in->unknown_end - message_overhead;
if (len != 0) {
data->size = len;
data->data = (const char*)(in + 1);
(*iter)++;
return true;
}
}
data->size = 0;
data->data = NULL;
return false;
}

bool upb_Message_HasUnknown(const upb_Message* msg) {
const upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (in) {
return in->unknown_end > message_overhead;
}
return false;
}

const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) {
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (in) {
*len = in->unknown_end - message_overhead;
*len = in->unknown_end - sizeof(upb_Message_Internal);
return (char*)(in + 1);
} else {
*len = 0;
Expand Down Expand Up @@ -4074,17 +4039,13 @@ void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m) {
}

// Extensions.
size_t ext_count;
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count);

for (size_t i = 0; i < ext_count; i++) {
const upb_MiniTableExtension* e = ext[i].ext;
uintptr_t iter = kUpb_Message_ExtensionBegin;
const upb_MiniTableExtension* e;
upb_MessageValue val;
while (upb_Message_NextExtension(msg, &e, &val, &iter)) {
const upb_MiniTableField* f = &e->UPB_PRIVATE(field);
const upb_MiniTable* m2 = upb_MiniTableExtension_GetSubMessage(e);

upb_MessageValue val;
memcpy(&val, &ext[i].data, sizeof(upb_MessageValue));

switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
case kUpb_FieldMode_Array: {
upb_Array* arr = (upb_Array*)val.array_val;
Expand Down Expand Up @@ -4226,8 +4187,8 @@ static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1,
upb_MessageValue val1;

// Iterate over all extensions for msg1, and search msg2 for each extension.
size_t iter1 = kUpb_Extension_Begin;
while (UPB_PRIVATE(_upb_Message_NextExtension)(msg1, m, &e, &val1, &iter1)) {
size_t iter1 = kUpb_Message_ExtensionBegin;
while (upb_Message_NextExtension(msg1, &e, &val1, &iter1)) {
const upb_Extension* ext2 = UPB_PRIVATE(_upb_Message_Getext)(msg2, e);
if (!ext2) return false;

Expand Down Expand Up @@ -7751,6 +7712,7 @@ const char* upb_DecodeStatus_String(upb_DecodeStatus status) {
#include <setjmp.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>


Expand Down Expand Up @@ -8236,32 +8198,33 @@ static void encode_field(upb_encstate* e, const upb_Message* msg,
}
}

static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) {
static void encode_msgset_item(upb_encstate* e,
const upb_MiniTableExtension* ext,
const upb_MessageValue ext_val) {
size_t size;
encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup);
encode_message(e, ext->data.msg_val,
upb_MiniTableExtension_GetSubMessage(ext->ext), &size);
encode_message(e, ext_val.msg_val, upb_MiniTableExtension_GetSubMessage(ext),
&size);
encode_varint(e, size);
encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited);
encode_varint(e, upb_MiniTableExtension_Number(ext->ext));
encode_varint(e, upb_MiniTableExtension_Number(ext));
encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint);
encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup);
}

static void encode_ext(upb_encstate* e, const upb_Extension* ext,
bool is_message_set) {
static void encode_ext(upb_encstate* e, const upb_MiniTableExtension* ext,
upb_MessageValue ext_val, bool is_message_set) {
if (UPB_UNLIKELY(is_message_set)) {
encode_msgset_item(e, ext);
encode_msgset_item(e, ext, ext_val);
} else {
upb_MiniTableSubInternal sub;
if (upb_MiniTableField_IsSubMessage(&ext->ext->UPB_PRIVATE(field))) {
sub.UPB_PRIVATE(submsg) = &ext->ext->UPB_PRIVATE(sub).UPB_PRIVATE(submsg);
if (upb_MiniTableField_IsSubMessage(&ext->UPB_PRIVATE(field))) {
sub.UPB_PRIVATE(submsg) = &ext->UPB_PRIVATE(sub).UPB_PRIVATE(submsg);
} else {
sub.UPB_PRIVATE(subenum) =
ext->ext->UPB_PRIVATE(sub).UPB_PRIVATE(subenum);
sub.UPB_PRIVATE(subenum) = ext->UPB_PRIVATE(sub).UPB_PRIVATE(subenum);
}
encode_field(e, &ext->data.UPB_PRIVATE(ext_msg_val), &sub,
&ext->ext->UPB_PRIVATE(field));
encode_field(e, &ext_val.UPB_PRIVATE(ext_msg_val), &sub,
&ext->UPB_PRIVATE(field));
}
}

Expand All @@ -8281,7 +8244,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
size_t unknown_size = 0;
uintptr_t iter = kUpb_Message_UnknownBegin;
upb_StringView unknown;
// Need to write in reverse order, but list is single-linked; scan to
// Need to write in reverse order, but iteration is in-order; scan to
// reserve capacity up front, then write in-order
while (upb_Message_NextUnknown(msg, &unknown, &iter)) {
unknown_size += unknown.size;
Expand All @@ -8298,24 +8261,33 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
}

if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) {
/* Encode all extensions together. Unlike C++, we do not attempt to keep
* these in field number order relative to normal fields or even to each
* other. */
size_t ext_count;
const upb_Extension* ext =
UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count);
if (ext_count) {
if (e->options & kUpb_EncodeOption_Deterministic) {
_upb_sortedmap sorted;
_upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted);
while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) {
encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet);
}
_upb_mapsorter_popmap(&e->sorter, &sorted);
} else {
const upb_Extension* end = ext + ext_count;
for (; ext != end; ext++) {
encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet);
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (in) {
/* Encode all extensions together. Unlike C++, we do not attempt to keep
* these in field number order relative to normal fields or even to each
* other. */
size_t ext_count = upb_Message_ExtensionCount(msg);
if (ext_count) {
if (e->options & kUpb_EncodeOption_Deterministic) {
_upb_sortedmap sorted;
if (!_upb_mapsorter_pushexts(&e->sorter, in, ext_count, &sorted)) {
// TODO: b/378744096 - handle alloc failure
}
const upb_Extension* ext;
while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) {
encode_ext(e, ext->ext, ext->data,
m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet);
}
_upb_mapsorter_popmap(&e->sorter, &sorted);
} else {
const upb_MiniTableExtension* ext;
upb_MessageValue ext_val;
uintptr_t iter = kUpb_Message_ExtensionBegin;
while (UPB_PRIVATE(_upb_Message_NextExtensionReverse)(
msg, &ext, &ext_val, &iter)) {
encode_ext(e, ext, ext_val,
m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet);
}
}
}
}
Expand Down Expand Up @@ -12393,7 +12365,7 @@ const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
if (in) {
*count = (in->size - in->ext_begin) / sizeof(upb_Extension);
return UPB_PTR_AT(in, in->ext_begin, void);
return UPB_PTR_AT(in, in->ext_begin, const upb_Extension);
} else {
*count = 0;
return NULL;
Expand Down Expand Up @@ -12542,23 +12514,6 @@ bool UPB_PRIVATE(_upb_Message_NextBaseField)(const upb_Message* msg,
return false;
}

bool UPB_PRIVATE(_upb_Message_NextExtension)(
const upb_Message* msg, const upb_MiniTable* m,
const upb_MiniTableExtension** out_e, upb_MessageValue* out_v,
size_t* iter) {
size_t count;
const upb_Extension* exts = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
size_t i = *iter;

if (++i < count) {
*out_e = exts[i].ext;
*out_v = exts[i].data;
*iter = i;
return true;
}

return false;
}

const char _kUpb_ToBase92[] = {
' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/',
Expand Down
Loading

0 comments on commit 36111c2

Please sign in to comment.