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