Skip to content

Commit aab3778

Browse files
committed
for error solving
1 parent 9008e0d commit aab3778

7 files changed

Lines changed: 145 additions & 146 deletions

File tree

Samples/SwiftJavaExtractFFMSampleApp/src/jmh/java/org/swift/swiftkit/ffm/StringPassingBenchmark.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors
5+
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -18,7 +18,6 @@
1818
import com.example.swift.MySwiftClass;
1919
import com.example.swift.MySwiftLibrary;
2020
import org.openjdk.jmh.annotations.*;
21-
import org.swift.swiftkit.core.ClosableSwiftArena;
2221

2322
import java.util.concurrent.TimeUnit;
2423

@@ -27,7 +26,7 @@
2726
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
2827
@OutputTimeUnit(TimeUnit.NANOSECONDS)
2928
@State(Scope.Thread)
30-
@Fork(value = 2, jvmArgsAppend = {"--enable-native-access=ALL-UNNAMED"})
29+
@Fork(value = 2, jvmArgsAppend = { "--enable-native-access=ALL-UNNAMED" })
3130
public class StringPassingBenchmark {
3231

3332
@Param({
@@ -70,16 +69,23 @@ public long writeString_baseline() {
7069
}
7170

7271
static String makeString(int size) {
73-
var text =
74-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut in augue ullamcorper, mattis lacus tincidunt, " +
75-
"accumsan massa. Morbi gravida purus ut porttitor iaculis. Vestibulum lacinia, mi in tincidunt hendrerit," +
76-
"lectus est placerat magna, vitae vestibulum nulla ligula at massa. Pellentesque nibh quam, pulvinar eu " +
77-
"nunc congue, molestie molestie augue. Nam convallis consectetur velit, at dictum risus ullamcorper iaculis. " +
78-
"Vestibulum lacinia nisi in elit consectetur vulputate. Praesent id odio tristique, tincidunt arcu et, convallis velit. " +
79-
"Sed vitae pulvinar arcu. Curabitur euismod mattis dui in suscipit. Morbi aliquet facilisis vulputate. Phasellus " +
80-
"non lectus dapibus, semper magna eu, aliquet magna. Suspendisse vel enim at augue luctus gravida. Suspendisse " +
81-
"venenatis justo non accumsan sollicitudin. Suspendisse vitae ornare odio, id blandit nibh. Nulla facilisi. " +
82-
"Nulla nulla orci, finibus nec luctus et, faucibus et ligula.";
72+
var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut in augue ullamcorper, mattis lacus tincidunt, "
73+
+
74+
"accumsan massa. Morbi gravida purus ut porttitor iaculis. Vestibulum lacinia, mi in tincidunt hendrerit,"
75+
+
76+
"lectus est placerat magna, vitae vestibulum nulla ligula at massa. Pellentesque nibh quam, pulvinar eu "
77+
+
78+
"nunc congue, molestie molestie augue. Nam convallis consectetur velit, at dictum risus ullamcorper iaculis. "
79+
+
80+
"Vestibulum lacinia nisi in elit consectetur vulputate. Praesent id odio tristique, tincidunt arcu et, convallis velit. "
81+
+
82+
"Sed vitae pulvinar arcu. Curabitur euismod mattis dui in suscipit. Morbi aliquet facilisis vulputate. Phasellus "
83+
+
84+
"non lectus dapibus, semper magna eu, aliquet magna. Suspendisse vel enim at augue luctus gravida. Suspendisse "
85+
+
86+
"venenatis justo non accumsan sollicitudin. Suspendisse vitae ornare odio, id blandit nibh. Nulla facilisi. "
87+
+
88+
"Nulla nulla orci, finibus nec luctus et, faucibus et ligula.";
8389
return text.substring(0, size);
8490
}
8591
}

Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/FFMArraysTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
5+
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -15,28 +15,28 @@
1515
package com.example.swift;
1616

1717
import org.junit.jupiter.api.Test;
18-
import org.swift.swiftkit.core.*;
1918
import org.swift.swiftkit.ffm.*;
2019

2120
import static org.junit.jupiter.api.Assertions.*;
2221

2322
import java.lang.foreign.ValueLayout;
2423
import java.util.Arrays;
25-
import java.util.concurrent.atomic.AtomicLong;
2624
import java.util.stream.IntStream;
2725

2826
public class FFMArraysTest {
2927

3028
@Test
3129
void test_sumAllByteArrayElements_throughMemorySegment() {
32-
byte[] bytes = new byte[124];
30+
byte[] bytes = new byte[124];
3331
Arrays.fill(bytes, (byte) 1);
3432

3533
try (var arena = AllocatingSwiftArena.ofConfined()) {
36-
// NOTE: We cannot use MemorySegment.ofArray because that creates a HEAP backed segment and therefore cannot pass into native:
37-
// java.lang.IllegalArgumentException: Heap segment not allowed: MemorySegment{ kind: heap, heapBase: [B@5b6ec132, address: 0x0, byteSize: 124 }
38-
// MemorySegment bytesSegment = MemorySegment.ofArray(bytes); // NO COPY (!)
39-
// MySwiftLibrary.sumAllByteArrayElements(bytesSegment, bytes.length);
34+
// NOTE: We cannot use MemorySegment.ofArray because that creates a HEAP backed
35+
// segment and therefore cannot pass into native:
36+
// java.lang.IllegalArgumentException: Heap segment not allowed: MemorySegment{
37+
// kind: heap, heapBase: [B@5b6ec132, address: 0x0, byteSize: 124 }
38+
// MemorySegment bytesSegment = MemorySegment.ofArray(bytes); // NO COPY (!)
39+
// MySwiftLibrary.sumAllByteArrayElements(bytesSegment, bytes.length);
4040

4141
var bytesCopy = arena.allocateFrom(ValueLayout.JAVA_BYTE, bytes);
4242
var swiftSideSum = MySwiftLibrary.sumAllByteArrayElements(bytesCopy, bytes.length);
@@ -48,7 +48,7 @@ void test_sumAllByteArrayElements_throughMemorySegment() {
4848

4949
@Test
5050
void test_sumAllByteArrayElements_arrayCopy() {
51-
byte[] bytes = new byte[124];
51+
byte[] bytes = new byte[124];
5252
Arrays.fill(bytes, (byte) 1);
5353

5454
var swiftSideSum = MySwiftLibrary.sumAllByteArrayElements(bytes);
@@ -59,9 +59,8 @@ void test_sumAllByteArrayElements_arrayCopy() {
5959

6060
@Test
6161
void test_getArray() {
62-
AtomicLong bufferSize = new AtomicLong();
6362
byte[] javaBytes = MySwiftLibrary.getArray(); // automatically converted [UInt8] to byte[]
6463

65-
assertArrayEquals(new byte[]{1, 2, 3}, javaBytes);
64+
assertArrayEquals(new byte[] { 1, 2, 3 }, javaBytes);
6665
}
6766
}

Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/MultipleTypesFromSingleFileTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
5+
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -15,17 +15,10 @@
1515
package com.example.swift;
1616

1717
import org.junit.jupiter.api.Test;
18-
import org.swift.swiftkit.core.*;
1918
import org.swift.swiftkit.ffm.*;
2019

21-
import java.lang.foreign.Arena;
22-
import java.util.Optional;
23-
import java.util.OptionalInt;
24-
25-
import static org.junit.jupiter.api.Assertions.*;
26-
2720
public class MultipleTypesFromSingleFileTest {
28-
21+
2922
@Test
3023
void bothTypesMustHaveBeenGenerated() {
3124
try (var arena = AllocatingSwiftArena.ofConfined()) {

Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors
5+
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -14,14 +14,9 @@
1414

1515
package com.example.swift;
1616

17-
import org.junit.jupiter.api.Disabled;
1817
import org.junit.jupiter.api.Test;
19-
import org.swift.swiftkit.core.SwiftLibraries;
2018
import org.swift.swiftkit.ffm.AllocatingSwiftArena;
2119

22-
import java.io.File;
23-
import java.util.stream.Stream;
24-
2520
import static org.junit.jupiter.api.Assertions.*;
2621

2722
public class SwiftTypeInSubDirectoryTest {

Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/WithBufferTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
5+
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -15,16 +15,11 @@
1515
package com.example.swift;
1616

1717
import org.junit.jupiter.api.Test;
18-
import org.swift.swiftkit.core.*;
19-
import org.swift.swiftkit.ffm.*;
18+
import org.swift.swiftkit.core.CallTraces;
2019

2120
import static org.junit.jupiter.api.Assertions.*;
2221

23-
import java.lang.foreign.*;
24-
import java.lang.invoke.MethodHandle;
25-
import java.util.Arrays;
2622
import java.util.concurrent.atomic.AtomicLong;
27-
import java.util.stream.IntStream;
2823

2924
public class WithBufferTest {
3025

Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaBindingsPrinting.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024-2025 Apple Inc. and the Swift.org project authors
5+
// Copyright (c) 2024-2026 Apple Inc. and the Swift.org project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -309,7 +309,9 @@ extension FFMSwift2JavaGenerator {
309309
"""
310310
)
311311

312-
let cdeclParams = functionType.cdeclType.parameters.map({ "\($0.parameterName!)" })
312+
let cdeclParams = functionType.cdeclType.parameters.enumerated().map { idx, param in
313+
param.parameterName ?? "_\(idx)"
314+
}
313315

314316
printer.printBraceBlock(
315317
"""

0 commit comments

Comments
 (0)