2009-09-15 03:52:42 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:36 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2009-09-15 03:52:42 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Header file for error values, etc.
|
|
|
|
*/
|
2021-03-04 20:29:10 +08:00
|
|
|
#ifndef H5TOOLS_ERROR_H
|
|
|
|
#define H5TOOLS_ERROR_H
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
#include "H5Epublic.h"
|
2019-11-07 23:48:56 +08:00
|
|
|
#include "H5Eprivate.h" /* Error handling */
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/* tools-HDF5 Error variables */
|
2020-09-30 22:27:10 +08:00
|
|
|
H5TOOLS_DLLVAR int H5tools_INDENT_g;
|
2012-03-13 00:33:15 +08:00
|
|
|
H5TOOLS_DLLVAR hid_t H5tools_ERR_STACK_g;
|
2010-05-12 04:10:25 +08:00
|
|
|
H5TOOLS_DLLVAR hid_t H5tools_ERR_CLS_g;
|
|
|
|
H5TOOLS_DLLVAR hid_t H5E_tools_g;
|
|
|
|
H5TOOLS_DLLVAR hid_t H5E_tools_min_id_g;
|
2019-11-07 23:48:56 +08:00
|
|
|
H5TOOLS_DLLVAR hid_t H5E_tools_min_info_id_g;
|
|
|
|
H5TOOLS_DLLVAR hid_t H5E_tools_min_dbg_id_g;
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* H5TOOLS_INIT_ERROR macro, used to initialize error reporting.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_INIT_ERROR() \
|
|
|
|
do { \
|
|
|
|
char lib_str[256]; \
|
|
|
|
\
|
|
|
|
/* Initialize library version string for error class */ \
|
2023-09-16 06:13:18 +08:00
|
|
|
snprintf(lib_str, sizeof(lib_str), "%d.%d.%d", H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Create new HDF5 error stack for the tools to use */ \
|
|
|
|
if ((H5tools_ERR_STACK_g = H5Ecreate_stack()) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to create HDF5 tools error stack\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Register errors from the HDF5 tools as a new error class */ \
|
|
|
|
if ((H5tools_ERR_CLS_g = H5Eregister_class("H5tools", "HDF5:tools", lib_str)) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to register HDF5 tools error class\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Create a new HDF5 major error message for errors from the tools library */ \
|
|
|
|
if ((H5E_tools_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MAJOR, "Failure in tools library")) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to register major error message for tools library errors\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Create a new HDF5 minor error message for errors from the tools library */ \
|
|
|
|
if ((H5E_tools_min_id_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MINOR, "error in function")) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to register minor error message for tools library errors\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Create a new HDF5 minor error message for info messages from the tools library */ \
|
|
|
|
if ((H5E_tools_min_info_id_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MINOR, "function info")) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to register minor error message for tools library info messages\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Create a new HDF5 minor error message for debug messages from the tools library */ \
|
|
|
|
if ((H5E_tools_min_dbg_id_g = H5Ecreate_msg(H5tools_ERR_CLS_g, H5E_MINOR, "function debug")) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to register minor error message for tools library debug messages\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
} while (0)
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/*
|
2019-12-28 13:02:26 +08:00
|
|
|
* H5TOOLS_CLOSE_ERROR macro, used to terminate error reporting.
|
2009-09-15 03:52:42 +08:00
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_CLOSE_ERROR() \
|
|
|
|
do { \
|
|
|
|
/* Close all error messages created by H5TOOLS_INIT_ERROR() */ \
|
|
|
|
if (H5Eclose_msg(H5E_tools_min_dbg_id_g) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to close minor error message for tools library debug messages\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Eclose_msg(H5E_tools_min_info_id_g) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to close minor error message for tools library info messages\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Eclose_msg(H5E_tools_min_id_g) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to close minor error message for tools library errors\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Eclose_msg(H5E_tools_g) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to close major error message for tools library errors\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Unregister the HDF5 tools error class */ \
|
|
|
|
if (H5Eunregister_class(H5tools_ERR_CLS_g) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to unregister the HDF5 tools error class\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
\
|
|
|
|
/* Close the tools error stack */ \
|
|
|
|
if (H5Eclose_stack(H5tools_ERR_STACK_g) < 0) \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "Failed to close HDF5 tools error stack\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
} while (0)
|
2009-09-15 03:52:42 +08:00
|
|
|
|
2019-11-07 23:48:56 +08:00
|
|
|
/*
|
2019-12-28 13:02:26 +08:00
|
|
|
* H5TOOLS_PUSH_ERROR macro, used to push an error to an error stack. Not meant to
|
|
|
|
* be called directly.
|
2019-11-07 23:48:56 +08:00
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_PUSH_ERROR(estack_id, err_cls, maj_err_id, min_err_id, ...) \
|
|
|
|
do { \
|
|
|
|
if (enable_error_stack > 0) { \
|
|
|
|
if (estack_id >= 0 && err_cls >= 0) \
|
2021-06-29 12:58:38 +08:00
|
|
|
H5Epush2(estack_id, __FILE__, __func__, __LINE__, err_cls, maj_err_id, min_err_id, \
|
|
|
|
__VA_ARGS__); \
|
2020-09-30 22:27:10 +08:00
|
|
|
else { \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
fprintf(stderr, "\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2019-11-07 23:48:56 +08:00
|
|
|
|
|
|
|
/*
|
2019-12-28 13:02:26 +08:00
|
|
|
* H5TOOLS_ERROR macro, used to facilitate error reporting within a function body.
|
|
|
|
* The arguments are the return value and an error string. The return value is assigned
|
|
|
|
* to a variable `ret_value'. This macro is meant to be used for reporting an error without
|
|
|
|
* having control branch to the `done' label. This is often used when an error occurs
|
|
|
|
* after the `done' label, in which case an infinite loop would ensue if control branched
|
|
|
|
* backwards.
|
2017-09-01 04:58:37 +08:00
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_ERROR(ret_val, ...) \
|
|
|
|
do { \
|
|
|
|
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, \
|
|
|
|
__VA_ARGS__); \
|
|
|
|
ret_value = ret_val; \
|
|
|
|
} while (0)
|
2017-09-01 04:58:37 +08:00
|
|
|
|
2009-09-15 03:52:42 +08:00
|
|
|
/*
|
2019-12-28 13:02:26 +08:00
|
|
|
* H5TOOLS_GOTO_ERROR macro, used to facilitate error reporting within a function body.
|
|
|
|
* The arguments are the return value and an error string. The return value is assigned
|
|
|
|
* to a variable `ret_value' and control branches to the `done' label.
|
2009-09-15 03:52:42 +08:00
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_GOTO_ERROR(ret_val, ...) \
|
|
|
|
do { \
|
|
|
|
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, \
|
|
|
|
__VA_ARGS__); \
|
|
|
|
H5TOOLS_GOTO_DONE(ret_val); \
|
|
|
|
} while (0)
|
2019-12-28 13:02:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* H5TOOLS_GOTO_DONE macro, used to facilitate normal return within a function body.
|
|
|
|
* The argument is the return value which is assigned to the `ret_value'
|
|
|
|
* variable. Control branches to the `done' label.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_GOTO_DONE(ret_val) \
|
|
|
|
do { \
|
|
|
|
ret_value = ret_val; \
|
|
|
|
goto done; \
|
|
|
|
} while (0)
|
2019-12-28 13:02:26 +08:00
|
|
|
|
2019-12-28 16:16:44 +08:00
|
|
|
/*
|
|
|
|
* H5TOOLS_GOTO_DONE_NO_RET macro, used to facilitate normal return within a function body.
|
|
|
|
* Control simply branches to the `done' label without setting any return value.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_GOTO_DONE_NO_RET() \
|
|
|
|
do { \
|
|
|
|
goto done; \
|
|
|
|
} while (0)
|
2019-12-28 16:16:44 +08:00
|
|
|
|
2019-12-28 13:02:26 +08:00
|
|
|
/*
|
|
|
|
* H5TOOLS_INFO macro, used to facilitate error reporting. The arguments are
|
|
|
|
* a description of the error.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_INFO(...) \
|
|
|
|
do { \
|
|
|
|
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_info_id_g, \
|
|
|
|
__VA_ARGS__); \
|
|
|
|
} while (0)
|
2019-12-28 13:02:26 +08:00
|
|
|
|
|
|
|
#ifdef H5_TOOLS_DEBUG
|
2019-12-28 16:16:44 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_START_DEBUG(...) \
|
|
|
|
do { \
|
|
|
|
H5tools_INDENT_g += 2; \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "%*sENTER %s:%d in %s()...", H5tools_INDENT_g, "", __FILE__, __LINE__, __func__); \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
fprintf(stderr, "\n"); \
|
2023-06-29 23:19:31 +08:00
|
|
|
fflush(stderr); \
|
2020-09-30 22:27:10 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define H5TOOLS_DEBUG(...) \
|
|
|
|
do { \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "%*s %s:%d in %s()...", H5tools_INDENT_g, "", __FILE__, __LINE__, __func__); \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
fprintf(stderr, "\n"); \
|
2023-06-29 23:19:31 +08:00
|
|
|
fflush(stderr); \
|
2020-09-30 22:27:10 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define H5TOOLS_ENDDEBUG(...) \
|
|
|
|
do { \
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "%*sEXIT %s:%d in %s()...", H5tools_INDENT_g, "", __FILE__, __LINE__, __func__); \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
fprintf(stderr, "\n"); \
|
2020-09-30 22:27:10 +08:00
|
|
|
H5tools_INDENT_g -= 2; \
|
2023-06-29 23:19:31 +08:00
|
|
|
fflush(stderr); \
|
2020-09-30 22:27:10 +08:00
|
|
|
} while (0)
|
2019-12-28 16:16:44 +08:00
|
|
|
|
2019-12-28 13:02:26 +08:00
|
|
|
#else
|
2019-12-28 16:16:44 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_START_DEBUG(...) \
|
|
|
|
do { \
|
|
|
|
; \
|
|
|
|
} while (0)
|
2019-12-28 16:16:44 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_DEBUG(...) \
|
|
|
|
do { \
|
|
|
|
; \
|
|
|
|
} while (0)
|
2019-12-28 16:16:44 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_ENDDEBUG(...) \
|
|
|
|
do { \
|
|
|
|
; \
|
|
|
|
} while (0)
|
2019-12-28 16:16:44 +08:00
|
|
|
|
2019-12-28 13:02:26 +08:00
|
|
|
#endif
|
2012-03-13 00:33:15 +08:00
|
|
|
|
2009-09-15 03:52:42 +08:00
|
|
|
/* Macro for "catching" flow of control when an error occurs. Note that the
|
|
|
|
* H5_LEAVE macro won't jump back here once it's past this point.
|
|
|
|
*/
|
2021-05-29 10:58:13 +08:00
|
|
|
#define CATCH \
|
|
|
|
catch_except:; \
|
2023-09-06 02:50:06 +08:00
|
|
|
past_catch = true;
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/*
|
2021-05-29 10:58:13 +08:00
|
|
|
* H5_LEAVE macro, used to facilitate control flow in a function. The argument
|
|
|
|
* is the return value. The return value is assigned to a variable `ret_value'
|
|
|
|
* and control branches to the `catch_except' label, if we're not already past
|
|
|
|
* it.
|
2009-09-15 03:52:42 +08:00
|
|
|
*/
|
2021-05-29 10:58:13 +08:00
|
|
|
#define H5_LEAVE(v) \
|
2023-07-25 05:18:04 +08:00
|
|
|
do { \
|
2021-05-29 10:58:13 +08:00
|
|
|
ret_value = v; \
|
|
|
|
if (!past_catch) \
|
|
|
|
goto catch_except; \
|
2023-07-25 05:18:04 +08:00
|
|
|
} while (0)
|
2009-09-15 03:52:42 +08:00
|
|
|
|
|
|
|
/*
|
2019-11-07 23:48:56 +08:00
|
|
|
* H5TOOLS_THROW macro, used to facilitate error reporting within a function body.
|
2009-09-15 03:52:42 +08:00
|
|
|
* The arguments are the minor error number, and an error string.
|
|
|
|
* The return value is assigned to a variable `ret_value' and control branches
|
|
|
|
* to the `catch_except' label, if we're not already past it.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define H5TOOLS_THROW(ret_val, ...) \
|
|
|
|
do { \
|
|
|
|
H5TOOLS_PUSH_ERROR(H5tools_ERR_STACK_g, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, \
|
|
|
|
__VA_ARGS__); \
|
2023-07-25 05:18:04 +08:00
|
|
|
H5_LEAVE(ret_val); \
|
2020-09-30 22:27:10 +08:00
|
|
|
} while (0)
|
2009-09-15 03:52:42 +08:00
|
|
|
|
2021-03-04 20:29:10 +08:00
|
|
|
#endif /* H5TOOLS_ERROR_H */
|