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 654753 - valac-0.12 incorrectly copies array element before passing it to struct function
valac-0.12 incorrectly copies array element before passing it to struct function
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.12.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-07-16 19:34 UTC by Alexander Kurtz
Modified: 2011-07-16 20:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test.vala (255 bytes, text/plain)
2011-07-16 19:35 UTC, Alexander Kurtz
Details
test.c (1.52 KB, text/plain)
2011-07-16 19:35 UTC, Alexander Kurtz
Details

Description Alexander Kurtz 2011-07-16 19:34:30 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.
Comment 1 Alexander Kurtz 2011-07-16 19:35:03 UTC
Created attachment 192098 [details]
test.vala
Comment 2 Alexander Kurtz 2011-07-16 19:35:36 UTC
Created attachment 192099 [details]
test.c
Comment 3 Luca Bruno 2011-07-16 20:45:18 UTC
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.