Skip to content
  • Benjamin Berg's avatar
    source: Fix source finalization in some corner cases · 08bc3ace
    Benjamin Berg authored and Arjan Molenaar's avatar Arjan Molenaar committed
    GLib will call the finalize handler when the GSource is destroyed. We
    already enforce destruction from __del__, however, the final reference
    might only be dropped later on because the main context (or something
    else) is holding another reference. The main case where this happens is
    if the source is pending at the time, e.g. if it is being destroyed
    while it is dispatching.
    
    After destroy is called on the source, the only callback that can still
    be called is finalize. As such, we can simply call finalize immediately
    and rely on GLib cleaning up the underlying GSource at a later point.
    
    Note that it can also happen that __del__ is not called at all if the
    interpreter quits. In this case, neither __del__ nor finalize will be
    called even though the underlying GSource may be finalized correctly.
    Compared to the previous behaviour this is a big improvement, as it
    would crash previously.
    08bc3ace