-
Notifications
You must be signed in to change notification settings - Fork 67
Make JNI handling of Int/UInt match FFM mode. #460
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for this! Definitely an important step that we handle I do however, think we need to give this some more thought. Especially since the JNI mode will probably be used a lot by Android folks, which is commonly 32-bit. If you have the following Swift function: func f(i: Int)with this PR it gets translated to void f(long i)however, the downcall to Swift would be Also we should add some codegen tests and runtime tests while we are it, as well as add the |
|
I am aware of Int64 -> Int32 conversion problem but I didn't think about it as problem needed to be addressed in the same PR. To be honest I thought 32-bit is rare for Android, so I have no problem to work on solution for it in this PR. |
|
Thanks for the PR, this would be good to address. Overall the two "modes" should behave the same wherever possible and it is a problem that they're a bit independent currently so this would be good to align the two. 32bit is very rare and AFAICS there is a number of prominent apps that choose to not support 32bit Android devices. The Java annotation mentioned is the https://github.com/swiftlang/swift-java/blob/main/SwiftKitCore/src/main/java/org/swift/swiftkit/core/annotations/Unsigned.java so please have a look how we're using it in the ffm mode to mark something was an "U"Int. The imported parameters or return types basically get an |
|
I know 32-bit is rare these days. But since it's still a supported platform, for both Swift and the Swift Android SDK, I think we should still handle it. For example for us, most of our devices are 32-bit, and that is in the millions:) OK by me to merge this and we can tackle it in another PR, just wanted to flag this, as we need to handle it somehow. @_cdecl()
func $f(i: jlong) {
let swiftInt = Int64(fromJNI: i, ...)
#if _pointerBitWidth(_32)
guard swiftInt <= Int32.max, swiftInt >= Int32.min else {
// throw overflow exception
}
#endif
}maybe this could even just be in the |
|
Well we can't merge anything this week, so yes, let's please polish this up before branches get unlocked next week. |
I believe that both modes should behave similarly when handling Int/UInt types. This PR makes JNI handle these types in the same way as FFM.