|
[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
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))))
?
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |