diff options
-rw-r--r-- | src/H5E.c | 298 | ||||
-rw-r--r-- | src/H5Eprivate.h | 4 | ||||
-rw-r--r-- | src/H5Epublic.h | 5 | ||||
-rw-r--r-- | test/errors.c | 68 |
4 files changed, 356 insertions, 19 deletions
@@ -760,7 +760,7 @@ H5E_create_msg(hid_t cls_id, H5E_type_t msg_type, const char *msg) H5E_msg_t *msg_ptr; FUNC_ENTER_NOAPI(H5E_create_msg, FAIL); - + /* Check arguments */ assert(msg); @@ -991,6 +991,101 @@ done: /*------------------------------------------------------------------------- + * Function: H5Eset_current_stack + * + * Purpose: Replaces current stack with specified stack. + * + * Return: Non-negative value on success/Negative on failure + * + * Programmer: Raymond Lu + * Friday, July 15, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Eset_current_stack(hid_t err_stack_id) +{ + herr_t ret_value = SUCCEED; /* Return value */ + H5E_t_new *estack; + + FUNC_ENTER_API(H5Eset_current_stack, FAIL); + H5TRACE1("e","i",err_stack_id); + + /* Need to check for errors */ + if(err_stack_id == H5E_DEFAULT) + goto done; /*HGOTO_DONE(SUCCEED);*/ + else + estack = H5I_object_verify(err_stack_id, H5I_ERROR_STACK); + + /* Add HGOTO_ERROR later */ + ret_value=H5E_set_current_stack(estack); + +done: + FUNC_LEAVE_API(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5E_set_current_stack + * + * Purpose: Private function to replace an error stack. + * + * Return: Non-negative value on success/Negative on failure + * + * Programmer: Raymond Lu + * Friday, July 15, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5E_set_current_stack(H5E_t_new *estack) +{ + herr_t ret_value = SUCCEED; /* Return value */ + H5E_t_new *current_stack = H5E_get_my_stack_new(); + H5E_error_t_new *current_error, *new_error; + int i; + + FUNC_ENTER_NOAPI(H5E_get_current_stack, FAIL); + + /* Empty current error stack */ + for(i=0; i<current_stack->nused; i++) { + current_error = &(current_stack->slot[i]); + if(current_error->func_name) + H5MM_xfree(current_error->func_name); + if(current_error->file_name) + H5MM_xfree(current_error->file_name); + if(current_error->desc) + H5MM_xfree(current_error->desc); + } + HDmemset(current_stack->slot, 0, sizeof(H5E_error_t_new)*current_stack->nused); + current_stack->nused = 0; + + /* Copy new stack to current error stack */ + current_stack->nused = estack->nused; + for(i=0; i<current_stack->nused; i++) { + current_error = &(current_stack->slot[i]); + new_error = &(estack->slot[i]); + + /* Should we make copies of these IDs? */ + current_error->cls_id = new_error->cls_id; + current_error->maj_id = new_error->maj_id; + current_error->min_id = new_error->min_id; + current_error->func_name = HDstrdup(new_error->func_name); + current_error->file_name = HDstrdup(new_error->file_name); + current_error->line = new_error->line; + current_error->desc = HDstrdup(new_error->desc); + } + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + +/*------------------------------------------------------------------------- * Function: H5Eclose_stack * * Purpose: Closes an error stack. @@ -1073,6 +1168,207 @@ done: FUNC_LEAVE_NOAPI(ret_value); } + +/*------------------------------------------------------------------------- + * Function: H5Eget_num + * + * Purpose: Retrieves the number of error message. + * + * Return: Non-negative value on success/Negative on failure + * + * Programmer: Raymond Lu + * Friday, July 15, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +H5Eget_num(hid_t error_stack_id) +{ + int ret_value; /* Return value */ + H5E_t_new *estack; + + FUNC_ENTER_API(H5Eget_num, FAIL); + H5TRACE1("Is","i",error_stack_id); + + /* Need to check for errors */ + if(error_stack_id == H5E_DEFAULT) + estack = H5E_get_my_stack_new(); + else + estack = H5I_object_verify(error_stack_id, H5I_ERROR_STACK); + + /* Add HGOTO_ERROR later */ + ret_value=H5E_get_num(estack); + +done: + FUNC_LEAVE_API(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5E_get_num + * + * Purpose: Private function to retrieve number of errors in error stack. + * + * Return: Non-negative value on success/Negative on failure + * + * Programmer: Raymond Lu + * Friday, July 15, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +H5E_get_num(H5E_t_new *err_stack) +{ + int ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5E_get_num, FAIL); + + ret_value = err_stack->nused; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5Epush_new + * + * Purpose: Pushes a new error record onto error stack for the current + * thread. The error has major and minor IDs MAJ_ID and + * MIN_ID, the name of a function where the error was detected, + * the name of the file where the error was detected, the + * line within that file, and an error description string. The + * function name, file name, and error description strings must + * be statically allocated. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Monday, October 18, 1999 + * + * Notes: Basically a public API wrapper around the H5E_push function. + * + * Modifications: + * Raymond Lu + * Tuesday, July 15, 2003 + + * Added the ID of the error stack to which the error is pushed + * on. The error message can be appended more message in the + * same control format as printf and fprintf. + * + *------------------------------------------------------------------------- + */ +herr_t +H5Epush_new(hid_t err_stack, const char *file, const char *func, unsigned line, + hid_t maj_id, hid_t min_id, const char *fmt, ...) +{ + herr_t ret_value; + H5E_t_new *estack_ptr; + H5E_msg_t *maj_ptr, *min_ptr; + va_list ap; + hid_t cls_id; + char tmp[128]; + + FUNC_ENTER_API(H5Epush_new, FAIL); + H5TRACE7("e","issIuiis",err_stack,file,func,line,maj_id,min_id,fmt); + + /* Need to check for errors */ + if(err_stack == H5E_DEFAULT) + estack_ptr = H5E_get_my_stack_new(); + else + estack_ptr = H5I_object_verify(err_stack, H5I_ERROR_STACK); + + maj_ptr = H5I_object_verify(maj_id, H5I_ERROR_MSG); + min_ptr = H5I_object_verify(min_id, H5I_ERROR_MSG); + /* Error check later */ + if(maj_ptr->cls != min_ptr->cls) + ; + cls_id = H5I_register(H5I_ERROR_CLASS, maj_ptr->cls); + + va_start(ap, fmt); + vsnprintf(tmp, 128, fmt, ap); + va_end(ap); + + /* Should we make copies of maj_idm and min_id? */ + ret_value = H5E_push_new(estack_ptr, file, func, line, cls_id, maj_id, min_id, tmp); + +done: + FUNC_LEAVE_API(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5E_push_new + * + * Purpose: Pushes a new error record onto error stack for the current + * thread. The error has major and minor IDs MAJ_ID and + * MIN_ID, the name of a function where the error was detected, + * the name of the file where the error was detected, the + * line within that file, and an error description string. The + * function name, file name, and error description strings must + * be statically allocated (the FUNC_ENTER() macro takes care of + * the function name and file name automatically, but the + * programmer is responsible for the description string). + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * Friday, December 12, 1997 + * + * Modifications: + * Raymond Lu + * Tuesday, July 15, 2003 + * + * Added the ID of the error stack to which the error is pushed + * on. The error message can be appended more message in the + * same control format as printf and fprintf. + * + *------------------------------------------------------------------------- + */ +herr_t +H5E_push_new(H5E_t_new *estack, const char *file, const char *func, unsigned line, + hid_t cls_id, hid_t maj_id, hid_t min_id, const char *desc) +{ + /* + * WARNING: We cannot call HERROR() from within this function or else we + * could enter infinite recursion. Furthermore, we also cannot + * call any other HDF5 macro or function which might call + * HERROR(). HERROR() is called by HRETURN_ERROR() which could + * be called by FUNC_ENTER(). + */ + FUNC_ENTER_NOINIT(H5E_push_new); + + /* + * Don't fail if arguments are bad. Instead, substitute some default + * value. + */ + if (!func) func = "Unknown_Function"; + if (!file) file = "Unknown_File"; + if (!desc) desc = "No description given"; + + /* + * Push the error if there's room. Otherwise just forget it. + */ + assert (estack); + if (estack->nused<H5E_NSLOTS) { + estack->slot[estack->nused].cls_id = cls_id; + estack->slot[estack->nused].maj_id = maj_id; + estack->slot[estack->nused].min_id = min_id; + estack->slot[estack->nused].func_name = func; + estack->slot[estack->nused].file_name = file; + estack->slot[estack->nused].line = line; + estack->slot[estack->nused].desc = desc; + estack->nused++; + } + + FUNC_LEAVE_NOAPI(SUCCEED); +} + + #endif /* NEW_ERR */ diff --git a/src/H5Eprivate.h b/src/H5Eprivate.h index 0063ff6..c993c69 100644 --- a/src/H5Eprivate.h +++ b/src/H5Eprivate.h @@ -290,6 +290,10 @@ H5_DLL hid_t H5E_get_current_stack(void); H5_DLL herr_t H5E_close_stack(H5E_t_new *err_stack); H5_DLL ssize_t H5E_get_class(H5E_cls_t *cls, char *name, size_t size); H5_DLL ssize_t H5E_get_msg(H5E_msg_t *msg_ptr, H5E_type_t *type, char *msg, size_t size); +H5_DLL int H5E_get_num(H5E_t_new *err_stack); +H5_DLL herr_t H5E_set_current_stack(H5E_t_new *estack); +H5_DLL herr_t H5E_push_new(H5E_t_new *estack, const char *file, const char *func, unsigned line, + hid_t cls_id, hid_t maj_id, hid_t min_id, const char *desc); #endif /* NEW_ERR */ diff --git a/src/H5Epublic.h b/src/H5Epublic.h index 38597de..038acc2 100644 --- a/src/H5Epublic.h +++ b/src/H5Epublic.h @@ -451,7 +451,12 @@ H5_DLL hid_t H5Eget_current_stack(void); H5_DLL herr_t H5Eclose_stack(hid_t stack_id); H5_DLL ssize_t H5Eget_class(hid_t class_id, char *name, size_t size); 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_new(hid_t err_stack, const char *file, const char *func, unsigned line, + hid_t maj_id, hid_t min_id, const char *msg, ...); + #ifdef __cplusplus } #endif diff --git a/test/errors.c b/test/errors.c index edffa26..e7373d5 100644 --- a/test/errors.c +++ b/test/errors.c @@ -32,17 +32,22 @@ const char *FILENAME[] = { int ipoints2[DIM0][DIM1], icheck2[DIM0][DIM1]; hid_t ERR_CLS; + hid_t ERR_MAJ_TEST; +hid_t ERR_MAJ_IO; + hid_t ERR_MIN_SUBROUTINE; -hid_t ERR_STACK; +hid_t ERR_MIN_CREATE; #define DSET_NAME "a_dataset" #define ERR_CLS_NAME "Error Test" #define PROG_NAME "Error Program" #define PROG_VERS "1.0" -#define ERR_MAJ_MSG "Error in test" -#define ERR_MIN_MSG "Error in subroutine" +#define ERR_MAJ_TEST_MSG "Error in test" +#define ERR_MAJ_IO_MSG "Error in IO" +#define ERR_MIN_SUBROUTINE_MSG "Error in subroutine" +#define ERR_MIN_CREATE_MSG "Error in H5Dcreate" #define SPACE1_DIM1 4 #define SPACE1_RANK 1 @@ -76,7 +81,8 @@ test_error(hid_t file) int i, j, n; hsize_t dims[2]; void *tmp; - + char *FUNC_test_error="test_error()"; + TESTING("error API based on atomic datatype"); /* Initialize the dataset */ @@ -94,7 +100,14 @@ test_error(hid_t file) /*------------------- Test data values ------------------------*/ /* Create the dataset */ if ((dataset = H5Dcreate(file, DSET_NAME, H5T_STD_I32BE, space, - H5P_DEFAULT))<0) TEST_ERROR; + H5P_DEFAULT))<0) { +#ifndef NEW_ERR + H5Epush_new(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_MAJ_IO, ERR_MIN_CREATE, + "H5Dcreate failed"); +#endif /* NEW_ERR */ + + TEST_ERROR; + } /* Write the data to the dataset */ if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2)<0) @@ -181,8 +194,8 @@ init_error(void) { size_t cls_size = strlen(ERR_CLS_NAME)+1; char *cls_name = malloc(strlen(ERR_CLS_NAME)+1); - size_t msg_size = strlen(ERR_MIN_MSG) + 1; - char *msg = malloc(strlen(ERR_MIN_MSG)+1); + size_t msg_size = strlen(ERR_MIN_SUBROUTINE_MSG) + 1; + char *msg = malloc(strlen(ERR_MIN_SUBROUTINE_MSG)+1); H5E_type_t *msg_type= malloc(sizeof(H5E_type_t)); if((ERR_CLS = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, PROG_VERS))<0) @@ -193,16 +206,21 @@ init_error(void) if(strcmp(ERR_CLS_NAME, cls_name)) TEST_ERROR; - if((ERR_MAJ_TEST = H5Ecreate_msg(ERR_CLS, H5E_MAJOR_new, ERR_MAJ_MSG))<0) + if((ERR_MAJ_TEST = H5Ecreate_msg(ERR_CLS, H5E_MAJOR_new, ERR_MAJ_TEST_MSG))<0) + TEST_ERROR; + if((ERR_MAJ_IO = H5Ecreate_msg(ERR_CLS, H5E_MAJOR_new, ERR_MAJ_IO_MSG))<0) + TEST_ERROR; + + if((ERR_MIN_SUBROUTINE = H5Ecreate_msg(ERR_CLS, H5E_MINOR_new, ERR_MIN_SUBROUTINE_MSG))<0) TEST_ERROR; - if((ERR_MIN_SUBROUTINE = H5Ecreate_msg(ERR_CLS, H5E_MINOR_new, ERR_MIN_MSG))<0) + if((ERR_MIN_CREATE = H5Ecreate_msg(ERR_CLS, H5E_MINOR_new, ERR_MIN_CREATE_MSG))<0) TEST_ERROR; if(msg_size != H5Eget_msg(ERR_MIN_SUBROUTINE, msg_type, msg, msg_size) + 1) TEST_ERROR; if(*msg_type != H5E_MINOR_new) TEST_ERROR; - if(strcmp(msg, ERR_MIN_MSG)) + if(strcmp(msg, ERR_MIN_SUBROUTINE_MSG)) TEST_ERROR; free(cls_name); @@ -237,10 +255,23 @@ init_error(void) static herr_t error_stack(void) { - if((ERR_STACK = H5Eget_current_stack())<0) + hid_t err_stack; + int err_num; + + if((err_num = H5Eget_num(H5E_DEFAULT))<0) + TEST_ERROR; + if(err_num) + TEST_ERROR; + + if((err_stack = H5Eget_current_stack())<0) TEST_ERROR; - if(H5Eclose_stack(ERR_STACK)<0) + if((err_num = H5Eget_num(err_stack))<0) + TEST_ERROR; + if(err_num) + TEST_ERROR; + + if(H5Eclose_stack(err_stack)<0) TEST_ERROR; PASSED(); @@ -309,8 +340,8 @@ main(void) { hid_t file, fapl; char filename[1024]; - const char *FUNC="main()"; - + const char *FUNC_main="main()"; + h5_reset(); #ifndef NEW_ERR if(init_error()<0) @@ -328,12 +359,13 @@ main(void) TEST_ERROR ; #endif /* NEW_ERR */ - /*if(test_error(file)<0) {*/ + if(test_error(file)<0) { #ifndef NEW_ERR - /*H5Epush(H5E_DEFAULT, __FILE__, FUNC, __LINE__, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, "Error test failed");*/ + H5Epush_new(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, + "Error test failed because %s", "it's wrong"); #endif /* NEW_ERR */ - /* TEST_ERROR ; - }*/ + TEST_ERROR ; + } if (H5Fclose(file)<0) TEST_ERROR ; h5_cleanup(FILENAME, fapl); |