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

Fix kotlin unsigned type conversion #747

Merged

Conversation

emarteca
Copy link
Contributor

The type conversion on the FFI boundary was broken in Kotlin for unsigned types -- regular methods and trait methods need to be treated differently. This PR fixes the issue.

@emarteca emarteca marked this pull request as ready for review December 10, 2024 22:15
Copy link
Contributor

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, but why is supports_unsigned necessary? Would love some comments explaining that situation, and then feel free to merge

tool/src/kotlin/mod.rs Show resolved Hide resolved
@emarteca
Copy link
Contributor Author

emarteca commented Dec 10, 2024

Ah, yes, I'll add a comment about this, good point!
The reason is that for non-trait methods (on opaques/structs/enums), the methods are being called via JNA, which is built in Java, and Java doesn't support unsigned types. Because of this, we need the defined JNA Library to only use signed types in the method signatures, and convert from unsigned to signed and back as required so that users of the methods can pass in/receive the unsigned types that match the API.

But, for the generated traits, we don't have a JNA Library -- the trait methods are meant to be implemented by the user, and so they should have the expected (unsigned) API. The methods are called directly from Rust, so the JNA lack of support for unsigned types doesn't apply.


That being said, the actual right way to do this is to subclass the JNA IntegerType and make a representation for all the unsigned types, since that's allowed over the FFI layer. I have someone blocked on this fix right now though, so I'm thinking I'll push this solution and then fix the issue properly in the next couple days when it's less urgent: #748

Copy link
Contributor

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, land once you have the code commented

tool/src/kotlin/formatter.rs Outdated Show resolved Hide resolved
@emarteca
Copy link
Contributor Author

Ok sweet, thanks!

@emarteca emarteca merged commit 893cf50 into rust-diplomat:main Dec 10, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants