1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  *  For details of the HDF libraries, see the HDF Documentation at:
16  *    http://hdfgroup.org/HDF5/doc/
17  *
18  */
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
24 #include <jni.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "hdf5.h"
28 #include "h5util.h"
29 #include "h5jni.h"
30 #include "h5aImp.h"
31 
32 /*
33  * Pointer to the JNI's Virtual Machine; used for callback functions.
34  */
35 extern JavaVM *jvm;
36 
37 typedef struct _cb_wrapper {
38     jobject visit_callback;
39     jobject op_data;
40 } cb_wrapper;
41 
42 /********************/
43 /* Local Prototypes */
44 /********************/
45 
46 static herr_t H5AwriteVL_asstr(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf);
47 static herr_t H5AwriteVL_str(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf);
48 static herr_t H5AreadVL_asstr(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf);
49 static herr_t H5AreadVL_str(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf);
50 
51 static herr_t H5A_iterate_cb(hid_t g_id, const char *name, const H5A_info_t *info, void *cb_data);
52 
53 /********************/
54 /* Local Macros     */
55 /********************/
56 
57 
58 /*
59  * Class:     hdf_hdf5lib_H5
60  * Method:    H5Acreate
61  * Signature: (JLjava/lang/String;JJJ)J
62  */
63 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Acreate(JNIEnv * env,jclass clss,jlong loc_id,jstring name,jlong type_id,jlong space_id,jlong create_plist)64 Java_hdf_hdf5lib_H5__1H5Acreate
65     (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong type_id,
66           jlong space_id, jlong create_plist)
67 {
68     const char *attrName = NULL;
69     hid_t       attr_id = H5I_INVALID_HID;
70 
71     UNUSED(clss);
72 
73     if (NULL == name)
74         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Acreate: attribute name is NULL");
75 
76     PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Acreate: attribute name not pinned");
77 
78     if ((attr_id = H5Acreate2((hid_t)loc_id, attrName, (hid_t)type_id, (hid_t)space_id, (hid_t)create_plist, (hid_t)H5P_DEFAULT)) < 0)
79         H5_LIBRARY_ERROR(ENVONLY);
80 
81 done:
82     if (attrName)
83         UNPIN_JAVA_STRING(ENVONLY, name, attrName);
84 
85     return (jlong)attr_id;
86 } /* end Java_hdf_hdf5lib_H5__1H5Acreate */
87 
88 /*
89  * Class:     hdf_hdf5lib_H5
90  * Method:    H5Aopen_name
91  * Signature: (JLjava/lang/String;)J
92  */
93 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aopen_1name(JNIEnv * env,jclass clss,jlong loc_id,jstring name)94 Java_hdf_hdf5lib_H5__1H5Aopen_1name
95     (JNIEnv *env, jclass clss, jlong loc_id, jstring name)
96 {
97     const char *attrName = NULL;
98     hid_t       attr_id = H5I_INVALID_HID;
99 
100     UNUSED(clss);
101 
102     if (NULL == name)
103         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aopen_name: attribute name is null");
104 
105     PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Aopen_name: attribute name not pinned");
106 
107     if((attr_id = H5Aopen_name((hid_t)loc_id, attrName)) < 0)
108         H5_LIBRARY_ERROR(ENVONLY);
109 
110 done:
111     if (attrName)
112         UNPIN_JAVA_STRING(ENVONLY, name, attrName);
113 
114     return (jlong)attr_id;
115 } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1name */
116 
117 /*
118  * Class:     hdf_hdf5lib_H5
119  * Method:    H5Aopen_idx
120  * Signature: (JI)J
121  */
122 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aopen_1idx(JNIEnv * env,jclass clss,jlong loc_id,jint idx)123 Java_hdf_hdf5lib_H5__1H5Aopen_1idx
124     (JNIEnv *env, jclass clss, jlong loc_id, jint idx)
125 {
126     hid_t attr_id = H5I_INVALID_HID;
127 
128     UNUSED(clss);
129 
130     if ((attr_id = H5Aopen_idx((hid_t) loc_id, (unsigned int) idx)) < 0)
131         H5_LIBRARY_ERROR(ENVONLY);
132 
133 done:
134     return (jlong)attr_id;
135 } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1idx */
136 
137 /*
138  * Class:     hdf_hdf5lib_H5
139  * Method:    H5Aread
140  * Signature: (JJ[BZ)I
141  */
142 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jbyteArray buf,jboolean isCriticalPinning)143 Java_hdf_hdf5lib_H5_H5Aread
144     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jbyteArray buf, jboolean isCriticalPinning)
145 {
146     jboolean  readBufIsCopy;
147     jbyte    *readBuf = NULL;
148     htri_t    data_class;
149     herr_t    status = FAIL;
150 
151     UNUSED(clss);
152 
153     if (NULL == buf)
154         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread: read buffer is NULL");
155 
156     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
157         H5_LIBRARY_ERROR(ENVONLY);
158 
159     if (data_class)
160         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: variable length type not supported");
161 
162     /* Recursively detect any vlen string in type (compound, array ...) */
163     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
164         H5_LIBRARY_ERROR(ENVONLY);
165 
166     if (data_class)
167         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: variable length type not supported");
168 
169     if (isCriticalPinning) {
170         PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread: read buffer not critically pinned");
171     }
172     else {
173         PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread: read buffer not pinned");
174     }
175 
176     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0)
177         H5_LIBRARY_ERROR(ENVONLY);
178 
179 done:
180     if (readBuf) {
181         if (isCriticalPinning) {
182             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
183         }
184         else {
185             UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
186         }
187     }
188 
189     return (jint)status;
190 } /* end Java_hdf_hdf5lib_H5_H5Aread */
191 
192 /*
193  * Class:     hdf_hdf5lib_H5
194  * Method:    H5Awrite
195  * Signature: (JJ[BZ)I
196  */
197 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jbyteArray buf,jboolean isCriticalPinning)198 Java_hdf_hdf5lib_H5_H5Awrite
199     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jbyteArray buf, jboolean isCriticalPinning)
200 {
201     jboolean  writeBufIsCopy;
202     jbyte    *writeBuf = NULL;
203     htri_t    data_class;
204     herr_t    status = FAIL;
205 
206     UNUSED(clss);
207 
208     if (NULL == buf)
209         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer is NULL");
210 
211     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
212         H5_LIBRARY_ERROR(ENVONLY);
213 
214     if (data_class)
215         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: variable length type not supported");
216 
217     /* Recursively detect any vlen string in type (compound, array ...) */
218     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
219         H5_LIBRARY_ERROR(ENVONLY);
220 
221     if (data_class)
222         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: variable length type not supported");
223 
224     if (isCriticalPinning) {
225         PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite: write buffer not critically pinned");
226     }
227     else {
228         PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite: write buffer not pinned");
229     }
230 
231     if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
232         H5_LIBRARY_ERROR(ENVONLY);
233 
234 done:
235     if (writeBuf) {
236         if (isCriticalPinning) {
237             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
238         }
239         else {
240             UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
241         }
242     }
243 
244     return (jint)status;
245 } /* end Java_hdf_hdf5lib_H5_H5Awrite */
246 
247 /*
248  * Class:     hdf_hdf5lib_H5
249  * Method:    H5Aread_short
250  * Signature: (JJ[SZ)I
251  */
252 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread_1short(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jshortArray buf,jboolean isCriticalPinning)253 Java_hdf_hdf5lib_H5_H5Aread_1short
254     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jshortArray buf, jboolean isCriticalPinning)
255 {
256     jboolean  readBufIsCopy;
257     jshort   *readBuf = NULL;
258     htri_t    data_class;
259     herr_t    status = FAIL;
260 
261     UNUSED(clss);
262 
263     if (NULL == buf)
264         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: read buffer is NULL");
265 
266     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
267         H5_LIBRARY_ERROR(ENVONLY);
268 
269     if (data_class)
270         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: variable length type not supported");
271 
272     /* Recursively detect any vlen string in type (compound, array ...) */
273     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
274         H5_LIBRARY_ERROR(ENVONLY);
275 
276     if (data_class)
277         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: variable length type not supported");
278 
279     if (isCriticalPinning) {
280         PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_short: read buffer not critically pinned");
281     }
282     else {
283         PIN_SHORT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_short: read buffer not pinned");
284     }
285 
286     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0)
287         H5_LIBRARY_ERROR(ENVONLY);
288 
289 done:
290     if (readBuf) {
291         if (isCriticalPinning) {
292             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
293         }
294         else {
295             UNPIN_SHORT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
296         }
297     }
298 
299     return (jint)status;
300 } /* end Java_hdf_hdf5lib_H5_H5Aread_1short */
301 
302 /*
303  * Class:     hdf_hdf5lib_H5
304  * Method:    H5Awrite_short
305  * Signature: (JJ[SZ)I
306  */
307 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite_1short(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jshortArray buf,jboolean isCriticalPinning)308 Java_hdf_hdf5lib_H5_H5Awrite_1short
309     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jshortArray buf, jboolean isCriticalPinning)
310 {
311     jboolean  writeBufIsCopy;
312     jshort   *writeBuf = NULL;
313     htri_t    data_class;
314     herr_t    status = FAIL;
315 
316     UNUSED(clss);
317 
318     if (NULL == buf)
319         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: write buffer is NULL");
320 
321     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
322         H5_LIBRARY_ERROR(ENVONLY);
323 
324     if (data_class)
325         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: variable length type not supported");
326 
327     /* Recursively detect any vlen string in type (compound, array ...) */
328     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
329         H5_LIBRARY_ERROR(ENVONLY);
330 
331     if (data_class)
332         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: variable length type not supported");
333 
334     if (isCriticalPinning) {
335         PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_short: write buffer not critically pinned");
336     }
337     else {
338         PIN_SHORT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_short: write buffer not pinned");
339     }
340 
341     if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
342         H5_LIBRARY_ERROR(ENVONLY);
343 
344 done:
345     if (writeBuf) {
346         if (isCriticalPinning) {
347             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
348         }
349         else {
350             UNPIN_SHORT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
351         }
352     }
353 
354     return (jint)status;
355 } /* end Java_hdf_hdf5lib_H5_H5Awrite_1short */
356 
357 /*
358  * Class:     hdf_hdf5lib_H5
359  * Method:    H5Aread_int
360  * Signature: (JJ[IZ)I
361  */
362 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread_1int(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jintArray buf,jboolean isCriticalPinning)363 Java_hdf_hdf5lib_H5_H5Aread_1int
364     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jintArray buf, jboolean isCriticalPinning)
365 {
366     jboolean  readBufIsCopy;
367     htri_t    data_class;
368     jint     *readBuf = NULL;
369     herr_t    status = FAIL;
370 
371     UNUSED(clss);
372 
373     if (buf == NULL)
374         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: read buffer is NULL");
375 
376     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
377         H5_LIBRARY_ERROR(ENVONLY);
378 
379     if (data_class)
380         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: variable length type not supported");
381 
382     /* Recursively detect any vlen string in type (compound, array ...) */
383     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
384         H5_LIBRARY_ERROR(ENVONLY);
385 
386     if (data_class)
387         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: variable length type not supported");
388 
389     if (isCriticalPinning) {
390         PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_int: read buffer not critically pinned");
391     }
392     else {
393         PIN_INT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_int: read buffer not pinned");
394     }
395 
396     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0)
397         H5_LIBRARY_ERROR(ENVONLY);
398 
399 done:
400     if (readBuf) {
401         if (isCriticalPinning) {
402             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
403         }
404         else {
405             UNPIN_INT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
406         }
407     }
408 
409     return (jint)status;
410 } /* end Java_hdf_hdf5lib_H5_H5Aread_1int */
411 
412 /*
413  * Class:     hdf_hdf5lib_H5
414  * Method:    H5Awrite_int
415  * Signature: (JJ[IZ)I
416  */
417 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite_1int(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jintArray buf,jboolean isCriticalPinning)418 Java_hdf_hdf5lib_H5_H5Awrite_1int
419     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jintArray buf, jboolean isCriticalPinning)
420 {
421     jboolean  writeBufIsCopy;
422     jint     *writeBuf = NULL;
423     htri_t    data_class;
424     herr_t    status = FAIL;
425 
426     UNUSED(clss);
427 
428     if (buf == NULL)
429         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: write buffer is NULL");
430 
431     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
432         H5_LIBRARY_ERROR(ENVONLY);
433 
434     if (data_class)
435         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: variable length type not supported");
436 
437     /* Recursively detect any vlen string in type (compound, array ...) */
438     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
439         H5_LIBRARY_ERROR(ENVONLY);
440 
441     if (data_class)
442         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: variable length type not supported");
443 
444     if (isCriticalPinning) {
445         PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_int: write buffer not critically pinned");
446     }
447     else {
448         PIN_INT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_int: write buffer not pinned");
449     }
450 
451     if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
452         H5_LIBRARY_ERROR(ENVONLY);
453 
454 done:
455     if (writeBuf) {
456         if (isCriticalPinning) {
457             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
458         }
459         else {
460             UNPIN_INT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
461         }
462     }
463 
464     return (jint)status;
465 } /* end Java_hdf_hdf5lib_H5_H5Awrite_1int */
466 
467 /*
468  * Class:     hdf_hdf5lib_H5
469  * Method:    H5Aread_long
470  * Signature: (JJ[JZ)I
471  */
472 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread_1long(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jlongArray buf,jboolean isCriticalPinning)473 Java_hdf_hdf5lib_H5_H5Aread_1long
474     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jlongArray buf, jboolean isCriticalPinning)
475 {
476     jboolean  readBufIsCopy;
477     jlong    *readBuf = NULL;
478     htri_t    data_class;
479     herr_t    status = FAIL;
480 
481     UNUSED(clss);
482 
483     if (NULL == buf)
484         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: read buffer is NULL");
485 
486     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
487         H5_LIBRARY_ERROR(ENVONLY);
488 
489     if (data_class)
490         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: variable length type not supported");
491 
492     /* Recursively detect any vlen string in type (compound, array ...) */
493     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
494         H5_LIBRARY_ERROR(ENVONLY);
495 
496     if (data_class)
497         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: variable length type not supported");
498 
499     if (isCriticalPinning) {
500         PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_long: read buffer not critically pinned");
501     }
502     else {
503         PIN_LONG_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_long: read buffer not pinned");
504     }
505 
506     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0)
507         H5_LIBRARY_ERROR(ENVONLY);
508 
509 done:
510     if (readBuf) {
511         if (isCriticalPinning) {
512             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
513         }
514         else {
515             UNPIN_LONG_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
516         }
517     }
518 
519     return (jint)status;
520 } /* end Java_hdf_hdf5lib_H5_H5Aread_1long */
521 
522 /*
523  * Class:     hdf_hdf5lib_H5
524  * Method:    H5Awrite_long
525  * Signature: (JJ[JZ)I
526  */
527 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite_1long(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jlongArray buf,jboolean isCriticalPinning)528 Java_hdf_hdf5lib_H5_H5Awrite_1long
529     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jlongArray buf, jboolean isCriticalPinning)
530 {
531     jboolean  writeBufIsCopy;
532     jlong    *writeBuf = NULL;
533     htri_t    data_class;
534     herr_t    status = FAIL;
535 
536     UNUSED(clss);
537 
538     if (NULL == buf)
539         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: write buffer is NULL");
540 
541     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
542         H5_LIBRARY_ERROR(ENVONLY);
543 
544     if (data_class)
545         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: variable length type not supported");
546 
547     /* Recursively detect any vlen string in type (compound, array ...) */
548     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
549         H5_LIBRARY_ERROR(ENVONLY);
550 
551     if (data_class)
552         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: variable length type not supported");
553 
554     if (isCriticalPinning) {
555         PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_long: write buffer not critically pinned");
556     }
557     else {
558         PIN_LONG_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_long: write buffer not pinned");
559     }
560 
561     if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
562         H5_LIBRARY_ERROR(ENVONLY);
563 
564 done:
565     if (writeBuf) {
566         if (isCriticalPinning) {
567             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
568         }
569         else {
570             UNPIN_LONG_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
571         }
572     }
573 
574     return (jint)status;
575 } /* end Java_hdf_hdf5lib_H5_H5Awrite_1long */
576 
577 /*
578  * Class:     hdf_hdf5lib_H5
579  * Method:    H5Aread_float
580  * Signature: (JJ[FZ)I
581  */
582 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread_1float(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jfloatArray buf,jboolean isCriticalPinning)583 Java_hdf_hdf5lib_H5_H5Aread_1float
584     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jfloatArray buf, jboolean isCriticalPinning)
585 {
586     jboolean  readBufIsCopy;
587     jfloat   *readBuf = NULL;
588     htri_t    data_class;
589     herr_t    status = FAIL;
590 
591     UNUSED(clss);
592 
593     if (NULL == buf)
594         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: read buffer is NULL");
595 
596     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
597         H5_LIBRARY_ERROR(ENVONLY);
598 
599     if (data_class)
600         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: variable length type not supported");
601 
602     /* Recursively detect any vlen string in type (compound, array ...) */
603     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
604         H5_LIBRARY_ERROR(ENVONLY);
605 
606     if (data_class)
607         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: variable length type not supported");
608 
609     if (isCriticalPinning) {
610         PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_float: read buffer not critically pinned");
611     }
612     else {
613         PIN_FLOAT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_float: read buffer not pinned");
614     }
615 
616     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0)
617         H5_LIBRARY_ERROR(ENVONLY);
618 
619 done:
620     if (readBuf) {
621         if (isCriticalPinning) {
622             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
623         }
624         else {
625             UNPIN_FLOAT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
626         }
627     }
628 
629     return (jint)status;
630 } /* end Java_hdf_hdf5lib_H5_H5Aread_1float */
631 
632 /*
633  * Class:     hdf_hdf5lib_H5
634  * Method:    H5Awrite_float
635  * Signature: (JJ[FZ)I
636  */
637 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite_1float(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jfloatArray buf,jboolean isCriticalPinning)638 Java_hdf_hdf5lib_H5_H5Awrite_1float
639     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jfloatArray buf, jboolean isCriticalPinning)
640 {
641     jboolean  writeBufIsCopy;
642     jfloat   *writeBuf = NULL;
643     htri_t    data_class;
644     herr_t    status = FAIL;
645 
646     UNUSED(clss);
647 
648     if (NULL == buf)
649         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: write buffer is NULL");
650 
651     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
652         H5_LIBRARY_ERROR(ENVONLY);
653 
654     if (data_class)
655         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: variable length type not supported");
656 
657     /* Recursively detect any vlen string in type (compound, array ...) */
658     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
659         H5_LIBRARY_ERROR(ENVONLY);
660 
661     if (data_class)
662         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: variable length type not supported");
663 
664     if (isCriticalPinning) {
665         PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_float: write buffer not critically pinned");
666     }
667     else {
668         PIN_FLOAT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_float: write buffer not pinned");
669     }
670 
671     if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
672         H5_LIBRARY_ERROR(ENVONLY);
673 
674 done:
675     if (writeBuf) {
676         if (isCriticalPinning) {
677             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
678         }
679         else {
680             UNPIN_FLOAT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
681         }
682     }
683 
684     return (jint)status;
685 } /* end Java_hdf_hdf5lib_H5_H5Awrite_1float */
686 
687 /*
688  * Class:     hdf_hdf5lib_H5
689  * Method:    H5Aread_double
690  * Signature: (JJ[DZ)I
691  */
692 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread_1double(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jdoubleArray buf,jboolean isCriticalPinning)693 Java_hdf_hdf5lib_H5_H5Aread_1double
694     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jdoubleArray buf, jboolean isCriticalPinning)
695 {
696     jboolean  readBufIsCopy;
697     jdouble  *readBuf = NULL;
698     htri_t    data_class;
699     herr_t    status = FAIL;
700 
701     UNUSED(clss);
702 
703     if (NULL == buf)
704         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: read buffer is NULL");
705 
706     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
707         H5_LIBRARY_ERROR(ENVONLY);
708 
709     if (data_class)
710         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: variable length type not supported");
711 
712     /* Recursively detect any vlen string in type (compound, array ...) */
713     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
714         H5_LIBRARY_ERROR(ENVONLY);
715 
716     if (data_class)
717         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: variable length type not supported");
718 
719     if (isCriticalPinning) {
720         PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_double: read buffer not critically pinned");
721     }
722     else {
723         PIN_DOUBLE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_double: read buffer not pinned");
724     }
725 
726     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0)
727         H5_LIBRARY_ERROR(ENVONLY);
728 
729 done:
730     if (readBuf) {
731         if (isCriticalPinning) {
732             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
733         }
734         else {
735             UNPIN_DOUBLE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
736         }
737     }
738 
739     return (jint)status;
740 } /* end Java_hdf_hdf5lib_H5_H5Aread_1double */
741 
742 /*
743  * Class:     hdf_hdf5lib_H5
744  * Method:    H5Awrite_double
745  * Signature: (JJ[DZ)I
746  */
747 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite_1double(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jdoubleArray buf,jboolean isCriticalPinning)748 Java_hdf_hdf5lib_H5_H5Awrite_1double
749     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jdoubleArray buf, jboolean isCriticalPinning)
750 {
751     jboolean  writeBufIsCopy;
752     jdouble  *writeBuf = NULL;
753     htri_t    data_class;
754     herr_t    status = FAIL;
755 
756     UNUSED(clss);
757 
758     if (NULL == buf)
759         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: write buffer is NULL");
760 
761     if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
762         H5_LIBRARY_ERROR(ENVONLY);
763 
764     if (data_class)
765         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: variable length type not supported");
766 
767     /* Recursively detect any vlen string in type (compound, array ...) */
768     if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
769         H5_LIBRARY_ERROR(ENVONLY);
770 
771     if (data_class)
772         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: variable length type not supported");
773 
774     if (isCriticalPinning) {
775         PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_double: write buffer not critically pinned");
776     }
777     else {
778         PIN_DOUBLE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_double: write buffer not pinned");
779     }
780 
781     if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0)
782         H5_LIBRARY_ERROR(ENVONLY);
783 
784 done:
785     if (writeBuf) {
786         if (isCriticalPinning) {
787             UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
788         }
789         else {
790             UNPIN_DOUBLE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
791         }
792     }
793 
794     return (jint)status;
795 } /* end Java_hdf_hdf5lib_H5_H5Awrite_1double */
796 
797 /*
798  * Class:     hdf_hdf5lib_H5
799  * Method:    H5Aread_string
800  * Signature: (JJ[Ljava/lang/String;)I
801  */
802 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread_1string(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jobjectArray j_buf)803 Java_hdf_hdf5lib_H5_H5Aread_1string
804     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray j_buf)
805 {
806     jstring  jstr;
807     size_t   str_len;
808     size_t   pos;
809     jsize    i, n;
810     char    *c_buf = NULL;
811     char    *cstr = NULL;
812     herr_t   status = FAIL;
813 
814     UNUSED(clss);
815 
816     if (NULL == j_buf)
817         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_string: read buffer is NULL");
818 
819     if ((n = ENVPTR->GetArrayLength(ENVONLY, j_buf)) <= 0) {
820         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
821         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_string: read buffer length <= 0");
822     }
823 
824     if (!(str_len = H5Tget_size((hid_t)mem_type_id)))
825         H5_LIBRARY_ERROR(ENVONLY);
826 
827     if (NULL == (cstr = (char *) HDmalloc(str_len + 1)))
828         H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_string: memory allocation failed");
829 
830     if (NULL == (c_buf = (char *) HDmalloc((size_t)n * str_len)))
831         H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_string: memory allocation failed");
832 
833     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, c_buf)) < 0)
834         H5_LIBRARY_ERROR(ENVONLY);
835 
836     for (i = 0, pos = 0; i < n; i++) {
837         HDmemcpy(cstr, c_buf+pos, str_len);
838         cstr[str_len] = '\0';
839 
840         if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, cstr))) {
841             CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
842             H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_string: out of memory - unable to construct string from UTF characters");
843         }
844 
845         ENVPTR->SetObjectArrayElement(ENVONLY, j_buf, i, jstr);
846         CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
847 
848         pos += str_len;
849 
850         ENVPTR->DeleteLocalRef(ENVONLY, jstr);
851     } /* end for */
852 
853 done:
854     if (c_buf)
855         HDfree(c_buf);
856     if (cstr)
857         HDfree(cstr);
858 
859     return (jint)status;
860 } /* end Java_hdf_hdf5lib_H5_H5Aread_1string */
861 
862 /*
863  * Class:     hdf_hdf5lib_H5
864  * Method:    H5Awrite_string
865  * Signature: (JJ[Ljava/lang/String;)I
866  */
867 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Awrite_1string(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jobjectArray j_buf)868 Java_hdf_hdf5lib_H5_H5Awrite_1string
869     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray j_buf)
870 {
871     const char *utf8 = NULL;
872     jstring     obj;
873     size_t      i, str_len;
874     jsize       n;
875     char       *c_buf = NULL;
876     herr_t      status = FAIL;
877 
878     UNUSED(clss);
879 
880     if (NULL == j_buf)
881         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_string: write buffer is NULL");
882 
883     if ((n = ENVPTR->GetArrayLength(ENVONLY, j_buf)) <= 0) {
884         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
885         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_string: write buffer length <= 0");
886     }
887 
888     if (!(str_len = H5Tget_size((hid_t)mem_type_id)))
889         H5_LIBRARY_ERROR(ENVONLY);
890 
891     if (NULL == (c_buf = (char *) HDmalloc((size_t)n * str_len)))
892         H5_JNI_FATAL_ERROR(ENVONLY, "H5Awrite_string: memory allocation failed");
893 
894     for (i = 0; i < (size_t) n; i++) {
895         if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)j_buf, (jsize) i))) {
896             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
897 
898             /*
899              * If the string object was NULL, skip it.
900              */
901             HDmemset(&c_buf[i * str_len], 0, str_len);
902             continue;
903         }
904 
905         /*
906          * length = ENVPTR->GetStringUTFLength(ENVONLY, obj);
907          * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
908          */
909 
910         PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5Awrite_string: string not pinned");
911 
912         HDstrncpy(&c_buf[i * str_len], utf8, str_len);
913 
914         UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
915         utf8 = NULL;
916 
917         ENVPTR->DeleteLocalRef(ENVONLY, obj);
918     } /* end for */
919 
920     if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, c_buf)) < 0)
921         H5_LIBRARY_ERROR(ENVONLY);
922 
923 done:
924     if (utf8)
925         UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
926     if (c_buf)
927         HDfree(c_buf);
928 
929     return (jint)status;
930 } /* end Java_hdf_hdf5lib_H5_H5Awrite_1string */
931 
932 /*
933  * Class:     hdf_hdf5lib_H5
934  * Method:    H5AreadVL
935  * Signature: (JJ[Ljava/lang/String;)I
936  */
937 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jobjectArray buf)938 Java_hdf_hdf5lib_H5_H5AreadVL
939     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf)
940 {
941     H5T_class_t type_class;
942     htri_t      isStr = 0;
943     htri_t      isVlenStr = 0;
944     htri_t      isComplex = 0;
945     htri_t      isComplex2 = 0;
946     hid_t       nested_tid = H5I_INVALID_HID;
947     herr_t      status = FAIL;
948 
949     UNUSED(clss);
950 
951     if (NULL == buf)
952         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: read buffer is NULL");
953 
954     if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0)
955         H5_LIBRARY_ERROR(ENVONLY);
956 
957     if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
958         H5_LIBRARY_ERROR(ENVONLY);
959 
960     if (type_class == H5T_COMPOUND) {
961         unsigned i;
962         int      num_members;
963 
964         if ((num_members = H5Tget_nmembers(mem_type_id)) < 0)
965             H5_LIBRARY_ERROR(ENVONLY);
966 
967         for (i = 0; i < (unsigned) num_members; i++) {
968             if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0)
969                 H5_LIBRARY_ERROR(ENVONLY);
970 
971             if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
972                 H5_LIBRARY_ERROR(ENVONLY);
973 
974             if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
975                 H5_LIBRARY_ERROR(ENVONLY);
976 
977             isComplex = isComplex || isComplex2;
978 
979             if (H5Tclose(nested_tid) < 0)
980                 H5_LIBRARY_ERROR(ENVONLY);
981             nested_tid = H5I_INVALID_HID;
982         }
983     }
984     else if (type_class == H5T_VLEN) {
985         isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */
986     }
987 
988     if (!isStr || isComplex || isVlenStr) {
989         if ((status = H5AreadVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0)
990             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
991     }
992     else if (isStr) {
993         if ((status = H5AreadVL_str(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0)
994             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
995     }
996 
997 done:
998     if (nested_tid >= 0)
999         H5Tclose(nested_tid);
1000 
1001     return (jint)status;
1002 } /* end Java_hdf_hdf5lib_H5_H5Aread_1VL */
1003 
1004 /*
1005  * Helper method to read in a buffer of variable-length strings from an HDF5
1006  * attribute. Each C-string is converted to a Java string and set in the output
1007  * buffer in turn.
1008  */
1009 static herr_t
H5AreadVL_str(JNIEnv * env,hid_t aid,hid_t tid,jobjectArray buf)1010 H5AreadVL_str
1011     (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
1012 {
1013     jstring   jstr;
1014     jsize     i, n;
1015     char    **strs = NULL;
1016     herr_t    status = FAIL;
1017 
1018     if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
1019         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
1020         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL_str: buf length < 0");
1021     }
1022 
1023     if (NULL == (strs = (char **) HDcalloc((size_t)n, sizeof(char *))))
1024         H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL_str: failed to allocate variable length string read buffer");
1025 
1026     if ((status = H5Aread(aid, tid, strs)) < 0)
1027         H5_LIBRARY_ERROR(ENVONLY);
1028 
1029     /*
1030      * When repeatedly reading a dataset with a large number of strs (e.g., 1,000,000 strings),
1031      * H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect
1032      * free space in time. Instead, we use "H5free_memory(strs[i])" to free individual strings
1033      * once done.
1034      */
1035     for (i = 0; i < n; i++) {
1036         if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, strs[i])))
1037             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1038 
1039         ENVPTR->SetObjectArrayElement(ENVONLY, buf, i, jstr);
1040         CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1041 
1042         H5free_memory(strs[i]);
1043         strs[i] = NULL;
1044 
1045         ENVPTR->DeleteLocalRef(ENVONLY, jstr);
1046     } /* end for */
1047 
1048 done:
1049     if (strs) {
1050         for (i = 0; i < n; i++) {
1051             if (strs[i])
1052                 H5free_memory(strs[i]);
1053         }
1054 
1055         HDfree(strs);
1056     }
1057 
1058     return status;
1059 } /* end H5AreadVL_str */
1060 
1061 /*
1062  * Helper method to read in a buffer of variable-length (hvl_t)
1063  * structures from an HDF5 attribute and convert each variable-length
1064  * element's buffer into a Java string. Each string is then set
1065  * in the output buffer in turn.
1066  */
1067 static herr_t
H5AreadVL_asstr(JNIEnv * env,hid_t aid,hid_t tid,jobjectArray buf)1068 H5AreadVL_asstr
1069     (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
1070 {
1071     hsize_t      dims[H5S_MAX_RANK];
1072     jstring      jstr;
1073     h5str_t      h5str;
1074     size_t       typeSize;
1075     size_t       i;
1076     hid_t        sid = H5I_INVALID_HID;
1077     jsize        n;
1078     void        *readBuf = NULL;
1079     herr_t       status = FAIL;
1080 
1081     HDmemset(&h5str, 0, sizeof(h5str_t));
1082 
1083     /* Get size of string array */
1084     if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
1085         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
1086         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL_asstr: buf length < 0");
1087     }
1088 
1089     dims[0] = (hsize_t)n;
1090     if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
1091         H5_LIBRARY_ERROR(ENVONLY);
1092 
1093     if (!(typeSize = H5Tget_size(tid)))
1094         H5_LIBRARY_ERROR(ENVONLY);
1095 
1096     if (NULL == (readBuf = HDcalloc((size_t)n, typeSize)))
1097         H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL_asstr: failed to allocate read buffer");
1098 
1099     if ((status = H5Aread(aid, tid, readBuf)) < 0)
1100         H5_LIBRARY_ERROR(ENVONLY);
1101 
1102     /* Allocate a decent-sized initial string */
1103     h5str_new(&h5str, 4 * typeSize);
1104 
1105     if (!h5str.s)
1106         H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL_asstr: failed to allocate buffer");
1107 
1108     /* Convert each element to a char string */
1109     for (i = 0; i < (size_t) n; i++) {
1110         h5str.s[0] = '\0';
1111 
1112         if (!h5str_sprintf(ENVONLY, &h5str, aid, tid, &(((char *) readBuf)[i * typeSize]), typeSize, 0))
1113             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1114 
1115         if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s)))
1116             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1117 
1118         ENVPTR->SetObjectArrayElement(ENVONLY, buf, (jsize) i, jstr);
1119         CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1120 
1121         ENVPTR->DeleteLocalRef(ENVONLY, jstr);
1122     } /* end for */
1123 
1124 done:
1125     if (h5str.s)
1126         h5str_free(&h5str);
1127     if (readBuf) {
1128         H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, readBuf);
1129         HDfree(readBuf);
1130     }
1131     if (sid >= 0)
1132         H5Sclose(sid);
1133 
1134     return status;
1135 }
1136 
1137 /*
1138  * Class:     hdf_hdf5lib_H5
1139  * Method:    H5AwriteVL
1140  * Signature: (JJ[Ljava/lang/String;)I
1141  */
1142 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jobjectArray buf)1143 Java_hdf_hdf5lib_H5_H5AwriteVL
1144     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf)
1145 {
1146     H5T_class_t type_class;
1147     htri_t      isStr = 0;
1148     htri_t      isVlenStr = 0;
1149     htri_t      isComplex = 0;
1150     htri_t      isComplex2 = 0;
1151     hid_t       nested_tid = H5I_INVALID_HID;
1152     herr_t      status = FAIL;
1153 
1154     UNUSED(clss);
1155 
1156     if (NULL == buf)
1157         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: write buffer is NULL");
1158 
1159     if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0)
1160         H5_LIBRARY_ERROR(ENVONLY);
1161 
1162     if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
1163         H5_LIBRARY_ERROR(ENVONLY);
1164 
1165     if (type_class == H5T_COMPOUND) {
1166         unsigned i;
1167         int      num_members;
1168 
1169         if ((num_members = H5Tget_nmembers(mem_type_id)) < 0)
1170             H5_LIBRARY_ERROR(ENVONLY);
1171 
1172         for(i = 0; i < (unsigned) num_members; i++) {
1173             if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0)
1174                 H5_LIBRARY_ERROR(ENVONLY);
1175 
1176             if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
1177                 H5_LIBRARY_ERROR(ENVONLY);
1178 
1179             if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
1180                 H5_LIBRARY_ERROR(ENVONLY);
1181 
1182             isComplex = isComplex || isComplex2;
1183 
1184             if (H5Tclose(nested_tid) < 0)
1185                 H5_LIBRARY_ERROR(ENVONLY);
1186             nested_tid = H5I_INVALID_HID;
1187         }
1188     }
1189     else if (type_class == H5T_VLEN) {
1190         isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */
1191     }
1192 
1193     if (!isStr || isComplex || isVlenStr) {
1194         if ((status = H5AwriteVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0)
1195             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1196     }
1197     else if (isStr) {
1198         if ((status = H5AwriteVL_str(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0)
1199             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1200     }
1201 
1202 done:
1203     if (nested_tid >= 0)
1204         H5Tclose(nested_tid);
1205 
1206     return (jint)status;
1207 } /* end Java_hdf_hdf5lib_H5_H5Awrite_1VL */
1208 
1209 /*
1210  * Helper method to convert an array of Java strings into a buffer of C-strings.
1211  * The buffer of C-strings is then written to the HDF5 attribute specified.
1212  */
1213 static herr_t
H5AwriteVL_str(JNIEnv * env,hid_t aid,hid_t tid,jobjectArray buf)1214 H5AwriteVL_str
1215     (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
1216 {
1217     const char  *utf8 = NULL;
1218     jstring      obj;
1219     jsize        size;
1220     jint         i;
1221     char       **writeBuf = NULL;
1222     herr_t       status = FAIL;
1223 
1224     if ((size = ENVPTR->GetArrayLength(ENVONLY, (jarray) buf)) < 0) {
1225         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
1226         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL_str: buf length < 0");
1227     }
1228 
1229     if (NULL == (writeBuf = (char **) HDcalloc((size_t)size + 1, sizeof(char *))))
1230         H5_JNI_FATAL_ERROR(ENVONLY, "H5AwriteVL_str: failed to allocate variable length string write buffer")
1231 
1232     for (i = 0; i < size; ++i) {
1233         jsize length;
1234 
1235         if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray) buf, i))) {
1236             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1237 
1238             /*
1239              * If the string object was NULL, skip it.
1240              */
1241             writeBuf[i] = NULL;
1242             continue;
1243         }
1244 
1245         length = ENVPTR->GetStringUTFLength(ENVONLY, obj);
1246         CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1247 
1248         PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5AwriteVL_str: string not pinned");
1249 
1250         if (NULL == (writeBuf[i] = (char *) HDmalloc((size_t)length + 1)))
1251             H5_JNI_FATAL_ERROR(ENVONLY, "H5AwriteVL_str: failed to allocate string buffer");
1252 
1253         HDstrncpy(writeBuf[i], utf8, (size_t)length);
1254         writeBuf[i][length] = '\0';
1255 
1256         UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
1257         utf8 = NULL;
1258 
1259         ENVPTR->DeleteLocalRef(ENVONLY, obj);
1260     } /* end for (i = 0; i < size; ++i) */
1261 
1262     if ((status = H5Awrite((hid_t)aid, (hid_t)tid, writeBuf)) < 0)
1263         H5_LIBRARY_ERROR(ENVONLY);
1264 
1265 done:
1266     if (utf8)
1267         UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
1268     if (writeBuf) {
1269         for (i = 0; i < size; i++) {
1270             if (writeBuf[i])
1271                 HDfree(writeBuf[i]);
1272         }
1273 
1274         HDfree(writeBuf);
1275     }
1276 
1277     return (jint)status;
1278 }
1279 
1280 /*
1281  * Helper method to convert an array of Java strings into a buffer of
1282  * variable-length (hvl_t) elements. The buffer of variable-length
1283  * elements is then written to the HDF5 attribute.
1284  */
1285 static herr_t
H5AwriteVL_asstr(JNIEnv * env,hid_t aid,hid_t tid,jobjectArray buf)1286 H5AwriteVL_asstr
1287     (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
1288 {
1289     const char *utf8 = NULL;
1290     hsize_t     dims[H5S_MAX_RANK];
1291     jstring     jstr;
1292     size_t      typeSize;
1293     size_t      i;
1294     hid_t       sid = H5I_INVALID_HID;
1295     jsize       n;
1296     void       *writeBuf = NULL;
1297     herr_t      status = FAIL;
1298 
1299     if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
1300         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
1301         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL_asstr: buf length < 0");
1302     }
1303 
1304     dims[0] = (hsize_t)n;
1305     if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
1306         H5_LIBRARY_ERROR(ENVONLY);
1307 
1308     if (!(typeSize = H5Tget_size(tid)))
1309         H5_LIBRARY_ERROR(ENVONLY);
1310 
1311     if (NULL == (writeBuf = HDcalloc((size_t)n, typeSize)))
1312         H5_JNI_FATAL_ERROR(ENVONLY, "H5AwriteVL_asstr: failed to allocate write buffer");
1313 
1314     /*
1315      * When repeatedly writing a dataset with a large number of strs (e.g., 1,000,000 strings),
1316      * H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect
1317      * free space in time. Instead, we use "H5free_memory(strs[i])" to free individual strings
1318      * once done.
1319      */
1320     for (i = 0; i < (size_t) n; i++) {
1321         if (NULL == (jstr = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray) buf, (jsize) i))) {
1322             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1323 
1324             /*
1325              * If the string object was NULL, skip it.
1326              */
1327             HDmemset(&(((char *) writeBuf)[i * typeSize]), 0, typeSize);
1328             continue;
1329         }
1330 
1331         /*
1332          * length = ENVPTR->GetStringUTFLength(ENVONLY, jstr);
1333          * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1334          */
1335 
1336         PIN_JAVA_STRING(ENVONLY, jstr, utf8, NULL, "H5AwriteVL_asstr: failed to pin string buffer");
1337 
1338         /*
1339          * TODO: If the string isn't a copy, we should probably make
1340          * one before destroying it with h5str_convert.
1341          */
1342 
1343         if (!h5str_convert(ENVONLY, (char **) &utf8, aid, tid, &(((char *) writeBuf)[i * typeSize]), 0))
1344             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1345 
1346         UNPIN_JAVA_STRING(ENVONLY, jstr, utf8);
1347         utf8 = NULL;
1348 
1349         ENVPTR->DeleteLocalRef(ENVONLY, jstr);
1350     } /* end for (i = 0; i < n; i++) */
1351 
1352     if ((status = H5Awrite(aid, tid, writeBuf)) < 0)
1353         H5_LIBRARY_ERROR(ENVONLY);
1354 
1355 done:
1356     if (utf8)
1357         UNPIN_JAVA_STRING(ENVONLY, jstr, utf8);
1358     if (writeBuf) {
1359         H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, writeBuf);
1360         HDfree(writeBuf);
1361     }
1362     if (sid >= 0)
1363         H5Sclose(sid);
1364 
1365     return status;
1366 } /* end H5AwriteVL_str */
1367 
1368 /*
1369  * Class:     hdf_hdf5lib_H5
1370  * Method:    H5Aread_reg_ref
1371  * Signature: (JJ[Ljava/lang/String;)I
1372  */
1373 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref(JNIEnv * env,jclass clss,jlong attr_id,jlong mem_type_id,jobjectArray buf)1374 Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref
1375     (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf)
1376 {
1377     hdset_reg_ref_t *ref_data = NULL;
1378     h5str_t          h5str;
1379     jstring          jstr;
1380     jsize            i, n;
1381     herr_t           status = FAIL;
1382 
1383     UNUSED(clss);
1384 
1385     HDmemset(&h5str, 0, sizeof(h5str_t));
1386 
1387     if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
1388         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
1389         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_reg_ref: buf length < 0");
1390     }
1391 
1392     if (NULL == (ref_data = (hdset_reg_ref_t *) HDcalloc(1, (size_t)n * sizeof(hdset_reg_ref_t))))
1393         H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_reg_ref: failed to allocate read buffer");
1394 
1395     if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, ref_data)) < 0)
1396         H5_LIBRARY_ERROR(ENVONLY);
1397 
1398     h5str_new(&h5str, 1024);
1399 
1400     if (!h5str.s)
1401         H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_reg_ref: failed to allocate buffer");
1402 
1403     for (i = 0; i < n; i++) {
1404         h5str.s[0] = '\0';
1405 
1406         if (!h5str_sprintf(ENVONLY, &h5str, (hid_t)attr_id, (hid_t)mem_type_id, ref_data[i], 0, 0))
1407             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1408 
1409         if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s)))
1410             CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1411 
1412         ENVPTR->SetObjectArrayElement(ENVONLY, buf, i, jstr);
1413         CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1414 
1415         ENVPTR->DeleteLocalRef(ENVONLY, jstr);
1416     } /* end for */
1417 
1418 done:
1419     if (h5str.s)
1420         h5str_free(&h5str);
1421     if (ref_data)
1422         HDfree(ref_data);
1423 
1424     return (jint)status;
1425 } /* end Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref */
1426 
1427 /*
1428  * Class:     hdf_hdf5lib_H5
1429  * Method:    H5Aget_space
1430  * Signature: (J)J
1431  */
1432 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aget_1space(JNIEnv * env,jclass clss,jlong attr_id)1433 Java_hdf_hdf5lib_H5__1H5Aget_1space
1434     (JNIEnv *env, jclass clss, jlong attr_id)
1435 {
1436     hid_t retVal = H5I_INVALID_HID;
1437 
1438     UNUSED(clss);
1439 
1440     if ((retVal = H5Aget_space((hid_t)attr_id)) < 0)
1441         H5_LIBRARY_ERROR(ENVONLY);
1442 
1443 done:
1444     return (jlong)retVal;
1445 } /* end Java_hdf_hdf5lib_H5__1H5Aget_1space */
1446 
1447 /*
1448  * Class:     hdf_hdf5lib_H5
1449  * Method:    H5Aget_type
1450  * Signature: (J)J
1451  */
1452 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aget_1type(JNIEnv * env,jclass clss,jlong attr_id)1453 Java_hdf_hdf5lib_H5__1H5Aget_1type
1454     (JNIEnv *env, jclass clss, jlong attr_id)
1455 {
1456     hid_t retVal = H5I_INVALID_HID;
1457 
1458     UNUSED(clss);
1459 
1460     if ((retVal = H5Aget_type((hid_t)attr_id)) < 0)
1461         H5_LIBRARY_ERROR(ENVONLY);
1462 
1463 done:
1464     return (jlong)retVal;
1465 } /* end Java_hdf_hdf5lib_H5__1H5Aget_1type */
1466 
1467 /*
1468  * Class:     hdf_hdf5lib_H5
1469  * Method:    H5Aget_name
1470  * Signature: (J)Ljava/lang/String;
1471  */
1472 JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Aget_1name(JNIEnv * env,jclass clss,jlong attr_id)1473 Java_hdf_hdf5lib_H5_H5Aget_1name
1474     (JNIEnv *env, jclass clss, jlong attr_id)
1475 {
1476     jstring  str = NULL;
1477     ssize_t  buf_size;
1478     char    *attrName = NULL;
1479 
1480     UNUSED(clss);
1481 
1482     if ((buf_size = H5Aget_name((hid_t)attr_id, 0, NULL)) < 0)
1483         H5_LIBRARY_ERROR(ENVONLY);
1484 
1485     if (NULL == (attrName = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1)))
1486         H5_JNI_FATAL_ERROR(ENVONLY, "H5Aget_name: failed to allocate attribute name buffer");
1487 
1488     if (H5Aget_name((hid_t)attr_id, (size_t)buf_size + 1, attrName) < 0)
1489         H5_LIBRARY_ERROR(ENVONLY);
1490     attrName[buf_size] = '\0';
1491 
1492     if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, attrName)))
1493         CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1494 
1495 done:
1496     if (attrName)
1497         HDfree(attrName);
1498 
1499     return str;
1500 } /* end Java_hdf_hdf5lib_H5_H5Aget_1name */
1501 
1502 /*
1503  * Class:     hdf_hdf5lib_H5
1504  * Method:    H5Aget_num_attrs
1505  * Signature: (J)I
1506  */
1507 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aget_1num_1attrs(JNIEnv * env,jclass clss,jlong loc_id)1508 Java_hdf_hdf5lib_H5_H5Aget_1num_1attrs
1509     (JNIEnv *env, jclass clss, jlong loc_id)
1510 {
1511     int retVal = FAIL;
1512 
1513     UNUSED(clss);
1514 
1515     if ((retVal = H5Aget_num_attrs((hid_t)loc_id)) < 0)
1516         H5_LIBRARY_ERROR(ENVONLY);
1517 
1518 done:
1519     return (jint)retVal;
1520 } /* end Java_hdf_hdf5lib_H5_H5Aget_1num_1attrs */
1521 
1522 /*
1523  * Class:     hdf_hdf5lib_H5
1524  * Method:    H5Adelete
1525  * Signature: (JLjava/lang/String;)I
1526  */
1527 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Adelete(JNIEnv * env,jclass clss,jlong loc_id,jstring name)1528 Java_hdf_hdf5lib_H5_H5Adelete
1529     (JNIEnv *env, jclass clss, jlong loc_id, jstring name)
1530 {
1531     const char *attrName = NULL;
1532     herr_t      status = FAIL;
1533 
1534     UNUSED(clss);
1535 
1536     if (NULL == name)
1537         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Adelete: attribute name is NULL");
1538 
1539     PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Adelete: attribute name not pinned");
1540 
1541     if ((status = H5Adelete((hid_t)loc_id, attrName)) < 0)
1542         H5_LIBRARY_ERROR(ENVONLY);
1543 
1544 done:
1545     if (attrName)
1546         UNPIN_JAVA_STRING(ENVONLY, name, attrName);
1547 
1548     return (jint)status;
1549 } /* end Java_hdf_hdf5lib_H5_H5Adelete */
1550 
1551 /*
1552  * Class:     hdf_hdf5lib_H5
1553  * Method:    H5Aclose
1554  * Signature: (J)I
1555  */
1556 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5__1H5Aclose(JNIEnv * env,jclass clss,jlong attr_id)1557 Java_hdf_hdf5lib_H5__1H5Aclose
1558     (JNIEnv *env, jclass clss, jlong attr_id)
1559 {
1560     herr_t retVal = FAIL;
1561 
1562     UNUSED(clss);
1563 
1564     if ((retVal = H5Aclose((hid_t)attr_id)) < 0)
1565         H5_LIBRARY_ERROR(ENVONLY);
1566 
1567 done:
1568     return (jint)retVal;
1569 } /* end Java_hdf_hdf5lib_H5__1H5Aclose */
1570 
1571 /*
1572  * Class:     hdf_hdf5lib_H5
1573  * Method:    _H5Acreate2
1574  * Signature: (JLjava/lang/String;JJJJ)J
1575  */
1576 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Acreate2(JNIEnv * env,jclass clss,jlong loc_id,jstring name,jlong type_id,jlong space_id,jlong create_plist,jlong access_plist)1577 Java_hdf_hdf5lib_H5__1H5Acreate2
1578     (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong type_id,
1579         jlong space_id, jlong create_plist, jlong access_plist)
1580 {
1581     const char *attrName = NULL;
1582     hid_t       status = H5I_INVALID_HID;
1583 
1584     UNUSED(clss);
1585 
1586     if (NULL == name)
1587         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Acreate2: attribute name is NULL");
1588 
1589     PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Acreate2: attribute name not pinned");
1590 
1591     if ((status = H5Acreate2((hid_t)loc_id, attrName, (hid_t)type_id,
1592             (hid_t)space_id, (hid_t)create_plist, (hid_t)access_plist)) < 0)
1593         H5_LIBRARY_ERROR(ENVONLY);
1594 
1595 done:
1596     if (attrName)
1597         UNPIN_JAVA_STRING(ENVONLY, name, attrName);
1598 
1599     return (jlong)status;
1600 } /* end Java_hdf_hdf5lib_H5__1H5Acreate2 */
1601 
1602 /*
1603  * Class:     hdf_hdf5lib_H5
1604  * Method:    _H5Aopen
1605  * Signature: (JLjava/lang/String;J)J
1606  */
1607 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aopen(JNIEnv * env,jclass clss,jlong obj_id,jstring name,jlong access_plist)1608 Java_hdf_hdf5lib_H5__1H5Aopen
1609     (JNIEnv *env, jclass clss, jlong obj_id, jstring name, jlong access_plist)
1610 
1611 {
1612     const char *attrName = NULL;
1613     hid_t       retVal = H5I_INVALID_HID;
1614 
1615     UNUSED(clss);
1616 
1617     if (NULL == name)
1618         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aopen: attribute name is NULL");
1619 
1620     PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Aopen: attribute name not pinned");
1621 
1622     if ((retVal = H5Aopen((hid_t)obj_id, attrName, (hid_t)access_plist)) < 0)
1623         H5_LIBRARY_ERROR(ENVONLY);
1624 
1625 done:
1626     if (attrName)
1627         UNPIN_JAVA_STRING(ENVONLY, name, attrName);
1628 
1629     return (jlong)retVal;
1630 } /* end Java_hdf_hdf5lib_H5__1H5Aopen */
1631 
1632 /*
1633  * Class:     hdf_hdf5lib_H5
1634  * Method:    _H5Aopen_by_idx
1635  * Signature: (JLjava/lang/String;IIJJJ)J
1636  */
1637 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aopen_1by_1idx(JNIEnv * env,jclass clss,jlong loc_id,jstring name,jint idx_type,jint order,jlong n,jlong aapl_id,jlong lapl_id)1638 Java_hdf_hdf5lib_H5__1H5Aopen_1by_1idx
1639     (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint idx_type, jint order, jlong n, jlong aapl_id, jlong lapl_id)
1640 {
1641     const char *objName = NULL;
1642     hid_t       retVal = H5I_INVALID_HID;
1643 
1644     UNUSED(clss);
1645 
1646     if (NULL == name)
1647         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aopen_by_idx: object name is NULL");
1648 
1649     PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Aopen_by_idx: object name not pinned");
1650 
1651     if ((retVal = H5Aopen_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type,
1652             (H5_iter_order_t)order, (hsize_t)n, (hid_t)aapl_id, (hid_t)lapl_id)) < 0)
1653         H5_LIBRARY_ERROR(ENVONLY);
1654 
1655 done:
1656     if (objName)
1657         UNPIN_JAVA_STRING(ENVONLY, name, objName);
1658 
1659     return (jlong)retVal;
1660 } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1by_1idx */
1661 
1662 /*
1663 * Class:     hdf_hdf5lib_H5
1664 * Method:    _H5Acreate_by_name
1665 * Signature: (JLjava/lang/String;Ljava/lang/String;JJJJJ)J
1666 */
1667 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Acreate_1by_1name(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jstring attr_name,jlong type_id,jlong space_id,jlong acpl_id,jlong aapl_id,jlong lapl_id)1668 Java_hdf_hdf5lib_H5__1H5Acreate_1by_1name
1669     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong type_id, jlong space_id, jlong acpl_id, jlong aapl_id, jlong lapl_id)
1670 {
1671     const char *objName = NULL;
1672     const char *attrName = NULL;
1673     hid_t       retVal = H5I_INVALID_HID;
1674 
1675     UNUSED(clss);
1676 
1677     if (NULL == obj_name)
1678         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Acreate_by_name: object name is NULL");
1679     if (NULL == attr_name)
1680         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Acreate_by_name: attribute name is NULL");
1681 
1682     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Acreate_by_name: object name not pinned");
1683     PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Acreate_by_name: attribute name not pinned");
1684 
1685     if ((retVal = H5Acreate_by_name((hid_t)loc_id, objName, attrName, (hid_t)type_id,
1686             (hid_t)space_id, (hid_t)acpl_id, (hid_t)aapl_id, (hid_t)lapl_id)) < 0)
1687         H5_LIBRARY_ERROR(ENVONLY);
1688 
1689 done:
1690     if (attrName)
1691         UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName);
1692     if (objName)
1693         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
1694 
1695     return (jlong)retVal;
1696 } /* end Java_hdf_hdf5lib_H5__1H5Acreate_1by_1name */
1697 
1698 /*
1699  * Class:     hdf_hdf5lib_H5
1700  * Method:    H5Aexists_by_name
1701  * Signature: (JLjava/lang/String;Ljava/lang/String;J)Z
1702  */
1703 JNIEXPORT jboolean JNICALL
Java_hdf_hdf5lib_H5_H5Aexists_1by_1name(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jstring attr_name,jlong lapl_id)1704 Java_hdf_hdf5lib_H5_H5Aexists_1by_1name
1705     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong lapl_id)
1706 {
1707     const char *objName = NULL;
1708     const char *attrName = NULL;
1709     htri_t      bval = JNI_FALSE;
1710 
1711     UNUSED(clss);
1712 
1713     if (NULL == obj_name)
1714         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aexists_by_name: object name is NULL");
1715     if (NULL == attr_name)
1716         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aexists_by_name: attribute name is NULL");
1717 
1718     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aexists_by_name: object name not pinned");
1719     PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aexists_by_name: attribute name not pinned");
1720 
1721     if ((bval = H5Aexists_by_name((hid_t)loc_id, objName, attrName, (hid_t)lapl_id)) < 0)
1722         H5_LIBRARY_ERROR(ENVONLY);
1723 
1724     bval = (bval > 0) ? JNI_TRUE : JNI_FALSE;
1725 
1726 done:
1727     if (attrName)
1728         UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName);
1729     if (objName)
1730         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
1731 
1732     return (jboolean)bval;
1733 } /* end Java_hdf_hdf5lib_H5_H5Aexists_1by_1name */
1734 
1735 /*
1736  * Class:     hdf_hdf5lib_H5
1737  * Method:    H5Arename
1738  * Signature: (JLjava/lang/String;Ljava/lang/String)I
1739  */
1740 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Arename(JNIEnv * env,jclass clss,jlong loc_id,jstring old_attr_name,jstring new_attr_name)1741 Java_hdf_hdf5lib_H5_H5Arename
1742     (JNIEnv *env, jclass clss, jlong loc_id, jstring old_attr_name, jstring new_attr_name)
1743 {
1744     const char *oldAttrName = NULL;
1745     const char *newAttrName = NULL;
1746     herr_t      retVal = FAIL;
1747 
1748     UNUSED(clss);
1749 
1750     if (NULL == old_attr_name)
1751         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Arename: old attribute name is NULL");
1752     if (NULL == new_attr_name)
1753         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Arename: new attribute name is NULL");
1754 
1755     PIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName, NULL, "H5Arename: old attribute name not pinned");
1756     PIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName, NULL, "H5Arename: new attribute name not pinned");
1757 
1758     if ((retVal = H5Arename((hid_t)loc_id, oldAttrName, newAttrName)) < 0)
1759         H5_LIBRARY_ERROR(ENVONLY);
1760 
1761 done:
1762     if (newAttrName)
1763         UNPIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName);
1764     if (oldAttrName)
1765         UNPIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName);
1766 
1767     return (jint)retVal;
1768 } /* end Java_hdf_hdf5lib_H5_H5Arename */
1769 
1770 /*
1771  * Class:     hdf_hdf5lib_H5
1772  * Method:    H5Arename_by_name
1773  * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I
1774  */
1775 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Arename_1by_1name(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jstring old_attr_name,jstring new_attr_name,jlong lapl_id)1776 Java_hdf_hdf5lib_H5_H5Arename_1by_1name
1777     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring old_attr_name, jstring new_attr_name, jlong lapl_id)
1778 {
1779     const char *objName = NULL;
1780     const char *oldAttrName = NULL;
1781     const char *newAttrName = NULL;
1782     herr_t      retVal = FAIL;
1783 
1784     UNUSED(clss);
1785 
1786     if (NULL == obj_name)
1787         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Arename_by_name: object name is NULL");
1788     if (NULL == old_attr_name)
1789         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Arename_by_name: old attribute name is NULL");
1790     if (NULL == new_attr_name)
1791         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Arename_by_name: new attribute name is NULL");
1792 
1793     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Arename_by_name: object name not pinned");
1794     PIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName, NULL, "H5Arename_by_name: old attribute name not pinned");
1795     PIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName, NULL, "H5Arename_by_name: new attribute name not pinned");
1796 
1797     if ((retVal = H5Arename_by_name((hid_t)loc_id, objName, oldAttrName, newAttrName, (hid_t)lapl_id)) < 0)
1798         H5_LIBRARY_ERROR(ENVONLY);
1799 
1800 done:
1801     if (newAttrName)
1802         UNPIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName);
1803     if (oldAttrName)
1804         UNPIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName);
1805     if (objName)
1806         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
1807 
1808     return (jint)retVal;
1809 } /* end Java_hdf_hdf5lib_H5_H5Arename_1by_1name */
1810 
1811 /*
1812  * Class:     hdf_hdf5lib_H5
1813  * Method:    H5Aget_name_by_idx
1814  * Signature: (JLjava/lang/String;IIJJ)Ljava/lang/String;
1815  */
1816 JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jint idx_type,jint order,jlong n,jlong lapl_id)1817 Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx
1818     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jint idx_type, jint order, jlong n, jlong lapl_id)
1819 {
1820     const char *objName = NULL;
1821     jstring     str = NULL;
1822     ssize_t     status_size = -1;
1823     char       *attrName = NULL;
1824 
1825     UNUSED(clss);
1826 
1827     if (NULL == obj_name)
1828         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aget_name_by_idx: object name is NULL");
1829 
1830     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aget_name_by_idx: object name not pinned");
1831 
1832     /* Get the length of the attribute name */
1833     if ((status_size = H5Aget_name_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type,
1834             (H5_iter_order_t) order, (hsize_t) n, (char *)NULL, (size_t)0, (hid_t)lapl_id)) < 0)
1835         H5_LIBRARY_ERROR(ENVONLY);
1836 
1837     if (NULL == (attrName = (char *) HDmalloc(sizeof(char) * (size_t) status_size + 1)))
1838         H5_JNI_FATAL_ERROR(ENVONLY, "H5Aget_name_by_idx: failed to allocate buffer for attribute name");
1839 
1840     if ((H5Aget_name_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type,
1841             (H5_iter_order_t) order, (hsize_t) n, (char *)attrName, (size_t)status_size + 1, (hid_t)lapl_id)) < 0)
1842         H5_LIBRARY_ERROR(ENVONLY);
1843     attrName[status_size] = '\0';
1844 
1845     if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, attrName)))
1846         CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
1847 
1848 done:
1849     if (attrName)
1850         HDfree(attrName);
1851     if (objName)
1852         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
1853 
1854     return str;
1855 } /* end Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx */
1856 
1857 /*
1858  * Class:     hdf_hdf5lib_H5
1859  * Method:    H5Aget_storage_size
1860  * Signature: (J)J
1861  */
1862 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Aget_1storage_1size(JNIEnv * env,jclass clss,jlong attr_id)1863 Java_hdf_hdf5lib_H5_H5Aget_1storage_1size
1864     (JNIEnv *env, jclass clss, jlong attr_id)
1865 {
1866     hsize_t retVal = 0;
1867 
1868     UNUSED(clss);
1869 
1870     if (!(retVal = H5Aget_storage_size((hid_t)attr_id)))
1871         H5_LIBRARY_ERROR(ENVONLY);
1872 
1873 done:
1874     return (jlong)retVal;
1875 } /* end Java_hdf_hdf5lib_H5_H5Aget_1storage_1size */
1876 
1877 /*
1878  * Class:     hdf_hdf5lib_H5
1879  * Method:    H5Aget_info
1880  * Signature: (J)Lhdf/hdf5lib/structs/H5A_info_t;
1881  */
1882 JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Aget_1info(JNIEnv * env,jclass clss,jlong attr_id)1883 Java_hdf_hdf5lib_H5_H5Aget_1info
1884     (JNIEnv *env, jclass clss, jlong attr_id)
1885 {
1886     H5A_info_t ainfo;
1887     jobject    ret_obj = NULL;
1888     jvalue     args[4];
1889 
1890     UNUSED(clss);
1891 
1892     if (H5Aget_info((hid_t)attr_id, &ainfo) < 0)
1893         H5_LIBRARY_ERROR(ENVONLY);
1894 
1895     args[0].z = ainfo.corder_valid;
1896     args[1].j = ainfo.corder;
1897     args[2].i = ainfo.cset;
1898     args[3].j = (jlong)ainfo.data_size;
1899 
1900     CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args, ret_obj);
1901 
1902 done:
1903     return ret_obj;
1904 } /* end Java_hdf_hdf5lib_H5_H5Aget_1info */
1905 
1906 /*
1907  * Class:     hdf_hdf5lib_H5
1908  * Method:    H5Aget_info_by_idx
1909  * Signature: (JLjava/lang/String;IIJJ)Lhdf/hdf5lib/structs/H5A_info_t;
1910  */
1911 JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jint idx_type,jint order,jlong n,jlong lapl_id)1912 Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx
1913     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jint idx_type, jint order, jlong n, jlong lapl_id)
1914 {
1915     const char *objName = NULL;
1916     H5A_info_t  ainfo;
1917     herr_t      status;
1918     jvalue      args[4];
1919     jobject     ret_obj = NULL;
1920 
1921     UNUSED(clss);
1922 
1923     if (NULL == obj_name)
1924         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aget_info_by_idx: object name is NULL");
1925 
1926     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aget_info_by_idx: object name not pinned");
1927 
1928     if ((status = H5Aget_info_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type,
1929             (H5_iter_order_t)order, (hsize_t)n, &ainfo, (hid_t)lapl_id)) < 0)
1930         H5_LIBRARY_ERROR(ENVONLY);
1931 
1932     args[0].z = ainfo.corder_valid;
1933     args[1].j = ainfo.corder;
1934     args[2].i = ainfo.cset;
1935     args[3].j = (jlong)ainfo.data_size;
1936 
1937     CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args, ret_obj);
1938 
1939 done:
1940     if (objName)
1941         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
1942 
1943     return ret_obj;
1944 } /* end Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx */
1945 
1946 /*
1947  * Class:     hdf_hdf5lib_H5
1948  * Method:    H5Aget_info_by_name
1949  * Signature: (JLjava/lang/String;Ljava/lang/String;J)Lhdf/hdf5lib/structs/H5A_info_t;
1950  */
1951 JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jstring attr_name,jlong lapl_id)1952 Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name
1953     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong lapl_id)
1954 {
1955     const char *objName = NULL;
1956     const char *attrName = NULL;
1957     H5A_info_t  ainfo;
1958     herr_t      status;
1959     jvalue      args[4];
1960     jobject     ret_obj = NULL;
1961 
1962     UNUSED(clss);
1963 
1964     if (NULL == obj_name)
1965         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aget_info_by_name: object name is NULL");
1966     if (NULL == attr_name)
1967         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aget_info_by_name: attribute name is NULL");
1968 
1969     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aget_info_by_name: object name not pinned");
1970     PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aget_info_by_name: attribute name not pinned");
1971 
1972     if ((status = H5Aget_info_by_name((hid_t)loc_id, objName, attrName, &ainfo, (hid_t)lapl_id)) < 0)
1973         H5_LIBRARY_ERROR(ENVONLY);
1974 
1975     args[0].z = ainfo.corder_valid;
1976     args[1].j = ainfo.corder;
1977     args[2].i = ainfo.cset;
1978     args[3].j = (jlong)ainfo.data_size;
1979 
1980     CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args, ret_obj);
1981 
1982 done:
1983     if (attrName)
1984         UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName);
1985     if (objName)
1986         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
1987 
1988     return ret_obj;
1989 } /* end Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name */
1990 
1991 /*
1992  * Class:     hdf_hdf5lib_H5
1993  * Method:    H5Adelete_by_name
1994  * Signature: (JLjava/lang/String;Ljava/lang/String;J)I
1995  */
1996 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Adelete_1by_1name(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jstring attr_name,jlong lapl_id)1997 Java_hdf_hdf5lib_H5_H5Adelete_1by_1name
1998     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong lapl_id)
1999 {
2000     const char *objName = NULL;
2001     const char *attrName = NULL;
2002     herr_t      retVal = FAIL;
2003 
2004     UNUSED(clss);
2005 
2006     if (NULL == obj_name)
2007         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Adelete_by_name: object name is NULL");
2008     if (NULL == attr_name)
2009         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Adelete_by_name: attribute name is NULL");
2010 
2011     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Adelete_by_name: object name not pinned");
2012     PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Adelete_by_name: attribute name not pinned");
2013 
2014     if ((retVal = H5Adelete_by_name((hid_t)loc_id, objName, attrName, (hid_t)lapl_id)) < 0)
2015         H5_LIBRARY_ERROR(ENVONLY);
2016 
2017 done:
2018     if (attrName)
2019         UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName);
2020     if (objName)
2021         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
2022 
2023     return (jint)retVal;
2024 } /* end Java_hdf_hdf5lib_H5_H5Adelete_1by_1name */
2025 
2026 /*
2027  * Class:     hdf_hdf5lib_H5
2028  * Method:    H5Aexists
2029  * Signature: (JLjava/lang/String;)Z
2030  */
2031 JNIEXPORT jboolean JNICALL
Java_hdf_hdf5lib_H5_H5Aexists(JNIEnv * env,jclass clss,jlong obj_id,jstring attr_name)2032 Java_hdf_hdf5lib_H5_H5Aexists
2033     (JNIEnv *env, jclass clss, jlong obj_id, jstring attr_name)
2034 {
2035     const char *attrName = NULL;
2036     htri_t      bval = JNI_FALSE;
2037 
2038     UNUSED(clss);
2039 
2040     if (NULL == attr_name)
2041         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aexists: attribute name is NULL");
2042 
2043     PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aexists: attribute name not pinned");
2044 
2045     if ((bval = H5Aexists((hid_t)obj_id, attrName)) < 0)
2046         H5_LIBRARY_ERROR(ENVONLY);
2047 
2048     bval = (bval > 0) ? JNI_TRUE : JNI_FALSE;
2049 
2050 done:
2051     if (attrName)
2052         UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName);
2053 
2054     return (jboolean)bval;
2055 } /* end Java_hdf_hdf5lib_H5_H5Aexists */
2056 
2057 /*
2058  * Class:     hdf_hdf5lib_H5
2059  * Method:    H5Adelete_by_idx
2060  * Signature: (JLjava/lang/String;IIJJ)V
2061  */
2062 JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Adelete_1by_1idx(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jint idx_type,jint order,jlong n,jlong lapl_id)2063 Java_hdf_hdf5lib_H5_H5Adelete_1by_1idx
2064     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jint idx_type, jint order, jlong n, jlong lapl_id)
2065 {
2066     const char *objName = NULL;
2067     herr_t      status = FAIL;
2068 
2069     UNUSED(clss);
2070 
2071     if (NULL == obj_name)
2072         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Adelete_by_idx: object name is NULL");
2073 
2074     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Adelete_by_idx: object name not pinned");
2075 
2076     if ((status = H5Adelete_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t)n, (hid_t)lapl_id)) < 0)
2077         H5_LIBRARY_ERROR(ENVONLY);
2078 
2079 done:
2080     if (objName)
2081         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
2082 } /* end Java_hdf_hdf5lib_H5_H5Adelete_1by_1idx */
2083 
2084 /*
2085  * Class:     hdf_hdf5lib_H5
2086  * Method:    _H5Aopen_by_name
2087  * Signature: (JLjava/lang/String;Ljava/lang/String;JJ)J
2088  */
2089 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name(JNIEnv * env,jclass clss,jlong loc_id,jstring obj_name,jstring attr_name,jlong aapl_id,jlong lapl_id)2090 Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name
2091     (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong aapl_id, jlong lapl_id)
2092 
2093 {
2094     const char *attrName = NULL;
2095     const char *objName = NULL;
2096     hid_t       status = H5I_INVALID_HID;
2097 
2098     UNUSED(clss);
2099 
2100     if (NULL == obj_name)
2101         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aopen_by_name: object name is NULL");
2102     if (NULL == attr_name)
2103         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aopen_by_name: attribute name is NULL");
2104 
2105     PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aopen_by_name: object name not pinned");
2106     PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aopen_by_name: attribute name not pinned");
2107 
2108     if ((status = H5Aopen_by_name((hid_t)loc_id, objName, attrName, (hid_t)aapl_id, (hid_t)lapl_id)) < 0)
2109         H5_LIBRARY_ERROR(ENVONLY);
2110 
2111 done:
2112     if (attrName)
2113         UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName);
2114     if (objName)
2115         UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);
2116 
2117     return (jlong)status;
2118 } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name */
2119 
2120 /*
2121  * Class:     hdf_hdf5lib_H5
2122  * Method:    H5Aget_create_plist
2123  * Signature: (J)J
2124  */
2125 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Aget_1create_1plist(JNIEnv * env,jclass clss,jlong attr_id)2126 Java_hdf_hdf5lib_H5__1H5Aget_1create_1plist
2127     (JNIEnv *env, jclass clss, jlong attr_id)
2128 {
2129     hid_t retVal = H5I_INVALID_HID;
2130 
2131     UNUSED(clss);
2132 
2133     if ((retVal = H5Aget_create_plist((hid_t)attr_id)) < 0)
2134         H5_LIBRARY_ERROR(ENVONLY);
2135 
2136 done:
2137     return (jlong)retVal;
2138 } /* end Java_hdf_hdf5lib_H5__1H5Aget_1create_1plist */
2139 
2140 static herr_t
H5A_iterate_cb(hid_t g_id,const char * name,const H5A_info_t * info,void * cb_data)2141 H5A_iterate_cb
2142     (hid_t g_id, const char *name, const H5A_info_t *info, void *cb_data) {
2143     cb_wrapper *wrapper = (cb_wrapper *)cb_data;
2144     jmethodID   constructor, mid;
2145     jobject     cb_info_t = NULL;
2146     jobject     visit_callback = wrapper->visit_callback;
2147     jstring     str;
2148     JNIEnv     *cbenv = NULL;
2149     jclass      cls;
2150     jvalue      args[4];
2151     void       *op_data = (void *)wrapper->op_data;
2152     jint        status = -1;
2153 
2154     if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) {
2155         CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE);
2156         H5_JNI_FATAL_ERROR(CBENVONLY, "H5A_iterate_cb: failed to attach current thread to JVM");
2157     }
2158 
2159     if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback)))
2160         CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
2161 
2162     if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5A_info_t;Lhdf/hdf5lib/callbacks/H5A_iterate_t;)I")))
2163         CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
2164 
2165     if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name)))
2166         CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
2167 
2168     args[0].z = info->corder_valid;
2169     args[1].j = info->corder;
2170     args[2].i = info->cset;
2171     args[3].j = (jlong)info->data_size;
2172 
2173     /* Get a reference to your class if you don't have it already */
2174     if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5A_info_t")))
2175         CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
2176 
2177     /* Get a reference to the constructor; the name is <init> */
2178     if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "<init>", "(ZJIJ)V")))
2179         CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
2180 
2181     if (NULL == (cb_info_t = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) {
2182         HDprintf("FATAL ERROR:  hdf/hdf5lib/structs/H5A_info_t: Creation failed\n");
2183         CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
2184     }
2185 
2186     status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, g_id, str, cb_info_t, op_data);
2187     CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE);
2188 
2189 done:
2190     if (cbenv)
2191         JVMPTR->DetachCurrentThread(JVMPAR);
2192 
2193     return (herr_t)status;
2194 } /* end H5A_iterate_cb */
2195 
2196 /*
2197  * Class:     hdf_hdf5lib_H5
2198  * Method:    H5Aiterate
2199  * Signature: (JIIJLjava/lang/Object;Ljava/lang/Object;)I
2200  */
2201 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aiterate(JNIEnv * env,jclass clss,jlong grp_id,jint idx_type,jint order,jlong idx,jobject callback_op,jobject op_data)2202 Java_hdf_hdf5lib_H5_H5Aiterate
2203     (JNIEnv *env, jclass clss, jlong grp_id, jint idx_type, jint order,
2204           jlong idx, jobject callback_op, jobject op_data)
2205 {
2206     cb_wrapper wrapper = { callback_op, op_data };
2207     hsize_t    start_idx = (hsize_t)idx;
2208     herr_t     status = FAIL;
2209 
2210     UNUSED(clss);
2211 
2212     ENVPTR->GetJavaVM(ENVONLY, &jvm);
2213     CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
2214 
2215     if (NULL == op_data)
2216         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate: op_data is NULL");
2217     if (NULL == callback_op)
2218         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate: callback_op is NULL");
2219 
2220     if ((status = H5Aiterate2((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)&wrapper)) < 0)
2221         H5_LIBRARY_ERROR(ENVONLY);
2222 
2223 done:
2224     return (jint)status;
2225 } /* end Java_hdf_hdf5lib_H5_H5Aiterate */
2226 
2227 /*
2228  * Class:     hdf_hdf5lib_H5
2229  * Method:    H5Aiterate_by_name
2230  * Signature: (JLjava/lang/String;IIJLjava/lang/Object;Ljava/lang/Object;J)I
2231  */
2232 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Aiterate_1by_1name(JNIEnv * env,jclass clss,jlong grp_id,jstring name,jint idx_type,jint order,jlong idx,jobject callback_op,jobject op_data,jlong access_id)2233 Java_hdf_hdf5lib_H5_H5Aiterate_1by_1name
2234     (JNIEnv *env, jclass clss, jlong grp_id, jstring name, jint idx_type, jint order,
2235           jlong idx, jobject callback_op, jobject op_data, jlong access_id)
2236 {
2237     const char *objName = NULL;
2238     cb_wrapper  wrapper = { callback_op, op_data };
2239     hsize_t     start_idx = (hsize_t)idx;
2240     herr_t      status = FAIL;
2241 
2242     UNUSED(clss);
2243 
2244     ENVPTR->GetJavaVM(ENVONLY, &jvm);
2245     CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
2246 
2247     if (NULL == op_data)
2248         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate_by_name: op_data is NULL");
2249     if (NULL == callback_op)
2250         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate_by_name: callback_op is NULL");
2251     if (NULL == name)
2252         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate_by_name: object name is NULL");
2253 
2254     PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Aiterate_by_name: object name not pinned");
2255 
2256     if ((status = H5Aiterate_by_name((hid_t)grp_id, objName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)&wrapper, (hid_t)access_id)) < 0)
2257         H5_LIBRARY_ERROR(ENVONLY);
2258 
2259 done:
2260     if (objName)
2261         UNPIN_JAVA_STRING(ENVONLY, name, objName);
2262 
2263     return (jint)status;
2264 } /* end Java_hdf_hdf5lib_H5_H5Aiterate_1by_1name */
2265 
2266 #ifdef __cplusplus
2267 } /* end extern "C" */
2268 #endif /* __cplusplus */
2269