[Libguestfs] [PATCH nbdkit v3 1/3] common: isaligned: Use a macro instead of relying on implicit truncation.

Nir Soffer nsoffer at redhat.com
Mon Sep 17 21:51:34 UTC 2018


On Tue, Sep 18, 2018 at 12:27 AM Richard W.M. Jones <rjones at redhat.com>
wrote:

> ---
>  common/include/isaligned.h | 11 +++++------
>  plugins/file/file.c        |  4 ++--
>  plugins/vddk/vddk.c        |  8 ++++----
>  3 files changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/common/include/isaligned.h b/common/include/isaligned.h
> index e693820..81ce8a7 100644
> --- a/common/include/isaligned.h
> +++ b/common/include/isaligned.h
> @@ -36,16 +36,15 @@
>
>  #include <assert.h>
>  #include <stdbool.h>
> +#include <stdint.h>
>

With the macro, stdint.h and stdbool.h are not needed.


>
>  #include "ispowerof2.h"
>
>  /* Return true if size is a multiple of align. align must be power of 2.
>   */
> -static inline bool
> -is_aligned (unsigned int size, unsigned int align)
> -{
> -  assert (is_power_of_2 (align));
> -  return !(size & (align - 1));
> -}
> +#define IS_ALIGNED(size, align) ({              \
> +      assert (is_power_of_2 ((align)));         \
> +      !((size) & ((align) - 1));                \
> +})
>
>  #endif /* NBDKIT_ISALIGNED_H */
> ...


Nir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20180918/358beceb/attachment.htm>


More information about the Libguestfs mailing list