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 519597 - Passing array from method call as argument breaks array length
Passing array from method call as argument breaks array length
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.1.x
Other All
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-02-29 19:19 UTC by Jürg Billeter
Modified: 2008-11-12 20:48 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jürg Billeter 2008-02-29 19:19:55 UTC
Test case:

class Test {
  public static void foo(char[] bar) {
    GLib.stdout.printf("%d\n", bar.length);
  }

  public static char[] bar() {
    return new char[16];
  }

  public static int main(string[] args) {
    var baz = bar();
    foo(baz);
    foo(bar());

    return 0;
  }
}

nemequ@desktop:~$ ./test
16
0

Generated C:

    test_foo ((_tmp3 = test_bar (&_tmp2)), _tmp2);

Instead, the C code should be as follows, as C doesn't guarantee that function arguments are evaluated in a specific order:

    ((_tmp3 = test_bar (&_tmp2)), test_foo (_tmp3, _tmp2));
Comment 1 Jürg Billeter 2008-03-01 10:39:51 UTC
2008-03-01  Jürg Billeter  <j@bitron.ch>

	* gobject/valaccodegeneratorinvocationexpression.vala: fix argument
	  dependency in the C code for array and delegate arguments,
	  fixes bug 519597

	* tests/arrays.vala: test array argument

Fixed in r1073.