GNOME Bugzilla – Bug 562391
Call dup_array with -1 length.
Last modified: 2008-12-18 00:08:01 UTC
Hi, If i want to use NULL terminated array, the _vala_array_dup%d function is called with -1 args when passing array as argument. Example code : public struct TestStruct { [NoArrayLength] public string[] strings; [NoArrayLength] public TestStruct(string[] strings) { this.strings = strings; } } public int main(string[] args) { string[] strings = { "test" }; TestStruct ts = TestStruct(strings); debug("%s", ts.strings[0]); return 0; } Produced C snippet : void test_struct_init (TestStruct *self, char** strings) { char** _tmp2; char** _tmp1; const char* _tmp0; memset (self, 0, sizeof (TestStruct)); _tmp2 = NULL; _tmp1 = NULL; _tmp0 = NULL; (*self).strings = (_tmp2 = (_tmp1 = strings, (_tmp1 == NULL ? ((gpointer) (_tmp1)) : _vala_array_dup1 (_tmp1, -1))), ((*self).strings = (_vala_array_free ((*self).strings, -1, ((GDestroyNotify) (g_free))), NULL)), _tmp2); } The constructor use _vala_array_dup1 with -1 as length argument. Vala should use a _vala_array_dup_null_terminated variant of _vala_array_dup. Étienne.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of 514186 ***