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 files COPYING and Copyright.html.  COPYING can be found at the root   *
9  * of the source code distribution tree; Copyright.html can be found at the  *
10  * root level of an installed copy of the electronic HDF5 document set and   *
11  * is linked from the top-level documents page.  It can also be found at     *
12  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
13  * access to either file, you may request a copy from help@hdfgroup.org.     *
14  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /*
17  *  Header file for error values, etc.
18  */
19 #ifndef _H5Eprivate_H
20 #define _H5Eprivate_H
21 
22 #include "H5Epublic.h"
23 
24 /* Private headers needed by this file */
25 #include "H5private.h"
26 
27 /* Typedef for error stack (defined in H5Epkg.h) */
28 typedef struct H5E_t H5E_t;
29 
30 /*
31  * HERROR macro, used to facilitate error reporting between a FUNC_ENTER()
32  * and a FUNC_LEAVE() within a function body.  The arguments are the major
33  * error number, the minor error number, and a description of the error.
34  */
35 #if defined(_MSC_VER) && (_MSC_VER < 1400)
36 #  define HERROR(maj_id, min_id, args) H5E_printf_stack(NULL, __FILE__, FUNC, __LINE__, H5E_ERR_CLS_g, maj_id, min_id, args)
37 #else
38 #  define HERROR(maj_id, min_id, ...) H5E_printf_stack(NULL, __FILE__, FUNC, __LINE__, H5E_ERR_CLS_g, maj_id, min_id, __VA_ARGS__)
39 #endif
40 
41 /*
42  * HCOMMON_ERROR macro, used by HDONE_ERROR and HGOTO_ERROR
43  * (Shouldn't need to be used outside this header file)
44  */
45 #if defined(_MSC_VER) && (_MSC_VER < 1400)
46 #define HCOMMON_ERROR(maj, min, args)                        \
47    HERROR(maj, min, args);                  \
48    err_occurred = TRUE;
49 #else
50 #define HCOMMON_ERROR(maj, min, ...)                        \
51    HERROR(maj, min, __VA_ARGS__);                  \
52    err_occurred = TRUE;                                                       \
53    err_occurred = err_occurred;         /* Shut GCC warnings up! */
54 #endif
55 
56 /*
57  * HDONE_ERROR macro, used to facilitate error reporting between a
58  * FUNC_ENTER() and a FUNC_LEAVE() within a function body, but _AFTER_ the
59  * "done:" label.  The arguments are
60  * the major error number, the minor error number, a return value, and a
61  * description of the error.
62  * (This macro can also be used to push an error and set the return value
63  *      without jumping to any labels)
64  */
65 #if defined(_MSC_VER) && (_MSC_VER < 1400)
66 #define HDONE_ERROR(maj, min, ret_val, args) {              \
67    HCOMMON_ERROR(maj, min, args);                \
68    ret_value = ret_val;                                                       \
69 }
70 #else
71 #define HDONE_ERROR(maj, min, ret_val, ...) {              \
72    HCOMMON_ERROR(maj, min, __VA_ARGS__);                \
73    ret_value = ret_val;                                                       \
74 }
75 #endif
76 
77 /*
78  * HGOTO_ERROR macro, used to facilitate error reporting between a
79  * FUNC_ENTER() and a FUNC_LEAVE() within a function body.  The arguments are
80  * the major error number, the minor error number, the return value, and an
81  * error string.  The return value is assigned to a variable `ret_value' and
82  * control branches to the `done' label.
83  */
84 #if defined(_MSC_VER) && (_MSC_VER < 1400)
85 #define HGOTO_ERROR(maj, min, ret_val, args) {              \
86    HCOMMON_ERROR(maj, min, args);                \
87    HGOTO_DONE(ret_val)                          \
88 }
89 #else
90 #define HGOTO_ERROR(maj, min, ret_val, ...) {              \
91    HCOMMON_ERROR(maj, min, __VA_ARGS__);                \
92    HGOTO_DONE(ret_val)                          \
93 }
94 #endif
95 
96 /*
97  * HGOTO_DONE macro, used to facilitate normal return between a FUNC_ENTER()
98  * and a FUNC_LEAVE() within a function body. The argument is the return
99  * value which is assigned to the `ret_value' variable.   Control branches to
100  * the `done' label.
101  */
102 #define HGOTO_DONE(ret_val) {ret_value = ret_val; goto done;}
103 
104 /* Library-private functions defined in H5E package */
105 H5_DLL herr_t H5E_init(void);
106 H5_DLL herr_t H5E_push_stack(H5E_t *estack, const char *file, const char *func,
107     unsigned line, hid_t cls_id, hid_t maj_id, hid_t min_id, const char *desc);
108 H5_DLL herr_t H5E_printf_stack(H5E_t *estack, const char *file, const char *func,
109     unsigned line, hid_t cls_id, hid_t maj_id, hid_t min_id, const char *fmt, ...);
110 H5_DLL herr_t H5E_clear_stack(H5E_t *estack);
111 H5_DLL herr_t H5E_dump_api_stack(int is_api);
112 
113 /*
114  * Macros handling system error messages as described in C standard.
115  * These macros assume errnum is a valid system error code.
116  */
117 
118 /* Retrieve the error code description string and push it onto the error
119  * stack.
120  */
121 #define  HSYS_DONE_ERROR(majorcode, minorcode, retcode, str) {          \
122     int myerrno = errno;                    \
123     HDONE_ERROR(majorcode, minorcode, retcode, "%s, errno = %d, error message = '%s'", str, myerrno, HDstrerror(myerrno));            \
124 }
125 #define  HSYS_GOTO_ERROR(majorcode, minorcode, retcode, str) {          \
126     int myerrno = errno;                    \
127     HGOTO_ERROR(majorcode, minorcode, retcode, "%s, errno = %d, error message = '%s'", str, myerrno, HDstrerror(myerrno));            \
128 }
129 
130 #ifdef H5_HAVE_PARALLEL
131 /*
132  * MPI error handling macros.
133  */
134 
135 extern  char  H5E_mpi_error_str[MPI_MAX_ERROR_STRING];
136 extern  int  H5E_mpi_error_str_len;
137 
138 #define  HMPI_ERROR(mpierr){                  \
139     MPI_Error_string(mpierr, H5E_mpi_error_str, &H5E_mpi_error_str_len);      \
140     HERROR(H5E_INTERNAL, H5E_MPIERRSTR, H5E_mpi_error_str);                   \
141 }
142 #define  HMPI_DONE_ERROR(retcode, str, mpierr){              \
143     HMPI_ERROR(mpierr);                    \
144     HDONE_ERROR(H5E_INTERNAL, H5E_MPI, retcode, str);            \
145 }
146 #define  HMPI_GOTO_ERROR(retcode, str, mpierr){              \
147     HMPI_ERROR(mpierr);                    \
148     HGOTO_ERROR(H5E_INTERNAL, H5E_MPI, retcode, str);            \
149 }
150 #endif /* H5_HAVE_PARALLEL */
151 
152 #endif /* _H5Eprivate_H */
153 
154