GNOME Bugzilla – Bug 652880
GLib.KeyFile can't be constructed properly
Last modified: 2015-02-07 16:50:45 UTC
Please consider the following code (using gnome-shell w/ gjs from git): -- const GLib = imports.gi.GLib; var x = new GLib.KeyFile(); x.load_from_file("/tmp/foo.ini", GLib.KeyFileFlags.NONE); -- Expected behavior: -- Assuming /tmp/foo.ini exists, this should return true Actual behavior: -- This shows following error message in gnome-shell console: Window manager warning: Log level 8: g_key_file_load_from_file: assertion `key_file != NULL' failed Relevant GLib source: http://git.gnome.org/browse/glib/tree/glib/gkeyfile.c#n490
The problem is that gjs is trying to use direct allocation of the boxed type, but that fails because the structure is opaque, and so it thinks it's 0 bytes, and so it does g_slice_alloc0(0). Fixing struct_is_simple() to return FALSE if n_fields == 0 fixes that, but then it still can't construct a GKeyFile, because for some reason g_key_file_new() is not recognized as belonging to GKeyFile, so it thinks there is no constructor.
Created attachment 190284 [details] [review] gi: don't try to directly allocate structs that we don't know the size of ==== I guess the other part is g-i, not gjs though
Review of attachment 190284 [details] [review]: Looks fine.
Comment on attachment 190284 [details] [review] gi: don't try to directly allocate structs that we don't know the size of Attachment 190284 [details] pushed as 63fb30e - gi: don't try to directly allocate structs that we don't know the size of
(In reply to comment #1) > [...] because for some reason g_key_file_new() is not recognized as belonging > to GKeyFile, so it thinks there is no constructor. That's because g_key_file_new() should be (transfer full), but that's not possible because GKeyFile is not a boxed (and it cannot be made one because it is not refcounted)
(In reply to comment #5) > > That's because g_key_file_new() should be (transfer full), but that's not > possible because GKeyFile is not a boxed (and it cannot be made one because it > is not refcounted) Both of these could be fixed, of course.
Created attachment 190442 [details] [review] glib: turn GKeyFile into a boxed for introspection Add reference counting to GKeyFile and introduce a boxed type. This, plus improved annotations, make it fully available to introspected bindings.
Review of attachment 190442 [details] [review]: Dup of https://bugzilla.gnome.org/show_bug.cgi?id=590808
The improved annotations should be a separate patch. As for the boxed type: your patch does a few things better than the other patch, but gets the unref/free wrong. So we need a synthesis of these two patches.
(In reply to comment #9) > The improved annotations should be a separate patch. > As for the boxed type: your patch does a few things better than the other > patch, but gets the unref/free wrong. So we need a synthesis of these two > patches. Ok. Marking duplicate and rebasing the annotations on top of the other patch. *** This bug has been marked as a duplicate of bug 590808 ***
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]