-
Notifications
You must be signed in to change notification settings - Fork 70
jextract/ffm: Support [UInt8] parameters #477
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
Conversation
1a940fa to
91ff2c5
Compare
| """ | ||
| @_cdecl("swiftjava_SwiftModule_acceptArray_array") | ||
| public func swiftjava_SwiftModule_acceptArray_array(_ array_pointer: UnsafeRawPointer, _ array_count: Int) { | ||
| acceptArray(array: [UInt8](UnsafeRawBufferPointer(start: array_pointer, count: array_count))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today we end up with 2 copies because of this.
Instead, we should accept a raw pointer that we know is an swift array of the rtight type here.
|
For some performance follow up work: #478 because for now passing arrays will not be ideasl |
| let cdeclParameters = [ | ||
| SwiftParameter( | ||
| convention: .byValue, | ||
| parameterName: "\(parameterName)_pointer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have naming inconsistency; these should be $ and not _ but seems we got this inconsistency already from the Data work -- lets fix it separately, since this made the PR kinda big
87efb9f to
598787c
Compare
598787c to
da42a87
Compare
3063fef to
a4fd03f
Compare
| printParameterDescriptorClasses(&printer, cFunc) | ||
| if let outCallback = translated.translatedSignature.result.outCallback { | ||
| printUpcallParameterDescriptorClasses(&printer, outCallback) | ||
| } else { // FIXME: not an "else" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably just fix this right away
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do later, after all
These cause severe copying as we must copy the Java array into an off heap memory segment and then we must copy AGAIN into the Swift Array (!), so this is deeply inefficient and you should always prefer pointers of
Datawhich we had support for already earlier.Edit: Returning an array is now efficient, we're able to return [UInt8] which gets directly copied from native memory into an
byte[]on the heap 🥳 In a single copy.We can do better with other types, but this is the best we can hope to achieve for native arrays on Swift an Java side.
We'll do even better with other types by keeping the native memory retained etc. This is the most convenient though.
However, this is useful for convenience and we should offer this anyway.