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 597737 - to_array produces wrong array
to_array produces wrong array
Status: RESOLVED FIXED
Product: libgee
Classification: Platform
Component: general
0.5.x
Other Linux
: Normal blocker
: ---
Assigned To: libgee-maint
libgee-maint
Depends on:
Blocks:
 
 
Reported: 2009-10-07 21:25 UTC by Sebastian Pölsterl
Modified: 2010-08-02 14:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (219 bytes, text/plain)
2009-10-07 21:27 UTC, Sebastian Pölsterl
Details

Description Sebastian Pölsterl 2009-10-07 21:25:39 UTC
Every second item is 0 in the returned array.
Comment 1 Sebastian Pölsterl 2009-10-07 21:27:10 UTC
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
Comment 2 Maciej (Matthew) Piechotka 2009-10-07 21:45:16 UTC
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
Comment 3 Maciej (Matthew) Piechotka 2009-10-07 21:46:49 UTC
Ops. I forgot to ask:
- Does all tests run correctly
- Does it runs ok with vala from git
Comment 4 Sebastian Pölsterl 2009-10-07 22:15:23 UTC
I'm using vala from git (a3327d98475f66a01b16e990faa6b836ab6d6c73).
The tests do pass fine.
Comment 5 Sebastian Pölsterl 2009-10-07 22:16:12 UTC
Forgot to mention, my architecture is 64bit.
Comment 6 Maciej (Matthew) Piechotka 2009-10-07 22:33:04 UTC
(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.
Comment 7 Maciej (Matthew) Piechotka 2009-10-08 07:00:23 UTC
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.
Comment 8 Jürg Billeter 2009-10-08 07:26:08 UTC
Known limitation of generics support, see bug 568972.
Comment 9 Didier "Ptitjes" 2009-10-08 08:15:19 UTC
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
Comment 10 Sebastian Pölsterl 2009-10-08 08:41:13 UTC
If the bug in Vala isn't fixed soon, I'd prefer the workaround.
Comment 11 Jürg Billeter 2010-03-23 07:12:25 UTC
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.
Comment 12 Didier "Ptitjes" 2010-08-02 14:57:19 UTC
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.