Commit 1e10f10b authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

miniobj: Allocate objects with a flexible array

parent c8bb4150
......@@ -30,6 +30,17 @@
(to)->magic = (type_magic); \
} while (0)
#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \
do { \
v_static_assert( \
sizeof *(to) == offsetof(typeof(*(to)), fld), \
"the last field must be a flexible array"); \
(to) = calloc(1, \
sizeof *(to) + ((len) * sizeof *((to)->fld))); \
if ((to) != NULL) \
(to)->magic = (type_magic); \
} while (0)
#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