Re: closure floating



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.

> 
> Havoc
>     

---
ciaoTJ






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]