On Mon, Sep 26, 2022 at 09:50:48AM +0100, Daniel P. Berrangé wrote:
> On Mon, Sep 26, 2022 at 10:18:06AM +0200, Laszlo Ersek wrote:
> > gcc reports:
> > 
> > > gui.c:1795:3: error: missing initializer for field ‘padding’ of
> > > ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
> > > [-Werror=missing-field-initializers]
> > >  1795 |   { "shutdown", activate_action, NULL, NULL, NULL },
> > >
> > > gui.c:1796:3: error: missing initializer for field ‘padding’ of
> > > ‘GActionEntry’ {aka ‘const struct _GActionEntry’}
> > > [-Werror=missing-field-initializers]
> > >  1796 |   { "reboot", activate_action, NULL, NULL, NULL },
> > 
> > I've found this only now because:
> > 
> > - this is the first time I'm building virt-p2v with GTK3,

One of the problems of having several different build axes :-(

> > - the "shutdown_actions" array depends on USE_POPOVERS which depends on
> >   GTK3 being selected,
> > 
> > - the "missing-field-initializers" warning (treated as an error) has
> >   recently been enabled via "-Wextra" in commit 391f9833d398 ("p2v-c.m4:
> >   elicit a stricter set of warnings from gcc", 2022-09-23).
> > 
> > The C-language documentation for GActionEntry is silent on the "padding"
> > array:
> > 
> >   https://docs.gtk.org/gio/struct.ActionEntry.html
> > 
> > However, the D-language docs expose it:
> > 
> >   https://api.gtkd.org/gio.c.types.GActionEntry.html
> > 
> > Provide the missing field initializer.
> > 
> > Signed-off-by: Laszlo Ersek <ler...@redhat.com>
> > ---
> >  gui.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/gui.c b/gui.c
> > index 49301d9a985b..4faaa710ed90 100644
> > --- a/gui.c
> > +++ b/gui.c
> > @@ -1792,8 +1792,8 @@ static gboolean close_running_dialog (GtkWidget *w, 
> > GdkEvent *event, gpointer da
> >  
> >  #ifdef USE_POPOVERS
> >  static const GActionEntry shutdown_actions[] = {
> > -  { "shutdown", activate_action, NULL, NULL, NULL },
> > -  { "reboot", activate_action, NULL, NULL, NULL },
> > +  { "shutdown", activate_action, NULL, NULL, NULL, { 0 } },
> > +  { "reboot", activate_action, NULL, NULL, NULL, { 0 } },
> >  };
> 
> Notice the header decl says 'padding' is private hence why it is
> not documented.
> 
> struct _GActionEntry
> {
>   const gchar *name;
> 
>   void (* activate) (GSimpleAction *action,
>                      GVariant      *parameter,
>                      gpointer       user_data);
> 
>   const gchar *parameter_type;
> 
>   const gchar *state;
> 
>   void (* change_state) (GSimpleAction *action,
>                          GVariant      *value,
>                          gpointer       user_data);
> 
>   /*< private >*/
>   gsize padding[3];
> };
> 
> 
> The purpose of this 'padding' entry is to reserve space in the struct
> for future usage. Apps should never touch the padding field, since it
> can change in future. ie that 3 element array can turn into three
> separate public fields later, and then the compound initializer above
> would be invalid.
> 
> The right way to declare this is using named initializers:
> 
>   { .name = "shutdown", .activate = activate_action },
>   { .name = "reboot", .activate = activate_action },

Yes I agree, if that shuts up the -Wextra warning.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to