-
Notifications
You must be signed in to change notification settings - Fork 0
/
H5VLerror.h
156 lines (138 loc) · 5.35 KB
/
H5VLerror.h
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
/*Copyright 2021 Hewlett Packard Enterprise Development LP.*/
#ifndef H5VLerror_H
#define H5VLerror_H
/* Public headers needed by this file */
#include <H5Epublic.h>
/**
* Must be defined for each VOL connector.
*/
#define H5VL_ERR_NAME dsetsplit
/**
* Boolean types.
*/
#ifndef FALSE
# define FALSE false
#endif
#ifndef TRUE
# define TRUE true
#endif
/**
* Define __func__ if not defined.
*/
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ < 199901L)
# if defined(__GNUC__) && (__GNUC__ >= 2)
# define __func__ __FUNCTION__
# else
# define __func__ "<unknown>"
# endif
#elif defined(_WIN32)
# define __func__ __FUNCTION__
#endif
/**
* Macros to declare and use error stack and class.
*/
#define H5VL_ERR_STACK_NAME(name) __H5VL ## name ## _err_stack_g
#define H5VL_ERR_STACK_NAME_CONC(name) H5VL_ERR_STACK_NAME(name)
#define H5VL_ERR_STACK_g H5VL_ERR_STACK_NAME_CONC(H5VL_ERR_NAME)
#define H5VL_ERR_CLS_NAME(name) __H5VL ## name ## _err_cls_g
#define H5VL_ERR_CLS_NAME_CONC(name) H5VL_ERR_CLS_NAME(name)
#define H5VL_ERR_CLS_g H5VL_ERR_CLS_NAME_CONC(H5VL_ERR_NAME)
/**
* Macro to print out the VOL connector's current error stack
* and then clear it for future use
*/
#define HERROR_DUMP_STACK(err_stack) do { \
H5E_auto2_t func; \
/* Check whether automatic error reporting has been disabled */ \
H5Eget_auto2(H5E_DEFAULT, &func, NULL); \
if(func && (err_stack > 0) && (H5Eget_num(err_stack) > 0)) { \
H5Eprint2(err_stack, NULL); \
H5Eclear2(err_stack); \
} \
} while(0)
/**
* Use this macro when entering a VOL connector function.
*/
#define FUNC_ENTER_VOL(type, init) \
type __ret_value = init; \
hbool_t __err_occurred = FALSE;
/**
* Use this macro when leaving a VOL connector function.
*/
#define FUNC_LEAVE_VOL_NAME(name) \
if(__err_occurred) \
HERROR_DUMP_STACK(H5VL_ERR_STACK_NAME(name)); \
return __ret_value;
#define FUNC_LEAVE_VOL \
FUNC_LEAVE_VOL_NAME(H5VL_ERR_NAME)
/**
* Use this macro to set return value.
*/
#define FUNC_RETURN_SET(ret) \
(__ret_value = ret)
/**
* Use this macro to test for error.
*/
#define FUNC_ERRORED \
(__err_occurred == TRUE)
/**
* HERROR macro, used to facilitate error reporting between a FUNC_ENTER()
* and a FUNC_LEAVE() within a function body. The arguments are the major
* error number, the minor error number, and a description of the error.
*/
#define HERROR(err_stack, err_cls, maj_id, min_id, ...) do { \
H5E_auto2_t func; \
/* Check whether automatic error reporting has been disabled */ \
H5Eget_auto2(H5E_DEFAULT, &func, NULL); \
if(func && err_stack > 0 && err_cls > 0) { \
H5Epush2(err_stack, __FILE__, __func__, __LINE__, \
err_cls, maj_id, min_id, __VA_ARGS__); \
} \
} while(0)
/**
* HCOMMON_ERROR macro, used by HDONE_ERROR and HGOTO_ERROR
* (Shouldn't need to be used outside this header file)
*/
#define HCOMMON_ERROR_NAME(name, maj, min, ...) do { \
HERROR(H5VL_ERR_STACK_NAME(name), \
H5VL_ERR_CLS_NAME(name), \
maj, min, __VA_ARGS__); \
__err_occurred = TRUE; \
} while(0)
#define HCOMMON_ERROR(maj, min, ...) \
HCOMMON_ERROR_NAME(H5VL_ERR_NAME, maj, min, __VA_ARGS__)
/**
* HDONE_ERROR macro, used to facilitate error reporting between a
* FUNC_ENTER() and a FUNC_LEAVE() within a function body, but _AFTER_ the
* "done:" label. The arguments are
* the major error number, the minor error number, a return value, and a
* description of the error.
* (This macro can also be used to push an error and set the return value
* without jumping to any labels)
*/
#define HDONE_ERROR(maj, min, ret_val, ...) do { \
HCOMMON_ERROR(maj, min, __VA_ARGS__); \
__ret_value = ret_val; \
} while(0)
/**
* HGOTO_ERROR macro, used to facilitate error reporting between a
* FUNC_ENTER() and a FUNC_LEAVE() within a function body. The arguments are
* the major error number, the minor error number, the return value, and an
* error string. The return value is assigned to a variable `ret_value' and
* control branches to the `done' label.
*/
#define HGOTO_ERROR(maj, min, ret_val, ...) do { \
HCOMMON_ERROR(maj, min, __VA_ARGS__); \
HGOTO_DONE(ret_val); \
} while(0)
/**
* HGOTO_DONE macro, used to facilitate normal return between a FUNC_ENTER()
* and a FUNC_LEAVE() within a function body. The argument is the return
* value which is assigned to the `ret_value' variable. Control branches to
* the `done' label.
*/
#define HGOTO_DONE(ret_val) do { \
__ret_value = ret_val; \
goto done; \
} while(0)
#endif /* H5VLerror_H */