After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 620419 - GLib.ObjectClass.list_property's return value should not be unowned
GLib.ObjectClass.list_property's return value should not be unowned
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings: GLib
0.8.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on: 571486
Blocks:
 
 
Reported: 2010-06-02 23:55 UTC by kastel88
Modified: 2015-11-22 19:02 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description kastel88 2010-06-02 23:55:52 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.
Comment 1 Luca Bruno 2010-06-03 07:16:15 UTC
Good point, unfortunately vala does not support unowned elements, but only full ownership. Perhaps I'd suggest a "unowned element ParamSpec[]" syntax or such.
Comment 2 kastel88 2010-06-03 15:17:13 UTC
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.
Comment 3 Evan Nemerson 2014-06-12 02:43:22 UTC
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.
Comment 4 Evan Nemerson 2014-06-12 03:40:47 UTC
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
Comment 5 Luca Bruno 2014-06-12 07:37:18 UTC
The best approach here is to #if VALA_0_26 ... then you could add it now.
Comment 6 Evan Nemerson 2014-06-12 07:40:53 UTC
(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.