On Mon,  9 Jul 2018 14:23:07 +0100
Daniel Stone <[email protected]> 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 <[email protected]>
> ---
>  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

Attachment: pgpanqgNPS993.pgp
Description: OpenPGP digital signature

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to