[Spice-devel] [PATCH 05/11] make red_pipe_item_init_full more typesafe

Frediano Ziglio fziglio at redhat.com
Mon May 23 09:57:52 UTC 2016


> 
> > > I don't find this very readable, and imo there is not a huge gain in
> > > doing this over a cast... I'd just go with a cast + a static
> > > compile-time assert that RedCursorPipeItem has a 'base' RedPipeItem
> > > field at offset 0.
> > > 
> > 
> > static void cursor_pipe_item_free(RedPipeItem *base)
> > {
> >    spice_return_if_fail(base);
> > 
> >    verify(SPICE_OFFSETOF(RedCursorPipeItem, base) == 0);
> >    RedCursorPipeItem *pipe_item = (RedCursorPipeItem *) base;
> >    ...
> > 
> > (obviously for every cast)
> 
> I'd put it next to the structure definition and forget about it
> 
> typedef struct RedCursorPipeItem {
>     RedPipeItem base;
>     CursorItem *cursor_item;
> } RedCursorPipeItem;
> 
> verify(SPICE_OFFSETOF(RedCursorPipeItem, base) == 0);
> 
> Christophe
> 

You didn't understand the problem, this is not enough
as a refactory of this would require a complete code scan
as currently is (was?) needed, you have to check for every
cast.

Frediano


More information about the Spice-devel mailing list