GNOME Bugzilla – Bug 581696
Support is_garray variants of array types in gjs
Last modified: 2010-05-27 18:53:24 UTC
This patch uses the GArray support in g-object-introspection (bug 581687) to allow gjs to marshal GArray as in/out parameters (even if wrapped as a gvalue, if bug 581686 and patch 134169 are applied).
Created attachment 134170 [details] [review] Support-is_garray-variants-of-array-types.patch
Created attachment 134435 [details] [review] Allow-conversion-of-JS-string-to-GArray-guchar.patch This additional patch allows converting strings to GArrays of characters/int8/etc. It depends on the patches attached to bug 581691, and simply broadens an overly restrictive test against JSVAL_IS_OBJECT, since JSVAL_IS_STRING objects can be passed to gjs_value_to_g_argument() too (this was added in bug 581695).
Created attachment 159848 [details] [review] build GJS arrays from GArrays The existing patches no longer apply to GJS and are not compatible with Tomeu's latest work in bug #581687 This patch will convert GArray arguments into GJS arrays. Tested against the new Telepathy-GLib.gir. Hypothetically it might handle GByteArrays and GPtrArrays but I haven't tested that yet. Need to support converting from GJS arrays to GArrays. Working on this now. http://git.collabora.co.uk/?p=user/danni/gjs.git;a=shortlog;h=refs/heads/bug-581696
Created attachment 159857 [details] [review] Build GArrays from GJS arrays This second patch builds a GArray from the GJS array. Requires extending for GPtrArray and GByteArray. Tested with Telepathy-GLib.
Added a unit test using GIMarshallingTests.
Review of attachment 159848 [details] [review]: Minor comments, please commit after fixing. ::: gi/arg.c @@ +1237,3 @@ + arg.v_##type = g_array_index(array, g##type, i); \ + if (!gjs_value_from_g_argument(context, &elem, param_info, &arg)) \ + goto finally; \ I'm a little dropping into gjs_value_from_g_argument for all the integer and FP types as opposed to just calling JS_NewNumberValue directly, but this is OK for now. @@ +1284,3 @@ + break; + default: + gjs_throw(context, "Unknown GArray element-type %d", element_type); Need goto finally;, right?
I fixed this up for comments and added some tests. There's definitely more to do here; we need to support e.g. input arrays of utf8.