Skip to content

[JExtract] Add support for JNI member methods #305

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 2 commits into from
Jul 12, 2025

Conversation

madsodgaard
Copy link
Contributor

Adds support for generating code for member methods in JNI mode. Also fixes a bug with throwing functions, that also affected the JavaKit macros.

public func doSomething(x: Int64) {}

is generated as:

Java

 public void doSomething(long x) {
  long selfPointer = this.pointer();
  MyClass.$doSomething(x, selfPointer);
}

private static native void $doSomething(long x, long selfPointer);

Swift

@_cdecl("Java_com_example_swift_MyClass__00024doSomething__JJ")
func Java_com_example_swift_MyClass__00024doSomething__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, x: jlong, selfPointer: jlong) {
  let self$ = UnsafeMutablePointer<MyClass>(bitPattern: Int(Int64(fromJNI: selfPointer, in: environment!)))!
  self$.pointee.doSomething(x: Int64(fromJNI: x, in: environment!))
}

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.

Very good! just the nitpick about the passing in the thread. Let's fix that separately maybe :-)

@ktoso ktoso merged commit 7bec685 into swiftlang:main Jul 12, 2025
55 of 56 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.

2 participants