]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Add default_value for CType to initialize variables if needed
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 30 Dec 2018 17:19:44 +0000 (18:19 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 21 Jan 2019 16:51:49 +0000 (17:51 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/724

codegen/valaccodebasemodule.vala
codegen/valaccodemethodcallmodule.vala
codegen/valactype.vala
codegen/valagtypemodule.vala

index 2e77ea30d6a64f50c617afa7133710f333980409..32ca7f349f4071cb4ed57de4700958c3ab444f81 100644 (file)
@@ -6331,6 +6331,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return new CCodeConstant ("NULL");
                } else if (type is ErrorType) {
                        return new CCodeConstant ("NULL");
+               } else if (type is CType) {
+                       return new CCodeConstant (((CType) type).cdefault_value);
                }
                return null;
        }
index 81381896b05a84bf5281d110af69efb2e2291714..a3f6030cabbdc62f7af6f24d20a7bf0cf76c8498 100644 (file)
@@ -437,7 +437,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                                        var array_type = (ArrayType) param.variable_type;
                                                        var array_length_type = int_type;
                                                        if (get_ccode_array_length_type (param) != null) {
-                                                               array_length_type = new CType (get_ccode_array_length_type (param));
+                                                               array_length_type = new CType (get_ccode_array_length_type (param), "0");
                                                        }
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
                                                                var temp_array_length = get_temp_variable (array_length_type);
@@ -531,7 +531,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                        if (get_ccode_array_length_type (m) == null) {
                                                temp_var = get_temp_variable (int_type, true, null, true);
                                        } else {
-                                               temp_var = get_temp_variable (new CType (get_ccode_array_length_type (m)), true, null, true);
+                                               temp_var = get_temp_variable (new CType (get_ccode_array_length_type (m), "0"), true, null, true);
                                        }
                                        var temp_ref = get_variable_cexpression (temp_var.name);
 
index 1190299cb8a143a82f7f722c627a25a51a54b725..88894069e1decaf0683884e6321d30cf89adb28c 100644 (file)
@@ -29,11 +29,17 @@ public class Vala.CType : DataType {
         */
        public string ctype_name { get; set; }
 
-       public CType (string ctype_name) {
+       /**
+        * The default value of the C type.
+        */
+       public string cdefault_value { get; set; }
+
+       public CType (string ctype_name, string cdefault_value) {
                this.ctype_name = ctype_name;
+               this.cdefault_value = cdefault_value;
        }
 
        public override DataType copy () {
-               return new CType (ctype_name);
+               return new CType (ctype_name, cdefault_value);
        }
 }
index 6b3dfa2b2ddf56d99e51ac5db18d6a37ad7ad1c1..603590aff2fae8b76e1674e45054f6c066c77a29 100644 (file)
@@ -2367,7 +2367,7 @@ public class Vala.GTypeModule : GErrorModule {
                        expr.value_type.value_owned = true;
                        set_cvalue (expr, to_string);
                } else {
-                       var temp_var = get_temp_variable (new CType (is_flags ? "GFlagsValue*" : "GEnumValue*"), false, expr, false);
+                       var temp_var = get_temp_variable (new CType (is_flags ? "GFlagsValue*" : "GEnumValue*", "NULL"), false, expr, false);
                        emit_temp_var (temp_var);
 
                        var class_ref = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_ref"));