From 67dd3549a78599fccf5894ed4062a5e3cb502bb2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 20 Mar 2026 19:36:51 +0100 Subject: [PATCH] system: use attribute packed for the spa_poll_event This makes it the same size as epoll_event and we don't need to copy the results over. It however technically causes an ABI break, in case someone was using the system interface directly. --- spa/include/spa/support/system.h | 8 ++++---- spa/plugins/support/system.c | 13 ++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/spa/include/spa/support/system.h b/spa/include/spa/support/system.h index 07a31a55f..3d287da04 100644 --- a/spa/include/spa/support/system.h +++ b/spa/include/spa/support/system.h @@ -41,7 +41,7 @@ struct itimerspec; #define SPA_TYPE_INTERFACE_System SPA_TYPE_INFO_INTERFACE_BASE "System" #define SPA_TYPE_INTERFACE_DataSystem SPA_TYPE_INFO_INTERFACE_BASE "DataSystem" -#define SPA_VERSION_SYSTEM 0 +#define SPA_VERSION_SYSTEM 1 struct spa_system { struct spa_interface iface; }; /* IO events */ @@ -60,10 +60,10 @@ struct spa_system { struct spa_interface iface; }; struct spa_poll_event { uint32_t events; void *data; -}; +} __attribute__ ((packed)); struct spa_system_methods { -#define SPA_VERSION_SYSTEM_METHODS 0 +#define SPA_VERSION_SYSTEM_METHODS 1 uint32_t version; /* read/write/ioctl */ @@ -151,7 +151,7 @@ SPA_API_SYSTEM int spa_system_pollfd_del(struct spa_system *object, int pfd, int SPA_API_SYSTEM int spa_system_pollfd_wait(struct spa_system *object, int pfd, struct spa_poll_event *ev, int n_ev, int timeout) { - return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_wait, 0, pfd, ev, n_ev, timeout); + return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_wait, 1, pfd, ev, n_ev, timeout); } SPA_API_SYSTEM int spa_system_timerfd_create(struct spa_system *object, int clockid, int flags) diff --git a/spa/plugins/support/system.c b/spa/plugins/support/system.c index 767e0b43d..d48636e2e 100644 --- a/spa/plugins/support/system.c +++ b/spa/plugins/support/system.c @@ -30,6 +30,8 @@ SPA_LOG_TOPIC_DEFINE_STATIC(log_topic, "spa.system"); # define TFD_TIMER_CANCEL_ON_SET (1 << 1) #endif +SPA_STATIC_ASSERT(sizeof(struct spa_poll_event) == sizeof(struct epoll_event)); + struct impl { struct spa_handle handle; struct spa_system system; @@ -132,16 +134,9 @@ static int impl_pollfd_del(void *object, int pfd, int fd) static int impl_pollfd_wait(void *object, int pfd, struct spa_poll_event *ev, int n_ev, int timeout) { - struct epoll_event ep[n_ev]; - int i, nfds; - - if (SPA_UNLIKELY((nfds = epoll_wait(pfd, ep, n_ev, timeout)) < 0)) + int nfds; + if (SPA_UNLIKELY((nfds = epoll_wait(pfd, (struct epoll_event*)ev, n_ev, timeout)) < 0)) return -errno; - - for (i = 0; i < nfds; i++) { - ev[i].events = ep[i].events; - ev[i].data = ep[i].data.ptr; - } return nfds; }