Jextract generates wraper interfaces for each function pointer field in a struct. This is handy, as the interface has a static "invoke" method that can be used to invoke the function pointer programmatically.
However, the first parameter of this "invoke" method is a memory segment for the function pointer itself, not the struct. This means that, whenever users want to call a function pointer in a struct field, they have to:
* access the field containing the desired function pointer using the correct accessor
* call the function pointer using the correct "invoke" method
This leads to code that looks like this:
var apiBase = OrtGetApiBase();
var version = OrtApiBase.GetVersionString.invoke(OrtApiBase.GetVersionString(apiBase));
Note how the code needs to first get the correct function pointer segment, then call the "invoke" method on such segment. This means the client has to spell the name of the field _twice_, once for the accessor, once for the interface wrapper. Any mistake here is costly: if these two uses go out of sync, we might risk invoking the function pointer with the wrong calling sequence (and crash the JVM).
It would be nice if the above code could be written like so:
var apiBase = OrtGetApiBase();
var version = OrtApiBase.GetVersionString.invoke(apiBase);
(e.g. if the accepted segment was a segment pointing to the enclosing struct, not to the specific function pointer instance).
Doing so would be an incompatible change (at least for function pointers inside structs/unions) -- but perhaps one we should consider?
However, the first parameter of this "invoke" method is a memory segment for the function pointer itself, not the struct. This means that, whenever users want to call a function pointer in a struct field, they have to:
* access the field containing the desired function pointer using the correct accessor
* call the function pointer using the correct "invoke" method
This leads to code that looks like this:
var apiBase = OrtGetApiBase();
var version = OrtApiBase.GetVersionString.invoke(OrtApiBase.GetVersionString(apiBase));
Note how the code needs to first get the correct function pointer segment, then call the "invoke" method on such segment. This means the client has to spell the name of the field _twice_, once for the accessor, once for the interface wrapper. Any mistake here is costly: if these two uses go out of sync, we might risk invoking the function pointer with the wrong calling sequence (and crash the JVM).
It would be nice if the above code could be written like so:
var apiBase = OrtGetApiBase();
var version = OrtApiBase.GetVersionString.invoke(apiBase);
(e.g. if the accepted segment was a segment pointing to the enclosing struct, not to the specific function pointer instance).
Doing so would be an incompatible change (at least for function pointers inside structs/unions) -- but perhaps one we should consider?