Commit 9c3d28ce authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

miniobj: Add ALLOC_OBJ_EXTRA() requested by PHK

And use it to implement ALLOC_FLEX_OBJ().
parent 9cc2fd87
......@@ -30,14 +30,16 @@
(to)->magic = (type_magic); \
} while (0)
#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \
#define ALLOC_OBJ_EXTRA(to, extra_size, type_magic) \
do { \
(to) = calloc(1, sizeof(*(to)) + \
((len) * sizeof *((to)->fld))); \
(to) = calloc(1, sizeof(*(to)) + (extra_size)); \
if ((to) != NULL) \
(to)->magic = (type_magic); \
} while (0)
#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \
ALLOC_OBJ_EXTRA(to, (len) * sizeof *((to)->fld), (type_magic))
#define FREE_OBJ(to) \
do { \
ZERO_OBJ(&(to)->magic, sizeof (to)->magic); \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment