[master] 1e10f10b8 miniobj: Allocate objects with a flexible array
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Thu Aug 17 06:07:07 UTC 2023
commit 1e10f10b8c364262c0eebe6326d1133e5460c297
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Mon Jul 10 12:21:44 2023 +0200
miniobj: Allocate objects with a flexible array
diff --git a/include/miniobj.h b/include/miniobj.h
index 8babaa251..832998019 100644
--- a/include/miniobj.h
+++ b/include/miniobj.h
@@ -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); \
More information about the varnish-commit
mailing list