Skip to content
  • Christoph Reiter's avatar
    g_binding_unbind: make it more introspection friendly; allow calling it multiple times. Fixes #1373 · 0319dac0
    Christoph Reiter authored
    g_object_bind_property() (transfer none) returns a GBinding with an existing internal
    reference which is active as long as the "binding" is. This allows to optionally use
    the binding without any memory management, as it will remove itself when it is no longer
    needed.
    
    There are currently three ways to remove the "binding" and as a result the reference:
    
    1) Either the source or target dies and we get notified by a weakref callback
    2) The user unrefs the binding until it is destroyed (which is semi-legal,
       but worked and is used in the test suite)
    3) The user calls g_binding_unbind()
    
    In case (3) the problem was that it always calls unref even if the "binding" is already
    gone, leading to crashes when called from bindings multiple times.
    In #1373 and !197 it was noticed that a function always unrefs which would be a
    "transfer full" annotation, but the problem here is that it should only remove the
    ref when removing the "binding" and the annotation should stay "transfer none".
    
    As a side effect of this fix it is now also possible to call g_binding_unbind() multiple
    times where every call after the first is a no-op.
    
    This also adds explicit tests for case (1) and (3) - only case (3) is affected by this change.
    0319dac0