summaryrefslogtreecommitdiff
path: root/codegen
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2022-02-24 13:45:18 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2022-02-24 13:45:18 +0100
commit87d66947248c5010062d6ee2a2b87f1ba92a93bb (patch)
tree4fb840902dc9db97f2981f08b280980830e20d26 /codegen
parent612bded4642734554b7658c64d90ec1c3336006d (diff)
downloadvala-87d66947248c5010062d6ee2a2b87f1ba92a93bb.tar.gz
codegen: Emit G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC() for structs
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1293
Diffstat (limited to 'codegen')
-rw-r--r--codegen/valaccodestructmodule.vala17
1 files changed, 17 insertions, 0 deletions
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 9c1e71310..19a616999 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -156,6 +156,23 @@ 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.header_filename == null|| decl_space.file_type == CCodeFileType.PUBLIC_HEADER
+ || (decl_space.file_type == CCodeFileType.INTERNAL_HEADER && st.is_internal_symbol ()))) {
+ 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) {