Auto-generate files after PR #15040

pull/15053/head
Protobuf Team Bot 12 months ago
parent 64a88ffb86
commit ddc5406170
  1. 54
      php/ext/google/protobuf/php-upb.c
  2. 69
      php/ext/google/protobuf/php-upb.h
  3. 54
      ruby/ext/google/protobuf_c/ruby-upb.c
  4. 69
      ruby/ext/google/protobuf_c/ruby-upb.h

@ -6197,7 +6197,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
if (unknown_size != 0) {
UPB_ASSERT(ptr);
// Make a copy into destination arena.
if (!_upb_Message_AddUnknown(dst, ptr, unknown_size, arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) {
return NULL;
}
}
@ -6552,6 +6552,9 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) {
}
#include <stdint.h>
#include <string.h>
// Must be last.
@ -6633,8 +6636,10 @@ static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted,
sorted->end = sorted->start + size;
if (sorted->end > s->cap) {
const int oldsize = s->cap * sizeof(*s->entries);
s->cap = upb_Log2CeilingSize(sorted->end);
s->entries = realloc(s->entries, s->cap * sizeof(*s->entries));
const int newsize = s->cap * sizeof(*s->entries);
s->entries = upb_grealloc(s->entries, oldsize, newsize);
if (!s->entries) return false;
}
@ -6690,18 +6695,21 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s,
}
#include <stddef.h>
#include <stdint.h>
#include <string.h>
// Must be last.
static const size_t message_overhead = sizeof(upb_Message_InternalData);
upb_Message* upb_Message_New(const upb_MiniTable* mini_table,
upb_Arena* arena) {
return _upb_Message_New(mini_table, arena);
upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) {
return _upb_Message_New(m, arena);
}
bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
upb_Arena* arena) {
bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data,
size_t len, upb_Arena* arena) {
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false;
upb_Message_Internal* in = upb_Message_Getinternal(msg);
memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len);
@ -8827,7 +8835,7 @@ const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s,
const upb_FieldDef* f = upb_value_getconstptr(val);
if (upb_FieldDef_ContainingType(f) == m) n++;
}
const upb_FieldDef** exts = malloc(n * sizeof(*exts));
const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts));
iter = UPB_INTTABLE_BEGIN;
size_t i = 0;
while (upb_inttable_next(&s->exts, &key, &val, &iter)) {
@ -10919,15 +10927,15 @@ const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx,
if (sym.size == 0) goto notfound;
upb_value v;
if (sym.data[0] == '.') {
/* Symbols starting with '.' are absolute, so we do a single lookup.
* Slice to omit the leading '.' */
// Symbols starting with '.' are absolute, so we do a single lookup.
// Slice to omit the leading '.'
if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) {
goto notfound;
}
} else {
/* Remove components from base until we find an entry or run out. */
// Remove components from base until we find an entry or run out.
size_t baselen = base ? strlen(base) : 0;
char* tmp = malloc(sym.size + baselen + 1);
char* tmp = upb_gmalloc(sym.size + baselen + 1);
while (1) {
char* p = tmp;
if (baselen) {
@ -10941,11 +10949,11 @@ const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx,
break;
}
if (!remove_component(tmp, &baselen)) {
free(tmp);
upb_gfree(tmp);
goto notfound;
}
}
free(tmp);
upb_gfree(tmp);
}
*type = _upb_DefType_Type(v);
@ -11349,7 +11357,8 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
if (!val.array_val || upb_Array_Size(val.array_val) == 0) continue;
break;
case kUpb_FieldMode_Scalar:
if (!_upb_MiniTable_ValueIsNonZero(&val, field)) continue;
if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, &val))
continue;
break;
}
}
@ -12970,7 +12979,7 @@ static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
end = upb_Decoder_EncodeVarint32(val1, end);
end = upb_Decoder_EncodeVarint32(val2, end);
if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, end - buf, &d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
}
@ -13256,7 +13265,7 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
_upb_Decoder_AddUnknownVarints(d, msg, tag, size);
if (!_upb_Message_AddUnknown(msg, buf, size, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, size, &d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
} else {
@ -13434,9 +13443,11 @@ static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d,
ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr);
char* end = ptr;
if (!_upb_Message_AddUnknown(msg, buf, split - buf, &d->arena) ||
!_upb_Message_AddUnknown(msg, message_data, message_size, &d->arena) ||
!_upb_Message_AddUnknown(msg, split, end - split, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, split - buf, &d->arena) ||
!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, message_data, message_size,
&d->arena) ||
!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, split, end - split,
&d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
}
@ -13821,7 +13832,8 @@ static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d,
start = d->unknown;
d->unknown = NULL;
}
if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, start, ptr - start,
&d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
} else if (wire_type == kUpb_WireType_StartGroup) {

@ -522,7 +522,7 @@ UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) {
}
UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) {
return a.size == b.size && memcmp(a.data, b.data, a.size) == 0;
return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size));
}
// LINT.ThenChange(
@ -1626,8 +1626,7 @@ extern "C" {
#endif
// Creates a new message with the given mini_table on the given arena.
UPB_API upb_Message* upb_Message_New(const upb_MiniTable* mini_table,
upb_Arena* arena);
UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena);
// Returns a reference to the message's unknown data.
const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len);
@ -2424,8 +2423,8 @@ void _upb_Message_DiscardUnknown_shallow(upb_Message* msg);
// Adds unknown data (serialized protobuf data) to the given message.
// The data is copied into the message instance.
bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
upb_Arena* arena);
bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data,
size_t len, upb_Arena* arena);
bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need,
upb_Arena* arena);
@ -2527,26 +2526,32 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)(
}
}
UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val,
const upb_MiniTableField* field) {
char zero[16] = {0};
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)(
const upb_MiniTableField* field, const void* a, const void* b) {
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) {
case kUpb_FieldRep_1Byte:
return memcmp(&zero, default_val, 1) != 0;
return memcmp(a, b, 1) == 0;
case kUpb_FieldRep_4Byte:
return memcmp(&zero, default_val, 4) != 0;
return memcmp(a, b, 4) == 0;
case kUpb_FieldRep_8Byte:
return memcmp(&zero, default_val, 8) != 0;
return memcmp(a, b, 8) == 0;
case kUpb_FieldRep_StringView: {
const upb_StringView* sv = (const upb_StringView*)default_val;
return sv->size != 0;
const upb_StringView sa = *(const upb_StringView*)a;
const upb_StringView sb = *(const upb_StringView*)b;
return upb_StringView_IsEqual(sa, sb);
}
}
UPB_UNREACHABLE();
}
UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from,
const upb_MiniTableField* field) {
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
const upb_MiniTableField* field, const void* val) {
const char zero[16] = {0};
return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(field, val, zero);
}
UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)(
const upb_MiniTableField* field, void* to, const void* from) {
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) {
case kUpb_FieldRep_1Byte:
memcpy(to, from, 1);
@ -2621,24 +2626,26 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField(
const void* default_val, void* val) {
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
if ((upb_MiniTableField_IsInOneof(field) ||
_upb_MiniTable_ValueIsNonZero(default_val, field)) &&
!UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, default_val)) &&
!_upb_Message_HasNonExtensionField(msg, field)) {
_upb_MiniTable_CopyFieldData(val, default_val, field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(field, val, default_val);
return;
}
_upb_MiniTable_CopyFieldData(val, _upb_MiniTableField_GetConstPtr(msg, field),
field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(field, val, _upb_MiniTableField_GetConstPtr(msg, field));
}
UPB_INLINE void _upb_Message_GetExtensionField(
const upb_Message* msg, const upb_MiniTableExtension* mt_ext,
const void* default_val, void* val) {
UPB_ASSUME(upb_MiniTableField_IsExtension(&mt_ext->UPB_PRIVATE(field)));
const upb_Message_Extension* ext = _upb_Message_Getext(msg, mt_ext);
const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field);
UPB_ASSUME(upb_MiniTableField_IsExtension(f));
if (ext) {
_upb_MiniTable_CopyFieldData(val, &ext->data, &mt_ext->UPB_PRIVATE(field));
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, &ext->data);
} else {
_upb_MiniTable_CopyFieldData(val, default_val, &mt_ext->UPB_PRIVATE(field));
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, default_val);
}
}
@ -2673,8 +2680,8 @@ UPB_INLINE void _upb_Message_SetNonExtensionField(
upb_Message* msg, const upb_MiniTableField* field, const void* val) {
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
UPB_PRIVATE(_upb_Message_SetPresence)(msg, field);
_upb_MiniTable_CopyFieldData(_upb_MiniTableField_GetPtr(msg, field), val,
field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(field, _upb_MiniTableField_GetPtr(msg, field), val);
}
UPB_INLINE bool _upb_Message_SetExtensionField(
@ -2684,7 +2691,8 @@ UPB_INLINE bool _upb_Message_SetExtensionField(
upb_Message_Extension* ext =
_upb_Message_GetOrCreateExtension(msg, mt_ext, a);
if (!ext) return false;
_upb_MiniTable_CopyFieldData(&ext->data, val, &mt_ext->UPB_PRIVATE(field));
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(&mt_ext->UPB_PRIVATE(field), &ext->data, val);
return true;
}
@ -2712,8 +2720,8 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField(
*ptr = 0;
}
const char zeros[16] = {0};
_upb_MiniTable_CopyFieldData(_upb_MiniTableField_GetPtr(msg, field), zeros,
field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(field, _upb_MiniTableField_GetPtr(msg, field), zeros);
}
UPB_INLINE void _upb_Message_AssertMapIsUntagged(
@ -2861,7 +2869,6 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i,
// LINT.ThenChange(
// GoogleInternalName1,
// //depot/google3/third_party/upb/bits/typescript/array.ts
//)
#ifdef __cplusplus
@ -12531,7 +12538,7 @@ UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) {
}
UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) {
if (s->entries) free(s->entries);
if (s->entries) upb_gfree(s->entries);
}
UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map,
@ -13551,8 +13558,8 @@ UPB_INLINE const char* _upb_Decoder_BufferFlipCallback(
if (!old_end) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
if (d->unknown) {
if (!_upb_Message_AddUnknown(d->unknown_msg, d->unknown,
old_end - d->unknown, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(
d->unknown_msg, d->unknown, old_end - d->unknown, &d->arena)) {
_upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
d->unknown = new_start;

@ -5711,7 +5711,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
if (unknown_size != 0) {
UPB_ASSERT(ptr);
// Make a copy into destination arena.
if (!_upb_Message_AddUnknown(dst, ptr, unknown_size, arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) {
return NULL;
}
}
@ -6066,6 +6066,9 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) {
}
#include <stdint.h>
#include <string.h>
// Must be last.
@ -6147,8 +6150,10 @@ static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted,
sorted->end = sorted->start + size;
if (sorted->end > s->cap) {
const int oldsize = s->cap * sizeof(*s->entries);
s->cap = upb_Log2CeilingSize(sorted->end);
s->entries = realloc(s->entries, s->cap * sizeof(*s->entries));
const int newsize = s->cap * sizeof(*s->entries);
s->entries = upb_grealloc(s->entries, oldsize, newsize);
if (!s->entries) return false;
}
@ -6204,18 +6209,21 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s,
}
#include <stddef.h>
#include <stdint.h>
#include <string.h>
// Must be last.
static const size_t message_overhead = sizeof(upb_Message_InternalData);
upb_Message* upb_Message_New(const upb_MiniTable* mini_table,
upb_Arena* arena) {
return _upb_Message_New(mini_table, arena);
upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) {
return _upb_Message_New(m, arena);
}
bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
upb_Arena* arena) {
bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data,
size_t len, upb_Arena* arena) {
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false;
upb_Message_Internal* in = upb_Message_Getinternal(msg);
memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len);
@ -8341,7 +8349,7 @@ const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s,
const upb_FieldDef* f = upb_value_getconstptr(val);
if (upb_FieldDef_ContainingType(f) == m) n++;
}
const upb_FieldDef** exts = malloc(n * sizeof(*exts));
const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts));
iter = UPB_INTTABLE_BEGIN;
size_t i = 0;
while (upb_inttable_next(&s->exts, &key, &val, &iter)) {
@ -10433,15 +10441,15 @@ const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx,
if (sym.size == 0) goto notfound;
upb_value v;
if (sym.data[0] == '.') {
/* Symbols starting with '.' are absolute, so we do a single lookup.
* Slice to omit the leading '.' */
// Symbols starting with '.' are absolute, so we do a single lookup.
// Slice to omit the leading '.'
if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) {
goto notfound;
}
} else {
/* Remove components from base until we find an entry or run out. */
// Remove components from base until we find an entry or run out.
size_t baselen = base ? strlen(base) : 0;
char* tmp = malloc(sym.size + baselen + 1);
char* tmp = upb_gmalloc(sym.size + baselen + 1);
while (1) {
char* p = tmp;
if (baselen) {
@ -10455,11 +10463,11 @@ const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx,
break;
}
if (!remove_component(tmp, &baselen)) {
free(tmp);
upb_gfree(tmp);
goto notfound;
}
}
free(tmp);
upb_gfree(tmp);
}
*type = _upb_DefType_Type(v);
@ -10863,7 +10871,8 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
if (!val.array_val || upb_Array_Size(val.array_val) == 0) continue;
break;
case kUpb_FieldMode_Scalar:
if (!_upb_MiniTable_ValueIsNonZero(&val, field)) continue;
if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, &val))
continue;
break;
}
}
@ -12484,7 +12493,7 @@ static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
end = upb_Decoder_EncodeVarint32(val1, end);
end = upb_Decoder_EncodeVarint32(val2, end);
if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, end - buf, &d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
}
@ -12770,7 +12779,7 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
_upb_Decoder_AddUnknownVarints(d, msg, tag, size);
if (!_upb_Message_AddUnknown(msg, buf, size, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, size, &d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
} else {
@ -12948,9 +12957,11 @@ static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d,
ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr);
char* end = ptr;
if (!_upb_Message_AddUnknown(msg, buf, split - buf, &d->arena) ||
!_upb_Message_AddUnknown(msg, message_data, message_size, &d->arena) ||
!_upb_Message_AddUnknown(msg, split, end - split, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, split - buf, &d->arena) ||
!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, message_data, message_size,
&d->arena) ||
!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, split, end - split,
&d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
}
@ -13335,7 +13346,8 @@ static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d,
start = d->unknown;
d->unknown = NULL;
}
if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, start, ptr - start,
&d->arena)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
} else if (wire_type == kUpb_WireType_StartGroup) {

@ -524,7 +524,7 @@ UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) {
}
UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) {
return a.size == b.size && memcmp(a.data, b.data, a.size) == 0;
return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size));
}
// LINT.ThenChange(
@ -1628,8 +1628,7 @@ extern "C" {
#endif
// Creates a new message with the given mini_table on the given arena.
UPB_API upb_Message* upb_Message_New(const upb_MiniTable* mini_table,
upb_Arena* arena);
UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena);
// Returns a reference to the message's unknown data.
const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len);
@ -2426,8 +2425,8 @@ void _upb_Message_DiscardUnknown_shallow(upb_Message* msg);
// Adds unknown data (serialized protobuf data) to the given message.
// The data is copied into the message instance.
bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
upb_Arena* arena);
bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data,
size_t len, upb_Arena* arena);
bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need,
upb_Arena* arena);
@ -2529,26 +2528,32 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)(
}
}
UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val,
const upb_MiniTableField* field) {
char zero[16] = {0};
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)(
const upb_MiniTableField* field, const void* a, const void* b) {
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) {
case kUpb_FieldRep_1Byte:
return memcmp(&zero, default_val, 1) != 0;
return memcmp(a, b, 1) == 0;
case kUpb_FieldRep_4Byte:
return memcmp(&zero, default_val, 4) != 0;
return memcmp(a, b, 4) == 0;
case kUpb_FieldRep_8Byte:
return memcmp(&zero, default_val, 8) != 0;
return memcmp(a, b, 8) == 0;
case kUpb_FieldRep_StringView: {
const upb_StringView* sv = (const upb_StringView*)default_val;
return sv->size != 0;
const upb_StringView sa = *(const upb_StringView*)a;
const upb_StringView sb = *(const upb_StringView*)b;
return upb_StringView_IsEqual(sa, sb);
}
}
UPB_UNREACHABLE();
}
UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from,
const upb_MiniTableField* field) {
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
const upb_MiniTableField* field, const void* val) {
const char zero[16] = {0};
return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(field, val, zero);
}
UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)(
const upb_MiniTableField* field, void* to, const void* from) {
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) {
case kUpb_FieldRep_1Byte:
memcpy(to, from, 1);
@ -2623,24 +2628,26 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField(
const void* default_val, void* val) {
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
if ((upb_MiniTableField_IsInOneof(field) ||
_upb_MiniTable_ValueIsNonZero(default_val, field)) &&
!UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, default_val)) &&
!_upb_Message_HasNonExtensionField(msg, field)) {
_upb_MiniTable_CopyFieldData(val, default_val, field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(field, val, default_val);
return;
}
_upb_MiniTable_CopyFieldData(val, _upb_MiniTableField_GetConstPtr(msg, field),
field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(field, val, _upb_MiniTableField_GetConstPtr(msg, field));
}
UPB_INLINE void _upb_Message_GetExtensionField(
const upb_Message* msg, const upb_MiniTableExtension* mt_ext,
const void* default_val, void* val) {
UPB_ASSUME(upb_MiniTableField_IsExtension(&mt_ext->UPB_PRIVATE(field)));
const upb_Message_Extension* ext = _upb_Message_Getext(msg, mt_ext);
const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field);
UPB_ASSUME(upb_MiniTableField_IsExtension(f));
if (ext) {
_upb_MiniTable_CopyFieldData(val, &ext->data, &mt_ext->UPB_PRIVATE(field));
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, &ext->data);
} else {
_upb_MiniTable_CopyFieldData(val, default_val, &mt_ext->UPB_PRIVATE(field));
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, default_val);
}
}
@ -2675,8 +2682,8 @@ UPB_INLINE void _upb_Message_SetNonExtensionField(
upb_Message* msg, const upb_MiniTableField* field, const void* val) {
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
UPB_PRIVATE(_upb_Message_SetPresence)(msg, field);
_upb_MiniTable_CopyFieldData(_upb_MiniTableField_GetPtr(msg, field), val,
field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(field, _upb_MiniTableField_GetPtr(msg, field), val);
}
UPB_INLINE bool _upb_Message_SetExtensionField(
@ -2686,7 +2693,8 @@ UPB_INLINE bool _upb_Message_SetExtensionField(
upb_Message_Extension* ext =
_upb_Message_GetOrCreateExtension(msg, mt_ext, a);
if (!ext) return false;
_upb_MiniTable_CopyFieldData(&ext->data, val, &mt_ext->UPB_PRIVATE(field));
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(&mt_ext->UPB_PRIVATE(field), &ext->data, val);
return true;
}
@ -2714,8 +2722,8 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField(
*ptr = 0;
}
const char zeros[16] = {0};
_upb_MiniTable_CopyFieldData(_upb_MiniTableField_GetPtr(msg, field), zeros,
field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
(field, _upb_MiniTableField_GetPtr(msg, field), zeros);
}
UPB_INLINE void _upb_Message_AssertMapIsUntagged(
@ -2863,7 +2871,6 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i,
// LINT.ThenChange(
// GoogleInternalName1,
// //depot/google3/third_party/upb/bits/typescript/array.ts
//)
#ifdef __cplusplus
@ -12303,7 +12310,7 @@ UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) {
}
UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) {
if (s->entries) free(s->entries);
if (s->entries) upb_gfree(s->entries);
}
UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map,
@ -13370,8 +13377,8 @@ UPB_INLINE const char* _upb_Decoder_BufferFlipCallback(
if (!old_end) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
if (d->unknown) {
if (!_upb_Message_AddUnknown(d->unknown_msg, d->unknown,
old_end - d->unknown, &d->arena)) {
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(
d->unknown_msg, d->unknown, old_end - d->unknown, &d->arena)) {
_upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
d->unknown = new_start;

Loading…
Cancel
Save