[Spice-devel] [PATCH] macros: do not use more type safe CONTAINEROF version if not requested

Frediano Ziglio fziglio at redhat.com
Tue Mar 1 09:44:39 UTC 2016


This prevents incompatibility if users (like old spice-server/spice-gtk)
are not expected to have this additional restriction.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 spice/macros.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

I defined a new SPICE_CONTAINEROF_MORESAFE macro to enable this extra check
on the type of member. Not really happy with the name.
Could be something related to the version of spice-protocol expected works
out?

diff --git a/spice/macros.h b/spice/macros.h
index 2efbaff..06bbd20 100644
--- a/spice/macros.h
+++ b/spice/macros.h
@@ -143,7 +143,8 @@
     ((long) ((uint8_t*) &((struct_type*) 0)->member))
 #endif
 
-#if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#if defined(__GNUC__) && defined(SPICE_CONTAINEROF_MORESAFE) && \
+    (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
 #define SPICE_CONTAINEROF(ptr, struct_type, member) ({ \
     const typeof( ((struct_type *)0)->member ) *__mptr = (ptr);    \
     ((struct_type *)(void *)((uint8_t *)(__mptr) - SPICE_OFFSETOF(struct_type, member))); })
-- 
2.5.0



More information about the Spice-devel mailing list