Skip to content

[JExtract/JNI] Add support for classes/structs as parameters and return values #326

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

Merged
merged 5 commits into from
Jul 22, 2025

Conversation

madsodgaard
Copy link
Contributor

Adds support for passing in classes/structs as parameters to functions and returning them as well. All functions now generate both a public "user-facing" Java method and a native method that is called from that. Any classes are passed as pointers and returned as pointers.

I also refactored quite a bit of the internal code to make it match the FFM style more, this should make it easier to understand and contribute to both modes.

@madsodgaard
Copy link
Contributor Author

@rintaro As I refactored the code to match the way FFM does things, with ConversionSteps and so on, it would be nice if you could take a look at this PR as well 😄

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Overall looks good to me! I did have some small nitpicks here and there. @rintaro could you also give it a look? This duplicates some small types the FFM side used, but maybe this way we'll be able to head towards converging them a bit... rather than do it all right away 🤔

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Looks good now!

@@ -110,7 +110,7 @@ extension JNISwift2JavaGenerator {
// so we pass the pointer.
return NativeResult(
javaType: .long,
conversion: .getJNIValue(.allocateSwiftValue(name: "_result", swiftType: swiftResult.type))
conversion: .getJNIValue(.allocateSwiftValue(name: "result", swiftType: swiftResult.type))
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks :)

@ktoso ktoso merged commit a25d216 into swiftlang:main Jul 22, 2025
79 of 84 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.

3 participants