Tue, 09 Jul 2024 02:03:20 -0500
Fix incompatible pointer types for GtkItemFactoryCallbacks on gcc-14
The GtkItemFactoryEntry struct callback is of type GtkItemFactoryCallbacks
(aka void (*)(void)) but is initialised with GtkItemFactoryCallback1 types
(aka void (*)(void *, guint, GtkWidget *)).
This is coherent with the gtk-2 documentation:
> gtk_item_factory_create_items(..., GtkItemFactoryEntry *entries,...)
> entries : an array of GtkItemFactoryEntrys whose callback members must by of
> type GtkItemFactoryCallback1
But, under gcc-14, the implicit cast from GtkItemFactoryCallback1 to
GtkItemFactoryCallback triggers an incompatible-pointer-types error (See [gcc-doc]).
An exemple of this error:
pidgin/gtkconv.c:3096:66: error: initialization of 'void (*)(void)' from incompatible pointer type 'void (*)(void *, guint, GtkWidget *)' {aka 'void (*)(void *, unsigned int, struct _GtkWidget *)'} [-Wincompatible-pointer-types]
3096 | { N_("/Conversation/New Instant _Message..."), "<CTL>M", menu_new_conv_cb,
| ^~~~~~~~~~~~~~~~
pidgin/gtkconv.c:3096:66: note: (near initialization for 'menu_items[1].callback')
To fix this, explicitely cast to GtkItemFactoryCallback where needed.
[0]: https://gcc.gnu.org/gcc-14/porting_to.html#incompatible-pointer-types
Testing Done:
Built with gcc-14, started and clicked on some affected menus
Reviewed at https://reviews.imfreedom.org/r/3282/
#!/bin/sh if [ $# -eq 0 ]; then echo "Usage: `basename "$0"` PurpleFoo..." echo echo "This script searches the *current working directory* and replaces casts" echo "with GObject-style type checking and casting macros." echo 'For example, "(PurpleBuddy *)b" becomes "PURPLE_BUDDY(b)".' exit 0 fi for struct in $* ; do cast=`echo $struct | sed "s|[A-Z]|_\0|g" | tr "a-z" "A-Z" | sed "s|^_||"` for file in `grep -rl "([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)" . --include=*.c --exclude=purple-client-bindings.c` ; do sed -i "s|([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)[[:space:]]*(|$cast(|g" $file sed -i "s|([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)[[:space:]]*\([^(][^,);]*\)|$cast(\1)|g" $file done done