diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2003-07-15 15:49:25 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2003-07-15 15:49:25 (GMT) |
commit | eb1eafd79873d640683357eadd04e65f4a212511 (patch) | |
tree | 04b3096402c90a5fdbc725f87662ceaa2d57e36e /src | |
parent | 8a98abf66f4d672e6f0fbfa4719d0100b54ff2e0 (diff) | |
download | hdf5-eb1eafd79873d640683357eadd04e65f4a212511.zip hdf5-eb1eafd79873d640683357eadd04e65f4a212511.tar.gz hdf5-eb1eafd79873d640683357eadd04e65f4a212511.tar.bz2 |
[svn-r7226] Purpose: Bug fix for error API.
Description: gradual checkin
Platforms tested: platinum, baldric
Diffstat (limited to 'src')
-rw-r--r-- | src/H5E.c | 186 | ||||
-rw-r--r-- | src/H5Eprivate.h | 2 | ||||
-rw-r--r-- | src/H5Epublic.h | 2 |
3 files changed, 187 insertions, 3 deletions
@@ -541,6 +541,79 @@ done: /*------------------------------------------------------------------------- + * Function: H5Eget_class + * + * Purpose: Retrieves error class name. + * + * Return: Non-negative for name length if succeeds(zero means no name); + * otherwise returns negative value. + * + * Programmer: Raymond Lu + * Friday, July 11, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +ssize_t +H5Eget_class(hid_t class_id, char *name, size_t size) +{ + ssize_t ret_value; /* Return value */ + H5E_cls_t *cls; + + FUNC_ENTER_API(H5Eget_class, FAIL); + H5TRACE3("Zs","isz",class_id,name,size); + + /* Need to check for errors */ + cls = H5I_object_verify(class_id, H5I_ERROR_CLASS); + + ret_value = H5E_get_class(cls, name, size); + +done: + FUNC_LEAVE_API(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5E_get_class + * + * Purpose: Private function to retrieve error class name. + * + * Return: Non-negative for name length if succeeds(zero means no name); + * otherwise returns negative value. + * + * Programmer: Raymond Lu + * Friday, July 11, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +ssize_t +H5E_get_class(H5E_cls_t *cls, char *name, size_t size) +{ + ssize_t ret_value; /* Return value */ + ssize_t len; + + FUNC_ENTER_NOAPI(H5E_get_class, FAIL); + + len = HDstrlen(cls->cls_name); + + if(name) { + HDstrncpy(name, cls->cls_name, MIN(len+1, size)); + if(len >= size) + name[size-1]='\0'; + } + + ret_value = len; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + + +/*------------------------------------------------------------------------- * Function: H5E_close_msg_cb * * Purpose: H5I_search callback function to close error messages in the @@ -707,6 +780,80 @@ done: } +/*------------------------------------------------------------------------- + * Function: H5Eget_msg + * + * Purpose: Retrieves an error message. + * + * Return: Non-negative for message length if succeeds(zero means no message); + * otherwise returns negative value. + * + * Programmer: Raymond Lu + * Friday, July 14, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +ssize_t +H5Eget_msg(hid_t msg_id, H5E_type_t *type, char *msg, size_t size) +{ + ssize_t ret_value; /* Return value */ + H5E_msg_t *msg_ptr; + + FUNC_ENTER_API(H5Eget_msg, FAIL); + + /* Need to check for errors */ + msg_ptr = H5I_object_verify(msg_id, H5I_ERROR_MSG); + + ret_value = H5E_get_msg(msg_ptr, type, msg, size); + +done: + FUNC_LEAVE_API(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5E_get_msg + * + * Purpose: Private function to retrieve an error message. + * + * Return: Non-negative for name length if succeeds(zero means no name); + * otherwise returns negative value. + * + * Programmer: Raymond Lu + * Friday, July 14, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +ssize_t +H5E_get_msg(H5E_msg_t *msg_ptr, H5E_type_t *type, char *msg, size_t size) +{ + ssize_t ret_value; /* Return value */ + ssize_t len; + + FUNC_ENTER_NOAPI(H5E_get_msg, FAIL); + + len = HDstrlen(msg_ptr->msg); + + if(msg) { + HDstrncpy(msg, msg_ptr->msg, MIN(len+1, size)); + if(len >= size) + msg[size-1]='\0'; + } + + if(type) + *type = msg_ptr->type; + + ret_value = len; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + #ifdef H5_HAVE_THREADSAFE /*------------------------------------------------------------------------- * Function: H5E_get_stack_new @@ -798,13 +945,45 @@ hid_t H5E_get_current_stack(void) { hid_t ret_value; /* Return value */ - H5E_t_new *estack = H5E_get_my_stack_new (); + H5E_t_new *current_stack = H5E_get_my_stack_new (); + H5E_t_new *estack_copy = H5MM_malloc(sizeof(H5E_t_new)); + H5E_error_t_new *current_error, *new_error; + int i; FUNC_ENTER_NOAPI(H5E_get_current_stack, FAIL); + /* Make a copy of current error stack */ + estack_copy->nused = current_stack->nused; + for(i=0; i<current_stack->nused; i++) { + current_error = &(current_stack->slot[i]); + new_error = &(estack_copy->slot[i]); + + /* Should we make copies of these IDs? */ + new_error->cls_id = current_error->cls_id; + new_error->maj_id = current_error->maj_id; + new_error->min_id = current_error->min_id; + new_error->func_name = HDstrdup(current_error->func_name); + new_error->file_name = HDstrdup(current_error->file_name); + new_error->line = current_error->line; + new_error->desc = HDstrdup(current_error->desc); + } + + /* 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; + /* Register the error stack to get an ID for it */ /* Need to check for error */ - ret_value = H5I_register(H5I_ERROR_STACK, estack); + ret_value = H5I_register(H5I_ERROR_STACK, estack_copy); done: FUNC_LEAVE_NOAPI(ret_value); @@ -873,12 +1052,13 @@ H5E_close_stack(H5E_t_new *err_stack) herr_t ret_value = SUCCEED; /* Return value */ H5E_error_t_new *error; int i; - + FUNC_ENTER_NOAPI(H5E_close_stack, FAIL); if(err_stack) { for(i=0; i<err_stack->nused; i++) { error = &(err_stack->slot[i]); + if(error->func_name) H5MM_xfree(error->func_name); if(error->file_name) diff --git a/src/H5Eprivate.h b/src/H5Eprivate.h index 56ed9d5..0063ff6 100644 --- a/src/H5Eprivate.h +++ b/src/H5Eprivate.h @@ -288,6 +288,8 @@ H5_DLL herr_t H5E_close_msg(H5E_msg_t *err); H5_DLL hid_t H5E_create_msg(hid_t cls_id, H5E_type_t msg_type, const char *msg); 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); #endif /* NEW_ERR */ diff --git a/src/H5Epublic.h b/src/H5Epublic.h index 792c637..38597de 100644 --- a/src/H5Epublic.h +++ b/src/H5Epublic.h @@ -449,6 +449,8 @@ H5_DLL herr_t H5Eclose_msg(hid_t err_id); H5_DLL hid_t H5Ecreate_msg(hid_t cls, H5E_type_t msg_type, const char *msg); 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); #ifdef __cplusplus } |