Accessing a fixed-size array in a struct will copy the struct
@naxuroqa
Submitted by naxuroqa Link to original bug (#734957)
Description
struct Options {
uint8 data[256];
}
int main(string[] args) {
Options options = Options();
string foo = "hello, world";
Memory.copy(options.data, foo, foo.length);
return 0;
}
results in
...
gint _vala_main (gchar** args, int args_length1) {
gint result = 0;
Options options = {0};
gchar* foo = NULL;
gchar* _tmp0_ = NULL;
Options _tmp1_ = {0};
gint _tmp2_ = 0;
gint _tmp3_ = 0;
memset (&options, 0, sizeof (Options));
_tmp0_ = g_strdup ("hello, world");
foo = _tmp0_;
_tmp1_ = options;
_tmp2_ = strlen (foo);
_tmp3_ = _tmp2_;
memcpy (_tmp1_.data, foo, (gsize) _tmp3_);
result = 0;
_g_free0 (foo);
return result;
}
...
Which copies the struct and memcpys to the duplicate.
Memory.copy(*(&options.data), foo, foo.length);
does the right, but seems to me like a terrible workaround.
Version: 0.24.x
Edited by Rico Tzschichholz