]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Support null elements in GenericArray
authorJürg Billeter <j@bitron.ch>
Fri, 22 Oct 2010 11:26:54 +0000 (13:26 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 23 Oct 2010 16:11:46 +0000 (18:11 +0200)
codegen/valaccodebasemodule.vala

index e37416fc48e13ed64a76c8d83700e344d8dbb975..e921ac3e4c1755c5e491324698af5e1cadec6f13 100644 (file)
@@ -2675,40 +2675,46 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                return destroy_func;
        }
 
-       public CCodeExpression? get_destroy_func_expression (DataType type, bool is_chainup = false) {
-               if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type)) {
-                       // create wrapper function to free list elements if necessary
+       public CCodeExpression? get_destroy0_func_expression (DataType type, bool is_chainup = false) {
+               var element_destroy_func_expression = get_destroy_func_expression (type, is_chainup);
 
-                       bool elements_require_free = false;
-                       CCodeExpression element_destroy_func_expression = null;
+               if (element_destroy_func_expression is CCodeIdentifier) {
+                       var freeid = (CCodeIdentifier) element_destroy_func_expression;
+                       string free0_func = "_%s0_".printf (freeid.name);
 
-                       foreach (DataType type_arg in type.get_type_arguments ()) {
-                               elements_require_free = requires_destroy (type_arg);
-                               if (elements_require_free) {
-                                       element_destroy_func_expression = get_destroy_func_expression (type_arg);
+                       if (add_wrapper (free0_func)) {
+                               var function = new CCodeFunction (free0_func, "void");
+                               function.modifiers = CCodeModifiers.STATIC;
 
-                                       if (element_destroy_func_expression is CCodeIdentifier) {
-                                               var freeid = (CCodeIdentifier) element_destroy_func_expression;
-                                               string free0_func = "_%s0_".printf (freeid.name);
+                               function.add_parameter (new CCodeFormalParameter ("var", "gpointer"));
 
-                                               if (add_wrapper (free0_func)) {
-                                                       var function = new CCodeFunction (free0_func, "void");
-                                                       function.modifiers = CCodeModifiers.STATIC;
+                               push_function (function);
 
-                                                       function.add_parameter (new CCodeFormalParameter ("var", "gpointer"));
+                               ccode.add_expression (get_unref_expression (new CCodeIdentifier ("var"), type, null, true));
 
-                                                       push_function (function);
+                               pop_function ();
 
-                                                       ccode.add_expression (get_unref_expression (new CCodeIdentifier ("var"), type_arg, null, true));
+                               cfile.add_function_declaration (function);
+                               cfile.add_function (function);
+                       }
 
-                                                       pop_function ();
+                       element_destroy_func_expression = new CCodeIdentifier (free0_func);
+               }
 
-                                                       cfile.add_function_declaration (function);
-                                                       cfile.add_function (function);
-                                               }
+               return element_destroy_func_expression;
+       }
 
-                                               element_destroy_func_expression = new CCodeIdentifier (free0_func);
-                                       }
+       public CCodeExpression? get_destroy_func_expression (DataType type, bool is_chainup = false) {
+               if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type)) {
+                       // create wrapper function to free list elements if necessary
+
+                       bool elements_require_free = false;
+                       CCodeExpression element_destroy_func_expression = null;
+
+                       foreach (DataType type_arg in type.get_type_arguments ()) {
+                               elements_require_free = requires_destroy (type_arg);
+                               if (elements_require_free) {
+                                       element_destroy_func_expression = get_destroy0_func_expression (type_arg);
                                }
                        }
                        
@@ -4154,7 +4160,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                                int type_param_index = 0;
                                foreach (var type_arg in expr.type_reference.get_type_arguments ()) {
                                        if (requires_copy (type_arg)) {
-                                               carg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), get_destroy_func_expression (type_arg));
+                                               carg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), get_destroy0_func_expression (type_arg));
                                        } else {
                                                carg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), new CCodeConstant ("NULL"));
                                        }