From: Rico Tzschichholz Date: Sat, 16 Jan 2021 09:05:30 +0000 (+0100) Subject: vala: GtkChild fields/properties must be declared as unowned X-Git-Tag: 0.51.1~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f78932e3dbcdba5660800b816e7dc8752771f0d5;p=thirdparty%2Fvala.git 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 --- 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..2fc1b4d60 100644 --- a/vala/valaproperty.vala +++ b/vala/valaproperty.vala @@ -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);