[PATCH v17 01/14] helpers: Add BUILD_BUG_ON from Linux kernel
Pekka Paalanen
ppaalanen at gmail.com
Mon Jul 9 13:53:38 UTC 2018
On Mon, 9 Jul 2018 14:23:07 +0100
Daniel Stone <daniels at collabora.com> wrote:
> Import the trivial definition of BUILD_BUG_ON() from the Linux kernel.
> This evaluates an expression such that it will call sizeof() on a
> negative-length array if the expression is false, generating a compiler
> error.
>
> This will be used in future patches to ensure two array lengths don't go
> out of sync.
>
> Signed-off-by: Daniel Stone <daniels at collabora.com>
> ---
> shared/helpers.h | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/shared/helpers.h b/shared/helpers.h
> index 46f745d1b..9ecc3c4e9 100644
> --- a/shared/helpers.h
> +++ b/shared/helpers.h
> @@ -100,6 +100,31 @@ extern "C" {
> (type *)( (char *)__mptr - offsetof(type,member) );})
> #endif
>
> +/**
> + * Build-time static assertion support
> + *
> + * A build-time equivalent to assert(), will generate a compilation error
> + * if the supplied condition does not evaluate true.
> + *
> + * The following example demonstrates use of BUILD_BUG_ON to ensure that
> + * arrays which are supposed to mirror each other have a consistent
> + * size.
> + *
> + * @code
> + * int small[4];
> + * long expanded[4];
> + *
> + * BUILD_BUG_ON(ARRAY_LENGTH(small) != ARRAY_LENGTH(expanded));
> + * for (i = 0; i < ARRAY_LENGTH(small); i++)
> + * expanded[i] = small[4];
> + * @endcode
> + *
> + * @param condition Expression to check for truth
> + */
> +#ifndef BUILD_BUG_ON
> +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
> +#endif
> +
> #ifdef __cplusplus
> }
> #endif
Hi,
I'm fairly paranoid of copying GPL code. The implementation sure is
trivial, but what exactly did you take from the kernel?
The documentation bit looks already copyrightable.
Did you know of the existing uses of static_assert in Weston?
Oh, but there are no uses left, all we have left are the fallback empty
definitions... two of them. >_<
Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20180709/253418f3/attachment-0001.sig>
More information about the wayland-devel
mailing list