On Thu, Mar 25, 2010 at 04:23:02PM +0100, Julian Andres Klode wrote:
> Hi,
> 
> string[] properties are not installed via g_object_class_install_property (),

Proposed patch attached.

-- 
http://www.debian.org - The Universal Operating System
From 8f940dd9f74831a56937162a45a1a45c1c8ef62f Mon Sep 17 00:00:00 2001
From: Luca Bruno <[email protected]>
Date: Tue, 30 Mar 2010 12:40:56 +0200
Subject: [PATCH] Support string[] (G_TYPE_STRV) properties for GObject.

---
 codegen/valagobjectmodule.vala |   45 +++++++++++++++++++++++++++++++++------
 codegen/valagtypemodule.vala   |    3 ++
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index bf5c94d..1566c7f 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -189,6 +189,7 @@ internal class Vala.GObjectModule : GTypeModule {
 		block.add_statement (cdecl);
 
 		bool boxed_declared = false;
+		bool length_declared = false;
 
 		var cswitch = new CCodeSwitchStatement (new CCodeIdentifier ("property_id"));
 		var props = cl.get_properties ();
@@ -242,6 +243,17 @@ internal class Vala.GObjectModule : GTypeModule {
 			} else {
 				ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_%s".printf (prefix, prop.name)));
 				ccall.add_argument (cself);
+				var array_type = prop.property_type as ArrayType;
+				if (array_type != null && array_type.element_type.data_type == string_type.data_type) {
+					// G_TYPE_STRV
+					if (!length_declared) {
+						cdecl = new CCodeDeclaration ("int");
+						cdecl.add_declarator (new CCodeVariableDeclarator ("length"));
+						block.add_statement (cdecl);
+						length_declared = true;
+					}
+					ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("length")));
+				}
 				var csetcall = new CCodeFunctionCall ();
 				if (prop.get_accessor.value_type.value_owned) {
 					csetcall.call = head.get_value_taker_function (prop.property_type);
@@ -281,6 +293,8 @@ internal class Vala.GObjectModule : GTypeModule {
 		var cdecl = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
 		cdecl.add_declarator (new CCodeVariableDeclarator ("self", ccall));
 		block.add_statement (cdecl);
+
+		var boxed_declared = false;
 		
 		var cswitch = new CCodeSwitchStatement (new CCodeIdentifier ("property_id"));
 		var props = cl.get_properties ();
@@ -311,14 +325,31 @@ internal class Vala.GObjectModule : GTypeModule {
 			cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
 			ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_set_%s".printf (prefix, prop.name)));
 			ccall.add_argument (cself);
-			var cgetcall = new CCodeFunctionCall ();
-			if (prop.property_type.data_type != null) {
-				cgetcall.call = new CCodeIdentifier (prop.property_type.data_type.get_get_value_function ());
+			if (prop.property_type is ArrayType && ((ArrayType)prop.property_type).element_type.data_type == string_type.data_type) {
+				if (!boxed_declared) {
+					cdecl = new CCodeDeclaration ("gpointer");
+					cdecl.add_declarator (new CCodeVariableDeclarator ("boxed"));
+					block.add_statement (cdecl);
+					boxed_declared = true;
+				}
+				var cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_boxed"));
+				cgetcall.add_argument (new CCodeIdentifier ("value"));
+				cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("boxed"), cgetcall)));
+				ccall.add_argument (new CCodeIdentifier ("boxed"));
+
+				var cstrvlen = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
+				cstrvlen.add_argument (new CCodeIdentifier ("boxed"));
+				ccall.add_argument (cstrvlen);
 			} else {
-				cgetcall.call = new CCodeIdentifier ("g_value_get_pointer");
+				var cgetcall = new CCodeFunctionCall ();
+				if (prop.property_type.data_type != null) {
+					cgetcall.call = new CCodeIdentifier (prop.property_type.data_type.get_get_value_function ());
+				} else {
+					cgetcall.call = new CCodeIdentifier ("g_value_get_pointer");
+				}
+				cgetcall.add_argument (new CCodeIdentifier ("value"));
+				ccall.add_argument (cgetcall);
 			}
-			cgetcall.add_argument (new CCodeIdentifier ("value"));
-			ccall.add_argument (cgetcall);
 			cswitch.add_statement (new CCodeExpressionStatement (ccall));
 			cswitch.add_statement (new CCodeBreakStatement ());
 		}
@@ -721,7 +752,7 @@ internal class Vala.GObjectModule : GTypeModule {
 			return false;
 		}
 
-		if (prop.property_type is ArrayType) {
+		if (prop.property_type is ArrayType && ((ArrayType)prop.property_type).element_type.data_type != string_type.data_type) {
 			return false;
 		}
 
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 21f57b0..d241d17 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1774,6 +1774,9 @@ internal class Vala.GTypeModule : GErrorModule {
 				cspec.call = new CCodeIdentifier ("g_param_spec_boxed");
 				cspec.add_argument (new CCodeIdentifier (st.get_type_id ()));
 			}
+		} else if (prop.property_type is ArrayType && ((ArrayType)prop.property_type).element_type.data_type == string_type.data_type) {
+			cspec.call = new CCodeIdentifier ("g_param_spec_boxed");
+			cspec.add_argument (new CCodeIdentifier ("G_TYPE_STRV"));
 		} else {
 			cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
 		}
-- 
1.7.0

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to