]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Emit G_DEFINE_AUTOPTR_CLEANUP_FUNC() for classes 38781a502b7381ef5383ae282fa33ddda9b493ed
authorRico Tzschichholz <ricotz@t-online.de>
Tue, 31 Jul 2018 11:16:48 +0000 (13:16 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 17 Sep 2018 14:05:57 +0000 (16:05 +0200)
This requires --target-glib=2.44

Fixes https://gitlab.gnome.org/GNOME/vala/issues/670

codegen/valagtypemodule.vala

index 6b60f7ef3ffa6ec2dce7e499fff38fa0cda1413b..4b39cbbee3f03728345e8b3991a4084563cf61dd 100644 (file)
@@ -188,6 +188,23 @@ public class Vala.GTypeModule : GErrorModule {
                        type_fun.init_from_type (context, in_plugin, true);
                        decl_space.add_type_member_declaration (type_fun.get_declaration ());
                }
+
+               if (context.require_glib_version (2, 44)) {
+                       var base_class = cl;
+                       while (base_class.base_class != null) {
+                               base_class = base_class.base_class;
+                       }
+                       string autoptr_cleanup_func;
+                       if (!is_gtypeinstance && !is_gsource) {
+                               autoptr_cleanup_func = get_ccode_free_function (base_class);
+                       } else {
+                               autoptr_cleanup_func = get_ccode_unref_function (base_class);
+                       }
+                       if (autoptr_cleanup_func == null || autoptr_cleanup_func == "") {
+                               Report.error (cl.source_reference, "internal error: autoptr_cleanup_func not available");
+                       }
+                       decl_space.add_type_member_declaration (new CCodeIdentifier ("G_DEFINE_AUTOPTR_CLEANUP_FUNC (%s, %s)".printf (get_ccode_name (cl), autoptr_cleanup_func)));
+               }
        }
 
        public override void generate_class_struct_declaration (Class cl, CCodeFile decl_space) {