array-length parameters for caller-allocated arrays are incorrectly marked as direction=out
I found a problem when trying to use a certain function in gjs:
gjs> Gio.InputStream.prototype.read_all_async;
function read_all_async(io_priority, cancellable, callback) {
/* wrapper for native symbol g_input_stream_read_all_async(); */
}
The C function has additional parameters, buffer (out caller-allocates) (array-length=count)
and count
. I read that gjs is supposed to handle caller-allocates
automagically, but in this case it can't because the count
parameter is missing, due to being marked out
in the gir file. Therefore the function wrapper has no idea how many bytes I want to allocate and the C implementation doesn't know how many bytes to read.
I think this direction=out
on count
is a mistake and that it's a bug in the gir scanner tool. The C source code for this function has no direction annotation, presumably assuming that it defaults to in
. I guess that the scanner changes the default to out
for parameters that are the array-length
target of an out
array. This can never be correct for caller-allocates
, and not always correct for callee-allocates
, because even then the function may need to be told how many bytes to allocate in an input, so in-out
would be a safer default.