mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 20:06:18 +01:00
gmain: Warn when g_source_remove() fails
Trying to remove a non-existent source should really be a programming error, as the programmer could be trying to use the wrong function to remove a callback, as seen when GtkScrolledWindow tried to remove ID from another function using g_source_remove(). See https://bugzilla.gnome.org/show_bug.cgi?id=710666#c12 https://bugzilla.gnome.org/show_bug.cgi?id=710724
This commit is contained in:
parent
fe7069749f
commit
a919be3d39
17
glib/gmain.c
17
glib/gmain.c
@ -2181,16 +2181,19 @@ g_main_context_find_source_by_user_data (GMainContext *context,
|
|||||||
* @tag: the ID of the source to remove.
|
* @tag: the ID of the source to remove.
|
||||||
*
|
*
|
||||||
* Removes the source with the given id from the default main context.
|
* Removes the source with the given id from the default main context.
|
||||||
* The id of
|
*
|
||||||
* a #GSource is given by g_source_get_id(), or will be returned by the
|
* The id of a #GSource is given by g_source_get_id(), or will be
|
||||||
* functions g_source_attach(), g_idle_add(), g_idle_add_full(),
|
* returned by the functions g_source_attach(), g_idle_add(),
|
||||||
* g_timeout_add(), g_timeout_add_full(), g_child_watch_add(),
|
* g_idle_add_full(), g_timeout_add(), g_timeout_add_full(),
|
||||||
* g_child_watch_add_full(), g_io_add_watch(), and g_io_add_watch_full().
|
* g_child_watch_add(), g_child_watch_add_full(), g_io_add_watch(), and
|
||||||
|
* g_io_add_watch_full().
|
||||||
*
|
*
|
||||||
* See also g_source_destroy(). You must use g_source_destroy() for sources
|
* See also g_source_destroy(). You must use g_source_destroy() for sources
|
||||||
* added to a non-default main context.
|
* added to a non-default main context.
|
||||||
*
|
*
|
||||||
* Return value: %TRUE if the source was found and removed.
|
* It is a programmer error to attempt to remove a non-existent source.
|
||||||
|
*
|
||||||
|
* Return value: For historical reasons, this function always returns %TRUE
|
||||||
**/
|
**/
|
||||||
gboolean
|
gboolean
|
||||||
g_source_remove (guint tag)
|
g_source_remove (guint tag)
|
||||||
@ -2202,6 +2205,8 @@ g_source_remove (guint tag)
|
|||||||
source = g_main_context_find_source_by_id (NULL, tag);
|
source = g_main_context_find_source_by_id (NULL, tag);
|
||||||
if (source)
|
if (source)
|
||||||
g_source_destroy (source);
|
g_source_destroy (source);
|
||||||
|
else
|
||||||
|
g_critical ("Source ID %u was not found when attempting to remove it", tag);
|
||||||
|
|
||||||
return source != NULL;
|
return source != NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user