GNOME Bugzilla – Bug 584568
Array support
Last modified: 2010-02-08 20:07:12 UTC
As I blogged about here http://blog.fubar.dk/?p=106 I ran into problems with gjs when trying to use methods returning arrays of strings, e.g. when using a function like http://people.freedesktop.org/~david/gudev/GUdevDevice.html#g-udev-device-get-device-file-symlinks with these GIR bits <return-value transfer-ownership="none" doc="A %NULL terminated string array of symlinks. This array is owned by @device and should not be freed by the caller."> <array c:type="gchar**"> <type name="utf8"/> </array> </return-value> Specifically I ran into this bug FIXME: Only supporting null ARRAYs in gi/arg.c. I will attach a patch that attempts to fix this.
Created attachment 135781 [details] [review] Add Array support Here's a patch to handle arrays. I've tested it with GUdev and it seems to work great. Note that due to bug 584453 this isn't terribly useful until either people start annotating libraries correctly or we start adopting more useful default annotations. For example, consider g_get_system_data_dirs() <function name="get_system_data_dirs" c:identifier="g_get_system_data_dirs"> <return-value transfer-ownership="full"> <type name="utf8" c:type="gchar**"/> </return-value> </function> However if we fix that, e.g. change the GIR to <function name="get_system_data_dirs" c:identifier="g_get_system_data_dirs"> <return-value transfer-ownership="none"> <array c:type="gchar**"> <type name="utf8"/> </array> </return-value> </function> and rebuild the typelib then things work as expected: $ gjs-console gjs> const GLib = imports.gi.GLib; gjs> GLib.get_system_data_dirs (); /usr/local/share/,/usr/share/
I missed that one and ended up implementing something similar in bug# 585852 I think my patch has the advantage of not duplicating some code by reusing the list -> array code path, while your has the advantage of handling non-zero-terminated arrays. I think your patch should check whether the array is an array of strings (or at least an array of pointers).
Comment on attachment 135781 [details] [review] Add Array support Patch overlaps and conflicts with Johan's committed patch. Is there some part of this that still makes sense, or should the bug be closed?
I'm marking this as a duplicate of bug 560567 as the patch for array support should probably do input and output arguments. *** This bug has been marked as a duplicate of bug 560567 ***