summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
authorScot Breitenfeld <brtnfld@hdfgroup.org>2009-05-06 18:15:35 (GMT)
committerScot Breitenfeld <brtnfld@hdfgroup.org>2009-05-06 18:15:35 (GMT)
commit90e6f401181ab82277860a62f281fe176b930aac (patch)
tree7724e884b1f4d0171e7edf7a18c147e047134633 /hl
parent8097ca579d394cc3014fd884948702cee4673bf3 (diff)
downloadhdf5-90e6f401181ab82277860a62f281fe176b930aac.zip
hdf5-90e6f401181ab82277860a62f281fe176b930aac.tar.gz
hdf5-90e6f401181ab82277860a62f281fe176b930aac.tar.bz2
[svn-r16924] Description:
Added error handling with throw/catch. Tested: smirom
Diffstat (limited to 'hl')
-rw-r--r--hl/src/H5HLerror.h4
-rw-r--r--hl/src/H5HLint.c34
-rw-r--r--hl/src/H5HLprivate2.h31
-rw-r--r--hl/src/H5LR.c353
-rw-r--r--hl/src/H5LRpkg.h2
-rw-r--r--hl/src/H5LRprivate.h2
-rw-r--r--hl/src/H5LT.c164
-rw-r--r--hl/src/H5LTpkg.h78
8 files changed, 459 insertions, 209 deletions
diff --git a/hl/src/H5HLerror.h b/hl/src/H5HLerror.h
index 0b98571..fd5ef0d 100644
--- a/hl/src/H5HLerror.h
+++ b/hl/src/H5HLerror.h
@@ -35,13 +35,9 @@ H5_DLLVAR hid_t H5HL_ERR_CLS_g;
/* Major error codes */
/*********************/
-#define H5E_LREF (H5OPEN H5E_LREF_g)
-H5_DLLVAR hid_t H5E_LREF_g; /* Lite References */
-
#define H5E_LT (H5OPEN H5E_LT_g)
H5_DLLVAR hid_t H5E_LT_g; /* HDF5 Lite */
-
/*********************/
/* Minor error codes */
/*********************/
diff --git a/hl/src/H5HLint.c b/hl/src/H5HLint.c
index cfe24c9..432d041 100644
--- a/hl/src/H5HLint.c
+++ b/hl/src/H5HLint.c
@@ -75,6 +75,9 @@ hbool_t H5HL_libinit_g = FALSE;
/* HL-HDF5 API Entered variable */
hbool_t H5HL_api_entered_g = FALSE;
+/* High-Level API error class */
+hid_t H5HL_ERR_CLS_g = (-1);
+
/*******************/
/* Local Variables */
@@ -97,7 +100,36 @@ herr_t
H5HL_init_library(void)
{
/* Perform any hfg-level library scoped initialization */
+
+ char lib_str[256];
+ herr_t status;
+
+ /* open the library */
+ status = H5open();
+
+ /* register the error class */
+
+ sprintf(lib_str, "%d.%d.%d",H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE);
+
+ /* H5LT error class */
- return SUCCEED;
+ H5HL_ERR_CLS_g = H5Eregister_class("H5HL", "HDF5:HL", lib_str);
+
+ return SUCCEED;
} /* end H5HL_init_library() */
+/*-------------------------------------------------------------------------
+ * Function: H5HL_close
+ *
+ * Purpose: Free high-level library scoped things.
+ *
+ * Return:
+ *
+ * Programmer: M. Scot Breitenfeld
+ * May 4, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+void H5HL_close(void) {
+ H5Eunregister_class(H5HL_ERR_CLS_g);
+ }
diff --git a/hl/src/H5HLprivate2.h b/hl/src/H5HLprivate2.h
index b29e85f..09428c7 100644
--- a/hl/src/H5HLprivate2.h
+++ b/hl/src/H5HLprivate2.h
@@ -67,12 +67,14 @@
#ifndef TRUE
# define TRUE 1
#endif
-
/* Macro for "glueing" together items, for re-scanning macros */
#define H5_GLUE(x,y) x##y
#define H5_GLUE3(x,y,z) x##y##z
#define H5_GLUE4(w,x,y,z) w##x##y##z
+
+
+
/************************************************/
/* Revisions to FUNC_ENTER/LEAVE & Error Macros */
/************************************************/
@@ -149,10 +151,11 @@ H5_DECLARE_PKG_FUNC(H5_MY_PKG_INIT, H5_MY_PKG)
#endif /* H5_MY_PKG */
/* API re-entrance variable */
-extern hbool_t H5HL_api_entered_g; /* Has library already been entered through API? */
+/* extern hbool_t H5HL_api_entered_g; */ /* Has library already been entered through API? */
/* extern global variables */
extern hbool_t H5HL_libinit_g; /* Has the library been initialized? */
+ \
/* Use FUNC to safely handle variations of C99 __func__ keyword handling */
#ifdef H5_HAVE_C99_FUNC
@@ -188,7 +191,6 @@ extern hbool_t H5HL_libinit_g; /* Has the library been initialized? */
\
/* Enter scope for this type of function */ \
{{
-
#define H5_PUBLIC_ENTER(pkg, pkg_init) \
FUNC_ENTER_NAME_CHECK(H5_IS_PUB(FUNC)) \
\
@@ -203,15 +205,16 @@ extern hbool_t H5HL_libinit_g; /* Has the library been initialized? */
H5E_PRINTF(H5E_CANTINIT, "interface initialization failed"); \
ret_value = fail_value; \
goto func_init_failed; \
- } /* end if */ \
+ } /* end if */ \
+ atexit( H5HL_close); \
} /* end if */ \
\
/* Initialize this interface if desired */ \
H5_GLUE3(H5_PKG_, pkg_init, _INIT)(pkg) \
\
/* Check for re-entering API routine */ \
- assert(!H5HL_api_entered_g); \
- H5HL_api_entered_g = TRUE; \
+ /* assert(!H5HL_api_entered_g); */ \
+ /* H5HL_api_entered_g = TRUE; */ \
\
/* Enter scope for this type of function */ \
{{{
@@ -246,6 +249,10 @@ func \
/* Open function */ \
{ \
ret_typ ret_value = ret_init; \
+ H5E_auto2_t efunc2; \
+ void *H5E_saved_edata; \
+ (void)H5Eget_auto2(H5E_DEFAULT, &efunc2, &H5E_saved_edata); \
+ (void)H5Eset_auto2(H5E_DEFAULT, NULL, NULL); \
H5_GLUE(FUNC_ERR_VAR_, use_err)(ret_typ, err) \
H5_GLUE(FUNC_ENTER_, scope)
@@ -286,15 +293,15 @@ func_init_failed: \
(void)H5HLE_dump_api_stack(TRUE); \
\
/* Check for leaving API routine */ \
- assert(H5HL_api_entered_g); \
- H5HL_api_entered_g = FALSE; \
+ /* assert(H5HL_api_entered_g); */ \
+ /* H5HL_api_entered_g = FALSE; */ \
\
/* Use this macro when leaving all functions */
-#define END_FUNC(scope) \
+#define END_FUNC(scope) \
+ (void)H5Eset_auto2(H5E_DEFAULT, efunc2, H5E_saved_edata); \
/* Scope-specific function conclusion */ \
H5_GLUE(FUNC_LEAVE_, scope) \
- \
/* Leave routine */ \
return(ret_value); \
\
@@ -330,7 +337,7 @@ func_init_failed: \
* The return value is assigned to a variable `ret_value' and control branches
* to the `catch_except' label, if we're not already past it.
*/
-#define H5E_THROW(...) { \
+#define H5E_THROW(...) { \
H5E_PRINTF(__VA_ARGS__); \
H5_LEAVE(fail_value) \
}
@@ -343,5 +350,7 @@ func_init_failed: \
/* Private functions */
herr_t H5HL_init_library(void);
+void H5HL_close(void);
+
#endif /* _H5HLprivate2_H */
diff --git a/hl/src/H5LR.c b/hl/src/H5LR.c
index aa85b44..cfa6e3e 100644
--- a/hl/src/H5LR.c
+++ b/hl/src/H5LR.c
@@ -35,7 +35,6 @@
#include "H5LRpkg.h" /* Lite References */
-
/****************/
/* Local Macros */
/****************/
@@ -47,13 +46,6 @@
hid_t H5_MY_PKG_ERR;
-hid_t ERR_MIN;
-
-#define ERR_CLS_NAME "H5LR"
-#define PROG_NAME "HDF5:LR"
-
-#define ERR_MAJ_MSG " *1*"
-#define ERR_MIN_MSG " *2*"
/********************/
/* Package Typedefs */
@@ -76,7 +68,7 @@ hid_t ERR_MIN;
hbool_t H5_H5LR_init_g = FALSE;
/* High-Level API error class */
-hid_t H5HL_ERR_CLS_g = (-1);
+/* hid_t H5HL_ERR_CLS_g = (-1); */
/* Major error codes */
hid_t H5E_LREF_g = (-1);
@@ -114,48 +106,14 @@ hid_t H5E_LREF_g = (-1);
*-------------------------------------------------------------------------
*/
-BEGIN_FUNC(PKGINIT, NOERR,
-herr_t, SUCCEED, -,
+BEGIN_FUNC(PKGINIT, ERR,
+herr_t, SUCCEED, FAIL,
H5LR__pkg_init(void))
- char lib_str[256];
-
- sprintf(lib_str, "%d.%d.%d",H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE);
-
- /* Perform any package initialization actions (like registering the
- * package's major error code, etc) here */
-
- if((H5HL_ERR_CLS_g = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, lib_str)) < 0)
- TEST_ERROR;
-
-/* if((H5_MY_PKG_ERR = H5Ecreate_msg(H5HL_ERR_CLS_g, H5E_MAJOR, ERR_MAJ_MSG)) < 0) */
-/* TEST_ERROR; */
-
-/* if((ERR_MIN = H5Ecreate_msg(H5HL_ERR_CLS_g, H5E_MINOR, ERR_MIN_MSG)) < 0) */
-/* TEST_ERROR; */
- return 0;
-
-error:
- return -1;
+CATCH
END_FUNC(PKGINIT)
-/* BEGIN_FUNC(PRIV, NOERR, */
-/* herr_t, SUCCEED, -, */
-/* H5LR__pkg_msg(char *ERR_MAJ_MSG, char *ERR_MIN_MSG )) */
-
-/* if((ERR_MAJ_IO = H5Ecreate_msg(H5HL_ERR_CLS_g, H5E_MAJOR, ERR_MAJ_MSG)) < 0) */
-/* TEST_ERROR; */
-
-/* if((ERR_MIN = H5Ecreate_msg(H5HL_ERR_CLS_g, H5E_MINOR, ERR_MIN_MSG)) < 0) */
-/* TEST_ERROR; */
-/* return 0; */
-
-/* error: */
-/* return -1; */
-
-/* END_FUNC(PRIV) */
-
/*-------------------------------------------------------------------------
*
* Public functions
@@ -177,21 +135,21 @@ END_FUNC(PKGINIT)
*
*-------------------------------------------------------------------------
*/
-
-herr_t H5LRget_region_info(hid_t obj_id, /* -IN- Id. of any object in a file associated with reference */
- const hdset_reg_ref_t *ref, /* -IN- Region reference to query */
- size_t *len, /* -IN/OUT- Size of the buffer path */
- char *path, /* -OUT- Full path that a region reference points to */
- int *rank, /* -OUT- The number of dimensions of the dataset pointed by region reference */
- hid_t *dtype, /* -OUT- Dataset datatype pointed by region reference */
- H5S_sel_type *sel_type, /* -OUT- Type fo the selection (point or hyperslab) */
- size_t *numelem, /* -IN/OUT- Number of coordinate blocks or selected elements */
- hsize_t *buf ) /* -OUT- Buffer containing description of the region */
-
-{
+BEGIN_FUNC(PUB, ERR,
+herr_t, SUCCEED, FAIL,
+H5LRget_region_info(hid_t obj_id, /* -IN- Id. of any object in a file associated with reference */
+ const hdset_reg_ref_t *ref, /* -IN- Region reference to query */
+ size_t *len, /* -IN/OUT- Size of the buffer path */
+ char *path, /* -OUT- Full path that a region reference points to */
+ int *rank, /* -OUT- The number of dimensions of the dataset pointed by region reference */
+ hid_t *dtype, /* -OUT- Dataset datatype pointed by region reference */
+ H5S_sel_type *sel_type, /* -OUT- Type fo the selection (point or hyperslab) */
+ size_t *numelem, /* -IN/OUT- Number of coordinate blocks or selected elements */
+ hsize_t *buf ) ) /* -OUT- Buffer containing description of the region */
+
hid_t dset = -1, sid = -1;
- hid_t ret_value = SUCCEED; /* Return value */
herr_t status;
+ hid_t current_stack_id = -1;
/* Determine the rank of the space */
sid = H5Rget_region(obj_id, H5R_DATASET_REGION, ref);
@@ -199,22 +157,18 @@ herr_t H5LRget_region_info(hid_t obj_id, /* -IN- Id. of any o
*sel_type = H5Sget_select_type(sid);
if(*sel_type!=H5S_SEL_HYPERSLABS) printf("wrong select type\n");
-
/* Try to open object */
- H5Eclear2(H5E_DEFAULT);
- H5E_BEGIN_TRY {
- dset = H5Rdereference(obj_id, H5R_DATASET_REGION, ref);
- } H5E_END_TRY;
+ dset = H5Rdereference(obj_id, H5R_DATASET_REGION, ref);
if(dset < 0){
- H5Eclear2(H5E_DEFAULT);
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "\n\n INVALID OBJECT TYPE\n\t- Argument 1 \n");
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_NOTFOUND, "LR: Failed to open the dataset")
}
*rank = (int)H5Sget_simple_extent_ndims(sid);
- if(*rank < 0){
- H5Eclear2(H5E_DEFAULT);
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "\n\n INTERNAL ERROR \n\n - Argument 1 \n");
+ if(rank < 0){
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_NOTFOUND, "LR: Failed to find extents of dataset")
}
/* Determine the type of the dataspace selection */
*sel_type = H5Sget_select_type(sid);
@@ -230,21 +184,22 @@ herr_t H5LRget_region_info(hid_t obj_id, /* -IN- Id. of any o
if( path == NULL) {
/* Determine the size of the name buffer, with null character included */
*len = (size_t)(1 + H5Iget_name (dset, NULL, (size_t)0));
- goto done;
+ goto catch_except;
}
/* Get the data set name the region reference points to */
status = H5Iget_name (dset, path, *len);
if(status < 0){
- H5Eclear2(H5E_DEFAULT);
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "\n\n INTERNAL ERROR \n\n - Argument 1 \n");
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_CANTGET, "LR: Failed to find the name associated with the region reference")
+
}
/* get the data type */
*dtype = (hid_t)H5Dget_type(dset);
- if(status < 0){
- H5Eclear2(H5E_DEFAULT);
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "\n\n INTERNAL ERROR \n\n - Argument 1 \n");
+ if(dtype < 0){
+ H5_MY_PKG_ERR = H5E_DATATYPE;
+ H5E_THROW(H5E_CANTGET, "LR: Failed to find the data type")
}
/* if((native_type = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) */
@@ -254,33 +209,26 @@ herr_t H5LRget_region_info(hid_t obj_id, /* -IN- Id. of any o
/* get the list of hyperslab blocks currently selected */
status = H5Sget_select_hyper_blocklist(sid, (hsize_t)0, (hsize_t)1, buf);
if(status < 0){
- H5Eclear2(H5E_DEFAULT);
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "\n\n INTERNAL ERROR \n\n - Argument 1 \n");
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_CANTSELECT, "LR: Failed to find list of hyperslab blocks")
}
}
- done:
+ CATCH
- if(sid > 0) {
- /* Close the dataspace */
- status = H5Sclose(sid);
- if(status < 0){
- H5Eclear2(H5E_DEFAULT);
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "\n\n INTERNAL ERROR \n\n - Argument 1 \n");
- }
- }
+ current_stack_id = H5Eget_current_stack();
- if(dset > 0) {
+ /* Close the dataspace */
+ if(sid > 0)
+ status = H5Sclose(sid);
+
/* Close the dataset */
- status = H5Dclose(dset);
- if(status < 0){
- H5Eclear2(H5E_DEFAULT);
- HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "\n\n INTERNAL ERROR \n\n - Argument 1 \n");
- }
- }
+ if(dset > 0)
+ status = H5Dclose(dset);
- return ret_value;
-}
+ status = H5Eset_current_stack(current_stack_id);
+
+END_FUNC(PUB)
/*-------------------------------------------------------------------------
* Function: H5LRread_region
@@ -296,39 +244,32 @@ herr_t H5LRget_region_info(hid_t obj_id, /* -IN- Id. of any o
*
*-------------------------------------------------------------------------
*/
-
BEGIN_FUNC(PUB, ERR,
herr_t, SUCCEED, FAIL,
H5LRread_region(hid_t obj_id, /* -IN- Id. of any object in a file associated with reference */
const hdset_reg_ref_t *ref, /* -IN- Region reference to query */
hid_t mem_type, /* -IN- Id. of the memory datatype */
size_t *numelem, /* -IN/OUT- Number of elements in the referenced region */
- void *buf /* -OUT- Buffer containing data from the referenced region */
- ) )
+ void *buf) ) /* -OUT- Buffer containing data from the referenced region */
hid_t dset = -1, file_space = -1; /* Identifier of the dataset's dataspace in the file */
hid_t mem_space = -1; /* Identifier of the memory dataspace */
-
- H5LR__pkg_init();
+ herr_t status;
/* Open the HDF5 object referenced */
- H5E_BEGIN_TRY {
- dset = H5Rdereference(obj_id, H5R_DATASET_REGION, ref);
- } H5E_END_TRY;
+ dset = H5Rdereference(obj_id, H5R_DATASET_REGION, ref);
if(dset < 0) {
H5_MY_PKG_ERR = H5E_REFERENCE;
- H5E_THROW(H5E_NOTFOUND, "HL: Failed to open object referenced")
+ H5E_THROW(H5E_NOTFOUND, "LR: Failed to open object referenced")
} /* end if */
/* Retrieve the dataspace with the specified region selected */
- H5E_BEGIN_TRY {
- file_space = H5Rget_region(dset, H5R_DATASET_REGION, ref);
- } H5E_END_TRY;
+ file_space = H5Rget_region(dset, H5R_DATASET_REGION, ref);
if(file_space < 0) {
H5_MY_PKG_ERR = H5E_REFERENCE;
- H5E_THROW(H5E_CANTGET, "HL: Retrieving dataspace referenced failed")
+ H5E_THROW(H5E_CANTGET, "LR: Retrieving dataspace referenced failed")
} /* end if */
/* Check for anything to retrieve */
@@ -337,7 +278,7 @@ H5LRread_region(hid_t obj_id, /* -IN- Id. of any object in a
/* Determine the number of elements the dataspace selection */
if((nelmts = H5Sget_select_npoints(file_space)) < 0)
- H5E_THROW(H5E_CANTGET, "Unable to retrieve number of elements in region")
+ H5E_THROW(H5E_CANTGET, "LR: Unable to retrieve number of elements in region")
/* Set the number of elements in the region, if requested */
if(numelem)
@@ -359,17 +300,14 @@ H5LRread_region(hid_t obj_id, /* -IN- Id. of any object in a
CATCH
/* Close appropriate items */
- if(mem_space > 0)
- if(H5Sclose(mem_space) < 0)
- H5E_THROW(H5E_CLOSEERROR, "Unable to close memory dataspace")
- if(file_space > 0)
- if(H5Sclose(file_space) < 0)
- H5E_THROW(H5E_CLOSEERROR, "Unable to close file dataspace")
- if(dset > 0)
- if(H5Dclose(dset) < 0)
- H5E_THROW(H5E_CLOSEERROR, "Unable to close dataset")
+ if(mem_space > 0)
+ status =H5Sclose(mem_space);
+
+ if(file_space > 0)
+ status =H5Sclose(file_space);
-/* H5Eclear2(H5E_DEFAULT); */
+ if(dset > 0)
+ status =H5Dclose(dset);
END_FUNC(PUB)
@@ -389,20 +327,21 @@ END_FUNC(PUB)
*
*-------------------------------------------------------------------------
*/
+BEGIN_FUNC(PUB, ERR,
+herr_t, SUCCEED, FAIL,
+H5LRcreate_region_references(hid_t file_id,
+ size_t num_elem,
+ const char **path,
+ hsize_t *block_coord,
+ hdset_reg_ref_t *buf) )
-herr_t H5LRcreate_region_references(hid_t file_id,
- size_t num_elem,
- const char **path,
- hsize_t *block_coord,
- hdset_reg_ref_t *buf)
-{
- hid_t ret_value = SUCCEED; /* Return value */
hid_t sid1 = -1;
hid_t dset_id;
herr_t status;
int nrank;
int i, j, nstart;
hsize_t *start, *count;
+ hid_t current_stack_id = -1;
nstart = 0;
for(i=0; i<(int)num_elem; i++) {
@@ -410,19 +349,42 @@ herr_t H5LRcreate_region_references(hid_t file_id,
/* Open the dataset for a given the path */
dset_id = H5Dopen2(file_id, path[i], H5P_DEFAULT);
+ if(dset_id < 0) {
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_CANTOPENOBJ, "LR: Failed to open dataset for given path")
+ } /* end if */
+
/* Get the dataspace of the dataset */
sid1 = H5Dget_space(dset_id);
+ if(sid1 < 0) {
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_CANTOPENOBJ, "LR: Failed to open dataspace for given path")
+ } /* end if */
+
/* Find the rank of the dataspace */
nrank = H5Sget_simple_extent_ndims(sid1);
+ if(nrank < 0) {
+ H5_MY_PKG_ERR = H5E_DATASPACE;
+ H5E_THROW(H5E_BADSELECT, "LR: Failed to find the rank of the dataspace")
+ } /* end if */
+
/* Create references */
/* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reference */
/* 1 2 n 1 2 n */
start = (hsize_t *)malloc (sizeof (hsize_t) * nrank);
+ if(start == NULL) {
+ H5_MY_PKG_ERR = H5E_RESOURCE;
+ H5E_THROW(H5E_CANTALLOC, "LR: Failed to allocate enough memory")
+ } /* end if */
count = (hsize_t *)malloc (sizeof (hsize_t) * nrank);
+ if(count == NULL) {
+ H5_MY_PKG_ERR = H5E_RESOURCE;
+ H5E_THROW(H5E_CANTALLOC, "LR: Failed to allocate enough memory")
+ } /* end if */
for (j=0; j<nrank; j++) {
start[j] = block_coord[nstart + j];
@@ -431,23 +393,71 @@ herr_t H5LRcreate_region_references(hid_t file_id,
nstart += 2*nrank;
status = H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL);
+ if(status < 0) {
+ free(start);
+ free(count);
+ H5_MY_PKG_ERR = H5E_DATASPACE;
+ H5E_THROW(H5E_CANTSELECT, "LR: Failed to select hyperslab")
+ } /* end if */
status = (int)H5Sget_select_npoints(sid1);
+ if(status < 0) {
+ free(start);
+ free(count);
+ H5_MY_PKG_ERR = H5E_DATASPACE;
+ H5E_THROW(H5E_CANTCOUNT, "LR: Failed to retrieve number of points in hyperslab")
+ } /* end if */
/* Store dataset region */
status = H5Rcreate(&buf[i], file_id, path[i], H5R_DATASET_REGION, sid1);
+ if(status < 0) {
+ free(start);
+ free(count);
+ H5_MY_PKG_ERR = H5E_REFERENCE;
+ H5E_THROW(H5E_CANTCREATE, "LR: Failed to create region reference to dataset")
+ } /* end if */
- /* Close */
- status = H5Dclose(dset_id);
- status = H5Sclose(sid1);
+ /* Close the dataspace */
+ if(sid1 > 0) {
+ status = H5Sclose(sid1);
+ if(status < 0) {
+ free(start);
+ free(count);
+ H5_MY_PKG_ERR = H5E_DATASPACE;
+ H5E_THROW(H5E_CLOSEERROR, "LR: Failed to close dataspace")
+ }
+ }
+
+ /* Close the dataset */
+ if(dset_id > 0) {
+ status = H5Dclose(dset_id);
+ if(status < 0) {
+ free(start);
+ free(count);
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_CLOSEERROR, "LR: Failed to close dataset")
+ }
+ }
+
free(start);
free(count);
- }
+ }
+ CATCH
+
+ current_stack_id = H5Eget_current_stack();
+
+ /* Close the dataspace */
+ if(sid1 > 0)
+ status = H5Sclose(sid1);
+
+ /* Close the dataset */
+ if(dset_id > 0)
+ status = H5Dclose(dset_id);
- return SUCCEED;
-}
+ status = H5Eset_current_stack(current_stack_id);
+END_FUNC(PUB)
/*-------------------------------------------------------------------------
* Function: H5LRmake_dataset
*
@@ -462,10 +472,10 @@ herr_t H5LRcreate_region_references(hid_t file_id,
*
*-------------------------------------------------------------------------
*/
+BEGIN_FUNC(PUB, ERR,
+ herr_t, SUCCEED, FAIL,
+ H5LRmake_dataset(hid_t loc_id, const char *path, hid_t type_id, hid_t loc_id_ref, int buf_size, hdset_reg_ref_t *ref) )
-herr_t H5LRmake_dataset(hid_t loc_id, const char *path, hid_t type_id, hid_t loc_id_ref, int buf_size, hdset_reg_ref_t *ref)
-{
- hid_t ret_value = SUCCEED; /* Return value */
hid_t dset_ref = -1, sid_ref = -1;
H5S_sel_type sel_type;
hid_t dset_id;
@@ -478,6 +488,7 @@ herr_t H5LRmake_dataset(hid_t loc_id, const char *path, hid_t type_id, hid_t loc
size_t numelem;
hsize_t start[2], end[2];
hsize_t *bounds_coor;
+ hid_t current_stack_id = -1;
for (i=0; i<buf_size; i++) {
@@ -490,15 +501,32 @@ herr_t H5LRmake_dataset(hid_t loc_id, const char *path, hid_t type_id, hid_t loc
dset_ref = H5Rdereference(loc_id_ref, H5R_DATASET_REGION, ref[i]);
+
+ if(dset_ref < 0) {
+ H5_MY_PKG_ERR = H5E_REFERENCE;
+ H5E_THROW(H5E_NOTFOUND, "LR: Failed to open object referenced")
+ } /* end if */
+
/* Retrieve the dataspace with the specified region selected */
sid_ref = H5Rget_region (dset_ref, H5R_DATASET_REGION, ref[i]);
+
+ if(sid_ref < 0) {
+ H5_MY_PKG_ERR = H5E_REFERENCE;
+ H5E_THROW(H5E_CANTGET, "LR: Retrieving dataspace referenced failed")
+ } /* end if */
/* get the rank of the region reference */
nrank = H5Sget_simple_extent_ndims(sid_ref);
-
+ if(nrank < 0){
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_NOTFOUND, "LR: Failed to find extents of dataspace")
+ }
/* Allocate space for the dimension array */
dims1 = (hsize_t *)malloc (sizeof (hsize_t) * nrank);
-
+ if(dims1 == NULL) {
+ H5_MY_PKG_ERR = H5E_RESOURCE;
+ H5E_THROW(H5E_CANTALLOC, "LR: Failed to allocate enough memory")
+ } /* end if */
/* get extents of the referenced data */
/* nrank = H5Sget_simple_extent_dims(sid_ref, dims1, NULL ); */
@@ -520,7 +548,6 @@ herr_t H5LRmake_dataset(hid_t loc_id, const char *path, hid_t type_id, hid_t loc
&numelem,
buf );
-
status = H5Sget_select_bounds(sid_ref, start, end );
/* dims1[0] = 6; */
@@ -566,10 +593,21 @@ herr_t H5LRmake_dataset(hid_t loc_id, const char *path, hid_t type_id, hid_t loc
/* status = H5Dread(dset_id, mem_type, sid2, sid1, H5P_DEFAULT, buf); */
- return SUCCEED;
+CATCH
+
+ current_stack_id = H5Eget_current_stack();
+/* /\* Close the dataspace *\/ */
+/* if(sid1 > 0) */
+/* status = H5Sclose(sid1); */
+
+/* /\* Close the dataset *\/ */
+/* if(dset_id > 0) */
+/* status = H5Dclose(dset_id); */
-}
+ status = H5Eset_current_stack(current_stack_id);
+
+END_FUNC(PUB)
/*-------------------------------------------------------------------------
* Function: H5LRcopy_region
@@ -585,14 +623,14 @@ herr_t H5LRmake_dataset(hid_t loc_id, const char *path, hid_t type_id, hid_t loc
*
*-------------------------------------------------------------------------
*/
+BEGIN_FUNC(PUB, ERR,
+herr_t, SUCCEED, FAIL,
+H5LRcopy_region(hid_t obj_id,
+ hdset_reg_ref_t *ref,
+ const char *file,
+ const char *path,
+ hsize_t *block_coord))
-herr_t H5LRcopy_region(hid_t obj_id,
- hdset_reg_ref_t *ref,
- const char *file,
- const char *path,
- hsize_t *block_coord)
-{
- hid_t ret_value = SUCCEED; /* Return value */
herr_t status;
hsize_t *dims1;
hid_t sid1;
@@ -726,12 +764,8 @@ herr_t H5LRcopy_region(hid_t obj_id,
status = H5Fclose(file_id);
status = H5Tclose(dtype);
status = H5Tclose(type_id);
-
-/* close the data */
-
- return SUCCEED;
-
-}
+ CATCH
+END_FUNC(PUB)
/*-------------------------------------------------------------------------
* Function: H5LRcopy_references
@@ -747,11 +781,11 @@ herr_t H5LRcopy_region(hid_t obj_id,
*
*-------------------------------------------------------------------------
*/
+BEGIN_FUNC(PUB, ERR,
+herr_t, SUCCEED, FAIL,
+H5LRcopy_references(hid_t obj_id, hdset_reg_ref_t *ref, const char *file,
+ const char *path, const hsize_t *block_coord_dset, hdset_reg_ref_t *ref_new) )
-herr_t H5LRcopy_references(hid_t obj_id, hdset_reg_ref_t *ref, const char *file,
- const char *path, const hsize_t *block_coord_dset, hdset_reg_ref_t *ref_new)
-{
- hid_t ret_value = SUCCEED; /* Return value */
herr_t status;
hsize_t *dims1, *dims_src;
hid_t sid1;
@@ -768,7 +802,6 @@ herr_t H5LRcopy_references(hid_t obj_id, hdset_reg_ref_t *ref, const char *file,
hsize_t *bounds_coor;
hid_t dtype;
-
/* Region reference data */
did_src = H5Rdereference(obj_id, H5R_DATASET_REGION, ref);
@@ -873,7 +906,7 @@ herr_t H5LRcopy_references(hid_t obj_id, hdset_reg_ref_t *ref, const char *file,
free(dims1);
free(buf);
- return SUCCEED;
+ CATCH
-}
+END_FUNC(PUB)
diff --git a/hl/src/H5LRpkg.h b/hl/src/H5LRpkg.h
index d8a5952..9013351 100644
--- a/hl/src/H5LRpkg.h
+++ b/hl/src/H5LRpkg.h
@@ -34,7 +34,7 @@
*/
#ifdef H5LR_MODULE
#define H5_MY_PKG H5LR
-#define H5_MY_PKG_ERR H5E_LREF
+#define H5_MY_PKG_ERR H5E_LR
#define H5_MY_PKG_INIT YES
#endif /* H5LR_MODULE */
diff --git a/hl/src/H5LRprivate.h b/hl/src/H5LRprivate.h
index 7a562ce..cb31e37 100644
--- a/hl/src/H5LRprivate.h
+++ b/hl/src/H5LRprivate.h
@@ -19,7 +19,7 @@
/* High-level library internal header file */
#include "H5HLprivate2.h"
-/* public LT prototypes */
+/* public LR prototypes */
#include "H5LRpublic.h"
/*-------------------------------------------------------------------------
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index 607eaca..bd49925 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -13,12 +13,24 @@
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <stdio.h>
-#include "H5LTprivate.h"
+/**********************/
+/* Module Declaration */
+/**********************/
+
+#define H5LT_MODULE
+/***********************/
+/* Other Packages Used */
+/***********************/
+
+/***********/
+/* Headers */
+/***********/
+//#include <string.h>
+#include <stdlib.h>
+//#include <assert.h>
+//#include <stdio.h>
+#include "H5LTpkg.h" /* Lite */
/* For Lex and Yacc */
#define COL 3
@@ -29,8 +41,46 @@ int input_len;
char *myinput;
int indent = 0;
+/******************/
+/* Local Typedefs */
+/******************/
+
+hid_t H5_MY_PKG_ERR;
+
+/********************/
+/* Package Typedefs */
+/********************/
+#define AT() printf (" at %s:%d in %s()...\n", \
+ __FILE__, __LINE__, __FUNCTION__);
+#define H5_FAILED() {puts("*FAILED*");fflush(stdout);}
+#define TEST_ERROR {H5_FAILED(); AT(); goto error;}
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+/*********************/
+/* Package Variables */
+/*********************/
+/* Package initialization flag */
+hbool_t H5_H5LT_init_g = FALSE;
+
+/* High-Level API error class */
+/* hid_t H5HL_ERR_CLS_g = (-1); */
+
+/* Major error codes */
+hid_t H5E_LT_g = (-1);
+
+/*****************************/
+/* Library Private Variables */
+/*****************************/
+
+
+/*******************/
+/* Local Variables */
+/*******************/
/*-------------------------------------------------------------------------
*
@@ -38,6 +88,45 @@ int indent = 0;
*
*-------------------------------------------------------------------------
*/
+
+/*-------------------------------------------------------------------------
+ * Function: H5LT__pkg_init
+ *
+ * Purpose: Package initialization
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Quincey Koziol
+ *
+ * Date: April 14, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+
+BEGIN_FUNC(PKGINIT, ERR,
+herr_t, SUCCEED, FAIL,
+H5LT__pkg_init(void))
+
+
+/* char lib_str[256]; */
+
+/* sprintf(lib_str, "%d.%d.%d",H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); */
+
+ /* Perform any package initialization actions (like registering the
+ * package's major error code, etc) here */
+
+/* H5HL_ERR_CLS_g = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, lib_str); */
+/* if(H5HL_ERR_CLS_g < 0) { */
+/* H5_MY_PKG_ERR = H5E_ERROR; */
+/* H5E_THROW(H5E_CANTREGISTER, "H5LT: Failed to register new error class") */
+/* } /\* end if *\/ */
+
+ CATCH
+
+END_FUNC(PKGINIT)
+
+
+
static herr_t H5LT_get_attribute_mem(hid_t loc_id,
const char *obj_name,
const char *attr_name,
@@ -639,43 +728,57 @@ out:
*
*-------------------------------------------------------------------------
*/
-
-herr_t H5LTget_dataset_ndims( hid_t loc_id,
- const char *dset_name,
- int *rank )
-{
+BEGIN_FUNC(PUB, ERR,
+herr_t, SUCCEED, FAIL,
+H5LTget_dataset_ndims( hid_t loc_id,
+ const char *dset_name,
+ int *rank ) )
+
hid_t did = -1;
hid_t sid = -1;
+ herr_t status;
+ hid_t current_stack_id = -1;
/* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
- return -1;
+ did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT);
+
+ if(did < 0) {
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_NOTFOUND, "H5LT: Failed to open the dataset")
+ } /* end if */
/* Get the dataspace handle */
- if((sid = H5Dget_space(did)) < 0)
- goto out;
+ sid = H5Dget_space(did);
+
+ if(sid < 0) {
+ H5_MY_PKG_ERR = H5E_DATASPACE;
+ H5E_THROW(H5E_BADSELECT, "H5LT: Failed to get dataspace handle")
+ } /* end if */
/* Get rank */
- if((*rank = H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
+ *rank = H5Sget_simple_extent_ndims(sid);
- /* Terminate access to the dataspace */
- if(H5Sclose(sid) < 0)
- goto out;
+ if(*rank < 0) {
+ H5_MY_PKG_ERR = H5E_DATASET;
+ H5E_THROW(H5E_BADSELECT, "H5LT: Failed to get dataspace rank")
+ } /* end if */
- /* End access to the dataset */
- if(H5Dclose(did))
- return -1;
+CATCH
- return 0;
+/* save the current error stack before closing */
+current_stack_id = H5Eget_current_stack();
-out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
-}
+/* Close appropriate items, if error occurs it will not be reported */
+if(sid > 0)
+ status = H5Sclose(sid);
+
+if(did > 0)
+ status = H5Dclose(did);
+
+/* retrieve the error stack */
+status = H5Eset_current_stack(current_stack_id);
+
+END_FUNC(PUB)
/*-------------------------------------------------------------------------
@@ -1790,7 +1893,6 @@ herr_t H5LTdtype_to_text(hid_t dtype, char *str, H5LT_lang_t lang_type, size_t *
if((ret = H5LT_dtype_to_text(dtype, &text_str, lang_type, &str_len, 1)) < 0)
goto out;
*len = strlen(text_str) + 1;
- free(text_str);
} else if(len && str) {
if((ret = H5LT_dtype_to_text(dtype, &str, lang_type, len, 0)) < 0)
goto out;
diff --git a/hl/src/H5LTpkg.h b/hl/src/H5LTpkg.h
new file mode 100644
index 0000000..db82b67
--- /dev/null
+++ b/hl/src/H5LTpkg.h
@@ -0,0 +1,78 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Programmer: Quincey Koziol <koziol@hdfgroup.org>
+ * Tuesday, April 14, 2009
+ *
+ * Purpose: This file contains declarations which are visible only within
+ * the H5LT package. Source files outside the H5LT package should
+ * include H5LTprivate.h instead.
+ */
+#if !(defined(H5LT_PACKAGE) | defined(H5LT_MODULE))
+#error "Do not include this file outside the H5LT package!"
+#endif
+
+#ifndef _H5LTpkg_H
+#define _H5LTpkg_H
+
+/* If this package header is being included in one of the H5LT modules, define
+ * the proper control macros for the generic FUNC_ENTER/LEAVE and error
+ * reporting macros.
+ */
+#ifdef H5LT_MODULE
+#define H5_MY_PKG H5LT
+#define H5_MY_PKG_ERR H5E_LT
+#define H5_MY_PKG_INIT YES
+#endif /* H5LT_MODULE */
+
+/* Get package's private header */
+#include "H5LTprivate.h"
+
+/* Other private headers needed by this file */
+
+
+/**************************/
+/* Package Private Macros */
+/**************************/
+
+/* If this package header is being included in one of the H5LT modules, define
+ * the proper control macros for the generic FUNC_ENTER/LEAVE and error
+ * reporting macros.
+ */
+//#ifdef H5LT_MODULE
+//#define H5_MY_PKG H5LT
+//#define H5_MY_PKG_ERR H5E_LT
+//#define H5_MY_PKG_INIT YES
+//#endif /* H5LT_MODULE */
+
+
+/****************************/
+/* Package Private Typedefs */
+/****************************/
+
+
+/*****************************/
+/* Package Private Variables */
+/*****************************/
+
+
+/******************************/
+/* Package Private Prototypes */
+/******************************/
+
+
+#endif /* _H5LTpkg_H */
+