[vala] Fix GStrv properties in bindings



commit 29b96d273dd7966072bbf1f848f1bf86571ca70c
Author: Jürg Billeter <j bitron ch>
Date:   Sun Jun 28 22:18:25 2009 +0200

    Fix GStrv properties in bindings
    
    Fixes bug 587068.

 codegen/valaccodearraymodule.vala        |    7 +++++--
 codegen/valaccodebasemodule.vala         |    2 +-
 codegen/valaccodememberaccessmodule.vala |    2 +-
 vala/valacodewriter.vala                 |   12 +++++++++++-
 vala/valaproperty.vala                   |   10 ++++++++++
 vapi/gio-2.0.vapi                        |    1 +
 vapi/gtk+-2.0.vapi                       |    4 ++++
 vapi/gtksourceview-2.0.vapi              |    4 ++++
 vapigen/valagidlparser.vala              |    7 ++++++-
 9 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 5ba2acf..ceba7d6 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -274,8 +274,11 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 				ccall.add_argument (new CCodeIdentifier (constant.get_cname ()));
 				return ccall;
 			} else if (array_expr.symbol_reference is Property) {
-				Gee.List<CCodeExpression> size = array_expr.get_array_sizes ();
-				return size[dim - 1];
+				var prop = (Property) array_expr.symbol_reference;
+				if (!prop.no_array_length) {
+					Gee.List<CCodeExpression> size = array_expr.get_array_sizes ();
+					return size[dim - 1];
+				}
 			}
 		} else if (array_expr is NullLiteral) {
 			return new CCodeConstant ("0");
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 23d0568..e926e92 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3803,7 +3803,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 		ccall.add_argument (cexpr);
 
 		var array_type = prop.property_type as ArrayType;
-		if (array_type != null && rhs != null) {
+		if (array_type != null && !prop.no_array_length && rhs != null) {
 			for (int dim = 1; dim <= array_type.rank; dim++) {
 				ccall.add_argument (head.get_array_length_cexpression (rhs, dim));
 			}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 0c03446..4bfd916 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -259,7 +259,7 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					expr.ccodenode = ccomma;
 				} else {
 					var array_type = base_property.property_type as ArrayType;
-					if (array_type != null) {
+					if (array_type != null && !base_property.no_array_length) {
 						for (int dim = 1; dim <= array_type.rank; dim++) {
 							var temp_var = get_temp_variable (int_type);
 							var ctemp = new CCodeIdentifier (temp_var.name);
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 72ba348..b924c84 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -917,7 +917,17 @@ public class Vala.CodeWriter : CodeVisitor {
 			write_indent ();
 			write_string ("[NoAccessorMethod]");
 		}
-		
+		if (prop.property_type is ArrayType && prop.no_array_length) {
+			write_indent ();
+			write_string ("[CCode (array_length = false");
+
+			if (prop.array_null_terminated) {
+				write_string (", array_null_terminated = true");
+			}
+
+			write_string (")]");
+		}
+
 		write_indent ();
 		write_accessibility (prop);
 
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index e00510c..e807410 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -146,6 +146,10 @@ public class Vala.Property : Member, Lockable {
 	 */
 	public Expression default_expression { get; set; }
 
+	public bool no_array_length { get; set; }
+
+	public bool array_null_terminated { get; set; }
+
 	/**
 	 * Nickname of this property.
 	 */
@@ -266,6 +270,12 @@ public class Vala.Property : Member, Lockable {
 		if (a.has_argument ("notify")) {
 			notify = a.get_bool ("notify");
 		}
+		if (a.has_argument ("array_length")) {
+			no_array_length = !a.get_bool ("array_length");
+		}
+		if (a.has_argument ("array_null_terminated")) {
+			array_null_terminated = a.get_bool ("array_null_terminated");
+		}
 	}
 
 	/**
diff --git a/vapi/gio-2.0.vapi b/vapi/gio-2.0.vapi
index 960868f..a6c907f 100644
--- a/vapi/gio-2.0.vapi
+++ b/vapi/gio-2.0.vapi
@@ -584,6 +584,7 @@ namespace GLib {
 		[CCode (type = "GIcon*", has_construct_function = false)]
 		public ThemedIcon.with_default_fallbacks (string iconname);
 		public string name { construct; }
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] names { get; construct; }
 		[NoAccessorMethod]
 		public bool use_default_fallbacks { get; construct; }
diff --git a/vapi/gtk+-2.0.vapi b/vapi/gtk+-2.0.vapi
index e9da662..83f5711 100644
--- a/vapi/gtk+-2.0.vapi
+++ b/vapi/gtk+-2.0.vapi
@@ -36,10 +36,13 @@ namespace Gtk {
 		public void set_website (string website);
 		public void set_website_label (string website_label);
 		public void set_wrap_license (bool wrap_license);
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] artists { get; set; }
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] authors { get; set; }
 		public string comments { get; set; }
 		public string copyright { get; set; }
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] documenters { get; set; }
 		public string license { get; set; }
 		public Gdk.Pixbuf logo { get; set; }
@@ -3249,6 +3252,7 @@ namespace Gtk {
 		public void set_value (double value);
 		public Gtk.Adjustment adjustment { get; set; }
 		[NoAccessorMethod]
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] icons { owned get; set; }
 		[NoAccessorMethod]
 		public Gtk.IconSize size { get; set; }
diff --git a/vapi/gtksourceview-2.0.vapi b/vapi/gtksourceview-2.0.vapi
index aeeee24..e7c0f8d 100644
--- a/vapi/gtksourceview-2.0.vapi
+++ b/vapi/gtksourceview-2.0.vapi
@@ -68,7 +68,9 @@ namespace Gtk {
 		[CCode (has_construct_function = false)]
 		public SourceLanguageManager ();
 		public void set_search_path ([CCode (array_length = false)] string[]? dirs);
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] language_ids { get; }
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] search_path { get; set; }
 	}
 	[CCode (cheader_filename = "gtksourceview/gtksourceview.h")]
@@ -193,7 +195,9 @@ namespace Gtk {
 		public SourceStyleSchemeManager ();
 		public void prepend_search_path (string path);
 		public void set_search_path (string path);
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] scheme_ids { get; }
+		[CCode (array_length = false, array_null_terminated = true)]
 		public string[] search_path { get; set; }
 	}
 	[CCode (cheader_filename = "gtksourceview/gtksourceview.h")]
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index dd8d82d..281019b 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -1722,7 +1722,12 @@ public class Vala.GIdlParser : CodeVisitor {
 		var prop = new Property (fix_prop_name (node.name), parse_type (prop_node.type), null, null, current_source_reference);
 		prop.access = SymbolAccessibility.PUBLIC;
 		prop.interface_only = true;
-		
+
+		if (prop_node.type.is_interface && prop_node.type.interface == "GStrv") {
+			prop.no_array_length = true;
+			prop.array_null_terminated = true;
+		}
+
 		if (prop_node.readable) {
 			prop.get_accessor = new PropertyAccessor (true, false, false, prop.property_type.copy (), null, null);
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]