node-gir
node-gir copied to clipboard
Add support for arrays + INOUT arguments
@romgrk I'm struggling a little bit with INOUT arguments. You can see my approach in this PR.
I'm trying to encapsule the logic and memory management of IN/OUT args in a Parameter class similar to your approach in node-gtk
. I'd love some tips of maybe even a breakdown of how it should work to get me over the last bump.
Do you have more specific questions? I see the general flow of the thing, but I'd need to understand the whole relevant parts of the codebase to spot specific bugs/issues.
General observations:
- INOUT-arguments are similar to OUT-arguments in that you always need to add a level of indirection to them. In node-gtk, we first fill the
GIArgument
as for an IN-argument, then store that value in a pointer on the stack, then point the GIArgument to that stack-pointer. - You will eventually need a FreeGIArgument function, to deallocate any resources created during the function call. (for reference, here is PyGObject version: https://gitlab.gnome.org/GNOME/pygobject/blob/master/gi/pygi-argument.c#L1005-1271)
- You're allocating your Out/In/InOutParameter instances on the heap. Function calling is a "hot" part of the bindings, if it's possible to do so you should use the stack only.