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 660994 - Add g_main_context_ref_thread_default()
Add g_main_context_ref_thread_default()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-10-05 15:13 UTC by Dan Winship
Modified: 2011-10-07 14:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add g_main_context_ref_thread_default() (23.35 KB, patch)
2011-10-05 15:13 UTC, Dan Winship
committed Details | Review

Description Dan Winship 2011-10-05 15:13:26 UTC
See patch. Unfortunately, just changing _get_thread_default() to not
return NULL would probably break some existing code that was assuming
that behavior. (Eg, see the gsimpleasyncresult.c change.)

I was thinking of adding g_cancellable_ref/g_cancellable_unref as
well, which would allow passing NULL, since there's a lot duplicated
code handling that too. Although maybe it would make sense to add new
GObject methods for that? Or just change the semantics of
g_object_ref/_unref to allow (and ignore) NULL? That wouldn't change
the behavior of any correct program...
Comment 1 Dan Winship 2011-10-05 15:13:29 UTC
Created attachment 198346 [details] [review]
Add g_main_context_ref_thread_default()

Add g_main_context_ref_thread_default(), which already returns a
reffed GMainContext, rather than sometimes returning a (non-reffed)
GMainContext, and sometimes returning NULL. This simplifies the
bookkeeping in any code that needs to keep a reference to the
thread-default context for a while.
Comment 2 Matthias Clasen 2011-10-05 23:18:57 UTC
Review of attachment 198346 [details] [review]:

::: glib/gmain.c
@@ +757,3 @@
+ * (with a ref added to it) rather than returning %NULL.
+ *
+ * Returns: (transfer full): the thread-default #GMainContext

It would be good to add a "Free with g_main_context_unref()" to the return value docs.
Comment 3 Dan Winship 2011-10-07 14:15:23 UTC
Attachment 198346 [details] pushed as 59f1f54 - Add g_main_context_ref_thread_default()