diff --git a/Makefile.am b/Makefile.am index ddbe08b2f051..9131d6645575 100644 --- a/Makefile.am +++ b/Makefile.am @@ -827,7 +827,6 @@ php_EXTRA_DIST= \ php/ext/google/protobuf/wkt.inc \ php/generate_descriptor_protos.sh \ php/generate_test_protos.sh \ - php/prepare_c_extension.sh \ php/release.sh \ php/src/GPBMetadata/Google/Protobuf/Any.php \ php/src/GPBMetadata/Google/Protobuf/Api.php \ @@ -1427,8 +1426,6 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ protobuf_deps.bzl \ third_party/six.BUILD \ third_party/zlib.BUILD \ - third_party/wyhash/LICENSE \ - third_party/wyhash/wyhash.h \ util/python/BUILD \ internal.bzl diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 7aaa5e25dd20..30f504827294 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -46,8 +46,6 @@ - - diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 774c8d22eb79..a668fe0c6d5c 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -169,7 +169,7 @@ /* Configure whether fasttable is switched on or not. *************************/ -#if defined(__has_attribute) +#ifdef __has_attribute #define UPB_HAS_ATTRIBUTE(x) __has_attribute(x) #else #define UPB_HAS_ATTRIBUTE(x) 0 @@ -524,24 +524,43 @@ static void decode_munge(int type, wireval *val) { } static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, - uint32_t field_number) { + uint32_t field_number, + int *last_field_index) { static upb_msglayout_field none = {0, 0, 0, 0, 0, 0}; - /* Lots of optimization opportunities here. */ - int i; if (l == NULL) return &none; - for (i = 0; i < l->field_count; i++) { - if (l->fields[i].number == field_number) { - return &l->fields[i]; + + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX + if (idx < l->dense_below) { + goto found; + } + + /* Resume scanning from last_field_index since fields are usually in order. */ + int last = *last_field_index; + for (idx = last; idx < l->field_count; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + + for (idx = 0; idx < last; idx++) { + if (l->fields[idx].number == field_number) { + goto found; } } return &none; /* Unknown field. */ + + found: + UPB_ASSERT(l->fields[idx].number == field_number); + *last_field_index = idx; + return &l->fields[idx]; } -static upb_msg *decode_newsubmsg(upb_decstate *d, const upb_msglayout *layout, +static upb_msg *decode_newsubmsg(upb_decstate *d, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field) { - const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + const upb_msglayout *subl = submsgs[field->submsg_index]; return _upb_msg_new_inl(subl, &d->arena); } @@ -571,9 +590,10 @@ static const char *decode_readstr(upb_decstate *d, const char *ptr, int size, UPB_FORCEINLINE static const char *decode_tosubmsg(upb_decstate *d, const char *ptr, - upb_msg *submsg, const upb_msglayout *layout, + upb_msg *submsg, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field, int size) { - const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + const upb_msglayout *subl = submsgs[field->submsg_index]; int saved_delta = decode_pushlimit(d, ptr, size); if (--d->depth < 0) decode_err(d); if (!decode_isdone(d, &ptr)) { @@ -602,15 +622,17 @@ static const char *decode_group(upb_decstate *d, const char *ptr, UPB_FORCEINLINE static const char *decode_togroup(upb_decstate *d, const char *ptr, - upb_msg *submsg, const upb_msglayout *layout, + upb_msg *submsg, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field) { - const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + const upb_msglayout *subl = submsgs[field->submsg_index]; return decode_group(d, ptr, submsg, subl, field->number); } static const char *decode_toarray(upb_decstate *d, const char *ptr, - upb_msg *msg, const upb_msglayout *layout, - const upb_msglayout_field *field, wireval val, + upb_msg *msg, + upb_msglayout const *const *submsgs, + const upb_msglayout_field *field, wireval *val, int op) { upb_array **arrp = UPB_PTR_AT(msg, field->offset, void); upb_array *arr = *arrp; @@ -632,27 +654,27 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, /* Append scalar value. */ mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void); arr->len++; - memcpy(mem, &val, 1 << op); + memcpy(mem, val, 1 << op); return ptr; case OP_STRING: - decode_verifyutf8(d, ptr, val.size); + decode_verifyutf8(d, ptr, val->size); /* Fallthrough. */ case OP_BYTES: { /* Append bytes. */ upb_strview *str = (upb_strview*)_upb_array_ptr(arr) + arr->len; arr->len++; - return decode_readstr(d, ptr, val.size, str); + return decode_readstr(d, ptr, val->size, str); } case OP_SUBMSG: { /* Append submessage / group. */ - upb_msg *submsg = decode_newsubmsg(d, layout, field); + upb_msg *submsg = decode_newsubmsg(d, submsgs, field); *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void *), upb_msg *) = submsg; arr->len++; if (UPB_UNLIKELY(field->descriptortype == UPB_DTYPE_GROUP)) { - return decode_togroup(d, ptr, submsg, layout, field); + return decode_togroup(d, ptr, submsg, submsgs, field); } else { - return decode_tosubmsg(d, ptr, submsg, layout, field, val.size); + return decode_tosubmsg(d, ptr, submsg, submsgs, field, val->size); } } case OP_FIXPCK_LG2(2): @@ -660,15 +682,15 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, /* Fixed packed. */ int lg2 = op - OP_FIXPCK_LG2(0); int mask = (1 << lg2) - 1; - size_t count = val.size >> lg2; - if ((val.size & mask) != 0) { + size_t count = val->size >> lg2; + if ((val->size & mask) != 0) { decode_err(d); /* Length isn't a round multiple of elem size. */ } decode_reserve(d, arr, count); mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); arr->len += count; - memcpy(mem, ptr, val.size); /* XXX: ptr boundary. */ - return ptr + val.size; + memcpy(mem, ptr, val->size); /* XXX: ptr boundary. */ + return ptr + val->size; } case OP_VARPCK_LG2(0): case OP_VARPCK_LG2(2): @@ -676,7 +698,7 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, /* Varint packed. */ int lg2 = op - OP_VARPCK_LG2(0); int scale = 1 << lg2; - int saved_limit = decode_pushlimit(d, ptr, val.size); + int saved_limit = decode_pushlimit(d, ptr, val->size); char *out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); while (!decode_isdone(d, &ptr)) { wireval elem; @@ -698,16 +720,15 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, } static const char *decode_tomap(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *layout, - const upb_msglayout_field *field, wireval val) { + upb_msglayout const *const *submsgs, + const upb_msglayout_field *field, wireval *val) { upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *); upb_map *map = *map_p; upb_map_entry ent; - const upb_msglayout *entry = layout->submsgs[field->submsg_index]; + const upb_msglayout *entry = submsgs[field->submsg_index]; if (!map) { /* Lazily create map. */ - const upb_msglayout *entry = layout->submsgs[field->submsg_index]; const upb_msglayout_field *key_field = &entry->fields[0]; const upb_msglayout_field *val_field = &entry->fields[1]; char key_size = desctype_to_mapsize[key_field->descriptortype]; @@ -727,28 +748,28 @@ static const char *decode_tomap(upb_decstate *d, const char *ptr, upb_msg *msg, ent.v.val = upb_value_ptr(_upb_msg_new(entry->submsgs[0], &d->arena)); } - ptr = decode_tosubmsg(d, ptr, &ent.k, layout, field, val.size); + ptr = decode_tosubmsg(d, ptr, &ent.k, submsgs, field, val->size); _upb_map_set(map, &ent.k, map->key_size, &ent.v, map->val_size, &d->arena); return ptr; } static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *layout, - const upb_msglayout_field *field, wireval val, + upb_msglayout const *const *submsgs, + const upb_msglayout_field *field, wireval *val, int op) { void *mem = UPB_PTR_AT(msg, field->offset, void); int type = field->descriptortype; /* Set presence if necessary. */ - if (field->presence < 0) { + if (field->presence > 0) { + _upb_sethas_field(msg, field); + } else if (field->presence < 0) { /* Oneof case */ uint32_t *oneof_case = _upb_oneofcase_field(msg, field); if (op == OP_SUBMSG && *oneof_case != field->number) { memset(mem, 0, sizeof(void*)); } *oneof_case = field->number; - } else if (field->presence > 0) { - _upb_sethas_field(msg, field); } /* Store into message. */ @@ -757,29 +778,29 @@ static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, upb_msg **submsgp = mem; upb_msg *submsg = *submsgp; if (!submsg) { - submsg = decode_newsubmsg(d, layout, field); + submsg = decode_newsubmsg(d, submsgs, field); *submsgp = submsg; } if (UPB_UNLIKELY(type == UPB_DTYPE_GROUP)) { - ptr = decode_togroup(d, ptr, submsg, layout, field); + ptr = decode_togroup(d, ptr, submsg, submsgs, field); } else { - ptr = decode_tosubmsg(d, ptr, submsg, layout, field, val.size); + ptr = decode_tosubmsg(d, ptr, submsg, submsgs, field, val->size); } break; } case OP_STRING: - decode_verifyutf8(d, ptr, val.size); + decode_verifyutf8(d, ptr, val->size); /* Fallthrough. */ case OP_BYTES: - return decode_readstr(d, ptr, val.size, mem); + return decode_readstr(d, ptr, val->size, mem); case OP_SCALAR_LG2(3): - memcpy(mem, &val, 8); + memcpy(mem, val, 8); break; case OP_SCALAR_LG2(2): - memcpy(mem, &val, 4); + memcpy(mem, val, 4); break; case OP_SCALAR_LG2(0): - memcpy(mem, &val, 1); + memcpy(mem, val, 1); break; default: UPB_UNREACHABLE(); @@ -805,6 +826,7 @@ static bool decode_tryfastdispatch(upb_decstate *d, const char **ptr, UPB_NOINLINE static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, const upb_msglayout *layout) { + int last_field_index = 0; while (true) { uint32_t tag; const upb_msglayout_field *field; @@ -819,7 +841,7 @@ static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, field_number = tag >> 3; wire_type = tag & 7; - field = upb_find_field(layout, field_number); + field = upb_find_field(layout, field_number, &last_field_index); switch (wire_type) { case UPB_WIRE_TYPE_VARINT: @@ -844,7 +866,7 @@ static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, case UPB_WIRE_TYPE_DELIMITED: { int ndx = field->descriptortype; uint64_t size; - if (_upb_isrepeated(field)) ndx += 18; + if (_upb_getmode(field) == _UPB_MODE_ARRAY) ndx += 18; ptr = decode_varint64(d, ptr, &size); if (size >= INT32_MAX || ptr - d->end + (int32_t)size > d->limit) { @@ -868,17 +890,18 @@ static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, if (op >= 0) { /* Parse, using op for dispatch. */ - switch (field->label) { - case UPB_LABEL_REPEATED: - case _UPB_LABEL_PACKED: - ptr = decode_toarray(d, ptr, msg, layout, field, val, op); + switch (_upb_getmode(field)) { + case _UPB_MODE_ARRAY: + ptr = decode_toarray(d, ptr, msg, layout->submsgs, field, &val, op); break; - case _UPB_LABEL_MAP: - ptr = decode_tomap(d, ptr, msg, layout, field, val); + case _UPB_MODE_MAP: + ptr = decode_tomap(d, ptr, msg, layout->submsgs, field, &val); break; - default: - ptr = decode_tomsg(d, ptr, msg, layout, field, val, op); + case _UPB_MODE_SCALAR: + ptr = decode_tomsg(d, ptr, msg, layout->submsgs, field, &val, op); break; + default: + UPB_UNREACHABLE(); } } else { unknown: @@ -924,7 +947,8 @@ static bool decode_top(struct upb_decstate *d, const char *buf, void *msg, } bool _upb_decode(const char *buf, size_t size, void *msg, - const upb_msglayout *l, upb_arena *arena, int options) { + const upb_msglayout *l, const upb_extreg *extreg, int options, + upb_arena *arena) { bool ok; upb_decstate state; unsigned depth = (unsigned)options >> 16; @@ -1126,7 +1150,7 @@ static void encode_fixedarray(upb_encstate *e, const upb_array *arr, } } -static void encode_message(upb_encstate *e, const char *msg, +static void encode_message(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, size_t *size); static void encode_scalar(upb_encstate *e, const void *_field_mem, @@ -1218,10 +1242,10 @@ static void encode_scalar(upb_encstate *e, const void *_field_mem, encode_tag(e, f->number, wire_type); } -static void encode_array(upb_encstate *e, const char *field_mem, +static void encode_array(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, const upb_msglayout_field *f) { - const upb_array *arr = *(const upb_array**)field_mem; - bool packed = f->label == _UPB_LABEL_PACKED; + const upb_array *arr = *UPB_PTR_AT(msg, f->offset, upb_array*); + bool packed = f->mode & _UPB_MODE_IS_PACKED; size_t pre_len = e->limit - e->ptr; if (arr == NULL || arr->len == 0) { @@ -1337,9 +1361,9 @@ static void encode_mapentry(upb_encstate *e, uint32_t number, encode_tag(e, number, UPB_WIRE_TYPE_DELIMITED); } -static void encode_map(upb_encstate *e, const char *field_mem, +static void encode_map(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, const upb_msglayout_field *f) { - const upb_map *map = *(const upb_map**)field_mem; + const upb_map *map = *UPB_PTR_AT(msg, f->offset, const upb_map*); const upb_msglayout *layout = m->submsgs[f->submsg_index]; UPB_ASSERT(layout->field_count == 2); @@ -1385,7 +1409,7 @@ static void encode_scalarfield(upb_encstate *e, const char *msg, encode_scalar(e, msg + f->offset, m, f, skip_empty); } -static void encode_message(upb_encstate *e, const char *msg, +static void encode_message(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, size_t *size) { size_t pre_len = e->limit - e->ptr; const upb_msglayout_field *f = &m->fields[m->field_count]; @@ -1402,12 +1426,18 @@ static void encode_message(upb_encstate *e, const char *msg, while (f != first) { f--; - if (_upb_isrepeated(f)) { - encode_array(e, msg + f->offset, m, f); - } else if (f->label == _UPB_LABEL_MAP) { - encode_map(e, msg + f->offset, m, f); - } else { - encode_scalarfield(e, msg, m, f); + switch (_upb_getmode(f)) { + case _UPB_MODE_ARRAY: + encode_array(e, msg, m, f); + break; + case _UPB_MODE_MAP: + encode_map(e, msg, m, f); + break; + case _UPB_MODE_SCALAR: + encode_scalarfield(e, msg, m, f); + break; + default: + UPB_UNREACHABLE(); } } @@ -1452,7 +1482,7 @@ char *upb_encode_ex(const void *msg, const upb_msglayout *l, int options, /** upb_msg *******************************************************************/ -static const size_t overhead = sizeof(upb_msg_internal); +static const size_t overhead = sizeof(upb_msg_internaldata); static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) { ptrdiff_t size = sizeof(upb_msg_internal); @@ -1468,49 +1498,107 @@ void _upb_msg_clear(upb_msg *msg, const upb_msglayout *l) { memset(mem, 0, upb_msg_sizeof(l)); } +static bool realloc_internal(upb_msg *msg, size_t need, upb_arena *arena) { + upb_msg_internal *in = upb_msg_getinternal(msg); + if (!in->internal) { + /* No internal data, allocate from scratch. */ + size_t size = UPB_MAX(128, _upb_lg2ceilsize(need + overhead)); + upb_msg_internaldata *internal = upb_arena_malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + /* Internal data is too small, reallocate. */ + size_t new_size = _upb_lg2ceilsize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_msg_internaldata *internal = + upb_arena_realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + /* Need to move extension data to the end. */ + char *ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; + } + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; +} + bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, upb_arena *arena) { - + if (!realloc_internal(msg, len, arena)) return false; upb_msg_internal *in = upb_msg_getinternal(msg); - if (!in->unknown) { - size_t size = 128; - while (size < len) size *= 2; - in->unknown = upb_arena_malloc(arena, size + overhead); - if (!in->unknown) return false; - in->unknown->size = size; - in->unknown->len = 0; - } else if (in->unknown->size - in->unknown->len < len) { - size_t need = in->unknown->len + len; - size_t size = in->unknown->size; - while (size < need) size *= 2; - in->unknown = upb_arena_realloc( - arena, in->unknown, in->unknown->size + overhead, size + overhead); - if (!in->unknown) return false; - in->unknown->size = size; - } - memcpy(UPB_PTR_AT(in->unknown + 1, in->unknown->len, char), data, len); - in->unknown->len += len; + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; return true; } void _upb_msg_discardunknown_shallow(upb_msg *msg) { upb_msg_internal *in = upb_msg_getinternal(msg); - if (in->unknown) { - in->unknown->len = 0; + if (in->internal) { + in->internal->unknown_end = overhead; } } const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { const upb_msg_internal *in = upb_msg_getinternal_const(msg); - if (in->unknown) { - *len = in->unknown->len; - return (char*)(in->unknown + 1); + if (in->internal) { + *len = in->internal->unknown_end - overhead; + return (char*)(in->internal + 1); } else { *len = 0; return NULL; } } +const upb_msg_ext *_upb_msg_getexts(const upb_msg *msg, size_t *count) { + const upb_msg_internal *in = upb_msg_getinternal_const(msg); + if (in->internal) { + *count = + (in->internal->size - in->internal->ext_begin) / sizeof(upb_msg_ext); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; + } +} + +const upb_msg_ext *_upb_msg_getext(const upb_msg *msg, + const upb_msglayout_ext *e) { + size_t n; + const upb_msg_ext *ext = _upb_msg_getexts(msg, &n); + + /* For now we use linear search exclusively to find extensions. If this + * becomes an issue due to messages with lots of extensions, we can introduce + * a table of some sort. */ + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } + + return NULL; +} + +upb_msg_ext *_upb_msg_getorcreateext(upb_msg *msg, const upb_msglayout_ext *e, + upb_arena *arena) { + upb_msg_ext *ext = (upb_msg_ext*)_upb_msg_getext(msg, e); + if (ext) return ext; + if (!realloc_internal(msg, sizeof(upb_msg_ext), arena)) return NULL; + upb_msg_internal *in = upb_msg_getinternal(msg); + in->internal->ext_begin -= sizeof(upb_msg_ext); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(upb_msg_ext)); + ext->ext = e; + return ext; +} + /** upb_array *****************************************************************/ bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) { @@ -1700,6 +1788,63 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, return true; } +/** upb_extreg ****************************************************************/ + +struct upb_extreg { + upb_arena *arena; + upb_strtable exts; /* Key is upb_msglayout* concatenated with fieldnum. */ +}; + +#define EXTREG_KEY_SIZE (sizeof(upb_msglayout*) + sizeof(uint32_t)) + +static void extreg_key(char *buf, const upb_msglayout *l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); +} + +upb_extreg *upb_extreg_new(upb_arena *arena) { + upb_extreg *r = upb_arena_malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; +} + +bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext *e, size_t count) { + char buf[EXTREG_KEY_SIZE]; + const upb_msglayout_ext *start = e; + const upb_msglayout_ext *end = e + count; + for (; e < end; e++) { + extreg_key(buf, e->extendee, e->field.number); + if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(e), r->arena)) { + goto failure; + } + } + return true; + +failure: + /* Back out the entries previously added. */ + for (end = e, e = start; e < end; e++) { + extreg_key(buf, e->extendee, e->field.number); + upb_strtable_remove(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + } + return false; +} + +const upb_msglayout_field *_upb_extreg_get(const upb_extreg *r, + const upb_msglayout *l, + uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, l, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); + } else { + return NULL; + } +} + /** upb/table.c ************************************************************/ /* * upb_table Implementation @@ -1709,7 +1854,6 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, #include -#include "third_party/wyhash/wyhash.h" /* Must be last. */ @@ -1982,8 +2126,143 @@ static upb_tabkey strcopy(lookupkey_t k2, upb_arena *a) { return (uintptr_t)str; } +/* Adapted from ABSL's wyhash. */ + +static uint64_t UnalignedLoad64(const void *p) { + uint64_t val; + memcpy(&val, p, 8); + return val; +} + +static uint32_t UnalignedLoad32(const void *p) { + uint32_t val; + memcpy(&val, p, 4); + return val; +} + +#if defined(_MSC_VER) && defined(_M_X64) +#include +#endif + +/* Computes a * b, returning the low 64 bits of the result and storing the high + * 64 bits in |*high|. */ +static uint64_t upb_umul128(uint64_t v0, uint64_t v1, uint64_t* out_high) { +#ifdef __SIZEOF_INT128__ + __uint128_t p = v0; + p *= v1; + *out_high = (uint64_t)(p >> 64); + return (uint64_t)p; +#elif defined(_MSC_VER) && defined(_M_X64) + return _umul128(v0, v1, out_high); +#else + uint64_t a32 = v0 >> 32; + uint64_t a00 = v0 & 0xffffffff; + uint64_t b32 = v1 >> 32; + uint64_t b00 = v1 & 0xffffffff; + uint64_t high = a32 * b32; + uint64_t low = a00 * b00; + uint64_t mid1 = a32 * b00; + uint64_t mid2 = a00 * b32; + low += (mid1 << 32) + (mid2 << 32); + // Omit carry bit, for mixing we do not care about exact numerical precision. + high += (mid1 >> 32) + (mid2 >> 32); + *out_high = high; + return low; +#endif +} + +static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { + uint64_t high; + uint64_t low = upb_umul128(v0, v1, &high); + return low ^ high; +} + +static uint64_t Wyhash(const void *data, size_t len, uint64_t seed, + const uint64_t salt[]) { + const uint8_t* ptr = (const uint8_t*)data; + uint64_t starting_length = (uint64_t)len; + uint64_t current_state = seed ^ salt[0]; + + if (len > 64) { + // If we have more than 64 bytes, we're going to handle chunks of 64 + // bytes at a time. We're going to build up two separate hash states + // which we will then hash together. + uint64_t duplicated_state = current_state; + + do { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); + uint64_t c = UnalignedLoad64(ptr + 16); + uint64_t d = UnalignedLoad64(ptr + 24); + uint64_t e = UnalignedLoad64(ptr + 32); + uint64_t f = UnalignedLoad64(ptr + 40); + uint64_t g = UnalignedLoad64(ptr + 48); + uint64_t h = UnalignedLoad64(ptr + 56); + + uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state); + current_state = (cs0 ^ cs1); + + uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state); + uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state); + duplicated_state = (ds0 ^ ds1); + + ptr += 64; + len -= 64; + } while (len > 64); + + current_state = current_state ^ duplicated_state; + } + + // We now have a data `ptr` with at most 64 bytes and the current state + // of the hashing state machine stored in current_state. + while (len > 16) { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); + + current_state = WyhashMix(a ^ salt[1], b ^ current_state); + + ptr += 16; + len -= 16; + } + + // We now have a data `ptr` with at most 16 bytes. + uint64_t a = 0; + uint64_t b = 0; + if (len > 8) { + // When we have at least 9 and at most 16 bytes, set A to the first 64 + // bits of the input and B to the last 64 bits of the input. Yes, they will + // overlap in the middle if we are working with less than the full 16 + // bytes. + a = UnalignedLoad64(ptr); + b = UnalignedLoad64(ptr + len - 8); + } else if (len > 3) { + // If we have at least 4 and at most 8 bytes, set A to the first 32 + // bits and B to the last 32 bits. + a = UnalignedLoad32(ptr); + b = UnalignedLoad32(ptr + len - 4); + } else if (len > 0) { + // If we have at least 1 and at most 3 bytes, read all of the provided + // bits into A, with some adjustments. + a = ((ptr[0] << 16) | (ptr[len >> 1] << 8) | ptr[len - 1]); + b = 0; + } else { + a = 0; + b = 0; + } + + uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t z = salt[1] ^ starting_length; + return WyhashMix(w, z); +} + +const uint64_t kWyhashSalt[5] = { + 0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL, 0xA4093822299F31D0ULL, + 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, +}; + static uint32_t table_hash(const char *p, size_t n) { - return wyhash(p, n, 0, _wyp); + return Wyhash(p, n, 0, kWyhashSalt); } static uint32_t strhash(upb_tabkey key) { @@ -3710,13 +3989,13 @@ static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = }; static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_FileDescriptorSet_msginit = { &google_protobuf_FileDescriptorSet_submsgs[0], &google_protobuf_FileDescriptorSet__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 1, 255, }; static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = { @@ -3729,24 +4008,24 @@ static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] }; static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(12, 24), 2, 0, 12, 1}, - {3, UPB_SIZE(36, 72), 0, 0, 12, 3}, - {4, UPB_SIZE(40, 80), 0, 0, 11, 3}, - {5, UPB_SIZE(44, 88), 0, 1, 11, 3}, - {6, UPB_SIZE(48, 96), 0, 4, 11, 3}, - {7, UPB_SIZE(52, 104), 0, 2, 11, 3}, - {8, UPB_SIZE(28, 56), 3, 3, 11, 1}, - {9, UPB_SIZE(32, 64), 4, 5, 11, 1}, - {10, UPB_SIZE(56, 112), 0, 0, 5, 3}, - {11, UPB_SIZE(60, 120), 0, 0, 5, 3}, - {12, UPB_SIZE(20, 40), 5, 0, 12, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(36, 72), 0, 0, 12, _UPB_MODE_ARRAY}, + {4, UPB_SIZE(40, 80), 0, 0, 11, _UPB_MODE_ARRAY}, + {5, UPB_SIZE(44, 88), 0, 1, 11, _UPB_MODE_ARRAY}, + {6, UPB_SIZE(48, 96), 0, 4, 11, _UPB_MODE_ARRAY}, + {7, UPB_SIZE(52, 104), 0, 2, 11, _UPB_MODE_ARRAY}, + {8, UPB_SIZE(28, 56), 3, 3, 11, _UPB_MODE_SCALAR}, + {9, UPB_SIZE(32, 64), 4, 5, 11, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(56, 112), 0, 0, 5, _UPB_MODE_ARRAY}, + {11, UPB_SIZE(60, 120), 0, 0, 5, _UPB_MODE_ARRAY}, + {12, UPB_SIZE(20, 40), 5, 0, 12, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_FileDescriptorProto_msginit = { &google_protobuf_FileDescriptorProto_submsgs[0], &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(64, 128), 12, false, 255, + UPB_SIZE(64, 128), 12, false, 12, 255, }; static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[7] = { @@ -3760,22 +4039,22 @@ static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[7] = { }; static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(16, 32), 0, 4, 11, 3}, - {3, UPB_SIZE(20, 40), 0, 0, 11, 3}, - {4, UPB_SIZE(24, 48), 0, 3, 11, 3}, - {5, UPB_SIZE(28, 56), 0, 1, 11, 3}, - {6, UPB_SIZE(32, 64), 0, 4, 11, 3}, - {7, UPB_SIZE(12, 24), 2, 5, 11, 1}, - {8, UPB_SIZE(36, 72), 0, 6, 11, 3}, - {9, UPB_SIZE(40, 80), 0, 2, 11, 3}, - {10, UPB_SIZE(44, 88), 0, 0, 12, 3}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(16, 32), 0, 4, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(20, 40), 0, 0, 11, _UPB_MODE_ARRAY}, + {4, UPB_SIZE(24, 48), 0, 3, 11, _UPB_MODE_ARRAY}, + {5, UPB_SIZE(28, 56), 0, 1, 11, _UPB_MODE_ARRAY}, + {6, UPB_SIZE(32, 64), 0, 4, 11, _UPB_MODE_ARRAY}, + {7, UPB_SIZE(12, 24), 2, 5, 11, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(36, 72), 0, 6, 11, _UPB_MODE_ARRAY}, + {9, UPB_SIZE(40, 80), 0, 2, 11, _UPB_MODE_ARRAY}, + {10, UPB_SIZE(44, 88), 0, 0, 12, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_DescriptorProto_msginit = { &google_protobuf_DescriptorProto_submsgs[0], &google_protobuf_DescriptorProto__fields[0], - UPB_SIZE(48, 96), 10, false, 255, + UPB_SIZE(48, 96), 10, false, 10, 255, }; static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { @@ -3783,26 +4062,26 @@ static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange }; static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, - {3, UPB_SIZE(12, 16), 3, 0, 11, 1}, + {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(12, 16), 3, 0, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = { &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], &google_protobuf_DescriptorProto_ExtensionRange__fields[0], - UPB_SIZE(16, 24), 3, false, 255, + UPB_SIZE(16, 24), 3, false, 3, 255, }; static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, + {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = { NULL, &google_protobuf_DescriptorProto_ReservedRange__fields[0], - UPB_SIZE(16, 16), 2, false, 255, + UPB_SIZE(16, 16), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = { @@ -3810,13 +4089,13 @@ static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[ }; static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {999, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = { &google_protobuf_ExtensionRangeOptions_submsgs[0], &google_protobuf_ExtensionRangeOptions__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 0, 255, }; static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1] = { @@ -3824,23 +4103,23 @@ static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1 }; static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = { - {1, UPB_SIZE(24, 24), 1, 0, 12, 1}, - {2, UPB_SIZE(32, 40), 2, 0, 12, 1}, - {3, UPB_SIZE(12, 12), 3, 0, 5, 1}, - {4, UPB_SIZE(4, 4), 4, 0, 14, 1}, - {5, UPB_SIZE(8, 8), 5, 0, 14, 1}, - {6, UPB_SIZE(40, 56), 6, 0, 12, 1}, - {7, UPB_SIZE(48, 72), 7, 0, 12, 1}, - {8, UPB_SIZE(64, 104), 8, 0, 11, 1}, - {9, UPB_SIZE(16, 16), 9, 0, 5, 1}, - {10, UPB_SIZE(56, 88), 10, 0, 12, 1}, - {17, UPB_SIZE(20, 20), 11, 0, 8, 1}, + {1, UPB_SIZE(24, 24), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(32, 40), 2, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(12, 12), 3, 0, 5, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(4, 4), 4, 0, 14, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(8, 8), 5, 0, 14, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(40, 56), 6, 0, 12, _UPB_MODE_SCALAR}, + {7, UPB_SIZE(48, 72), 7, 0, 12, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(64, 104), 8, 0, 11, _UPB_MODE_SCALAR}, + {9, UPB_SIZE(16, 16), 9, 0, 5, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(56, 88), 10, 0, 12, _UPB_MODE_SCALAR}, + {17, UPB_SIZE(20, 20), 11, 0, 8, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = { &google_protobuf_FieldDescriptorProto_submsgs[0], &google_protobuf_FieldDescriptorProto__fields[0], - UPB_SIZE(72, 112), 11, false, 255, + UPB_SIZE(72, 112), 11, false, 10, 255, }; static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = { @@ -3848,14 +4127,14 @@ static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1 }; static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(12, 24), 2, 0, 11, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 24), 2, 0, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = { &google_protobuf_OneofDescriptorProto_submsgs[0], &google_protobuf_OneofDescriptorProto__fields[0], - UPB_SIZE(16, 32), 2, false, 255, + UPB_SIZE(16, 32), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = { @@ -3865,28 +4144,28 @@ static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] }; static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(16, 32), 0, 2, 11, 3}, - {3, UPB_SIZE(12, 24), 2, 1, 11, 1}, - {4, UPB_SIZE(20, 40), 0, 0, 11, 3}, - {5, UPB_SIZE(24, 48), 0, 0, 12, 3}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(16, 32), 0, 2, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(12, 24), 2, 1, 11, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(20, 40), 0, 0, 11, _UPB_MODE_ARRAY}, + {5, UPB_SIZE(24, 48), 0, 0, 12, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = { &google_protobuf_EnumDescriptorProto_submsgs[0], &google_protobuf_EnumDescriptorProto__fields[0], - UPB_SIZE(32, 64), 5, false, 255, + UPB_SIZE(32, 64), 5, false, 5, 255, }; static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, + {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { NULL, &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], - UPB_SIZE(16, 16), 2, false, 255, + UPB_SIZE(16, 16), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { @@ -3894,15 +4173,15 @@ static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_subms }; static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = { - {1, UPB_SIZE(8, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(4, 4), 2, 0, 5, 1}, - {3, UPB_SIZE(16, 24), 3, 0, 11, 1}, + {1, UPB_SIZE(8, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(4, 4), 2, 0, 5, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(16, 24), 3, 0, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = { &google_protobuf_EnumValueDescriptorProto_submsgs[0], &google_protobuf_EnumValueDescriptorProto__fields[0], - UPB_SIZE(24, 32), 3, false, 255, + UPB_SIZE(24, 32), 3, false, 3, 255, }; static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { @@ -3911,15 +4190,15 @@ static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs }; static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(16, 32), 0, 0, 11, 3}, - {3, UPB_SIZE(12, 24), 2, 1, 11, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(16, 32), 0, 0, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(12, 24), 2, 1, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = { &google_protobuf_ServiceDescriptorProto_submsgs[0], &google_protobuf_ServiceDescriptorProto__fields[0], - UPB_SIZE(24, 48), 3, false, 255, + UPB_SIZE(24, 48), 3, false, 3, 255, }; static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = { @@ -3927,18 +4206,18 @@ static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[ }; static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(12, 24), 2, 0, 12, 1}, - {3, UPB_SIZE(20, 40), 3, 0, 12, 1}, - {4, UPB_SIZE(28, 56), 4, 0, 11, 1}, - {5, UPB_SIZE(1, 1), 5, 0, 8, 1}, - {6, UPB_SIZE(2, 2), 6, 0, 8, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(20, 40), 3, 0, 12, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(28, 56), 4, 0, 11, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(1, 1), 5, 0, 8, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(2, 2), 6, 0, 8, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = { &google_protobuf_MethodDescriptorProto_submsgs[0], &google_protobuf_MethodDescriptorProto__fields[0], - UPB_SIZE(32, 64), 6, false, 255, + UPB_SIZE(32, 64), 6, false, 6, 255, }; static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { @@ -3946,33 +4225,33 @@ static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = { - {1, UPB_SIZE(20, 24), 1, 0, 12, 1}, - {8, UPB_SIZE(28, 40), 2, 0, 12, 1}, - {9, UPB_SIZE(4, 4), 3, 0, 14, 1}, - {10, UPB_SIZE(8, 8), 4, 0, 8, 1}, - {11, UPB_SIZE(36, 56), 5, 0, 12, 1}, - {16, UPB_SIZE(9, 9), 6, 0, 8, 1}, - {17, UPB_SIZE(10, 10), 7, 0, 8, 1}, - {18, UPB_SIZE(11, 11), 8, 0, 8, 1}, - {20, UPB_SIZE(12, 12), 9, 0, 8, 1}, - {23, UPB_SIZE(13, 13), 10, 0, 8, 1}, - {27, UPB_SIZE(14, 14), 11, 0, 8, 1}, - {31, UPB_SIZE(15, 15), 12, 0, 8, 1}, - {36, UPB_SIZE(44, 72), 13, 0, 12, 1}, - {37, UPB_SIZE(52, 88), 14, 0, 12, 1}, - {39, UPB_SIZE(60, 104), 15, 0, 12, 1}, - {40, UPB_SIZE(68, 120), 16, 0, 12, 1}, - {41, UPB_SIZE(76, 136), 17, 0, 12, 1}, - {42, UPB_SIZE(16, 16), 18, 0, 8, 1}, - {44, UPB_SIZE(84, 152), 19, 0, 12, 1}, - {45, UPB_SIZE(92, 168), 20, 0, 12, 1}, - {999, UPB_SIZE(100, 184), 0, 0, 11, 3}, + {1, UPB_SIZE(20, 24), 1, 0, 12, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(28, 40), 2, 0, 12, _UPB_MODE_SCALAR}, + {9, UPB_SIZE(4, 4), 3, 0, 14, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(8, 8), 4, 0, 8, _UPB_MODE_SCALAR}, + {11, UPB_SIZE(36, 56), 5, 0, 12, _UPB_MODE_SCALAR}, + {16, UPB_SIZE(9, 9), 6, 0, 8, _UPB_MODE_SCALAR}, + {17, UPB_SIZE(10, 10), 7, 0, 8, _UPB_MODE_SCALAR}, + {18, UPB_SIZE(11, 11), 8, 0, 8, _UPB_MODE_SCALAR}, + {20, UPB_SIZE(12, 12), 9, 0, 8, _UPB_MODE_SCALAR}, + {23, UPB_SIZE(13, 13), 10, 0, 8, _UPB_MODE_SCALAR}, + {27, UPB_SIZE(14, 14), 11, 0, 8, _UPB_MODE_SCALAR}, + {31, UPB_SIZE(15, 15), 12, 0, 8, _UPB_MODE_SCALAR}, + {36, UPB_SIZE(44, 72), 13, 0, 12, _UPB_MODE_SCALAR}, + {37, UPB_SIZE(52, 88), 14, 0, 12, _UPB_MODE_SCALAR}, + {39, UPB_SIZE(60, 104), 15, 0, 12, _UPB_MODE_SCALAR}, + {40, UPB_SIZE(68, 120), 16, 0, 12, _UPB_MODE_SCALAR}, + {41, UPB_SIZE(76, 136), 17, 0, 12, _UPB_MODE_SCALAR}, + {42, UPB_SIZE(16, 16), 18, 0, 8, _UPB_MODE_SCALAR}, + {44, UPB_SIZE(84, 152), 19, 0, 12, _UPB_MODE_SCALAR}, + {45, UPB_SIZE(92, 168), 20, 0, 12, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(100, 184), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_FileOptions_msginit = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], - UPB_SIZE(104, 192), 21, false, 255, + UPB_SIZE(104, 192), 21, false, 1, 255, }; static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { @@ -3980,17 +4259,17 @@ static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {2, UPB_SIZE(2, 2), 2, 0, 8, 1}, - {3, UPB_SIZE(3, 3), 3, 0, 8, 1}, - {7, UPB_SIZE(4, 4), 4, 0, 8, 1}, - {999, UPB_SIZE(8, 8), 0, 0, 11, 3}, + {1, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(2, 2), 2, 0, 8, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(3, 3), 3, 0, 8, _UPB_MODE_SCALAR}, + {7, UPB_SIZE(4, 4), 4, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(8, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_MessageOptions_msginit = { &google_protobuf_MessageOptions_submsgs[0], &google_protobuf_MessageOptions__fields[0], - UPB_SIZE(16, 16), 5, false, 255, + UPB_SIZE(16, 16), 5, false, 3, 255, }; static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { @@ -3998,19 +4277,19 @@ static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = { - {1, UPB_SIZE(4, 4), 1, 0, 14, 1}, - {2, UPB_SIZE(12, 12), 2, 0, 8, 1}, - {3, UPB_SIZE(13, 13), 3, 0, 8, 1}, - {5, UPB_SIZE(14, 14), 4, 0, 8, 1}, - {6, UPB_SIZE(8, 8), 5, 0, 14, 1}, - {10, UPB_SIZE(15, 15), 6, 0, 8, 1}, - {999, UPB_SIZE(16, 16), 0, 0, 11, 3}, + {1, UPB_SIZE(4, 4), 1, 0, 14, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 12), 2, 0, 8, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(13, 13), 3, 0, 8, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(14, 14), 4, 0, 8, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(8, 8), 5, 0, 14, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(15, 15), 6, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(16, 16), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_FieldOptions_msginit = { &google_protobuf_FieldOptions_submsgs[0], &google_protobuf_FieldOptions__fields[0], - UPB_SIZE(24, 24), 7, false, 255, + UPB_SIZE(24, 24), 7, false, 3, 255, }; static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { @@ -4018,13 +4297,13 @@ static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {999, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_OneofOptions_msginit = { &google_protobuf_OneofOptions_submsgs[0], &google_protobuf_OneofOptions__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 0, 255, }; static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { @@ -4032,15 +4311,15 @@ static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = { - {2, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {3, UPB_SIZE(2, 2), 2, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, + {2, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(2, 2), 2, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_EnumOptions_msginit = { &google_protobuf_EnumOptions_submsgs[0], &google_protobuf_EnumOptions__fields[0], - UPB_SIZE(8, 16), 3, false, 255, + UPB_SIZE(8, 16), 3, false, 0, 255, }; static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = { @@ -4048,14 +4327,14 @@ static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = }; static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, + {1, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_EnumValueOptions_msginit = { &google_protobuf_EnumValueOptions_submsgs[0], &google_protobuf_EnumValueOptions__fields[0], - UPB_SIZE(8, 16), 2, false, 255, + UPB_SIZE(8, 16), 2, false, 1, 255, }; static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { @@ -4063,14 +4342,14 @@ static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = { - {33, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, + {33, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_ServiceOptions_msginit = { &google_protobuf_ServiceOptions_submsgs[0], &google_protobuf_ServiceOptions__fields[0], - UPB_SIZE(8, 16), 2, false, 255, + UPB_SIZE(8, 16), 2, false, 0, 255, }; static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { @@ -4078,15 +4357,15 @@ static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = { - {33, UPB_SIZE(8, 8), 1, 0, 8, 1}, - {34, UPB_SIZE(4, 4), 2, 0, 14, 1}, - {999, UPB_SIZE(12, 16), 0, 0, 11, 3}, + {33, UPB_SIZE(8, 8), 1, 0, 8, _UPB_MODE_SCALAR}, + {34, UPB_SIZE(4, 4), 2, 0, 14, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(12, 16), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_MethodOptions_msginit = { &google_protobuf_MethodOptions_submsgs[0], &google_protobuf_MethodOptions__fields[0], - UPB_SIZE(16, 24), 3, false, 255, + UPB_SIZE(16, 24), 3, false, 0, 255, }; static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = { @@ -4094,30 +4373,30 @@ static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] }; static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = { - {2, UPB_SIZE(56, 80), 0, 0, 11, 3}, - {3, UPB_SIZE(32, 32), 1, 0, 12, 1}, - {4, UPB_SIZE(8, 8), 2, 0, 4, 1}, - {5, UPB_SIZE(16, 16), 3, 0, 3, 1}, - {6, UPB_SIZE(24, 24), 4, 0, 1, 1}, - {7, UPB_SIZE(40, 48), 5, 0, 12, 1}, - {8, UPB_SIZE(48, 64), 6, 0, 12, 1}, + {2, UPB_SIZE(56, 80), 0, 0, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(32, 32), 1, 0, 12, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(8, 8), 2, 0, 4, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(16, 16), 3, 0, 3, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(24, 24), 4, 0, 1, _UPB_MODE_SCALAR}, + {7, UPB_SIZE(40, 48), 5, 0, 12, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(48, 64), 6, 0, 12, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_UninterpretedOption_msginit = { &google_protobuf_UninterpretedOption_submsgs[0], &google_protobuf_UninterpretedOption__fields[0], - UPB_SIZE(64, 96), 7, false, 255, + UPB_SIZE(64, 96), 7, false, 0, 255, }; static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 2}, - {2, UPB_SIZE(1, 1), 2, 0, 8, 2}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(1, 1), 2, 0, 8, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = { NULL, &google_protobuf_UninterpretedOption_NamePart__fields[0], - UPB_SIZE(16, 32), 2, false, 255, + UPB_SIZE(16, 32), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { @@ -4125,27 +4404,27 @@ static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_SourceCodeInfo_msginit = { &google_protobuf_SourceCodeInfo_submsgs[0], &google_protobuf_SourceCodeInfo__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 1, 255, }; static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_LABEL_PACKED}, - {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_LABEL_PACKED}, - {3, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {4, UPB_SIZE(12, 24), 2, 0, 12, 1}, - {6, UPB_SIZE(28, 56), 0, 0, 12, 3}, + {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, + {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, + {3, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(28, 56), 0, 0, 12, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = { NULL, &google_protobuf_SourceCodeInfo_Location__fields[0], - UPB_SIZE(32, 64), 5, false, 255, + UPB_SIZE(32, 64), 5, false, 4, 255, }; static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = { @@ -4153,26 +4432,26 @@ static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = }; static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = { &google_protobuf_GeneratedCodeInfo_submsgs[0], &google_protobuf_GeneratedCodeInfo__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 1, 255, }; static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { - {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED}, - {2, UPB_SIZE(12, 16), 1, 0, 12, 1}, - {3, UPB_SIZE(4, 4), 2, 0, 5, 1}, - {4, UPB_SIZE(8, 8), 3, 0, 5, 1}, + {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, + {2, UPB_SIZE(12, 16), 1, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(4, 4), 2, 0, 5, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(8, 8), 3, 0, 5, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = { NULL, &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], - UPB_SIZE(24, 48), 4, false, 255, + UPB_SIZE(24, 48), 4, false, 4, 255, }; @@ -5552,13 +5831,44 @@ static int field_number_cmp(const void *p1, const void *p2) { return f1->number - f2->number; } -static void assign_layout_indices(const upb_msgdef *m, upb_msglayout_field *fields) { +static void assign_layout_indices(const upb_msgdef *m, upb_msglayout *l, + upb_msglayout_field *fields) { int i; int n = upb_msgdef_numfields(m); + int dense_below = 0; for (i = 0; i < n; i++) { upb_fielddef *f = (upb_fielddef*)upb_msgdef_itof(m, fields[i].number); UPB_ASSERT(f); f->layout_index = i; + if (i < UINT8_MAX && fields[i].number == i + 1 && + (i == 0 || fields[i-1].number == i)) { + dense_below = i + 1; + } + } + l->dense_below = dense_below; +} + +static void fill_fieldlayout(upb_msglayout_field *field, const upb_fielddef *f) { + field->number = upb_fielddef_number(f); + field->descriptortype = upb_fielddef_descriptortype(f); + + if (field->descriptortype == UPB_DTYPE_STRING && + f->file->syntax == UPB_SYNTAX_PROTO2) { + /* See TableDescriptorType() in upbc/generator.cc for details and + * rationale. */ + field->descriptortype = UPB_DTYPE_BYTES; + } + + if (upb_fielddef_ismap(f)) { + field->mode = _UPB_MODE_MAP; + } else if (upb_fielddef_isseq(f)) { + field->mode = _UPB_MODE_ARRAY; + } else { + field->mode = _UPB_MODE_SCALAR; + } + + if (upb_fielddef_packed(f)) { + field->mode |= _UPB_MODE_IS_PACKED; } } @@ -5603,8 +5913,8 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { const upb_fielddef *val = upb_msgdef_itof(m, 2); fields[0].number = 1; fields[1].number = 2; - fields[0].label = UPB_LABEL_OPTIONAL; - fields[1].label = UPB_LABEL_OPTIONAL; + fields[0].mode = _UPB_MODE_SCALAR; + fields[1].mode = _UPB_MODE_SCALAR; fields[0].presence = 0; fields[1].presence = 0; fields[0].descriptortype = upb_fielddef_descriptortype(key); @@ -5640,22 +5950,7 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { upb_fielddef* f = upb_msg_iter_field(&it); upb_msglayout_field *field = &fields[upb_fielddef_index(f)]; - field->number = upb_fielddef_number(f); - field->descriptortype = upb_fielddef_descriptortype(f); - field->label = upb_fielddef_label(f); - - if (field->descriptortype == UPB_DTYPE_STRING && - f->file->syntax == UPB_SYNTAX_PROTO2) { - /* See TableDescriptorType() in upbc/generator.cc for details and - * rationale. */ - field->descriptortype = UPB_DTYPE_BYTES; - } - - if (upb_fielddef_ismap(f)) { - field->label = _UPB_LABEL_MAP; - } else if (upb_fielddef_packed(f)) { - field->label = _UPB_LABEL_PACKED; - } + fill_fieldlayout(field, f); if (upb_fielddef_issubmsg(f)) { const upb_msgdef *subm = upb_fielddef_msgsubdef(f); @@ -5731,7 +6026,7 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { /* Sort fields by number. */ qsort(fields, upb_msgdef_numfields(m), sizeof(*fields), field_number_cmp); - assign_layout_indices(m, fields); + assign_layout_indices(m, l, fields); } static char *strviewdup(symtab_addctx *ctx, upb_strview view) { @@ -6441,13 +6736,18 @@ static void build_filedef( const upb_strview* strs; size_t i, n; - count_types_in_file(file_proto, file); + file->symtab = ctx->symtab; + /* One pass to count and allocate. */ + file->msg_count = 0; + file->enum_count = 0; + file->ext_count = 0; + count_types_in_file(file_proto, file); file->msgs = symtab_alloc(ctx, sizeof(*file->msgs) * file->msg_count); file->enums = symtab_alloc(ctx, sizeof(*file->enums) * file->enum_count); file->exts = symtab_alloc(ctx, sizeof(*file->exts) * file->ext_count); - /* We increment these as defs are added. */ + /* In the second pass we increment these as defs are added. */ file->msg_count = 0; file->enum_count = 0; file->ext_count = 0; @@ -6576,41 +6876,43 @@ static void remove_filedef(upb_symtab *s, upb_filedef *file) { static const upb_filedef *_upb_symtab_addfile( upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, const upb_msglayout **layouts, upb_status *status) { - upb_arena *file_arena = upb_arena_new(); - upb_filedef *file; symtab_addctx ctx; + upb_strview name = google_protobuf_FileDescriptorProto_name(file_proto); - if (!file_arena) return NULL; - - file = upb_arena_malloc(file_arena, sizeof(*file)); - if (!file) goto done; + if (upb_strtable_lookup2(&s->files, name.data, name.size, NULL)) { + upb_status_seterrf(status, "duplicate file name (%.*s)", + UPB_STRVIEW_ARGS(name)); + return NULL; + } - ctx.file = file; ctx.symtab = s; - ctx.arena = file_arena; ctx.layouts = layouts; ctx.status = status; + ctx.file = NULL; + ctx.arena = upb_arena_new(); - file->msg_count = 0; - file->enum_count = 0; - file->ext_count = 0; - file->symtab = s; + if (!ctx.arena) { + upb_status_setoom(status); + return NULL; + } if (UPB_UNLIKELY(UPB_SETJMP(ctx.err))) { UPB_ASSERT(!upb_ok(status)); - remove_filedef(s, file); - file = NULL; + if (ctx.file) { + remove_filedef(s, ctx.file); + ctx.file = NULL; + } } else { - build_filedef(&ctx, file, file_proto); - upb_strtable_insert(&s->files, file->name, strlen(file->name), - upb_value_constptr(file), ctx.arena); + ctx.file = symtab_alloc(&ctx, sizeof(*ctx.file)); + build_filedef(&ctx, ctx.file, file_proto); + upb_strtable_insert(&s->files, name.data, name.size, + upb_value_constptr(ctx.file), ctx.arena); UPB_ASSERT(upb_ok(status)); - upb_arena_fuse(s->arena, file_arena); + upb_arena_fuse(s->arena, ctx.arena); } -done: - upb_arena_free(file_arena); - return file; + upb_arena_free(ctx.arena); + return ctx.file; } const upb_filedef *upb_symtab_addfile( @@ -6643,7 +6945,8 @@ bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) { } file = google_protobuf_FileDescriptorProto_parse_ex( - init->descriptor.data, init->descriptor.size, arena, UPB_DECODE_ALIAS); + init->descriptor.data, init->descriptor.size, NULL, UPB_DECODE_ALIAS, + arena); s->bytes_loaded += init->descriptor.size; if (!file) { @@ -8773,7 +9076,17 @@ static void jsonenc_double(jsonenc *e, const char *fmt, double val) { } else if (val != val) { jsonenc_putstr(e, "\"NaN\""); } else { + char *p = e->ptr; jsonenc_printf(e, fmt, val); + + /* printf() is dependent on locales; sadly there is no easy and portable way + * to avoid this. This little post-processing step will translate 1,2 -> 1.2 + * since JSON needs the latter. Arguably a hack, but it is simple and the + * alternatives are far more complicated, platform-dependent, and/or larger + * in code size. */ + for (char *end = e->ptr; p < end; p++) { + if (*p == ',') *p = '.'; + } } } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 77a87c769130..8883668b790c 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -168,7 +168,7 @@ /* Configure whether fasttable is switched on or not. *************************/ -#if defined(__has_attribute) +#ifdef __has_attribute #define UPB_HAS_ATTRIBUTE(x) __has_attribute(x) #else #define UPB_HAS_ATTRIBUTE(x) 0 @@ -636,6 +636,48 @@ void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, /* Returns a reference to the message's unknown data. */ const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); +/** upb_extreg *******************************************************************/ + +/* Extension registry: a dynamic data structure that stores a map of: + * (upb_msglayout, number) -> extension info + * + * upb_decode() uses upb_extreg to look up extensions while parsing binary + * format. + * + * upb_extreg is part of the mini-table (msglayout) family of objects. Like all + * mini-table objects, it is suitable for reflection-less builds that do not + * want to expose names into the binary. + * + * Unlike most mini-table types, upb_extreg requires dynamic memory allocation + * and dynamic initialization: + * * If reflection is being used, then upb_symtab will construct an appropriate + * upb_extreg automatically. + * * For a mini-table only build, the user must manually construct the + * upb_extreg and populate it with all of the extensions the user cares about. + * * A third alternative is to manually unpack relevant extensions after the + * main parse is complete, similar to how Any works. This is perhaps the + * nicest solution from the perspective of reducing dependencies, avoiding + * dynamic memory allocation, and avoiding the need to parse uninteresting + * extensions. The downsides are: + * (1) parse errors are not caught during the main parse + * (2) the CPU hit of parsing comes during access, which could cause an + * undesirable stutter in application performance. + * + * Users cannot directly get or put into this map. Users can only add the + * extensions from a generated module and pass the extension registry to the + * binary decoder. + * + * A upb_symtab provides a upb_extreg, so any users who use reflection do not + * need to populate a upb_extreg directly. + */ + +struct upb_extreg; +typedef struct upb_extreg upb_extreg; + +/* Creates a upb_extreg in the given arena. The arena must outlive any use of + * the extreg. */ +upb_extreg *upb_extreg_new(upb_arena *arena); + #ifdef __cplusplus } /* extern "C" */ #endif @@ -657,12 +699,13 @@ enum { #define UPB_DECODE_MAXDEPTH(depth) ((depth) << 16) bool _upb_decode(const char *buf, size_t size, upb_msg *msg, - const upb_msglayout *l, upb_arena *arena, int options); + const upb_msglayout *l, const upb_extreg *extreg, int options, + upb_arena *arena); UPB_INLINE bool upb_decode(const char *buf, size_t size, upb_msg *msg, const upb_msglayout *l, upb_arena *arena) { - return _upb_decode(buf, size, msg, l, arena, 0); + return _upb_decode(buf, size, msg, l, NULL, 0, arena); } #ifdef __cplusplus @@ -1047,9 +1090,34 @@ typedef struct { int16_t presence; /* If >0, hasbit_index. If <0, ~oneof_index. */ uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */ uint8_t descriptortype; - uint8_t label; /* google.protobuf.Label or _UPB_LABEL_* above. */ + int8_t mode; /* upb_fieldmode, with flags from upb_labelflags */ } upb_msglayout_field; +typedef enum { + _UPB_MODE_MAP = 0, + _UPB_MODE_ARRAY = 1, + _UPB_MODE_SCALAR = 2, +} upb_fieldmode; + +/* Extra flags on the mode field. */ +enum upb_labelflags { + _UPB_MODE_IS_PACKED = 4, +}; + +UPB_INLINE upb_fieldmode _upb_getmode(const upb_msglayout_field *field) { + return (upb_fieldmode)(field->mode & 3); +} + +UPB_INLINE bool _upb_repeated_or_map(const upb_msglayout_field *field) { + /* This works because upb_fieldmode has no value 3. */ + return !(field->mode & _UPB_MODE_SCALAR); +} + +UPB_INLINE bool _upb_issubmsg(const upb_msglayout_field *field) { + return field->descriptortype == UPB_DTYPE_MESSAGE || + field->descriptortype == UPB_DTYPE_GROUP; +} + struct upb_decstate; struct upb_msglayout; @@ -1070,27 +1138,65 @@ struct upb_msglayout { uint16_t size; uint16_t field_count; bool extendable; + uint8_t dense_below; uint8_t table_mask; /* To constant-initialize the tables of variable length, we need a flexible * array member, and we need to compile in C99 mode. */ _upb_fasttable_entry fasttable[]; }; +typedef struct { + upb_msglayout_field field; + const upb_msglayout *extendee; + const upb_msglayout *submsg; /* NULL for non-submessage fields. */ +} upb_msglayout_ext; + +/** upb_extreg ****************************************************************/ + +/* Adds the given extension info for message type |l| and field number |num| + * into the registry. Returns false if this message type and field number were + * already in the map, or if memory allocation fails. */ +bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext *e, size_t count); + +/* Looks up the extension (if any) defined for message type |l| and field + * number |num|. If an extension was found, copies the field info into |*ext| + * and returns true. Otherwise returns false. */ +const upb_msglayout_field *_upb_extreg_get(const upb_extreg *r, + const upb_msglayout *l, + uint32_t num); + /** upb_msg *******************************************************************/ -/* Internal members of a upb_msg. We can change this without breaking binary - * compatibility. We put these before the user's data. The user's upb_msg* - * points after the upb_msg_internal. */ +/* Internal members of a upb_msg that track unknown fields and/or extensions. + * We can change this without breaking binary compatibility. We put these + * before the user's data. The user's upb_msg* points after the + * upb_msg_internal. */ typedef struct { - uint32_t len; + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_msg_ext) */ uint32_t size; - /* Data follows. */ -} upb_msg_unknowndata; -/* Used when a message is not extendable. */ + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = sizeof(upb_msg_internaldata) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_msg_internaldata)]; */ +} upb_msg_internaldata; + typedef struct { - upb_msg_unknowndata *unknown; + upb_msg_internaldata *internal; } upb_msg_internal; /* Maps upb_fieldtype_t -> memory size. */ @@ -1129,6 +1235,35 @@ void _upb_msg_discardunknown_shallow(upb_msg *msg); bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, upb_arena *arena); +/** upb_msg_ext ***************************************************************/ + +/* The internal representation of an extension is self-describing: it contains + * enough information that we can serialize it to binary format without needing + * to look it up in a registry. */ +typedef struct { + const upb_msglayout_ext *ext; + union { + upb_strview str; + void *ptr; + double dbl; + char scalar_data[8]; + } data; +} upb_msg_ext; + +/* Adds the given extension data to the given message. The returned extension will + * have its "ext" member initialized according to |ext|. */ +upb_msg_ext *_upb_msg_getorcreateext(upb_msg *msg, const upb_msglayout_ext *ext, + upb_arena *arena); + +/* Returns an array of extensions for this message. Note: the array is + * ordered in reverse relative to the order of creation. */ +const upb_msg_ext *_upb_msg_getexts(const upb_msg *msg, size_t *count); + +/* Returns an extension for the given field number, or NULL if no extension + * exists for this field number. */ +const upb_msg_ext *_upb_msg_getext(const upb_msg *msg, + const upb_msglayout_ext *ext); + /** Hasbit access *************************************************************/ UPB_INLINE bool _upb_hasbit(const upb_msg *msg, size_t idx) { @@ -1192,14 +1327,6 @@ UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_msg *msg, size_t ofs) { return *UPB_PTR_AT(msg, ofs, const upb_msg*) != NULL; } -UPB_INLINE bool _upb_isrepeated(const upb_msglayout_field *field) { - return (field->label & 3) == UPB_LABEL_REPEATED; -} - -UPB_INLINE bool _upb_repeated_or_map(const upb_msglayout_field *field) { - return field->label >= UPB_LABEL_REPEATED; -} - /** upb_array *****************************************************************/ /* Our internal representation for repeated fields. */ @@ -2121,13 +2248,19 @@ UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_ UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len); @@ -2158,13 +2291,19 @@ UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorPr UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len); @@ -2321,13 +2460,19 @@ UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new( UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len); @@ -2480,13 +2625,19 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_Descr UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len); @@ -2529,13 +2680,19 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_Descri UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len); @@ -2563,13 +2720,19 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRange UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len); @@ -2600,13 +2763,19 @@ UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptor UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len); @@ -2697,13 +2866,19 @@ UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptor UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len); @@ -2740,13 +2915,19 @@ UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorPr UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len); @@ -2824,13 +3005,19 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobu UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len); @@ -2858,13 +3045,19 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDe UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len); @@ -2907,13 +3100,19 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescri UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len); @@ -2965,13 +3164,19 @@ UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescript UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len); @@ -3032,13 +3237,19 @@ UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_aren UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len); @@ -3189,13 +3400,19 @@ UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(up UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len); @@ -3250,13 +3467,19 @@ UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_ar UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len); @@ -3323,13 +3546,19 @@ UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_ar UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len); @@ -3360,13 +3589,19 @@ UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_aren UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len); @@ -3409,13 +3644,19 @@ UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_ne UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len); @@ -3452,13 +3693,19 @@ UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(up UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len); @@ -3495,13 +3742,19 @@ UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_ UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len); @@ -3544,13 +3797,19 @@ UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOpt UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len); @@ -3617,13 +3876,19 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_Uninter UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len); @@ -3651,13 +3916,19 @@ UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(up UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len); @@ -3688,13 +3959,19 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeIn UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len); @@ -3755,13 +4032,19 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_ UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len); @@ -3792,13 +4075,19 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_Generat UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len); diff --git a/php/generate_test_protos.sh b/php/generate_test_protos.sh index e86ca07a687c..44bf4fccab90 100755 --- a/php/generate_test_protos.sh +++ b/php/generate_test_protos.sh @@ -4,8 +4,6 @@ set -e cd `dirname $0` -./prepare_c_extension.sh - if ../src/protoc --help > /dev/null; then PROTOC=src/protoc else @@ -13,7 +11,6 @@ else PROTOC=bazel-bin/protoc fi - if [[ -d tmp && -z $(find tests/proto ../$PROTOC -newer tmp) ]]; then # Generated protos are already present and up to date, so we can skip protoc. # diff --git a/php/prepare_c_extension.sh b/php/prepare_c_extension.sh deleted file mode 100755 index 1b6b9f1dae9d..000000000000 --- a/php/prepare_c_extension.sh +++ /dev/null @@ -1,20 +0,0 @@ - -cd $(dirname $0) - -if [[ -f ext/google/protobuf/third_party/wyhash/wyhash.h && -z $(find ../third_party/wyhash -newer ext/google/protobuf/third_party) ]]; then - # Generated protos are already present and up to date, so we can skip protoc. - # - # Protoc is very fast, but sometimes it is not available (like if we haven't - # built it in Docker). Skipping it helps us proceed in this case. - echo "wyhash is up to date, skipping." - exit 0 -fi - -# wyhash has to live in the base third_party directory. -# We copy it into the ext/google/protobuf directory for the build -# (and for the release to PECL). -rm -rf ext/google/protobuf/third_party -mkdir -p ext/google/protobuf/third_party/wyhash -cp ../third_party/wyhash/* ext/google/protobuf/third_party/wyhash - -echo "Copied wyhash from ../third_party -> ext/google/protobuf/third_party" diff --git a/php/tests/compile_extension.sh b/php/tests/compile_extension.sh index fce046952600..80378f02d59a 100755 --- a/php/tests/compile_extension.sh +++ b/php/tests/compile_extension.sh @@ -4,7 +4,6 @@ set -e cd $(dirname $0) -../prepare_c_extension.sh pushd ../ext/google/protobuf > /dev/null CONFIGURE_OPTIONS=("./configure" "--with-php-config=$(which php-config)") diff --git a/ruby/Rakefile b/ruby/Rakefile index 523d4de458b7..60ec6ea66583 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -78,12 +78,6 @@ if RUBY_PLATFORM == "java" system("mvn --batch-mode package") end else - unless ENV['IN_DOCKER'] == 'true' - # We need wyhash in-tree. - FileUtils.mkdir_p("ext/google/protobuf_c/third_party/wyhash") - FileUtils.cp("../third_party/wyhash/wyhash.h", "ext/google/protobuf_c/third_party/wyhash/wyhash.h") - end - Rake::ExtensionTask.new("protobuf_c", spec) do |ext| unless RUBY_PLATFORM =~ /darwin/ # TODO: also set "no_native to true" for mac if possible. As is, diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c index 2fddc096291b..8bcf6eee0067 100644 --- a/ruby/ext/google/protobuf_c/convert.c +++ b/ruby/ext/google/protobuf_c/convert.c @@ -41,7 +41,6 @@ #include "message.h" #include "protobuf.h" -#include "third_party/wyhash/wyhash.h" static upb_strview Convert_StringData(VALUE str, upb_arena *arena) { upb_strview ret; @@ -328,19 +327,19 @@ bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info) { uint64_t Msgval_GetHash(upb_msgval val, TypeInfo type_info, uint64_t seed) { switch (type_info.type) { case UPB_TYPE_BOOL: - return wyhash(&val, 1, seed, _wyp); + return Wyhash(&val, 1, seed, kWyhashSalt); case UPB_TYPE_FLOAT: case UPB_TYPE_INT32: case UPB_TYPE_UINT32: case UPB_TYPE_ENUM: - return wyhash(&val, 4, seed, _wyp); + return Wyhash(&val, 4, seed, kWyhashSalt); case UPB_TYPE_DOUBLE: case UPB_TYPE_INT64: case UPB_TYPE_UINT64: - return wyhash(&val, 8, seed, _wyp); + return Wyhash(&val, 8, seed, kWyhashSalt); case UPB_TYPE_STRING: case UPB_TYPE_BYTES: - return wyhash(val.str_val.data, val.str_val.size, seed, _wyp); + return Wyhash(val.str_val.data, val.str_val.size, seed, kWyhashSalt); case UPB_TYPE_MESSAGE: return Message_Hash(val.msg_val, type_info.def.msgdef, seed); default: diff --git a/ruby/ext/google/protobuf_c/extconf.rb b/ruby/ext/google/protobuf_c/extconf.rb index eaab4db74f30..ec17787f79fd 100755 --- a/ruby/ext/google/protobuf_c/extconf.rb +++ b/ruby/ext/google/protobuf_c/extconf.rb @@ -17,5 +17,4 @@ $objs = ["protobuf.o", "convert.o", "defs.o", "message.o", "repeated_field.o", "map.o", "ruby-upb.o", "wrap_memcpy.o"] -find_header('third_party/wyhash/wyhash.h', '../../../..') create_makefile("google/protobuf_c") diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 98f89e82771a..59602cf0899d 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -35,7 +35,6 @@ #include "map.h" #include "protobuf.h" #include "repeated_field.h" -#include "third_party/wyhash/wyhash.h" static VALUE cParseError = Qnil; static ID descriptor_instancevar_interned; @@ -717,7 +716,7 @@ uint64_t Message_Hash(const upb_msg* msg, const upb_msgdef* m, uint64_t seed) { &size); if (data) { - uint64_t ret = wyhash(data, size, seed, _wyp); + uint64_t ret = Wyhash(data, size, seed, kWyhashSalt); upb_arena_free(arena); return ret; } else { diff --git a/ruby/ext/google/protobuf_c/repeated_field.c b/ruby/ext/google/protobuf_c/repeated_field.c index 1cc4915e06db..88e8434f0a89 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.c +++ b/ruby/ext/google/protobuf_c/repeated_field.c @@ -34,7 +34,6 @@ #include "defs.h" #include "message.h" #include "protobuf.h" -#include "third_party/wyhash/wyhash.h" // ----------------------------------------------------------------------------- // Repeated field container type. diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index b1b701b4eef5..d68caac0e2cc 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -524,24 +524,43 @@ static void decode_munge(int type, wireval *val) { } static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, - uint32_t field_number) { + uint32_t field_number, + int *last_field_index) { static upb_msglayout_field none = {0, 0, 0, 0, 0, 0}; - /* Lots of optimization opportunities here. */ - int i; if (l == NULL) return &none; - for (i = 0; i < l->field_count; i++) { - if (l->fields[i].number == field_number) { - return &l->fields[i]; + + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX + if (idx < l->dense_below) { + goto found; + } + + /* Resume scanning from last_field_index since fields are usually in order. */ + int last = *last_field_index; + for (idx = last; idx < l->field_count; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + + for (idx = 0; idx < last; idx++) { + if (l->fields[idx].number == field_number) { + goto found; } } return &none; /* Unknown field. */ + + found: + UPB_ASSERT(l->fields[idx].number == field_number); + *last_field_index = idx; + return &l->fields[idx]; } -static upb_msg *decode_newsubmsg(upb_decstate *d, const upb_msglayout *layout, +static upb_msg *decode_newsubmsg(upb_decstate *d, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field) { - const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + const upb_msglayout *subl = submsgs[field->submsg_index]; return _upb_msg_new_inl(subl, &d->arena); } @@ -571,9 +590,10 @@ static const char *decode_readstr(upb_decstate *d, const char *ptr, int size, UPB_FORCEINLINE static const char *decode_tosubmsg(upb_decstate *d, const char *ptr, - upb_msg *submsg, const upb_msglayout *layout, + upb_msg *submsg, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field, int size) { - const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + const upb_msglayout *subl = submsgs[field->submsg_index]; int saved_delta = decode_pushlimit(d, ptr, size); if (--d->depth < 0) decode_err(d); if (!decode_isdone(d, &ptr)) { @@ -602,15 +622,17 @@ static const char *decode_group(upb_decstate *d, const char *ptr, UPB_FORCEINLINE static const char *decode_togroup(upb_decstate *d, const char *ptr, - upb_msg *submsg, const upb_msglayout *layout, + upb_msg *submsg, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field) { - const upb_msglayout *subl = layout->submsgs[field->submsg_index]; + const upb_msglayout *subl = submsgs[field->submsg_index]; return decode_group(d, ptr, submsg, subl, field->number); } static const char *decode_toarray(upb_decstate *d, const char *ptr, - upb_msg *msg, const upb_msglayout *layout, - const upb_msglayout_field *field, wireval val, + upb_msg *msg, + upb_msglayout const *const *submsgs, + const upb_msglayout_field *field, wireval *val, int op) { upb_array **arrp = UPB_PTR_AT(msg, field->offset, void); upb_array *arr = *arrp; @@ -632,27 +654,27 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, /* Append scalar value. */ mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void); arr->len++; - memcpy(mem, &val, 1 << op); + memcpy(mem, val, 1 << op); return ptr; case OP_STRING: - decode_verifyutf8(d, ptr, val.size); + decode_verifyutf8(d, ptr, val->size); /* Fallthrough. */ case OP_BYTES: { /* Append bytes. */ upb_strview *str = (upb_strview*)_upb_array_ptr(arr) + arr->len; arr->len++; - return decode_readstr(d, ptr, val.size, str); + return decode_readstr(d, ptr, val->size, str); } case OP_SUBMSG: { /* Append submessage / group. */ - upb_msg *submsg = decode_newsubmsg(d, layout, field); + upb_msg *submsg = decode_newsubmsg(d, submsgs, field); *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void *), upb_msg *) = submsg; arr->len++; if (UPB_UNLIKELY(field->descriptortype == UPB_DTYPE_GROUP)) { - return decode_togroup(d, ptr, submsg, layout, field); + return decode_togroup(d, ptr, submsg, submsgs, field); } else { - return decode_tosubmsg(d, ptr, submsg, layout, field, val.size); + return decode_tosubmsg(d, ptr, submsg, submsgs, field, val->size); } } case OP_FIXPCK_LG2(2): @@ -660,15 +682,15 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, /* Fixed packed. */ int lg2 = op - OP_FIXPCK_LG2(0); int mask = (1 << lg2) - 1; - size_t count = val.size >> lg2; - if ((val.size & mask) != 0) { + size_t count = val->size >> lg2; + if ((val->size & mask) != 0) { decode_err(d); /* Length isn't a round multiple of elem size. */ } decode_reserve(d, arr, count); mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); arr->len += count; - memcpy(mem, ptr, val.size); /* XXX: ptr boundary. */ - return ptr + val.size; + memcpy(mem, ptr, val->size); /* XXX: ptr boundary. */ + return ptr + val->size; } case OP_VARPCK_LG2(0): case OP_VARPCK_LG2(2): @@ -676,7 +698,7 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, /* Varint packed. */ int lg2 = op - OP_VARPCK_LG2(0); int scale = 1 << lg2; - int saved_limit = decode_pushlimit(d, ptr, val.size); + int saved_limit = decode_pushlimit(d, ptr, val->size); char *out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); while (!decode_isdone(d, &ptr)) { wireval elem; @@ -698,16 +720,15 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, } static const char *decode_tomap(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *layout, - const upb_msglayout_field *field, wireval val) { + upb_msglayout const *const *submsgs, + const upb_msglayout_field *field, wireval *val) { upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *); upb_map *map = *map_p; upb_map_entry ent; - const upb_msglayout *entry = layout->submsgs[field->submsg_index]; + const upb_msglayout *entry = submsgs[field->submsg_index]; if (!map) { /* Lazily create map. */ - const upb_msglayout *entry = layout->submsgs[field->submsg_index]; const upb_msglayout_field *key_field = &entry->fields[0]; const upb_msglayout_field *val_field = &entry->fields[1]; char key_size = desctype_to_mapsize[key_field->descriptortype]; @@ -727,28 +748,28 @@ static const char *decode_tomap(upb_decstate *d, const char *ptr, upb_msg *msg, ent.v.val = upb_value_ptr(_upb_msg_new(entry->submsgs[0], &d->arena)); } - ptr = decode_tosubmsg(d, ptr, &ent.k, layout, field, val.size); + ptr = decode_tosubmsg(d, ptr, &ent.k, submsgs, field, val->size); _upb_map_set(map, &ent.k, map->key_size, &ent.v, map->val_size, &d->arena); return ptr; } static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *layout, - const upb_msglayout_field *field, wireval val, + upb_msglayout const *const *submsgs, + const upb_msglayout_field *field, wireval *val, int op) { void *mem = UPB_PTR_AT(msg, field->offset, void); int type = field->descriptortype; /* Set presence if necessary. */ - if (field->presence < 0) { + if (field->presence > 0) { + _upb_sethas_field(msg, field); + } else if (field->presence < 0) { /* Oneof case */ uint32_t *oneof_case = _upb_oneofcase_field(msg, field); if (op == OP_SUBMSG && *oneof_case != field->number) { memset(mem, 0, sizeof(void*)); } *oneof_case = field->number; - } else if (field->presence > 0) { - _upb_sethas_field(msg, field); } /* Store into message. */ @@ -757,29 +778,29 @@ static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, upb_msg **submsgp = mem; upb_msg *submsg = *submsgp; if (!submsg) { - submsg = decode_newsubmsg(d, layout, field); + submsg = decode_newsubmsg(d, submsgs, field); *submsgp = submsg; } if (UPB_UNLIKELY(type == UPB_DTYPE_GROUP)) { - ptr = decode_togroup(d, ptr, submsg, layout, field); + ptr = decode_togroup(d, ptr, submsg, submsgs, field); } else { - ptr = decode_tosubmsg(d, ptr, submsg, layout, field, val.size); + ptr = decode_tosubmsg(d, ptr, submsg, submsgs, field, val->size); } break; } case OP_STRING: - decode_verifyutf8(d, ptr, val.size); + decode_verifyutf8(d, ptr, val->size); /* Fallthrough. */ case OP_BYTES: - return decode_readstr(d, ptr, val.size, mem); + return decode_readstr(d, ptr, val->size, mem); case OP_SCALAR_LG2(3): - memcpy(mem, &val, 8); + memcpy(mem, val, 8); break; case OP_SCALAR_LG2(2): - memcpy(mem, &val, 4); + memcpy(mem, val, 4); break; case OP_SCALAR_LG2(0): - memcpy(mem, &val, 1); + memcpy(mem, val, 1); break; default: UPB_UNREACHABLE(); @@ -805,6 +826,7 @@ static bool decode_tryfastdispatch(upb_decstate *d, const char **ptr, UPB_NOINLINE static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, const upb_msglayout *layout) { + int last_field_index = 0; while (true) { uint32_t tag; const upb_msglayout_field *field; @@ -819,7 +841,7 @@ static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, field_number = tag >> 3; wire_type = tag & 7; - field = upb_find_field(layout, field_number); + field = upb_find_field(layout, field_number, &last_field_index); switch (wire_type) { case UPB_WIRE_TYPE_VARINT: @@ -844,7 +866,7 @@ static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, case UPB_WIRE_TYPE_DELIMITED: { int ndx = field->descriptortype; uint64_t size; - if (_upb_isrepeated(field)) ndx += 18; + if (_upb_getmode(field) == _UPB_MODE_ARRAY) ndx += 18; ptr = decode_varint64(d, ptr, &size); if (size >= INT32_MAX || ptr - d->end + (int32_t)size > d->limit) { @@ -868,17 +890,18 @@ static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, if (op >= 0) { /* Parse, using op for dispatch. */ - switch (field->label) { - case UPB_LABEL_REPEATED: - case _UPB_LABEL_PACKED: - ptr = decode_toarray(d, ptr, msg, layout, field, val, op); + switch (_upb_getmode(field)) { + case _UPB_MODE_ARRAY: + ptr = decode_toarray(d, ptr, msg, layout->submsgs, field, &val, op); break; - case _UPB_LABEL_MAP: - ptr = decode_tomap(d, ptr, msg, layout, field, val); + case _UPB_MODE_MAP: + ptr = decode_tomap(d, ptr, msg, layout->submsgs, field, &val); break; - default: - ptr = decode_tomsg(d, ptr, msg, layout, field, val, op); + case _UPB_MODE_SCALAR: + ptr = decode_tomsg(d, ptr, msg, layout->submsgs, field, &val, op); break; + default: + UPB_UNREACHABLE(); } } else { unknown: @@ -924,7 +947,8 @@ static bool decode_top(struct upb_decstate *d, const char *buf, void *msg, } bool _upb_decode(const char *buf, size_t size, void *msg, - const upb_msglayout *l, upb_arena *arena, int options) { + const upb_msglayout *l, const upb_extreg *extreg, int options, + upb_arena *arena) { bool ok; upb_decstate state; unsigned depth = (unsigned)options >> 16; @@ -1126,7 +1150,7 @@ static void encode_fixedarray(upb_encstate *e, const upb_array *arr, } } -static void encode_message(upb_encstate *e, const char *msg, +static void encode_message(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, size_t *size); static void encode_scalar(upb_encstate *e, const void *_field_mem, @@ -1218,10 +1242,10 @@ static void encode_scalar(upb_encstate *e, const void *_field_mem, encode_tag(e, f->number, wire_type); } -static void encode_array(upb_encstate *e, const char *field_mem, +static void encode_array(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, const upb_msglayout_field *f) { - const upb_array *arr = *(const upb_array**)field_mem; - bool packed = f->label == _UPB_LABEL_PACKED; + const upb_array *arr = *UPB_PTR_AT(msg, f->offset, upb_array*); + bool packed = f->mode & _UPB_MODE_IS_PACKED; size_t pre_len = e->limit - e->ptr; if (arr == NULL || arr->len == 0) { @@ -1337,9 +1361,9 @@ static void encode_mapentry(upb_encstate *e, uint32_t number, encode_tag(e, number, UPB_WIRE_TYPE_DELIMITED); } -static void encode_map(upb_encstate *e, const char *field_mem, +static void encode_map(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, const upb_msglayout_field *f) { - const upb_map *map = *(const upb_map**)field_mem; + const upb_map *map = *UPB_PTR_AT(msg, f->offset, const upb_map*); const upb_msglayout *layout = m->submsgs[f->submsg_index]; UPB_ASSERT(layout->field_count == 2); @@ -1385,7 +1409,7 @@ static void encode_scalarfield(upb_encstate *e, const char *msg, encode_scalar(e, msg + f->offset, m, f, skip_empty); } -static void encode_message(upb_encstate *e, const char *msg, +static void encode_message(upb_encstate *e, const upb_msg *msg, const upb_msglayout *m, size_t *size) { size_t pre_len = e->limit - e->ptr; const upb_msglayout_field *f = &m->fields[m->field_count]; @@ -1402,12 +1426,18 @@ static void encode_message(upb_encstate *e, const char *msg, while (f != first) { f--; - if (_upb_isrepeated(f)) { - encode_array(e, msg + f->offset, m, f); - } else if (f->label == _UPB_LABEL_MAP) { - encode_map(e, msg + f->offset, m, f); - } else { - encode_scalarfield(e, msg, m, f); + switch (_upb_getmode(f)) { + case _UPB_MODE_ARRAY: + encode_array(e, msg, m, f); + break; + case _UPB_MODE_MAP: + encode_map(e, msg, m, f); + break; + case _UPB_MODE_SCALAR: + encode_scalarfield(e, msg, m, f); + break; + default: + UPB_UNREACHABLE(); } } @@ -1452,7 +1482,7 @@ char *upb_encode_ex(const void *msg, const upb_msglayout *l, int options, /** upb_msg *******************************************************************/ -static const size_t overhead = sizeof(upb_msg_internal); +static const size_t overhead = sizeof(upb_msg_internaldata); static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) { ptrdiff_t size = sizeof(upb_msg_internal); @@ -1468,49 +1498,107 @@ void _upb_msg_clear(upb_msg *msg, const upb_msglayout *l) { memset(mem, 0, upb_msg_sizeof(l)); } +static bool realloc_internal(upb_msg *msg, size_t need, upb_arena *arena) { + upb_msg_internal *in = upb_msg_getinternal(msg); + if (!in->internal) { + /* No internal data, allocate from scratch. */ + size_t size = UPB_MAX(128, _upb_lg2ceilsize(need + overhead)); + upb_msg_internaldata *internal = upb_arena_malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + /* Internal data is too small, reallocate. */ + size_t new_size = _upb_lg2ceilsize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_msg_internaldata *internal = + upb_arena_realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + /* Need to move extension data to the end. */ + char *ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; + } + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; +} + bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, upb_arena *arena) { - + if (!realloc_internal(msg, len, arena)) return false; upb_msg_internal *in = upb_msg_getinternal(msg); - if (!in->unknown) { - size_t size = 128; - while (size < len) size *= 2; - in->unknown = upb_arena_malloc(arena, size + overhead); - if (!in->unknown) return false; - in->unknown->size = size; - in->unknown->len = 0; - } else if (in->unknown->size - in->unknown->len < len) { - size_t need = in->unknown->len + len; - size_t size = in->unknown->size; - while (size < need) size *= 2; - in->unknown = upb_arena_realloc( - arena, in->unknown, in->unknown->size + overhead, size + overhead); - if (!in->unknown) return false; - in->unknown->size = size; - } - memcpy(UPB_PTR_AT(in->unknown + 1, in->unknown->len, char), data, len); - in->unknown->len += len; + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; return true; } void _upb_msg_discardunknown_shallow(upb_msg *msg) { upb_msg_internal *in = upb_msg_getinternal(msg); - if (in->unknown) { - in->unknown->len = 0; + if (in->internal) { + in->internal->unknown_end = overhead; } } const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { const upb_msg_internal *in = upb_msg_getinternal_const(msg); - if (in->unknown) { - *len = in->unknown->len; - return (char*)(in->unknown + 1); + if (in->internal) { + *len = in->internal->unknown_end - overhead; + return (char*)(in->internal + 1); } else { *len = 0; return NULL; } } +const upb_msg_ext *_upb_msg_getexts(const upb_msg *msg, size_t *count) { + const upb_msg_internal *in = upb_msg_getinternal_const(msg); + if (in->internal) { + *count = + (in->internal->size - in->internal->ext_begin) / sizeof(upb_msg_ext); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; + } +} + +const upb_msg_ext *_upb_msg_getext(const upb_msg *msg, + const upb_msglayout_ext *e) { + size_t n; + const upb_msg_ext *ext = _upb_msg_getexts(msg, &n); + + /* For now we use linear search exclusively to find extensions. If this + * becomes an issue due to messages with lots of extensions, we can introduce + * a table of some sort. */ + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } + + return NULL; +} + +upb_msg_ext *_upb_msg_getorcreateext(upb_msg *msg, const upb_msglayout_ext *e, + upb_arena *arena) { + upb_msg_ext *ext = (upb_msg_ext*)_upb_msg_getext(msg, e); + if (ext) return ext; + if (!realloc_internal(msg, sizeof(upb_msg_ext), arena)) return NULL; + upb_msg_internal *in = upb_msg_getinternal(msg); + in->internal->ext_begin -= sizeof(upb_msg_ext); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(upb_msg_ext)); + ext->ext = e; + return ext; +} + /** upb_array *****************************************************************/ bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) { @@ -1700,6 +1788,63 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, return true; } +/** upb_extreg ****************************************************************/ + +struct upb_extreg { + upb_arena *arena; + upb_strtable exts; /* Key is upb_msglayout* concatenated with fieldnum. */ +}; + +#define EXTREG_KEY_SIZE (sizeof(upb_msglayout*) + sizeof(uint32_t)) + +static void extreg_key(char *buf, const upb_msglayout *l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); +} + +upb_extreg *upb_extreg_new(upb_arena *arena) { + upb_extreg *r = upb_arena_malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; +} + +bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext *e, size_t count) { + char buf[EXTREG_KEY_SIZE]; + const upb_msglayout_ext *start = e; + const upb_msglayout_ext *end = e + count; + for (; e < end; e++) { + extreg_key(buf, e->extendee, e->field.number); + if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(e), r->arena)) { + goto failure; + } + } + return true; + +failure: + /* Back out the entries previously added. */ + for (end = e, e = start; e < end; e++) { + extreg_key(buf, e->extendee, e->field.number); + upb_strtable_remove(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + } + return false; +} + +const upb_msglayout_field *_upb_extreg_get(const upb_extreg *r, + const upb_msglayout *l, + uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, l, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); + } else { + return NULL; + } +} + /** upb/table.c ************************************************************/ /* * upb_table Implementation @@ -1709,7 +1854,6 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, #include -#include "third_party/wyhash/wyhash.h" /* Must be last. */ @@ -1982,8 +2126,143 @@ static upb_tabkey strcopy(lookupkey_t k2, upb_arena *a) { return (uintptr_t)str; } +/* Adapted from ABSL's wyhash. */ + +static uint64_t UnalignedLoad64(const void *p) { + uint64_t val; + memcpy(&val, p, 8); + return val; +} + +static uint32_t UnalignedLoad32(const void *p) { + uint32_t val; + memcpy(&val, p, 4); + return val; +} + +#if defined(_MSC_VER) && defined(_M_X64) +#include +#endif + +/* Computes a * b, returning the low 64 bits of the result and storing the high + * 64 bits in |*high|. */ +static uint64_t upb_umul128(uint64_t v0, uint64_t v1, uint64_t* out_high) { +#ifdef __SIZEOF_INT128__ + __uint128_t p = v0; + p *= v1; + *out_high = (uint64_t)(p >> 64); + return (uint64_t)p; +#elif defined(_MSC_VER) && defined(_M_X64) + return _umul128(v0, v1, out_high); +#else + uint64_t a32 = v0 >> 32; + uint64_t a00 = v0 & 0xffffffff; + uint64_t b32 = v1 >> 32; + uint64_t b00 = v1 & 0xffffffff; + uint64_t high = a32 * b32; + uint64_t low = a00 * b00; + uint64_t mid1 = a32 * b00; + uint64_t mid2 = a00 * b32; + low += (mid1 << 32) + (mid2 << 32); + // Omit carry bit, for mixing we do not care about exact numerical precision. + high += (mid1 >> 32) + (mid2 >> 32); + *out_high = high; + return low; +#endif +} + +static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { + uint64_t high; + uint64_t low = upb_umul128(v0, v1, &high); + return low ^ high; +} + +uint64_t Wyhash(const void *data, size_t len, uint64_t seed, + const uint64_t salt[]) { + const uint8_t* ptr = (const uint8_t*)data; + uint64_t starting_length = (uint64_t)len; + uint64_t current_state = seed ^ salt[0]; + + if (len > 64) { + // If we have more than 64 bytes, we're going to handle chunks of 64 + // bytes at a time. We're going to build up two separate hash states + // which we will then hash together. + uint64_t duplicated_state = current_state; + + do { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); + uint64_t c = UnalignedLoad64(ptr + 16); + uint64_t d = UnalignedLoad64(ptr + 24); + uint64_t e = UnalignedLoad64(ptr + 32); + uint64_t f = UnalignedLoad64(ptr + 40); + uint64_t g = UnalignedLoad64(ptr + 48); + uint64_t h = UnalignedLoad64(ptr + 56); + + uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state); + current_state = (cs0 ^ cs1); + + uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state); + uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state); + duplicated_state = (ds0 ^ ds1); + + ptr += 64; + len -= 64; + } while (len > 64); + + current_state = current_state ^ duplicated_state; + } + + // We now have a data `ptr` with at most 64 bytes and the current state + // of the hashing state machine stored in current_state. + while (len > 16) { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); + + current_state = WyhashMix(a ^ salt[1], b ^ current_state); + + ptr += 16; + len -= 16; + } + + // We now have a data `ptr` with at most 16 bytes. + uint64_t a = 0; + uint64_t b = 0; + if (len > 8) { + // When we have at least 9 and at most 16 bytes, set A to the first 64 + // bits of the input and B to the last 64 bits of the input. Yes, they will + // overlap in the middle if we are working with less than the full 16 + // bytes. + a = UnalignedLoad64(ptr); + b = UnalignedLoad64(ptr + len - 8); + } else if (len > 3) { + // If we have at least 4 and at most 8 bytes, set A to the first 32 + // bits and B to the last 32 bits. + a = UnalignedLoad32(ptr); + b = UnalignedLoad32(ptr + len - 4); + } else if (len > 0) { + // If we have at least 1 and at most 3 bytes, read all of the provided + // bits into A, with some adjustments. + a = ((ptr[0] << 16) | (ptr[len >> 1] << 8) | ptr[len - 1]); + b = 0; + } else { + a = 0; + b = 0; + } + + uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t z = salt[1] ^ starting_length; + return WyhashMix(w, z); +} + +const uint64_t kWyhashSalt[5] = { + 0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL, 0xA4093822299F31D0ULL, + 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, +}; + static uint32_t table_hash(const char *p, size_t n) { - return wyhash(p, n, 0, _wyp); + return Wyhash(p, n, 0, kWyhashSalt); } static uint32_t strhash(upb_tabkey key) { @@ -3710,13 +3989,13 @@ static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = }; static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_FileDescriptorSet_msginit = { &google_protobuf_FileDescriptorSet_submsgs[0], &google_protobuf_FileDescriptorSet__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 1, 255, }; static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = { @@ -3729,24 +4008,24 @@ static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] }; static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(12, 24), 2, 0, 12, 1}, - {3, UPB_SIZE(36, 72), 0, 0, 12, 3}, - {4, UPB_SIZE(40, 80), 0, 0, 11, 3}, - {5, UPB_SIZE(44, 88), 0, 1, 11, 3}, - {6, UPB_SIZE(48, 96), 0, 4, 11, 3}, - {7, UPB_SIZE(52, 104), 0, 2, 11, 3}, - {8, UPB_SIZE(28, 56), 3, 3, 11, 1}, - {9, UPB_SIZE(32, 64), 4, 5, 11, 1}, - {10, UPB_SIZE(56, 112), 0, 0, 5, 3}, - {11, UPB_SIZE(60, 120), 0, 0, 5, 3}, - {12, UPB_SIZE(20, 40), 5, 0, 12, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(36, 72), 0, 0, 12, _UPB_MODE_ARRAY}, + {4, UPB_SIZE(40, 80), 0, 0, 11, _UPB_MODE_ARRAY}, + {5, UPB_SIZE(44, 88), 0, 1, 11, _UPB_MODE_ARRAY}, + {6, UPB_SIZE(48, 96), 0, 4, 11, _UPB_MODE_ARRAY}, + {7, UPB_SIZE(52, 104), 0, 2, 11, _UPB_MODE_ARRAY}, + {8, UPB_SIZE(28, 56), 3, 3, 11, _UPB_MODE_SCALAR}, + {9, UPB_SIZE(32, 64), 4, 5, 11, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(56, 112), 0, 0, 5, _UPB_MODE_ARRAY}, + {11, UPB_SIZE(60, 120), 0, 0, 5, _UPB_MODE_ARRAY}, + {12, UPB_SIZE(20, 40), 5, 0, 12, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_FileDescriptorProto_msginit = { &google_protobuf_FileDescriptorProto_submsgs[0], &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(64, 128), 12, false, 255, + UPB_SIZE(64, 128), 12, false, 12, 255, }; static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[7] = { @@ -3760,22 +4039,22 @@ static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[7] = { }; static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(16, 32), 0, 4, 11, 3}, - {3, UPB_SIZE(20, 40), 0, 0, 11, 3}, - {4, UPB_SIZE(24, 48), 0, 3, 11, 3}, - {5, UPB_SIZE(28, 56), 0, 1, 11, 3}, - {6, UPB_SIZE(32, 64), 0, 4, 11, 3}, - {7, UPB_SIZE(12, 24), 2, 5, 11, 1}, - {8, UPB_SIZE(36, 72), 0, 6, 11, 3}, - {9, UPB_SIZE(40, 80), 0, 2, 11, 3}, - {10, UPB_SIZE(44, 88), 0, 0, 12, 3}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(16, 32), 0, 4, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(20, 40), 0, 0, 11, _UPB_MODE_ARRAY}, + {4, UPB_SIZE(24, 48), 0, 3, 11, _UPB_MODE_ARRAY}, + {5, UPB_SIZE(28, 56), 0, 1, 11, _UPB_MODE_ARRAY}, + {6, UPB_SIZE(32, 64), 0, 4, 11, _UPB_MODE_ARRAY}, + {7, UPB_SIZE(12, 24), 2, 5, 11, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(36, 72), 0, 6, 11, _UPB_MODE_ARRAY}, + {9, UPB_SIZE(40, 80), 0, 2, 11, _UPB_MODE_ARRAY}, + {10, UPB_SIZE(44, 88), 0, 0, 12, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_DescriptorProto_msginit = { &google_protobuf_DescriptorProto_submsgs[0], &google_protobuf_DescriptorProto__fields[0], - UPB_SIZE(48, 96), 10, false, 255, + UPB_SIZE(48, 96), 10, false, 10, 255, }; static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { @@ -3783,26 +4062,26 @@ static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange }; static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, - {3, UPB_SIZE(12, 16), 3, 0, 11, 1}, + {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(12, 16), 3, 0, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = { &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], &google_protobuf_DescriptorProto_ExtensionRange__fields[0], - UPB_SIZE(16, 24), 3, false, 255, + UPB_SIZE(16, 24), 3, false, 3, 255, }; static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, + {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = { NULL, &google_protobuf_DescriptorProto_ReservedRange__fields[0], - UPB_SIZE(16, 16), 2, false, 255, + UPB_SIZE(16, 16), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = { @@ -3810,13 +4089,13 @@ static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[ }; static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {999, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = { &google_protobuf_ExtensionRangeOptions_submsgs[0], &google_protobuf_ExtensionRangeOptions__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 0, 255, }; static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1] = { @@ -3824,23 +4103,23 @@ static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1 }; static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = { - {1, UPB_SIZE(24, 24), 1, 0, 12, 1}, - {2, UPB_SIZE(32, 40), 2, 0, 12, 1}, - {3, UPB_SIZE(12, 12), 3, 0, 5, 1}, - {4, UPB_SIZE(4, 4), 4, 0, 14, 1}, - {5, UPB_SIZE(8, 8), 5, 0, 14, 1}, - {6, UPB_SIZE(40, 56), 6, 0, 12, 1}, - {7, UPB_SIZE(48, 72), 7, 0, 12, 1}, - {8, UPB_SIZE(64, 104), 8, 0, 11, 1}, - {9, UPB_SIZE(16, 16), 9, 0, 5, 1}, - {10, UPB_SIZE(56, 88), 10, 0, 12, 1}, - {17, UPB_SIZE(20, 20), 11, 0, 8, 1}, + {1, UPB_SIZE(24, 24), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(32, 40), 2, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(12, 12), 3, 0, 5, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(4, 4), 4, 0, 14, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(8, 8), 5, 0, 14, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(40, 56), 6, 0, 12, _UPB_MODE_SCALAR}, + {7, UPB_SIZE(48, 72), 7, 0, 12, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(64, 104), 8, 0, 11, _UPB_MODE_SCALAR}, + {9, UPB_SIZE(16, 16), 9, 0, 5, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(56, 88), 10, 0, 12, _UPB_MODE_SCALAR}, + {17, UPB_SIZE(20, 20), 11, 0, 8, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = { &google_protobuf_FieldDescriptorProto_submsgs[0], &google_protobuf_FieldDescriptorProto__fields[0], - UPB_SIZE(72, 112), 11, false, 255, + UPB_SIZE(72, 112), 11, false, 10, 255, }; static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = { @@ -3848,14 +4127,14 @@ static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1 }; static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(12, 24), 2, 0, 11, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 24), 2, 0, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = { &google_protobuf_OneofDescriptorProto_submsgs[0], &google_protobuf_OneofDescriptorProto__fields[0], - UPB_SIZE(16, 32), 2, false, 255, + UPB_SIZE(16, 32), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = { @@ -3865,28 +4144,28 @@ static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] }; static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(16, 32), 0, 2, 11, 3}, - {3, UPB_SIZE(12, 24), 2, 1, 11, 1}, - {4, UPB_SIZE(20, 40), 0, 0, 11, 3}, - {5, UPB_SIZE(24, 48), 0, 0, 12, 3}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(16, 32), 0, 2, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(12, 24), 2, 1, 11, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(20, 40), 0, 0, 11, _UPB_MODE_ARRAY}, + {5, UPB_SIZE(24, 48), 0, 0, 12, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = { &google_protobuf_EnumDescriptorProto_submsgs[0], &google_protobuf_EnumDescriptorProto__fields[0], - UPB_SIZE(32, 64), 5, false, 255, + UPB_SIZE(32, 64), 5, false, 5, 255, }; static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, - {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, + {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { NULL, &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], - UPB_SIZE(16, 16), 2, false, 255, + UPB_SIZE(16, 16), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { @@ -3894,15 +4173,15 @@ static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_subms }; static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = { - {1, UPB_SIZE(8, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(4, 4), 2, 0, 5, 1}, - {3, UPB_SIZE(16, 24), 3, 0, 11, 1}, + {1, UPB_SIZE(8, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(4, 4), 2, 0, 5, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(16, 24), 3, 0, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = { &google_protobuf_EnumValueDescriptorProto_submsgs[0], &google_protobuf_EnumValueDescriptorProto__fields[0], - UPB_SIZE(24, 32), 3, false, 255, + UPB_SIZE(24, 32), 3, false, 3, 255, }; static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { @@ -3911,15 +4190,15 @@ static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs }; static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(16, 32), 0, 0, 11, 3}, - {3, UPB_SIZE(12, 24), 2, 1, 11, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(16, 32), 0, 0, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(12, 24), 2, 1, 11, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = { &google_protobuf_ServiceDescriptorProto_submsgs[0], &google_protobuf_ServiceDescriptorProto__fields[0], - UPB_SIZE(24, 48), 3, false, 255, + UPB_SIZE(24, 48), 3, false, 3, 255, }; static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = { @@ -3927,18 +4206,18 @@ static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[ }; static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {2, UPB_SIZE(12, 24), 2, 0, 12, 1}, - {3, UPB_SIZE(20, 40), 3, 0, 12, 1}, - {4, UPB_SIZE(28, 56), 4, 0, 11, 1}, - {5, UPB_SIZE(1, 1), 5, 0, 8, 1}, - {6, UPB_SIZE(2, 2), 6, 0, 8, 1}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(20, 40), 3, 0, 12, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(28, 56), 4, 0, 11, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(1, 1), 5, 0, 8, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(2, 2), 6, 0, 8, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = { &google_protobuf_MethodDescriptorProto_submsgs[0], &google_protobuf_MethodDescriptorProto__fields[0], - UPB_SIZE(32, 64), 6, false, 255, + UPB_SIZE(32, 64), 6, false, 6, 255, }; static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { @@ -3946,33 +4225,33 @@ static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = { - {1, UPB_SIZE(20, 24), 1, 0, 12, 1}, - {8, UPB_SIZE(28, 40), 2, 0, 12, 1}, - {9, UPB_SIZE(4, 4), 3, 0, 14, 1}, - {10, UPB_SIZE(8, 8), 4, 0, 8, 1}, - {11, UPB_SIZE(36, 56), 5, 0, 12, 1}, - {16, UPB_SIZE(9, 9), 6, 0, 8, 1}, - {17, UPB_SIZE(10, 10), 7, 0, 8, 1}, - {18, UPB_SIZE(11, 11), 8, 0, 8, 1}, - {20, UPB_SIZE(12, 12), 9, 0, 8, 1}, - {23, UPB_SIZE(13, 13), 10, 0, 8, 1}, - {27, UPB_SIZE(14, 14), 11, 0, 8, 1}, - {31, UPB_SIZE(15, 15), 12, 0, 8, 1}, - {36, UPB_SIZE(44, 72), 13, 0, 12, 1}, - {37, UPB_SIZE(52, 88), 14, 0, 12, 1}, - {39, UPB_SIZE(60, 104), 15, 0, 12, 1}, - {40, UPB_SIZE(68, 120), 16, 0, 12, 1}, - {41, UPB_SIZE(76, 136), 17, 0, 12, 1}, - {42, UPB_SIZE(16, 16), 18, 0, 8, 1}, - {44, UPB_SIZE(84, 152), 19, 0, 12, 1}, - {45, UPB_SIZE(92, 168), 20, 0, 12, 1}, - {999, UPB_SIZE(100, 184), 0, 0, 11, 3}, + {1, UPB_SIZE(20, 24), 1, 0, 12, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(28, 40), 2, 0, 12, _UPB_MODE_SCALAR}, + {9, UPB_SIZE(4, 4), 3, 0, 14, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(8, 8), 4, 0, 8, _UPB_MODE_SCALAR}, + {11, UPB_SIZE(36, 56), 5, 0, 12, _UPB_MODE_SCALAR}, + {16, UPB_SIZE(9, 9), 6, 0, 8, _UPB_MODE_SCALAR}, + {17, UPB_SIZE(10, 10), 7, 0, 8, _UPB_MODE_SCALAR}, + {18, UPB_SIZE(11, 11), 8, 0, 8, _UPB_MODE_SCALAR}, + {20, UPB_SIZE(12, 12), 9, 0, 8, _UPB_MODE_SCALAR}, + {23, UPB_SIZE(13, 13), 10, 0, 8, _UPB_MODE_SCALAR}, + {27, UPB_SIZE(14, 14), 11, 0, 8, _UPB_MODE_SCALAR}, + {31, UPB_SIZE(15, 15), 12, 0, 8, _UPB_MODE_SCALAR}, + {36, UPB_SIZE(44, 72), 13, 0, 12, _UPB_MODE_SCALAR}, + {37, UPB_SIZE(52, 88), 14, 0, 12, _UPB_MODE_SCALAR}, + {39, UPB_SIZE(60, 104), 15, 0, 12, _UPB_MODE_SCALAR}, + {40, UPB_SIZE(68, 120), 16, 0, 12, _UPB_MODE_SCALAR}, + {41, UPB_SIZE(76, 136), 17, 0, 12, _UPB_MODE_SCALAR}, + {42, UPB_SIZE(16, 16), 18, 0, 8, _UPB_MODE_SCALAR}, + {44, UPB_SIZE(84, 152), 19, 0, 12, _UPB_MODE_SCALAR}, + {45, UPB_SIZE(92, 168), 20, 0, 12, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(100, 184), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_FileOptions_msginit = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], - UPB_SIZE(104, 192), 21, false, 255, + UPB_SIZE(104, 192), 21, false, 1, 255, }; static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { @@ -3980,17 +4259,17 @@ static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {2, UPB_SIZE(2, 2), 2, 0, 8, 1}, - {3, UPB_SIZE(3, 3), 3, 0, 8, 1}, - {7, UPB_SIZE(4, 4), 4, 0, 8, 1}, - {999, UPB_SIZE(8, 8), 0, 0, 11, 3}, + {1, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(2, 2), 2, 0, 8, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(3, 3), 3, 0, 8, _UPB_MODE_SCALAR}, + {7, UPB_SIZE(4, 4), 4, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(8, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_MessageOptions_msginit = { &google_protobuf_MessageOptions_submsgs[0], &google_protobuf_MessageOptions__fields[0], - UPB_SIZE(16, 16), 5, false, 255, + UPB_SIZE(16, 16), 5, false, 3, 255, }; static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { @@ -3998,19 +4277,19 @@ static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = { - {1, UPB_SIZE(4, 4), 1, 0, 14, 1}, - {2, UPB_SIZE(12, 12), 2, 0, 8, 1}, - {3, UPB_SIZE(13, 13), 3, 0, 8, 1}, - {5, UPB_SIZE(14, 14), 4, 0, 8, 1}, - {6, UPB_SIZE(8, 8), 5, 0, 14, 1}, - {10, UPB_SIZE(15, 15), 6, 0, 8, 1}, - {999, UPB_SIZE(16, 16), 0, 0, 11, 3}, + {1, UPB_SIZE(4, 4), 1, 0, 14, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(12, 12), 2, 0, 8, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(13, 13), 3, 0, 8, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(14, 14), 4, 0, 8, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(8, 8), 5, 0, 14, _UPB_MODE_SCALAR}, + {10, UPB_SIZE(15, 15), 6, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(16, 16), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_FieldOptions_msginit = { &google_protobuf_FieldOptions_submsgs[0], &google_protobuf_FieldOptions__fields[0], - UPB_SIZE(24, 24), 7, false, 255, + UPB_SIZE(24, 24), 7, false, 3, 255, }; static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { @@ -4018,13 +4297,13 @@ static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {999, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_OneofOptions_msginit = { &google_protobuf_OneofOptions_submsgs[0], &google_protobuf_OneofOptions__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 0, 255, }; static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { @@ -4032,15 +4311,15 @@ static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = { - {2, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {3, UPB_SIZE(2, 2), 2, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, + {2, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(2, 2), 2, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_EnumOptions_msginit = { &google_protobuf_EnumOptions_submsgs[0], &google_protobuf_EnumOptions__fields[0], - UPB_SIZE(8, 16), 3, false, 255, + UPB_SIZE(8, 16), 3, false, 0, 255, }; static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = { @@ -4048,14 +4327,14 @@ static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = }; static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, + {1, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_EnumValueOptions_msginit = { &google_protobuf_EnumValueOptions_submsgs[0], &google_protobuf_EnumValueOptions__fields[0], - UPB_SIZE(8, 16), 2, false, 255, + UPB_SIZE(8, 16), 2, false, 1, 255, }; static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { @@ -4063,14 +4342,14 @@ static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = { - {33, UPB_SIZE(1, 1), 1, 0, 8, 1}, - {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, + {33, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_ServiceOptions_msginit = { &google_protobuf_ServiceOptions_submsgs[0], &google_protobuf_ServiceOptions__fields[0], - UPB_SIZE(8, 16), 2, false, 255, + UPB_SIZE(8, 16), 2, false, 0, 255, }; static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { @@ -4078,15 +4357,15 @@ static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = { - {33, UPB_SIZE(8, 8), 1, 0, 8, 1}, - {34, UPB_SIZE(4, 4), 2, 0, 14, 1}, - {999, UPB_SIZE(12, 16), 0, 0, 11, 3}, + {33, UPB_SIZE(8, 8), 1, 0, 8, _UPB_MODE_SCALAR}, + {34, UPB_SIZE(4, 4), 2, 0, 14, _UPB_MODE_SCALAR}, + {999, UPB_SIZE(12, 16), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_MethodOptions_msginit = { &google_protobuf_MethodOptions_submsgs[0], &google_protobuf_MethodOptions__fields[0], - UPB_SIZE(16, 24), 3, false, 255, + UPB_SIZE(16, 24), 3, false, 0, 255, }; static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = { @@ -4094,30 +4373,30 @@ static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] }; static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = { - {2, UPB_SIZE(56, 80), 0, 0, 11, 3}, - {3, UPB_SIZE(32, 32), 1, 0, 12, 1}, - {4, UPB_SIZE(8, 8), 2, 0, 4, 1}, - {5, UPB_SIZE(16, 16), 3, 0, 3, 1}, - {6, UPB_SIZE(24, 24), 4, 0, 1, 1}, - {7, UPB_SIZE(40, 48), 5, 0, 12, 1}, - {8, UPB_SIZE(48, 64), 6, 0, 12, 1}, + {2, UPB_SIZE(56, 80), 0, 0, 11, _UPB_MODE_ARRAY}, + {3, UPB_SIZE(32, 32), 1, 0, 12, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(8, 8), 2, 0, 4, _UPB_MODE_SCALAR}, + {5, UPB_SIZE(16, 16), 3, 0, 3, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(24, 24), 4, 0, 1, _UPB_MODE_SCALAR}, + {7, UPB_SIZE(40, 48), 5, 0, 12, _UPB_MODE_SCALAR}, + {8, UPB_SIZE(48, 64), 6, 0, 12, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_UninterpretedOption_msginit = { &google_protobuf_UninterpretedOption_submsgs[0], &google_protobuf_UninterpretedOption__fields[0], - UPB_SIZE(64, 96), 7, false, 255, + UPB_SIZE(64, 96), 7, false, 0, 255, }; static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, 2}, - {2, UPB_SIZE(1, 1), 2, 0, 8, 2}, + {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {2, UPB_SIZE(1, 1), 2, 0, 8, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = { NULL, &google_protobuf_UninterpretedOption_NamePart__fields[0], - UPB_SIZE(16, 32), 2, false, 255, + UPB_SIZE(16, 32), 2, false, 2, 255, }; static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { @@ -4125,27 +4404,27 @@ static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { }; static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_SourceCodeInfo_msginit = { &google_protobuf_SourceCodeInfo_submsgs[0], &google_protobuf_SourceCodeInfo__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 1, 255, }; static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_LABEL_PACKED}, - {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_LABEL_PACKED}, - {3, UPB_SIZE(4, 8), 1, 0, 12, 1}, - {4, UPB_SIZE(12, 24), 2, 0, 12, 1}, - {6, UPB_SIZE(28, 56), 0, 0, 12, 3}, + {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, + {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, + {3, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, + {6, UPB_SIZE(28, 56), 0, 0, 12, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = { NULL, &google_protobuf_SourceCodeInfo_Location__fields[0], - UPB_SIZE(32, 64), 5, false, 255, + UPB_SIZE(32, 64), 5, false, 4, 255, }; static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = { @@ -4153,26 +4432,26 @@ static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = }; static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, + {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, }; const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = { &google_protobuf_GeneratedCodeInfo_submsgs[0], &google_protobuf_GeneratedCodeInfo__fields[0], - UPB_SIZE(8, 8), 1, false, 255, + UPB_SIZE(8, 8), 1, false, 1, 255, }; static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { - {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED}, - {2, UPB_SIZE(12, 16), 1, 0, 12, 1}, - {3, UPB_SIZE(4, 4), 2, 0, 5, 1}, - {4, UPB_SIZE(8, 8), 3, 0, 5, 1}, + {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, + {2, UPB_SIZE(12, 16), 1, 0, 12, _UPB_MODE_SCALAR}, + {3, UPB_SIZE(4, 4), 2, 0, 5, _UPB_MODE_SCALAR}, + {4, UPB_SIZE(8, 8), 3, 0, 5, _UPB_MODE_SCALAR}, }; const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = { NULL, &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], - UPB_SIZE(24, 48), 4, false, 255, + UPB_SIZE(24, 48), 4, false, 4, 255, }; @@ -5167,13 +5446,44 @@ static int field_number_cmp(const void *p1, const void *p2) { return f1->number - f2->number; } -static void assign_layout_indices(const upb_msgdef *m, upb_msglayout_field *fields) { +static void assign_layout_indices(const upb_msgdef *m, upb_msglayout *l, + upb_msglayout_field *fields) { int i; int n = upb_msgdef_numfields(m); + int dense_below = 0; for (i = 0; i < n; i++) { upb_fielddef *f = (upb_fielddef*)upb_msgdef_itof(m, fields[i].number); UPB_ASSERT(f); f->layout_index = i; + if (i < UINT8_MAX && fields[i].number == i + 1 && + (i == 0 || fields[i-1].number == i)) { + dense_below = i + 1; + } + } + l->dense_below = dense_below; +} + +static void fill_fieldlayout(upb_msglayout_field *field, const upb_fielddef *f) { + field->number = upb_fielddef_number(f); + field->descriptortype = upb_fielddef_descriptortype(f); + + if (field->descriptortype == UPB_DTYPE_STRING && + f->file->syntax == UPB_SYNTAX_PROTO2) { + /* See TableDescriptorType() in upbc/generator.cc for details and + * rationale. */ + field->descriptortype = UPB_DTYPE_BYTES; + } + + if (upb_fielddef_ismap(f)) { + field->mode = _UPB_MODE_MAP; + } else if (upb_fielddef_isseq(f)) { + field->mode = _UPB_MODE_ARRAY; + } else { + field->mode = _UPB_MODE_SCALAR; + } + + if (upb_fielddef_packed(f)) { + field->mode |= _UPB_MODE_IS_PACKED; } } @@ -5218,8 +5528,8 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { const upb_fielddef *val = upb_msgdef_itof(m, 2); fields[0].number = 1; fields[1].number = 2; - fields[0].label = UPB_LABEL_OPTIONAL; - fields[1].label = UPB_LABEL_OPTIONAL; + fields[0].mode = _UPB_MODE_SCALAR; + fields[1].mode = _UPB_MODE_SCALAR; fields[0].presence = 0; fields[1].presence = 0; fields[0].descriptortype = upb_fielddef_descriptortype(key); @@ -5255,22 +5565,7 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { upb_fielddef* f = upb_msg_iter_field(&it); upb_msglayout_field *field = &fields[upb_fielddef_index(f)]; - field->number = upb_fielddef_number(f); - field->descriptortype = upb_fielddef_descriptortype(f); - field->label = upb_fielddef_label(f); - - if (field->descriptortype == UPB_DTYPE_STRING && - f->file->syntax == UPB_SYNTAX_PROTO2) { - /* See TableDescriptorType() in upbc/generator.cc for details and - * rationale. */ - field->descriptortype = UPB_DTYPE_BYTES; - } - - if (upb_fielddef_ismap(f)) { - field->label = _UPB_LABEL_MAP; - } else if (upb_fielddef_packed(f)) { - field->label = _UPB_LABEL_PACKED; - } + fill_fieldlayout(field, f); if (upb_fielddef_issubmsg(f)) { const upb_msgdef *subm = upb_fielddef_msgsubdef(f); @@ -5346,7 +5641,7 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { /* Sort fields by number. */ qsort(fields, upb_msgdef_numfields(m), sizeof(*fields), field_number_cmp); - assign_layout_indices(m, fields); + assign_layout_indices(m, l, fields); } static char *strviewdup(symtab_addctx *ctx, upb_strview view) { @@ -6056,13 +6351,18 @@ static void build_filedef( const upb_strview* strs; size_t i, n; - count_types_in_file(file_proto, file); + file->symtab = ctx->symtab; + /* One pass to count and allocate. */ + file->msg_count = 0; + file->enum_count = 0; + file->ext_count = 0; + count_types_in_file(file_proto, file); file->msgs = symtab_alloc(ctx, sizeof(*file->msgs) * file->msg_count); file->enums = symtab_alloc(ctx, sizeof(*file->enums) * file->enum_count); file->exts = symtab_alloc(ctx, sizeof(*file->exts) * file->ext_count); - /* We increment these as defs are added. */ + /* In the second pass we increment these as defs are added. */ file->msg_count = 0; file->enum_count = 0; file->ext_count = 0; @@ -6191,41 +6491,43 @@ static void remove_filedef(upb_symtab *s, upb_filedef *file) { static const upb_filedef *_upb_symtab_addfile( upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, const upb_msglayout **layouts, upb_status *status) { - upb_arena *file_arena = upb_arena_new(); - upb_filedef *file; symtab_addctx ctx; + upb_strview name = google_protobuf_FileDescriptorProto_name(file_proto); - if (!file_arena) return NULL; - - file = upb_arena_malloc(file_arena, sizeof(*file)); - if (!file) goto done; + if (upb_strtable_lookup2(&s->files, name.data, name.size, NULL)) { + upb_status_seterrf(status, "duplicate file name (%.*s)", + UPB_STRVIEW_ARGS(name)); + return NULL; + } - ctx.file = file; ctx.symtab = s; - ctx.arena = file_arena; ctx.layouts = layouts; ctx.status = status; + ctx.file = NULL; + ctx.arena = upb_arena_new(); - file->msg_count = 0; - file->enum_count = 0; - file->ext_count = 0; - file->symtab = s; + if (!ctx.arena) { + upb_status_setoom(status); + return NULL; + } if (UPB_UNLIKELY(UPB_SETJMP(ctx.err))) { UPB_ASSERT(!upb_ok(status)); - remove_filedef(s, file); - file = NULL; + if (ctx.file) { + remove_filedef(s, ctx.file); + ctx.file = NULL; + } } else { - build_filedef(&ctx, file, file_proto); - upb_strtable_insert(&s->files, file->name, strlen(file->name), - upb_value_constptr(file), ctx.arena); + ctx.file = symtab_alloc(&ctx, sizeof(*ctx.file)); + build_filedef(&ctx, ctx.file, file_proto); + upb_strtable_insert(&s->files, name.data, name.size, + upb_value_constptr(ctx.file), ctx.arena); UPB_ASSERT(upb_ok(status)); - upb_arena_fuse(s->arena, file_arena); + upb_arena_fuse(s->arena, ctx.arena); } -done: - upb_arena_free(file_arena); - return file; + upb_arena_free(ctx.arena); + return ctx.file; } const upb_filedef *upb_symtab_addfile( @@ -6258,7 +6560,8 @@ bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) { } file = google_protobuf_FileDescriptorProto_parse_ex( - init->descriptor.data, init->descriptor.size, arena, UPB_DECODE_ALIAS); + init->descriptor.data, init->descriptor.size, NULL, UPB_DECODE_ALIAS, + arena); s->bytes_loaded += init->descriptor.size; if (!file) { @@ -8388,7 +8691,17 @@ static void jsonenc_double(jsonenc *e, const char *fmt, double val) { } else if (val != val) { jsonenc_putstr(e, "\"NaN\""); } else { + char *p = e->ptr; jsonenc_printf(e, fmt, val); + + /* printf() is dependent on locales; sadly there is no easy and portable way + * to avoid this. This little post-processing step will translate 1,2 -> 1.2 + * since JSON needs the latter. Arguably a hack, but it is simple and the + * alternatives are far more complicated, platform-dependent, and/or larger + * in code size. */ + for (char *end = e->ptr; p < end; p++) { + if (*p == ',') *p = '.'; + } } } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 68d6345fc508..40072772b2fa 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -636,6 +636,48 @@ void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, /* Returns a reference to the message's unknown data. */ const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); +/** upb_extreg *******************************************************************/ + +/* Extension registry: a dynamic data structure that stores a map of: + * (upb_msglayout, number) -> extension info + * + * upb_decode() uses upb_extreg to look up extensions while parsing binary + * format. + * + * upb_extreg is part of the mini-table (msglayout) family of objects. Like all + * mini-table objects, it is suitable for reflection-less builds that do not + * want to expose names into the binary. + * + * Unlike most mini-table types, upb_extreg requires dynamic memory allocation + * and dynamic initialization: + * * If reflection is being used, then upb_symtab will construct an appropriate + * upb_extreg automatically. + * * For a mini-table only build, the user must manually construct the + * upb_extreg and populate it with all of the extensions the user cares about. + * * A third alternative is to manually unpack relevant extensions after the + * main parse is complete, similar to how Any works. This is perhaps the + * nicest solution from the perspective of reducing dependencies, avoiding + * dynamic memory allocation, and avoiding the need to parse uninteresting + * extensions. The downsides are: + * (1) parse errors are not caught during the main parse + * (2) the CPU hit of parsing comes during access, which could cause an + * undesirable stutter in application performance. + * + * Users cannot directly get or put into this map. Users can only add the + * extensions from a generated module and pass the extension registry to the + * binary decoder. + * + * A upb_symtab provides a upb_extreg, so any users who use reflection do not + * need to populate a upb_extreg directly. + */ + +struct upb_extreg; +typedef struct upb_extreg upb_extreg; + +/* Creates a upb_extreg in the given arena. The arena must outlive any use of + * the extreg. */ +upb_extreg *upb_extreg_new(upb_arena *arena); + #ifdef __cplusplus } /* extern "C" */ #endif @@ -657,12 +699,13 @@ enum { #define UPB_DECODE_MAXDEPTH(depth) ((depth) << 16) bool _upb_decode(const char *buf, size_t size, upb_msg *msg, - const upb_msglayout *l, upb_arena *arena, int options); + const upb_msglayout *l, const upb_extreg *extreg, int options, + upb_arena *arena); UPB_INLINE bool upb_decode(const char *buf, size_t size, upb_msg *msg, const upb_msglayout *l, upb_arena *arena) { - return _upb_decode(buf, size, msg, l, arena, 0); + return _upb_decode(buf, size, msg, l, NULL, 0, arena); } #ifdef __cplusplus @@ -836,6 +879,10 @@ typedef struct upb_tabval { /* upb_table ******************************************************************/ +uint64_t Wyhash(const void *data, size_t len, uint64_t seed, + const uint64_t salt[]); +extern const uint64_t kWyhashSalt[5]; + typedef struct _upb_tabent { upb_tabkey key; upb_tabval val; @@ -1047,9 +1094,34 @@ typedef struct { int16_t presence; /* If >0, hasbit_index. If <0, ~oneof_index. */ uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */ uint8_t descriptortype; - uint8_t label; /* google.protobuf.Label or _UPB_LABEL_* above. */ + int8_t mode; /* upb_fieldmode, with flags from upb_labelflags */ } upb_msglayout_field; +typedef enum { + _UPB_MODE_MAP = 0, + _UPB_MODE_ARRAY = 1, + _UPB_MODE_SCALAR = 2, +} upb_fieldmode; + +/* Extra flags on the mode field. */ +enum upb_labelflags { + _UPB_MODE_IS_PACKED = 4, +}; + +UPB_INLINE upb_fieldmode _upb_getmode(const upb_msglayout_field *field) { + return (upb_fieldmode)(field->mode & 3); +} + +UPB_INLINE bool _upb_repeated_or_map(const upb_msglayout_field *field) { + /* This works because upb_fieldmode has no value 3. */ + return !(field->mode & _UPB_MODE_SCALAR); +} + +UPB_INLINE bool _upb_issubmsg(const upb_msglayout_field *field) { + return field->descriptortype == UPB_DTYPE_MESSAGE || + field->descriptortype == UPB_DTYPE_GROUP; +} + struct upb_decstate; struct upb_msglayout; @@ -1070,27 +1142,65 @@ struct upb_msglayout { uint16_t size; uint16_t field_count; bool extendable; + uint8_t dense_below; uint8_t table_mask; /* To constant-initialize the tables of variable length, we need a flexible * array member, and we need to compile in C99 mode. */ _upb_fasttable_entry fasttable[]; }; +typedef struct { + upb_msglayout_field field; + const upb_msglayout *extendee; + const upb_msglayout *submsg; /* NULL for non-submessage fields. */ +} upb_msglayout_ext; + +/** upb_extreg ****************************************************************/ + +/* Adds the given extension info for message type |l| and field number |num| + * into the registry. Returns false if this message type and field number were + * already in the map, or if memory allocation fails. */ +bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext *e, size_t count); + +/* Looks up the extension (if any) defined for message type |l| and field + * number |num|. If an extension was found, copies the field info into |*ext| + * and returns true. Otherwise returns false. */ +const upb_msglayout_field *_upb_extreg_get(const upb_extreg *r, + const upb_msglayout *l, + uint32_t num); + /** upb_msg *******************************************************************/ -/* Internal members of a upb_msg. We can change this without breaking binary - * compatibility. We put these before the user's data. The user's upb_msg* - * points after the upb_msg_internal. */ +/* Internal members of a upb_msg that track unknown fields and/or extensions. + * We can change this without breaking binary compatibility. We put these + * before the user's data. The user's upb_msg* points after the + * upb_msg_internal. */ typedef struct { - uint32_t len; + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_msg_ext) */ uint32_t size; - /* Data follows. */ -} upb_msg_unknowndata; -/* Used when a message is not extendable. */ + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = sizeof(upb_msg_internaldata) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_msg_internaldata)]; */ +} upb_msg_internaldata; + typedef struct { - upb_msg_unknowndata *unknown; + upb_msg_internaldata *internal; } upb_msg_internal; /* Maps upb_fieldtype_t -> memory size. */ @@ -1129,6 +1239,35 @@ void _upb_msg_discardunknown_shallow(upb_msg *msg); bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, upb_arena *arena); +/** upb_msg_ext ***************************************************************/ + +/* The internal representation of an extension is self-describing: it contains + * enough information that we can serialize it to binary format without needing + * to look it up in a registry. */ +typedef struct { + const upb_msglayout_ext *ext; + union { + upb_strview str; + void *ptr; + double dbl; + char scalar_data[8]; + } data; +} upb_msg_ext; + +/* Adds the given extension data to the given message. The returned extension will + * have its "ext" member initialized according to |ext|. */ +upb_msg_ext *_upb_msg_getorcreateext(upb_msg *msg, const upb_msglayout_ext *ext, + upb_arena *arena); + +/* Returns an array of extensions for this message. Note: the array is + * ordered in reverse relative to the order of creation. */ +const upb_msg_ext *_upb_msg_getexts(const upb_msg *msg, size_t *count); + +/* Returns an extension for the given field number, or NULL if no extension + * exists for this field number. */ +const upb_msg_ext *_upb_msg_getext(const upb_msg *msg, + const upb_msglayout_ext *ext); + /** Hasbit access *************************************************************/ UPB_INLINE bool _upb_hasbit(const upb_msg *msg, size_t idx) { @@ -1192,14 +1331,6 @@ UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_msg *msg, size_t ofs) { return *UPB_PTR_AT(msg, ofs, const upb_msg*) != NULL; } -UPB_INLINE bool _upb_isrepeated(const upb_msglayout_field *field) { - return (field->label & 3) == UPB_LABEL_REPEATED; -} - -UPB_INLINE bool _upb_repeated_or_map(const upb_msglayout_field *field) { - return field->label >= UPB_LABEL_REPEATED; -} - /** upb_array *****************************************************************/ /* Our internal representation for repeated fields. */ @@ -2121,13 +2252,19 @@ UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_ UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len); @@ -2158,13 +2295,19 @@ UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorPr UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len); @@ -2321,13 +2464,19 @@ UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new( UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len); @@ -2480,13 +2629,19 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_Descr UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len); @@ -2529,13 +2684,19 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_Descri UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len); @@ -2563,13 +2724,19 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRange UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len); @@ -2600,13 +2767,19 @@ UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptor UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len); @@ -2697,13 +2870,19 @@ UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptor UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len); @@ -2740,13 +2919,19 @@ UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorPr UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len); @@ -2824,13 +3009,19 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobu UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len); @@ -2858,13 +3049,19 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDe UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len); @@ -2907,13 +3104,19 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescri UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len); @@ -2965,13 +3168,19 @@ UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescript UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len); @@ -3032,13 +3241,19 @@ UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_aren UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len); @@ -3189,13 +3404,19 @@ UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(up UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len); @@ -3250,13 +3471,19 @@ UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_ar UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len); @@ -3323,13 +3550,19 @@ UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_ar UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len); @@ -3360,13 +3593,19 @@ UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_aren UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len); @@ -3409,13 +3648,19 @@ UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_ne UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len); @@ -3452,13 +3697,19 @@ UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(up UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len); @@ -3495,13 +3746,19 @@ UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_ UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len); @@ -3544,13 +3801,19 @@ UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOpt UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len); @@ -3617,13 +3880,19 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_Uninter UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len); @@ -3651,13 +3920,19 @@ UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(up UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len); @@ -3688,13 +3963,19 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeIn UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len); @@ -3755,13 +4036,19 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_ UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len); @@ -3792,13 +4079,19 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_Generat UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse(const char *buf, size_t size, upb_arena *arena) { google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena)) ? ret : NULL; + if (!ret) return NULL; + if (!upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena)) return NULL; + return ret; } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse_ex(const char *buf, size_t size, - upb_arena *arena, int options) { + const upb_extreg *extreg, int options, + upb_arena *arena) { google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); - return (ret && _upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, options)) - ? ret : NULL; + if (!ret) return NULL; + if (!_upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, extreg, options, arena)) { + return NULL; + } + return ret; } UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) { return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len); diff --git a/ruby/lib/google/protobuf/descriptor_dsl.rb b/ruby/lib/google/protobuf/descriptor_dsl.rb index 3c1b8e41d07a..ba1a255f0423 100644 --- a/ruby/lib/google/protobuf/descriptor_dsl.rb +++ b/ruby/lib/google/protobuf/descriptor_dsl.rb @@ -7,7 +7,24 @@ module Google module Protobuf module Internal + class AtomicCounter + def initialize + @n = 0 + @mu = Mutex.new + end + + def get_and_increment + n = @n + @mu.synchronize { + @n += 1 + } + return n + end + end + class Builder + @@file_number = AtomicCounter.new + def initialize(pool) @pool = pool @default_file = nil # Constructed lazily @@ -42,7 +59,9 @@ def build end private def internal_default_file - @default_file ||= FileBuilder.new(@pool, "ruby_default_file.proto") + number = @@file_number.get_and_increment + filename = "ruby_default_file#{number}.proto" + @default_file ||= FileBuilder.new(@pool, filename) end end diff --git a/third_party/wyhash/LICENSE b/third_party/wyhash/LICENSE deleted file mode 100644 index 471f09f4cfb5..000000000000 --- a/third_party/wyhash/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to - diff --git a/third_party/wyhash/wyhash.h b/third_party/wyhash/wyhash.h deleted file mode 100644 index bb247a9af50d..000000000000 --- a/third_party/wyhash/wyhash.h +++ /dev/null @@ -1,145 +0,0 @@ -/* Copyright 2020 王一 Wang Yi - This is free and unencumbered software released into the public domain. http://unlicense.org/ - See github.com/wangyi-fudan/wyhash/ LICENSE - */ -#ifndef wyhash_final_version -#define wyhash_final_version -//defines that change behavior -#ifndef WYHASH_CONDOM -#define WYHASH_CONDOM 1 //0: read 8 bytes before and after boundaries, dangerous but fastest. 1: normal valid behavior 2: extra protection against entropy loss (probability=2^-63), aka. "blind multiplication" -#endif -#define WYHASH_32BIT_MUM 0 //faster on 32 bit system -//includes -#include -#include -#if defined(_MSC_VER) && defined(_M_X64) - #include - #pragma intrinsic(_umul128) -#endif -#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__) - #define _likely_(x) __builtin_expect(x,1) - #define _unlikely_(x) __builtin_expect(x,0) -#else - #define _likely_(x) (x) - #define _unlikely_(x) (x) -#endif -//mum function -static inline uint64_t _wyrot(uint64_t x) { return (x>>32)|(x<<32); } -static inline void _wymum(uint64_t *A, uint64_t *B){ -#if(WYHASH_32BIT_MUM) - uint64_t hh=(*A>>32)*(*B>>32), hl=(*A>>32)*(unsigned)*B, lh=(unsigned)*A*(*B>>32), ll=(uint64_t)(unsigned)*A*(unsigned)*B; - #if(WYHASH_CONDOM>1) - *A^=_wyrot(hl)^hh; *B^=_wyrot(lh)^ll; - #else - *A=_wyrot(hl)^hh; *B=_wyrot(lh)^ll; - #endif -#elif defined(__SIZEOF_INT128__) - __uint128_t r=*A; r*=*B; - #if(WYHASH_CONDOM>1) - *A^=(uint64_t)r; *B^=(uint64_t)(r>>64); - #else - *A=(uint64_t)r; *B=(uint64_t)(r>>64); - #endif -#elif defined(_MSC_VER) && defined(_M_X64) - #if(WYHASH_CONDOM>1) - uint64_t a, b; - a=_umul128(*A,*B,&b); - *A^=a; *B^=b; - #else - *A=_umul128(*A,*B,B); - #endif -#else - uint64_t ha=*A>>32, hb=*B>>32, la=(uint32_t)*A, lb=(uint32_t)*B, hi, lo; - uint64_t rh=ha*hb, rm0=ha*lb, rm1=hb*la, rl=la*lb, t=rl+(rm0<<32), c=t>32)+(rm1>>32)+c; - #if(WYHASH_CONDOM>1) - *A^=lo; *B^=hi; - #else - *A=lo; *B=hi; - #endif -#endif -} -static inline uint64_t _wymix(uint64_t A, uint64_t B){ _wymum(&A,&B); return A^B; } -//read functions -#ifndef WYHASH_LITTLE_ENDIAN - #if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - #define WYHASH_LITTLE_ENDIAN 1 - #elif defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - #define WYHASH_LITTLE_ENDIAN 0 - #endif -#endif -#if (WYHASH_LITTLE_ENDIAN) -static inline uint64_t _wyr8(const uint8_t *p) { uint64_t v; memcpy(&v, p, 8); return v;} -static inline uint64_t _wyr4(const uint8_t *p) { unsigned v; memcpy(&v, p, 4); return v;} -#elif defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__) -static inline uint64_t _wyr8(const uint8_t *p) { uint64_t v; memcpy(&v, p, 8); return __builtin_bswap64(v);} -static inline uint64_t _wyr4(const uint8_t *p) { unsigned v; memcpy(&v, p, 4); return __builtin_bswap32(v);} -#elif defined(_MSC_VER) -static inline uint64_t _wyr8(const uint8_t *p) { uint64_t v; memcpy(&v, p, 8); return _byteswap_uint64(v);} -static inline uint64_t _wyr4(const uint8_t *p) { unsigned v; memcpy(&v, p, 4); return _byteswap_ulong(v);} -#endif -static inline uint64_t _wyr3(const uint8_t *p, unsigned k) { return (((uint64_t)p[0])<<16)|(((uint64_t)p[k>>1])<<8)|p[k-1];} -//wyhash function -static inline uint64_t _wyfinish16(const uint8_t *p, uint64_t len, uint64_t seed, const uint64_t *secret, uint64_t i){ -#if(WYHASH_CONDOM>0) - uint64_t a, b; - if(_likely_(i<=8)){ - if(_likely_(i>=4)){ a=_wyr4(p); b=_wyr4(p+i-4); } - else if (_likely_(i)){ a=_wyr3(p,i); b=0; } - else a=b=0; - } - else{ a=_wyr8(p); b=_wyr8(p+i-8); } - return _wymix(secret[1]^len,_wymix(a^secret[1], b^seed)); -#else - #define oneshot_shift ((i<8)*((8-i)<<3)) - return _wymix(secret[1]^len,_wymix((_wyr8(p)<>oneshot_shift)^seed)); -#endif -} - -static inline uint64_t _wyfinish(const uint8_t *p, uint64_t len, uint64_t seed, const uint64_t *secret, uint64_t i){ - if(_likely_(i<=16)) return _wyfinish16(p,len,seed,secret,i); - return _wyfinish(p+16,len,_wymix(_wyr8(p)^secret[1],_wyr8(p+8)^seed),secret,i-16); -} - -static inline uint64_t wyhash(const void *key, uint64_t len, uint64_t seed, const uint64_t *secret){ - const uint8_t *p=(const uint8_t *)key; - uint64_t i=len; seed^=*secret; - if(_unlikely_(i>64)){ - uint64_t see1=seed; - do{ - seed=_wymix(_wyr8(p)^secret[1],_wyr8(p+8)^seed)^_wymix(_wyr8(p+16)^secret[2],_wyr8(p+24)^seed); - see1=_wymix(_wyr8(p+32)^secret[3],_wyr8(p+40)^see1)^_wymix(_wyr8(p+48)^secret[4],_wyr8(p+56)^see1); - p+=64; i-=64; - }while(i>64); - seed^=see1; - } - return _wyfinish(p,len,seed,secret,i); -} -//utility functions -static const uint64_t _wyp[5] = {0xa0761d6478bd642full, 0xe7037ed1a0b428dbull, 0x8ebc6af09c88c6e3ull, 0x589965cc75374cc3ull, 0x1d8e4e27c47d124full}; -static inline uint64_t wyhash64(uint64_t A, uint64_t B){ A^=_wyp[0]; B^=_wyp[1]; _wymum(&A,&B); return _wymix(A^_wyp[0],B^_wyp[1]);} -static inline uint64_t wyrand(uint64_t *seed){ *seed+=_wyp[0]; return _wymix(*seed,*seed^_wyp[1]);} -static inline double wy2u01(uint64_t r){ const double _wynorm=1.0/(1ull<<52); return (r>>12)*_wynorm;} -static inline double wy2gau(uint64_t r){ const double _wynorm=1.0/(1ull<<20); return ((r&0x1fffff)+((r>>21)&0x1fffff)+((r>>42)&0x1fffff))*_wynorm-3.0;} -static inline uint64_t wy2u0k(uint64_t r, uint64_t k){ _wymum(&r,&k); return k; } - -static inline void make_secret(uint64_t seed, uint64_t *secret){ - uint8_t c[] = {15, 23, 27, 29, 30, 39, 43, 45, 46, 51, 53, 54, 57, 58, 60, 71, 75, 77, 78, 83, 85, 86, 89, 90, 92, 99, 101, 102, 105, 106, 108, 113, 114, 116, 120, 135, 139, 141, 142, 147, 149, 150, 153, 154, 156, 163, 165, 166, 169, 170, 172, 177, 178, 180, 184, 195, 197, 198, 201, 202, 204, 209, 210, 212, 216, 225, 226, 228, 232, 240 }; - for(size_t i=0;i<5;i++){ - uint8_t ok; - do{ - ok=1; secret[i]=0; - for(size_t j=0;j<64;j+=8) secret[i]|=((uint64_t)c[wyrand(&seed)%sizeof(c)])<