Skip to content

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