Skip to content

jextract/jni: handle UnsafeRawBufferPointer params#668

Merged
ktoso merged 4 commits intoswiftlang:mainfrom
ktoso:wip-unsafeRawBufferPointer-jni
Apr 1, 2026
Merged

jextract/jni: handle UnsafeRawBufferPointer params#668
ktoso merged 4 commits intoswiftlang:mainfrom
ktoso:wip-unsafeRawBufferPointer-jni

Conversation

@ktoso
Copy link
Copy Markdown
Collaborator

@ktoso ktoso commented Apr 1, 2026

This allows passing a Java byte array to an UnsafeRawBufferPointer accepting API in Swift. This conversion needs to copy a bunch but makes pretty much sense. This is in JNI mode specifically.

In FFM mode we could do better by allocating and passing a MemorySegment but this is to unblock APIs in JNI mode specifically.

We do allow returning an URBP to Java as well, but this is very dubious and scary, so we don't make anything sneaky here and literarily return this as an SwiftUnsafeRawBufferPointer that you may be able to do "something" with in java... I actually ended up deciding that's a horrible idea, if anyone really needs it they can talk to us and we'll figure it out, otherwise I'm skipping this for now.

@ktoso ktoso force-pushed the wip-unsafeRawBufferPointer-jni branch from ac5ddbc to 3feba7f Compare April 1, 2026 12:58
This allows passing a Java byte array to an `UnsafeRawBufferPointer` accepting API in Swift. This conversion needs to copy a bunch but makes pretty much sense. This is in JNI mode specifically.

In FFM mode we could do better by allocating and passing a MemorySegment but this is to unblock APIs in JNI mode specifically.
@ktoso ktoso force-pushed the wip-unsafeRawBufferPointer-jni branch from 3feba7f to d24ffae Compare April 1, 2026 12:59
ktoso added 2 commits April 1, 2026 22:19
This allows passing a Java byte array to an `UnsafeRawBufferPointer` accepting API in Swift. This conversion needs to copy a bunch but makes pretty much sense. This is in JNI mode specifically.

In FFM mode we could do better by allocating and passing a MemorySegment but this is to unblock APIs in JNI mode specifically.
@ktoso ktoso merged commit f5b6c66 into swiftlang:main Apr 1, 2026
61 checks passed
@ktoso ktoso deleted the wip-unsafeRawBufferPointer-jni branch April 1, 2026 14:23
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.

1 participant