From: Rico Tzschichholz Date: Thu, 24 Feb 2022 12:45:18 +0000 (+0100) Subject: codegen: Emit G_DEFINE_AUTOPTR_CLEANUP_FUNC() for interfaces with base class X-Git-Tag: 0.48.24~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=97d25a2e02fa655d05b6a4bf365b51c1c41ca444;p=thirdparty%2Fvala.git codegen: Emit G_DEFINE_AUTOPTR_CLEANUP_FUNC() for interfaces with base class Fixes https://gitlab.gnome.org/GNOME/vala/issues/1292 --- diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 8dab871b7..99c263ce6 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -2090,8 +2090,9 @@ public class Vala.GTypeModule : GErrorModule { decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (iface)), new CCodeVariableDeclarator (get_ccode_name (iface)))); decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (get_ccode_type_name (iface)))); + unowned Class? prereq_cl = null; foreach (DataType prerequisite in iface.get_prerequisites ()) { - unowned Class? prereq_cl = prerequisite.type_symbol as Class; + prereq_cl = prerequisite.type_symbol as Class; unowned Interface? prereq_iface = prerequisite.type_symbol as Interface; if (prereq_cl != null) { generate_class_declaration (prereq_cl, decl_space); @@ -2156,6 +2157,16 @@ public class Vala.GTypeModule : GErrorModule { var type_fun = new InterfaceRegisterFunction (iface); type_fun.init_from_type (context, in_plugin, true); decl_space.add_type_member_declaration (type_fun.get_declaration ()); + + if (prereq_cl != null) { + var base_class = prereq_cl; + while (base_class.base_class != null) { + base_class = base_class.base_class; + } + // Custom unref-methods need to be emitted before G_DEFINE_AUTOPTR_CLEANUP_FUNC, + // so we guard against that special case and handle it in generate_method_declaration. + generate_autoptr_cleanup (iface, base_class, decl_space); + } } public override void visit_interface (Interface iface) {