[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Xen-devel] [PATCH V4 5/8] xen/common: Introduce xrealloc_flex_struct() helper macros
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Oleksandr <olekstysh@xxxxxxxxx>
- Date: Mon, 16 Sep 2019 21:11:16 +0300
- Cc: sstabellini@xxxxxxxxxx, Wei Liu <wl@xxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Tim Deegan <tim@xxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, julien.grall@xxxxxxx, Paul Durrant <paul.durrant@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Volodymyr_Babchuk@xxxxxxxx
- Delivery-date: Mon, 16 Sep 2019 18:11:22 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 16.09.19 13:37, Jan Beulich wrote:
Hi, Jan
On 13.09.2019 17:35, Oleksandr Tyshchenko wrote:
--- a/xen/include/xen/xmalloc.h
+++ b/xen/include/xen/xmalloc.h
@@ -35,6 +35,15 @@
#define xzalloc_array(_type, _num) \
((_type *)_xzalloc_array(sizeof(_type), __alignof__(_type), _num))
+/* Allocate space for a structure with a flexible array of typed objects. */
+#define xmalloc_flex_struct(type, field, nr) \
+ (type *)_xmalloc(offsetof(type, field[nr]), __alignof__(type))
+
+/* Re-allocate space for a structure with a flexible array of typed objects. */
+#define xrealloc_flex_struct(ptr, field, nr) \
+ (typeof(ptr))_xrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \
+ __alignof__(typeof(*(ptr))))
With the missing parentheses around the entire constructs added
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
Thank you.
I'd like to note though that it sort of feels as if this notation
isn't going to provide maximum flexibility. I therefore wonder
whether the last two parameters shouldn't be combined, resulting
in an invocation like
ptr = xmalloc_flex_struct(struct s, field[5]);
But I realize this would allow for (more; I'll reply to patch 6
in a minute) abuse, so this wouldn't be a clear win.
Agree.
--
Regards,
Oleksandr Tyshchenko
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|