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, str) H5E_push_stack(NULL, __FILE__, FUNC, __LINE__, H5E_ERR_CLS_g, maj_id, min_id, str)
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, str)                                          \
00042    HERROR(maj, min, str);                                                     \
00043    (void)H5E_dump_api_stack((int)H5_IS_API(FUNC));
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, str) {                                 \
00055    HCOMMON_ERROR(maj, min, str);                                              \
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, str) {                                 \
00067    HCOMMON_ERROR(maj, min, str);                                              \
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, unsigned line,
00082                             hid_t cls_id, hid_t maj_id, hid_t min_id, const char *desc);
00083 H5_DLL herr_t H5E_clear_stack(H5E_t *estack);
00084 H5_DLL herr_t H5E_dump_api_stack(int is_api);
00085 
00086 /*
00087  * Macros handling system error messages as described in C standard.
00088  * These macros assume errnum is a valid system error code.
00089  */
00090 
00091 /* Retrieve the error code description string and push it onto the error
00092  * stack.
00093  */
00094 #define HSYS_ERROR(errnum) {                                                  \
00095     HERROR(H5E_INTERNAL, H5E_SYSERRSTR, HDstrerror(errnum));                  \
00096 }
00097 #define HSYS_DONE_ERROR(majorcode, minorcode, retcode, str) {                 \
00098     HSYS_ERROR(errno);                                                        \
00099     HDONE_ERROR(majorcode, minorcode, retcode, str);                          \
00100 }
00101 #define HSYS_GOTO_ERROR(majorcode, minorcode, retcode, str) {                 \
00102     HSYS_ERROR(errno);                                                        \
00103     HGOTO_ERROR(majorcode, minorcode, retcode, str);                          \
00104 }
00105 
00106 #ifdef H5_HAVE_PARALLEL
00107 /*
00108  * MPI error handling macros.
00109  */
00110 
00111 extern  char    H5E_mpi_error_str[MPI_MAX_ERROR_STRING];
00112 extern  int     H5E_mpi_error_str_len;
00113 
00114 #define HMPI_ERROR(mpierr){                                                   \
00115     MPI_Error_string(mpierr, H5E_mpi_error_str, &H5E_mpi_error_str_len);      \
00116     HERROR(H5E_INTERNAL, H5E_MPIERRSTR, H5E_mpi_error_str);                   \
00117 }
00118 #define HMPI_DONE_ERROR(retcode, str, mpierr){                                \
00119     HMPI_ERROR(mpierr);                                                       \
00120     HDONE_ERROR(H5E_INTERNAL, H5E_MPI, retcode, str);                         \
00121 }
00122 #define HMPI_GOTO_ERROR(retcode, str, mpierr){                                \
00123     HMPI_ERROR(mpierr);                                                       \
00124     HGOTO_ERROR(H5E_INTERNAL, H5E_MPI, retcode, str);                         \
00125 }
00126 #endif /* H5_HAVE_PARALLEL */
00127 
00128 #endif /* _H5Eprivate_H */
00129