gsource: clarify restrictions on non-existant IDs
authorRyan Lortie <desrt@desrt.ca>
Tue, 16 Sep 2014 23:40:30 +0000 (19:40 -0400)
committerRyan Lortie <desrt@desrt.ca>
Fri, 19 Sep 2014 17:39:00 +0000 (13:39 -0400)
commit1cbdbef77209fe82239bd10f062425491cf256ae
treebb7df5c596ce4bd2cb93585c38dad5bcdd0f82a2
parent7db1baf59078c667ac1ae43f839b2b1866e65a87
gsource: clarify restrictions on non-existant IDs

Document that one must not use the "by id" source APIs with non-existent
IDs.  The real justification behind this restriction is that the reuse
of source ids makes it unsafe to call these functions unless you're
absolutely sure that the source exists and it belongs to you.  If you
call one of these functions on a source that may already have been
removed then you run the risk of finding someone else's source (with
your reused id).

This also bails us out of a slightly tricky situation with respect to
the threadsafety of g_main_context_find_source_by_id().  The fact that
this function doesn't return a reference implies that its return value
cannot be safely accessed unless we already know for sure that a
reference is being held elsewhere (by example, by the main context
itself if we know that the source has not been removed).  The function
itself, however, performs an access to the value, which could result in
a crash.

If we mandate that it is only valid to call this function on
known-to-exist source IDs then we dodge this problem.

https://bugzilla.gnome.org/show_bug.cgi?id=736683
glib/gmain.c