[Spice-devel] [PATCH v4 2/3] Put alignment checks under #ifdef SPICE_DEBUG_ALIGNMENT

Christophe Fergeau cfergeau at redhat.com
Wed May 31 09:20:54 UTC 2017


Why is this not done with the first patch?

Christophe

On Tue, May 30, 2017 at 02:51:50PM +0200, Christophe de Dinechin wrote:
> From: Christophe de Dinechin <dinechin at redhat.com>
> 
> Signed-off-by: Christophe de Dinechin <dinechin at redhat.com>
> ---
>  common/mem.c |  3 +--
>  common/mem.h | 27 ++++++++++++++-------------
>  2 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/common/mem.c b/common/mem.c
> index 5ce6874..fc8b453 100644
> --- a/common/mem.c
> +++ b/common/mem.c
> @@ -295,6 +295,7 @@ size_t spice_buffer_remove(SpiceBuffer *buffer, size_t len)
>      return len;
>  }
>  
> +#ifdef SPICE_DEBUG_ALIGNMENT
>  void spice_alignment_warning(const char *loc, void *p, unsigned sz)
>  {
>      static const char *last_loc = NULL;
> @@ -305,8 +306,6 @@ void spice_alignment_warning(const char *loc, void *p, unsigned sz)
>      }
>  }
>  
> -
> -#ifdef SPICE_DEBUG_ALIGNMENT
>  void spice_alignment_debug(const char *loc, void *p, unsigned sz)
>  {
>      static const char *last_loc = NULL;
> diff --git a/common/mem.h b/common/mem.h
> index 91d49ce..9c911bd 100644
> --- a/common/mem.h
> +++ b/common/mem.h
> @@ -141,37 +141,38 @@ size_t spice_strnlen(const char *str, size_t max_len);
>  #endif
>  
>  /* Cast to a type with stricter alignment constraints (to build with clang) */
> +
> +/* Misaligned cast to a type with stricter alignment */
> +#ifndef SPICE_DEBUG_ALIGNMENT
> +#define SPICE_UNALIGNED_CAST(type, value) ((type)(void *)(value))
> +#define SPICE_ALIGNED_CAST(type, value)   ((type)(void *)(value))
> +
> +#else // SPICE_DEBUG_ALIGNMENT
>  #define SPICE_ALIGNED_CAST(type, value)                                 \
>      ((type)spice_alignment_check(SPICE_STRLOC,                          \
>                                   (void *)(value),                       \
>                                   __alignof(*((type)0))))
>  
> +#define SPICE_UNALIGNED_CAST(type, value)                               \
> +    ((type)spice_alignment_weak_check(SPICE_STRLOC,                     \
> +                                      (void *)(value),                  \
> +                                      __alignof(*((type)0))))
> +
>  extern void spice_alignment_warning(const char *loc, void *p, unsigned sz);
> +extern void spice_alignment_debug(const char *loc, void *p, unsigned sz);
> +
>  static inline  void *spice_alignment_check(const char *loc,
>                                             void *ptr, unsigned sz)
>  {
> -#ifndef NDEBUG
>      if (G_UNLIKELY(((uintptr_t) ptr & (sz-1U)) != 0))
>          spice_alignment_warning(loc, ptr, sz);
> -#endif // NDEBUG
>      return ptr;
>  
>  }
>  
> -/* Misaligned cast to a type with stricter alignment */
> -#ifndef SPICE_DEBUG_ALIGNMENT
> -#define SPICE_UNALIGNED_CAST(type, value) ((type)(void *)(value))
> -
> -#else // SPICE_DEBUG_ALIGNMENT
> -#define SPICE_UNALIGNED_CAST(type, value)                               \
> -    ((type)spice_alignment_weak_check(SPICE_STRLOC,                     \
> -                                      (void *)(value),                  \
> -                                      __alignof(*((type)0))))
> -
>  static inline void *spice_alignment_weak_check(const char *loc,
>                                                 void *ptr, unsigned sz)
>  {
> -    extern void spice_alignment_debug(const char *loc, void *p, unsigned sz);
>      if (G_UNLIKELY(((uintptr_t) ptr & (sz-1U)) != 0))
>          spice_alignment_debug(loc, ptr, sz);
>      return ptr;
> -- 
> 2.11.0 (Apple Git-81)
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170531/04b15776/attachment.sig>


More information about the Spice-devel mailing list