Re: closure floating
- From: Owen Taylor <otaylor redhat com>
 
- To: gtk-devel-list gnome org
 
- Subject: Re: closure floating
 
- Date: 16 Jan 2001 23:05:18 -0500
 
Tim Janik <timj gtk org> writes:
> On 16 Jan 2001, Havoc Pennington wrote:
> 
> > 
> > Hi,
> > 
> 
> > Comment in the source code indicates that we are avoiding ref count of
> > 0, but you may as well use ref count of 0 - the semantics are the
> > same:
> 
> right, except that a literal 0 refcount breaks our assertions.
> 
> >     GClosure*
> >     g_closure_ref (GClosure *closure)
> >     {
> >       g_return_val_if_fail (closure != NULL, NULL);
> >       g_return_val_if_fail (closure->ref_count > 0, NULL);
> >       g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
> > 
> >       /* floating is basically a kludge to avoid creating closures
> >        * with a ref_count of 0. so the first one doing _ref() will
> >        * own the closure's initial ref_count
> >        */
> >       if (closure->floating)
> >         closure->floating = FALSE;
> >       else
> >         closure->ref_count += 1;
> > 
> >       return closure;
> >     }
> > 
> > Can you give some rationale for this behavior?
> 
> it is not yet clear where exactly closures will end up being
> used, thus who's going to do actuall sinking. we'll probably
> end up with explicit sink calls in places that take callbacks,
> though your first example:
> 
>     closure = g_cclosure_new (func, data, dnotify);
>     gtk_container_foreach (container, closure);
>     /* closure is already finalized at this point */
>     gtk_container_foreach (container, closure);
> 
> will of course still be broken.
I'm of the opinion that setting a closure in a persistant manner -
g_signal_connect_closure(), g_timeout_set_closure(), whatever can sink
the closure. This is much like gtk_container_add(). But simply
_using_ a closure for, say, gtk_container_foreach_closure() -
as an argument to a function call should not not sink the closure.
The operation of 'sink' basically represents transfer of ownershop -
but an operation like g_signal_closure_foreach() should not
retain a refcount to the closure and thus cannot become
the owner of the closure.
Regards,
                                        Owen
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]