Re: [Vala] Fwd: Re: GenericArray problem



Thanks for the very detailed response, Evan.  I have filed a bug
accordingly.

In the meantime a simple [Compact] vala implementation of the generic array
functionality I need appears to take fewer cpu cycles than GenericArray
(when optimised) when tested with a few operation patterns, so it's not a
stopper issue for me, and the derivation works fine in that case.

On Sun, Oct 18, 2015 at 5:25 AM, Evan Nemerson <evan coeus-group com> wrote:

On Sun, 2015-10-18 at 00:13 +1100, Andy Lees wrote:
I wonder if anyone has suggestions as to why GenericArray should
demonstrate this behaviour?

The types in GLib aren't designed for inheritance.  Due to restrictions
in the C API it can never be fully functional, so it is generally
better to use composition.

That said, this specific case *could* work with a bit of work in the
compiler.  Support for inheriting from a compact class which uses
simple generics in the constructor (a fairly uncommon thing to do) is,
apparently, a bit buggy.  Specifically, the generic free function isn't
passed.  It would be great if you filed a bug about this.

Also I note that the doco for GenericArray indicates that it takes a
defaulted initial size parameter, but it appears that it just ain't
so -
giving an initial size causes a compilation error on too many args.

If you take a look at the VAPI, you'll notice it looks like this:

    #if GLIB_2_30
    [CCode (cname = "g_ptr_array_new_full", simple_generics = true)]
    public GenericArray (uint reserved_size = 0);
    #else
    [CCode (cname = "g_ptr_array_new_with_free_func", simple_generics =
    true)]
    public GenericArray ();
    #endif

The version with the reserved_size argument is only available if you
target a version of glib >= 2.30, which makes sense given that
g_ptr_array_new_full was only added in glib 2.30.

Pass --target-glib=2.30 (or greater) to valac and the extra argument
will work.

I believe valadoc.org produces documentation which assumes you are
targeting the current stable version of glib.  Unfortunately it's not
really possible to produce output which contains both versions without
substantial changes to the parser in libvala, so a choice had to be
made.  Targeting the current stable version seemed like the best
approach.


On Sat, Oct 17, 2015 at 11:58 PM, Daniel Espinosa <esodan gmail com>
wrote:

---------- Mensaje reenviado ----------
De: "Daniel Espinosa" <esodan gmail com>
Fecha: oct. 17, 2015 7:58 AM
Asunto: Re: [Vala] GenericArray problem
Para: "Andy Lees" <andrewl oz gmail com>
Cc:

In LibreSCL (www.librescl.org) I just declare an empty class
derived from
a
generic one, this makes to call

var a = new Intclass ();

Just works.

If you want a binding friendly class definition you should define
your own
get/set methods returning the actual value type not a generic, as
in:


https://github.com/powerwaremediacore/librescl/blob/master/librescl
/tDA.vala

I plan to add iterator methods to collections, this will allow
bindings to
use them on loops. Because we relay on Gee, its iterators are
generic
making hard/impossible to use on GObject Introspection bindings.
El oct. 16, 2015 6:22 PM, "Andy Lees" <andrewl oz gmail com>
escribió:

Hi,

If I declare a derived class of GenericArray, like so:

public class IntArray : GenericArray<int> {
  public IntArray() {
  }
}

I get a gcc error, like so:
/tmp/a.vala.AH856X.c: In function ‘int_array_new’:
/tmp/a.vala.AH856X.c:66:2: error: too few arguments to function
‘g_ptr_array_new_with_free_func’
  self = (IntArray*) g_ptr_array_new_with_free_func ();

whereas with Array (for example) it just works.

Is there something I'm doing wrong, or is this a bug?

Using Vala 0.30.0

Regards,

Andrew Lees
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list

_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list

_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list



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