From 36cef8653fe57eff7d38fc0f4877bb900b1a21ea Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 28 Mar 2024 15:33:41 +0100 Subject: [PATCH] util: convert macros to inline functions Functionally equivalent except the usual macro footguns are avoided and type safety is increased. Signed-off-by: Simon Ser --- src/wayland-util.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/wayland-util.c b/src/wayland-util.c index bb2a1838..7231346b 100644 --- a/src/wayland-util.c +++ b/src/wayland-util.c @@ -174,9 +174,23 @@ union map_entry { void *data; }; -#define map_entry_is_free(entry) ((entry).next & 0x1) -#define map_entry_get_data(entry) ((void *)((entry).next & ~(uintptr_t)0x3)) -#define map_entry_get_flags(entry) (((entry).next >> 1) & 0x1) +static inline bool +map_entry_is_free(union map_entry entry) +{ + return entry.next & 0x1; +} + +static inline void * +map_entry_get_data(union map_entry entry) +{ + return (void *)(entry.next & ~(uintptr_t)0x3); +} + +static inline uint32_t +map_entry_get_flags(union map_entry entry) +{ + return (entry.next >> 1) & 0x1; +} void wl_map_init(struct wl_map *map, uint32_t side)