mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-05 14:48:02 +02:00
util-object: split macro to generate unref into one two
One macro that also defines the cleanup function, one macro that only defines the unref. This is required for any place where we want to use cleanup from multiple source files - like the test suite.
This commit is contained in:
parent
cc28d90a82
commit
b6f477fb96
25 changed files with 38 additions and 31 deletions
|
|
@ -80,7 +80,7 @@ ei_device_destroy(struct ei_device *device)
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(ei_device);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(ei_device);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_device);
|
||||
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(ei_device);
|
||||
|
|
@ -150,7 +150,7 @@ ei_device_add_region(struct ei_device *device, struct ei_region *region)
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(ei_keymap);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(ei_keymap);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_keymap);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_GETTER(ei_keymap, type, enum ei_keymap_type);
|
||||
_public_
|
||||
|
|
@ -536,7 +536,7 @@ ei_device_keyboard_key(struct ei_device *device,
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(ei_touch);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(ei_touch);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_touch);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_GETTER(ei_touch, device, struct ei_device*);
|
||||
_public_
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
OBJECT_IMPLEMENT_REF(ei_event);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(ei_event);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_event);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_GETTER(ei_event, type, enum ei_event_type);
|
||||
_public_
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ ei_fd_destroy(struct ei_fd *backend)
|
|||
static
|
||||
OBJECT_IMPLEMENT_CREATE(ei_fd);
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(ei_fd);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_fd);
|
||||
|
||||
static void
|
||||
interface_fd_destroy(struct ei *ei, void *backend)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ OBJECT_IMPLEMENT_PARENT(ei_portal, ei);
|
|||
static
|
||||
OBJECT_IMPLEMENT_REF(ei_portal);
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(ei_portal);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_portal);
|
||||
|
||||
static void
|
||||
interface_portal_destroy(struct ei *ei, void *backend)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ ei_property_destroy(struct ei_property *prop)
|
|||
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(ei_property);
|
||||
OBJECT_IMPLEMENT_UNREF(ei_property);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_property);
|
||||
|
||||
|
||||
#define _PERM(p_, mask_) (((p_) & (mask_)) == (mask_))
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ ei_region_destroy(struct ei_region *region)
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(ei_region);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(ei_region);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_region);
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(ei_region);
|
||||
_public_
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ ei_seat_destroy(struct ei_seat *seat)
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(ei_seat);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(ei_seat);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_seat);
|
||||
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(ei_seat);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ ei_socket_destroy(struct ei_socket *socket)
|
|||
static
|
||||
OBJECT_IMPLEMENT_CREATE(ei_socket);
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(ei_socket);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_socket);
|
||||
|
||||
static void
|
||||
interface_socket_destroy(struct ei *ei, void *backend)
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ OBJECT_IMPLEMENT_CREATE(ei);
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(ei);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(ei);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_SETTER(ei, user_data, void *);
|
||||
_public_
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ _public_
|
|||
OBJECT_IMPLEMENT_REF(eis_client);
|
||||
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(eis_client);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_client);
|
||||
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_GETTER(eis_client, name, const char*);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(eis_keymap);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(eis_keymap);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_keymap);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_GETTER(eis_keymap, type, enum eis_keymap_type);
|
||||
_public_
|
||||
|
|
@ -140,7 +140,7 @@ eis_device_destroy(struct eis_device *device)
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(eis_device);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(eis_device);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_device);
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(eis_device);
|
||||
static
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ eis_event_new_for_device(struct eis_device *device)
|
|||
OBJECT_IMPLEMENT_REF(eis_event);
|
||||
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(eis_event);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_event);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_GETTER(eis_event, type, enum eis_event_type);
|
||||
_public_
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ eis_fd_destroy(struct eis_fd *eis_fd)
|
|||
static
|
||||
OBJECT_IMPLEMENT_CREATE(eis_fd);
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(eis_fd);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_fd);
|
||||
|
||||
static void
|
||||
interface_fd_destroy(struct eis *eis, void *backend)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ eis_property_destroy(struct eis_property *prop)
|
|||
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(eis_property);
|
||||
OBJECT_IMPLEMENT_UNREF(eis_property);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_property);
|
||||
|
||||
#define _PERM(p_, mask_) (((p_) & (mask_)) == (mask_))
|
||||
#define PERM_R(p_) _PERM((p_)->permissions, EIS_PROPERTY_PERM_READ)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ eis_region_destroy(struct eis_region *region)
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(eis_region);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(eis_region);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_region);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_GETTER(eis_region, user_data, void *);
|
||||
_public_
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ eis_seat_destroy(struct eis_seat *seat)
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(eis_seat);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(eis_seat);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_seat);
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(eis_seat);
|
||||
static
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ eis_socket_destroy(struct eis_socket *socket)
|
|||
static
|
||||
OBJECT_IMPLEMENT_CREATE(eis_socket);
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(eis_socket);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_socket);
|
||||
|
||||
static
|
||||
OBJECT_IMPLEMENT_PARENT(eis_socket, eis);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ OBJECT_IMPLEMENT_CREATE(eis);
|
|||
_public_
|
||||
OBJECT_IMPLEMENT_REF(eis);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(eis);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis);
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_SETTER(eis, user_data, void *);
|
||||
_public_
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ reis_destroy(struct reis *reis)
|
|||
}
|
||||
|
||||
_public_
|
||||
OBJECT_IMPLEMENT_UNREF(reis);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(reis);
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(reis);
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ logger_destroy(struct logger* logger)
|
|||
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(logger);
|
||||
OBJECT_IMPLEMENT_UNREF(logger);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(logger);
|
||||
OBJECT_IMPLEMENT_SETTER(logger, priority, enum logger_priority);
|
||||
OBJECT_IMPLEMENT_GETTER(logger, priority, enum logger_priority);
|
||||
OBJECT_IMPLEMENT_SETTER(logger, user_data, void *);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ memfile_destroy(struct memfile *memfile)
|
|||
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(memfile);
|
||||
OBJECT_IMPLEMENT_UNREF(memfile);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(memfile);
|
||||
OBJECT_IMPLEMENT_REF(memfile);
|
||||
OBJECT_IMPLEMENT_GETTER(memfile, fd, int);
|
||||
OBJECT_IMPLEMENT_GETTER(memfile, size, size_t);
|
||||
|
|
|
|||
|
|
@ -107,20 +107,27 @@ struct type_ * type_##_ref(struct type_ *obj) { \
|
|||
* struct foo *foo_unref(struct foo *f);
|
||||
* The function always returns NULL, when the last reference is removed the
|
||||
* object is freed.
|
||||
*
|
||||
* This macro also defines a unrefp function, use with
|
||||
* __attribute__((cleanup(foo_unrefp))
|
||||
*/
|
||||
#define OBJECT_IMPLEMENT_UNREF(type_) \
|
||||
struct type_ * type_##_unref(struct type_ *obj) { \
|
||||
if (!obj) return NULL; \
|
||||
return object_unref(&obj->object); \
|
||||
} \
|
||||
struct __useless_struct_to_allow_trailing_semicolon__
|
||||
|
||||
/**
|
||||
* Same as OBJECT_IMPLEMENT_UNREF() but also
|
||||
* also defines a unrefp function, use with
|
||||
* __attribute__((cleanup(foo_unrefp))
|
||||
*/
|
||||
#define OBJECT_IMPLEMENT_UNREF_CLEANUP(type_) \
|
||||
OBJECT_IMPLEMENT_UNREF(type_); \
|
||||
__attribute__((used)) static inline void type_##_unrefp(struct type_ **p_) { \
|
||||
if (*p_) type_##_unref(*p_); \
|
||||
} \
|
||||
struct __useless_struct_to_allow_trailing_semicolon__
|
||||
|
||||
|
||||
/**
|
||||
* For a type for "foo", generate
|
||||
* void foo_init_object(struct foo *f)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ struct source {
|
|||
};
|
||||
|
||||
OBJECT_IMPLEMENT_REF(source);
|
||||
OBJECT_IMPLEMENT_UNREF(source);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(source);
|
||||
OBJECT_IMPLEMENT_GETTER(source, fd, int);
|
||||
OBJECT_IMPLEMENT_GETTER(source, user_data, void*);
|
||||
OBJECT_IMPLEMENT_SETTER(source, user_data, void*);
|
||||
|
|
@ -135,7 +135,7 @@ sink_destroy(struct sink *sink)
|
|||
xclose(sink->epollfd);
|
||||
}
|
||||
|
||||
OBJECT_IMPLEMENT_UNREF(sink);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(sink);
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(sink);
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ peck_destroy(struct peck *peck)
|
|||
|
||||
static
|
||||
OBJECT_IMPLEMENT_CREATE(peck);
|
||||
OBJECT_IMPLEMENT_UNREF(peck);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(peck);
|
||||
OBJECT_IMPLEMENT_GETTER(peck, ei, struct ei*);
|
||||
OBJECT_IMPLEMENT_GETTER(peck, eis, struct eis*);
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ static void sighandler(int signal) {
|
|||
}
|
||||
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(eis_demo_client);
|
||||
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_demo_client);
|
||||
|
||||
static void
|
||||
eis_demo_client_destroy(struct eis_demo_client *democlient)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue