diff options
| author | Simon Ser <contact@emersion.fr> | 2022-09-17 10:53:56 +0200 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2024-04-23 09:17:02 +0000 |
| commit | b258d5f36137088e5cb5ae097db7964290da7d55 (patch) | |
| tree | 2f59d6061156e64e8c5797942fe4818ab69529be /tests/data/small-server.h | |
| parent | Clarify behavior of buffer transformations (diff) | |
| download | wayland-b258d5f36137088e5cb5ae097db7964290da7d55.tar wayland-b258d5f36137088e5cb5ae097db7964290da7d55.tar.gz wayland-b258d5f36137088e5cb5ae097db7964290da7d55.tar.bz2 wayland-b258d5f36137088e5cb5ae097db7964290da7d55.tar.lz wayland-b258d5f36137088e5cb5ae097db7964290da7d55.tar.xz wayland-b258d5f36137088e5cb5ae097db7964290da7d55.tar.zst wayland-b258d5f36137088e5cb5ae097db7964290da7d55.zip | |
scanner: add validators for enums
Right now compositors need to manually check that enum values sent
by the client are valid. In particular:
- Check that the value sent by the client is not outside of the enum.
- Check that the version of the enum entry is consistent with the
object version.
Automatically generate validator functions to perform these tasks.
Signed-off-by: Simon Ser <contact@emersion.fr>
Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/104
Diffstat (limited to 'tests/data/small-server.h')
| -rw-r--r-- | tests/data/small-server.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/data/small-server.h b/tests/data/small-server.h index 22b8113..13fd1ed 100644 --- a/tests/data/small-server.h +++ b/tests/data/small-server.h @@ -83,11 +83,42 @@ enum intf_A_foo { * @since 2 */ INTF_A_FOO_THIRD = 2, + /** + * this is a negative value + * @since 2 + */ + INTF_A_FOO_NEGATIVE = -1, }; /** * @ingroup iface_intf_A */ #define INTF_A_FOO_THIRD_SINCE_VERSION 2 +/** + * @ingroup iface_intf_A + */ +#define INTF_A_FOO_NEGATIVE_SINCE_VERSION 2 +/** + * @ingroup iface_intf_A + * Validate a intf_A foo value. + * + * @return true on success, false on error. + * @ref intf_A_foo + */ +static inline bool +intf_A_foo_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case INTF_A_FOO_FIRST: + return version >= 1; + case INTF_A_FOO_SECOND: + return version >= 1; + case INTF_A_FOO_THIRD: + return version >= 2; + case (uint32_t)INTF_A_FOO_NEGATIVE: + return version >= 2; + default: + return false; + } +} #endif /* INTF_A_FOO_ENUM */ /** |
