[Spice-devel] [PATCH] macros: make SPICE_CONTAINEROF more typesafe
Jonathon Jongsma
jjongsma at redhat.com
Thu Dec 3 08:23:48 PST 2015
On Thu, 2015-12-03 at 10:52 -0500, Frediano Ziglio wrote:
> >
> > On Thu, 2015-12-03 at 15:28 +0000, Frediano Ziglio wrote:
> > > Check the pointer given is the same type as member pointer.
> > >
> >
> > maybe mention here that this uses a gcc extension:
> > https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
> >
>
> Kind of an additional line like:
>
> "This works using gcc compiler."
I just thought It was would be useful to point to the documentation for the gcc
extension since I was not familiar with it.
>
> ?
>
> >
> > > 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.
> >
> > Did it uncover some bugs, or?
> >
>
> Not in the actual (master) code but is some later patches in the refactory
> branch yes.
>
> >
> > >
> > >
> > > 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)))
> >
> >
> > Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
> >
>
> Frediano
More information about the Spice-devel
mailing list