From: Rico Tzschichholz Date: Thu, 24 Feb 2022 12:45:18 +0000 (+0100) Subject: codegen: Emit G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC() for structs X-Git-Tag: 0.48.24~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18b07be9b71f1eb8c66b69d62d244575b7788386;p=thirdparty%2Fvala.git codegen: Emit G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC() for structs Fixes https://gitlab.gnome.org/GNOME/vala/issues/1293 --- diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index 2b685383d..dff0d9827 100644 --- a/codegen/valaccodestructmodule.vala +++ b/codegen/valaccodestructmodule.vala @@ -142,6 +142,22 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { function.add_parameter (new CCodeParameter ("self", get_ccode_name (st) + "*")); decl_space.add_function_declaration (function); } + + if (context.profile == Profile.GOBJECT) { + generate_auto_cleanup_clear (st, decl_space); + } + } + + void generate_auto_cleanup_clear (Struct st, CCodeFile decl_space) { + if (st.is_disposable () + && (!context.use_header || decl_space.is_header)) { + string auto_cleanup_clear_func = get_ccode_destroy_function (st); + if (auto_cleanup_clear_func == null || auto_cleanup_clear_func == "") { + Report.error (st.source_reference, "internal error: auto_cleanup_clear_func not available"); + } + decl_space.add_type_member_declaration (new CCodeIdentifier ("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (%s, %s)".printf (get_ccode_name (st), auto_cleanup_clear_func))); + decl_space.add_type_member_declaration (new CCodeNewline ()); + } } public override void visit_struct (Struct st) {