Skip to content

Commit 6df1b41

Browse files
committed
cleanups
1 parent da42a87 commit 6df1b41

File tree

3 files changed

+16
-66
lines changed

3 files changed

+16
-66
lines changed

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

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,67 +28,22 @@
2828

2929
public class WithBufferTest {
3030

31-
/**
32-
* {@snippet lang = c:
33-
* void swiftjava_SwiftModule_returnArray(void (*_result_initialize)(const void *, ptrdiff_t))
34-
*}
35-
*/
36-
private static class swiftjava_SwiftModule_returnArray {
37-
private static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
38-
/* _result_initialize: */SwiftValueLayout.SWIFT_POINTER
39-
);
40-
private static final MemorySegment ADDR = null;
41-
// SwiftModule.findOrThrow("swiftjava_SwiftModule_returnArray");
42-
private static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
43-
44-
public static void call(java.lang.foreign.MemorySegment _result_initialize) {
45-
try {
46-
if (CallTraces.TRACE_DOWNCALLS) {
47-
CallTraces.traceDowncall(_result_initialize);
48-
}
49-
HANDLE.invokeExact(_result_initialize);
50-
} catch (Throwable ex$) {
51-
throw new AssertionError("should not reach here", ex$);
52-
}
53-
}
54-
55-
/**
56-
* {snippet lang=c :
57-
* void (*)(const void *, ptrdiff_t)
58-
* }
59-
*/
60-
private static class $_result_initialize {
61-
public static final class Function {
62-
byte[] result = null;
63-
64-
void apply(java.lang.foreign.MemorySegment _0, long _1) {
65-
this.result = _0.reinterpret(_1).toArray(ValueLayout.JAVA_BYTE);
66-
}
67-
}
68-
69-
private static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
70-
/* _0: */SwiftValueLayout.SWIFT_POINTER,
71-
/* _1: */SwiftValueLayout.SWIFT_INT
72-
);
73-
private static final MethodHandle HANDLE = SwiftRuntime.upcallHandle(Function.class, "apply", DESC);
74-
75-
private static MemorySegment toUpcallStub(Function fi, Arena arena) {
76-
return Linker.nativeLinker().upcallStub(HANDLE.bindTo(fi), DESC, arena);
77-
}
78-
}
31+
@Test
32+
void test_withBuffer() {
33+
AtomicLong bufferSize = new AtomicLong();
34+
MySwiftLibrary.withBuffer((buf) -> {
35+
CallTraces.trace("withBuffer{$0.byteSize()}=" + buf.byteSize());
36+
bufferSize.set(buf.byteSize());
37+
});
38+
39+
assertEquals(124, bufferSize.get());
7940
}
8041

42+
@Test
43+
void test_getArray() {
44+
AtomicLong bufferSize = new AtomicLong();
45+
byte[] javaBytes = MySwiftLibrary.getArray()
8146

82-
}
83-
84-
@Test
85-
void test_withBuffer() {
86-
AtomicLong bufferSize = new AtomicLong();
87-
MySwiftLibrary.withBuffer((buf) -> {
88-
CallTraces.trace("withBuffer{$0.byteSize()}=" + buf.byteSize());
89-
bufferSize.set(buf.byteSize());
90-
});
91-
92-
assertEquals(124, bufferSize.get());
93-
}
47+
assertEquals({1, 2, 3}, bufferSize.get());
48+
}
9449
}

Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,9 @@ struct CdeclLowering {
738738
base: "\(outParameterName)_initialize",
739739
methodName: nil, // just `(...)` apply the closure
740740
arguments: [
741-
.init(label: nil, argument: .member(.constant("_0"), member: "baseAddress")),
741+
.init(label: nil, argument: .member(.constant("_0"), member: "baseAddress!")),
742742
.init(label: nil, argument: .member(.constant("_0"), member: "count")),
743743
]
744-
// arguments: [
745-
// .init(label: nil, argument: .member(.placeholder, member: "baseAddress")),
746-
// .init(label: nil, argument: .member(.placeholder, member: "count")),
747-
// ]
748744
)
749745
)
750746
)

Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaBindingsPrinting.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ extension FFMSwift2JavaGenerator.JavaConversionStep {
582582

583583
/// Returns the conversion string applied to the placeholder.
584584
func render(_ printer: inout CodePrinter, _ placeholder: String, placeholderForDowncall: String? = nil) -> String {
585-
print("render: \(self)")
586585
// NOTE: 'printer' is used if the conversion wants to cause side-effects.
587586
// E.g. storing a temporary values into a variable.
588587
switch self {

0 commit comments

Comments
 (0)