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 635248 - crash on accessing floating gobjects in container with transfer mode "full"
crash on accessing floating gobjects in container with transfer mode "full"
Status: RESOLVED NOTABUG
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2010-11-19 08:16 UTC by Daiki Ueno
Modified: 2010-11-30 01:21 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Daiki Ueno 2010-11-19 08:16:31 UTC
I'm trying to access IBus engines from gjs.  First I tried to enumerate available IBus engines:

 gjs> const ibus = imports.gi.IBus;
 gjs> ibus.init();
 gjs> var bus = new ibus.Bus();
 gjs> var engines = bus.list_engines();
 gjs> engines.length
 234

It's working so far, but if I access to an element of the list:

 gjs> engines[0]
 conflicting gtypes for prototype (null) (20631584) (was IBusEngineDesc (20574992))

 Aborted (core dumped)

The return value of bus.list_engines() (ibus_bus_list_engines()) is "GList *" and annotated as:

 @returns: (transfer full) (element-type IBusEngineDesc): A List of engines.

I suspect that this is because every IBus objects are derived from GInitiallyUnowned.

FWIW, pygobject2 does not crash on this case:

 >>> from gi.repository import IBus
 >>> IBus.init()
 >>> bus = IBus.Bus()
 >>> engines = bus.list_engines()
 >>> engines[0]
 <EngineDesc object at 0x7f6976ecfeb0 (IBusEngineDesc at 0x1cc90c0)>
 >>> engines[0].get_name()
 'xkb:layout:nl'
Comment 1 Colin Walters 2010-11-19 20:59:29 UTC
Does list_engines() create them?  If so, and they're initially unowned, they need to be (transfer none).
Comment 2 Daiki Ueno 2010-11-29 08:52:24 UTC
Thanks for the reply.  Yes, list_engines() creates "initially unowned" objects, and if I change "(transfer full)" to "(transfer container)" or "(transfer none)", gjs does not crash.

However, in that case who is responsible to unref/free those objects?

I run:

 $ cat > test.js
 const ibus = imports.gi.IBus;
 ibus.init();
 var bus = new ibus.Bus();
 var engines = bus.list_engines();
 engines[0]
 ^D

and:

 $ G_SLICE=always_malloc valgrind --leak-check=full gjs < test.js

I see "definitely lost" messages caused by ibus_bus_list_engines().
Comment 3 Owen Taylor 2010-11-29 12:47:01 UTC
What will happen is that the first time GJS creates a proxy for a floating object it "adopts" the floating reference count using g_object_ref_sink().

Most likely they show up as leaked in the test above because they are never garbage collected during the run of the test.

[ I think it's inappropriate for IBusObject to be "initially unowned" - it only make sense for something like GtkWidget or ClutterActor where there is a strong pattern of building a tree of objects and the parent objects act as the owners of the child objects. But as far as GJS is concerned, the memory management is fine. ]
Comment 4 Daiki Ueno 2010-11-30 01:21:50 UTC
Aha, good to know that. Thank you.
Now I'm closing this as NOTABUG.