On 2 July 2014 00:21, Chad Versace <chad.vers...@linux.intel.com> wrote: > Emil discovered that MSVC does rejects empty structs with the error > message "C requires that a struct or union has at least one member". > > This patch removes all empty structs from the wcore objects, and > replaces each with a pair of safe typecast functions that provide > bidirectional casting waffle_OBJ <-> wcore_OBJ. > While we cannot use container_of() prior to casting I believe that we should be safe for the time being. Thank you. It works like a charm.
Reviewed-by: Emil Velikov <emil.l.veli...@gmail.com> > Reported-by: Emil Velikov <emil.l.veli...@gmail.com> > Signed-off-by: Chad Versace <chad.vers...@linux.intel.com> > --- > src/waffle/api/waffle_config.c | 2 +- > src/waffle/api/waffle_context.c | 2 +- > src/waffle/api/waffle_display.c | 2 +- > src/waffle/api/waffle_window.c | 2 +- > src/waffle/core/wcore_config.h | 15 +++++++++------ > src/waffle/core/wcore_context.h | 15 +++++++++------ > src/waffle/core/wcore_display.h | 15 +++++++++------ > src/waffle/core/wcore_window.h | 14 ++++++++------ > 8 files changed, 39 insertions(+), 28 deletions(-) > > diff --git a/src/waffle/api/waffle_config.c b/src/waffle/api/waffle_config.c > index 107f07d..01843d9 100644 > --- a/src/waffle/api/waffle_config.c > +++ b/src/waffle/api/waffle_config.c > @@ -56,7 +56,7 @@ waffle_config_choose( > if (!wc_self) > return NULL; > > - return &wc_self->wfl; > + return waffle_config(wc_self); > } > > WAFFLE_API bool > diff --git a/src/waffle/api/waffle_context.c b/src/waffle/api/waffle_context.c > index b246a63..00649ba 100644 > --- a/src/waffle/api/waffle_context.c > +++ b/src/waffle/api/waffle_context.c > @@ -54,7 +54,7 @@ waffle_context_create( > if (!wc_self) > return NULL; > > - return &wc_self->wfl; > + return waffle_context(wc_self); > } > > WAFFLE_API bool > diff --git a/src/waffle/api/waffle_display.c b/src/waffle/api/waffle_display.c > index 9d741e9..fa19462 100644 > --- a/src/waffle/api/waffle_display.c > +++ b/src/waffle/api/waffle_display.c > @@ -42,7 +42,7 @@ waffle_display_connect(const char *name) > if (!wc_self) > return NULL; > > - return &wc_self->wfl; > + return waffle_display(wc_self); > } > > WAFFLE_API bool > diff --git a/src/waffle/api/waffle_window.c b/src/waffle/api/waffle_window.c > index 1dbf823..207ef33 100644 > --- a/src/waffle/api/waffle_window.c > +++ b/src/waffle/api/waffle_window.c > @@ -54,7 +54,7 @@ waffle_window_create( > if (!wc_self) > return NULL; > > - return &wc_self->wfl; > + return waffle_window(wc_self); > } > > WAFFLE_API bool > diff --git a/src/waffle/core/wcore_config.h b/src/waffle/core/wcore_config.h > index 9c3597e..7911f56 100644 > --- a/src/waffle/core/wcore_config.h > +++ b/src/waffle/core/wcore_config.h > @@ -40,17 +40,20 @@ struct wcore_config; > union waffle_native_config; > > struct wcore_config { > - struct waffle_config {} wfl; > struct api_object api; > struct wcore_config_attrs attrs; > - > struct wcore_display *display; > }; > > -DEFINE_CONTAINER_CAST_FUNC(wcore_config, > - struct wcore_config, > - struct waffle_config, > - wfl) > +static inline struct waffle_config* > +waffle_config(struct wcore_config *cfg) { > + return (struct waffle_config*) cfg; > +} > + > +static inline struct wcore_config* > +wcore_config(struct waffle_config *cfg) { > + return (struct wcore_config*) cfg; > +} > > static inline bool > wcore_config_init(struct wcore_config *self, > diff --git a/src/waffle/core/wcore_context.h b/src/waffle/core/wcore_context.h > index 548da50..fb67e4c 100644 > --- a/src/waffle/core/wcore_context.h > +++ b/src/waffle/core/wcore_context.h > @@ -39,16 +39,19 @@ struct wcore_display; > union waffle_native_context; > > struct wcore_context { > - struct waffle_context {} wfl; > struct api_object api; > - > struct wcore_display *display; > }; > > -DEFINE_CONTAINER_CAST_FUNC(wcore_context, > - struct wcore_context, > - struct waffle_context, > - wfl) > +static inline struct waffle_context* > +waffle_context(struct wcore_context *ctx) { > + return (struct waffle_context*) ctx; > +} > + > +static inline struct wcore_context* > +wcore_context(struct waffle_context *ctx) { > + return (struct wcore_context*) ctx; > +} > > static inline bool > wcore_context_init(struct wcore_context *self, > diff --git a/src/waffle/core/wcore_display.h b/src/waffle/core/wcore_display.h > index f67bf03..0b95729 100644 > --- a/src/waffle/core/wcore_display.h > +++ b/src/waffle/core/wcore_display.h > @@ -34,16 +34,19 @@ struct wcore_platform; > union waffle_native_display; > > struct wcore_display { > - struct waffle_display {} wfl; > struct api_object api; > - > struct wcore_platform *platform; > }; > > -DEFINE_CONTAINER_CAST_FUNC(wcore_display, > - struct wcore_display, > - struct waffle_display, > - wfl) > +static inline struct waffle_display* > +waffle_display(struct wcore_display *dpy) { > + return (struct waffle_display*) dpy; > +} > + > +static inline struct wcore_display* > +wcore_display(struct waffle_display *dpy) { > + return (struct wcore_display*) dpy; > +} > > bool > wcore_display_init(struct wcore_display *self, > diff --git a/src/waffle/core/wcore_window.h b/src/waffle/core/wcore_window.h > index fc82111..20a154b 100644 > --- a/src/waffle/core/wcore_window.h > +++ b/src/waffle/core/wcore_window.h > @@ -32,17 +32,19 @@ struct wcore_window; > union waffle_native_window; > > struct wcore_window { > - struct waffle_window {} wfl; > struct api_object api; > - > struct wcore_display *display; > }; > > -DEFINE_CONTAINER_CAST_FUNC(wcore_window, > - struct wcore_window, > - struct waffle_window, > - wfl) > +static inline struct waffle_window* > +waffle_window(struct wcore_window *win) { > + return (struct waffle_window*) win; > +} > > +static inline struct wcore_window* > +wcore_window(struct waffle_window *win) { > + return (struct wcore_window*) win; > +} > > static inline bool > wcore_window_init(struct wcore_window *self, > -- > 2.0.0 > _______________________________________________ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle