[Vala] what does # mean in a member method formal parameter?



what does # mean in a member method formal parameter?
Generally, # stands for ownership transfer; But there are some
in-consistence. Consider the following two examples:


1. if I write a library by vala:

class MyHashTable: Object{
  void insert(Object # obj) {
    ..
  }
  static void test {
     MyHashTable h;
     Object o;
     h.insert(o = new Object());
  }
}
I will get 
MyHashTable_test(){
   MyHashTable_insert(g_object_ref(tmp));
}
and 
MyHashTable_insert(GObject *o ){
   ....
   ....
   g_object_unref(o);
}

what happens is during the life time of insert the ownership of 'o' is
guarantted to be held in 'h'; then the reference is removed. The total
effect is the ownership is not transferred to 'h' at all; 

2. Now consider the same .vapi, but a route in GLib:
GHashTable.insert(#key, #obj);

GHashTable h = new GHashTable.full(....,....,g_free, g_object_unref);
h.insert("key", o = new Object());

the code will be 
g_hash_table_insert(g_strdup(key)), g_object_ref(o));

and 'h' will own 'o' until one removes o from the hash table.


The two behaviors are inconsistent. 

I propose to (1) remove the tailing unref code when there is a ownership
transfer tag in the declaration; or (2) to completely ignore the # tag,
and relies on the programmer to explicitly claim a reference of 'o' by
o.ref().

Yu








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