GNOME Bugzilla – Bug 660994
Add g_main_context_ref_thread_default()
Last modified: 2011-10-07 14:15: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...
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.
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.
Attachment 198346 [details] pushed as 59f1f54 - Add g_main_context_ref_thread_default()