Re: [Vala] Patch: libgee:get_weak_ref



On Fri, 2008-11-21 at 21:03 +0100, Jürg Billeter wrote:
On Fri, 2008-11-21 at 02:59 -0500, Yu Feng wrote:
On Wed, 2008-11-19 at 18:26 -0500, Yu Feng wrote:
When the collections in Gee are holding strong references, it is
difficult to obtain a weak reference to the elements in the container.

The situation is:

class Node {
  Gee.List<Node> childNodes;
  public Node? firstChild {
          get {
                  return childNodes.get(0);
////// panic! the signature of properties are weak!.
          }
  }

}

A better alternative is to modify the signature of 'get' directly to
weak.

I understand your issue but I don't think that we should change the
return value of `get' to weak as this would make it impossible to
generate values in an iterator, for example.
I don't understand. Can you give an example? I am not using a local copy
with weak get. and everything works perfectly.


An alternative is to default property getters to non-weak, this would
also solve similar issues in other situations. Any objections?

Strong objections come from me. 

The return values of properties shouldn't be strong by default.

0. weak or not in the property declarition describes the behavior of the
property instead of the behavior of the getter and setters. A weak
property holds a weak reference to the object; a strong property holds a
strong reference to the object. No implications on the return values of
the getters.

1. Current way keeps the consistency between getter setter properties
and member variable properties. Think about you have 
   class A {
        public Object foo;
   }
        A a = new A();
I am free to create weak reference to A.foo by
   weak Object ref = a.foo;
and also strong reference to A.foo by
   Object ref = a.foo;

If I later on add setter and getters for foo, both code still work. New
way will fail the weak one.

2. Think about gluing the vala library with other c programs. Most GTK
property getters return a weak reference; although the property itself
holds a reference.

Yu


Jürg





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