From f7860e788d1ae58f35f72d3de8ad9f6d684de71b Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Fri, 1 Nov 2019 02:18:31 +0100 Subject: [PATCH 78/82] v4l2: add shorthand macros for v4l2 type checks Some wrappers for common static_assert checks. * v4l2.c (CHECK_V4L2_STRUCT_SIZE, CHECK_V4L2_RESERVED_SIZE. CHECK_V4L2_STRUCT_RESERVED_SIZE): New macros. --- v4l2.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/v4l2.c b/v4l2.c index 1e01fa6..b45f7f8 100644 --- a/v4l2.c +++ b/v4l2.c @@ -15,6 +15,24 @@ #include #include +#include "static_assert.h" + +#define CHECK_V4L2_STRUCT_SIZE(s_) \ + static_assert(sizeof(struct s_) == sizeof(struct_##s_), \ + "Unexpected struct " #s_ " size") +#define CHECK_V4L2_STRUCT_SIZE_LE(s_) \ + static_assert(sizeof(struct s_) <= sizeof(struct_##s_), \ + "Unexpected struct " #s_ " size, " \ + "please update the decoder") +#define CHECK_V4L2_RESERVED_SIZE(s_) \ + static_assert(sizeof_field(struct s_, reserved) \ + >= sizeof_field(struct_##s_, reserved), \ + "Unexpected struct " #s_ ".reserved size, " \ + "please update the decoder") +#define CHECK_V4L2_STRUCT_RESERVED_SIZE(s_) \ + CHECK_V4L2_STRUCT_SIZE(s_); \ + CHECK_V4L2_RESERVED_SIZE(s_) + #include DEF_MPERS_TYPE(struct_v4l2_buffer) #include DEF_MPERS_TYPE(struct_v4l2_clip) #ifdef VIDIOC_CREATE_BUFS -- 2.1.4