Merge pull request #762 from Wyverald:patch-1
PiperOrigin-RevId: 473026273
diff --git a/BUILD b/BUILD
index a49327b..68cd345 100644
--- a/BUILD
+++ b/BUILD
@@ -412,10 +412,10 @@
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
+ ":collections",
":encode_internal",
":port",
":reflection",
- ":table_internal",
],
)
@@ -433,6 +433,7 @@
visibility = ["//visibility:public"],
deps = [
":atoi_internal",
+ ":collections",
":encode_internal",
":port",
":reflection",
@@ -512,8 +513,22 @@
)
cc_test(
- name = "json_test",
- srcs = ["upb/json_test.cc"],
+ name = "json_decode_test",
+ srcs = ["upb/json_decode_test.cc"],
+ deps = [
+ ":json",
+ ":json_test_upb_proto",
+ ":json_test_upb_proto_reflection",
+ ":reflection",
+ ":struct_upb_proto",
+ ":upb",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+
+cc_test(
+ name = "json_encode_test",
+ srcs = ["upb/json_encode_test.cc"],
deps = [
":json",
":json_test_upb_proto",
diff --git a/python/convert.c b/python/convert.c
index 3d9b94a..b9df501 100644
--- a/python/convert.c
+++ b/python/convert.c
@@ -29,6 +29,7 @@
#include "python/message.h"
#include "python/protobuf.h"
+#include "upb/map.h"
#include "upb/reflection.h"
#include "upb/util/compare.h"
diff --git a/python/message.c b/python/message.c
index 47b00e8..e67bf23 100644
--- a/python/message.c
+++ b/python/message.c
@@ -1361,7 +1361,7 @@
}
if (o) f = upb_Message_WhichOneof(self->ptr.msg, o);
- PyUpb_Message_DoClearField(_self, f);
+ if (f) PyUpb_Message_DoClearField(_self, f);
Py_RETURN_NONE;
}
diff --git a/upb/bindings/lua/msg.c b/upb/bindings/lua/msg.c
index 5da2765..9c66c74 100644
--- a/upb/bindings/lua/msg.c
+++ b/upb/bindings/lua/msg.c
@@ -41,6 +41,7 @@
#include "upb/bindings/lua/upb.h"
#include "upb/json_decode.h"
#include "upb/json_encode.h"
+#include "upb/map.h"
#include "upb/port_def.inc"
#include "upb/reflection.h"
#include "upb/text_encode.h"
diff --git a/upb/decode.c b/upb/decode.c
index 2456efa..8ba5c21 100644
--- a/upb/decode.c
+++ b/upb/decode.c
@@ -181,28 +181,31 @@
uint32_t size;
} wireval;
-static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg,
- const upb_MiniTable* layout);
+static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr,
+ upb_Message* msg,
+ const upb_MiniTable* layout);
-UPB_NORETURN static void* decode_err(upb_Decoder* d, upb_DecodeStatus status) {
+UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d,
+ upb_DecodeStatus status) {
assert(status != kUpb_DecodeStatus_Ok);
UPB_LONGJMP(d->err, status);
}
-const char* fastdecode_err(upb_Decoder* d, int status) {
+const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) {
assert(status != kUpb_DecodeStatus_Ok);
UPB_LONGJMP(d->err, status);
return NULL;
}
-static void decode_verifyutf8(upb_Decoder* d, const char* buf, int len) {
- if (!decode_verifyutf8_inl(buf, len))
- decode_err(d, kUpb_DecodeStatus_BadUtf8);
+static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) {
+ if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8);
+ }
}
-static bool decode_reserve(upb_Decoder* d, upb_Array* arr, size_t elem) {
+static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) {
bool need_realloc = arr->capacity - arr->size < elem;
if (need_realloc && !_upb_array_realloc(arr, arr->size + elem, &d->arena)) {
- decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
return need_realloc;
}
@@ -210,11 +213,12 @@
typedef struct {
const char* ptr;
uint64_t val;
-} decode_vret;
+} _upb_DecodeLongVarintReturn;
UPB_NOINLINE
-static decode_vret decode_longvarint64(const char* ptr, uint64_t val) {
- decode_vret ret = {NULL, 0};
+static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint(
+ const char* ptr, uint64_t val) {
+ _upb_DecodeLongVarintReturn ret = {NULL, 0};
uint64_t byte;
int i;
for (i = 1; i < 10; i++) {
@@ -230,31 +234,32 @@
}
UPB_FORCEINLINE
-static const char* decode_varint64(upb_Decoder* d, const char* ptr,
- uint64_t* val) {
+static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
+ uint64_t* val) {
uint64_t byte = (uint8_t)*ptr;
if (UPB_LIKELY((byte & 0x80) == 0)) {
*val = byte;
return ptr + 1;
} else {
- decode_vret res = decode_longvarint64(ptr, byte);
- if (!res.ptr) return decode_err(d, kUpb_DecodeStatus_Malformed);
+ _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte);
+ if (!res.ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
*val = res.val;
return res.ptr;
}
}
UPB_FORCEINLINE
-static const char* decode_tag(upb_Decoder* d, const char* ptr, uint32_t* val) {
+static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
+ uint32_t* val) {
uint64_t byte = (uint8_t)*ptr;
if (UPB_LIKELY((byte & 0x80) == 0)) {
*val = byte;
return ptr + 1;
} else {
const char* start = ptr;
- decode_vret res = decode_longvarint64(ptr, byte);
+ _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte);
if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) {
- return decode_err(d, kUpb_DecodeStatus_Malformed);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
}
*val = res.val;
return res.ptr;
@@ -265,22 +270,22 @@
static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr,
uint32_t* size) {
uint64_t size64;
- ptr = decode_varint64(d, ptr, &size64);
+ ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64);
if (size64 >= INT32_MAX || ptr - d->end + (int)size64 > d->limit) {
- decode_err(d, kUpb_DecodeStatus_Malformed);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
}
*size = size64;
return ptr;
}
-static void decode_munge_int32(wireval* val) {
+static void _upb_Decoder_MungeInt32(wireval* val) {
if (!_upb_IsLittleEndian()) {
/* The next stage will memcpy(dst, &val, 4) */
val->uint32_val = val->uint64_val;
}
}
-static void decode_munge(int type, wireval* val) {
+static void _upb_Decoder_Munge(int type, wireval* val) {
switch (type) {
case kUpb_FieldType_Bool:
val->bool_val = val->uint64_val != 0;
@@ -298,38 +303,36 @@
case kUpb_FieldType_Int32:
case kUpb_FieldType_UInt32:
case kUpb_FieldType_Enum:
- decode_munge_int32(val);
+ _upb_Decoder_MungeInt32(val);
break;
}
}
-static upb_Message* decode_newsubmsg(upb_Decoder* d,
- const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field) {
+static upb_Message* _upb_Decoder_NewSubMessage(
+ upb_Decoder* d, const upb_MiniTable_Sub* subs,
+ const upb_MiniTable_Field* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
upb_Message* msg = _upb_Message_New_inl(subl, &d->arena);
- if (!msg) decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
return msg;
}
UPB_NOINLINE
-const char* decode_isdonefallback(upb_Decoder* d, const char* ptr,
- int overrun) {
+const char* _upb_Decoder_IsDoneFallback(upb_Decoder* d, const char* ptr,
+ int overrun) {
int status;
- ptr = decode_isdonefallback_inl(d, ptr, overrun, &status);
- if (ptr == NULL) {
- return decode_err(d, status);
- }
+ ptr = _upb_Decoder_IsDoneFallbackInline(d, ptr, overrun, &status);
+ if (ptr == NULL) _upb_Decoder_ErrorJmp(d, status);
return ptr;
}
-static const char* decode_readstr(upb_Decoder* d, const char* ptr, int size,
- upb_StringView* str) {
+static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr,
+ int size, upb_StringView* str) {
if (d->options & kUpb_DecodeOption_AliasString) {
str->data = ptr;
} else {
char* data = upb_Arena_Malloc(&d->arena, size);
- if (!data) return decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ if (!data) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
memcpy(data, ptr, size);
str->data = data;
}
@@ -338,50 +341,56 @@
}
UPB_FORCEINLINE
-static const char* decode_tosubmsg2(upb_Decoder* d, const char* ptr,
- upb_Message* submsg,
- const upb_MiniTable* subl, int size) {
- int saved_delta = decode_pushlimit(d, ptr, size);
- if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded);
- ptr = decode_msg(d, ptr, submsg, subl);
- if (d->end_group != DECODE_NOGROUP)
- return decode_err(d, kUpb_DecodeStatus_Malformed);
- decode_poplimit(d, ptr, saved_delta);
+static const char* _upb_Decoder_DecodeSubMessage(
+ upb_Decoder* d, const char* ptr, upb_Message* submsg,
+ const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) {
+ int saved_delta = _upb_Decoder_PushLimit(d, ptr, size);
+ const upb_MiniTable* subl = subs[field->submsg_index].submsg;
+ if (--d->depth < 0) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded);
+ }
+ ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl);
+ if (d->end_group != DECODE_NOGROUP) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
+ }
+ _upb_Decoder_PopLimit(d, ptr, saved_delta);
d->depth++;
return ptr;
}
UPB_FORCEINLINE
-static const char* decode_tosubmsg(upb_Decoder* d, const char* ptr,
- upb_Message* submsg,
- const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field, int size) {
- return decode_tosubmsg2(d, ptr, submsg, subs[field->submsg_index].submsg,
- size);
-}
-
-UPB_FORCEINLINE
-static const char* decode_group(upb_Decoder* d, const char* ptr,
- upb_Message* submsg, const upb_MiniTable* subl,
- uint32_t number) {
- if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded);
- if (decode_isdone(d, &ptr)) {
- return decode_err(d, kUpb_DecodeStatus_Malformed);
+static const char* _upb_Decoder_DoDecodeGroup(upb_Decoder* d, const char* ptr,
+ upb_Message* submsg,
+ const upb_MiniTable* subl,
+ uint32_t number) {
+ if (--d->depth < 0) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded);
}
- ptr = decode_msg(d, ptr, submsg, subl);
- if (d->end_group != number) return decode_err(d, kUpb_DecodeStatus_Malformed);
+ if (_upb_Decoder_IsDone(d, &ptr)) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
+ }
+ ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl);
+ if (d->end_group != number) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
+ }
d->end_group = DECODE_NOGROUP;
d->depth++;
return ptr;
}
UPB_FORCEINLINE
-static const char* decode_togroup(upb_Decoder* d, const char* ptr,
- upb_Message* submsg,
- const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field) {
+static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d,
+ const char* ptr,
+ uint32_t number) {
+ return _upb_Decoder_DoDecodeGroup(d, ptr, NULL, NULL, number);
+}
+
+UPB_FORCEINLINE
+static const char* _upb_Decoder_DecodeKnownGroup(
+ upb_Decoder* d, const char* ptr, upb_Message* submsg,
+ const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
- return decode_group(d, ptr, submsg, subl, field->number);
+ return _upb_Decoder_DoDecodeGroup(d, ptr, submsg, subl, field->number);
}
static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) {
@@ -394,23 +403,24 @@
return ptr;
}
-static void upb_Decode_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
- uint32_t val1, uint32_t val2) {
+static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
+ uint32_t val1, uint32_t val2) {
char buf[20];
char* end = buf;
end = upb_Decoder_EncodeVarint32(val1, end);
end = upb_Decoder_EncodeVarint32(val2, end);
if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) {
- decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
}
UPB_NOINLINE
-static bool decode_checkenum_slow(upb_Decoder* d, const char* ptr,
- upb_Message* msg, const upb_MiniTable_Enum* e,
- const upb_MiniTable_Field* field,
- uint32_t v) {
+static bool _upb_Decoder_CheckEnumSlow(upb_Decoder* d, const char* ptr,
+ upb_Message* msg,
+ const upb_MiniTable_Enum* e,
+ const upb_MiniTable_Field* field,
+ uint32_t v) {
// OPT: binary search long lists?
int n = e->value_count;
for (int i = 0; i < n; i++) {
@@ -423,29 +433,30 @@
uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint;
upb_Message* unknown_msg =
field->mode & kUpb_LabelFlags_IsExtension ? d->unknown_msg : msg;
- upb_Decode_AddUnknownVarints(d, unknown_msg, tag, v);
+ _upb_Decoder_AddUnknownVarints(d, unknown_msg, tag, v);
return false;
}
UPB_FORCEINLINE
-static bool decode_checkenum(upb_Decoder* d, const char* ptr, upb_Message* msg,
- const upb_MiniTable_Enum* e,
- const upb_MiniTable_Field* field, wireval* val) {
+static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr,
+ upb_Message* msg,
+ const upb_MiniTable_Enum* e,
+ const upb_MiniTable_Field* field,
+ wireval* val) {
uint32_t v = val->uint32_val;
if (UPB_LIKELY(v < 64) && UPB_LIKELY(((1ULL << v) & e->mask))) return true;
- return decode_checkenum_slow(d, ptr, msg, e, field, v);
+ return _upb_Decoder_CheckEnumSlow(d, ptr, msg, e, field, v);
}
UPB_NOINLINE
-static const char* decode_enum_toarray(upb_Decoder* d, const char* ptr,
- upb_Message* msg, upb_Array* arr,
- const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field,
- wireval* val) {
+static const char* _upb_Decoder_DecodeEnumArray(
+ upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr,
+ const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field,
+ wireval* val) {
const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum;
- if (!decode_checkenum(d, ptr, msg, e, field, val)) return ptr;
+ if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr;
void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void);
arr->size++;
memcpy(mem, val, 4);
@@ -453,17 +464,16 @@
}
UPB_FORCEINLINE
-static const char* decode_fixed_packed(upb_Decoder* d, const char* ptr,
- upb_Array* arr, wireval* val,
- const upb_MiniTable_Field* field,
- int lg2) {
+static const char* _upb_Decoder_DecodeFixedPacked(
+ upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val,
+ const upb_MiniTable_Field* field, int lg2) {
int mask = (1 << lg2) - 1;
size_t count = val->size >> lg2;
if ((val->size & mask) != 0) {
// Length isn't a round multiple of elem size.
- return decode_err(d, kUpb_DecodeStatus_Malformed);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
}
- decode_reserve(d, arr, count);
+ _upb_Decoder_Reserve(d, arr, count);
void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void);
arr->size += count;
// Note: if/when the decoder supports multi-buffer input, we will need to
@@ -496,70 +506,68 @@
}
UPB_FORCEINLINE
-static const char* decode_varint_packed(upb_Decoder* d, const char* ptr,
- upb_Array* arr, wireval* val,
- const upb_MiniTable_Field* field,
- int lg2) {
+static const char* _upb_Decoder_DecodeVarintPacked(
+ upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val,
+ const upb_MiniTable_Field* field, int lg2) {
int scale = 1 << lg2;
- int saved_limit = decode_pushlimit(d, ptr, val->size);
+ int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size);
char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void);
- while (!decode_isdone(d, &ptr)) {
+ while (!_upb_Decoder_IsDone(d, &ptr)) {
wireval elem;
- ptr = decode_varint64(d, ptr, &elem.uint64_val);
- decode_munge(field->descriptortype, &elem);
- if (decode_reserve(d, arr, 1)) {
+ ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val);
+ _upb_Decoder_Munge(field->descriptortype, &elem);
+ if (_upb_Decoder_Reserve(d, arr, 1)) {
out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void);
}
arr->size++;
memcpy(out, &elem, scale);
out += scale;
}
- decode_poplimit(d, ptr, saved_limit);
+ _upb_Decoder_PopLimit(d, ptr, saved_limit);
return ptr;
}
UPB_NOINLINE
-static const char* decode_enum_packed(upb_Decoder* d, const char* ptr,
- upb_Message* msg, upb_Array* arr,
- const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field,
- wireval* val) {
+static const char* _upb_Decoder_DecodeEnumPacked(
+ upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr,
+ const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field,
+ wireval* val) {
const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum;
- int saved_limit = decode_pushlimit(d, ptr, val->size);
+ int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size);
char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void);
- while (!decode_isdone(d, &ptr)) {
+ while (!_upb_Decoder_IsDone(d, &ptr)) {
wireval elem;
- ptr = decode_varint64(d, ptr, &elem.uint64_val);
- decode_munge_int32(&elem);
- if (!decode_checkenum(d, ptr, msg, e, field, &elem)) {
+ ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val);
+ _upb_Decoder_MungeInt32(&elem);
+ if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, &elem)) {
continue;
}
- if (decode_reserve(d, arr, 1)) {
+ if (_upb_Decoder_Reserve(d, arr, 1)) {
out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void);
}
arr->size++;
memcpy(out, &elem, 4);
out += 4;
}
- decode_poplimit(d, ptr, saved_limit);
+ _upb_Decoder_PopLimit(d, ptr, saved_limit);
return ptr;
}
-static const char* decode_toarray(upb_Decoder* d, const char* ptr,
- upb_Message* msg,
- const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field,
- wireval* val, int op) {
+static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr,
+ upb_Message* msg,
+ const upb_MiniTable_Sub* subs,
+ const upb_MiniTable_Field* field,
+ wireval* val, int op) {
upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void);
upb_Array* arr = *arrp;
void* mem;
if (arr) {
- decode_reserve(d, arr, 1);
+ _upb_Decoder_Reserve(d, arr, 1);
} else {
size_t lg2 = desctype_to_elem_size_lg2[field->descriptortype];
arr = _upb_Array_New(&d->arena, 4, lg2);
- if (!arr) return decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ if (!arr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
*arrp = arr;
}
@@ -573,48 +581,50 @@
memcpy(mem, val, 1 << op);
return ptr;
case OP_STRING:
- decode_verifyutf8(d, ptr, val->size);
+ _upb_Decoder_VerifyUtf8(d, ptr, val->size);
/* Fallthrough. */
case OP_BYTES: {
/* Append bytes. */
upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->size;
arr->size++;
- return decode_readstr(d, ptr, val->size, str);
+ return _upb_Decoder_ReadString(d, ptr, val->size, str);
}
case OP_SUBMSG: {
/* Append submessage / group. */
- upb_Message* submsg = decode_newsubmsg(d, subs, field);
+ upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field);
*UPB_PTR_AT(_upb_array_ptr(arr), arr->size * sizeof(void*),
upb_Message*) = submsg;
arr->size++;
if (UPB_UNLIKELY(field->descriptortype == kUpb_FieldType_Group)) {
- return decode_togroup(d, ptr, submsg, subs, field);
+ return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field);
} else {
- return decode_tosubmsg(d, ptr, submsg, subs, field, val->size);
+ return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field,
+ val->size);
}
}
case OP_FIXPCK_LG2(2):
case OP_FIXPCK_LG2(3):
- return decode_fixed_packed(d, ptr, arr, val, field,
- op - OP_FIXPCK_LG2(0));
+ return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field,
+ op - OP_FIXPCK_LG2(0));
case OP_VARPCK_LG2(0):
case OP_VARPCK_LG2(2):
case OP_VARPCK_LG2(3):
- return decode_varint_packed(d, ptr, arr, val, field,
- op - OP_VARPCK_LG2(0));
+ return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field,
+ op - OP_VARPCK_LG2(0));
case OP_ENUM:
- return decode_enum_toarray(d, ptr, msg, arr, subs, field, val);
+ return _upb_Decoder_DecodeEnumArray(d, ptr, msg, arr, subs, field, val);
case OP_PACKED_ENUM:
- return decode_enum_packed(d, ptr, msg, arr, subs, field, val);
+ return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, subs, field, val);
default:
UPB_UNREACHABLE();
}
}
-static const char* decode_tomap(upb_Decoder* d, const char* ptr,
- upb_Message* msg, const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field,
- wireval* val) {
+static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
+ upb_Message* msg,
+ const upb_MiniTable_Sub* subs,
+ const upb_MiniTable_Field* field,
+ wireval* val) {
upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*);
upb_Map* map = *map_p;
upb_MapEntry ent;
@@ -643,35 +653,35 @@
}
const char* start = ptr;
- ptr = decode_tosubmsg(d, ptr, &ent.k, subs, field, val->size);
+ ptr = _upb_Decoder_DecodeSubMessage(d, ptr, &ent.k, subs, field, val->size);
// check if ent had any unknown fields
size_t size;
upb_Message_GetUnknown(&ent.k, &size);
if (size != 0) {
uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited;
- upb_Decode_AddUnknownVarints(d, msg, tag, (uint32_t)(ptr - start));
+ _upb_Decoder_AddUnknownVarints(d, msg, tag, (uint32_t)(ptr - start));
if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) {
- decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
} else {
if (_upb_Map_Insert(map, &ent.k, map->key_size, &ent.v, map->val_size,
&d->arena) == _kUpb_MapInsertStatus_OutOfMemory) {
- decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
}
return ptr;
}
-static const char* decode_tomsg(upb_Decoder* d, const char* ptr,
- upb_Message* msg, const upb_MiniTable_Sub* subs,
- const upb_MiniTable_Field* field, wireval* val,
- int op) {
+static const char* _upb_Decoder_DecodeToSubMessage(
+ upb_Decoder* d, const char* ptr, upb_Message* msg,
+ const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field,
+ wireval* val, int op) {
void* mem = UPB_PTR_AT(msg, field->offset, void);
int type = field->descriptortype;
if (UPB_UNLIKELY(op == OP_ENUM) &&
- !decode_checkenum(d, ptr, msg, subs[field->submsg_index].subenum, field,
- val)) {
+ !_upb_Decoder_CheckEnum(d, ptr, msg, subs[field->submsg_index].subenum,
+ field, val)) {
return ptr;
}
@@ -693,21 +703,22 @@
upb_Message** submsgp = mem;
upb_Message* submsg = *submsgp;
if (!submsg) {
- submsg = decode_newsubmsg(d, subs, field);
+ submsg = _upb_Decoder_NewSubMessage(d, subs, field);
*submsgp = submsg;
}
if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) {
- ptr = decode_togroup(d, ptr, submsg, subs, field);
+ ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field);
} else {
- ptr = decode_tosubmsg(d, ptr, submsg, subs, field, val->size);
+ ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field,
+ val->size);
}
break;
}
case OP_STRING:
- decode_verifyutf8(d, ptr, val->size);
+ _upb_Decoder_VerifyUtf8(d, ptr, val->size);
/* Fallthrough. */
case OP_BYTES:
- return decode_readstr(d, ptr, val->size, mem);
+ return _upb_Decoder_ReadString(d, ptr, val->size, mem);
case OP_SCALAR_LG2(3):
memcpy(mem, val, 8);
break;
@@ -726,9 +737,9 @@
}
UPB_NOINLINE
-const char* decode_checkrequired(upb_Decoder* d, const char* ptr,
- const upb_Message* msg,
- const upb_MiniTable* l) {
+const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
+ const upb_Message* msg,
+ const upb_MiniTable* l) {
assert(l->required_count);
if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) {
return ptr;
@@ -743,14 +754,14 @@
}
UPB_FORCEINLINE
-static bool decode_tryfastdispatch(upb_Decoder* d, const char** ptr,
- upb_Message* msg,
- const upb_MiniTable* layout) {
+static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr,
+ upb_Message* msg,
+ const upb_MiniTable* layout) {
#if UPB_FASTTABLE
if (layout && layout->table_mask != (unsigned char)-1) {
- uint16_t tag = fastdecode_loadtag(*ptr);
+ uint16_t tag = _upb_FastDecoder_LoadTag(*ptr);
intptr_t table = decode_totable(layout);
- *ptr = fastdecode_tagdispatch(d, *ptr, msg, table, 0, tag);
+ *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag);
return true;
}
#endif
@@ -764,7 +775,7 @@
switch (wire_type) {
case kUpb_WireType_Varint: {
uint64_t val;
- return decode_varint64(d, ptr, &val);
+ return _upb_Decoder_DecodeVarint(d, ptr, &val);
}
case kUpb_WireType_64Bit:
return ptr + 8;
@@ -776,9 +787,9 @@
return ptr + size;
}
case kUpb_WireType_StartGroup:
- return decode_group(d, ptr, NULL, NULL, field_number);
+ return _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number);
default:
- decode_err(d, kUpb_DecodeStatus_Malformed);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
}
}
@@ -794,12 +805,15 @@
const char* data, uint32_t size) {
upb_Message_Extension* ext =
_upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena);
- if (UPB_UNLIKELY(!ext)) decode_err(d, kUpb_DecodeStatus_OutOfMemory);
- upb_Message* submsg = decode_newsubmsg(d, &ext->ext->sub, &ext->ext->field);
+ if (UPB_UNLIKELY(!ext)) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
+ }
+ upb_Message* submsg =
+ _upb_Decoder_NewSubMessage(d, &ext->ext->sub, &ext->ext->field);
upb_DecodeStatus status = upb_Decode(data, size, submsg, item_mt->sub.submsg,
d->extreg, d->options, &d->arena);
memcpy(&ext->data, &submsg, sizeof(submsg));
- if (status != kUpb_DecodeStatus_Ok) decode_err(d, status);
+ if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status);
}
static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d,
@@ -822,7 +836,7 @@
if (!_upb_Message_AddUnknown(msg, buf, split - buf, &d->arena) ||
!_upb_Message_AddUnknown(msg, message_data, message_size, &d->arena) ||
!_upb_Message_AddUnknown(msg, split, end - split, &d->arena)) {
- decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
}
@@ -849,15 +863,15 @@
kUpb_HavePayload = 1 << 1,
} StateMask;
StateMask state_mask = 0;
- while (!decode_isdone(d, &ptr)) {
+ while (!_upb_Decoder_IsDone(d, &ptr)) {
uint32_t tag;
- ptr = decode_tag(d, ptr, &tag);
+ ptr = _upb_Decoder_DecodeTag(d, ptr, &tag);
switch (tag) {
case kEndItemTag:
return ptr;
case kTypeIdTag: {
uint64_t tmp;
- ptr = decode_varint64(d, ptr, &tmp);
+ ptr = _upb_Decoder_DecodeVarint(d, ptr, &tmp);
if (state_mask & kUpb_HaveId) break; // Ignore dup.
state_mask |= kUpb_HaveId;
type_id = tmp;
@@ -889,13 +903,12 @@
break;
}
}
- decode_err(d, kUpb_DecodeStatus_Malformed);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
}
-static const upb_MiniTable_Field* decode_findfield(upb_Decoder* d,
- const upb_MiniTable* l,
- uint32_t field_number,
- int* last_field_index) {
+static const upb_MiniTable_Field* _upb_Decoder_FindField(
+ upb_Decoder* d, const upb_MiniTable* l, uint32_t field_number,
+ int* last_field_index) {
static upb_MiniTable_Field none = {0, 0, 0, 0, 0, 0};
if (l == NULL) return &none;
@@ -948,14 +961,14 @@
}
UPB_FORCEINLINE
-static const char* decode_wireval(upb_Decoder* d, const char* ptr,
- const upb_MiniTable_Field* field,
- int wire_type, wireval* val, int* op) {
+static const char* _upb_Decoder_DecodeWireValue(
+ upb_Decoder* d, const char* ptr, const upb_MiniTable_Field* field,
+ int wire_type, wireval* val, int* op) {
switch (wire_type) {
case kUpb_WireType_Varint:
- ptr = decode_varint64(d, ptr, &val->uint64_val);
+ ptr = _upb_Decoder_DecodeVarint(d, ptr, &val->uint64_val);
*op = varint_ops[field->descriptortype];
- decode_munge(field->descriptortype, val);
+ _upb_Decoder_Munge(field->descriptortype, val);
return ptr;
case kUpb_WireType_32Bit:
memcpy(&val->uint32_val, ptr, 4);
@@ -993,14 +1006,14 @@
default:
break;
}
- return decode_err(d, kUpb_DecodeStatus_Malformed);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
}
UPB_FORCEINLINE
-static const char* decode_known(upb_Decoder* d, const char* ptr,
- upb_Message* msg, const upb_MiniTable* layout,
- const upb_MiniTable_Field* field, int op,
- wireval* val) {
+static const char* _upb_Decoder_DecodeKnownField(
+ upb_Decoder* d, const char* ptr, upb_Message* msg,
+ const upb_MiniTable* layout, const upb_MiniTable_Field* field, int op,
+ wireval* val) {
const upb_MiniTable_Sub* subs = layout->subs;
uint8_t mode = field->mode;
@@ -1009,7 +1022,9 @@
(const upb_MiniTable_Extension*)field;
upb_Message_Extension* ext =
_upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena);
- if (UPB_UNLIKELY(!ext)) return decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ if (UPB_UNLIKELY(!ext)) {
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
+ }
d->unknown_msg = msg;
msg = &ext->data;
subs = &ext->ext->sub;
@@ -1017,17 +1032,18 @@
switch (mode & kUpb_FieldMode_Mask) {
case kUpb_FieldMode_Array:
- return decode_toarray(d, ptr, msg, subs, field, val, op);
+ return _upb_Decoder_DecodeToArray(d, ptr, msg, subs, field, val, op);
case kUpb_FieldMode_Map:
- return decode_tomap(d, ptr, msg, subs, field, val);
+ return _upb_Decoder_DecodeToMap(d, ptr, msg, subs, field, val);
case kUpb_FieldMode_Scalar:
- return decode_tomsg(d, ptr, msg, subs, field, val, op);
+ return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, subs, field, val, op);
default:
UPB_UNREACHABLE();
}
}
-static const char* decode_reverse_skip_varint(const char* ptr, uint32_t val) {
+static const char* _upb_Decoder_ReverseSkipVarint(const char* ptr,
+ uint32_t val) {
uint32_t seen = 0;
do {
ptr--;
@@ -1037,10 +1053,12 @@
return ptr;
}
-static const char* decode_unknown(upb_Decoder* d, const char* ptr,
- upb_Message* msg, int field_number,
- int wire_type, wireval val) {
- if (field_number == 0) return decode_err(d, kUpb_DecodeStatus_Malformed);
+static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d,
+ const char* ptr,
+ upb_Message* msg,
+ int field_number,
+ int wire_type, wireval val) {
+ if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
// Since unknown fields are the uncommon case, we do a little extra work here
// to walk backwards through the buffer to find the field start. This frees
@@ -1068,37 +1086,38 @@
assert(start == d->debug_valstart);
uint32_t tag = ((uint32_t)field_number << 3) | wire_type;
- start = decode_reverse_skip_varint(start, tag);
+ start = _upb_Decoder_ReverseSkipVarint(start, tag);
assert(start == d->debug_tagstart);
if (wire_type == kUpb_WireType_StartGroup) {
d->unknown = start;
d->unknown_msg = msg;
- ptr = decode_group(d, ptr, NULL, NULL, field_number);
+ ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number);
start = d->unknown;
d->unknown = NULL;
}
if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) {
- return decode_err(d, kUpb_DecodeStatus_OutOfMemory);
+ _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
}
} else if (wire_type == kUpb_WireType_StartGroup) {
- ptr = decode_group(d, ptr, NULL, NULL, field_number);
+ ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number);
}
return ptr;
}
UPB_NOINLINE
-static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg,
- const upb_MiniTable* layout) {
+static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr,
+ upb_Message* msg,
+ const upb_MiniTable* layout) {
int last_field_index = 0;
#if UPB_FASTTABLE
// The first time we want to skip fast dispatch, because we may have just been
// invoked by the fast parser to handle a case that it bailed on.
- if (!decode_isdone(d, &ptr)) goto nofast;
+ if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast;
#endif
- while (!decode_isdone(d, &ptr)) {
+ while (!_upb_Decoder_IsDone(d, &ptr)) {
uint32_t tag;
const upb_MiniTable_Field* field;
int field_number;
@@ -1106,7 +1125,7 @@
wireval val;
int op;
- if (decode_tryfastdispatch(d, &ptr, msg, layout)) break;
+ if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break;
#if UPB_FASTTABLE
nofast:
@@ -1117,7 +1136,7 @@
#endif
UPB_ASSERT(ptr < d->limit_ptr);
- ptr = decode_tag(d, ptr, &tag);
+ ptr = _upb_Decoder_DecodeTag(d, ptr, &tag);
field_number = tag >> 3;
wire_type = tag & 7;
@@ -1130,15 +1149,16 @@
return ptr;
}
- field = decode_findfield(d, layout, field_number, &last_field_index);
- ptr = decode_wireval(d, ptr, field, wire_type, &val, &op);
+ field = _upb_Decoder_FindField(d, layout, field_number, &last_field_index);
+ ptr = _upb_Decoder_DecodeWireValue(d, ptr, field, wire_type, &val, &op);
if (op >= 0) {
- ptr = decode_known(d, ptr, msg, layout, field, op, &val);
+ ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val);
} else {
switch (op) {
case OP_UNKNOWN:
- ptr = decode_unknown(d, ptr, msg, field_number, wire_type, val);
+ ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number,
+ wire_type, val);
break;
case OP_MSGSET_ITEM:
ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout);
@@ -1148,22 +1168,24 @@
}
return UPB_UNLIKELY(layout && layout->required_count)
- ? decode_checkrequired(d, ptr, msg, layout)
+ ? _upb_Decoder_CheckRequired(d, ptr, msg, layout)
: ptr;
}
-const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr,
- upb_Message* msg, intptr_t table,
- uint64_t hasbits, uint64_t data) {
+const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d,
+ const char* ptr, upb_Message* msg,
+ intptr_t table, uint64_t hasbits,
+ uint64_t data) {
(void)data;
*(uint32_t*)msg |= hasbits;
- return decode_msg(d, ptr, msg, decode_totablep(table));
+ return _upb_Decoder_DecodeMessage(d, ptr, msg, decode_totablep(table));
}
-static upb_DecodeStatus decode_top(struct upb_Decoder* d, const char* buf,
- void* msg, const upb_MiniTable* l) {
- if (!decode_tryfastdispatch(d, &buf, msg, l)) {
- decode_msg(d, buf, msg, l);
+static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d,
+ const char* buf, void* msg,
+ const upb_MiniTable* l) {
+ if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, l)) {
+ _upb_Decoder_DecodeMessage(d, buf, msg, l);
}
if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed;
if (d->missing_required) return kUpb_DecodeStatus_MissingRequired;
@@ -1203,7 +1225,7 @@
upb_DecodeStatus status = UPB_SETJMP(state.err);
if (UPB_LIKELY(status == kUpb_DecodeStatus_Ok)) {
- status = decode_top(&state, buf, msg, l);
+ status = _upb_Decoder_DecodeTop(&state, buf, msg, l);
}
arena->head.ptr = state.arena.head.ptr;
diff --git a/upb/decode_fast.c b/upb/decode_fast.c
index 30210b0..79ff6db 100644
--- a/upb/decode_fast.c
+++ b/upb/decode_fast.c
@@ -57,7 +57,7 @@
/* Uncomment either of these for debugging purposes. */ \
/* fprintf(stderr, m); */ \
/*__builtin_trap(); */ \
- return fastdecode_generic(d, ptr, msg, table, hasbits, 0);
+ return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0);
typedef enum {
CARD_s = 0, /* Singular (optional, non-repeated) */
@@ -70,12 +70,10 @@
static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) {
int overrun = data;
int status;
- ptr = decode_isdonefallback_inl(d, ptr, overrun, &status);
- if (ptr == NULL) {
- return fastdecode_err(d, status);
- }
- data = fastdecode_loadtag(ptr);
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS);
+ ptr = _upb_Decoder_IsDoneFallbackInline(d, ptr, overrun, &status);
+ if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, status);
+ data = _upb_FastDecoder_LoadTag(ptr);
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS);
}
UPB_FORCEINLINE
@@ -87,7 +85,7 @@
*(uint32_t*)msg |= hasbits; // Sync hasbits.
const upb_MiniTable* l = decode_totablep(table);
return UPB_UNLIKELY(l->required_count)
- ? decode_checkrequired(d, ptr, msg, l)
+ ? _upb_Decoder_CheckRequired(d, ptr, msg, l)
: ptr;
} else {
data = overrun;
@@ -96,8 +94,8 @@
}
// Read two bytes of tag data (for a one-byte tag, the high byte is junk).
- data = fastdecode_loadtag(ptr);
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS);
+ data = _upb_FastDecoder_LoadTag(ptr);
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS);
}
UPB_FORCEINLINE
@@ -176,9 +174,9 @@
// Corrupt wire format: invalid limit.
return NULL;
}
- int delta = decode_pushlimit(d, ptr, len);
+ int delta = _upb_Decoder_PushLimit(d, ptr, len);
ptr = func(d, ptr, ctx);
- decode_poplimit(d, ptr, delta);
+ _upb_Decoder_PopLimit(d, ptr, delta);
} else {
// Fast case: Sub-message is <128 bytes and fits in the current buffer.
// This means we can preserve limit/limit_ptr verbatim.
@@ -258,8 +256,8 @@
fastdecode_nextret ret;
dst = (char*)dst + valbytes;
- if (UPB_LIKELY(!decode_isdone(d, ptr))) {
- ret.tag = fastdecode_loadtag(*ptr);
+ if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) {
+ ret.tag = _upb_FastDecoder_LoadTag(*ptr);
if (fastdecode_tagmatch(ret.tag, data, tagbytes)) {
ret.next = FD_NEXT_SAMEFIELD;
} else {
@@ -315,7 +313,7 @@
}
begin = _upb_array_ptr(farr->arr);
farr->end = begin + (farr->arr->capacity * valbytes);
- *data = fastdecode_loadtag(ptr);
+ *data = _upb_FastDecoder_LoadTag(ptr);
return begin + (farr->arr->size * valbytes);
}
default:
@@ -402,7 +400,7 @@
\
ptr += tagbytes; \
ptr = fastdecode_varint64(ptr, &val); \
- if (ptr == NULL) return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \
+ if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \
val = fastdecode_munge(val, valbytes, zigzag); \
memcpy(dst, &val, valbytes); \
\
@@ -415,7 +413,7 @@
goto again; \
case FD_NEXT_OTHERFIELD: \
data = ret.tag; \
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
case FD_NEXT_ATLIMIT: \
return ptr; \
} \
@@ -437,7 +435,7 @@
void* dst = data->dst;
uint64_t val;
- while (!decode_isdone(d, &ptr)) {
+ while (!_upb_Decoder_IsDone(d, &ptr)) {
dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes);
ptr = fastdecode_varint64(ptr, &val);
if (ptr == NULL) return NULL;
@@ -466,7 +464,7 @@
ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \
\
if (UPB_UNLIKELY(ptr == NULL)) { \
- return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \
} \
\
UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0);
@@ -561,7 +559,7 @@
goto again; \
case FD_NEXT_OTHERFIELD: \
data = ret.tag; \
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
case FD_NEXT_ATLIMIT: \
return ptr; \
} \
@@ -582,7 +580,7 @@
\
if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr) || \
(size % valbytes) != 0)) { \
- return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \
} \
\
upb_Array** arr_p = fastdecode_fieldmem(msg, data); \
@@ -593,7 +591,7 @@
if (UPB_LIKELY(!arr)) { \
*arr_p = arr = _upb_Array_New(&d->arena, elems, elem_size_lg2); \
if (!arr) { \
- return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \
} \
} else { \
_upb_Array_Resize(arr, elems, &d->arena); \
@@ -659,8 +657,8 @@
upb_Message* msg, intptr_t table,
uint64_t hasbits, uint64_t data) {
upb_StringView* dst = (upb_StringView*)data;
- if (!decode_verifyutf8_inl(dst->data, dst->size)) {
- return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8);
+ if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) {
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8);
}
UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS);
}
@@ -674,7 +672,7 @@
\
if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr))) { \
dst->size = 0; \
- return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \
} \
\
if (d->options & kUpb_DecodeOption_AliasString) { \
@@ -683,7 +681,7 @@
} else { \
char* data = upb_Arena_Malloc(&d->arena, size); \
if (!data) { \
- return fastdecode_err(d, kUpb_DecodeStatus_OutOfMemory); \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \
} \
memcpy(data, ptr, size); \
dst->data = data; \
@@ -774,8 +772,9 @@
ptr += size; \
\
if (card == CARD_r) { \
- if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \
- return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \
+ if (validate_utf8 && \
+ !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \
} \
fastdecode_nextret ret = fastdecode_nextrepeated( \
d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \
@@ -785,7 +784,7 @@
goto again; \
case FD_NEXT_OTHERFIELD: \
data = ret.tag; \
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
case FD_NEXT_ATLIMIT: \
return ptr; \
} \
@@ -852,8 +851,9 @@
ptr += size; \
\
if (card == CARD_r) { \
- if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \
- return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \
+ if (validate_utf8 && \
+ !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \
} \
fastdecode_nextret ret = fastdecode_nextrepeated( \
d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \
@@ -866,12 +866,12 @@
/* data also. */ \
fastdecode_commitarr(dst, &farr, sizeof(upb_StringView)); \
data = ret.tag; \
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
} \
goto again; \
case FD_NEXT_OTHERFIELD: \
data = ret.tag; \
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
case FD_NEXT_ATLIMIT: \
return ptr; \
} \
@@ -966,7 +966,7 @@
} \
\
if (--d->depth == 0) { \
- return fastdecode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \
} \
\
upb_Message** dst; \
@@ -1003,7 +1003,7 @@
ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \
\
if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \
- return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \
+ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \
} \
\
if (card == CARD_r) { \
@@ -1016,7 +1016,7 @@
case FD_NEXT_OTHERFIELD: \
d->depth++; \
data = ret.tag; \
- UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \
+ UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
case FD_NEXT_ATLIMIT: \
d->depth++; \
return ptr; \
diff --git a/upb/decode_fast.h b/upb/decode_fast.h
index 3ccd1a0..7803367 100644
--- a/upb/decode_fast.h
+++ b/upb/decode_fast.h
@@ -75,9 +75,10 @@
// The fallback, generic parsing function that can handle any field type.
// This just uses the regular (non-fast) parser to parse a single field.
-const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr,
- upb_Message* msg, intptr_t table,
- uint64_t hasbits, uint64_t data);
+const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d,
+ const char* ptr, upb_Message* msg,
+ intptr_t table, uint64_t hasbits,
+ uint64_t data);
#define UPB_PARSE_PARAMS \
struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \
diff --git a/upb/def.c b/upb/def.c
index 261c444..a7144be 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -51,7 +51,7 @@
*
* We have to allocate an extra pointer for upb's internal metadata. */
static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0};
-static const char* opt_default = &opt_default_buf[sizeof(void*)];
+static const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)];
struct upb_FieldDef {
const google_protobuf_FieldOptions* opts;
@@ -245,28 +245,24 @@
return num & UPB_DEFTYPE_MASK;
}
-static const void* unpack_def(upb_value v, upb_deftype_t type) {
+static const void* _upb_DefUtil_Unpack(upb_value v, upb_deftype_t type) {
uintptr_t num = (uintptr_t)upb_value_getconstptr(v);
return (num & UPB_DEFTYPE_MASK) == type
? (const void*)(num & ~UPB_DEFTYPE_MASK)
: NULL;
}
-static upb_value pack_def(const void* ptr, upb_deftype_t type) {
+static upb_value _upb_DefUtil_Pack(const void* ptr, upb_deftype_t type,
+ size_t size) {
// Our 3-bit pointer tagging requires all pointers to be multiples of 8.
// The arena will always yield 8-byte-aligned addresses, however we put
// the defs into arrays. For each element in the array to be 8-byte-aligned,
// the sizes of each def type must also be a multiple of 8.
//
- // If any of these asserts fail, we need to add or remove padding on 32-bit
+ // If any of these asserts fail, we need to add or remove padding on 32-bit
// machines (64-bit machines will have 8-byte alignment already due to
// pointers, which all of these structs have).
- UPB_ASSERT((sizeof(upb_FieldDef) & UPB_DEFTYPE_MASK) == 0);
- UPB_ASSERT((sizeof(upb_MessageDef) & UPB_DEFTYPE_MASK) == 0);
- UPB_ASSERT((sizeof(upb_EnumDef) & UPB_DEFTYPE_MASK) == 0);
- UPB_ASSERT((sizeof(upb_EnumValueDef) & UPB_DEFTYPE_MASK) == 0);
- UPB_ASSERT((sizeof(upb_ServiceDef) & UPB_DEFTYPE_MASK) == 0);
- UPB_ASSERT((sizeof(upb_OneofDef) & UPB_DEFTYPE_MASK) == 0);
+ UPB_ASSERT((size & UPB_DEFTYPE_MASK) == 0);
uintptr_t num = (uintptr_t)ptr;
UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0);
num |= type;
@@ -294,7 +290,7 @@
return upb_isletter(c) || upb_isbetween(c, '0', '9');
}
-static const char* shortdefname(const char* fullname) {
+static const char* _upb_DefUtil_FullToShort(const char* fullname) {
const char* p;
if (fullname == NULL) {
@@ -378,10 +374,10 @@
int msg_count; /* Count of messages built so far. */
int ext_count; /* Count of extensions built so far. */
jmp_buf err; /* longjmp() on error. */
-} upb_AddDefCtx;
+} upb_DefBuilder;
UPB_NORETURN UPB_NOINLINE UPB_PRINTF(2, 3) static void _upb_DefBuilder_Errf(
- upb_AddDefCtx* ctx, const char* fmt, ...) {
+ upb_DefBuilder* ctx, const char* fmt, ...) {
va_list argp;
va_start(argp, fmt);
upb_Status_VSetErrorFormat(ctx->status, fmt, argp);
@@ -390,12 +386,12 @@
}
UPB_NORETURN UPB_NOINLINE static void _upb_DefBuilder_OomErr(
- upb_AddDefCtx* ctx) {
+ upb_DefBuilder* ctx) {
upb_Status_SetErrorMessage(ctx->status, "out of memory");
UPB_LONGJMP(ctx->err, 1);
}
-void* _upb_DefBuilder_Alloc(upb_AddDefCtx* ctx, size_t bytes) {
+void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) {
if (bytes == 0) return NULL;
void* ret = upb_Arena_Malloc(ctx->arena, bytes);
if (!ret) _upb_DefBuilder_OomErr(ctx);
@@ -409,13 +405,13 @@
}
bool upb_EnumDef_HasOptions(const upb_EnumDef* e) {
- return e->opts != (void*)opt_default;
+ return e->opts != (void*)kUpbDefOptDefault;
}
const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; }
const char* upb_EnumDef_Name(const upb_EnumDef* e) {
- return shortdefname(e->full_name);
+ return _upb_DefUtil_FullToShort(e->full_name);
}
const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; }
@@ -480,7 +476,7 @@
}
bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* e) {
- return e->opts != (void*)opt_default;
+ return e->opts != (void*)kUpbDefOptDefault;
}
const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* ev) {
@@ -492,7 +488,7 @@
}
const char* upb_EnumValueDef_Name(const upb_EnumValueDef* ev) {
- return shortdefname(ev->full_name);
+ return _upb_DefUtil_FullToShort(ev->full_name);
}
int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* ev) {
@@ -512,7 +508,7 @@
}
bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) {
- return r->opts != (void*)opt_default;
+ return r->opts != (void*)kUpbDefOptDefault;
}
int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* e) {
@@ -522,7 +518,7 @@
int32_t upb_ExtensionRange_End(const upb_ExtensionRange* e) { return e->end; }
// Allocate sufficient storage to contain an array of |n| extension ranges.
-static upb_ExtensionRange* _upb_ExtensionRange_Alloc(upb_AddDefCtx* ctx,
+static upb_ExtensionRange* _upb_ExtensionRange_Alloc(upb_DefBuilder* ctx,
int n) {
return _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n);
}
@@ -535,7 +531,7 @@
}
bool upb_FieldDef_HasOptions(const upb_FieldDef* f) {
- return f->opts != (void*)opt_default;
+ return f->opts != (void*)kUpbDefOptDefault;
}
const char* upb_FieldDef_FullName(const upb_FieldDef* f) {
@@ -592,7 +588,7 @@
bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { return f->packed_; }
const char* upb_FieldDef_Name(const upb_FieldDef* f) {
- return shortdefname(f->full_name);
+ return _upb_DefUtil_FullToShort(f->full_name);
}
const char* upb_FieldDef_JsonName(const upb_FieldDef* f) {
@@ -743,7 +739,7 @@
}
// Allocate sufficient storage to contain an array of |n| field defs.
-static upb_FieldDef* _upb_FieldDef_Alloc(upb_AddDefCtx* ctx, int n) {
+static upb_FieldDef* _upb_FieldDef_Alloc(upb_DefBuilder* ctx, int n) {
return _upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n);
}
@@ -755,7 +751,7 @@
}
bool upb_MessageDef_HasOptions(const upb_MessageDef* m) {
- return m->opts != (void*)opt_default;
+ return m->opts != (void*)kUpbDefOptDefault;
}
const char* upb_MessageDef_FullName(const upb_MessageDef* m) {
@@ -771,7 +767,7 @@
}
const char* upb_MessageDef_Name(const upb_MessageDef* m) {
- return shortdefname(m->full_name);
+ return _upb_DefUtil_FullToShort(m->full_name);
}
upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) {
@@ -793,7 +789,7 @@
return NULL;
}
- return unpack_def(val, UPB_DEFTYPE_FIELD);
+ return _upb_DefUtil_Unpack(val, UPB_DEFTYPE_FIELD);
}
const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize(
@@ -804,7 +800,7 @@
return NULL;
}
- return unpack_def(val, UPB_DEFTYPE_ONEOF);
+ return _upb_DefUtil_Unpack(val, UPB_DEFTYPE_ONEOF);
}
bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m,
@@ -817,8 +813,8 @@
return false;
}
- const upb_FieldDef* f = unpack_def(val, UPB_DEFTYPE_FIELD);
- const upb_OneofDef* o = unpack_def(val, UPB_DEFTYPE_ONEOF);
+ const upb_FieldDef* f = _upb_DefUtil_Unpack(val, UPB_DEFTYPE_FIELD);
+ const upb_OneofDef* o = _upb_DefUtil_Unpack(val, UPB_DEFTYPE_ONEOF);
if (out_f) *out_f = f;
if (out_o) *out_o = o;
return f || o; /* False if this was a JSON name. */
@@ -833,8 +829,8 @@
return NULL;
}
- f = unpack_def(val, UPB_DEFTYPE_FIELD);
- if (!f) f = unpack_def(val, UPB_DEFTYPE_FIELD_JSONNAME);
+ f = _upb_DefUtil_Unpack(val, UPB_DEFTYPE_FIELD);
+ if (!f) f = _upb_DefUtil_Unpack(val, UPB_DEFTYPE_FIELD_JSONNAME);
return f;
}
@@ -924,11 +920,11 @@
}
bool upb_OneofDef_HasOptions(const upb_OneofDef* o) {
- return o->opts != (void*)opt_default;
+ return o->opts != (void*)kUpbDefOptDefault;
}
const char* upb_OneofDef_Name(const upb_OneofDef* o) {
- return shortdefname(o->full_name);
+ return _upb_DefUtil_FullToShort(o->full_name);
}
const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) {
@@ -974,7 +970,7 @@
}
bool upb_FileDef_HasOptions(const upb_FileDef* f) {
- return f->opts != (void*)opt_default;
+ return f->opts != (void*)kUpbDefOptDefault;
}
const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; }
@@ -1061,7 +1057,7 @@
}
bool upb_MethodDef_HasOptions(const upb_MethodDef* m) {
- return m->opts != (void*)opt_default;
+ return m->opts != (void*)kUpbDefOptDefault;
}
const char* upb_MethodDef_FullName(const upb_MethodDef* m) {
@@ -1071,7 +1067,7 @@
int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; }
const char* upb_MethodDef_Name(const upb_MethodDef* m) {
- return shortdefname(m->full_name);
+ return _upb_DefUtil_FullToShort(m->full_name);
}
const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) {
@@ -1101,7 +1097,7 @@
}
bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) {
- return s->opts != (void*)opt_default;
+ return s->opts != (void*)kUpbDefOptDefault;
}
const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) {
@@ -1109,7 +1105,7 @@
}
const char* upb_ServiceDef_Name(const upb_ServiceDef* s) {
- return shortdefname(s->full_name);
+ return _upb_DefUtil_FullToShort(s->full_name);
}
int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; }
@@ -1168,14 +1164,16 @@
static const void* symtab_lookup(const upb_DefPool* s, const char* sym,
upb_deftype_t type) {
upb_value v;
- return upb_strtable_lookup(&s->syms, sym, &v) ? unpack_def(v, type) : NULL;
+ return upb_strtable_lookup(&s->syms, sym, &v) ? _upb_DefUtil_Unpack(v, type)
+ : NULL;
}
static const void* symtab_lookup2(const upb_DefPool* s, const char* sym,
size_t size, upb_deftype_t type) {
upb_value v;
- return upb_strtable_lookup2(&s->syms, sym, size, &v) ? unpack_def(v, type)
- : NULL;
+ return upb_strtable_lookup2(&s->syms, sym, size, &v)
+ ? _upb_DefUtil_Unpack(v, type)
+ : NULL;
}
const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s,
@@ -1221,9 +1219,9 @@
switch (deftype(v)) {
case UPB_DEFTYPE_FIELD:
- return unpack_def(v, UPB_DEFTYPE_FIELD);
+ return _upb_DefUtil_Unpack(v, UPB_DEFTYPE_FIELD);
case UPB_DEFTYPE_MSG: {
- const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG);
+ const upb_MessageDef* m = _upb_DefUtil_Unpack(v, UPB_DEFTYPE_MSG);
return m->in_message_set ? &m->nested_exts[0] : NULL;
}
default:
@@ -1255,23 +1253,25 @@
if (upb_strtable_lookup(&s->syms, name, &v)) {
switch (deftype(v)) {
case UPB_DEFTYPE_EXT: {
- const upb_FieldDef* f = unpack_def(v, UPB_DEFTYPE_EXT);
+ const upb_FieldDef* f = _upb_DefUtil_Unpack(v, UPB_DEFTYPE_EXT);
return upb_FieldDef_File(f);
}
case UPB_DEFTYPE_MSG: {
- const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG);
+ const upb_MessageDef* m = _upb_DefUtil_Unpack(v, UPB_DEFTYPE_MSG);
return upb_MessageDef_File(m);
}
case UPB_DEFTYPE_ENUM: {
- const upb_EnumDef* e = unpack_def(v, UPB_DEFTYPE_ENUM);
+ const upb_EnumDef* e = _upb_DefUtil_Unpack(v, UPB_DEFTYPE_ENUM);
return upb_EnumDef_File(e);
}
case UPB_DEFTYPE_ENUMVAL: {
- const upb_EnumValueDef* ev = unpack_def(v, UPB_DEFTYPE_ENUMVAL);
+ const upb_EnumValueDef* ev =
+ _upb_DefUtil_Unpack(v, UPB_DEFTYPE_ENUMVAL);
return upb_EnumDef_File(upb_EnumValueDef_Enum(ev));
}
case UPB_DEFTYPE_SERVICE: {
- const upb_ServiceDef* service = unpack_def(v, UPB_DEFTYPE_SERVICE);
+ const upb_ServiceDef* service =
+ _upb_DefUtil_Unpack(v, UPB_DEFTYPE_SERVICE);
return upb_ServiceDef_File(service);
}
default:
@@ -1302,26 +1302,21 @@
* this code is used to directly build defs from Ruby (for example) we do need
* to validate important constraints like uniqueness of names and numbers. */
-#define CHK_OOM(x) \
- if (!(x)) { \
- _upb_DefBuilder_OomErr(ctx); \
- }
-
// We want to copy the options verbatim into the destination options proto.
// We use serialize+parse as our deep copy.
-#define SET_OPTIONS(target, desc_type, options_type, proto) \
+#define SET_OPTIONS(target, desc_type, options_type, proto) \
if (google_protobuf_##desc_type##_has_options(proto)) { \
- size_t size; \
+ size_t size; \
char* pb = google_protobuf_##options_type##_serialize( \
google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \
- CHK_OOM(pb); \
+ if (!pb) _upb_DefBuilder_OomErr(ctx); \
target = google_protobuf_##options_type##_parse(pb, size, ctx->arena); \
- CHK_OOM(target); \
- } else { \
- target = (const google_protobuf_##options_type*)opt_default; \
+ if (!target) _upb_DefBuilder_OomErr(ctx); \
+ } else { \
+ target = (const google_protobuf_##options_type*)kUpbDefOptDefault; \
}
-static void _upb_DefBuilder_CheckIdent(upb_AddDefCtx* ctx, upb_StringView name,
+static void _upb_DefBuilder_CheckIdent(upb_DefBuilder* ctx, upb_StringView name,
bool full) {
const char* str = name.data;
size_t len = name.size;
@@ -1392,7 +1387,7 @@
}
}
-static uint32_t upb_MiniTable_place(upb_AddDefCtx* ctx, upb_MiniTable* l,
+static uint32_t upb_MiniTable_place(upb_DefBuilder* ctx, upb_MiniTable* l,
size_t size, const upb_MessageDef* m) {
size_t ofs = UPB_ALIGN_UP(l->size, size);
size_t next = ofs + size;
@@ -1504,7 +1499,7 @@
/* This function is the dynamic equivalent of message_layout.{cc,h} in upbc.
* It computes a dynamic layout for all of the fields in |m|. */
-static void make_layout(upb_AddDefCtx* ctx, const upb_MessageDef* m) {
+static void make_layout(upb_DefBuilder* ctx, const upb_MessageDef* m) {
upb_MiniTable* l = (upb_MiniTable*)upb_MessageDef_MiniTable(m);
size_t field_count = upb_MessageDef_numfields(m);
size_t sublayout_count = 0;
@@ -1546,7 +1541,7 @@
/* TODO(haberman): initialize fast tables so that reflection-based parsing
* can get the same speeds as linked-in types. */
- l->fasttable[0].field_parser = &fastdecode_generic;
+ l->fasttable[0].field_parser = &_upb_FastDecoder_DecodeGeneric;
l->fasttable[0].field_data = 0;
if (upb_MessageDef_IsMapEntry(m)) {
@@ -1700,9 +1695,9 @@
assign_layout_indices(m, l, fields);
}
-static char* strviewdup(upb_AddDefCtx* ctx, upb_StringView view) {
+static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) {
char* ret = upb_strdup2(view.data, view.size, ctx->arena);
- CHK_OOM(ret);
+ if (!ret) _upb_DefBuilder_OomErr(ctx);
return ret;
}
@@ -1714,7 +1709,7 @@
return streql2(view.data, view.size, b);
}
-static const char* _upb_DefBuilder_MakeFullName(upb_AddDefCtx* ctx,
+static const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx,
const char* prefix,
upb_StringView name) {
if (prefix) {
@@ -1731,7 +1726,7 @@
}
}
-static void finalize_oneofs(upb_AddDefCtx* ctx, upb_MessageDef* m) {
+static void finalize_oneofs(upb_DefBuilder* ctx, upb_MessageDef* m) {
int i;
int synthetic_count = 0;
upb_OneofDef* mutable_oneofs = (upb_OneofDef*)m->oneofs;
@@ -1809,7 +1804,7 @@
#undef WRITE
}
-static char* makejsonname(upb_AddDefCtx* ctx, const char* name) {
+static char* makejsonname(upb_DefBuilder* ctx, const char* name) {
size_t size = getjsonname(name, NULL, 0);
char* json_name = _upb_DefBuilder_Alloc(ctx, size);
getjsonname(name, json_name, size);
@@ -1819,7 +1814,7 @@
/* Adds a symbol |v| to the symtab, which must be a def pointer previously
* packed with pack_def(). The def's pointer to upb_FileDef* must be set before
* adding, so we know which entries to remove if building this file fails. */
-static void _upb_DefBuilder_Add(upb_AddDefCtx* ctx, const char* name,
+static void _upb_DefBuilder_Add(upb_DefBuilder* ctx, const char* name,
upb_value v) {
// TODO: table should support an operation "tryinsert" to avoid the double
// lookup.
@@ -1827,8 +1822,9 @@
_upb_DefBuilder_Errf(ctx, "duplicate symbol '%s'", name);
}
size_t len = strlen(name);
- CHK_OOM(upb_strtable_insert(&ctx->symtab->syms, name, len, v,
- ctx->symtab->arena));
+ bool ok =
+ upb_strtable_insert(&ctx->symtab->syms, name, len, v, ctx->symtab->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
}
static bool remove_component(char* base, size_t* len) {
@@ -1847,7 +1843,7 @@
/* Given a symbol and the base symbol inside which it is defined, find the
* symbol's definition in t. */
-static const void* symtab_resolveany(upb_AddDefCtx* ctx,
+static const void* symtab_resolveany(upb_DefBuilder* ctx,
const char* from_name_dbg,
const char* base, upb_StringView sym,
upb_deftype_t* type) {
@@ -1885,16 +1881,16 @@
}
*type = deftype(v);
- return unpack_def(v, *type);
+ return _upb_DefUtil_Unpack(v, *type);
notfound:
_upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'",
UPB_STRINGVIEW_ARGS(sym));
}
-static const void* symtab_resolve(upb_AddDefCtx* ctx, const char* from_name_dbg,
- const char* base, upb_StringView sym,
- upb_deftype_t type) {
+static const void* symtab_resolve(upb_DefBuilder* ctx,
+ const char* from_name_dbg, const char* base,
+ upb_StringView sym, upb_deftype_t type) {
upb_deftype_t found_type;
const void* ret =
symtab_resolveany(ctx, from_name_dbg, base, sym, &found_type);
@@ -1907,7 +1903,7 @@
return ret;
}
-static void create_oneofdef(upb_AddDefCtx* ctx, upb_MessageDef* m,
+static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m,
const google_protobuf_OneofDescriptorProto* oneof_proto,
const upb_OneofDef* _o) {
upb_OneofDef* o = (upb_OneofDef*)_o;
@@ -1926,17 +1922,22 @@
_upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name);
}
- v = pack_def(o, UPB_DEFTYPE_ONEOF);
- CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, v, ctx->arena));
+ v = _upb_DefUtil_Pack(o, UPB_DEFTYPE_ONEOF, sizeof(upb_OneofDef));
- CHK_OOM(upb_inttable_init(&o->itof, ctx->arena));
- CHK_OOM(upb_strtable_init(&o->ntof, 4, ctx->arena));
+ bool ok = upb_strtable_insert(&m->ntof, name.data, name.size, v, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
+
+ ok = upb_inttable_init(&o->itof, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
+
+ ok = upb_strtable_init(&o->ntof, 4, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
}
// Allocate and initialize an array of |n| oneof defs.
static upb_OneofDef* _upb_OneofDefs_New(
- upb_AddDefCtx* ctx, int n, const google_protobuf_OneofDescriptorProto* const* protos,
- upb_MessageDef* m) {
+ upb_DefBuilder* ctx, int n,
+ const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m) {
upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n);
for (int i = 0; i < n; i++) {
create_oneofdef(ctx, m, protos[i], &o[i]);
@@ -1944,9 +1945,9 @@
return o;
}
-static str_t* newstr(upb_AddDefCtx* ctx, const char* data, size_t len) {
+static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) {
str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len);
- CHK_OOM(ret);
+ if (!ret) _upb_DefBuilder_OomErr(ctx);
ret->len = len;
if (len) memcpy(ret->str, data, len);
ret->str[len] = '\0';
@@ -1976,7 +1977,7 @@
return -1;
}
-static char upb_DefPool_ParseHexEscape(upb_AddDefCtx* ctx,
+static char upb_DefPool_ParseHexEscape(upb_DefBuilder* ctx,
const upb_FieldDef* f, const char** src,
const char* end) {
char hex_digit = upb_DefPool_TryGetHexDigit(f, src, end);
@@ -2008,7 +2009,7 @@
return -1;
}
-static char upb_DefPool_ParseOctalEscape(upb_AddDefCtx* ctx,
+static char upb_DefPool_ParseOctalEscape(upb_DefBuilder* ctx,
const upb_FieldDef* f,
const char** src, const char* end) {
char ch = 0;
@@ -2021,7 +2022,7 @@
return ch;
}
-static char upb_DefPool_ParseEscape(upb_AddDefCtx* ctx, const upb_FieldDef* f,
+static char upb_DefPool_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f,
const char** src, const char* end) {
char ch;
if (!upb_DefPool_TryGetChar(src, end, &ch)) {
@@ -2069,7 +2070,7 @@
_upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch);
}
-static str_t* unescape(upb_AddDefCtx* ctx, const upb_FieldDef* f,
+static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f,
const char* data, size_t len) {
// Size here is an upper bound; escape sequences could ultimately shrink it.
str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len);
@@ -2090,7 +2091,7 @@
return ret;
}
-static void parse_default(upb_AddDefCtx* ctx, const char* str, size_t len,
+static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len,
upb_FieldDef* f) {
char* end;
char nullz[64];
@@ -2204,7 +2205,7 @@
(int)upb_FieldDef_Type(f));
}
-static void set_default_default(upb_AddDefCtx* ctx, upb_FieldDef* f) {
+static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) {
switch (upb_FieldDef_CType(f)) {
case kUpb_CType_Int32:
case kUpb_CType_Int64:
@@ -2234,7 +2235,7 @@
}
}
-static void create_fielddef(upb_AddDefCtx* ctx, const char* prefix,
+static void create_fielddef(upb_DefBuilder* ctx, const char* prefix,
upb_MessageDef* m,
const google_protobuf_FieldDescriptorProto* field_proto,
const upb_FieldDef* _f, bool is_extension) {
@@ -2254,7 +2255,7 @@
name = google_protobuf_FieldDescriptorProto_name(field_proto);
_upb_DefBuilder_CheckIdent(ctx, name, false);
full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name);
- shortname = shortdefname(full_name);
+ shortname = _upb_DefUtil_FullToShort(full_name);
if (google_protobuf_FieldDescriptorProto_has_json_name(field_proto)) {
json_name = strviewdup(
@@ -2316,8 +2317,9 @@
f->msgdef = m;
f->is_extension_ = false;
- field_v = pack_def(f, UPB_DEFTYPE_FIELD);
- json_v = pack_def(f, UPB_DEFTYPE_FIELD_JSONNAME);
+ field_v = _upb_DefUtil_Pack(f, UPB_DEFTYPE_FIELD, sizeof(upb_FieldDef));
+ json_v =
+ _upb_DefUtil_Pack(f, UPB_DEFTYPE_FIELD_JSONNAME, sizeof(upb_FieldDef));
v = upb_value_constptr(f);
json_size = strlen(json_name);
@@ -2325,15 +2327,17 @@
_upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname);
}
- CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, field_v,
- ctx->arena));
+ bool ok = upb_strtable_insert(&m->ntof, name.data, name.size, field_v,
+ ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
if (strcmp(shortname, json_name) != 0) {
if (upb_strtable_lookup(&m->ntof, json_name, &v)) {
_upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name);
} else {
- CHK_OOM(upb_strtable_insert(&m->ntof, json_name, json_size, json_v,
- ctx->arena));
+ ok = upb_strtable_insert(&m->ntof, json_name, json_size, json_v,
+ ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
}
}
@@ -2341,7 +2345,8 @@
_upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number);
}
- CHK_OOM(upb_inttable_insert(&m->itof, field_number, v, ctx->arena));
+ ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
if (ctx->layout) {
const upb_MiniTable* mt = upb_MessageDef_MiniTable(m);
@@ -2361,7 +2366,9 @@
/* extension field. */
f->is_extension_ = true;
f->scope.extension_scope = m;
- _upb_DefBuilder_Add(ctx, full_name, pack_def(f, UPB_DEFTYPE_EXT));
+ _upb_DefBuilder_Add(
+ ctx, full_name,
+ _upb_DefUtil_Pack(f, UPB_DEFTYPE_EXT, sizeof(upb_FieldDef)));
f->layout_index = ctx->ext_count++;
if (ctx->layout) {
UPB_ASSERT(_upb_FieldDef_ExtensionMiniTable(f)->field.number ==
@@ -2416,9 +2423,12 @@
if (f->proto3_optional_) {
oneof->synthetic = true;
}
- CHK_OOM(upb_inttable_insert(&oneof->itof, f->number_, v, ctx->arena));
- CHK_OOM(
- upb_strtable_insert(&oneof->ntof, name.data, name.size, v, ctx->arena));
+
+ bool ok = upb_inttable_insert(&oneof->itof, f->number_, v, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
+
+ ok = upb_strtable_insert(&oneof->ntof, name.data, name.size, v, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
} else {
if (f->proto3_optional_) {
_upb_DefBuilder_Errf(ctx,
@@ -2439,7 +2449,7 @@
}
}
-static void create_method(upb_AddDefCtx* ctx,
+static void create_method(upb_DefBuilder* ctx,
const google_protobuf_MethodDescriptorProto* method_proto,
upb_ServiceDef* s, upb_MethodDef* m) {
upb_StringView name = google_protobuf_MethodDescriptorProto_name(method_proto);
@@ -2462,7 +2472,7 @@
// Allocate and initialize an array of |n| method defs.
static upb_MethodDef* _upb_MethodDefs_New(
- upb_AddDefCtx* ctx, int n,
+ upb_DefBuilder* ctx, int n,
const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s) {
upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n);
for (int i = 0; i < n; i++) {
@@ -2472,7 +2482,7 @@
return m;
}
-static void create_service(upb_AddDefCtx* ctx,
+static void create_service(upb_DefBuilder* ctx,
const google_protobuf_ServiceDescriptorProto* svc_proto,
upb_ServiceDef* s) {
upb_StringView name;
@@ -2483,7 +2493,9 @@
name = google_protobuf_ServiceDescriptorProto_name(svc_proto);
_upb_DefBuilder_CheckIdent(ctx, name, false);
s->full_name = _upb_DefBuilder_MakeFullName(ctx, ctx->file->package, name);
- _upb_DefBuilder_Add(ctx, s->full_name, pack_def(s, UPB_DEFTYPE_SERVICE));
+ _upb_DefBuilder_Add(
+ ctx, s->full_name,
+ _upb_DefUtil_Pack(s, UPB_DEFTYPE_SERVICE, sizeof(upb_ServiceDef)));
const google_protobuf_MethodDescriptorProto* const* methods =
google_protobuf_ServiceDescriptorProto_method(svc_proto, &n);
@@ -2495,7 +2507,7 @@
// Allocate and initialize an array of |n| service defs.
static upb_ServiceDef* _upb_ServiceDefs_New(
- upb_AddDefCtx* ctx, int n,
+ upb_DefBuilder* ctx, int n,
const google_protobuf_ServiceDescriptorProto* const* protos) {
upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n);
for (int i = 0; i < n; i++) {
@@ -2521,7 +2533,7 @@
return a < b ? -1 : (a == b ? 0 : 1);
}
-static upb_MiniTable_Enum* create_enumlayout(upb_AddDefCtx* ctx,
+static upb_MiniTable_Enum* create_enumlayout(upb_DefBuilder* ctx,
const upb_EnumDef* e) {
const char* desc = _upb_EnumDef_MiniDescriptor(e, ctx->tmp_arena);
if (!desc)
@@ -2535,7 +2547,7 @@
return layout;
}
-static void create_enumvaldef(upb_AddDefCtx* ctx, const char* prefix,
+static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix,
const google_protobuf_EnumValueDescriptorProto* val_proto,
upb_EnumDef* e, upb_EnumValueDef* v) {
upb_StringView name = google_protobuf_EnumValueDescriptorProto_name(val_proto);
@@ -2544,22 +2556,27 @@
v->parent = e; // Must happen prior to _upb_DefBuilder_Add()
v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name);
v->number = google_protobuf_EnumValueDescriptorProto_number(val_proto);
- _upb_DefBuilder_Add(ctx, v->full_name, pack_def(v, UPB_DEFTYPE_ENUMVAL));
+ _upb_DefBuilder_Add(
+ ctx, v->full_name,
+ _upb_DefUtil_Pack(v, UPB_DEFTYPE_ENUMVAL, sizeof(upb_EnumDef)));
SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, val_proto);
- CHK_OOM(upb_strtable_insert(&e->ntoi, name.data, name.size, val, ctx->arena));
+ bool ok =
+ upb_strtable_insert(&e->ntoi, name.data, name.size, val, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
// Multiple enumerators can have the same number, first one wins.
if (!upb_inttable_lookup(&e->iton, v->number, NULL)) {
- CHK_OOM(upb_inttable_insert(&e->iton, v->number, val, ctx->arena));
+ ok = upb_inttable_insert(&e->iton, v->number, val, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
}
}
// Allocate and initialize an array of |n| enum value defs.
// TODO(b/243726666): This will eventually become the (only) public constructor.
static upb_EnumValueDef* _upb_EnumValueDefs_New(
- upb_AddDefCtx* ctx, const char* prefix, int n,
+ upb_DefBuilder* ctx, const char* prefix, int n,
const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e) {
upb_EnumValueDef* v =
_upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumValueDef) * n);
@@ -2585,7 +2602,7 @@
return v;
}
-static void create_enumdef(upb_AddDefCtx* ctx, const char* prefix,
+static void create_enumdef(upb_DefBuilder* ctx, const char* prefix,
const google_protobuf_EnumDescriptorProto* enum_proto,
upb_EnumDef* e) {
const google_protobuf_EnumValueDescriptorProto* const* values;
@@ -2598,11 +2615,17 @@
_upb_DefBuilder_CheckIdent(ctx, name, false);
e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name);
- _upb_DefBuilder_Add(ctx, e->full_name, pack_def(e, UPB_DEFTYPE_ENUM));
+ _upb_DefBuilder_Add(
+ ctx, e->full_name,
+ _upb_DefUtil_Pack(e, UPB_DEFTYPE_ENUM, sizeof(upb_EnumDef)));
values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n);
- CHK_OOM(upb_strtable_init(&e->ntoi, n, ctx->arena));
- CHK_OOM(upb_inttable_init(&e->iton, ctx->arena));
+
+ bool ok = upb_strtable_init(&e->ntoi, n, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
+
+ ok = upb_inttable_init(&e->iton, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
e->defaultval = 0;
e->value_count = n;
@@ -2634,7 +2657,7 @@
// Allocate and initialize an array of |n| enum defs.
// TODO(b/243726666): This will eventually become the (only) public constructor.
static upb_EnumDef* _upb_EnumDefs_New(
- upb_AddDefCtx* ctx, int n, const google_protobuf_EnumDescriptorProto* const* protos,
+ upb_DefBuilder* ctx, int n, const google_protobuf_EnumDescriptorProto* const* protos,
const upb_MessageDef* containing_type) {
// If a containing type is defined then get the full name from that.
// Otherwise use the package name from the file def.
@@ -2649,11 +2672,11 @@
return e;
}
-static void msgdef_create_nested(upb_AddDefCtx* ctx,
+static void msgdef_create_nested(upb_DefBuilder* ctx,
const google_protobuf_DescriptorProto* msg_proto,
upb_MessageDef* m);
-static void create_msgdef(upb_AddDefCtx* ctx, const char* prefix,
+static void create_msgdef(upb_DefBuilder* ctx, const char* prefix,
const google_protobuf_DescriptorProto* msg_proto,
const upb_MessageDef* containing_type,
const upb_MessageDef* _m) {
@@ -2671,15 +2694,20 @@
_upb_DefBuilder_CheckIdent(ctx, name, false);
m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name);
- _upb_DefBuilder_Add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG));
+ _upb_DefBuilder_Add(
+ ctx, m->full_name,
+ _upb_DefUtil_Pack(m, UPB_DEFTYPE_MSG, sizeof(upb_MessageDef)));
oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof);
fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field);
ext_ranges =
google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range);
- CHK_OOM(upb_inttable_init(&m->itof, ctx->arena));
- CHK_OOM(upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena));
+ bool ok = upb_inttable_init(&m->itof, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
+
+ ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
if (ctx->layout) {
/* create_fielddef() below depends on this being set. */
@@ -2739,7 +2767,7 @@
// Allocate and initialize an array of |n| message defs.
static upb_MessageDef* _upb_MessageDefs_New(
- upb_AddDefCtx* ctx, int n, const google_protobuf_DescriptorProto* const* protos,
+ upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos,
const upb_MessageDef* containing_type) {
const char* name =
containing_type ? containing_type->full_name : ctx->file->package;
@@ -2750,7 +2778,7 @@
return m;
}
-static void msgdef_create_nested(upb_AddDefCtx* ctx,
+static void msgdef_create_nested(upb_DefBuilder* ctx,
const google_protobuf_DescriptorProto* msg_proto,
upb_MessageDef* m) {
size_t n;
@@ -2776,7 +2804,7 @@
m->nested_msgs = _upb_MessageDefs_New(ctx, n, msgs, m);
}
-static void resolve_subdef(upb_AddDefCtx* ctx, const char* prefix,
+static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix,
upb_FieldDef* f) {
const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved;
upb_StringView name =
@@ -2822,7 +2850,7 @@
}
}
-static void resolve_extension(upb_AddDefCtx* ctx, const char* prefix,
+static void resolve_extension(upb_DefBuilder* ctx, const char* prefix,
upb_FieldDef* f,
const google_protobuf_FieldDescriptorProto* field_proto) {
if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) {
@@ -2866,11 +2894,12 @@
mut_ext->sub.submsg = f->sub.msgdef->layout;
}
- CHK_OOM(upb_inttable_insert(&ctx->symtab->exts, (uintptr_t)ext,
- upb_value_constptr(f), ctx->arena));
+ bool ok = upb_inttable_insert(&ctx->symtab->exts, (uintptr_t)ext,
+ upb_value_constptr(f), ctx->arena);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
}
-static void resolve_default(upb_AddDefCtx* ctx, upb_FieldDef* f,
+static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f,
const google_protobuf_FieldDescriptorProto* field_proto) {
// Have to delay resolving of the default value until now because of the enum
// case, since enum defaults are specified with a label.
@@ -2898,7 +2927,7 @@
}
}
-static void resolve_fielddef(upb_AddDefCtx* ctx, const char* prefix,
+static void resolve_fielddef(upb_DefBuilder* ctx, const char* prefix,
upb_FieldDef* f) {
// We have to stash this away since resolve_subdef() may overwrite it.
const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved;
@@ -2911,7 +2940,7 @@
}
}
-static void resolve_msgdef(upb_AddDefCtx* ctx, upb_MessageDef* m) {
+static void resolve_msgdef(upb_DefBuilder* ctx, upb_MessageDef* m) {
for (int i = 0; i < m->field_count; i++) {
resolve_fielddef(ctx, m->full_name, (upb_FieldDef*)&m->fields[i]);
}
@@ -2950,7 +2979,7 @@
}
// Allocate and initialize one file def, and add it to the context object.
-static void _upb_FileDef_Create(upb_AddDefCtx* ctx,
+static void _upb_FileDef_Create(upb_DefBuilder* ctx,
const google_protobuf_FileDescriptorProto* file_proto) {
upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef));
ctx->file = file;
@@ -3103,8 +3132,9 @@
}
if (file->ext_count) {
- CHK_OOM(_upb_extreg_add(ctx->symtab->extreg, file->ext_layouts,
- file->ext_count));
+ bool ok = _upb_extreg_add(ctx->symtab->extreg, file->ext_layouts,
+ file->ext_count);
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
}
}
@@ -3116,20 +3146,20 @@
const upb_FileDef* f;
switch (deftype(val)) {
case UPB_DEFTYPE_EXT:
- f = upb_FieldDef_File(unpack_def(val, UPB_DEFTYPE_EXT));
+ f = upb_FieldDef_File(_upb_DefUtil_Unpack(val, UPB_DEFTYPE_EXT));
break;
case UPB_DEFTYPE_MSG:
- f = upb_MessageDef_File(unpack_def(val, UPB_DEFTYPE_MSG));
+ f = upb_MessageDef_File(_upb_DefUtil_Unpack(val, UPB_DEFTYPE_MSG));
break;
case UPB_DEFTYPE_ENUM:
- f = upb_EnumDef_File(unpack_def(val, UPB_DEFTYPE_ENUM));
+ f = upb_EnumDef_File(_upb_DefUtil_Unpack(val, UPB_DEFTYPE_ENUM));
break;
case UPB_DEFTYPE_ENUMVAL:
- f = upb_EnumDef_File(
- upb_EnumValueDef_Enum(unpack_def(val, UPB_DEFTYPE_ENUMVAL)));
+ f = upb_EnumDef_File(upb_EnumValueDef_Enum(
+ _upb_DefUtil_Unpack(val, UPB_DEFTYPE_ENUMVAL)));
break;
case UPB_DEFTYPE_SERVICE:
- f = upb_ServiceDef_File(unpack_def(val, UPB_DEFTYPE_SERVICE));
+ f = upb_ServiceDef_File(_upb_DefUtil_Unpack(val, UPB_DEFTYPE_SERVICE));
break;
default:
UPB_UNREACHABLE();
@@ -3154,7 +3184,7 @@
}
}
- upb_AddDefCtx ctx = {
+ upb_DefBuilder ctx = {
.symtab = s,
.layout = layout,
.msg_count = 0,
@@ -3299,5 +3329,3 @@
*count = n;
return exts;
}
-
-#undef CHK_OOM
diff --git a/upb/fuzz_test_util.cc b/upb/fuzz_test_util.cc
index 12de4a9..219e4a3 100644
--- a/upb/fuzz_test_util.cc
+++ b/upb/fuzz_test_util.cc
@@ -111,8 +111,6 @@
bool Builder::LinkExtension(upb_MiniTable_Extension* ext) {
upb_MiniTable_Field* field = &ext->field;
- ext->extendee = NextMiniTable();
- if (!ext->extendee) return false;
if (field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group) {
auto mt = NextMiniTable();
@@ -140,8 +138,10 @@
upb_MiniTable_Extension* ext = reinterpret_cast<upb_MiniTable_Extension*>(
upb_Arena_Malloc(arena_, sizeof(*ext)));
upb_MiniTable_Sub sub;
- ptr =
- upb_MiniTable_BuildExtension(ptr, end - ptr, ext, sub, status.ptr());
+ const upb_MiniTable* extendee = NextMiniTable();
+ if (!extendee) break;
+ ptr = upb_MiniTable_BuildExtension(ptr, end - ptr, ext, extendee, sub,
+ status.ptr());
if (!ptr) break;
if (!LinkExtension(ext)) continue;
if (_upb_extreg_get(*exts, ext->extendee, ext->field.number)) continue;
diff --git a/upb/internal/decode.h b/upb/internal/decode.h
index 99aa5ae..ddd6fec 100644
--- a/upb/internal/decode.h
+++ b/upb/internal/decode.h
@@ -72,12 +72,12 @@
* of our optimizations. That is also why we must declare it in a separate file,
* otherwise the compiler will see that it calls longjmp() and deduce that it is
* noreturn. */
-const char* fastdecode_err(upb_Decoder* d, int status);
+const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status);
extern const uint8_t upb_utf8_offsets[];
UPB_INLINE
-bool decode_verifyutf8_inl(const char* ptr, int len) {
+bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) {
const char* end = ptr + len;
// Check 8 bytes at a time for any non-ASCII char.
@@ -100,9 +100,9 @@
return utf8_range2((const unsigned char*)ptr, end - ptr) == 0;
}
-const char* decode_checkrequired(upb_Decoder* d, const char* ptr,
- const upb_Message* msg,
- const upb_MiniTable* l);
+const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
+ const upb_Message* msg,
+ const upb_MiniTable* l);
/* x86-64 pointers always have the high 16 bits matching. So we can shift
* left 8 and right 8 without loss of information. */
@@ -115,8 +115,8 @@
}
UPB_INLINE
-const char* decode_isdonefallback_inl(upb_Decoder* d, const char* ptr,
- int overrun, int* status) {
+const char* _upb_Decoder_IsDoneFallbackInline(upb_Decoder* d, const char* ptr,
+ int overrun, int* status) {
if (overrun < d->limit) {
/* Need to copy remaining data into patch buffer. */
UPB_ASSERT(overrun < 16);
@@ -143,26 +143,27 @@
}
}
-const char* decode_isdonefallback(upb_Decoder* d, const char* ptr, int overrun);
+const char* _upb_Decoder_IsDoneFallback(upb_Decoder* d, const char* ptr,
+ int overrun);
UPB_INLINE
-bool decode_isdone(upb_Decoder* d, const char** ptr) {
+bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) {
int overrun = *ptr - d->end;
if (UPB_LIKELY(*ptr < d->limit_ptr)) {
return false;
} else if (UPB_LIKELY(overrun == d->limit)) {
return true;
} else {
- *ptr = decode_isdonefallback(d, *ptr, overrun);
+ *ptr = _upb_Decoder_IsDoneFallback(d, *ptr, overrun);
return false;
}
}
#if UPB_FASTTABLE
UPB_INLINE
-const char* fastdecode_tagdispatch(upb_Decoder* d, const char* ptr,
- upb_Message* msg, intptr_t table,
- uint64_t hasbits, uint64_t tag) {
+const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr,
+ upb_Message* msg, intptr_t table,
+ uint64_t hasbits, uint64_t tag) {
const upb_MiniTable* table_p = decode_totablep(table);
uint8_t mask = table;
uint64_t data;
@@ -175,33 +176,34 @@
}
#endif
-UPB_INLINE uint32_t fastdecode_loadtag(const char* ptr) {
+UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) {
uint16_t tag;
memcpy(&tag, ptr, 2);
return tag;
}
-UPB_INLINE void decode_checklimit(upb_Decoder* d) {
+UPB_INLINE void _upb_Decoder_CheckLimit(upb_Decoder* d) {
UPB_ASSERT(d->limit_ptr == d->end + UPB_MIN(0, d->limit));
}
-UPB_INLINE int decode_pushlimit(upb_Decoder* d, const char* ptr, int size) {
+UPB_INLINE int _upb_Decoder_PushLimit(upb_Decoder* d, const char* ptr,
+ int size) {
int limit = size + (int)(ptr - d->end);
int delta = d->limit - limit;
- decode_checklimit(d);
+ _upb_Decoder_CheckLimit(d);
d->limit = limit;
d->limit_ptr = d->end + UPB_MIN(0, limit);
- decode_checklimit(d);
+ _upb_Decoder_CheckLimit(d);
return delta;
}
-UPB_INLINE void decode_poplimit(upb_Decoder* d, const char* ptr,
- int saved_delta) {
+UPB_INLINE void _upb_Decoder_PopLimit(upb_Decoder* d, const char* ptr,
+ int saved_delta) {
UPB_ASSERT(ptr - d->end == d->limit);
- decode_checklimit(d);
+ _upb_Decoder_CheckLimit(d);
d->limit += saved_delta;
d->limit_ptr = d->end + UPB_MIN(0, d->limit);
- decode_checklimit(d);
+ _upb_Decoder_CheckLimit(d);
}
#include "upb/port_undef.inc"
diff --git a/upb/json_decode.c b/upb/json_decode.c
index 1eed62f..56775cb 100644
--- a/upb/json_decode.c
+++ b/upb/json_decode.c
@@ -38,6 +38,7 @@
#include "upb/encode.h"
#include "upb/internal/atoi.h"
#include "upb/internal/unicode.h"
+#include "upb/map.h"
#include "upb/reflection.h"
// Must be last.
@@ -744,11 +745,11 @@
}
if (upb_FieldDef_CType(f) == kUpb_CType_Float) {
- if (val.double_val != INFINITY && val.double_val != -INFINITY &&
- (val.double_val > FLT_MAX || val.double_val < -FLT_MAX)) {
- jsondec_err(d, "Float out of range");
+ float f = val.double_val;
+ if (val.double_val != INFINITY && val.double_val != -INFINITY) {
+ if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range");
}
- val.float_val = val.double_val;
+ val.float_val = f;
}
return val;
diff --git a/upb/json_decode_test.cc b/upb/json_decode_test.cc
new file mode 100644
index 0000000..fcc65a9
--- /dev/null
+++ b/upb/json_decode_test.cc
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2009-2022, Google LLC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Google LLC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "upb/json_decode.h"
+
+#include <stdio.h>
+
+#include "google/protobuf/struct.upb.h"
+#include "gtest/gtest.h"
+#include "upb/def.hpp"
+#include "upb/json_test.upb.h"
+#include "upb/json_test.upbdefs.h"
+#include "upb/upb.hpp"
+
+static upb_test_Box* JsonDecode(const char* json, upb_Arena* a) {
+ upb::Status status;
+ upb::DefPool defpool;
+ upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr()));
+ EXPECT_TRUE(m.ptr() != nullptr);
+
+ upb_test_Box* box = upb_test_Box_new(a);
+ int options = 0;
+ bool ok = upb_JsonDecode(json, strlen(json), box, m.ptr(), defpool.ptr(),
+ options, a, status.ptr());
+ return ok ? box : nullptr;
+}
+
+struct FloatTest {
+ const std::string json;
+ float f;
+};
+
+static const std::vector<FloatTest> FloatTestsPass = {
+ {R"({"f": 0})", 0},
+ {R"({"f": 1})", 1},
+ {R"({"f": 1.000000})", 1},
+ {R"({"f": 1.5e1})", 15},
+ {R"({"f": 15e-1})", 1.5},
+ {R"({"f": -3.5})", -3.5},
+ {R"({"f": 3.402823e38})", 3.402823e38},
+ {R"({"f": -3.402823e38})", -3.402823e38},
+ {R"({"f": 340282346638528859811704183484516925440.0})",
+ 340282346638528859811704183484516925440.0},
+ {R"({"f": -340282346638528859811704183484516925440.0})",
+ -340282346638528859811704183484516925440.0},
+};
+
+static const std::vector<FloatTest> FloatTestsFail = {
+ {R"({"f": 1z})", 0},
+ {R"({"f": 3.4028236e+38})", 0},
+ {R"({"f": -3.4028236e+38})", 0},
+};
+
+// Decode some floats.
+TEST(JsonTest, DecodeFloats) {
+ upb::Arena a;
+
+ for (const auto& test : FloatTestsPass) {
+ upb_test_Box* box = JsonDecode(test.json.c_str(), a.ptr());
+ EXPECT_NE(box, nullptr);
+ float f = upb_test_Box_f(box);
+ EXPECT_EQ(f, test.f);
+ }
+
+ for (const auto& test : FloatTestsFail) {
+ upb_test_Box* box = JsonDecode(test.json.c_str(), a.ptr());
+ EXPECT_EQ(box, nullptr);
+ }
+}
diff --git a/upb/json_encode.c b/upb/json_encode.c
index 468b7f8..9c657dd 100644
--- a/upb/json_encode.c
+++ b/upb/json_encode.c
@@ -38,6 +38,7 @@
#include "upb/decode.h"
#include "upb/internal/encode.h"
#include "upb/internal/vsnprintf_compat.h"
+#include "upb/map.h"
#include "upb/reflection.h"
// Must be last.
diff --git a/upb/json_test.cc b/upb/json_encode_test.cc
similarity index 100%
rename from upb/json_test.cc
rename to upb/json_encode_test.cc
diff --git a/upb/json_test.proto b/upb/json_test.proto
index d14b2f1..0765333 100644
--- a/upb/json_test.proto
+++ b/upb/json_test.proto
@@ -17,4 +17,6 @@
optional Tag last_tag = 5;
optional string name = 4;
optional google.protobuf.Value val = 6;
+ optional float f = 7;
+ optional double d = 8;
}
diff --git a/upb/mini_table.c b/upb/mini_table.c
index 0b59607..3d13780 100644
--- a/upb/mini_table.c
+++ b/upb/mini_table.c
@@ -1102,6 +1102,7 @@
const char* upb_MiniTable_BuildExtension(const char* data, size_t len,
upb_MiniTable_Extension* ext,
+ const upb_MiniTable* extendee,
upb_MiniTable_Sub sub,
upb_Status* status) {
upb_MtDecoder decoder = {
@@ -1117,9 +1118,25 @@
uint16_t count = 0;
const char* ret =
upb_MtDecoder_Parse(&decoder, data, len, ext, sizeof(*ext), &count, NULL);
- ext->field.mode |= kUpb_LabelFlags_IsExtension;
- ext->field.offset = 0;
- ext->field.presence = 0;
+ if (!ret) return NULL;
+
+ upb_MiniTable_Field* f = &ext->field;
+
+ f->mode |= kUpb_LabelFlags_IsExtension;
+ f->offset = 0;
+ f->presence = 0;
+
+ if (extendee->ext & kUpb_ExtMode_IsMessageSet) {
+ // Extensions of MessageSet must be messages.
+ if (!upb_IsSubMessage(f)) return NULL;
+
+ // Extensions of MessageSet must be non-repeating.
+ if ((f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array) return NULL;
+ }
+
+ ext->extendee = extendee;
+ ext->sub = sub;
+
return ret;
}
diff --git a/upb/mini_table.h b/upb/mini_table.h
index 238c6d7..d71ebcf 100644
--- a/upb/mini_table.h
+++ b/upb/mini_table.h
@@ -156,6 +156,7 @@
const char* upb_MiniTable_BuildExtension(const char* data, size_t len,
upb_MiniTable_Extension* ext,
+ const upb_MiniTable* extendee,
upb_MiniTable_Sub sub,
upb_Status* status);
diff --git a/upb/msg_test.cc b/upb/msg_test.cc
index 68fd626..9e1548a 100644
--- a/upb/msg_test.cc
+++ b/upb/msg_test.cc
@@ -534,4 +534,40 @@
// "\010\002", 342248070, -806315555);
// }
//
+// TEST(FuzzTest, DecodeExtendMessageSetWithNonMessage) {
+// DecodeEncodeArbitrarySchemaAndPayload(
+// {{"\n"}, {""}, ".\244", {}}, "\013\032\005\212a#\365\336\020\001\226",
+// 14803219, 670718349);
+// }
+//
+// TEST(FuzzTest, DecodeExtendMessageSetWithNonMessage2) {
+// DecodeEncodeArbitrarySchemaAndPayload({{"\n", "G", "\n", "\274", ""},
+// {"", "\030"},
+// "_@",
+// {4294967295, 2147483647}},
+// std::string("\013\032\000\220", 4),
+// 279975758, 1647495141);
+// }
+//
+// TEST(FuzzTest, DecodeExtendMessageSetWithNonMessage3) {
+// DecodeEncodeArbitrarySchemaAndPayload(
+// {{"\n"}, {"B", ""}, "\212:b", {11141121}},
+// "\013\032\004\357;7\363\020\001\346\240\200\201\271", 399842149,
+// -452966025);
+// }
+//
+// TEST(FuzzTest, DecodeExtendMessageSetWithNonMessage4) {
+// DecodeEncodeArbitrarySchemaAndPayload(
+// {{"\n", "3\340", "\354"}, {}, "B}G", {4294967295, 4082331310}},
+// "\013\032\004\244B\331\255\020\001\220\224\243\350\t", -561523015,
+// 1683327312);
+// }
+//
+// TEST(FuzzTest, DecodeExtendMessageSetWithNonMessage5) {
+// DecodeEncodeArbitrarySchemaAndPayload(
+// {{"\n"}, {""}, "kB", {0}},
+// "x\203\251\006\013\032\002S\376\010\273\'\020\014\365\207\244\234",
+// -696925610, -654590577);
+// }
+//
// end:google_only
diff --git a/upb/port_def.inc b/upb/port_def.inc
index 17b23ca..b63988d 100644
--- a/upb/port_def.inc
+++ b/upb/port_def.inc
@@ -241,7 +241,11 @@
#undef UPB_FASTTABLE_SUPPORTED
-/* ASAN poisoning (for arena) *************************************************/
+/* ASAN poisoning (for arena).
+ * If using UPB from an interpreted language like Ruby, a build of the
+ * interpreter compiled with ASAN enbabled must be used in order to get sane and
+ * expected behavior.
+ */
#if defined(__SANITIZE_ADDRESS__)
#define UPB_ASAN 1
diff --git a/upb/reflection.c b/upb/reflection.c
index 43f8844..f2913b2 100644
--- a/upb/reflection.c
+++ b/upb/reflection.c
@@ -30,6 +30,7 @@
#include <string.h>
#include "upb/internal/table.h"
+#include "upb/map.h"
#include "upb/msg.h"
#include "upb/port_def.inc"
diff --git a/upb/reflection.h b/upb/reflection.h
index 23a7d34..1fea8c6 100644
--- a/upb/reflection.h
+++ b/upb/reflection.h
@@ -28,9 +28,8 @@
#ifndef UPB_REFLECTION_H_
#define UPB_REFLECTION_H_
-#include "upb/array.h"
#include "upb/def.h"
-#include "upb/map.h"
+#include "upb/message_value.h"
#include "upb/msg.h"
#include "upb/upb.h"
diff --git a/upb/text_encode.c b/upb/text_encode.c
index f3a63e9..393b8d7 100644
--- a/upb/text_encode.c
+++ b/upb/text_encode.c
@@ -36,6 +36,7 @@
#include "upb/internal/encode.h"
#include "upb/internal/vsnprintf_compat.h"
+#include "upb/map.h"
#include "upb/reflection.h"
// Must be last.
diff --git a/upb/util/BUILD b/upb/util/BUILD
index 9c34822..48e648d 100644
--- a/upb/util/BUILD
+++ b/upb/util/BUILD
@@ -62,6 +62,7 @@
hdrs = ["required_fields.h"],
visibility = ["//visibility:public"],
deps = [
+ "//:collections",
"//:port",
"//:reflection",
],
diff --git a/upb/util/required_fields.c b/upb/util/required_fields.c
index 90f40b6..260a5b1 100644
--- a/upb/util/required_fields.c
+++ b/upb/util/required_fields.c
@@ -33,6 +33,7 @@
#include <stdio.h>
#include "upb/internal/vsnprintf_compat.h"
+#include "upb/map.h"
#include "upb/reflection.h"
// Must be last.
diff --git a/upbc/file_layout.cc b/upbc/file_layout.cc
index 49268aa..f9dbac3 100644
--- a/upbc/file_layout.cc
+++ b/upbc/file_layout.cc
@@ -265,8 +265,12 @@
GetFieldModifiers(f));
upb_MiniTable_Extension& ext = extension_map_[f];
upb_MiniTable_Sub sub;
+ // The extendee may be from another file, so we build a temporary MiniTable
+ // for it, just for the purpose of building the extension.
+ // Note, we are not caching so this could use more memory than is necessary.
+ upb_MiniTable* extendee = MakeMiniTable(f->containing_type());
bool ok = upb_MiniTable_BuildExtension(e.data().data(), e.data().size(),
- &ext, sub, status.ptr());
+ &ext, extendee, sub, status.ptr());
if (!ok) {
// TODO(haberman): Use ABSL CHECK() when it is available.
fprintf(stderr, "Error building mini-table: %s\n",
diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc
index b418670..24ac89d 100644
--- a/upbc/protoc-gen-upb.cc
+++ b/upbc/protoc-gen-upb.cc
@@ -896,7 +896,7 @@
if (i == 0) {
output("/* Public Imports. */\n");
}
- output("#include \"$0\"\n", HeaderFilename(file));
+ output("#include \"$0\"\n", HeaderFilename(file->public_dependency(i)));
if (i == file->public_dependency_count() - 1) {
output("\n");
}
@@ -1208,9 +1208,9 @@
}
while ((size_t)slot >= table.size()) {
size_t size = std::max(static_cast<size_t>(1), table.size() * 2);
- table.resize(size, TableEntry{"fastdecode_generic", 0});
+ table.resize(size, TableEntry{"_upb_FastDecoder_DecodeGeneric", 0});
}
- if (table[slot].first != "fastdecode_generic") {
+ if (table[slot].first != "_upb_FastDecoder_DecodeGeneric") {
// A hotter field already filled this slot.
continue;
}