Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Thu, 16 Nov 2023 09:56:02 UTC Commit: 09b1558d3496a193d2efdd2f99adcb321743fffb https://github.com/geany/geany/commit/09b1558d3496a193d2efdd2f99adcb321743ff...
Log Message: ----------- 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.
Modified Paths: -------------- src/spawn.c
Modified: src/spawn.c 10 lines changed, 5 insertions(+), 5 deletions(-) =================================================================== @@ -1185,7 +1185,7 @@ gboolean spawn_with_callbacks(const gchar *working_directory, const gchar *comma { SpawnChannelData *sc = &sw->sc[i]; GIOCondition condition; - GSourceFunc callback; + GIOFunc callback;
if (pipe[i] == -1) continue; @@ -1205,15 +1205,15 @@ gboolean spawn_with_callbacks(const gchar *working_directory, const gchar *comma { sc->cb.write = stdin_cb; condition = G_IO_OUT | SPAWN_IO_FAILURE; - callback = (GSourceFunc) spawn_write_cb; + callback = spawn_write_cb; } else { gboolean line_buffered = !(spawn_flags & ((SPAWN_STDOUT_UNBUFFERED >> 1) << i));
condition = G_IO_IN | G_IO_PRI | SPAWN_IO_FAILURE; - callback = (GSourceFunc) spawn_read_cb; + callback = spawn_read_cb;
if (i == 1) { @@ -1245,15 +1245,15 @@ gboolean spawn_with_callbacks(const gchar *working_directory, const gchar *comma else if (i) /* to avoid new string on each call */ sc->buffer = g_string_sized_new(sc->max_length);
- g_source_set_callback(source, callback, sc, spawn_destroy_cb); + g_source_set_callback(source, (GSourceFunc) (void(*)(void)) callback, sc, spawn_destroy_cb); g_source_attach(source, sw->main_context); g_source_unref(source); }
sw->exit_cb = exit_cb; sw->exit_data = exit_data; source = g_child_watch_source_new(pid); - g_source_set_callback(source, (GSourceFunc) spawn_watch_cb, sw, NULL); + g_source_set_callback(source, (GSourceFunc) (void(*)(void)) (GChildWatchFunc) spawn_watch_cb, sw, NULL); g_source_attach(source, sw->main_context); g_source_unref(source);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).