[Spice-devel] [spice-gtk 1/3] build-sys: Disable -Wcast-function-type

Frediano Ziglio fziglio at redhat.com
Thu May 3 11:37:44 UTC 2018


> 
> With gcc 8.0.1 from Fedora 28, I'm getting warnings related to
> -Wcast-function-type in a few places. Most of these could be solved
> by adding an intermediate wrapper with the right number of args, but the
> g_source_set_callback() warning cannot be solved this way as the
> callback signature will vary depending on the source it's called on.
> 
> ../../src/spice-session.c: In function 'spice_session_init':
> ../../src/spice-session.c:293:33: warning: cast between incompatible function
> types from 'pixman_bool_t (*)(pixman_image_t *)' {aka 'int (*)(union
> pixman_image *)'} to 'void (*)(void *)' [-Wcast-function-type]
>      s->images = cache_image_new((GDestroyNotify)pixman_image_unref);
>                                  ^
> ../../src/gio-coroutine.c: In function 'g_coroutine_socket_wait':
> ../../src/gio-coroutine.c:59:32: warning: cast between incompatible function
> types from 'gboolean (*)(GSocket *, GIOCondition,  void *)' {aka 'int
> (*)(struct _GSocket *, enum <anonymous>,  void *)'} to 'gboolean (*)(void
> *)' {aka 'int (*)(void *)'} [-Wcast-function-type]
>      g_source_set_callback(src, (GSourceFunc)g_io_wait_helper, self, NULL);
>                                 ^
> ../../src/spice-channel.c: In function 'spice_channel_iterate_read':
> ../../src/spice-channel.c:2342:36: warning: cast between incompatible
> function types from 'void (*)(SpiceChannel *, SpiceMsgIn *)' {aka 'void
> (*)(struct _SpiceChannel *, struct _SpiceMsgIn *)'} to 'void
> (*)(SpiceChannel *, SpiceMsgIn *, void *)' {aka 'void (*)(struct
> _SpiceChannel *, struct _SpiceMsgIn *, void *)'} [-Wcast-function-type]
>                                     (handler_msg_in)SPICE_CHANNEL_GET_CLASS(channel)->handle_msg,
>                                     NULL);
>                                     ^
> ../../src/spice-channel.c: In function 'channel_reset':
> ../../src/spice-channel.c:2838:37: warning: cast between incompatible
> function types from 'void (*)(SpiceMsgOut *)' {aka 'void (*)(struct
> _SpiceMsgOut *)'} to 'void (*)(void *, void *)' [-Wcast-function-type]
>      g_queue_foreach(&c->xmit_queue, (GFunc)spice_msg_out_unref, NULL);
>                                      ^
> ../../src/channel-usbredir.c: In function 'try_write_compress_LZ4':
> ../../src/channel-usbredir.c:714:42: warning: cast between incompatible
> function types from 'void (*)(void *)' to 'void (*)(uint8_t *, void *)' {aka
> 'void (*)(unsigned char *, void *)'} [-Wcast-function-type]
>                                           (spice_marshaller_item_free_func)g_free,
>                                           ^
> ../../src/channel-smartcard.c: In function
> 'spice_smartcard_channel_finalize':
> ../../src/channel-smartcard.c:167:43: warning: cast between incompatible
> function types from 'void (*)(SpiceSmartcardChannelMessage *)' {aka 'void
> (*)(struct _SpiceSmartcardChannelMessage *)'} to 'void (*)(void *, void *)'
> [-Wcast-function-type]
>          g_queue_foreach(c->message_queue, (GFunc)smartcard_message_free,
>          NULL);
>                                            ^
> ../../src/channel-smartcard.c: In function 'spice_smartcard_channel_reset':
> ../../src/channel-smartcard.c:187:43: warning: cast between incompatible
> function types from 'void (*)(SpiceSmartcardChannelMessage *)' {aka 'void
> (*)(struct _SpiceSmartcardChannelMessage *)'} to 'void (*)(void *, void *)'
> [-Wcast-function-type]
>          g_queue_foreach(c->message_queue, (GFunc)smartcard_message_free,
>          NULL);
>                                            ^
> In file included from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
>                  from /usr/include/glib-2.0/glib.h:32,
>                  from /usr/include/glib-2.0/gobject/gbinding.h:28,
>                  from /usr/include/glib-2.0/glib-object.h:23,
>                  from ../../src/smartcard-manager.c:20:
> ../../src/smartcard-manager.c: In function 'spice_smartcard_manager_get':
> ../../src/smartcard-manager.c:250:19: warning: cast between incompatible
> function types from 'SpiceSmartcardManager * (*)(void)' {aka 'struct
> _SpiceSmartcardManager * (*)(void)'} to 'void * (*)(void *)'
> [-Wcast-function-type]
>                    (GThreadFunc)spice_smartcard_manager_new,
>                    ^
> /usr/include/glib-2.0/glib/gthread.h:243:26: note: in definition of macro
> 'g_once'
>     g_once_impl ((once), (func), (arg)))
>                           ^~~~
> ../../src/smartcard-manager.c: In function 'smartcard_source_dispatch':
> ../../src/smartcard-manager.c:333:46: warning: cast between incompatible
> function types from 'GSourceFunc' {aka 'int (*)(void *)'} to 'gboolean
> (*)(VEvent *, void *)' {aka 'int (*)(struct VEventStruct *, void *)'}
> [-Wcast-function-type]
>      SmartcardSourceFunc smartcard_callback = (SmartcardSourceFunc)callback;
>                                               ^
> ../../src/smartcard-manager.c: In function 'smartcard_monitor_add':
> ../../src/smartcard-manager.c:379:35: warning: cast between incompatible
> function types from 'SmartcardSourceFunc' {aka 'int (*)(struct VEventStruct
> *, void *)'} to 'gboolean (*)(void *)' {aka 'int (*)(void *)'}
> [-Wcast-function-type]
>      g_source_set_callback(source, (GSourceFunc)callback, user_data, NULL);
>                                    ^
> In file included from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
>                  from /usr/include/glib-2.0/glib.h:32,
>                  from /usr/include/glib-2.0/gobject/gbinding.h:28,
>                  from /usr/include/glib-2.0/glib-object.h:23,
>                  from ../../src/smartcard-manager.c:20:
> ../../src/smartcard-manager.c: In function 'smartcard_manager_init_helper':
> ../../src/smartcard-manager.c:484:12: warning: cast between incompatible
> function types from 'gboolean (*)(SmartcardManagerInitArgs *)' {aka 'int
> (*)(struct <anonymous> *)'} to 'void * (*)(void *)' [-Wcast-function-type]
>             (GThreadFunc)smartcard_manager_init,
>             ^
> /usr/include/glib-2.0/glib/gthread.h:243:26: note: in definition of macro
> 'g_once'
>     g_once_impl ((once), (func), (arg)))
>                           ^~~~
> ../../src/usb-device-manager.c: In function 'channel_new':
> ../../src/usb-device-manager.c:861:42: warning: cast between incompatible
> function types from 'void (*)(void *)' to 'void (*)(void *, GObject *)' {aka
> 'void (*)(void *, struct _GObject *)'} [-Wcast-function-type]
>      g_object_weak_ref(G_OBJECT(channel), (GWeakNotify)g_object_unref, self);
>                                           ^
> ../../src/spice-widget.c: In function 'spice_display_get_pixbuf':
> ../../src/spice-widget.c:3150:40: warning: cast between incompatible function
> types from 'void (*)(void *)' to 'void (*)(guchar *, void *)' {aka 'void
> (*)(unsigned char *, void *)'} [-Wcast-function-type]
>                                         (GdkPixbufDestroyNotify)g_free,
>                                         NULL);
>                                         ^
> ../../src/spice-widget.c:3178:43: warning: cast between incompatible function
> types from 'void (*)(void *)' to 'void (*)(guchar *, void *)' {aka 'void
> (*)(unsigned char *, void *)'} [-Wcast-function-type]
>                                            (GdkPixbufDestroyNotify)g_free,
>                                            NULL);
>                                            ^

Maybe not reporting all warnings but just the head ?
I think is clear too.

> ---
>  m4/spice-compile-warnings.m4 | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/m4/spice-compile-warnings.m4 b/m4/spice-compile-warnings.m4
> index dfa88fe3..0ae3bd78 100644
> --- a/m4/spice-compile-warnings.m4
> +++ b/m4/spice-compile-warnings.m4
> @@ -86,6 +86,11 @@ AC_DEFUN([SPICE_COMPILE_WARNINGS],[
>      # We use some deprecated functions to avoid #ifdef hell while
>      maintaining
>      # compat with older gtk / glib versions
>      gl_WARN_ADD([-Wno-error=deprecated-declarations])
> +    # g_source_set_callback() can't be compatible with this warning. Its API
> +    # doc states:
> +    # "The exact type of func depends on the type of source; ie. you should
> +    # not count on func being called with data as its first parameter."
> +    gl_WARN_ADD([-Wno-cast-function-type])
>  
>  

Frediano


More information about the Spice-devel mailing list