]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use gtype-boxed API for structs with "g_boxed_free" attribute
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 Oct 2019 13:07:58 +0000 (15:07 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 Oct 2019 14:51:55 +0000 (16:51 +0200)
See https://gitlab.gnome.org/GNOME/vala/issues/863

codegen/valaccodebasemodule.vala

index 9963b83c09797ceaa3c213d619da60e7df63c569..7ae022aa331dc22db432d87079da95ea8bc08696 100644 (file)
@@ -2760,7 +2760,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                if (dup_function == null) {
                                        dup_function = "";
                                }
-                       } else if (cl != null && get_ccode_is_gboxed (cl)) {
+                       } else if (get_ccode_is_gboxed (type.data_type)) {
                                // allow duplicates of gboxed instances
                                dup_function = generate_dup_func_wrapper (type);
                                if (dup_function == null) {
@@ -3070,11 +3070,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                push_function (function);
 
-               var cl = type.data_type as Class;
-               assert (cl != null && get_ccode_is_gboxed (cl));
-
                var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_boxed_copy"));
-               free_call.add_argument (new CCodeIdentifier (get_ccode_type_id (cl)));
+               free_call.add_argument (new CCodeIdentifier (get_ccode_type_id (type.data_type)));
                free_call.add_argument (new CCodeIdentifier ("self"));
 
                ccode.add_return (free_call);
@@ -3160,10 +3157,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                push_function (function);
 
-               var cl = type.data_type as Class;
-               if (cl != null && get_ccode_is_gboxed (cl)) {
+               if (get_ccode_is_gboxed (type.data_type)) {
                        var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_boxed_free"));
-                       free_call.add_argument (new CCodeIdentifier (get_ccode_type_id (cl)));
+                       free_call.add_argument (new CCodeIdentifier (get_ccode_type_id (type.data_type)));
                        free_call.add_argument (new CCodeIdentifier ("self"));
 
                        ccode.add_expression (free_call);
@@ -3266,8 +3262,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                                return null;
                                        }
                                } else {
-                                       var cl = type.data_type as Class;
-                                       if (cl != null && get_ccode_is_gboxed (cl)) {
+                                       if (get_ccode_is_gboxed (type.data_type)) {
                                                unref_function = generate_free_func_wrapper (type);
                                        } else {
                                                if (is_free_function_address_of (type)) {
@@ -3279,7 +3274,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                }
                        } else {
                                if (type.nullable) {
-                                       unref_function = get_ccode_free_function (type.data_type);
+                                       if (get_ccode_is_gboxed (type.data_type)) {
+                                               unref_function = generate_free_func_wrapper (type);
+                                       } else {
+                                               unref_function = get_ccode_free_function (type.data_type);
+                                       }
                                        if (unref_function == null) {
                                                if (type.data_type is Struct && ((Struct) type.data_type).is_disposable ()) {
                                                        unref_function = generate_free_func_wrapper (type);