From bbbe757a260fc800ad609cd240569d2ef98ea3a9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 2 Apr 2025 15:24:59 +1000 Subject: [PATCH] Define a set of cleanup helpers These are all data structs that are used in libinput and the tests, let's declare them in a shared header so we can use them everywhere. For udev and libevdev let's use an ifdef check for a known #define so we don't have to add those deps everywhere. Part-of: --- src/libinput-util.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libinput-util.h b/src/libinput-util.h index 9e1ecbf5..4e363177 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -43,6 +43,7 @@ #include "util-range.h" #include "util-prop-parsers.h" #include "util-time.h" +#include "util-mem.h" #define VENDOR_ID_APPLE 0x5ac #define VENDOR_ID_CHICONY 0x4f2 @@ -71,4 +72,21 @@ #define LIBINPUT_EXPORT __attribute__ ((visibility("default"))) #define LIBINPUT_UNUSED __attribute__ ((unused)) +/* Commonly-used cleanup */ +#ifdef udev_list_entry_foreach +DEFINE_UNREF_CLEANUP_FUNC(udev); +DEFINE_UNREF_CLEANUP_FUNC(udev_device); +DEFINE_UNREF_CLEANUP_FUNC(udev_enumerate); +DEFINE_UNREF_CLEANUP_FUNC(udev_monitor); +#endif +#ifdef LIBEVDEV_ATTRIBUTE_PRINTF +DEFINE_FREE_CLEANUP_FUNC(libevdev); +#endif +DEFINE_UNREF_CLEANUP_FUNC(libinput); +DEFINE_UNREF_CLEANUP_FUNC(libinput_device); +DEFINE_UNREF_CLEANUP_FUNC(libinput_tablet_tool); +DEFINE_UNREF_CLEANUP_FUNC(libinput_seat); +DEFINE_DESTROY_CLEANUP_FUNC(libinput_event); +DEFINE_DESTROY_CLEANUP_FUNC(libinput_config_accel); + #endif /* LIBINPUT_UTIL_H */