Re: Sinkability: usefull in language bindings ? [was: Re: Sinkability considered harmful]

muppet wrote:
For a plain GObject:

   $pixbuf = Gtk2::Gdk::Pixbuf->new (...);

- C function returns object with one reference.
- wrapper adds one reference.
- binding knows that this function is a constructor, so it removes
  one reference to ensure that the wrapper is the sole owner.


   $pixbuf = $pixbuf_loader->get_pixbuf;  # you don't own the return yet!

- C function returns object with n refs.
- wrapper adds one reference.

Contrast this with a GtkObject:

   $button = Gtk2::Button->new ("hi");

breaks down into

- C function returns object with one floating ref
- wrapper refs and sinks, becoming sole owner.


   $child = $widget->get_child;

breaks down into

- C function returns sunken object with n refs.
- wrapper refs and sinks.  was already sunk, so sink does nothing, and
  C object gets another ref owned by the wrapper.

Excuse me but I still dont register, why can you assume that
a function returning a GtkObject cant return an added reference ?

The function could be a factory function that may decide to
return a fresh GtkObject, or alternatively return you an added
reference to a shared singleton GtkObject (for a random example).


Note that I make the assumption that you want to garbage collect
your wrapped objects when they run out of context or whatever
appropriate time.

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