[vlc-devel] [PATCH v2 1/3] vlc_common: add vlc_align helper

Alexandre Janniaux ajanni at videolabs.io
Tue Mar 24 10:11:45 CET 2020


Hi,

Previous discussion were against because it couldn't be used
for case where it was needed as a compile time value, eg. as
an array size for array initializer.

As there is no such case currently, this patch is fine with me.

Regards,
--
Alexandre Janniaux
Videolabs

On Mon, Mar 23, 2020 at 11:16:43PM +0100, Marvin Scholz wrote:
> ---
>  include/vlc_common.h | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/include/vlc_common.h b/include/vlc_common.h
> index d5e9f1eb71..5178556362 100644
> --- a/include/vlc_common.h
> +++ b/include/vlc_common.h
> @@ -549,6 +549,23 @@ typedef int ( * vlc_list_callback_t ) ( vlc_object_t *,      /* variable's objec
>  /* clip v in [min, max] */
>  #define VLC_CLIP(v, min, max)    __MIN(__MAX((v), (min)), (max))
>
> +/**
> + * Make integer v a multiple of align
> + *
> + * \note align must be a power of 2
> + */
> +VLC_USED
> +static inline size_t vlc_align(size_t v, size_t align)
> +{
> +    return (v + (align - 1)) & ~(align - 1);
> +}
> +
> +#if defined(__clang__) && __has_attribute(diagnose_if)
> +static inline size_t vlc_align(size_t v, size_t align)
> +    __attribute__((diagnose_if((align & (align - 1) || align == 0),
> +        "align must be power of 2", "error")));
> +#endif
> +
>  /** Greatest common divisor */
>  VLC_USED
>  static inline int64_t GCD ( int64_t a, int64_t b )
> --
> 2.21.1 (Apple Git-122.3)
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list