[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Xen-devel] [PATCH V3 4/8] xen/common: Introduce xrealloc_flex_struct() helper macros
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Oleksandr <olekstysh@xxxxxxxxx>
- Date: Thu, 29 Aug 2019 22:04:53 +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, xen-devel@xxxxxxxxxxxxxxxxxxxx, Volodymyr_Babchuk@xxxxxxxx
- Delivery-date: Thu, 29 Aug 2019 19:05:00 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 29.08.19 10:21, Jan Beulich wrote:
Hi Jan
On 28.08.2019 20:23, Oleksandr wrote:
--- a/xen/include/xen/xmalloc.h
+++ b/xen/include/xen/xmalloc.h
@@ -35,6 +35,18 @@
#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, type, field, nr)
({ \
+ typeof(*(ptr)) *ptr_ =
(ptr); \
+ /* Type checking: make sure that incoming pointer is of correct
type */ \
+ (void)((ptr) == (type
*)0); \
+ (type *)_xrealloc(ptr_, offsetof(type, field[nr]),
__alignof__(type)); \
+})
+
What about
#define xrealloc_flex_struct(ptr, field, nr) \
(typeof(ptr))_xrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \
__alignof__(typeof(*(ptr))))
?
Even better. And works...
Thank you.
--
Regards,
Oleksandr Tyshchenko
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|