Repository navigation
Expand file tree
/
Copy pathexceptionImp.c
More file actions
executable file
·701 lines (620 loc) · 16.4 KB
/
Copy pathexceptionImp.c
File metadata and controls
executable file
·701 lines (620 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/****************************************************************************
* NCSA HDF *
* National Comptational Science Alliance *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* For conditions of distribution and use, see the accompanying *
* java-hdf5/COPYING file. *
* *
****************************************************************************/
/*
* This is a utility program used by the HDF Java-C wrapper layer to
* generate exceptions. This may be called from any part of the
* Java-C interface.
*
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "hdf5.h"
#include <stdio.h>
#include "jni.h"
/*
#include "H5Eprivate.h"
*/
/* These types are copied from H5Eprivate.h
* They should be moved to a public include file, and deleted from
* here.
*/
#define H5E_NSLOTS 32 /*number of slots in an error stack */
/*
* The list of error messages in the system is kept as an array of
* error_code/message pairs, one for major error numbers and another for
* minor error numbers.
*/
typedef struct H5E_major_mesg_t {
H5E_major_t error_code;
const char *str;
} H5E_major_mesg_t;
typedef struct H5E_minor_mesg_t {
H5E_minor_t error_code;
const char *str;
} H5E_minor_mesg_t;
/* An error stack */
typedef struct H5E_t {
/*intn*/int nused; /*num slots currently used in stack */
H5E_error_t slot[H5E_NSLOTS]; /*array of error records */
} H5E_t;
/*
* The error stack. Eventually we'll have some sort of global table so each
* thread has it's own stack. The stacks will be created on demand when the
* thread first calls H5E_push().
*/
#ifdef WIN32
/* windows does not like the 'extern' here */
H5E_t H5E_stack_g[1];
#else
extern H5E_t H5E_stack_g[1];
#endif
#define H5E_get_my_stack() (H5E_stack_g+0)
char *defineHDF5LibraryException(int maj_num);
/*
* Class: ncsa_hdf_hdf5lib_exceptions_HDF5Library
* Method: H5error_off
* Signature: ()I
*
*/
JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5error_1off
(JNIEnv *env, jclass clss )
{
return H5Eset_auto(NULL, NULL);
}
/*
* Class: ncsa_hdf_hdf5lib_exceptions_HDFLibraryException
* Method: printStackTrace0
* Signature: (Ljava/lang/Object;)V
*
* Call the HDF-5 library to print the HDF-5 error stack to 'file_name'.
*/
JNIEXPORT void JNICALL Java_ncsa_hdf_hdf5lib_exceptions_HDF5LibraryException_printStackTrace0
(JNIEnv *env, jobject obj, jstring file_name)
{
FILE *stream;
char *file;
if (file_name == NULL)
H5Eprint(stderr);
else
{
#ifdef __cplusplus
file = (char *)env->GetStringUTFChars(file_name,0);
#else
file = (char *)(*env)->GetStringUTFChars(env,file_name,0);
#endif
stream = fopen(file, "a+");
H5Eprint(stream);
#ifdef __cplusplus
env->ReleaseStringUTFChars(file_name, file);
#else
(*env)->ReleaseStringUTFChars(env, file_name, file);
#endif
if (stream) fclose(stream);
}
}
int getMajorErrorNumber();
int getMinorErrorNumber();
/*
* Class: ncsa_hdf_hdf5lib_exceptions_HDFLibraryException
* Method: getMajorErrorNumber
* Signature: ()I
*
* Extract the HDF-5 major error number from the HDF-5 error stack.
*
* Note: This relies on undocumented, 'private' code in the HDF-5
* library. Later releases will have a public interface for this
* purpose.
*/
JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_exceptions_HDF5LibraryException_getMajorErrorNumber
(JNIEnv *env, jobject obj)
{
return (jint) getMajorErrorNumber();
}
int getMajorErrorNumber()
{
H5E_t *estack = H5E_get_my_stack ();
H5E_error_t *err_desc;
H5E_major_t maj_num = H5E_NONE_MAJOR;
if (estack && estack->nused>0)
{
err_desc = estack->slot+0;
maj_num = err_desc->maj_num;
}
return (int) maj_num;
}
/*
* Class: ncsa_hdf_hdf5lib_exceptions_HDFLibraryException
* Method: getMinorErrorNumber
* Signature: ()I
*
* Extract the HDF-5 minor error number from the HDF-5 error stack.
*
* Note: This relies on undocumented, 'private' code in the HDF-5
* library. Later releases will have a public interface for this
* purpose.
*/
JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_exceptions_HDF5LibraryException_getMinorErrorNumber
(JNIEnv *env, jobject obj)
{
return (jint) getMinorErrorNumber();
}
int getMinorErrorNumber()
{
H5E_t *estack = H5E_get_my_stack ();
H5E_error_t *err_desc;
H5E_minor_t min_num = H5E_NONE_MINOR;
if (estack && estack->nused>0)
{
err_desc = estack->slot+0;
min_num = err_desc->min_num;
}
return (int) min_num;
}
/*
* Routine to raise particular Java exceptions from C
*/
/*
* Create and throw an 'outOfMemoryException'
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5outOfMemory( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;
#ifdef __cplusplus
jc = env->FindClass("java/lang/OutOfMemoryError");
#else
jc = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
str = (env)->NewStringUTF(functName);
#else
str = (*env)->NewStringUTF(env,functName);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw( (jthrowable ) ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
printf("FATAL ERROR: OutOfMemoryError: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
* A fatal error in a JNI call
* Create and throw an 'InternalError'
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5JNIFatalError( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;
#ifdef __cplusplus
jc = env->FindClass("java/lang/InternalError");
#else
jc = (*env)->FindClass(env, "java/lang/InternalError");
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
str = env->NewStringUTF(functName);
#else
str = (*env)->NewStringUTF(env,functName);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw( (jthrowable) ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
printf("FATAL ERROR: JNIFatal: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
* A NULL argument in an HDF5 call
* Create and throw an 'NullPointerException'
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5nullArgument( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;
#ifdef __cplusplus
jc = env->FindClass("java/lang/NullPointerException");
#else
jc = (*env)->FindClass(env, "java/lang/NullPointerException");
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
str = env->NewStringUTF(functName);
#else
str = (*env)->NewStringUTF(env,functName);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw((jthrowable) ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
printf("FATAL ERROR: NullPoitner: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
* A bad argument in an HDF5 call
* Create and throw an 'IllegalArgumentException'
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5badArgument( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;
#ifdef __cplusplus
jc = env->FindClass("java/lang/IllegalArgumentException");
#else
jc = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
str = env->NewStringUTF(functName);
#else
str = (*env)->NewStringUTF(env,functName);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw((jthrowable) ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
printf("FATAL ERROR: BadArgument: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
* Some feature Not implemented yet
* Create and throw an 'UnsupportedOperationException'
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5unimplemented( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;
#ifdef __cplusplus
jc = env->FindClass("java/lang/UnsupportedOperationException");
#else
jc = (*env)->FindClass(env, "java/lang/UnsupportedOperationException");
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
str = env->NewStringUTF(functName);
#else
str = (*env)->NewStringUTF(env,functName);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw((jthrowable) ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
printf("FATAL ERROR: Unsupported: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
* h5libraryError() determines the HDF-5 major error code
* and creates and throws the appropriate sub-class of
* HDF5LibraryException(). This routine should be called
* whenever a call to the HDF-5 library fails, i.e., when
* the return is -1.
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5libraryError( JNIEnv *env )
{
jmethodID jm;
jclass jc;
char *args[2];
char *exception;
jobject ex;
jstring str;
char *msg;
int rval, min_num, maj_num;
maj_num = (int)getMajorErrorNumber();
exception = (char *)defineHDF5LibraryException(maj_num);
#ifdef __cplusplus
jc = env->FindClass(exception);
#else
jc = (*env)->FindClass(env, exception);
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
min_num = (int)getMinorErrorNumber();
msg = (char *)H5Eget_minor((H5E_minor_t)min_num);
#ifdef __cplusplus
str = env->NewStringUTF(msg);
#else
str = (*env)->NewStringUTF(env,msg);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw((jthrowable) ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
printf("FATAL ERROR: h5libraryError: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
/* raiseException(). This routine is called to generate
* an arbitrary Java exception with a particular message.
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5raiseException( JNIEnv *env, char *exception, char *message)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;
#ifdef __cplusplus
jc = env->FindClass(exception);
#else
jc = (*env)->FindClass(env, exception);
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
str = env->NewStringUTF(message);
#else
str = (*env)->NewStringUTF(env,message);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw( (jthrowable)ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
printf("FATAL ERROR: raiseException: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
jboolean buildException( JNIEnv *env, char *exception, jint HDFerr)
{
jmethodID jm;
jclass jc;
int args[2];
jobject ex;
int rval;
jc = (*env)->FindClass(env, exception);
if (jc == NULL) {
return JNI_FALSE;
}
jm = (*env)->GetMethodID(env, jc, "<init>", "(I)V");
if (jm == NULL) {
return JNI_FALSE;
}
args[0] = HDFerr;
args[1] = 0;
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
if (rval < 0) {
printf("FATAL ERROR: raiseException: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
*/
/*
* defineHDF5LibraryException() returns the name of the sub-class
* which goes with an HDF-5 error code.
*/
char *defineHDF5LibraryException(int maj_num)
{
H5E_major_t err_num = (H5E_major_t) maj_num;
switch (err_num)
{
case H5E_ARGS:
return "ncsa/hdf/hdf5lib/exceptions/HDF5FunctionArgumentException";
case H5E_RESOURCE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5ResourceUnavailabletException";
case H5E_INTERNAL:
return "ncsa/hdf/hdf5lib/exceptions/HDF5InternalErrorException";
case H5E_FILE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5FileInterfaceException";
case H5E_IO:
return "ncsa/hdf/hdf5lib/exceptions/HDF5LowLevelIOException";
case H5E_FUNC:
return "ncsa/hdf/hdf5lib/exceptions/HDF5FunctionEntryExitException";
case H5E_ATOM:
return "ncsa/hdf/hdf5lib/exceptions/HDF5AtomException";
case H5E_CACHE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5MetaDataCacheException";
case H5E_BTREE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5BtreeException";
case H5E_SYM:
return "ncsa/hdf/hdf5lib/exceptions/HDF5SymbolTableException";
case H5E_HEAP:
return "ncsa/hdf/hdf5lib/exceptions/HDF5HeapException";
case H5E_OHDR:
return "ncsa/hdf/hdf5lib/exceptions/HDF5ObjectHeaderException";
case H5E_DATATYPE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5DatatypeInterfaceException";
case H5E_DATASPACE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5DataspaceInterfaceException";
case H5E_DATASET:
return "ncsa/hdf/hdf5lib/exceptions/HDF5DatasetInterfaceException";
case H5E_STORAGE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5DataStorageException";
case H5E_PLIST:
return "ncsa/hdf/hdf5lib/exceptions/HDF5PropertyListInterfaceException";
case H5E_ATTR:
return "ncsa/hdf/hdf5lib/exceptions/HDF5AttributeException";
case H5E_PLINE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5DataFiltersExceptionn";
case H5E_EFL:
return "ncsa/hdf/hdf5lib/exceptions/HDF5ExternalFileListException";
case H5E_REFERENCE:
return "ncsa/hdf/hdf5lib/exceptions/HDF5ReferenceException";
default:
return "ncsa/hdf/hdf5lib/exceptions/HDF5LibraryException";
}
}
#ifdef __cplusplus
}
#endif