summaryrefslogtreecommitdiff
path: root/upb/decode.c
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-08-12 19:23:26 -0700
committerJoshua Haberman <jhaberman@gmail.com>2018-08-12 19:23:26 -0700
commitc8f6a27e6b27ed5d51cf6c8da5ec080b9952fa99 (patch)
tree8d9e160dcb6f52f530a00868f342ab08121d1684 /upb/decode.c
parentb0a6602fc8fddf71ac959d43b4cd82707e6235b9 (diff)
Enforced that upb_msg lives in an Arena only, and other simplifying.
upb_msg was trying to be general enough that it could either live in an arena or be allocated with malloc()/free(). This was too much complexity for too little benefit. We should commit to just saying that upb_msg is arena-only. I also ripped out the code to glue upb_msg to the existing handlers-based encoder/decoder. upb_msg has its own, small, simple encoder/decoder. I'm trying to whittle down upb_msg to a small and simple core. I updated the Lua extension for these changes. Lua needs some more work to properly create arenas per message. For now I just created a single global arena.
Diffstat (limited to 'upb/decode.c')
-rw-r--r--upb/decode.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/upb/decode.c b/upb/decode.c
index b5033f0..ca18e95 100644
--- a/upb/decode.c
+++ b/upb/decode.c
@@ -172,6 +172,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) {
size_t new_bytes;
size_t old_bytes;
void *new_data;
+ upb_alloc *alloc = upb_arena_alloc(arr->arena);
while (new_size < needed) {
new_size *= 2;
@@ -179,7 +180,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) {
old_bytes = arr->len * arr->element_size;
new_bytes = new_size * arr->element_size;
- new_data = upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes);
+ new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes);
CHK(new_data);
arr->data = new_data;
@@ -212,12 +213,11 @@ static upb_array *upb_getorcreatearr(upb_decstate *d,
upb_array *arr = upb_getarr(frame, field);
if (!arr) {
- arr = upb_env_malloc(d->env, sizeof(*arr));
+ upb_fieldtype_t type = upb_desctype_to_fieldtype[field->descriptortype];
+ arr = upb_array_new(type, upb_env_arena(d->env));
if (!arr) {
return NULL;
}
- upb_array_init(arr, upb_desctype_to_fieldtype[field->descriptortype],
- upb_arena_alloc(upb_env_arena(d->env)));
*(upb_array**)&frame->msg[field->offset] = arr;
}
@@ -278,10 +278,8 @@ static bool upb_decode_submsg(upb_decstate *d,
UPB_ASSERT(subm);
if (!submsg) {
- submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm));
+ submsg = upb_msg_new((upb_msglayout *)subm, upb_env_arena(d->env));
CHK(submsg);
- submsg = upb_msg_init(
- submsg, (upb_msglayout*)subm, upb_arena_alloc(upb_env_arena(d->env)));
*(void**)submsg_slot = submsg;
}
@@ -460,10 +458,8 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
subm = frame->m->submsgs[field->submsg_index];
UPB_ASSERT(subm);
- submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm));
+ submsg = upb_msg_new((upb_msglayout *)subm, upb_env_arena(d->env));
CHK(submsg);
- submsg = upb_msg_init(submsg, (upb_msglayout*)subm,
- upb_arena_alloc(upb_env_arena(d->env)));
field_mem = upb_array_add(arr, 1);
CHK(field_mem);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback