upb_fielddef *upb_fielddef_new(const void *owner) { static const struct upb_refcounted_vtbl vtbl = {visitfield, freefield}; upb_fielddef *f = malloc(sizeof(*f)); if (!f) return NULL; if (!upb_def_init(upb_upcast(f), UPB_DEF_FIELD, &vtbl, owner)) { free(f); return NULL; } f->msgdef = NULL; f->sub.def = NULL; f->subdef_is_symbolic = false; f->label_ = UPB_LABEL_OPTIONAL; f->type_ = UPB_TYPE_INT32; f->number_ = 0; f->type_is_set_ = false; f->tagdelim = false; // For the moment we default this to UPB_INTFMT_VARIABLE, since it will work // with all integer types and is in some since more "default" since the most // normal-looking proto2 types int32/int64/uint32/uint64 use variable. // // Other options to consider: // - there is no default; users must set this manually (like type). // - default signed integers to UPB_INTFMT_ZIGZAG, since it's more likely to // be an optimal default for signed integers. f->intfmt = UPB_INTFMT_VARIABLE; return f; }
upb_enumdef *upb_enumdef_new() { upb_enumdef *e = malloc(sizeof(*e)); upb_def_init(&e->base, UPB_DEF_ENUM); upb_strtable_init(&e->ntoi, 0, sizeof(upb_ntoi_ent)); upb_inttable_init(&e->iton, 0, sizeof(upb_iton_ent)); return e; }
upb_msgdef *upb_msgdef_new() { upb_msgdef *m = malloc(sizeof(*m)); upb_def_init(&m->base, UPB_DEF_MSG); upb_inttable_init(&m->itof, 4, sizeof(upb_itof_ent)); upb_strtable_init(&m->ntof, 4, sizeof(upb_ntof_ent)); m->size = 0; m->hasbit_bytes = 0; m->extstart = 0; m->extend = 0; return m; }
upb_msgdef *upb_msgdef_new(const void *owner) { static const struct upb_refcounted_vtbl vtbl = {visitmsg, freemsg}; upb_msgdef *m = malloc(sizeof(*m)); if (!m) return NULL; if (!upb_def_init(upb_upcast(m), UPB_DEF_MSG, &vtbl, owner)) goto err2; if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err2; if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err1; return m; err1: upb_inttable_uninit(&m->itof); err2: free(m); return NULL; }
upb_enumdef *upb_enumdef_new(const void *owner) { static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_enumdef_free}; upb_enumdef *e = malloc(sizeof(*e)); if (!e) return NULL; if (!upb_def_init(upb_upcast(e), UPB_DEF_ENUM, &vtbl, owner)) goto err2; if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2; if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1; return e; err1: upb_strtable_uninit(&e->ntoi); err2: free(e); return NULL; }
upb_fielddef *upb_fielddef_new(const void *owner) { static const struct upb_refcounted_vtbl vtbl = {visitfield, freefield}; upb_fielddef *f = malloc(sizeof(*f)); if (!f) return NULL; if (!upb_def_init(upb_upcast(f), UPB_DEF_FIELD, &vtbl, owner)) { free(f); return NULL; } f->msgdef = NULL; f->sub.def = NULL; f->subdef_is_symbolic = false; f->subdef_is_owned = false; f->label_ = UPB_LABEL(OPTIONAL); // These are initialized to be invalid; the user must set them explicitly. // Could relax this later if it's convenient and non-confusing to have a // defaults for them. f->type_ = UPB_TYPE_NONE; f->number_ = 0; upb_fielddef_init_default(f); return f; }
// Is passed a ref on the string. static upb_unresolveddef *upb_unresolveddef_new(const char *str) { upb_unresolveddef *def = malloc(sizeof(*def)); upb_def_init(&def->base, UPB_DEF_UNRESOLVED); def->base.fqname = strdup(str); return def; }