Skip to content

Commit f6888e3

Browse files
committed
fix tests
1 parent 62f9c36 commit f6888e3

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import Darwin
16-
1715
import JavaTypes
1816
import SwiftJavaConfigurationShared
1917

SwiftKitCore/src/test/java/org/swift/swiftkit/AutoArenaTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public FakeSwiftInstance(SwiftArena arena) {
5858
return () -> {};
5959
}
6060

61+
@Override
62+
public long $typeMetadataAddress() {
63+
return 0;
64+
}
65+
6166
@Override
6267
public long $memoryAddress() {
6368
return 0;

SwiftKitFFM/src/main/java/org/swift/swiftkit/ffm/FFMSwiftInstance.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
import org.swift.swiftkit.core.SwiftInstanceCleanup;
1919

2020
import java.lang.foreign.MemorySegment;
21+
import java.util.concurrent.atomic.AtomicBoolean;
2122

2223
public abstract class FFMSwiftInstance implements SwiftInstance {
2324
private final MemorySegment memorySegment;
2425

26+
// TODO: make this a flagset integer and/or use a field updater
27+
/** Used to track additional state of the underlying object, e.g. if it was explicitly destroyed. */
28+
private final AtomicBoolean $state$destroyed = new AtomicBoolean(false);
29+
2530
/**
2631
* The designated constructor of any imported Swift types.
2732
*
@@ -52,6 +57,16 @@ protected FFMSwiftInstance(MemorySegment segment, AllocatingSwiftArena arena) {
5257
*/
5358
public abstract SwiftAnyType $swiftType();
5459

60+
/**
61+
* Exposes a boolean value which can be used to indicate if the object was destroyed.
62+
* <p/>
63+
* This is exposing the object, rather than performing the action because we don't want to accidentally
64+
* form a strong reference to the {@code SwiftInstance} which could prevent the cleanup from running,
65+
* if using an GC managed instance (e.g. using an {@code AutoSwiftMemorySession}.
66+
*/
67+
public final AtomicBoolean $statusDestroyedFlag() {
68+
return this.$state$destroyed;
69+
}
5570

5671
@Override
5772
public SwiftInstanceCleanup $createCleanup() {
@@ -65,7 +80,6 @@ protected FFMSwiftInstance(MemorySegment segment, AllocatingSwiftArena arena) {
6580
);
6681
}
6782

68-
6983
/**
7084
* Returns `true` if this swift instance is a reference type, i.e. a `class` or (`distributed`) `actor`.
7185
*

0 commit comments

Comments
 (0)