It's both an error from you and valac.

1)
List<...> values = hash.get_values();
That should be unowned, because the documentation clearly stated that
it is owned by the hash table.
"a GList containing all the values inside the hash table. The content
of the list is owned by the hash table and should not be modified or
freed. Use g_list_free() when done using the list."

2) Valac should warn you against assigning an unowned list to an owned list.



On Sun, Jan 16, 2011 at 4:09 AM,  <[email protected]> wrote:
> Hi!
>
>
>
> I just used the HashTable-Function get_values in one of my programs and 
> noticed, that the returned List-Object becomes deleted at the end of the 
> function where I am using it - that's ok - but the values also become deleted 
> / unreferenced.
>
> I think that this is not ok, because the values do not get referenced by the 
> get_values function.
>
> One example:
>
>
>
> void test(HashTable<...> hash)
>
> {
>
>  /* At this point all values in hash have reference count 1 */
>
>  List<...> values = hash.get_values();
>
>  /* At this point all values in hash have still reference count 1 */
>
>  ... CODE ...
>
>  /* At the end of the function the method __g_list_free_g_object_unref0 
> (hash); is called in the c code */
>
>  /* __g_list_free_g_object_unref0 unrefs all objects in values -> they have 
> reference count 0 now and become deleted */
>
> }
>
>
>
> Now my question - is my code wrong? Should I insert an unowned for the 
> values-variable? Or is the API wrong? Or is this an error in the GLib?
>
>
>
> Gerhard
> _______________________________________________
> vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
>
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to