mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-05 15:38:44 +02:00
gbinding: drop obsolete code in weak_unbind()
At the time when this code was added ([1]), the code and the comment was correct. g_object_run_dispose() did not clear GWeakRef. That was later adjusted to clear them ([2]), but at various times it was not ensured that the GWeakRef was cleared *before* the weak notification is emitted. This is now fixed, and the checks for "where_the_object_was" are no longer necessary. Drop them. I considered to keep the checks just to be extra safe. But we need to rely on how g_object_run_dispose() works in detail. By now there is a test that checks GWeakRef are cleared before emitting the notifications, so we should not accidentally mess this up and the code is no longer needed. [1] commite82eb490fe
('Handle the case of g_object_run_dispose() in GBinding') [2] commita7262d6357
('gobject: Cleanup weak locations data as part of dispose')
This commit is contained in:
@@ -387,31 +387,10 @@ weak_unbind (gpointer user_data,
|
||||
source = g_weak_ref_get (&context->source);
|
||||
target = g_weak_ref_get (&context->target);
|
||||
|
||||
/* If this is called then either the source or target or both must be in the
|
||||
* process of being disposed. If this happens as part of g_object_unref()
|
||||
* then the weak references are actually cleared, otherwise if disposing
|
||||
* happens as part of g_object_run_dispose() then they would still point to
|
||||
* the disposed object.
|
||||
*
|
||||
* If the object this is being called for is either the source or the target
|
||||
* and we actually got a strong reference to it nonetheless (see above),
|
||||
* then signal handlers and weak notifies for it are already disconnected
|
||||
* and they must not be disconnected a second time. Instead simply clear the
|
||||
* weak reference and be done with it.
|
||||
*
|
||||
* See https://gitlab.gnome.org/GNOME/glib/-/issues/2266 */
|
||||
|
||||
if (source == where_the_object_was)
|
||||
{
|
||||
g_weak_ref_set (&context->source, NULL);
|
||||
g_clear_object (&source);
|
||||
}
|
||||
|
||||
if (target == where_the_object_was)
|
||||
{
|
||||
g_weak_ref_set (&context->target, NULL);
|
||||
g_clear_object (&target);
|
||||
}
|
||||
/* FIXME: note that another thread might (at this point) race to call
|
||||
* g_object_run_dispose(). In that case, unbind_internal_locked() will
|
||||
* also try to unref the weak notifications and we get a double
|
||||
* binding_context_unref(). */
|
||||
|
||||
binding_was_removed = unbind_internal_locked (context, binding, source, target);
|
||||
|
||||
|
Reference in New Issue
Block a user