GNOME Bugzilla – Bug 586162
[PATCH] unusable ByteArray binding
Last modified: 2009-07-26 21:02:48 UTC
ByteArray is actually a struct in C, which has "data" and "len" members. As VAPI can't define proper length variable yet (at least as far as I know), Vala tries to use data_length1, which obviously can't compile. One solution would be to add a CCode property for this (which I don't really know how to do). Another is this simple change that adds an inline method to access the data. (sorry but I don't know how to use diff :( ) [Compact] [CCode (cprefix = "g_byte_array_", free_function = "g_byte_array_free")] public class ByteArray { public ByteArray (); [CCode (cname = "g_byte_array_sized_new")] public ByteArray.sized (uint reserved_size); public void append (uint8[] data); public void prepend (uint8[] data); public void remove_index (uint index); public void remove_index_fast (uint index); public void remove_range (uint index, uint length); public void sort (CompareFunc compare_func); public void sort_with_data (CompareDataFunc compare_func); public void set_size (uint length); private uint len; [CCode (array_length = false, array_null_terminated = false)] private uint8[] data; public unowned uint8[] get_data () { unowned uint8[] tmp = data; tmp.length = (int) len; return tmp; } }
Created attachment 137948 [details] [review] glib-2.0: Make ByteArray.data use ByteArray.len as length. array_length_cname is what you're looking for. Unfortunately, array_length_type seems to be ignored for properties (I've only seen it used for return values). I'll file a bug about that. Meanwhile, valac will expect data.length to be an int, instead of a uint.
Ah, thanks. Someone should really write that CCode attributes down.
Evan, do you have git access? If so please push this patch to git. Otherwise I can do it
Jaap, no, I don't have git access. Thanks.
commit d298e1025327df42b0135a0576196f3c0945bde8 Author: Jaap A. Haitsma <jaap@haitsma.org> Date: Sat Jul 11 18:34:06 2009 +0200 glib-2.0: Make ByteArray.data use ByteArray.len as length. Fixes bug 586162 Patch by Evan Nemerson <evan@polussystems.com>