Skip to content

Commit 9cd3191

Browse files
NakaokaReiclaude
andcommitted
fix: use C-compatible types in @JavaImplementation macro for C++ interop
- Update ImplementsJavaMacro to generate CJNIEnv instead of JNIEnv to ensure compatibility with C++ interoperability mode - Update JNIAsyncTests LegacyFuture test expectations to use C-compatible types (CJNIEnv, Cjobject) See: #391 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ec7332c commit 9cd3191

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ jobs:
202202
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
203203
env:
204204
CXX_INTEROP: '1'
205+
SWIFT_JAVA_VERBOSE: true
205206
steps:
206207
- uses: actions/checkout@v4
207208
- name: Prepare CI Environment
@@ -229,6 +230,7 @@ jobs:
229230
]
230231
env:
231232
CXX_INTEROP: '1'
233+
SWIFT_JAVA_VERBOSE: true
232234
steps:
233235
- uses: actions/checkout@v4
234236
- name: Prepare CI Environment

Sources/SwiftJavaMacros/ImplementsJavaMacro.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ extension JavaImplementationMacro: PeerMacro {
7777
}
7878

7979
// Map the parameters.
80+
// Use CJNIEnv for C++ interoperability compatibility.
81+
// See: https://github.com/swiftlang/swift-java/issues/391
8082
let cParameters: [FunctionParameterSyntax] =
8183
[
82-
"environment: UnsafeMutablePointer<JNIEnv?>!",
84+
"environment: UnsafeMutablePointer<CJNIEnv?>!",
8385
isStatic ? "thisClass: jclass" : "thisObj: jobject",
8486
]
8587
+ parametersClause.parameters.map { param in

Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,12 @@ struct JNIAsyncTests {
457457
expectedChunks: [
458458
"""
459459
@_cdecl("Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2")
460-
func Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, c: jlong, result_future: jobject?) {
460+
func Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2(environment: UnsafeMutablePointer<CJNIEnv?>!, thisClass: jclass, c: jlong, result_future: Cjobject?) {
461461
...
462462
var task: Task<Void, Never>? = nil
463463
...
464464
environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.SimpleCompletableFuture.complete, [jvalue(l: boxedResult$)])
465-
...
465+
...
466466
}
467467
"""
468468
]

0 commit comments

Comments
 (0)