Laszlo Ersek
2022-Sep-26 08:18 UTC
[Libguestfs] [p2v PATCH 1/7] "shutdown_actions": suppress "missing initializer" warnings/errors
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, - 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 <lersek at 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 } }, }; #endif
Daniel P. Berrangé
2022-Sep-26 08:50 UTC
[Libguestfs] [p2v PATCH 1/7] "shutdown_actions": suppress "missing initializer" warnings/errors
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, > > - 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 <lersek at 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 }, With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|