After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 554344 - Use g_object_add_weak_pointer for weak references
Use g_object_add_weak_pointer for weak references
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Objects
unspecified
Other All
: Normal normal
: 2.0
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-09-29 18:45 UTC by Jürg Billeter
Modified: 2018-05-22 13:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add deprecation warning for `weak` keyword when it doesn't mark a field or a local variable (8.34 KB, patch)
2010-02-13 16:05 UTC, zarevucky.jiri
committed Details | Review
Start supporting weak refs for local variables (7.03 KB, patch)
2011-01-10 00:30 UTC, Luca Bruno
none Details | Review

Description Jürg Billeter 2008-09-29 18:45:57 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.
Comment 1 Jürg Billeter 2008-09-29 18:47:09 UTC
s/g_object_weak_ref/g_object_add_weak_pointer/
Comment 2 Jürg Billeter 2008-12-19 10:47:34 UTC
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
Comment 3 Luca Bruno 2010-02-13 15:07:13 UTC
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".
Comment 4 zarevucky.jiri 2010-02-13 15:16:58 UTC
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.
Comment 5 zarevucky.jiri 2010-02-13 16:05:50 UTC
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.
Comment 6 Jürg Billeter 2010-03-20 10:33:57 UTC
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.
Comment 7 Luca Bruno 2011-01-10 00:30:07 UTC
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.
Comment 8 Philip Withnall 2012-09-02 19:41:19 UTC
It might be better to implement this using the new GWeakRef, since it’s thread safe.
Comment 9 Daniel Espinosa 2017-02-17 18:43:54 UTC
This improvements could be good for a 2.0 release.
Comment 10 GNOME Infrastructure Team 2018-05-22 13:09:58 UTC
-- 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.