[Spice-devel] [PATCH] macros: make SPICE_CONTAINEROF more typesafe
Christophe Fergeau
cfergeau at redhat.com
Tue Jan 12 06:58:45 PST 2016
Hey,
I just realized that this patch breaks the build of spice 0.12.6 (and
earlier). I don't think upgrading spice-protocol should cause such
breakage, if we can't turn this to a warning, I would revert the patch
(or wrap it in some #ifdef SPICE_STRICT_TYPE_CHECK)
Christophe
On Thu, Dec 03, 2015 at 03:28:09PM +0000, Frediano Ziglio wrote:
> Check the pointer given is the same type as member pointer.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> spice/macros.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
>
> Note that some spice-server need some update in order to compile after
> this macro change.
>
>
> diff --git a/spice/macros.h b/spice/macros.h
> index cd63528..2efbaff 100644
> --- a/spice/macros.h
> +++ b/spice/macros.h
> @@ -143,8 +143,14 @@
> ((long) ((uint8_t*) &((struct_type*) 0)->member))
> #endif
>
> +#if __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))); })
> +#else
> #define SPICE_CONTAINEROF(ptr, struct_type, member) \
> ((struct_type *)(void *)((uint8_t *)(ptr) - SPICE_OFFSETOF(struct_type, member)))
> +#endif
>
> #define SPICE_MEMBER_P(struct_p, struct_offset) \
> ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
> --
> 2.4.3
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20160112/00e30b1e/attachment.sig>
More information about the Spice-devel
mailing list