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

Christophe de Dinechin christophe at dinechin.org
Wed May 31 09:23:27 UTC 2017


> On 31 May 2017, at 11:20, Christophe Fergeau <cfergeau at redhat.com> wrote:
> 
> Why is this not done with the first patch?

Mostly to make clear what had changed, and keep the previous version separate in case that one did not stick. But I can rebase + fixup if you prefer.

Christophe
> 
> 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



More information about the Spice-devel mailing list