Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#if os(Linux)
import Glibc
#elseif os(Android)
import Android
#else
import Darwin.C
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,12 @@ extension JNISwift2JavaGenerator {
if swiftFunctionResultType.isVoid {
printer.print("environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: nil)])")
} else {
printer.printBraceBlock("withVaList([SwiftJavaRuntimeSupport._JNIBoxedConversions.box(\(inner), in: environment)])") { printer in
printer.print("environment.interface.CallBooleanMethodV(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, $0)")
}
printer.print(
"""
let boxedResult$ = SwiftJavaRuntimeSupport._JNIBoxedConversions.box(\(inner), in: environment)
environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: boxedResult$)])
"""
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,14 @@ extension JNISwift2JavaGenerator {
"""
)
let upcallArguments = zip(enumCase.parameterConversions, caseNames).map { conversion, caseName in
// '0' is treated the same as a null pointer.
let nullConversion = !conversion.native.javaType.isPrimitive ? " ?? 0" : ""
let nullConversion = !conversion.native.javaType.isPrimitive ? " ?? nil" : ""
let result = conversion.native.conversion.render(&printer, caseName)
return "\(result)\(nullConversion)"
return "jvalue(\(conversion.native.javaType.jniFieldName): \(result)\(nullConversion))"
}
printer.print(
"""
return withVaList([\(upcallArguments.joined(separator: ", "))]) {
return environment.interface.NewObjectV(environment, class$, constructorID$, $0)
}
let newObjectArgs$: [jvalue] = [\(upcallArguments.joined(separator: ", "))]
return environment.interface.NewObjectA(environment, class$, constructorID$, newObjectArgs$)
"""
)
}
Expand Down
20 changes: 8 additions & 12 deletions Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ struct JNIAsyncTests {
}
let swiftResult$ = await SwiftModule.async(i: Int64(fromJNI: i, in: environment))
environment = try JavaVirtualMachine.shared().environment()
withVaList([SwiftJavaRuntimeSupport._JNIBoxedConversions.box(swiftResult$.getJNIValue(in: environment), in: environment)]) {
environment.interface.CallBooleanMethodV(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, $0)
}
let boxedResult$ = SwiftJavaRuntimeSupport._JNIBoxedConversions.box(swiftResult$.getJNIValue(in: environment), in: environment)
environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: boxedResult$)])
}
}
else {
Expand All @@ -238,9 +237,8 @@ struct JNIAsyncTests {
}
let swiftResult$ = await SwiftModule.async(i: Int64(fromJNI: i, in: environment))
environment = try JavaVirtualMachine.shared().environment()
withVaList([SwiftJavaRuntimeSupport._JNIBoxedConversions.box(swiftResult$.getJNIValue(in: environment), in: environment)]) {
environment.interface.CallBooleanMethodV(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, $0)
}
let boxedResult$ = SwiftJavaRuntimeSupport._JNIBoxedConversions.box(swiftResult$.getJNIValue(in: environment), in: environment)
environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: boxedResult$)])
}
}
return
Expand Down Expand Up @@ -317,9 +315,8 @@ struct JNIAsyncTests {
let result$ = UnsafeMutablePointer<MyClass>.allocate(capacity: 1)
result$.initialize(to: swiftResult$)
let resultBits$ = Int64(Int(bitPattern: result$))
withVaList([SwiftJavaRuntimeSupport._JNIBoxedConversions.box(resultBits$.getJNIValue(in: environment), in: environment)]) {
environment.interface.CallBooleanMethodV(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, $0)
}
let boxedResult$ = SwiftJavaRuntimeSupport._JNIBoxedConversions.box(resultBits$.getJNIValue(in: environment), in: environment)
environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: boxedResult$)])
}
}
else {
Expand All @@ -334,9 +331,8 @@ struct JNIAsyncTests {
let result$ = UnsafeMutablePointer<MyClass>.allocate(capacity: 1)
result$.initialize(to: swiftResult$)
let resultBits$ = Int64(Int(bitPattern: result$))
withVaList([SwiftJavaRuntimeSupport._JNIBoxedConversions.box(resultBits$.getJNIValue(in: environment), in: environment)]) {
environment.interface.CallBooleanMethodV(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, $0)
}
let boxedResult$ = SwiftJavaRuntimeSupport._JNIBoxedConversions.box(resultBits$.getJNIValue(in: environment), in: environment)
environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: boxedResult$)])
}
}
return
Expand Down
10 changes: 4 additions & 6 deletions Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,8 @@ struct JNIEnumTests {
let class$ = cache$.javaClass
let method$ = _JNIMethodIDCache.Method(name: "<init>", signature: "(Ljava/lang/String;)V")
let constructorID$ = cache$[method$]
return withVaList([_0.getJNIValue(in: environment) ?? 0]) {
return environment.interface.NewObjectV(environment, class$, constructorID$, $0)
}
let newObjectArgs$: [jvalue] = [jvalue(l: _0.getJNIValue(in: environment) ?? nil)]
return environment.interface.NewObjectA(environment, class$, constructorID$, newObjectArgs$)
}
""",
"""
Expand All @@ -318,9 +317,8 @@ struct JNIEnumTests {
let class$ = cache$.javaClass
let method$ = _JNIMethodIDCache.Method(name: "<init>", signature: "(JI)V")
let constructorID$ = cache$[method$]
return withVaList([x.getJNIValue(in: environment), y.getJNIValue(in: environment)]) {
return environment.interface.NewObjectV(environment, class$, constructorID$, $0)
}
let newObjectArgs$: [jvalue] = [jvalue(j: x.getJNIValue(in: environment)), jvalue(i: y.getJNIValue(in: environment))]
return environment.interface.NewObjectA(environment, class$, constructorID$, newObjectArgs$)
}
"""
])
Expand Down
Loading