After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 737259 - gcancellable: Clarify that GSources hold references to GCancellables
gcancellable: Clarify that GSources hold references to GCancellables
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-09-24 13:07 UTC by Philip Withnall
Modified: 2014-10-27 13:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gcancellable: Clarify that GSources hold references to GCancellables (1.21 KB, patch)
2014-09-24 13:07 UTC, Philip Withnall
none Details | Review
gcancellable: Clarify that GSources hold references to GCancellables (1.04 KB, patch)
2014-10-27 09:45 UTC, Philip Withnall
committed Details | Review
gmain: Document convention of strong refs in GSources (1.03 KB, patch)
2014-10-27 09:45 UTC, Philip Withnall
rejected Details | Review

Description Philip Withnall 2014-09-24 13:07:41 UTC
Trivial documentation patch attached.
Comment 1 Philip Withnall 2014-09-24 13:07:44 UTC
Created attachment 286975 [details] [review]
gcancellable: Clarify that GSources hold references to GCancellables

Clarify in the documentation that a GSource created with
g_cancellable_source_new() must be explicitly removed from its
GMainContext before the GCancellable can be finalised.

This could be a common way of leaking GCancellables.
Comment 2 Dan Winship 2014-09-24 13:37:24 UTC
Comment on attachment 286975 [details] [review]
gcancellable: Clarify that GSources hold references to GCancellables

>+ * The new #GSource will hold a reference to the #GCancellable, so will not be
>+ * automatically destroyed when your last reference to the #GCancellable is
>+ * dropped, and instead must be explicitly removed from its #GMainContext.

I'm fine with "The new #GSource will hold a reference to the #GCancellable", but the rest of the text seems to imply that this behavior is unexpected, which I don't think it is. (Are there any GSources that *don't* behave this way?)
Comment 3 Philip Withnall 2014-09-24 13:55:28 UTC
(In reply to comment #2)
> (From update of attachment 286975 [details] [review])
> >+ * The new #GSource will hold a reference to the #GCancellable, so will not be
> >+ * automatically destroyed when your last reference to the #GCancellable is
> >+ * dropped, and instead must be explicitly removed from its #GMainContext.
> 
> I'm fine with "The new #GSource will hold a reference to the #GCancellable",
> but the rest of the text seems to imply that this behavior is unexpected, which
> I don't think it is. (Are there any GSources that *don't* behave this way?)

Hmm, I guess my thought when I first started using GCancellableSource* was that it would act as a weak notifier for the GCancellable so, yes, I assumed it would automatically destroy itself when the GCancellable went away. None of the other GSources document their reference behaviour either, so (unless I’m missing some documentation somewhere) there is no precedent there.

And the behaviour doesn’t necessarily become clear as soon as you start using GCancellable either, since GCancellables don’t generally get cancelled often.

*I’m just cleaning up and checking some code from that period, which is how I came across this docs omission.
Comment 4 Philip Withnall 2014-10-20 07:47:56 UTC
Ping?
Comment 5 Dan Winship 2014-10-26 15:10:35 UTC
As I said, I'm find pointing out that the source holds a ref on the cancellable, but I don't think the docs should imply that this is unexpected.
Comment 6 Philip Withnall 2014-10-27 09:45:10 UTC
Created attachment 289392 [details] [review]
gcancellable: Clarify that GSources hold references to GCancellables

Clarify in the documentation that a GSource created with
g_cancellable_source_new() must be explicitly removed from its
GMainContext before the GCancellable can be finalised.

This could be a common way of leaking GCancellables.
Comment 7 Philip Withnall 2014-10-27 09:45:14 UTC
Created attachment 289393 [details] [review]
gmain: Document convention of strong refs in GSources

By convention, any GSource which holds a pointer to another GObject
always holds a strong reference. Document that.
Comment 8 Matthias Clasen 2014-10-27 12:46:45 UTC
tbh, I don't think any of this needs pointing out. this is just how reference counting works. Adding excessive detail like this to the docs in places only serves to muddle the picture and saw doubts in the minds of the reader: 'wait, does it work this way only if the docs point it out ?!'. No, it doesn't. It works this way everywhere. And that is why it doesn't need random documentation additions.
Comment 9 Allison Karlitskaya (desrt) 2014-10-27 13:15:45 UTC
Review of attachment 289392 [details] [review]:

This one is fine.
Comment 10 Allison Karlitskaya (desrt) 2014-10-27 13:16:05 UTC
Review of attachment 289393 [details] [review]:

This is probably too much indeed.
Comment 11 Philip Withnall 2014-10-27 13:20:19 UTC
(In reply to comment #8)
> tbh, I don't think any of this needs pointing out. this is just how reference
> counting works. Adding excessive detail like this to the docs in places only
> serves to muddle the picture and saw doubts in the minds of the reader: 'wait,
> does it work this way only if the docs point it out ?!'. No, it doesn't. It
> works this way everywhere. And that is why it doesn't need random documentation
> additions.

Sure, normal reference counting doesn’t need pointing out. The problem here is that the relationship between GCancellable and GCancellableSource is unclear, and hence the strength of the refs is unclear.

GCancellableSource is effectively a notifier for GCancellable, and so I think it’s quite reasonable for someone to expect it to be destroyed when the GCancellable it’s watching is destroyed. So it clarifies the picture to make it explicit that it’s not the case.
Comment 12 Philip Withnall 2014-10-27 13:38:34 UTC
Sorted.

Attachment 289392 [details] pushed as 203fe3b - gcancellable: Clarify that GSources hold references to GCancellables