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 642434 - Inconsistency in (transfer) annotations for constructors wrt floating refs
Inconsistency in (transfer) annotations for constructors wrt floating refs
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks: 708060
 
 
Reported: 2011-02-16 07:25 UTC by Steve Frécinaux
Modified: 2018-01-24 18:48 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Steve Frécinaux 2011-02-16 07:25:57 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.
Comment 1 Steve Frécinaux 2011-02-16 08:34:43 UTC
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"...
Comment 2 Dan Winship 2011-02-16 13:23:58 UTC
I think bindings are expected to wrap g_object_new* manually rather than having introspection on them Just Work.
Comment 3 Torsten Schoenfeld 2015-01-17 16:02:40 UTC
This seems closely related to bug 657202.
Comment 4 André Klapper 2015-02-07 17:15:16 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 5 Emmanuele Bassi (:ebassi) 2018-01-24 18:48:10 UTC
We have a `transfer floating` annotation, these days.