[vala/wip/issue/1121] vala: GtkChild fields/properties must be declared as unowned




commit 3d7a929cfb549b9c1dc316a40b7e21d92fac2385
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Jan 15 19:35:33 2021 +0100

    vala: GtkChild fields/properties must be declared as unowned
    
    The backing field won't be assigned to hold a dedicated reference.
    gtk_widget_class_bind_template_child_full will make it point to the
    instance owned by GtkBuilder.
    
    This avoids doing a rogue (but safe) call of _g_object_unref0 on already
    disposed child.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1121

 vala/valafield.vala    | 5 +++++
 vala/valaproperty.vala | 5 +++++
 2 files changed, 10 insertions(+)
---
diff --git a/vala/valafield.vala b/vala/valafield.vala
index bee686222..731249e71 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -104,6 +104,11 @@ public class Vala.Field : Variable, Lockable {
                        return false;
                }
 
+               if (get_attribute ("GtkChild") != null && variable_type.value_owned) {
+                       Report.warning (source_reference, "[GtkChild] fields must be declared as `unowned'");
+                       variable_type.value_owned = false;
+               }
+
                variable_type.check (context);
                if (!external_package) {
                        context.analyzer.check_type (variable_type);
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 2c73fcbc4..d745bd89f 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -468,6 +468,11 @@ public class Vala.Property : Symbol, Lockable {
                        return false;
                }
 
+               if (get_attribute ("GtkChild") != null && property_type.value_owned) {
+                       Report.warning (source_reference, "[GtkChild] properties must be declared as 
`unowned'");
+                       property_type.value_owned = false;
+               }
+
                property_type.check (context);
                if (!external_package) {
                        context.analyzer.check_type (property_type);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]