[vala/wip/issue/1121: 1/2] vala: GtkChild fields/properties must be declared as unowned
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/1121: 1/2] vala: GtkChild fields/properties must be declared as unowned
- Date: Sat, 16 Jan 2021 11:22:41 +0000 (UTC)
commit f78932e3dbcdba5660800b816e7dc8752771f0d5
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jan 16 10:05:30 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 | 9 +++++++++
2 files changed, 14 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..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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]