Silence warnings on appropriate GSourceFunc casts
commit09b1558d3496a193d2efdd2f99adcb321743fffb
authorColomban Wendling <ban@herbesfolles.org>
Tue, 24 Oct 2023 22:58:22 +0000 (25 00:58 +0200)
committerColomban Wendling <ban@herbesfolles.org>
Thu, 16 Nov 2023 09:56:02 +0000 (16 10:56 +0100)
tree3d11c0024f89f37fb36572d77078bccc9e7d103f
parentf3d466a359c9c501d815938602f24dff6ab622ff
Silence warnings on appropriate GSourceFunc casts

`g_source_set_callback()` is a generic API that takes a `GFunc`, but
some specific `GSource`s use other signatures for their callback, so
the cast is valid (given the callback is effectively correct).

Silence warnings from `-Wcast-function-type` by inserting an
intermediate `(void(*)(void))` cast, but keep some type checking by
first casting to the actually wanted type:

    (GSourceFunc) (void(*)(void)) (GChildWatchFunc) spawn_watch_cb

which reads from right to left:

- `spawn_watch_cb`, the callback that should match `GChildWatchFunc`;
- `(GChildWatchFunc)`, which allows the compiler to verify the function
  is effectively compatible with what we know it should be;
- `(void(*)(void))`, dummy cast to silence `-Wcast-function-type`;
- `(GSourceFunc)`, cast to the type expected by the generic API call.

We could use GLib's `G_SOURCE_FUNC()` cast macro to some extent
(everything but the rightmost cast), but it's in 2.58 which is newer
than our target.
src/spawn.c