GNOME Bugzilla – Bug 554344
Use g_object_add_weak_pointer for weak references
Last modified: 2018-05-22 13:09:58 UTC
We should probably use g_object_weak_ref for weak GObject references where possible to avoid dangling pointers. Maybe introduce [Unowned] and [Owned] with the semantics that `weak' and `#' currently have, deprecate `#', and use g_object_weak_ref for `weak' fields.
s/g_object_weak_ref/g_object_add_weak_pointer/
2008-12-19 Jürg Billeter <j@bitron.ch> * vala/valaparser.vala: * vala/valascanner.vala: * vala/valatokentype.vala: Add `owned' type modifier and `(owned)' cast to replace `#', add `unowned' type modifier to complement `weak' for non-reference counted objects. `#' will be deprecated in Vala 0.5.5
One should be still able to decide whether the pointer must be nullified or not. So unowned might be used for referenced objects to say "it's weak but not nullified".
Agreed. There is one thing we should do already - pop a warning every time 'weak' is used in place where it won't be possible with weak_pointer semantics.
Created attachment 153717 [details] [review] Add deprecation warning for `weak` keyword when it doesn't mark a field or a local variable This assumes `weak` will only be usable for fields and local variables and not for example method parameters and return values. Also, it doesn't check the type to be GObject yet.
commit bd65b0d4dc74142ab00bcd9620ce798f3f304c55 Author: Jürg Billeter <j@bitron.ch> Date: Sat Mar 20 11:32:30 2010 +0100 Warn when using `weak' modifier where it is not applicable Based on patch by Jiří Zárevúcky.
Created attachment 177896 [details] [review] Start supporting weak refs for local variables This is a proof but some of the diff could be committed in the while. Actually supports very simple local variable weak refs and it's untested. Main issue is that *_weak_pointer functions must not be called with NULL object.
It might be better to implement this using the new GWeakRef, since it’s thread safe.
This improvements could be good for a 2.0 release.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/15.