Transferring ownership of inline-allocated array
Test case 1:
Vala code:
void main() {
string arr[3];
(owned)arr;
}
Generated C code:
void
_vala_main (void)
{
gchar* arr[3] = {0};
gchar* _tmp0_[3];
gint _tmp0__length1;
memcpy (_tmp0_, arr, 3 * sizeof (gchar*));
arr = NULL;
_vala_array_destroy (_tmp0_, 3, (GDestroyNotify) g_free);
_vala_array_destroy (arr, 3, (GDestroyNotify) g_free);
}
The line arr = NULL
is invalid since arr
is an array.
If int
is used instead of string
here, valac emits an error instead:
test.vala:3.5-3.14: error: No reference to be transferred
(owned)arr;
^^^^^^^^^^
Test case 2:
Vala code:
void func(string[] arr) {
}
void main() {
string arr[3];
func((owned)arr);
}
makes valac fail with a cryptic internal error:
error: internal error: invalid array_length for given dimension
Compilation failed: 1 error(s), 0 warning(s)
Expected outcome
If transferring ownership of inline arrays should be allowed at all, the source array should be memset
to 0.