diff --git a/SwiftKitCore/src/main/java/org/swift/swiftkit/core/JNISwiftInstance.java b/SwiftKitCore/src/main/java/org/swift/swiftkit/core/JNISwiftInstance.java index 891745a2..b9e9a914 100644 --- a/SwiftKitCore/src/main/java/org/swift/swiftkit/core/JNISwiftInstance.java +++ b/SwiftKitCore/src/main/java/org/swift/swiftkit/core/JNISwiftInstance.java @@ -17,6 +17,16 @@ import java.util.concurrent.atomic.AtomicBoolean; public abstract class JNISwiftInstance extends SwiftInstance { + /// Pointer to the "self". + private final long selfPointer; + + /** + * The pointer to the instance in memory. I.e. the {@code self} of the Swift object or value. + */ + public final long pointer() { + return this.selfPointer; + } + /** * The designated constructor of any imported Swift types. * @@ -24,7 +34,8 @@ public abstract class JNISwiftInstance extends SwiftInstance { * @param arena the arena this object belongs to. When the arena goes out of scope, this value is destroyed. */ protected JNISwiftInstance(long pointer, SwiftArena arena) { - super(pointer, arena); + super(arena); + this.selfPointer = pointer; } /** diff --git a/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftInstance.java b/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftInstance.java index 638cb8be..6d65c043 100644 --- a/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftInstance.java +++ b/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftInstance.java @@ -17,15 +17,6 @@ import java.util.concurrent.atomic.AtomicBoolean; public abstract class SwiftInstance { - /// Pointer to the "self". - private final long selfPointer; - - /** - * The pointer to the instance in memory. I.e. the {@code self} of the Swift object or value. - */ - public final long pointer() { - return this.selfPointer; - } /** * Called when the arena has decided the value should be destroyed. @@ -55,8 +46,7 @@ public final long pointer() { * @param pointer a pointer to the memory containing the value * @param arena the arena this object belongs to. When the arena goes out of scope, this value is destroyed. */ - protected SwiftInstance(long pointer, SwiftArena arena) { - this.selfPointer = pointer; + protected SwiftInstance(SwiftArena arena) { arena.register(this); } diff --git a/SwiftKitFFM/src/main/java/org/swift/swiftkit/ffm/FFMSwiftInstance.java b/SwiftKitFFM/src/main/java/org/swift/swiftkit/ffm/FFMSwiftInstance.java index f4a01aa4..d6d8a8d6 100644 --- a/SwiftKitFFM/src/main/java/org/swift/swiftkit/ffm/FFMSwiftInstance.java +++ b/SwiftKitFFM/src/main/java/org/swift/swiftkit/ffm/FFMSwiftInstance.java @@ -41,7 +41,7 @@ public abstract class FFMSwiftInstance extends SwiftInstance { * @param arena the arena this object belongs to. When the arena goes out of scope, this value is destroyed. */ protected FFMSwiftInstance(MemorySegment segment, AllocatingSwiftArena arena) { - super(segment.address(), arena); + super(arena); this.memorySegment = segment; }