-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return a struct by value #14
Comments
Care to put that in terms of an example test case? Note that there's been improvements in how Struct is laid out and passed around, so check 2.1 out. |
I have encountered the same issue as @jeromerobert when trying to connect to a C library. For example, consider the following C code: struct IntPair {
int a;
int b;
};
// some function which creates a pair
struct IntPair makePair(int x, int y) {
struct IntPair p;
p.a = x;
p.b = y;
return p;
} Here makePair returns IntPair struct itself, and not just a pointer to it. |
It aims at illustrating jnr/jnr-ffi#14
I modified the getpid example as if
|
Is it possible to return a struct by value in version 2.19? I had asked question on Stack Overflow before I found this GitHub issue: https://stackoverflow.com/questions/56129984/how-to-return-by-value-from-native-function How can I prevent memory leak shown in SO question? |
This appears to still be an issue - is using a function that returns a struct by value supported? |
@charleskorn yeah this is still an issue, see #262 |
Makes sense, thanks for the quick response @basshelal. If it helps raise the priority, this makes working with functions exported from Golang's cgo quite difficult - in cgo, any function that returns multiple values (a very common pattern in Golang) gets translated to a function that returns a struct by value. |
Thanks @charleskorn Personally I'd want it to be higher priority since I've had to deal with my own problems with struct by value as a parameter but the fix would be quite complicated to implement and verify, hence the lower priority. But you are welcome to look into the code yourself and see if you can help with anything, you can also join our matrix discussion: |
Unless I missed something there is no way in jnr-ffi, to bind a function which return a struct by value.
This available at jffi level using Invoker.invoke or Invoker.invokeStruct but it would be nice to have it a jnr-ffi level.
The text was updated successfully, but these errors were encountered: