Skip to content

Commit 1bfa241

Browse files
committed
SwiftKit: use inner-static class pattern for DESC/ADDR/HANDLE constants
It's useful to keep the exact same pattern everywhere as it's so repetetive code.
1 parent 2536aa7 commit 1bfa241

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,31 @@ static MemorySegment findOrThrow(String symbol) {
8181
// ==== ------------------------------------------------------------------------------------------------------------
8282
// free
8383

84-
/**
85-
* Descriptor for the free C runtime function.
86-
*/
87-
public static final FunctionDescriptor free$descriptor = FunctionDescriptor.ofVoid(
88-
ValueLayout.ADDRESS
89-
);
84+
static abstract class free {
85+
/**
86+
* Descriptor for the free C runtime function.
87+
*/
88+
public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
89+
ValueLayout.ADDRESS
90+
);
9091

91-
/**
92-
* Address of the free C runtime function.
93-
*/
94-
public static final MemorySegment free$addr = findOrThrow("free");
92+
/**
93+
* Address of the free C runtime function.
94+
*/
95+
public static final MemorySegment ADDR = findOrThrow("free");
9596

96-
/**
97-
* Handle for the free C runtime function.
98-
*/
99-
public static final MethodHandle free$handle = Linker.nativeLinker().downcallHandle(free$addr, free$descriptor);
97+
/**
98+
* Handle for the free C runtime function.
99+
*/
100+
public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
101+
}
100102

101103
/**
102104
* free the given pointer
103105
*/
104106
public static void cFree(MemorySegment pointer) {
105107
try {
106-
free$handle.invokeExact(pointer);
108+
free.HANDLE.invokeExact(pointer);
107109
} catch (Throwable ex$) {
108110
throw new AssertionError("should not reach here", ex$);
109111
}
@@ -137,7 +139,7 @@ public static long retainCount(MemorySegment object) {
137139
}
138140

139141
public static long retainCount(SwiftHeapObject object) {
140-
return retainCount(object.$self());
142+
return retainCount(object.$memorySegment());
141143
}
142144

143145
// ==== ------------------------------------------------------------------------------------------------------------
@@ -167,7 +169,7 @@ public static void retain(MemorySegment object) {
167169
}
168170

169171
public static long retain(SwiftHeapObject object) {
170-
return retainCount(object.$self());
172+
return retainCount(object.$memorySegment());
171173
}
172174

173175
// ==== ------------------------------------------------------------------------------------------------------------
@@ -197,7 +199,7 @@ public static void release(MemorySegment object) {
197199
}
198200

199201
public static long release(SwiftHeapObject object) {
200-
return retainCount(object.$self());
202+
return retainCount(object.$memorySegment());
201203
}
202204

203205
// ==== ------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)