diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2018-03-07 12:46:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-07 12:46:24 -0800 |
commit | 6edcf6a82a1d49d784302c152735e4bdba6d643e (patch) | |
tree | e413ab067a5971fbfd2e2c928b929b7318ccf924 /upb | |
parent | 69719e0a06da41e074dc43b7f593006a5f145f86 (diff) | |
parent | bc7f1eaca0bcdda9d1ba876bc877e8e128fe2cec (diff) |
Merge pull request #99 from TeBoring/php-change
In case of circular dependency, layout has to be inserted first.
Diffstat (limited to 'upb')
-rw-r--r-- | upb/msg.c | 25 |
1 files changed, 10 insertions, 15 deletions
@@ -221,11 +221,11 @@ static bool upb_msglayout_initdefault(upb_msglayout *l, const upb_msgdef *m) { return true; } -static upb_msglayout *upb_msglayout_new(const upb_msgdef *m, - upb_msgfactory *factory) { +static bool upb_msglayout_init(const upb_msgdef *m, + upb_msglayout *l, + upb_msgfactory *factory) { upb_msg_field_iter it; upb_msg_oneof_iter oit; - upb_msglayout *l; size_t hasbit; size_t submsg_count = 0; const upb_msglayout_msginit_v1 **submsgs; @@ -241,9 +241,6 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m, } } - l = upb_gmalloc(sizeof(*l)); - if (!l) return NULL; - memset(l, 0, sizeof(*l)); fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields)); @@ -254,11 +251,10 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m, (!submsgs && submsg_count) || (!oneofs && upb_msgdef_numoneofs(m))) { /* OOM. */ - upb_gfree(l); upb_gfree(fields); upb_gfree(submsgs); upb_gfree(oneofs); - return NULL; + return false; } l->data.field_count = upb_msgdef_numfields(m); @@ -357,12 +353,7 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m, * alignment. TODO: track overall alignment for real? */ l->data.size = align_up(l->data.size, 8); - if (upb_msglayout_initdefault(l, m)) { - return l; - } else { - upb_msglayout_free(l); - return NULL; - } + return upb_msglayout_initdefault(l, m); } @@ -417,10 +408,14 @@ const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, UPB_ASSERT(upb_value_getptr(v)); return upb_value_getptr(v); } else { + /* In case of circular dependency, layout has to be inserted first. */ + upb_msglayout *l = upb_gmalloc(sizeof(*l)); upb_msgfactory *mutable_f = (void*)f; - upb_msglayout *l = upb_msglayout_new(m, mutable_f); upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l)); UPB_ASSERT(l); + if (!upb_msglayout_init(m, l, f)) { + upb_msglayout_free(l); + } return l; } } |