Convert 'malloc' and 'free' macros in 'decompress.h' from object-like
to function-like form.
The object-like macros '#define free xfree' perform unconditional text
replacement, causing conflicts with struct field 'free' in 'page_info'
unions. Function-like macros only match when followed by parentheses,
allowing 'free' to be used both as a macro and as a struct field without
conflicts.
Applying function-like form to both 'malloc' and 'free' ensures consistent
macro style.
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
xen/common/decompress.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/xen/common/decompress.h b/xen/common/decompress.h
index 034c833665..df9fb9234f 100644
--- a/xen/common/decompress.h
+++ b/xen/common/decompress.h
@@ -9,8 +9,8 @@
#include <xen/types.h>
#include <xen/xmalloc.h>
-#define malloc xmalloc_bytes
-#define free xfree
+#define malloc(a) xmalloc_bytes(a)
+#define free(a) xfree(a)
#define large_malloc xmalloc_bytes
#define large_free xfree
--
2.43.0
On 21.05.2026 22:18, Dmytro Prokopchuk1 wrote: > Convert 'malloc' and 'free' macros in 'decompress.h' from object-like > to function-like form. > > The object-like macros '#define free xfree' perform unconditional text > replacement, causing conflicts with struct field 'free' in 'page_info' > unions. Function-like macros only match when followed by parentheses, > allowing 'free' to be used both as a macro and as a struct field without > conflicts. At the same time function-like macros cannot be used to e.g. pass the (underlying) function pointer to a function. Likely there aren't any such uses here, but imo this aspect needs covering in patches like this one. > Applying function-like form to both 'malloc' and 'free' ensures consistent > macro style. Not quite, seeing ... > --- a/xen/common/decompress.h > +++ b/xen/common/decompress.h > @@ -9,8 +9,8 @@ > #include <xen/types.h> > #include <xen/xmalloc.h> > > -#define malloc xmalloc_bytes > -#define free xfree > +#define malloc(a) xmalloc_bytes(a) > +#define free(a) xfree(a) > > #define large_malloc xmalloc_bytes > #define large_free xfree ... these two in context? IOW if you mean to achieve consistency, convert these (and whatever else, if anything) as well? Jan
Hello Jan, On 5/22/26 09:10, Jan Beulich wrote: > On 21.05.2026 22:18, Dmytro Prokopchuk1 wrote: >> Convert 'malloc' and 'free' macros in 'decompress.h' from object-like >> to function-like form. >> >> The object-like macros '#define free xfree' perform unconditional text >> replacement, causing conflicts with struct field 'free' in 'page_info' >> unions. Function-like macros only match when followed by parentheses, >> allowing 'free' to be used both as a macro and as a struct field without >> conflicts. > > At the same time function-like macros cannot be used to e.g. pass the > (underlying) function pointer to a function. Likely there aren't any > such uses here, but imo this aspect needs covering in patches like > this one. I will search through the Xen codebase these macros. > >> Applying function-like form to both 'malloc' and 'free' ensures consistent >> macro style. > > Not quite, seeing ... > >> --- a/xen/common/decompress.h >> +++ b/xen/common/decompress.h >> @@ -9,8 +9,8 @@ >> #include <xen/types.h> >> #include <xen/xmalloc.h> >> >> -#define malloc xmalloc_bytes >> -#define free xfree >> +#define malloc(a) xmalloc_bytes(a) >> +#define free(a) xfree(a) >> >> #define large_malloc xmalloc_bytes >> #define large_free xfree > > ... these two in context? IOW if you mean to achieve consistency, > convert these (and whatever else, if anything) as well? > Yes, this makes sense as well. > Jan BR, Dmytro.
© 2016 - 2026 Red Hat, Inc.