@@ -80,29 +80,32 @@ static MemorySegment findOrThrow(String symbol) {
80
80
81
81
// ==== ------------------------------------------------------------------------------------------------------------
82
82
// free
83
- /**
84
- * Descriptor for the free C runtime function.
85
- */
86
- public static final FunctionDescriptor free$descriptor = FunctionDescriptor .ofVoid (
87
- ValueLayout .ADDRESS
88
- );
89
83
90
- /**
91
- * Address of the free C runtime function.
92
- */
93
- public static final MemorySegment free$addr = findOrThrow ("free" );
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
+ );
94
91
95
- /**
96
- * Handle for the free C runtime function.
97
- */
98
- public static final MethodHandle free$handle = Linker .nativeLinker ().downcallHandle (free$addr , free$descriptor );
92
+ /**
93
+ * Address of the free C runtime function.
94
+ */
95
+ public static final MemorySegment ADDR = findOrThrow ("free" );
96
+
97
+ /**
98
+ * Handle for the free C runtime function.
99
+ */
100
+ public static final MethodHandle HANDLE = Linker .nativeLinker ().downcallHandle (ADDR , DESC );
101
+ }
99
102
100
103
/**
101
104
* free the given pointer
102
105
*/
103
106
public static void cFree (MemorySegment pointer ) {
104
107
try {
105
- free$handle .invokeExact (pointer );
108
+ free . HANDLE .invokeExact (pointer );
106
109
} catch (Throwable ex$ ) {
107
110
throw new AssertionError ("should not reach here" , ex$ );
108
111
}
@@ -136,7 +139,7 @@ public static long retainCount(MemorySegment object) {
136
139
}
137
140
138
141
public static long retainCount (SwiftHeapObject object ) {
139
- return retainCount (object .$self ());
142
+ return retainCount (object .$memorySegment ());
140
143
}
141
144
142
145
// ==== ------------------------------------------------------------------------------------------------------------
@@ -166,7 +169,7 @@ public static void retain(MemorySegment object) {
166
169
}
167
170
168
171
public static long retain (SwiftHeapObject object ) {
169
- return retainCount (object .$self ());
172
+ return retainCount (object .$memorySegment ());
170
173
}
171
174
172
175
// ==== ------------------------------------------------------------------------------------------------------------
@@ -196,10 +199,11 @@ public static void release(MemorySegment object) {
196
199
}
197
200
198
201
public static long release (SwiftHeapObject object ) {
199
- return retainCount (object .$self ());
202
+ return retainCount (object .$memorySegment ());
200
203
}
201
204
202
205
// ==== ------------------------------------------------------------------------------------------------------------
206
+ // getTypeByName
203
207
204
208
/**
205
209
* {@snippet lang = swift:
@@ -395,38 +399,41 @@ public static long alignmentOfSwiftType(MemorySegment typeMetadata) {
395
399
return (flags & 0xFF ) + 1 ;
396
400
}
397
401
398
- /**
399
- * Descriptor for the swift_getTypeName runtime function.
400
- */
401
- public static final FunctionDescriptor swift_getTypeName$descriptor = FunctionDescriptor .of (
402
- /*returns=*/ MemoryLayout .structLayout (
403
- SWIFT_POINTER .withName ("utf8Chars" ),
404
- SWIFT_INT .withName ("length" )
405
- ),
406
- ValueLayout .ADDRESS ,
407
- ValueLayout .JAVA_BOOLEAN
408
- );
402
+ private static class swift_getTypeName {
409
403
410
- /**
411
- * Address of the swift_getTypeName runtime function.
412
- */
413
- public static final MemorySegment swift_getTypeName$addr = findOrThrow ("swift_getTypeName" );
404
+ /**
405
+ * Descriptor for the swift_getTypeName runtime function.
406
+ */
407
+ public static final FunctionDescriptor DESC = FunctionDescriptor .of (
408
+ /*returns=*/ MemoryLayout .structLayout (
409
+ SWIFT_POINTER .withName ("utf8Chars" ),
410
+ SWIFT_INT .withName ("length" )
411
+ ),
412
+ ValueLayout .ADDRESS ,
413
+ ValueLayout .JAVA_BOOLEAN
414
+ );
414
415
415
- /**
416
- * Handle for the swift_getTypeName runtime function.
417
- */
418
- public static final MethodHandle swift_getTypeName$handle = Linker .nativeLinker ().downcallHandle (swift_getTypeName$addr , swift_getTypeName$descriptor );
416
+ /**
417
+ * Address of the swift_getTypeName runtime function.
418
+ */
419
+ public static final MemorySegment ADDR = findOrThrow ("swift_getTypeName" );
420
+
421
+ /**
422
+ * Handle for the swift_getTypeName runtime function.
423
+ */
424
+ public static final MethodHandle HANDLE = Linker .nativeLinker ().downcallHandle (ADDR , DESC );
425
+ }
419
426
420
427
/**
421
428
* Produce the name of the Swift type given its Swift type metadata.
422
429
* <p>
423
- * If 'qualified' is true, leave all of the qualification in place to
430
+ * If 'qualified' is true, leave all the qualification in place to
424
431
* disambiguate the type, producing a more complete (but longer) type name.
425
432
*/
426
433
public static String nameOfSwiftType (MemorySegment typeMetadata , boolean qualified ) {
427
434
try {
428
435
try (Arena arena = Arena .ofConfined ()) {
429
- MemorySegment charsAndLength = (MemorySegment ) swift_getTypeName$handle .invokeExact ((SegmentAllocator ) arena , typeMetadata , qualified );
436
+ MemorySegment charsAndLength = (MemorySegment ) swift_getTypeName . HANDLE .invokeExact ((SegmentAllocator ) arena , typeMetadata , qualified );
430
437
MemorySegment utf8Chars = charsAndLength .get (SWIFT_POINTER , 0 );
431
438
String typeName = utf8Chars .getString (0 );
432
439
cFree (utf8Chars );
0 commit comments