示例#1
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Eset_current_stack
 * Signature: (J)V
 */
JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Eset_1current_1stack
    (JNIEnv *env, jclass cls, jlong stk_id)
{
    if (stk_id < 0) {
        h5badArgument(env, "H5Eset_current_stack: invalid argument");
    } /* end if */
    else if (H5Eset_current_stack((hid_t)stk_id) < 0)
        h5libraryError(env);
} /* end Java_hdf_hdf5lib_H5_H5Eset_1current_1stack */
示例#2
0
/*
 *  h5libraryError()   determines the HDF-5 major error code
 *  and creates and throws the appropriate sub-class of
 *  HDF5LibraryException().  This routine should be called
 *  whenever a call to the HDF-5 library fails, i.e., when
 *  the return is -1.
 *
 *  Note:  This routine never returns from the 'throw',
 *  and the Java native method immediately raises the
 *  exception.
 */
jboolean
h5libraryError
    (JNIEnv *env)
{
    char       *args[2];
    const char *exception = NULL;
    char       *msg_str = NULL;
    int         num_errs = 0;
    hid_t       min_num;
    hid_t       maj_num;
    ssize_t     msg_size = 0;
    H5E_type_t  error_msg_type;
    jstring     str = NULL;
    hid_t       stk_id = -1;
    H5E_num_t   exceptionNumbers;

    exceptionNumbers.maj_num = 0;
    exceptionNumbers.min_num = 0;

    /* Save current stack contents for future use */
    stk_id = H5Eget_current_stack(); /* This will clear current stack  */
    if(stk_id >= 0)
        H5Ewalk2(stk_id, H5E_WALK_DOWNWARD, walk_error_callback, &exceptionNumbers);
    maj_num = exceptionNumbers.maj_num;
    min_num = exceptionNumbers.min_num;

    exception = defineHDF5LibraryException(maj_num);

    /* get the length of the name */
    msg_size = H5Eget_msg(min_num, NULL, NULL, 0);
    if(msg_size > 0) {
        msg_size++; /* add extra space for the null terminator */
        msg_str = (char*)HDcalloc((size_t)msg_size, sizeof(char));
        if(msg_str) {
            msg_size = H5Eget_msg(min_num, &error_msg_type, (char *)msg_str, (size_t)msg_size);
            str = ENVPTR->NewStringUTF(ENVPAR msg_str);
            HDfree(msg_str);
        } /* end if */
    } /* end if */
    else
        str = NULL;
    if(stk_id >= 0)
        H5Eset_current_stack(stk_id);

    args[0] = (char *)str;
    args[1] = 0;
    THROWEXCEPTION(exception, args);
} /* end h5libraryError() */
示例#3
0
/*-------------------------------------------------------------------------
 * Function:    test_copy
 *
 * Purpose:     Test copyinging an error stack
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 * Programmer:  Allen Byrne
 *              February 18, 2010
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_copy(void)
{
    const char *err_func = "test_copy";      /* 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 */
    herr_t      ret;                 /* Generic return value */

    /* Push an error with a long description */
    if(H5Epush(H5E_DEFAULT, __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(H5E_DEFAULT);
    if(err_num != 1) TEST_ERROR
            
    /* Copy error stack, which clears the original */
    if((estack_id = H5Eget_current_stack()) < 0) TEST_ERROR
    
    /* Check the number of errors on stack copy */
    err_num = H5Eget_num(estack_id);
    if(err_num != 1) TEST_ERROR

    /* Check the number of errors on original stack */
    err_num = H5Eget_num(H5E_DEFAULT);
    if(err_num != 0) TEST_ERROR

    /* Put the stack copy as the default.  It closes the stack copy, too. */
    if(H5Eset_current_stack(estack_id) < 0) TEST_ERROR

    /* Check the number of errors on default stack */
    err_num = H5Eget_num(H5E_DEFAULT);
    if(err_num != 1) TEST_ERROR

    /* Try to close error stack copy.  Should fail because 
     * the current H5Eset_current_stack closes the stack to be set.*/
    H5E_BEGIN_TRY {
       ret = H5Eclose_stack(estack_id);
    } H5E_END_TRY
    if(ret >= 0) TEST_ERROR

    return(0);

error:
    return(-1);
} /* end test_copy() */
示例#4
0
/*-------------------------------------------------------------------------
 * Function:	test_error
 *
 * Purpose:	Test error API functions
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Raymond Lu
 *		July 10, 2003
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_error(hid_t file)
{
    hid_t		dataset, space;
    hid_t               estack_id;
    hsize_t		dims[2];
    const char          *FUNC_test_error = "test_error";
    H5E_auto2_t         old_func;
    void                *old_data;

    HDfprintf(stderr, "\nTesting error API based on data I/O\n");

    /* Create the data space */
    dims[0] = DIM0;
    dims[1] = DIM1;
    if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR;

    /* Test H5E_BEGIN_TRY */
    H5E_BEGIN_TRY {
        dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    } H5E_END_TRY;

    /* Create the dataset */
    if((dataset = H5Dcreate2(file, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_CREATE,
                "H5Dcreate2 failed");
        goto error;
    } /* end if */

    /* Test enabling and disabling default printing */
    if(H5Eget_auto2(H5E_DEFAULT, &old_func, &old_data) < 0)
	TEST_ERROR;
    if(old_data != NULL)
	TEST_ERROR;
#ifdef H5_USE_16_API
    if (old_func != (H5E_auto_t)H5Eprint)
	TEST_ERROR;
#else /* H5_USE_16_API */
    if (old_func != (H5E_auto2_t)H5Eprint2)
	TEST_ERROR;
#endif /* H5_USE_16_API */

    if(H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0)
        TEST_ERROR;

    /* Make H5Dwrite fail, verify default print is disabled */
    if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) >= 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
                "H5Dwrite shouldn't succeed");
        goto error;
    } /* end if */

    if(H5Eset_auto2(H5E_DEFAULT, old_func, old_data) < 0)
        TEST_ERROR;

    /* Test saving and restoring the current error stack */
    if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
                "H5Dwrite failed as supposed to");
        estack_id = H5Eget_current_stack();
        H5Dclose(dataset);
        H5Sclose(space);
        H5Eset_current_stack(estack_id);
        goto error;
    } /* end if */

    /* In case program comes to this point, close dataset */
    if(H5Dclose(dataset) < 0) TEST_ERROR;

    TEST_ERROR;

  error:
    return -1;
} /* end test_error() */