diff options
-rw-r--r-- | include/datatype.h | 8 | ||||
-rw-r--r-- | src/datatype.c | 15 |
2 files changed, 20 insertions, 3 deletions
diff --git a/include/datatype.h b/include/datatype.h index 8a123631..053fbd93 100644 --- a/include/datatype.h +++ b/include/datatype.h @@ -81,11 +81,16 @@ enum byteorder { struct expr; +enum datatype_flags { + DTYPE_F_ALLOC = (1 << 0), +}; + /** * struct datatype * * @type: numeric identifier * @byteorder: byteorder of type (non-basetypes only) + * @flags: flags * @size: type size (fixed sized non-basetypes only) * @name: type name * @desc: type description @@ -96,8 +101,9 @@ struct expr; * @sym_tbl: symbol table for this type */ struct datatype { - enum datatypes type; + uint32_t type; enum byteorder byteorder; + unsigned int flags; unsigned int size; const char *name; const char *desc; diff --git a/src/datatype.c b/src/datatype.c index 2cb937f5..ca6c92f5 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -658,6 +658,16 @@ static struct error_record *concat_type_parse(const struct expr *sym, sym->dtype->desc); } +static struct datatype *dtype_alloc(void) +{ + struct datatype *dtype; + + dtype = xzalloc(sizeof(*dtype)); + dtype->flags = DTYPE_F_ALLOC; + + return dtype; +} + const struct datatype *concat_type_alloc(const struct expr *expr) { struct datatype *dtype; @@ -676,7 +686,7 @@ const struct datatype *concat_type_alloc(const struct expr *expr) } strncat(desc, ")", sizeof(desc) - strlen(desc) - 1); - dtype = xzalloc(sizeof(*dtype)); + dtype = dtype_alloc(); dtype->type = type; dtype->size = size; dtype->desc = xstrdup(desc); @@ -687,5 +697,6 @@ const struct datatype *concat_type_alloc(const struct expr *expr) void concat_type_destroy(const struct datatype *dtype) { - xfree(dtype); + if (dtype->flags & DTYPE_F_ALLOC) + xfree(dtype); } |