GNOME Bugzilla – Bug 620419
GLib.ObjectClass.list_property's return value should not be unowned
Last modified: 2015-11-22 19:02:33 UTC
Valac version: 0.8.1 From the GLib manual: "g_object_class_list_properties (...) Returns an array of GParamSpec* which should be freed after use." However, vala-generated code does not free the array if the return value is assigned to an unowned variable, and duplicates it if the return value is assigned to an owned variable. I think the return type should be ParamSpec*[], in order to prevent Vala from deleting each element of the array.
Good point, unfortunately vala does not support unowned elements, but only full ownership. Perhaps I'd suggest a "unowned element ParamSpec[]" syntax or such.
Actually, I solved this problem for me by changing line 277 of gobject-1.0.vapi from public unowned ParamSpec[] list_properties (); to public ParamSpec*[] list_properties (); Being an array of pointers, elements are not eventually deleted, but the array is. (You can see it in the C code generated.) The only problem that arises is that you can't use the dot operator: list_properties()[index].name doesn't work, list_properties()[index]->name does. However, assigment works as expected: var params = myclass.list_properties(); ParamSpec p = params[0]; Incidentally, I don't see the point in using the '->' operator instead of '.' for pointers, as pointers themselves should have no members.
commit 35a5c184b32d89718a0611b1f75af21299beac04 Author: Evan Nemerson <evan@nemerson.com> Date: Wed Jun 11 19:41:51 2014 -0700 gobject-2.0: make ObjectClass.list_properties transfer container Fixes bug 620419.
Sigh. Next cycle. commit 3360251a8424aaca5cf8663963969f9b7c447658 Author: Evan Nemerson <evan@nemerson.com> Date: Wed Jun 11 20:37:18 2014 -0700 Revert "gobject-2.0: make ObjectClass.list_properties transfer container" Breaks bootstrapping with valac <= 0.24
The best approach here is to #if VALA_0_26 ... then you could add it now.
(In reply to comment #5) > The best approach here is to #if VALA_0_26 ... then you could add it now. I tried that, it doesn't work.
https://git.gnome.org/browse/vala/commit/?id=6437f63b34cc32d90cd703cef719919e90f5508b