@@ -34,6 +34,9 @@ class OpenSlideFFM {
34
34
private static final AddressLayout C_POINTER = ADDRESS .withTargetLayout (
35
35
MemoryLayout .sequenceLayout (Long .MAX_VALUE , JAVA_BYTE ));
36
36
37
+ private static final MemoryLayout SIZE_T = Linker .nativeLinker ()
38
+ .canonicalLayouts ().get ("size_t" );
39
+
37
40
private OpenSlideFFM () {
38
41
}
39
42
@@ -102,7 +105,7 @@ static String openslide_detect_vendor(String filename) {
102
105
ret = (MemorySegment ) detect_vendor .invokeExact (
103
106
arena .allocateFrom (filename ));
104
107
} catch (Throwable ex ) {
105
- throw new AssertionError ("Invalid call" , ex );
108
+ throw new AssertionError ("Invalid call" , ex );
106
109
}
107
110
if (ret .equals (MemorySegment .NULL )) {
108
111
return null ;
@@ -122,7 +125,7 @@ static MemorySegment openslide_open(String filename) {
122
125
ret = (MemorySegment ) open .invokeExact (
123
126
arena .allocateFrom (filename ));
124
127
} catch (Throwable ex ) {
125
- throw new AssertionError ("Invalid call" , ex );
128
+ throw new AssertionError ("Invalid call" , ex );
126
129
}
127
130
if (ret .equals (MemorySegment .NULL )) {
128
131
return null ;
@@ -137,7 +140,7 @@ static int openslide_get_level_count(MemorySegment osr) {
137
140
try {
138
141
return (int ) get_level_count .invokeExact (osr );
139
142
} catch (Throwable ex ) {
140
- throw new AssertionError ("Invalid call" , ex );
143
+ throw new AssertionError ("Invalid call" , ex );
141
144
}
142
145
}
143
146
@@ -153,7 +156,7 @@ static void openslide_get_level_dimensions(MemorySegment osr, int level,
153
156
try {
154
157
get_level_dimensions .invokeExact (osr , level , w , h );
155
158
} catch (Throwable ex ) {
156
- throw new AssertionError ("Invalid call" , ex );
159
+ throw new AssertionError ("Invalid call" , ex );
157
160
}
158
161
dim [0 ] = w .get (JAVA_LONG , 0 );
159
162
dim [1 ] = h .get (JAVA_LONG , 0 );
@@ -167,7 +170,7 @@ static double openslide_get_level_downsample(MemorySegment osr, int level) {
167
170
try {
168
171
return (double ) get_level_downsample .invokeExact (osr , level );
169
172
} catch (Throwable ex ) {
170
- throw new AssertionError ("Invalid call" , ex );
173
+ throw new AssertionError ("Invalid call" , ex );
171
174
}
172
175
}
173
176
@@ -182,7 +185,7 @@ static void openslide_read_region(MemorySegment osr, int dest[],
182
185
try {
183
186
read_region .invokeExact (osr , buf , x , y , level , w , h );
184
187
} catch (Throwable ex ) {
185
- throw new AssertionError ("Invalid call" , ex );
188
+ throw new AssertionError ("Invalid call" , ex );
186
189
}
187
190
MemorySegment .copy (buf , JAVA_INT , 0 , dest , 0 , dest .length );
188
191
}
@@ -195,7 +198,7 @@ static void openslide_close(MemorySegment osr) {
195
198
try {
196
199
close .invokeExact (osr );
197
200
} catch (Throwable ex ) {
198
- throw new AssertionError ("Invalid call" , ex );
201
+ throw new AssertionError ("Invalid call" , ex );
199
202
}
200
203
}
201
204
@@ -207,7 +210,7 @@ static String openslide_get_error(MemorySegment osr) {
207
210
try {
208
211
ret = (MemorySegment ) get_error .invokeExact (osr );
209
212
} catch (Throwable ex ) {
210
- throw new AssertionError ("Invalid call" , ex );
213
+ throw new AssertionError ("Invalid call" , ex );
211
214
}
212
215
if (ret .equals (MemorySegment .NULL )) {
213
216
return null ;
@@ -223,7 +226,7 @@ static String[] openslide_get_property_names(MemorySegment osr) {
223
226
try {
224
227
ret = (MemorySegment ) get_property_names .invokeExact (osr );
225
228
} catch (Throwable ex ) {
226
- throw new AssertionError ("Invalid call" , ex );
229
+ throw new AssertionError ("Invalid call" , ex );
227
230
}
228
231
return segment_to_string_array (ret );
229
232
}
@@ -240,7 +243,7 @@ static String openslide_get_property_value(MemorySegment osr, String name) {
240
243
ret = (MemorySegment ) get_property_value .invokeExact (osr ,
241
244
arena .allocateFrom (name ));
242
245
} catch (Throwable ex ) {
243
- throw new AssertionError ("Invalid call" , ex );
246
+ throw new AssertionError ("Invalid call" , ex );
244
247
}
245
248
if (ret .equals (MemorySegment .NULL )) {
246
249
return null ;
@@ -256,7 +259,7 @@ static String[] openslide_get_associated_image_names(MemorySegment osr) {
256
259
try {
257
260
ret = (MemorySegment ) get_associated_image_names .invokeExact (osr );
258
261
} catch (Throwable ex ) {
259
- throw new AssertionError ("Invalid call" , ex );
262
+ throw new AssertionError ("Invalid call" , ex );
260
263
}
261
264
return segment_to_string_array (ret );
262
265
}
@@ -277,7 +280,7 @@ static void openslide_get_associated_image_dimensions(MemorySegment osr,
277
280
get_associated_image_dimensions .invokeExact (osr ,
278
281
arena .allocateFrom (name ), w , h );
279
282
} catch (Throwable ex ) {
280
- throw new AssertionError ("Invalid call" , ex );
283
+ throw new AssertionError ("Invalid call" , ex );
281
284
}
282
285
dim [0 ] = w .get (JAVA_LONG , 0 );
283
286
dim [1 ] = h .get (JAVA_LONG , 0 );
@@ -299,12 +302,45 @@ static void openslide_read_associated_image(MemorySegment osr, String name,
299
302
read_associated_image .invokeExact (osr , arena .allocateFrom (name ),
300
303
buf );
301
304
} catch (Throwable ex ) {
302
- throw new AssertionError ("Invalid call" , ex );
305
+ throw new AssertionError ("Invalid call" , ex );
303
306
}
304
307
MemorySegment .copy (buf , JAVA_INT , 0 , dest , 0 , dest .length );
305
308
}
306
309
}
307
310
311
+ private static final MethodHandle cache_create = function (
312
+ C_POINTER , "openslide_cache_create" , SIZE_T );
313
+
314
+ static MemorySegment openslide_cache_create (long capacity ) {
315
+ try {
316
+ return (MemorySegment ) cache_create .invokeExact (capacity );
317
+ } catch (Throwable ex ) {
318
+ throw new AssertionError ("Invalid call" , ex );
319
+ }
320
+ }
321
+
322
+ private static final MethodHandle set_cache = function (
323
+ null , "openslide_set_cache" , C_POINTER , C_POINTER );
324
+
325
+ static void openslide_set_cache (MemorySegment osr , MemorySegment cache ) {
326
+ try {
327
+ set_cache .invokeExact (osr , cache );
328
+ } catch (Throwable ex ) {
329
+ throw new AssertionError ("Invalid call" , ex );
330
+ }
331
+ }
332
+
333
+ private static final MethodHandle cache_release = function (
334
+ null , "openslide_cache_release" , C_POINTER );
335
+
336
+ static void openslide_cache_release (MemorySegment cache ) {
337
+ try {
338
+ cache_release .invokeExact (cache );
339
+ } catch (Throwable ex ) {
340
+ throw new AssertionError ("Invalid call" , ex );
341
+ }
342
+ }
343
+
308
344
private static final MethodHandle get_version = function (
309
345
C_POINTER , "openslide_get_version" );
310
346
@@ -313,7 +349,7 @@ static String openslide_get_version() {
313
349
try {
314
350
ret = (MemorySegment ) get_version .invokeExact ();
315
351
} catch (Throwable ex ) {
316
- throw new AssertionError ("Invalid call" , ex );
352
+ throw new AssertionError ("Invalid call" , ex );
317
353
}
318
354
return ret .getString (0 );
319
355
}
0 commit comments