GNOME Bugzilla – Bug 659305
GObject properties, null terminated string array doesn't work
Last modified: 2018-05-22 14:09:55 UTC
Created attachment 196792 [details] Code to show the bug If a gobject property is a null terminated array of string, it behaves as if it was not null terminated (see attached code, that I compile with "valac -H header.h -C header.vala") It produces C functions like: void test_array_set_null_terminated_array (TestArray* self, gchar** value, int value_length1); But it is not logical, it should produce functions like: void test_array_set_null_terminated_array (TestArray* self, gchar** value); The length argument is not needed since the array must be null terminated.
Even if the array is null terminated, it's nothing bad to have a length. So the problem is not that vala adds the length, but it's whether you explicitly want to _not_ have a length and vala fails. I assume the bug is about the latter.
Hum ok, my problem is that I want to make a C API which already exists (we wanted to do some modifications to GtkAbotuDialog in Vala, with the function set_authors for instance, we are stuck). But I think vala should just not put the length when the array is null terminated... or maybe there is another flag to say to valac that we don't want it ?
Using [CCode (array_length = false, array_null_terminated = true)] should work for bindings. Can you confirm?
Yes, it works for the .vapi. (but as shown in the example code, it doesn't work to generate .h)
This bug is particularly nasty in that it can lead to very hard-to-debug situations. I've got a constructor like: public Foo (string[] some_str_array) { Object (str_array: some_str_array); } In some tests, the value of str-array was turning out to be {"abc", "def", "123", "456"}. The first two values were from a pre-defined array of common valid values. But the second two values were from a completely different array that wasn't even being used in the construction of the object. So I burned a bit of time on this until I realized that it was a freak accident due to some_str_array not being NULL-terminated,
This is a limitation of Vala. If property use a GLib collection, like GQueue, or Gee one, this shouldn't be a problem. So I would like to suggest this bug to be changed to enhancement and Target 1.2 instead.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/232.