summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-04-18 21:01:19 +0200
committerThomas Haller <thaller@redhat.com>2021-04-19 14:47:47 +0200
commit3b4ff77bcdb4fc3bc79ccc955605c686fc243052 (patch)
tree651ff3bc125590a488d93a87f9916da98c00dded
parent29215185b640e47e01bdae3958597a4bda1d89cd (diff)
downloadglib-th/gdbus-doc-unsubscribe-idle.tar.gz
main: document notify function gets called during g_source_destroy()th/gdbus-doc-unsubscribe-idle
This seems non-obvious to me. Document it. It also seems important to know, because it means that the data pointer might already be destroyed, before the source is unreferenced for good. For example, if the data pointer keeps a reference to the GSource, and it might seem sensible to call: g_source_destroy(data->source); g_source_unref(data->source); /* <<< data is already destroyed? */ This leads to a crash, if the source was attached to a context.
-rw-r--r--glib/gmain.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/glib/gmain.c b/glib/gmain.c
index 2e1ab3a25..4fe587a67 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -1370,6 +1370,10 @@ g_source_destroy_internal (GSource *source,
*
* This function is safe to call from any thread, regardless of which thread
* the #GMainContext is running in.
+ *
+ * If the source is currently attached to a #GMainContext, destroying it
+ * will effectively unset the callback similar to calling g_source_set_callback().
+ * This can mean, that the data's #GDestroyNotify gets called right away.
*/
void
g_source_destroy (GSource *source)
@@ -1761,6 +1765,9 @@ g_source_set_callback_indirect (GSource *source,
* It is safe to call this function multiple times on a source which has already
* been attached to a context. The changes will take effect for the next time
* the source is dispatched after this call returns.
+ *
+ * Note that g_source_destroy() for a currently attached source has the effect
+ * of also unsetting the callback.
**/
void
g_source_set_callback (GSource *source,