After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 586162 - [PATCH] unusable ByteArray binding
[PATCH] unusable ByteArray binding
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings
unspecified
Other Linux
: Normal major
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-06-17 19:18 UTC by zarevucky.jiri
Modified: 2009-07-26 21:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
glib-2.0: Make ByteArray.data use ByteArray.len as length. (679 bytes, patch)
2009-07-06 23:07 UTC, Evan Nemerson
committed Details | Review

Description zarevucky.jiri 2009-06-17 19:18: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;
		}
	}
Comment 1 Evan Nemerson 2009-07-06 23:07:35 UTC
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.
Comment 2 zarevucky.jiri 2009-07-07 00:11:09 UTC
Ah, thanks. Someone should really write that CCode attributes down.
Comment 3 Jaap A. Haitsma 2009-07-07 06:06:01 UTC
Evan, do you have git access? If so please push this patch to git.
Otherwise I can do it
Comment 4 Evan Nemerson 2009-07-08 19:04:09 UTC
Jaap, no, I don't have git access. Thanks.
Comment 5 Jaap A. Haitsma 2009-07-11 16:36:19 UTC
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>