Support flat C array return values
Following up from #601 (closed).
We support flat C arrays, but only of GValue
. Trying to call a function that returns a flat C array of any other type, throws an exception referencing this issue.
Reproducer:
import GTop from 'gi://GTop';
const buf = new GTop.glibtop_mountlist();
const mountlist = GTop.glibtop_get_mountlist(buf, 0);
(glibtop_get_mountlist
seems like an awkward API with the in-out buffer, though, and requires an external dependency; so any better examples of an API like this inside e.g. Gio would be appreciated)
For reference, introspection data:
<return-value transfer-ownership="full">
<array c:type="glibtop_mountentry*">
<type name="glibtop_mountentry" c:type="glibtop_mountentry"/>
</array>
</return-value>
Probably the best way to implement this is to take the existing special-case support for GValue flat arrays and generalize it to any struct. The complication will be that by not special-casing a struct with a size known at compile time, the size of the struct will only be known at runtime.
The code for this is in gjs_array_from_zero_terminated_c_array()
in the glibtop_get_mountlist
case, but will also need to be supported elsewhere.
gobject-introspection contains tests for GValue flat arrays. Check if they cover all the kinds of array (zero-terminated, fixed-length, length-parameter) as well as transfer (full, none; container doesn't seem to apply here) and check that we support in and out parameters as well as return values (inout doesn't seem to apply here.)