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 652880 - GLib.KeyFile can't be constructed properly
GLib.KeyFile can't be constructed properly
Status: RESOLVED DUPLICATE of bug 590808
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:
 
 
Reported: 2011-06-18 04:18 UTC by arun
Modified: 2015-02-07 16:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gi: don't try to directly allocate structs that we don't know the size of (864 bytes, patch)
2011-06-20 16:08 UTC, Dan Winship
committed Details | Review
glib: turn GKeyFile into a boxed for introspection (14.37 KB, patch)
2011-06-22 14:56 UTC, Giovanni Campagna
none Details | Review

Description arun 2011-06-18 04:18:22 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
Comment 1 Dan Winship 2011-06-20 15:43:11 UTC
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.
Comment 2 Dan Winship 2011-06-20 16:08:33 UTC
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
Comment 3 Colin Walters 2011-06-20 16:16:43 UTC
Review of attachment 190284 [details] [review]:

Looks fine.
Comment 4 Dan Winship 2011-06-20 16:45:45 UTC
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
Comment 5 Giovanni Campagna 2011-06-20 17:50:37 UTC
(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)
Comment 6 Matthias Clasen 2011-06-22 12:54:42 UTC
(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.
Comment 7 Giovanni Campagna 2011-06-22 14:56:03 UTC
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.
Comment 8 Colin Walters 2011-06-22 15:01:16 UTC
Review of attachment 190442 [details] [review]:

Dup of https://bugzilla.gnome.org/show_bug.cgi?id=590808
Comment 9 Matthias Clasen 2011-06-22 15:10:58 UTC
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.
Comment 10 Giovanni Campagna 2011-06-22 16:15:22 UTC
(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 ***
Comment 11 André Klapper 2015-02-07 16:50:45 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]