]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't create special GArray clear-func for non-null structs
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 10 Mar 2019 20:51:02 +0000 (21:51 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 22 Mar 2019 20:18:41 +0000 (21:18 +0100)
Based on patch by Jakub Kaszycki

codegen/valaccodebasemodule.vala

index 1980d7b59090fb6011df755401517d123faaba58..0a46bd9adf3db528fd60d17df4171d9d6506b593 100644 (file)
@@ -5125,10 +5125,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        if (cl == garray_type) {
                                var type_arg = expr.type_reference.get_type_arguments ().get (0);
                                if (requires_destroy (type_arg)) {
-                                       var free_wrapper = generate_destroy_function_content_of_wrapper (type_arg);
                                        var clear_func = new CCodeFunctionCall (new CCodeIdentifier ("g_array_set_clear_func"));
                                        clear_func.add_argument (get_cvalue_ (expr.target_value));
-                                       clear_func.add_argument (new CCodeIdentifier (free_wrapper));
+                                       string destroy_func;
+                                       if (type_arg.is_non_null_simple_type () || type_arg.is_real_non_null_struct_type ()) {
+                                               destroy_func = get_ccode_destroy_function (type_arg.data_type);
+                                       } else {
+                                               destroy_func = generate_destroy_function_content_of_wrapper (type_arg);
+                                       }
+                                       clear_func.add_argument (new CCodeCastExpression (new CCodeIdentifier (destroy_func), "GDestroyNotify"));
                                        ccode.add_expression (clear_func);
                                }
                        }