Hey!

I think I have run in to a strange bug, with either vala or glib, and
I'd like to check if I'm doing something wrong.

My library versions:
    valac --version:          Vala 0.9.7.143
    dpkg -l 'libglib2.0-0':   2.24.1-0ubuntu

Attached is a test case that illustrates the problem I am having, but
basically when I use an integer as a generic argument, I get really
strange results on 64bits while on 32bits everything works well.

Thanks for any help!
Sam

These are the outputs I get when I try and run the program:


Compiled with: valac -X -m64 generic-array.vala
        Original:       1 4 8 2 

Array Slice
        Not Boxed:      1 0 4 0 
        Boxed:          1 4 8 2 

For-loop Copy
        Not Boxed:      1 0 4 0 
        Boxed:          1 4 8 2


---------

Compiled with: valac -X -m32 generic-array.vala
        Original:       1 4 8 2 

Array Slice
        Not Boxed:      1 4 8 2 
        Boxed:          1 4 8 2 

For-loop Copy
        Not Boxed:      1 4 8 2 
        Boxed:          1 4 8 2


public class TestClass<G>
{
	private G[] _buffer = new G[30];
	private int _count = 0;
	
	public void add(owned G item)
	{
		_buffer[_count++] = (owned) item;
	}
	
	public G @get(int index)
	{
		return _buffer[index];
	}
	
	public G[] to_array()
	{
		return _buffer[0:_count];
	}
	
	public G[] to_array_alt()
	{
		G[] temp = new G[_count];
		
		for (int ii = 0; ii < _count; ii++)
			temp[ii] = _buffer[ii];
			
		return temp;
	}
}

private void print_array0(int[] array)
{
	stdout.printf("\tOriginal:\t");
	foreach (int i in array)
		stdout.printf("%d ", i);
	stdout.printf("\n");
}

private void print_array1(int[] array)
{
	stdout.printf("\tNot Boxed:\t");
	foreach (int i in array)
		stdout.printf("%d ", i);
	stdout.printf("\n");
}

private void print_array2(int?[] array)
{
	stdout.printf("\tBoxed:\t\t");
	foreach (int? i in array)
		stdout.printf("%d ", (!)i);
	stdout.printf("\n");
}

public int main(string[] args)
{
	int[] original = {1, 4, 8, 2};
	TestClass<int> not_boxed = new TestClass<int>();
	TestClass<int?> boxed = new TestClass<int?>();
	
	foreach (int i in original)
	{
		not_boxed.add(i);
		boxed.add(i);
	}

	
	print_array0(original);

	stdout.printf("\n");
	
	stdout.printf("Array Slice\n");
	print_array1(not_boxed.to_array());
	print_array2(boxed.to_array());
	
	stdout.printf("\n");
	
	stdout.printf("For-loop Copy\n");
	print_array1(not_boxed.to_array_alt());
	print_array2(boxed.to_array_alt());
	
	return 0;
}
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to