GNOME Bugzilla – Bug 704842
Segfaults when handling out arrays of structs
Last modified: 2016-02-07 04:16:12 UTC
gjs segfaults when marshalling an out array of structs. This is easily reproducible with e.g. gdk_keymap_get_entries_for_keyval(), where the out argument is a GdkKeymapKey **, i.e. a location to store an array of GdkKeymapKey structures. See attached testcase. Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7175d80 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) bt
+ Trace 232292
Created attachment 250082 [details] testcase
Yeah, the current code handling arrays of structures assumes that they are arrays of pointers to structures (except for "flat GValue arrays"), so it would be GdkKeymapKey*** in this case.
Created attachment 250528 [details] [review] arg: add support for arrays of flat structures (to JS) Add support for marshalling from C to JS arrays not of pointer to structures but of actual structures, as for example used by gdk_keymap_get_entries_for_keyval().
Review of attachment 250528 [details] [review]: Not a gjs reviewer, but the patch makes sense to me and makes the testcase work correctly.
Ping, can we get this in?
Review of attachment 250528 [details] [review]: Looks good.
Review of attachment 250528 [details] [review]: Would like a test case in g-i's regress.h and then consume it here. ::: gi/arg.c @@ +2140,3 @@ + if (info_type == GI_INFO_TYPE_ENUM || + info_type == GI_INFO_TYPE_FLAGS) { + ITERATE(int); Unfortunately enums/flags are not just integers always. See https://bugzilla.gnome.org/show_bug.cgi?id=629705 If this code path isn't necessary I'd prefer to just drop it until we have a correct fix. (Or alternatively, throw an exception).
Giovanni, any chance we could get this in, or do we need to address Colin's comment?
Created attachment 287381 [details] [review] arg: add support for arrays of flat structures (to JS) Add support for marshalling from C to JS arrays not of pointer to structures but of actual structures, as for example used by gdk_keymap_get_entries_for_keyval().
It's missing a test case indeed.
Pushed to master with a testcase. Attachment 287381 [details] pushed as 967d696 - arg: add support for arrays of flat structures (to JS)
Heads up that I filed https://bugzilla.gnome.org/show_bug.cgi?id=761658 (with patch) to fix a problem with this patch.