]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: GtkChild fields/properties must be declared as unowned
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 16 Jan 2021 09:05:30 +0000 (10:05 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 16 Jan 2021 09:05:30 +0000 (10:05 +0100)
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
vala/valaproperty.vala

index bee686222e06e343411da19dd8137604d598f9fc..731249e71e0413b25e2e6ac7dda74dbcb6ea667d 100644 (file)
@@ -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);
index 2c73fcbc435b7cc31a6ed822cecfcda68aae2169..2fc1b4d603e6dd5cc03d0824e8537fba7170a576 100644 (file)
@@ -116,6 +116,11 @@ public class Vala.Property : Symbol, Lockable {
                                                Report.error (source_reference, "Property setter must have a body");
                                        }
                                        if (!get_has_body && !set_has_body) {
+                                               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;
+                                               }
+
                                                /* automatic property accessor body generation */
                                                _field = new Field ("_%s".printf (name), property_type.copy (), initializer, source_reference);
                                                _field.access = SymbolAccessibility.PRIVATE;
@@ -468,6 +473,10 @@ public class Vala.Property : Symbol, Lockable {
                        return false;
                }
 
+               if (field != null) {
+                       field.check (context);
+               }
+
                property_type.check (context);
                if (!external_package) {
                        context.analyzer.check_type (property_type);