Skip to content

Commit 185a880

Browse files
committed
Use varHandle instead of offset for reading data off VWT
1 parent 6a07e93 commit 185a880

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

SwiftKit/src/main/java/org/swift/swiftkit/SwiftKit.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.lang.foreign.*;
2222
import java.lang.invoke.MethodHandle;
23+
import java.lang.invoke.VarHandle;
2324
import java.nio.file.CopyOption;
2425
import java.nio.file.FileSystems;
2526
import java.nio.file.Files;
@@ -437,6 +438,14 @@ public static long getSwiftInt(MemorySegment memorySegment, long offset) {
437438
}
438439
}
439440

441+
public static long getSwiftInt(MemorySegment memorySegment, VarHandle handle) {
442+
if (SwiftValueLayout.SWIFT_INT == ValueLayout.JAVA_LONG) {
443+
return (long) handle.get(memorySegment, 0);
444+
} else {
445+
return (int) handle.get(memorySegment, 0);
446+
}
447+
}
448+
440449

441450
private static class swift_getTypeName {
442451

0 commit comments

Comments
 (0)