diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-04-06 16:12:26 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-04-06 16:12:26 -0700 |
commit | 8823fa6069452c86325b4d5a6065a0d4fd67f1a2 (patch) | |
tree | 39cb7c59737895b757c0a830b166d6ed69e83027 /upb/symtab.c | |
parent | f8c26358f0b87a9c90be3f038cdea5bdcae185a0 (diff) |
Refactored upb_def_freeze() a bit per PR comments.
Diffstat (limited to 'upb/symtab.c')
-rw-r--r-- | upb/symtab.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/upb/symtab.c b/upb/symtab.c index 83f549e..b694104 100644 --- a/upb/symtab.c +++ b/upb/symtab.c @@ -202,6 +202,7 @@ static bool symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, size_t freeze_n; upb_strtable_iter iter; upb_refcounted **add_objs = NULL; + upb_def **add_defs = NULL; size_t add_objs_size; upb_strtable addtab; upb_inttable seen; @@ -347,26 +348,38 @@ static bool symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, } } - /* We need an array of the defs in addtab, for passing to upb_def_freeze. */ + /* We need an array of the defs in addtab, for passing to + * upb_refcounted_freeze(). */ add_objs_size = upb_strtable_count(&addtab); if (freeze_also) { add_objs_size++; } - add_objs = malloc(sizeof(void*) * add_objs_size); - if (add_objs == NULL) goto oom_err; + add_defs = malloc(sizeof(void*) * add_objs_size); + if (add_defs == NULL) goto oom_err; upb_strtable_begin(&iter, &addtab); for (add_n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { - add_objs[add_n++] = upb_value_getptr(upb_strtable_iter_value(&iter)); + add_defs[add_n++] = upb_value_getptr(upb_strtable_iter_value(&iter)); } + /* Validate defs. */ + if (!_upb_def_validate(add_defs, add_n, status)) { + goto err; + } + + /* Cheat a little and give the array a new type. + * This is probably undefined behavior, but this code will be deleted soon. */ + add_objs = (upb_refcounted**)add_defs; + freeze_n = add_n; if (freeze_also) { add_objs[freeze_n++] = freeze_also; } - if (!upb_def_freeze2(add_objs, add_n, freeze_n, status)) + if (!upb_refcounted_freeze(add_objs, freeze_n, status, + UPB_MAX_MESSAGE_DEPTH * 2)) { goto err; + } /* This must be delayed until all errors have been detected, since error * recovery code uses this table to cleanup defs. */ |