From 1f3aede7c7adb1a12efb839a15c8cf3a1bce8f1c Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 1 Nov 2007 14:27:15 -0500 Subject: [svn-r14230] Description: Add H5Ecreate_stack() API routine, to fill a minor gap in the error routines. Tested on: FreeBSD/32 6.2 (duty) in debug mode FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Mac OS X/32 10.4.10 (amazon) in debug mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode --- src/H5E.c | 92 +++++++++++++++++++++++++++++++++++++++++++++---------- src/H5Epublic.h | 1 + test/error_test.c | 57 +++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 18 deletions(-) diff --git a/src/H5E.c b/src/H5E.c index 6e553c6..72f0619 100644 --- a/src/H5E.c +++ b/src/H5E.c @@ -153,6 +153,37 @@ done: /*-------------------------------------------------------------------------- + * Function: H5E_set_default_auto + * + * Purpose: Initialize "automatic" error stack reporting info to library + * default + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, November 1, 2007 + * + *-------------------------------------------------------------------------- + */ +static herr_t +H5E_set_default_auto(H5E_t *stk) +{ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5E_set_default_auto) + +#ifdef H5_USE_16_API + stk->auto_op.vers = 1; + stk->auto_op.u.func1 = (H5E_auto1_t)H5Eprint1; +#else /* H5_USE_16_API */ + stk->auto_op.vers = 2; + stk->auto_op.u.func2 = (H5E_auto2_t)H5Eprint2; +#endif /* H5_USE_16_API */ + stk->auto_data = NULL; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5E_set_default_auto() */ + + +/*-------------------------------------------------------------------------- * Function: H5E_init_interface * * Purpose: Initialize interface-specific information @@ -191,14 +222,7 @@ H5E_init_interface(void) #ifndef H5_HAVE_THREADSAFE H5E_stack_g[0].nused = 0; -#ifdef H5_USE_16_API - H5E_stack_g[0].auto_op.vers = 1; - H5E_stack_g[0].auto_op.u.func1 = (H5E_auto1_t)H5Eprint1; -#else /* H5_USE_16_API */ - H5E_stack_g[0].auto_op.vers = 2; - H5E_stack_g[0].auto_op.u.func2 = (H5E_auto2_t)H5Eprint2; -#endif /* H5_USE_16_API */ - H5E_stack_g[0].auto_data = NULL; + H5E_set_default_auto(H5E_stack_g); #endif /* H5_HAVE_THREADSAFE */ /* Allocate the HDF5 error class */ @@ -321,14 +345,7 @@ H5E_get_stack(void) /* Set the thread-specific info */ estack->nused = 0; -#ifdef H5_USE_16_API - estack->auto_op.vers = 1; - estack->auto_op.u.func1 = (H5E_auto1_t)H5Eprint1; -#else /* H5_USE_16_API */ - estack->auto_op.vers = 2; - estack->auto_op.u.func2 = (H5E_auto2_t)H5Eprint2; -#endif /* H5_USE_16_API */ - estack->auto_data = NULL; + H5E_set_default_auto(estack); /* (It's not necessary to release this in this API, it is * released by the "key destructor" set up in the H5TS @@ -793,6 +810,43 @@ done: /*------------------------------------------------------------------------- + * Function: H5Ecreate_stack + * + * Purpose: Creates a new, empty, error stack. + * + * Return: Non-negative value as stack ID on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, November 1, 2007 + * + *------------------------------------------------------------------------- + */ +hid_t +H5Ecreate_stack(void) +{ + H5E_t *stk; /* Error stack */ + hid_t ret_value; /* Return value */ + + FUNC_ENTER_API(H5Ecreate_stack, FAIL) + H5TRACE0("i",""); + + /* Allocate a new error stack */ + if(NULL == (stk = H5FL_CALLOC(H5E_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + + /* Set the "automatic" error reporting info to the library default */ + H5E_set_default_auto(stk); + + /* Register the stack */ + if((ret_value = H5I_register(H5I_ERROR_STACK, stk)) < 0) + HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't create error stack") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Ecreate_stack() */ + + +/*------------------------------------------------------------------------- * Function: H5Eget_current_stack * * Purpose: Registers current error stack, returns object handle for it, @@ -855,7 +909,7 @@ H5E_get_current_stack(void) HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get current error stack") /* Allocate a new error stack */ - if(NULL == (estack_copy = H5FL_MALLOC(H5E_t))) + if(NULL == (estack_copy = H5FL_CALLOC(H5E_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Make a copy of current error stack */ @@ -886,6 +940,10 @@ H5E_get_current_stack(void) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") } /* end for */ + /* Copy the "automatic" error reporting information */ + estack_copy->auto_op = current_stack->auto_op; + estack_copy->auto_data = current_stack->auto_data; + /* Empty current error stack */ H5E_clear_stack(current_stack); diff --git a/src/H5Epublic.h b/src/H5Epublic.h index 7b716ef..b0e93bb 100644 --- a/src/H5Epublic.h +++ b/src/H5Epublic.h @@ -159,6 +159,7 @@ H5_DLL hid_t H5Eregister_class(const char *cls_name, const char *lib_name, H5_DLL herr_t H5Eunregister_class(hid_t class_id); 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 H5Ecreate_stack(void); H5_DLL hid_t H5Eget_current_stack(void); H5_DLL herr_t H5Eclose_stack(hid_t stack_id); H5_DLL ssize_t H5Eget_class_name(hid_t class_id, char *name, size_t size); diff --git a/test/error_test.c b/test/error_test.c index 97da864..027f31b 100644 --- a/test/error_test.c +++ b/test/error_test.c @@ -17,7 +17,7 @@ * Programmer: Raymond Lu * October 14, 2001 * - * Purpose: Tests the H5Tget_native_type function. + * Purpose: Tests the error API routines. */ #include "h5test.h" @@ -454,6 +454,58 @@ error: /*------------------------------------------------------------------------- + * Function: test_create + * + * Purpose: Test creating an empty error stack + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Quincey Koziol + * November 1, 2007 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_create(void) +{ + const char *err_func = "test_create"; /* Function name for pushing error */ + const char *err_msg = "Error message"; /* Error message for pushing error */ + int err_num; /* Number of errors on stack */ + hid_t estack_id; /* Error stack ID */ + + /* Create an empty error stack */ + if((estack_id = H5Ecreate_stack()) < 0) TEST_ERROR + + /* Check the number of errors on stack */ + err_num = H5Eget_num(estack_id); + if(err_num != 0) TEST_ERROR + + /* Push an error with a long description */ + if(H5Epush(estack_id, __FILE__, err_func, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, err_msg) < 0) TEST_ERROR; + + /* Check the number of errors on stack */ + err_num = H5Eget_num(estack_id); + if(err_num != 1) TEST_ERROR + + /* Clear the error stack */ + if(H5Eclear2(estack_id) < 0) TEST_ERROR + + /* Check the number of errors on stack */ + err_num = H5Eget_num(estack_id); + if(err_num != 0) TEST_ERROR + + /* Close error stack */ + if(H5Eclose_stack(estack_id) < 0) TEST_ERROR + + return(0); + +error: + return(-1); +} /* end test_create() */ + + +/*------------------------------------------------------------------------- * Function: close_error * * Purpose: Closes error information. @@ -551,6 +603,9 @@ main(void) /* Test pushing a very long error description */ if(test_long_desc() < 0) TEST_ERROR; + /* Test creating a new error stack */ + if(test_create() < 0) TEST_ERROR; + if(H5Fclose(file) < 0) TEST_ERROR; h5_cleanup(FILENAME, fapl); -- cgit v0.12