Handle transfer-none string return value from vfunc implemented in JS
There is a memory leak with gi_marshalling_tests_object_method_str_arg_out_ret()
.
The method (and the corresponding vfunc) return a string annotated as transfer-none.
But a vfunc implemented in JS cannot really return a transfer-none string. It could certainly tie the lifetime of the JS string to the object, something like this:
vfunc_method_str_arg_out_ret(s) {
this.#transferNoneString = `Called with ${s}`;
return [this.#transferNoneString, 41];
}
But that doesn't help us. The string data is owned by the object, but C code can't access that string data directly. In order to marshal that string back to C, we have to convert it to UTF-8, which creates a temporary string; but the temporary string has to outlive the call to the vfunc. I'm not sure what we can tie the lifetime of that temporary string to. One option might be to treat a string return value from a vfunc as transfer-full; but in this case, that would mean that the memory leak is just shunted over to gi_marshalling_tests_object_method_str_arg_out_ret()
, which calls the vfunc expecting to receive and return a transfer-none string.
Another option might be to stuff the string somewhere with g_object_set_qdata_full()
, to tie it to the lifetime of the object.
Note this doesn't apply to object return values, because we don't have to create a temporary in order to marshal them into C.