Skip to content

Commit

Permalink
Fix H5Eget_auto2/H5Eauto_is_v2 to not clear error stack (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendersonHDF authored May 12, 2021
1 parent 7d140b9 commit 78f0728
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
47 changes: 39 additions & 8 deletions src/H5E.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ H5E_term_package(void)
nstk = H5I_nmembers(H5I_ERROR_STACK);

if ((ncls + nmsg + nstk) > 0) {
/* Clear the default error stack. Note that
* the following H5I_clear_type calls do not
* force the clears and will not be able to
* clear any error message IDs that are still
* in use by the default error stack unless we
* clear that stack manually.
*
* Error message IDs will typically still be
* in use by the default error stack when the
* application does H5E_BEGIN/END_TRY cleanup
* at the very end.
*/
H5E_clear_stack(NULL);

/* Clear any outstanding error stacks */
if (nstk > 0)
(void)H5I_clear_type(H5I_ERROR_STACK, FALSE, FALSE);
Expand Down Expand Up @@ -1532,16 +1546,22 @@ H5Eget_auto2(hid_t estack_id, H5E_auto2_t *func /*out*/, void **client_data /*ou
H5E_auto_op_t op; /* Error stack function */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_API(FAIL)
/* Don't clear the error stack! :-) */
FUNC_ENTER_API_NOCLEAR(FAIL)
H5TRACE3("e", "ixx", estack_id, func, client_data);

if (estack_id == H5E_DEFAULT) {
if (NULL == (estack = H5E__get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in
non-threaded case */
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack")
} /* end if */
else if (NULL == (estack = (H5E_t *)H5I_object_verify(estack_id, H5I_ERROR_STACK)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID")
else {
/* Only clear the error stack if it's not the default stack */
H5E_clear_stack(NULL);

if (NULL == (estack = (H5E_t *)H5I_object_verify(estack_id, H5I_ERROR_STACK)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID")
} /* end else */

/* Get the automatic error reporting information */
if (H5E__get_auto(estack, &op, client_data) < 0)
Expand Down Expand Up @@ -1598,8 +1618,13 @@ H5Eset_auto2(hid_t estack_id, H5E_auto2_t func, void *client_data)
non-threaded case */
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack")
} /* end if */
else if (NULL == (estack = (H5E_t *)H5I_object_verify(estack_id, H5I_ERROR_STACK)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID")
else {
/* Only clear the error stack if it's not the default stack */
H5E_clear_stack(NULL);

if (NULL == (estack = (H5E_t *)H5I_object_verify(estack_id, H5I_ERROR_STACK)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID")
} /* end else */

#ifndef H5_NO_DEPRECATED_SYMBOLS
/* Get the automatic error reporting information */
Expand Down Expand Up @@ -1646,16 +1671,22 @@ H5Eauto_is_v2(hid_t estack_id, unsigned *is_stack)
H5E_t *estack; /* Error stack to operate on */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_API(FAIL)
/* Don't clear the error stack! :-) */
FUNC_ENTER_API_NOCLEAR(FAIL)
H5TRACE2("e", "i*Iu", estack_id, is_stack);

if (estack_id == H5E_DEFAULT) {
if (NULL == (estack = H5E__get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in
non-threaded case */
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack")
} /* end if */
else if (NULL == (estack = (H5E_t *)H5I_object_verify(estack_id, H5I_ERROR_STACK)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID")
else {
/* Only clear the error stack if it's not the default stack */
H5E_clear_stack(NULL);

if (NULL == (estack = (H5E_t *)H5I_object_verify(estack_id, H5I_ERROR_STACK)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID")
} /* end else */

/* Check if the error stack reporting function is the "newer" stack type */
if (is_stack)
Expand Down
14 changes: 13 additions & 1 deletion test/testfiles/err_compat_1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
minor: Unable to create file

********* Print error stack in customized way *********
error #000: (file name) in H5Eget_auto(1 or 2)(): line (number)
error #000: (file name) in H5VL_vol_object(): line (number)
major: Invalid arguments to routine
minor: Inappropriate type
error #001: (file name) in H5VL_setup_acc_args(): line (number)
major: Invalid arguments to routine
minor: Inappropriate type
error #002: (file name) in H5D__create_api_common(): line (number)
major: Dataset
minor: Can't set value
error #003: (file name) in H5Dcreate2(): line (number)
major: Dataset
minor: Unable to create file
error #004: (file name) in H5Eget_auto(1 or 2)(): line (number)
major: Error API
minor: Can't get value

Expand Down

0 comments on commit 78f0728

Please sign in to comment.