GNOME Bugzilla – Bug 656205
Any static method who returns floating ref object should be marked as (transfer none)
Last modified: 2015-02-07 16:58:30 UTC
Problem: currently using lot of Gstreamer 0.11 classes methods which returns GstObjects are not possible with Gobject Introspection because objects get destroyed right after their creation. For example this Python script segfaults because of this: from gi.repository import Gst Gst.init(None) element = Gst.ElementFactory.make("audioconvert", "aconvert") print element.name Solution: all values which returns floating ref objects (GstObject for example) should have transfer ownership set to none. Object has his floating reference sinked in bindings (pygobject for example). See more http://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#floating-ref I might be wrong, but as far my research goes floating refs should be sinked this way because it otherwise is left floating and therefore it goes away. Transfer full means that Gstreamer leaves to itself to add ref, but it doesn't work that way. I add patch which changes transfer mode for Gst.ElementFactory.make() method. With this element is accessible and aren't destroyed before time has come. I have tried this successfully for Gst.Bin.new() and Gst.parse_bin_from_description too, which both segfaulted with transfer full.
Created attachment 193483 [details] [review] Patch for changing annotation to transfer none for gst_element_factory_make
Comment on attachment 193483 [details] [review] Patch for changing annotation to transfer none for gst_element_factory_make As discussed on IRC this is not a good solution because it's conceptionally wrong. The return value is owned by the caller and the caller has to unref it after usage. pygobject has some special magic to handle floating refs which makes it work if transfer none is used but a better solution should be found on the GI side. For example by adding a new (transfer floating) annotation
Conceptionally functions returning floating refs owned by the caller should be either (transfer full) or a new (transfer floating), (transfer none) doesn't make any sense. The same goes for constructors, they should be (transfer full), which currently is done implicit... or a new (transfer floating)
(In reply to comment #2) > pygobject has some special magic to handle floating refs which makes it work if > transfer none is used but a better solution should be found on the GI side. For > example by adding a new (transfer floating) annotation If it makes you happy, we can add "floating" as an alias for "none". We also kind of desperately need better docs of course =( However for bindings, we already tell them that they have to specially handle floating refs. For library authors, the story is that they're returning a floating reference - a special case. See also https://bugzilla.gnome.org/show_bug.cgi?id=657202
floating as an alias for none would at least improve the API docs but for bindings this would still leave the weird special casing for GInitiallyUnowned and the transfer annotation. IMHO what happens here should be made more explicit, like suggested in bug #657202
*** This bug has been marked as a duplicate of bug 657202 ***
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]