GNOME Bugzilla – Bug 654753
valac-0.12 incorrectly copies array element before passing it to struct function
Last modified: 2011-07-16 20:45:18 UTC
If you compile and run the attached trivial test program, this will be the output: $ ./test element.data = 42, array[23].data = 0 $ If you look at the intermediate C-code, it's clear what happens: 70 foo_bar (&element); 71 _tmp2_ = array[23]; 72 foo_bar (&_tmp2_); 73 fprintf (stdout, "element.data = %d, array[23].data = %d\n", element.data, array[23].data); So while a single variable will be directly passed (by reference) to the modifying function, an element of an array will first be copied to a temporary variable and a reference to that temporary variable will be passed along. Since only the temporary variable will be modified this won't have any affect on the array. Unless this is the intended behavior, I think vala shouldn't copy structs before passing them to some function when they are elements of an array. At the very least, the behavior should be consistent regardless whether it's an array of structs or a single struct.
Created attachment 192098 [details] test.vala
Created attachment 192099 [details] test.c
commit 29426b0482ca7b2593bf7f19ea83fa91e6beb5b4 Author: Luca Bruno <lucabru@src.gnome.org> Date: Sat Jul 16 22:09:39 2011 +0200 codegen: Use temporary variables in array element access Fixes bug 654753. This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.