Floating refs and transfer-ownership
Submitted by Torsten Schoenfeld
Link to original bug (#657202)
Description
Currently g-i always sets transfer-ownership=none for return values whose type is some GInitiallyUnowned descendant¹. The understanding is that bindings will always use ref_sink on the floating ref anyway, irregardless of transfer-ownership. But this falls flat for gtk_action_get_proxies, which returns a list of GtkWidgets with transfer-ownership=none and which sometimes happen to have only one single, floating ref. When bindings use ref_sink as above, and then later, when the language object goes out of scope, use a normal unref, the widgets are destroyed prematurely. This can lead to crashes.²
¹ Code: http://git.gnome.org/browse/gobject-introspection/tree/giscanner/maintransformer.py#n490
² Test case: http://git.gnome.org/browse/perl-Gtk2/tree/t/GtkAction.t#n56
So how about we remove the GInitiallyUnowned special-casing and thus have normal transfer-ownership flags also for GInitiallyUnowned-returning functions? Bindings then would need to do this in their GObject-to-native converter:
if transfer-ownership=full, floating=true: ref_sink, and take over a ref
if transfer-ownership=full, floating=false: take over a ref
if transfer-ownership=none, floating=true: ref
if transfer-ownership=none, floating=false: ref