Skip to content
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

Improve interop with C's union types #34

Open
densh opened this issue May 5, 2016 · 4 comments
Open

Improve interop with C's union types #34

densh opened this issue May 5, 2016 · 4 comments

Comments

@densh
Copy link
Member

densh commented May 5, 2016

Currently it's possible to use C structs that have union members through definition of multiple variants of the same struct and casting between them. This is a bit sub-optimal from the boilerplate point of view and it would be nice to have something more user friendly in this area.

@densh densh added this to the Backlog milestone May 5, 2016
@densh densh changed the title Improve interop with C union types Improve interop with C's union types Nov 9, 2016
@densh densh added the feature label Nov 9, 2016
@densh densh modified the milestones: 0.1, Backlog Jan 4, 2017
@densh densh modified the milestones: Backlog, 0.1 Feb 15, 2017
@densh densh modified the milestones: 0.4, Backlog May 20, 2017
@densh densh modified the milestones: 0.4, Backlog Jan 9, 2018
@IbrahimaWane
Copy link

Hello,
I am currently facing this issue; where I need to create a struct with a union as a member. Can you please provide a code of what you're describing above?
Thanks in advance

@densh
Copy link
Member Author

densh commented May 6, 2019

@IbrahimaWane Have you had a look at https://github.com/scala-native/scala-native-bindgen, otherwise feel free to drop by our gitter and we'll figure out a good mapping for your use case.

@IbrahimaWane
Copy link

Great!
Finally, I understood the concept of the binding generator - I had some difficulties.
I hope I will be able to use it properly.
Thank you

@IbrahimaWane
Copy link

IbrahimaWane commented May 7, 2019

Actually, I have encountered an issue. It seems to be the same as #555.
This is the thrown error:
[error] scala.scalanative.util.UnsupportedException: can't cast from Array(Byte,2) to Array(Class(Top(java.lang.Object)),0)

This is the struct generated by bindgen :

type struct_odbsys = native.CStruct7[native.CShort, native.CArray[native.CChar, native.Nat._2], native.CArray[native.CChar, native.Nat._2], native.CArray[native.CChar, native.Nat._2], native.CArray[native.CChar, native.Nat._4], native.CArray[native.CChar, native.Nat._4], native.CArray[native.CChar, native.Nat._2]]

In my code I pass the type, ODBSYS, surrounded by a Ptr[ ].

Do you have any suggestions?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants