GNOME Bugzilla – Bug 597737
to_array produces wrong array
Last modified: 2010-08-02 14:57:19 UTC
Every second item is 0 in the returned array.
Created attachment 144995 [details] Test case The output of this test program is: 0 0 1 0 2 0 3 0 4 0 Actually, it should be the numbers 0 to 9
Hmm. Works for me (x86, vala from git). Please provide your architecture and vala version. % cat test.vala using Gee; static void main (string[] args) { ArrayList<uint> l = new ArrayList<uint> (); for (int i=0; i<10; i++) l.add(i); uint[] a = (uint[])l.to_array (); foreach (uint i in a) stdout.printf ("%u\n", i); } % valac --vapidir ../gee --pkg gee-1.0 test.vala % ./test 0 1 2 3 4 5 6 7 8 9
Ops. I forgot to ask: - Does all tests run correctly - Does it runs ok with vala from git
I'm using vala from git (a3327d98475f66a01b16e990faa6b836ab6d6c73). The tests do pass fine.
Forgot to mention, my architecture is 64bit.
(In reply to comment #5) > Forgot to mention, my architecture is 64bit. Ok. I'll check the case on 64-bits. However as I need to access a shared shell account at university I need to ask for permission first. May be other developer (if I can call myself a libgee dev) will respond quicker but I haven't seen them recently.
Ok. I reproduced with char. IMHO vala tries to threat G[] as (sizeof(void *))[] - which in some cases (char, *int on 64-bit system etc.) is wrong. I belive it's vala bug but I'll do furthr invastigation if it should be workaround in libgee or vala.
Known limitation of generics support, see bug 568972.
I have a workaround for some months in my local repository, but I hesitate to push it because: 1) It is a dirty hack; that workaround is using private to_array variants for all the possible primitive types 2) Valac still requests for the (primitive-type[]) cast Please tell me your opinion whether you think it would be worth it to: 1) add the workaround to make it work whatever type G is, 2) or document that it can't work for primitive types
If the bug in Vala isn't fixed soon, I'd prefer the workaround.
BTW: The cast is not necessary anymore in Vala master. However, it's still only working for pointer-based element types without hack due to limitations of the pointer based generics API. It is working properly in the experimental dova backend.
commit 3199e7a5d999cc5b3120593f073d4a39943b6ef1 Author: Didier 'Ptitjes <ptitjes@free.fr> Date: Mon Aug 2 16:50:39 2010 +0200 Implement typed variants for Collection.to_array Fixes bug 597737.