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 694765 - Can't copy generic GLib.List
Can't copy generic GLib.List
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Generics
0.41.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2013-02-26 20:59 UTC by Zeeshan Ali
Modified: 2018-03-22 14:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: Free generic elements of glib collections (12.52 KB, patch)
2018-03-20 13:08 UTC, Rico Tzschichholz
committed Details | Review

Description Zeeshan Ali 2013-02-26 20:59:32 UTC
The following function:

-------CODE----
    public GLib.List<G> copy_list<G> (GLib.List<G> list) {
        var ret = new  GLib.List<G> ();

        foreach (var item in list)
            ret.prepend (item);
        ret.reverse ();

        return ret;
-----------------

gets me following errors from C compiler:

/extra-data/checkout/gnome/gnome-boxes/src/util-app.vala: In function ‘_g_destroy_func0_’:
/extra-data/checkout/gnome/gnome-boxes/src/util-app.vala:397:28: error: ‘g_destroy_func’ undeclared (first use in this function)
/extra-data/checkout/gnome/gnome-boxes/src/util-app.vala:397:28: note: each undeclared identifier is reported only once for each function it appears in

Had a chat on IRC about this:

<Lethalman> interesting
<Lethalman> seems to not happen with gee
<flo> probably about simple generics
<Lethalman> indeed
<Lethalman> flo, his function is not simple generics, but glib.list is... there must be something wrong in the compiler
<Lethalman> zeenix, it's vala bug obviously
<flo> yes, that's what I thought
<zeenix> ah ok
* zeenix files
<Lethalman> and... I don't see a workaround
<zeenix> i guess i can make it specific to GLib.Object
<Lethalman> either that or write it in C
<Lethalman> zeenix, there's a copy_deep in GList
<Lethalman> but I have no idea how to pass the CopyFunc in vala, I believe we need some compiler support
Comment 1 Zeeshan Ali 2013-02-26 21:11:06 UTC
I thought I'll make the function act on GLib.Object as a workaround but that also gets me into trouble it seems :(

-----CODE---------------
    public GLib.List<GLib.Object> copy_list (GLib.List<GLib.Object> list) {
        var ret = new  GLib.List<GLib.Object> ();

        foreach (var item in list)
            ret.prepend (item);
        ret.reverse ();

        return ret;
    }

...

    private GLib.List<DeviceDriver> get_drivers (DriverTestFunction test_func) {
        var drivers = new GLib.HashTable<string,DeviceDriver> (str_hash, str_equal);
...
        // We can't just return drivers.get_values () as we don't own the list returned by this call
        return copy_list (drivers.get_values ()) as GLib.List<Osinfo.DeviceDriver>;
-------------------

I get the following errors/warnings:

unattended-installer.vala:792.16-792.82: error: Operation not supported for this type
        return copy_list (drivers.get_values ()) as GLib.List<Osinfo.DeviceDriver>;
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

** (valac:2718): CRITICAL **: vala_ccode_base_module_store_temp_value: assertion `initializer != NULL' failed

** (valac:2718): CRITICAL **: vala_ccode_function_add_assignment: assertion `right != NULL' failed
Comment 2 Luca Bruno 2013-02-27 09:05:35 UTC
Don't abuse "as", use a cast.
Comment 3 Zeeshan Ali 2013-02-27 12:45:03 UTC
(In reply to comment #2)
> Don't abuse "as", use a cast.

How is this an abuse?
Comment 4 Rico Tzschichholz 2018-03-20 13:08:21 UTC
Created attachment 369906 [details] [review]
codegen: Free generic elements of glib collections

It needs to be possible to use parameters or fields/properties which hold
dup/free functions for a generic type in scope.

This required to make the destroy_func being a parameter with the benefit
of being able to use g_*_free_all directly and adding a _g_node_free_all
wrapper with a compatible signature.
Comment 5 Rico Tzschichholz 2018-03-22 14:40:34 UTC
Attachment 369906 [details] pushed as e0440ce - codegen: Free generic elements of glib collections