]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support string[] (G_TYPE_STRV) properties for GObject
authorLuca Bruno <lethalman88@gmail.com>
Tue, 30 Mar 2010 10:40:56 +0000 (12:40 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 31 Mar 2010 15:19:45 +0000 (17:19 +0200)
Fixes bug 614355.

codegen/valagobjectmodule.vala
codegen/valagtypemodule.vala

index bf5c94db2d0121ddd171c86fe7c6e33f5e30860f..feadc0745f4090568f07e6c8e695d12243807143 100644 (file)
@@ -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,7 +293,9 @@ 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 ();
                foreach (Property prop in props) {
@@ -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;
                }
 
index bda752ce578b33c085647a4004a97e24fadef687..90d2d720163cd3997ee71434a8ec8b14178c4101 100644 (file)
@@ -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");
                }