jextract/ffm: Support [UInt8] parameters#477
Merged
Merged
Conversation
1a940fa to
91ff2c5
Compare
ktoso
commented
Dec 3, 2025
ktoso
commented
Dec 3, 2025
| """ | ||
| @_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))) |
Collaborator
Author
There was a problem hiding this comment.
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.
Collaborator
Author
|
For some performance follow up work: #478 because for now passing arrays will not be ideasl |
ktoso
commented
Dec 3, 2025
| let cdeclParameters = [ | ||
| SwiftParameter( | ||
| convention: .byValue, | ||
| parameterName: "\(parameterName)_pointer", |
Collaborator
Author
There was a problem hiding this comment.
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
ktoso
commented
Dec 5, 2025
| printParameterDescriptorClasses(&printer, cFunc) | ||
| if let outCallback = translated.translatedSignature.result.outCallback { | ||
| printUpcallParameterDescriptorClasses(&printer, outCallback) | ||
| } else { // FIXME: not an "else" |
Collaborator
Author
There was a problem hiding this comment.
should probably just fix this right away
Collaborator
Author
There was a problem hiding this comment.
will do later, after all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.