ffi: improve support for functions returning arrays