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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Christophe de Dinechin <dinechin@xxxxxxxxxx>

Signed-off-by: Christophe de Dinechin <dinechin@xxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]