GNOME Bugzilla – Bug 642434
Inconsistency in (transfer) annotations for constructors wrt floating refs
Last modified: 2018-01-24 18:48:10 UTC
There is an inconsistency in the annotations due to the fact that constructors returning floating refs (like GtkWidgets) are marked as (transfer none) but constructors which return regular refs (like GObjects) are marked as (transfer full). This causes an issue for the introspection information for g_object_newv() and possibly other similar functions. Here is the gir snippet for the return value of g_object_newv(): <return-value transfer-ownership="full"> <doc xml:whitespace="preserve">a new instance of</doc> <type name="Object"/> </return-value> So basically, if I do gobject.new(Gtk.Button), g-i tells me I own the return value, but actually I don't! I could even end up with one less reference than expected and finalize the object one unref() call too early... I think it would be more consistent to consider floating refs as proper references and asking the various g-i bindings to add that snippet of code after a function call: if (constructor and transfer is full and g_object_is_floating(obj)) { g_object_ref_sink(obj); } Also this could fix the g_object_new() annotations as mentioned above.
Note that it wouldn't solve the issue for g_object_new(GtkWindow), which returns a "sunk" GInitiallyUnowned reference... Unless you do if (constructor and transfer is full and G_IS_INITIALLY_UNOWNED(obj)) { g_object_ref_sink(obj); } but then it would not really be "transfer full"...
I think bindings are expected to wrap g_object_new* manually rather than having introspection on them Just Work.
This seems closely related to bug 657202.
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
We have a `transfer floating` annotation, these days.