[svn-r7298] Purpose:

Code cleanup & bug fix

Description:
    Refactor code to clean up

    Corrected several bugs, including problems with library termination and
        thread-safete, etc.

Platforms tested:
    h5committested
This commit is contained in:
Quincey Koziol 2003-08-08 13:52:00 -05:00
parent 1186c0b7fa
commit 7255ce7c07
3 changed files with 842 additions and 535 deletions

1298
src/H5E.c

File diff suppressed because it is too large Load Diff

View File

@ -28,24 +28,24 @@
/* Error class */
typedef struct H5E_cls_t {
char *cls_name;
char *lib_name;
char *lib_vers;
char *cls_name; /* Name of error class */
char *lib_name; /* Name of library within class */
char *lib_vers; /* Version of library */
} H5E_cls_t;
/* Major or minor message */
typedef struct H5E_msg_t {
char *msg;
H5E_type_t type;
H5E_cls_t *cls;
char *msg; /* Message for error */
H5E_type_t type; /* Type of error (major or minor) */
H5E_cls_t *cls; /* Which error class this message belongs to */
} H5E_msg_t;
/* Error stack */
typedef struct H5E_t {
int nused; /*num slots currently used in stack */
H5E_error_t slot[32]; /*array of error records */
H5E_auto_t func;
void *auto_data;
size_t nused; /* Num slots currently used in stack */
H5E_error_t slot[H5E_NSLOTS]; /* Array of error records */
H5E_auto_t func; /* Function for 'automatic' error reporting */
void *auto_data; /* Callback data for 'automatic error reporting */
} H5E_t;
/* Printing information */
@ -60,7 +60,6 @@ typedef struct H5E_print_t {
#define H5E_CLS_LIB_VERS "" /* How to find out version number? */
/* HDF5 error class: major errors */
#define H5E_NONE_MAJOR_MSG "No error"
#define H5E_MAJ_ARGS_MSG "Function arguments"
#define H5E_MAJ_RESOURCE_MSG "Resource unavailable"
#define H5E_MAJ_INTERNAL_MSG "Internal HDF5 error"
@ -91,7 +90,6 @@ typedef struct H5E_print_t {
/* HDF5 error class: minor errors */
/* Argument errors */
#define H5E_NONE_MINOR_MSG "No error"
#define H5E_MIN_UNINITIALIZED_MSG "Information is uninitialized"
#define H5E_MIN_UNSUPPORTED_MSG "Feature is unsupported"
#define H5E_MIN_BADTYPE_MSG "Inappropriate type"
@ -202,44 +200,20 @@ typedef struct H5E_print_t {
#define H5E_MIN_CANAPPLY_MSG "Error from filter \"can apply\" callback"
#define H5E_MIN_SETLOCAL_MSG "Error from filter \"set local\" callback"
#ifdef H5_HAVE_THREADSAFE
/*
* The per-thread error stack. pthread_once() initializes a special
* key that will be used by all threads to create a stack specific to
* each thread individually. The association of stacks to threads will
* be handled by the pthread library.
*
* In order for this macro to work, H5E_get_my_stack() must be preceeded
* by "H5E_t *estack =".
*/
H5E_t * H5E_get_stack(void);
#define H5E_get_my_stack() H5E_get_stack()
#else /* H5_HAVE_THREADSAFE */
/*
* The current error stack. Eventually we'll have some sort of global table
* so each thread has it's own stack. The stacks will be created on demand
* when the thread first calls H5E_push(). */
H5_DLLVAR H5E_t H5E_stack_g[1];
#define H5E_get_my_stack() (H5E_stack_g+0)
#endif /* H5_HAVE_THREADSAFE */
/*
* 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(maj_id, min_id, str) H5E_push(H5E_get_my_stack(), __FILE__, FUNC, __LINE__, H5E_ERR_CLS_g, maj_id, min_id, str)
#define HERROR(maj_id, min_id, str) H5E_push(NULL, __FILE__, FUNC, __LINE__, H5E_ERR_CLS_g, maj_id, min_id, str)
/*
* HCOMMON_ERROR macro, used by HDONE_ERROR and HGOTO_ERROR
* (Shouldn't need to be used outside this header file)
*/
#define HCOMMON_ERROR(maj, min, str) \
H5E_t *estack = H5E_get_my_stack(); \
HERROR(maj, min, str); \
/*fprintf(stderr, "HCOMMON_ERROR: estack->func=%p\n", estack->func);*/ \
if (H5_IS_API(FUNC) && estack->auto_data) \
(void)((estack->func)(H5E_DEFAULT, estack->auto_data))
H5E_dump_api_stack(H5_IS_API(FUNC));
/*
* HDONE_ERROR macro, used to facilitate error reporting between a
@ -247,6 +221,8 @@ H5_DLLVAR H5E_t H5E_stack_g[1];
* "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, str) { \
HCOMMON_ERROR (maj, min, str); \
@ -293,6 +269,7 @@ H5_DLL herr_t H5E_walk (H5E_t *estack, H5E_direction_t direction, H5E_walk_t fu
void *client_data);
H5_DLL herr_t H5E_get_auto(H5E_t *estack, H5E_auto_t *func, void **client_data);
H5_DLL herr_t H5E_set_auto(H5E_t *estack, H5E_auto_t func, void *client_data);
H5_DLL herr_t H5E_dump_api_stack(int is_api);
#ifdef H5_HAVE_PARALLEL
/*

View File

@ -24,7 +24,10 @@
#include "H5public.h"
#include "H5Ipublic.h"
/* Value for the default error stack */
#define H5E_DEFAULT 0
/* Limit of error strings recorded */
#define H5E_LEN 128
/* Take out _new later */
@ -59,7 +62,6 @@ typedef struct H5E_error_t {
H5_DLLVAR hid_t H5E_ERR_CLS_g;
/* HDF5 error class: major errors. */
#define H5E_NONE_MAJOR (H5OPEN H5E_NONE_MAJOR_g)
#define H5E_ARGS (H5OPEN H5E_ARGS_g)
#define H5E_RESOURCE (H5OPEN H5E_RESOURCE_g)
#define H5E_INTERNAL (H5OPEN H5E_INTERNAL_g)
@ -88,7 +90,6 @@ H5_DLLVAR hid_t H5E_ERR_CLS_g;
#define H5E_RS (H5OPEN H5E_RS_g)
#define H5E_ERROR (H5OPEN H5E_ERROR_g)
H5_DLLVAR hid_t H5E_NONE_MAJOR_g; /*special zero, no error */
H5_DLLVAR hid_t H5E_ARGS_g; /*invalid arguments to routine */
H5_DLLVAR hid_t H5E_RESOURCE_g; /*resource unavailable */
H5_DLLVAR hid_t H5E_INTERNAL_g; /*Internal error (too specific to document in detail) */
@ -119,14 +120,12 @@ H5_DLLVAR hid_t H5E_ERROR_g; /*Error API */
/* HDF5 error class: minor errors. */
/* Argument errors */
#define H5E_NONE_MINOR (H5OPEN H5E_NONE_MINOR_g)
#define H5E_UNINITIALIZED (H5OPEN H5E_UNINITIALIZED_g)
#define H5E_UNSUPPORTED (H5OPEN H5E_UNSUPPORTED_g)
#define H5E_BADTYPE (H5OPEN H5E_BADTYPE_g)
#define H5E_BADRANGE (H5OPEN H5E_BADRANGE_g)
#define H5E_BADVALUE (H5OPEN H5E_BADVALUE_g)
H5_DLLVAR hid_t H5E_NONE_MINOR_g; /*special zero, no error */
H5_DLLVAR hid_t H5E_UNINITIALIZED_g; /*information is unitialized */
H5_DLLVAR hid_t H5E_UNSUPPORTED_g; /*feature is unsupported */
H5_DLLVAR hid_t H5E_BADTYPE_g; /*incorrect type found */
@ -354,22 +353,22 @@ H5_DLLVAR hid_t H5E_SETLOCAL_g; /*error from filter "set loc
* Public API Convenience Macros for Error reporting - Documented
*/
/* Use the Standard C __FILE__ & __LINE__ macros instead of typing them in */
#define H5Epush_sim(func,maj,min,str) H5Epush(H5E_DEFAULT,__FILE__,func,__LINE__,maj,min,str)
#define H5Epush_sim(func,cls,maj,min,str) H5Epush(H5E_DEFAULT,__FILE__,func,__LINE__,cls,maj,min,str)
/*
* Public API Convenience Macros for Error reporting - Undocumented
*/
/* Use the Standard C __FILE__ & __LINE__ macros instead of typing them in */
/* And return after pushing error onto stack */
#define H5Epush_ret(func,maj,min,str,ret) { \
H5Epush(H5E_DEFAULT,__FILE__,func,__LINE__,maj,min,str); \
#define H5Epush_ret(func,cls,maj,min,str,ret) { \
H5Epush(H5E_DEFAULT,__FILE__,func,__LINE__,cls,maj,min,str); \
return(ret); \
}
/* Use the Standard C __FILE__ & __LINE__ macros instead of typing them in */
/* And goto a label after pushing error onto stack */
#define H5Epush_goto(func,maj,min,str,label) { \
H5Epush(H5E_DEFAULT,__FILE__,func,__LINE__,maj,min,str); \
#define H5Epush_goto(func,cls,maj,min,str,label) { \
H5Epush(H5E_DEFAULT,__FILE__,func,__LINE__,cls,maj,min,str); \
goto label; \
}
@ -384,6 +383,11 @@ typedef enum H5E_direction_t {
extern "C" {
#endif
/* Error stack traversal callback function pointers */
typedef herr_t (*H5E_walk_t)(unsigned n, H5E_error_t *err_desc, void *client_data);
typedef herr_t (*H5E_auto_t)(hid_t estack, void *client_data);
/* Public API functions */
H5_DLL hid_t H5Eregister_class(const char *cls_name, const char *lib_name, const char *version);
H5_DLL herr_t H5Eunregister_class(hid_t class_id);
H5_DLL herr_t H5Eclose_msg(hid_t err_id);
@ -395,12 +399,10 @@ H5_DLL ssize_t H5Eget_msg(hid_t msg_id, H5E_type_t *type, char *msg, size_t size
H5_DLL int H5Eget_num(hid_t error_stack_id);
H5_DLL herr_t H5Eset_current_stack(hid_t err_stack_id);
H5_DLL herr_t H5Epush(hid_t err_stack, const char *file, const char *func, unsigned line,
hid_t maj_id, hid_t min_id, const char *msg, ...);
hid_t cls_id, hid_t maj_id, hid_t min_id, const char *msg, ...);
H5_DLL herr_t H5Epop(hid_t err_stack, size_t count);
H5_DLL herr_t H5Eclear(hid_t err_stack);
H5_DLL herr_t H5Eprint(hid_t err_stack, FILE *stream);
typedef herr_t (*H5E_walk_t)(int n, H5E_error_t *err_desc, void *client_data);
typedef herr_t (*H5E_auto_t)(hid_t estack, void *client_data);
H5_DLL herr_t H5Ewalk(hid_t err_stack, H5E_direction_t direction, H5E_walk_t func,
void *client_data);
H5_DLL herr_t H5Eget_auto(hid_t estack_id, H5E_auto_t *func, void **client_data);