H5Eprivate.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  *  Header file for error values, etc.
00018  */
00019 #ifndef _H5Eprivate_H
00020 #define _H5Eprivate_H
00021 
00022 #include "H5Epublic.h"
00023 
00024 /* Private headers needed by this file */
00025 #include "H5private.h"
00026 
00027 /* Typedef for error stack (defined in H5Epkg.h) */
00028 typedef struct H5E_t H5E_t;
00029 
00030 /*
00031  * HERROR macro, used to facilitate error reporting between a FUNC_ENTER()
00032  * and a FUNC_LEAVE() within a function body.  The arguments are the major
00033  * error number, the minor error number, and a description of the error.
00034  */
00035 #define HERROR(maj_id, min_id, ...) H5E_printf_stack(NULL, __FILE__, FUNC, __LINE__, H5E_ERR_CLS_g, maj_id, min_id, __VA_ARGS__)
00036 
00037 /*
00038  * HCOMMON_ERROR macro, used by HDONE_ERROR and HGOTO_ERROR
00039  * (Shouldn't need to be used outside this header file)
00040  */
00041 #define HCOMMON_ERROR(maj, min, ...)                                          \
00042    HERROR(maj, min, __VA_ARGS__);                                                     \
00043    err_occurred = TRUE;
00044 
00045 /*
00046  * HDONE_ERROR macro, used to facilitate error reporting between a
00047  * FUNC_ENTER() and a FUNC_LEAVE() within a function body, but _AFTER_ the
00048  * "done:" label.  The arguments are
00049  * the major error number, the minor error number, a return value, and a
00050  * description of the error.
00051  * (This macro can also be used to push an error and set the return value
00052  *      without jumping to any labels)
00053  */
00054 #define HDONE_ERROR(maj, min, ret_val, ...) {                                 \
00055    HCOMMON_ERROR(maj, min, __VA_ARGS__);                                              \
00056    ret_value = ret_val;                                                       \
00057 }
00058 
00059 /*
00060  * HGOTO_ERROR macro, used to facilitate error reporting between a
00061  * FUNC_ENTER() and a FUNC_LEAVE() within a function body.  The arguments are
00062  * the major error number, the minor error number, the return value, and an
00063  * error string.  The return value is assigned to a variable `ret_value' and
00064  * control branches to the `done' label.
00065  */
00066 #define HGOTO_ERROR(maj, min, ret_val, ...) {                                 \
00067    HCOMMON_ERROR(maj, min, __VA_ARGS__);                                              \
00068    HGOTO_DONE(ret_val)                                                        \
00069 }
00070 
00071 /*
00072  * HGOTO_DONE macro, used to facilitate normal return between a FUNC_ENTER()
00073  * and a FUNC_LEAVE() within a function body. The argument is the return
00074  * value which is assigned to the `ret_value' variable.  Control branches to
00075  * the `done' label.
00076  */
00077 #define HGOTO_DONE(ret_val) {ret_value = ret_val; goto done;}
00078 
00079 /* Library-private functions defined in H5E package */
00080 H5_DLL herr_t H5E_init(void);
00081 H5_DLL herr_t H5E_push_stack(H5E_t *estack, const char *file, const char *func,
00082     unsigned line, hid_t cls_id, hid_t maj_id, hid_t min_id, const char *desc);
00083 H5_DLL herr_t H5E_printf_stack(H5E_t *estack, const char *file, const char *func,
00084     unsigned line, hid_t cls_id, hid_t maj_id, hid_t min_id, const char *fmt, ...);
00085 H5_DLL herr_t H5E_clear_stack(H5E_t *estack);
00086 H5_DLL herr_t H5E_dump_api_stack(int is_api);
00087 
00088 /*
00089  * Macros handling system error messages as described in C standard.
00090  * These macros assume errnum is a valid system error code.
00091  */
00092 
00093 /* Retrieve the error code description string and push it onto the error
00094  * stack.
00095  */
00096 #define HSYS_DONE_ERROR(majorcode, minorcode, retcode, str) {                 \
00097     int myerrno = errno;                                                              \
00098     HDONE_ERROR(majorcode, minorcode, retcode, "%s, errno = %d, error message = '%s'", str, myerrno, HDstrerror(myerrno));                            \
00099 }
00100 #define HSYS_GOTO_ERROR(majorcode, minorcode, retcode, str) {                 \
00101     int myerrno = errno;                                                              \
00102     HGOTO_ERROR(majorcode, minorcode, retcode, "%s, errno = %d, error message = '%s'", str, myerrno, HDstrerror(myerrno));                            \
00103 }
00104 
00105 #ifdef H5_HAVE_PARALLEL
00106 /*
00107  * MPI error handling macros.
00108  */
00109 
00110 extern  char    H5E_mpi_error_str[MPI_MAX_ERROR_STRING];
00111 extern  int     H5E_mpi_error_str_len;
00112 
00113 #define HMPI_ERROR(mpierr){                                                   \
00114     MPI_Error_string(mpierr, H5E_mpi_error_str, &H5E_mpi_error_str_len);      \
00115     HERROR(H5E_INTERNAL, H5E_MPIERRSTR, H5E_mpi_error_str);                   \
00116 }
00117 #define HMPI_DONE_ERROR(retcode, str, mpierr){                                \
00118     HMPI_ERROR(mpierr);                                                       \
00119     HDONE_ERROR(H5E_INTERNAL, H5E_MPI, retcode, str);                         \
00120 }
00121 #define HMPI_GOTO_ERROR(retcode, str, mpierr){                                \
00122     HMPI_ERROR(mpierr);                                                       \
00123     HGOTO_ERROR(H5E_INTERNAL, H5E_MPI, retcode, str);                         \
00124 }
00125 #endif /* H5_HAVE_PARALLEL */
00126 
00127 #endif /* _H5Eprivate_H */
00128