diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2009-12-10 17:43:14 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2009-12-10 17:43:14 (GMT) |
commit | 9d06256018fbebbefa08879ae9f16696a5bbef19 (patch) | |
tree | db84f4d812d122c8c9fafbcc4b828fc12cbf6a8e | |
parent | a4750dfae7e187f95c4515939968e6fce880efed (diff) | |
download | hdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.zip hdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.tar.gz hdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.tar.bz2 |
[svn-r17987] Description:
Bring r17945:17986 from trunk to revise_chunks branch
(needs to have autotools files regenerated before testing, those will
be checked in in a few minutes)
75 files changed, 1773 insertions, 1202 deletions
@@ -1,4 +1,4 @@ -HDF5 version 1.9.52-FA_a4 currently under development +HDF5 version 1.9.54-FA_a4 currently under development Please refer to the release_docs/INSTALL file for installation instructions. ------------------------------------------------------------------------------ diff --git a/bin/snapshot b/bin/snapshot index 82bf557..4235670 100755 --- a/bin/snapshot +++ b/bin/snapshot @@ -460,7 +460,9 @@ if [ "$cmd" = "all" -o -n "$cmdrel" ]; then echo "Making snapshot release ($RELEASE_VERSION) to ${ReleaseDir}..." bin/release -d $ReleaseDir $METHODS perl bin/h5vers -i - svn -q commit -m "Snapshot $RELEASE_VERSION" + echo "Committing snapshot from current/bin/snapshot." + ls + svn -q commit -m "Snapshot $RELEASE_VERSION" . ) errcode=$? fi diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index f9311c6..dd4a419 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -570,8 +570,10 @@ H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const // if the actual length of the comment is longer than bufsize and bufsize // was the default value, i.e., not given by the user, then call - // H5Oget_comment_by_name again with the correct value - if ((size_t)ret_value > bufsize && bufsize == 256) + // H5Oget_comment_by_name again with the correct value. + // If the call to H5Oget_comment_by_name returned an error, skip this block + // and throw an exception below. + if (ret_value >= 0 && (size_t)ret_value > bufsize && bufsize == 256) { size_t new_size = ret_value; delete []comment_C; diff --git a/c++/src/Makefile.in b/c++/src/Makefile.in index a76df89..420292b 100644 --- a/c++/src/Makefile.in +++ b/c++/src/Makefile.in @@ -390,7 +390,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Add libtool shared library version numbers to the HDF5 library # See libtool versioning documentation online. LT_VERS_INTERFACE = 6 -LT_VERS_REVISION = 42 +LT_VERS_REVISION = 44 LT_VERS_AGE = 0 # Include src directory diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index f17f37a..c4ac93b 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -217,6 +217,12 @@ static void test_reference_obj(void) H5std_string read_comment1 = group.getComment(".", 10); verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__); + // Test that getComment handles failures gracefully + try { + H5std_string read_comment_tmp = group.getComment(NULL); + } + catch (Exception E) {} // We expect this to fail + // Close group group.close(); diff --git a/config/lt_vers.am b/config/lt_vers.am index 7e4079b..ea46130 100644 --- a/config/lt_vers.am +++ b/config/lt_vers.am @@ -17,7 +17,7 @@ # Add libtool shared library version numbers to the HDF5 library # See libtool versioning documentation online. LT_VERS_INTERFACE = 6 -LT_VERS_REVISION = 42 +LT_VERS_REVISION = 44 LT_VERS_AGE = 0 ## If the API changes *at all*, increment LT_VERS_INTERFACE and diff --git a/configure.in b/configure.in index 11868e7..88b545d 100644 --- a/configure.in +++ b/configure.in @@ -26,7 +26,7 @@ dnl dnl NOTE: Don't forget to change the version number here when we do a dnl release!!! dnl -AC_INIT([HDF5], [1.9.52-FA_a4], [help@hdfgroup.org]) +AC_INIT([HDF5], [1.9.54-FA_a4], [help@hdfgroup.org]) AC_CONFIG_SRCDIR([src/H5.c]) AM_CONFIG_HEADER([src/H5config.h]) diff --git a/fortran/src/H5Pff.f90 b/fortran/src/H5Pff.f90 index c35c383..48d36ab 100644 --- a/fortran/src/H5Pff.f90 +++ b/fortran/src/H5Pff.f90 @@ -7056,10 +7056,10 @@ ! other chunks. ! ! Inputs: -! dapl_id - Link creation property list identifier -! rdcc_nslots - -! rdcc_nbytes - -! rdcc_w0 - +! dapl_id - Dataset access property list identifier. +! rdcc_nslots - The number of chunk slots in the raw data chunk cache for this dataset. +! rdcc_nbytes - The total size of the raw data chunk cache for this dataset. +! rdcc_w0 - The chunk preemption policy for this dataset. ! Outputs: ! hdferr: - error code ! Success: 0 @@ -7075,11 +7075,14 @@ SUBROUTINE h5pset_chunk_cache_f(dapl_id, rdcc_nslots, rdcc_nbytes, rdcc_w0, hdferr) IMPLICIT NONE - INTEGER(HID_T), INTENT(IN) :: dapl_id - INTEGER(SIZE_T), INTENT(IN) :: rdcc_nslots - INTEGER(SIZE_T), INTENT(IN) :: rdcc_nbytes - REAL, INTENT(IN) :: rdcc_w0 - INTEGER, INTENT(OUT) :: hdferr + INTEGER(HID_T), INTENT(IN) :: dapl_id ! Dataset access property list identifier. + INTEGER(SIZE_T), INTENT(IN) :: rdcc_nslots ! The number of chunk slots in the raw data + ! chunk cache for this dataset. + INTEGER(SIZE_T), INTENT(IN) :: rdcc_nbytes ! The total size of the raw data chunk cache + ! for this dataset. + REAL, INTENT(IN) :: rdcc_w0 ! The chunk preemption policy for this dataset. + INTEGER, INTENT(OUT) :: hdferr ! Error code + ! 0 on success and -1 on failure INTERFACE @@ -7111,11 +7114,11 @@ ! file access property list are returned. ! ! Inputs: -! dapl_id - Link creation property list identifier -! rdcc_nslots - -! rdcc_nbytes - -! rdcc_w0 - -! Outputs: +! dapl_id - Dataset access property list identifier. +! Outputs: +! rdcc_nslots - Number of chunk slots in the raw data chunk cache hash table. +! rdcc_nbytes - Total size of the raw data chunk cache, in bytes. +! rdcc_w0 - Preemption policy. ! hdferr: - error code ! Success: 0 ! Failure: -1 @@ -7130,11 +7133,11 @@ SUBROUTINE h5pget_chunk_cache_f(dapl_id, rdcc_nslots, rdcc_nbytes, rdcc_w0, hdferr) IMPLICIT NONE - INTEGER(HID_T), INTENT(IN) :: dapl_id - INTEGER(SIZE_T), INTENT(OUT) :: rdcc_nslots - INTEGER(SIZE_T), INTENT(OUT) :: rdcc_nbytes - REAL, INTENT(OUT) :: rdcc_w0 - INTEGER, INTENT(OUT) :: hdferr + INTEGER(HID_T), INTENT(IN) :: dapl_id ! Dataset access property list identifier. + INTEGER(SIZE_T), INTENT(OUT) :: rdcc_nslots ! Number of chunk slots in the raw data chunk cache hash table. + INTEGER(SIZE_T), INTENT(OUT) :: rdcc_nbytes ! Total size of the raw data chunk cache, in bytes. + REAL, INTENT(OUT) :: rdcc_w0 ! Preemption policy. + INTEGER, INTENT(OUT) :: hdferr ! error code INTERFACE INTEGER FUNCTION h5pget_chunk_cache_c(dapl_id, rdcc_nslots, rdcc_nbytes, rdcc_w0) diff --git a/fortran/src/Makefile.in b/fortran/src/Makefile.in index 3205695..7138639 100644 --- a/fortran/src/Makefile.in +++ b/fortran/src/Makefile.in @@ -424,7 +424,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Add libtool shared library version numbers to the HDF5 library # See libtool versioning documentation online. LT_VERS_INTERFACE = 6 -LT_VERS_REVISION = 42 +LT_VERS_REVISION = 44 LT_VERS_AGE = 0 # Include src directory in both Fortran and C flags (C compiler is used diff --git a/hl/c++/src/Makefile.in b/hl/c++/src/Makefile.in index 069db9c..cf49155 100644 --- a/hl/c++/src/Makefile.in +++ b/hl/c++/src/Makefile.in @@ -380,7 +380,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Add libtool shared library version numbers to the HDF5 library # See libtool versioning documentation online. LT_VERS_INTERFACE = 6 -LT_VERS_REVISION = 42 +LT_VERS_REVISION = 44 LT_VERS_AGE = 0 # Include src directory diff --git a/hl/fortran/src/Makefile.in b/hl/fortran/src/Makefile.in index a3ce044..afe8ed4 100644 --- a/hl/fortran/src/Makefile.in +++ b/hl/fortran/src/Makefile.in @@ -389,7 +389,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Add libtool shared library version numbers to the HDF5 library # See libtool versioning documentation online. LT_VERS_INTERFACE = 6 -LT_VERS_REVISION = 42 +LT_VERS_REVISION = 44 LT_VERS_AGE = 0 INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/hl/src -I$(top_builddir)/hl/src \ -I$(top_srcdir)/fortran/src -I$(top_builddir)/fortran/src diff --git a/hl/src/Makefile.in b/hl/src/Makefile.in index 2aca5fa..0e3bd46 100644 --- a/hl/src/Makefile.in +++ b/hl/src/Makefile.in @@ -380,7 +380,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Add libtool shared library version numbers to the HDF5 library # See libtool versioning documentation online. LT_VERS_INTERFACE = 6 -LT_VERS_REVISION = 42 +LT_VERS_REVISION = 44 LT_VERS_AGE = 0 # This library is our main target. diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 9264bc1..6a75c48 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -204,11 +204,14 @@ Bug Fixes since HDF5-1.8.0 release Library ------- + - H5Tdetect_class said a VL string is a string type. But when it's + in a compound type, it said it's a VL type (Bug #1584). I fixed it + to be consistent. It always return string type. (SLU - 2009/12/10) - Fixed a bug where writing and deleting many global heap objects (i.e. variable length data) would render the file unreadable. Previously created files exhibiting this problem should now be readable. - NAF - 2009/10/27 - 1483 - - Fixed incorrect return value for H5Pget_preserve. AKC - 2009/10/08 - 1628 + (NAF - 2009/10/27 - 1483) + - Fixed incorrect return value for H5Pget_preserve. (AKC - 2009/10/08 - 1628) - Fixed an assertion failure that occurred when H5Ocopy was called on a dataset using a vlen inside a compound. (NAF - 2009/10/02 - 1597) - Fixed incorrect return value for H5Pget_filter_by_id1/2 in H5Ppublic.h. @@ -3638,7 +3638,8 @@ H5AC_ext_config_2_int_config(H5AC_cache_config_t * ext_conf_ptr, if ( ( ext_conf_ptr == NULL ) || ( ext_conf_ptr->version != H5AC__CURR_CACHE_CONFIG_VERSION ) || ( int_conf_ptr == NULL ) ) { - + HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, \ + "Bad ext_conf_ptr or inf_conf_ptr on entry.") } int_conf_ptr->version = H5C__CURR_AUTO_SIZE_CTL_VER; diff --git a/src/H5Aint.c b/src/H5Aint.c index c50126a..a89c1c9 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -150,32 +150,21 @@ H5A_compact_build_table_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, /* Re-allocate the table if necessary */ if(udata->curr_attr == udata->atable->nattrs) { - size_t i; - size_t n = MAX(1, 2 * udata->atable->nattrs); - H5A_t **table = (H5A_t **)H5FL_SEQ_CALLOC(H5A_t_ptr, n); - - /* Use attribute functions for operation */ - for(i=0; i<udata->atable->nattrs; i++) { - table[i] = (H5A_t *)H5FL_CALLOC(H5A_t); - if(NULL == H5A_copy(table[i], udata->atable->attrs[i])) - HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") - if(H5A_close(udata->atable->attrs[i]) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, H5_ITER_ERROR, "can't close attribute") - } - - if(udata->atable->nattrs) - udata->atable->attrs = (H5A_t **)H5FL_SEQ_FREE(H5A_t_ptr, udata->atable->attrs); + H5A_t **new_table; /* New table for attributes */ + size_t new_table_size; /* Number of attributes in new table */ - if(!table) + /* Allocate larger table */ + new_table_size = MAX(1, 2 * udata->atable->nattrs); + if(NULL == (new_table = (H5A_t **)H5FL_SEQ_REALLOC(H5A_t_ptr, udata->atable->attrs, new_table_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "unable to extend attribute table") - udata->atable->attrs = table; - udata->atable->nattrs = n; + + /* Update table information in user data */ + udata->atable->attrs = new_table; + udata->atable->nattrs = new_table_size; } /* end if */ /* Copy attribute into table */ - udata->atable->attrs[udata->curr_attr] = (H5A_t *)H5FL_CALLOC(H5A_t); - - if(NULL == H5A_copy(udata->atable->attrs[udata->curr_attr], (const H5A_t *)mesg->native)) + if(NULL == (udata->atable->attrs[udata->curr_attr] = H5A_copy(NULL, (const H5A_t *)mesg->native))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") /* Assign [somewhat arbitrary] creation order value, if requested */ @@ -944,7 +933,7 @@ H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_si HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Check if we need to convert data */ - if(H5T_detect_class(attr_src->shared->dt, H5T_VLEN) > 0) { + if(H5T_detect_class(attr_src->shared->dt, H5T_VLEN, FALSE) > 0) { H5T_path_t *tpath_src_mem, *tpath_mem_dst; /* Datatype conversion paths */ H5T_t *dt_mem; /* Memory datatype */ size_t src_dt_size; /* Source datatype size */ @@ -1760,7 +1760,7 @@ done: H5B_shared_t * H5B_shared_new(const H5F_t *f, const H5B_class_t *type, size_t sizeof_rkey) { - H5B_shared_t *shared; /* New shared B-tree struct */ + H5B_shared_t *shared = NULL; /* New shared B-tree struct */ size_t u; /* Local index variable */ H5B_shared_t *ret_value; /* Return value */ @@ -1772,8 +1772,8 @@ H5B_shared_new(const H5F_t *f, const H5B_class_t *type, size_t sizeof_rkey) HDassert(type); /* Allocate space for the shared structure */ - if(NULL == (shared = H5FL_MALLOC(H5B_shared_t))) - HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "memory allocation failed for shared B-tree info") + if(NULL == (shared = H5FL_CALLOC(H5B_shared_t))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for shared B-tree info") /* Set up the "global" information for this file's groups */ shared->type = type; @@ -1788,12 +1788,12 @@ H5B_shared_new(const H5F_t *f, const H5B_class_t *type, size_t sizeof_rkey) /* Allocate shared buffers */ if(NULL == (shared->page = H5FL_BLK_MALLOC(page, shared->sizeof_rnode))) - HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree page") + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for B-tree page") #ifdef H5_CLEAR_MEMORY HDmemset(shared->page, 0, shared->sizeof_rnode); #endif /* H5_CLEAR_MEMORY */ if(NULL == (shared->nkey = H5FL_SEQ_MALLOC(size_t, (size_t)(shared->two_k + 1)))) - HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree page") + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for B-tree native keys") /* Initialize the offsets into the native key buffer */ for(u = 0; u < (shared->two_k + 1); u++) @@ -1803,6 +1803,15 @@ HDmemset(shared->page, 0, shared->sizeof_rnode); ret_value = shared; done: + if(NULL == ret_value) + if(shared) { + if(shared->page) + shared->page = H5FL_BLK_FREE(page, shared->page); + if(shared->nkey) + shared->nkey = H5FL_SEQ_FREE(size_t, shared->nkey); + shared = H5FL_FREE(H5B_shared_t, shared); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5B_shared_new() */ @@ -9814,12 +9814,8 @@ H5C__autoadjust__ageout__insert_new_marker(H5C_t * cache_ptr) i++; } - HDassert( i < H5C__MAX_EPOCH_MARKERS ); - - if ( (cache_ptr->epoch_marker_active)[i] != FALSE ) { - + if(i >= H5C__MAX_EPOCH_MARKERS) HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Can't find unused marker.") - } HDassert( ((cache_ptr->epoch_markers)[i]).addr == (haddr_t)i ); HDassert( ((cache_ptr->epoch_markers)[i]).next == NULL ); diff --git a/src/H5Dbtree.c b/src/H5Dbtree.c index 2c13677..d9cde4b 100644 --- a/src/H5Dbtree.c +++ b/src/H5Dbtree.c @@ -1492,8 +1492,9 @@ done: /* Free the raw B-tree node buffer */ if(NULL == storage.u.btree.shared) HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "ref-counted page nil") - if(H5RC_DEC(storage.u.btree.shared) < 0) - HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "unable to decrement ref-counted page") + else + if(H5RC_DEC(storage.u.btree.shared) < 0) + HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "unable to decrement ref-counted page") } /* end if */ FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 5b1703a..95334af 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -2480,6 +2480,7 @@ H5D_chunk_flush_entry(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t * done: /* Free the temp buffer only if it's different than the entry chunk */ if(buf != ent->chunk) + /* coverity["double_free"] */ H5MM_xfree(buf); /* @@ -4256,7 +4257,7 @@ H5D_chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) /* Check parameter for type conversion */ if(udata->do_convert) { - if(H5T_detect_class(udata->dt_src, H5T_VLEN) > 0) + if(H5T_detect_class(udata->dt_src, H5T_VLEN, FALSE) > 0) is_vlen = TRUE; else if((H5T_get_class(udata->dt_src, FALSE) == H5T_REFERENCE) && (udata->file_src != udata->idx_info_dst->f)) fix_ref = TRUE; @@ -4502,7 +4503,7 @@ H5D_chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype") /* If there's a VLEN source datatype, set up type conversion information */ - if(H5T_detect_class(dt_src, H5T_VLEN) > 0) { + if(H5T_detect_class(dt_src, H5T_VLEN, FALSE) > 0) { H5T_t *dt_dst; /* Destination datatype */ H5T_t *dt_mem; /* Memory datatype */ size_t mem_dt_size; /* Memory datatype size */ @@ -4514,16 +4515,22 @@ H5D_chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, /* create a memory copy of the variable-length datatype */ if(NULL == (dt_mem = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") - if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) + if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) { + (void)H5T_close(dt_mem); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register memory datatype") + } /* end if */ /* create variable-length datatype at the destinaton file */ if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") - if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) + if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) { + (void)H5T_close(dt_dst); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") - if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) + } /* end if */ + if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) { + (void)H5T_close(dt_dst); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register destination file datatype") + } /* end if */ /* Set up the conversion functions */ if(NULL == (tpath_src_mem = H5T_path_find(dt_src, dt_mem, NULL, NULL, dxpl_id, FALSE))) @@ -4553,7 +4560,7 @@ H5D_chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, /* Atomize */ if((sid_buf = H5I_register(H5I_DATASPACE, buf_space, FALSE)) < 0) { - H5S_close(buf_space); + (void)H5S_close(buf_space); HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID") } /* end if */ diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index f66e955..22f29e8 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -422,7 +422,7 @@ H5D_compact_copy(H5F_t *f_src, H5O_storage_compact_t *storage_src, H5F_t *f_dst, HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register source file datatype") /* If there's a VLEN source datatype, do type conversion information */ - if(H5T_detect_class(dt_src, H5T_VLEN) > 0) { + if(H5T_detect_class(dt_src, H5T_VLEN, FALSE) > 0) { H5T_path_t *tpath_src_mem, *tpath_mem_dst; /* Datatype conversion paths */ H5T_t *dt_dst; /* Destination datatype */ H5T_t *dt_mem; /* Memory datatype */ diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index 3e88be6..282cecb 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -1275,7 +1275,7 @@ H5D_contig_copy(H5F_t *f_src, const H5O_storage_contig_t *storage_src, HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype") /* If there's a VLEN source datatype, set up type conversion information */ - if(H5T_detect_class(dt_src, H5T_VLEN) > 0) { + if(H5T_detect_class(dt_src, H5T_VLEN, FALSE) > 0) { /* create a memory copy of the variable-length datatype */ if(NULL == (dt_mem = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") diff --git a/src/H5Dfill.c b/src/H5Dfill.c index bacaca2..2f3f112 100644 --- a/src/H5Dfill.c +++ b/src/H5Dfill.c @@ -240,7 +240,7 @@ H5D_fill(const void *fill, const H5T_t *fill_type, void *buf, * then do conversion on each element so that each of them has a copy * of the VL data. */ - if(TRUE == H5T_detect_class(fill_type, H5T_VLEN)) { + if(TRUE == H5T_detect_class(fill_type, H5T_VLEN, FALSE)) { H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */ H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ H5S_sel_iter_t mem_iter; /* Memory selection iteration info */ @@ -397,7 +397,7 @@ H5D_fill_init(H5D_fill_buf_info_t *fb_info, void *caller_fill_buf, htri_t has_vlen_type; /* Whether the datatype has a VL component */ /* Detect whether the datatype has a VL component */ - if((has_vlen_type = H5T_detect_class(dset_type, H5T_VLEN)) < 0) + if((has_vlen_type = H5T_detect_class(dset_type, H5T_VLEN, FALSE)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "unable to detect vlen datatypes?") fb_info->has_vlen_fill_type = (hbool_t)has_vlen_type; diff --git a/src/H5Dint.c b/src/H5Dint.c index 85d421a..f9329b6 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -736,7 +736,7 @@ H5D_update_oh_info(H5F_t *file, hid_t dxpl_id, H5D_t *dset, hid_t dapl_id) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't tell if fill value defined") /* Special case handling for variable-length types */ - if(H5T_detect_class(type, H5T_VLEN)) { + if(H5T_detect_class(type, H5T_VLEN, FALSE)) { /* If the default fill value is chosen for variable-length types, always write it */ if(fill_prop->fill_time == H5D_FILL_TIME_IFSET && fill_status == H5D_FILL_VALUE_DEFAULT) { /* Update dataset creation property */ @@ -927,7 +927,7 @@ H5D_create(H5F_t *file, hid_t type_id, const H5S_t *space, hid_t dcpl_id, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "datatype is not sensible") /* Check if the datatype is/contains a VL-type */ - if(H5T_detect_class(type, H5T_VLEN)) + if(H5T_detect_class(type, H5T_VLEN, FALSE)) has_vl_type = TRUE; /* Check if the dataspace has an extent set (or is NULL) */ diff --git a/src/H5Dio.c b/src/H5Dio.c index 62d2177..406b5ce 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -485,7 +485,7 @@ H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, /* If MPI based VFD is used, no VL datatype support yet. */ /* This is because they use the global heap in the file and we don't */ /* support parallel access of that yet */ - if(H5T_detect_class(type_info.mem_type, H5T_VLEN) > 0) + if(H5T_detect_class(type_info.mem_type, H5T_VLEN, FALSE) > 0) HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "Parallel IO does not support writing VL datatypes yet") /* If MPI based VFD is used, no VL datatype support yet. */ @@ -543,7 +543,7 @@ H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "can't retrieve number of elements in file dataset") /* Always allow fill values to be written if the dataset has a VL datatype */ - if(H5T_detect_class(dataset->shared->type, H5T_VLEN)) + if(H5T_detect_class(dataset->shared->type, H5T_VLEN, FALSE)) full_overwrite = FALSE; else full_overwrite = (hbool_t)((hsize_t)file_nelmts == nelmts ? TRUE : FALSE); @@ -751,7 +751,7 @@ H5D_typeinfo_init(const H5D_t *dset, const H5D_dxpl_cache_t *dxpl_cache, type_info->cmpd_subset = H5T_path_compound_subset(type_info->tpath); /* Check if we need a background buffer */ - if(do_write && H5T_detect_class(dset->shared->type, H5T_VLEN)) + if(do_write && H5T_detect_class(dset->shared->type, H5T_VLEN, FALSE)) type_info->need_bkg = H5T_BKG_YES; else { H5T_bkg_t path_bkg; /* Type conversion's background info */ @@ -69,6 +69,8 @@ static size_t H5F_get_objects(const H5F_t *f, unsigned types, size_t max_objs, h static int H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key); static H5F_t *H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id, H5FD_t *lf); +static herr_t H5F_build_actual_name(const H5F_t *f, const H5P_genplist_t *fapl, + const char *name, char ** /*out*/ actual_name); static herr_t H5F_dest(H5F_t *f, hid_t dxpl_id); static herr_t H5F_close(H5F_t *f); @@ -1142,7 +1144,8 @@ H5F_dest(H5F_t *f, hid_t dxpl_id) *------------------------------------------------------------------------- */ H5F_t * -H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t dxpl_id) +H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, + hid_t dxpl_id) { H5F_t *file = NULL; /*the success return value */ H5F_file_t *shared = NULL; /*shared part of `file' */ @@ -1319,7 +1322,7 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t d HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to build extpath") /* Formulate the actual file name, after following symlinks, etc. */ - if(H5F_build_actual_name(file, name, &file->actual_name) < 0) + if(H5F_build_actual_name(file, a_plist, name, &file->actual_name) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to build actual name") /* Success */ @@ -2170,15 +2173,18 @@ H5F_decr_nopen_objs(H5F_t *f) * *------------------------------------------------------------------------- */ -herr_t -H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out*/) +static herr_t +H5F_build_actual_name(const H5F_t *f, const H5P_genplist_t *fapl, const char *name, + char **actual_name/*out*/) { + hid_t new_fapl_id = -1; /* ID for duplicated FAPL */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5F_build_actual_name) /* Sanity check */ HDassert(f); + HDassert(fapl); HDassert(name); HDassert(actual_name); @@ -2199,10 +2205,12 @@ H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out* /* Check for symbolic link */ if(S_IFLNK == (lst.st_mode & S_IFMT)) { + H5P_genplist_t *new_fapl; /* Duplicated FAPL */ int *fd; /* POSIX I/O file descriptor */ h5_stat_t st; /* Stat info from stat() call */ h5_stat_t fst; /* Stat info from fstat() call */ char realname[PATH_MAX]; /* Fully resolved path name of file */ + hbool_t want_posix_fd; /* Flag for retrieving file descriptor from VFD */ /* Perform a sanity check that the file or link wasn't switched * between when we opened it and when we called lstat(). This is @@ -2210,8 +2218,19 @@ H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out* * here: https://www.securecoding.cert.org/confluence/display/seccode/POS35-C.+Avoid+race+conditions+while+checking+for+the+existence+of+a+symbolic+link */ + /* Copy the FAPL object to modify */ + if((new_fapl_id = H5P_copy_plist(fapl, FALSE)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "unable to copy file access property list") + if(NULL == (new_fapl = (H5P_genplist_t *)H5I_object(new_fapl_id))) + HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, FAIL, "can't get property list") + + /* Set the character encoding on the new property list */ + want_posix_fd = TRUE; + if(H5P_set(new_fapl, H5F_ACS_WANT_POSIX_FD_NAME, &want_posix_fd) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set character encoding") + /* Retrieve the file handle */ - if(H5F_get_vfd_handle(f, H5P_DEFAULT, (void **)&fd) < 0) + if(H5F_get_vfd_handle(f, new_fapl_id, (void **)&fd) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve POSIX file descriptor") /* Stat the filename we're resolving */ @@ -2245,6 +2264,9 @@ H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out* } /* end else */ done: + if(new_fapl_id > 0 && H5Pclose(new_fapl_id) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, FAIL, "can't close duplicated FAPL") + FUNC_LEAVE_NOAPI(ret_value) } /* H5F_build_actual_name() */ diff --git a/src/H5FDcore.c b/src/H5FDcore.c index bd77199..15f4094 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -401,29 +401,29 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, FUNC_ENTER_NOAPI(H5FD_core_open, NULL) /* Check arguments */ - if (!name || !*name) + if(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name") - if (0==maxaddr || HADDR_UNDEF==maxaddr) + if(0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr") if(ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "maxaddr overflow") - assert(H5P_DEFAULT != fapl_id); - if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") - fa = (H5FD_core_fapl_t *)H5P_get_driver_info(plist); + HDassert(H5P_DEFAULT != fapl_id); + if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") + fa = (H5FD_core_fapl_t *)H5P_get_driver_info(plist); /* Build the open flags */ o_flags = (H5F_ACC_RDWR & flags) ? O_RDWR : O_RDONLY; - if (H5F_ACC_TRUNC & flags) o_flags |= O_TRUNC; - if (H5F_ACC_CREAT & flags) o_flags |= O_CREAT; - if (H5F_ACC_EXCL & flags) o_flags |= O_EXCL; + if(H5F_ACC_TRUNC & flags) o_flags |= O_TRUNC; + if(H5F_ACC_CREAT & flags) o_flags |= O_CREAT; + if(H5F_ACC_EXCL & flags) o_flags |= O_EXCL; /* Open backing store. The only case that backing store is off is when * the backing_store flag is off and H5F_ACC_CREAT is on. */ if(fa->backing_store || !(H5F_ACC_CREAT & flags)) { - if (fa && (fd=HDopen(name, o_flags, 0666))<0) + if(fa && (fd = HDopen(name, o_flags, 0666)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") - } + } /* end if */ /* Create the new file struct */ if(NULL == (file = (H5FD_core_t *)H5MM_calloc(sizeof(H5FD_core_t)))) @@ -444,39 +444,38 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, /* If an existing file is opened, load the whole file into memory. */ if(!(H5F_ACC_CREAT & flags)) { - unsigned char *x=NULL; size_t size; - if (HDfstat(file->fd, &sb)<0) + /* stat() file to retrieve its size */ + if(HDfstat(file->fd, &sb) < 0) HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file") - size = (size_t)sb.st_size; + /* Check if we should allocate the memory buffer and read in existing data */ if(size) { - if (NULL==file->mem) - x = (unsigned char*)H5MM_malloc(size); - - if (!x) + /* Allocate memory for the file's data */ + if(NULL == (file->mem = (unsigned char*)H5MM_malloc(size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory block") - file->mem = x; + /* Set up data structures */ file->eof = size; - if(HDread(file->fd, file->mem, size)<0) + /* Read in existing data */ + if(HDread(file->fd, file->mem, size) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read file") - } - } + } /* end if */ + } /* end if */ /* Check for SWMR reader access */ if(flags & H5F_ACC_SWMR_READ) file->swmr_read = TRUE; /* Set return value */ - ret_value=(H5FD_t *)file; + ret_value = (H5FD_t *)file; done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5FD_core_open() */ /*------------------------------------------------------------------------- @@ -583,13 +582,12 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t -H5FD_core_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */) +H5FD_core_query(const H5FD_t * _file, unsigned long *flags /* out */) { - herr_t ret_value = SUCCEED; /* Return value */ + const H5FD_core_t *file = (const H5FD_core_t*)_file; - FUNC_ENTER_NOAPI(H5FD_core_query, FAIL) + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_core_query) /* Set the VFL feature flags that this driver supports */ if(flags) { @@ -598,10 +596,13 @@ H5FD_core_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */) *flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */ *flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */ *flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */ + + /* If the backing store is open, a POSIX file handle is available */ + if(file->fd >= 0 && file->backing_store) + *flags |= H5FD_FEAT_POSIX_COMPAT_HANDLE; /* VFD handle is POSIX I/O call compatible */ } /* end if */ -done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FD_core_query() */ @@ -629,9 +630,8 @@ done: static haddr_t H5FD_core_get_eoa(const H5FD_t *_file, H5FD_mem_t UNUSED type) { - haddr_t ret_value; /* Return value */ - const H5FD_core_t *file = (const H5FD_core_t*)_file; + haddr_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5FD_core_get_eoa, HADDR_UNDEF) @@ -733,23 +733,52 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t -H5FD_core_get_handle(H5FD_t *_file, hid_t UNUSED fapl, void** file_handle) +H5FD_core_get_handle(H5FD_t *_file, hid_t fapl, void** file_handle) { - H5FD_core_t *file = (H5FD_core_t *)_file; - herr_t ret_value = SUCCEED; + H5FD_core_t *file = (H5FD_core_t *)_file; /* core VFD info */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5FD_core_get_handle, FAIL) + /* Check args */ if(!file_handle) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file handle not valid") - *file_handle = &(file->mem); + /* Check for non-default FAPL */ + if(H5P_FILE_ACCESS_DEFAULT != fapl && H5P_DEFAULT != fapl) { + H5P_genplist_t *plist; /* Property list pointer */ + + /* Get the FAPL */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl))) + HGOTO_ERROR(H5E_VFL, H5E_BADTYPE, FAIL, "not a file access property list") + + /* Check if private property for retrieving the backing store POSIX + * file descriptor is set. (This should not be set except within the + * library) QAK - 2009/12/04 + */ + if(H5P_exist_plist(plist, H5F_ACS_WANT_POSIX_FD_NAME) > 0) { + hbool_t want_posix_fd; /* Setting for retrieving file descriptor from core VFD */ + + /* Get property */ + if(H5P_get(plist, H5F_ACS_WANT_POSIX_FD_NAME, &want_posix_fd) < 0) + HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't get property of retrieving file descriptor") + + /* If property is set, pass back the file descriptor instead of the memory address */ + if(want_posix_fd) + *file_handle = &(file->fd); + else + *file_handle = &(file->mem); + } /* end if */ + else + *file_handle = &(file->mem); + } /* end if */ + else + *file_handle = &(file->mem); done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5FD_core_get_handle() */ /*------------------------------------------------------------------------- diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index 9817270..87e5e84 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -818,9 +818,11 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, /* Enlarge member array */ if(file->nmembs >= file->amembs) { unsigned n = MAX(64, 2 * file->amembs); - H5FD_t **x = (H5FD_t **)H5MM_realloc(file->memb, n * sizeof(H5FD_t *)); + H5FD_t **x; - if(!x) + HDassert(n > 0); + /* coverity["freed_arg"] */ + if(NULL == (x = (H5FD_t **)H5MM_realloc(file->memb, n * sizeof(H5FD_t *)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to reallocate members") file->amembs = n; file->memb = x; diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index 324f489..ab2bc72 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -331,19 +331,18 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static H5FD_t * H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) { - int o_flags; - int fd=(-1); - H5FD_sec2_t *file=NULL; + H5FD_sec2_t *file = NULL; /* sec2 VFD info */ + int fd = (-1); /* File descriptor */ + int o_flags; /* Flags for open() call */ #ifdef _WIN32 HFILE filehandle; struct _BY_HANDLE_FILE_INFORMATION fileinfo; #endif h5_stat_t sb; - H5FD_t *ret_value; + H5FD_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5FD_sec2_open, NULL) @@ -432,9 +431,11 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) ret_value = (H5FD_t*)file; done: - if(ret_value==NULL) { - if(fd>=0) + if(NULL == ret_value) { + if(fd >= 0) HDclose(fd); + if(file) + file = H5FL_FREE(H5FD_sec2_t, file); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) @@ -471,7 +472,7 @@ H5FD_sec2_close(H5FD_t *_file) HSYS_GOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file") /* Release the file info */ - (void)H5FL_FREE(H5FD_sec2_t, file); + file = H5FL_FREE(H5FD_sec2_t, file); done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index e86a99e..29f3aa7 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -380,6 +380,7 @@ typedef struct H5F_blk_aggr_t H5F_blk_aggr_t; #define H5F_ACS_FAMILY_TO_SEC2_NAME "family_to_sec2" /* Whether to convert family to sec2 driver. (private property only used by h5repart) */ #define H5F_ACS_MULTI_TYPE_NAME "multi_type" /* Data type in multi file driver */ #define H5F_ACS_LATEST_FORMAT_NAME "latest_format" /* 'Use latest format version' flag */ +#define H5F_ACS_WANT_POSIX_FD_NAME "want_posix_fd" /* Internal: query the file descriptor from the core VFD, instead of the memory address */ /* ======================== File Mount properties ====================*/ #define H5F_MNT_SYM_LOCAL_NAME "local" /* Whether absolute symlinks local to file. */ @@ -475,8 +476,6 @@ H5_DLL H5F_t *H5F_open(const char *name, unsigned flags, hid_t fcpl_id, H5_DLL herr_t H5F_try_close(H5F_t *f); H5_DLL unsigned H5F_incr_nopen_objs(H5F_t *f); H5_DLL unsigned H5F_decr_nopen_objs(H5F_t *f); -H5_DLL herr_t H5F_build_actual_name(const H5F_t *f, const char *, - char ** /*out*/ ); /* Functions than retrieve values from the file struct */ H5_DLL unsigned H5F_get_intent(const H5F_t *f); diff --git a/src/H5Fsuper_cache.c b/src/H5Fsuper_cache.c index 1f2de6d..f7a35b9 100644 --- a/src/H5Fsuper_cache.c +++ b/src/H5Fsuper_cache.c @@ -111,7 +111,8 @@ H5FL_EXTERN(H5F_super_t); *------------------------------------------------------------------------- */ static H5F_super_t * -H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void *udata2/*out*/) +H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t UNUSED addr, const void UNUSED *udata1, + void *udata2/*out*/) { H5F_super_t *sblock = NULL; /* File's superblock */ haddr_t base_addr = HADDR_UNDEF; /* Base address of file */ @@ -609,6 +610,11 @@ H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 ret_value = sblock; done: + /* Release the [possibly partially initialized] superblock on errors */ + if(!ret_value && sblock) + if(H5F_sblock_dest(f, sblock) < 0) + HDONE_ERROR(H5E_FILE, H5E_CANTFREE, NULL, "unable to destroy superblock data") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5F_sblock_load() */ @@ -628,7 +634,8 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5F_super_t *sblock) +H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t UNUSED addr, + H5F_super_t *sblock) { herr_t ret_value = SUCCEED; diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 971c514..ad068ad 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -234,6 +234,21 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned UNUSED mesg_fl ret_value = attr; done: + if(NULL == ret_value) { + if(attr) { + if(attr->shared) { + /* Free any dynamicly allocated items */ + if(H5A_free(attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, NULL, "can't release attribute info") + + /* Destroy shared attribute struct */ + attr->shared = H5FL_FREE(H5A_shared_t, attr->shared); + } /* end if */ + } /* end if */ + + attr = H5FL_FREE(H5A_t, attr); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_attr_decode() */ diff --git a/src/H5Ofill.c b/src/H5Ofill.c index 8cf901f..d133a0a 100644 --- a/src/H5Ofill.c +++ b/src/H5Ofill.c @@ -689,7 +689,7 @@ H5O_fill_reset_dyn(H5O_fill_t *fill) HDassert(fill); if(fill->buf) { - if(fill->type && H5T_detect_class(fill->type, H5T_VLEN) > 0) { + if(fill->type && H5T_detect_class(fill->type, H5T_VLEN, FALSE) > 0) { H5T_t *fill_type; /* Copy of fill value datatype */ H5S_t *fill_space; /* Scalar dataspace for fill value element */ diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index e082e9c..486bda3 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -101,18 +101,23 @@ #define H5F_ACS_FAMILY_OFFSET_DEF 0 /* Definition for new member size of family driver. It's private * property only used by h5repart */ -#define H5F_ACS_FAMILY_NEWSIZE_SIZE sizeof(hsize_t) -#define H5F_ACS_FAMILY_NEWSIZE_DEF 0 +#define H5F_ACS_FAMILY_NEWSIZE_SIZE sizeof(hsize_t) +#define H5F_ACS_FAMILY_NEWSIZE_DEF 0 /* Definition for whether to convert family to sec2 driver. It's private * property only used by h5repart */ -#define H5F_ACS_FAMILY_TO_SEC2_SIZE sizeof(hbool_t) -#define H5F_ACS_FAMILY_TO_SEC2_DEF FALSE +#define H5F_ACS_FAMILY_TO_SEC2_SIZE sizeof(hbool_t) +#define H5F_ACS_FAMILY_TO_SEC2_DEF FALSE /* Definition for data type in multi file driver */ #define H5F_ACS_MULTI_TYPE_SIZE sizeof(H5FD_mem_t) #define H5F_ACS_MULTI_TYPE_DEF H5FD_MEM_DEFAULT /* Definition for 'use latest format version' flag */ #define H5F_ACS_LATEST_FORMAT_SIZE sizeof(hbool_t) #define H5F_ACS_LATEST_FORMAT_DEF FALSE +/* Definition for whether to query the file descriptor from the core VFD + * instead of the memory address. (Private to library) + */ +#define H5F_ACS_WANT_POSIX_FD_SIZE sizeof(hbool_t) +#define H5F_ACS_WANT_POSIX_FD_DEF FALSE /******************/ @@ -204,6 +209,7 @@ H5P_facc_reg_prop(H5P_genclass_t *pclass) hbool_t family_to_sec2 = H5F_ACS_FAMILY_TO_SEC2_DEF; /* Default ?? for family VFD */ H5FD_mem_t mem_type = H5F_ACS_MULTI_TYPE_DEF; /* Default file space type for multi VFD */ hbool_t latest_format = H5F_ACS_LATEST_FORMAT_DEF; /* Default setting for "use the latest version of the format" flag */ + hbool_t want_posix_fd = H5F_ACS_WANT_POSIX_FD_DEF; /* Default setting for retrieving 'handle' from core VFD */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5P_facc_reg_prop) @@ -280,6 +286,11 @@ H5P_facc_reg_prop(H5P_genclass_t *pclass) if(H5P_register(pclass, H5F_ACS_LATEST_FORMAT_NAME, H5F_ACS_LATEST_FORMAT_SIZE, &latest_format, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + /* Register the private property of whether to retrieve the file descriptor from the core VFD */ + /* (used internally to the library only) */ + if(H5P_register(pclass, H5F_ACS_WANT_POSIX_FD_NAME, H5F_ACS_WANT_POSIX_FD_SIZE, &want_posix_fd, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P_facc_reg_prop() */ diff --git a/src/H5Pint.c b/src/H5Pint.c index 4da7f09..7111cba 100644 --- a/src/H5Pint.c +++ b/src/H5Pint.c @@ -619,7 +619,7 @@ done: REVISION LOG --------------------------------------------------------------------------*/ hid_t -H5P_copy_plist(H5P_genplist_t *old_plist, hbool_t app_ref) +H5P_copy_plist(const H5P_genplist_t *old_plist, hbool_t app_ref) { H5P_genclass_t *tclass; /* Temporary class pointer */ H5P_genplist_t *new_plist=NULL; /* New property list generated from copy */ diff --git a/src/H5Pprivate.h b/src/H5Pprivate.h index 0b37938..f544dbc 100644 --- a/src/H5Pprivate.h +++ b/src/H5Pprivate.h @@ -58,7 +58,7 @@ H5_DLL herr_t H5P_init(void); /* Internal versions of API routines */ H5_DLL herr_t H5P_close(void *_plist); H5_DLL hid_t H5P_create_id(H5P_genclass_t *pclass, hbool_t app_ref); -H5_DLL hid_t H5P_copy_plist(H5P_genplist_t *old_plist, hbool_t app_ref); +H5_DLL hid_t H5P_copy_plist(const H5P_genplist_t *old_plist, hbool_t app_ref); H5_DLL herr_t H5P_get(const H5P_genplist_t *plist, const char *name, void *value); H5_DLL herr_t H5P_set(H5P_genplist_t *plist, const char *name, const void *value); H5_DLL herr_t H5P_insert(H5P_genplist_t *plist, const char *name, size_t size, @@ -1913,12 +1913,9 @@ H5Tdetect_class(hid_t type, H5T_class_t cls) if(!(cls > H5T_NO_CLASS && cls < H5T_NCLASSES)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a datatype class") - /* Set return value. Consider VL string as a string for API, as a VL for - * internal use. */ - if(H5T_IS_VL_STRING(dt->shared)) - ret_value = (H5T_STRING == cls); - else - ret_value = H5T_detect_class(dt, cls); + /* Set return value */ + if((ret_value = H5T_detect_class(dt, cls, TRUE)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5T_NO_CLASS, "can't get datatype class") done: FUNC_LEAVE_API(ret_value) @@ -1937,11 +1934,18 @@ done: * Wednesday, November 29, 2000 * * Modifications: - * + * Raymond Lu + * 4 December 2009 + * Added a flag as a parameter to indicate whether the caller is + * H5Tdetect_class. I also added the check for VL string type + * just like the public function. Because we want to tell users + * VL string is a string type but we treat it as a VL type + * internally, H5T_detect_class needs to know where the caller + * is from. *------------------------------------------------------------------------- */ htri_t -H5T_detect_class (const H5T_t *dt, H5T_class_t cls) +H5T_detect_class(const H5T_t *dt, H5T_class_t cls, hbool_t from_api) { unsigned i; htri_t ret_value=FALSE; /* Return value */ @@ -1951,6 +1955,14 @@ H5T_detect_class (const H5T_t *dt, H5T_class_t cls) assert(dt); assert(cls>H5T_NO_CLASS && cls<H5T_NCLASSES); + /* Consider VL string as a string for API, as a VL for internal use. */ + /* (note that this check must be performed before checking if the VL + * string belongs to the H5T_VLEN class, which would otherwise return + * true. -QAK) + */ + if(from_api && H5T_IS_VL_STRING(dt->shared)) + HGOTO_DONE(H5T_STRING == cls); + /* Check if this type is the correct type */ if(dt->shared->type==cls) HGOTO_DONE(TRUE); @@ -1967,7 +1979,7 @@ H5T_detect_class (const H5T_t *dt, H5T_class_t cls) /* Recurse if it's VL, compound, enum or array */ if(H5T_IS_COMPLEX(dt->shared->u.compnd.memb[i].type->shared->type)) - if((nested_ret=H5T_detect_class(dt->shared->u.compnd.memb[i].type,cls))!=FALSE) + if((nested_ret=H5T_detect_class(dt->shared->u.compnd.memb[i].type, cls, from_api))!=FALSE) HGOTO_DONE(nested_ret); } /* end for */ break; @@ -1975,7 +1987,7 @@ H5T_detect_class (const H5T_t *dt, H5T_class_t cls) case H5T_ARRAY: case H5T_VLEN: case H5T_ENUM: - HGOTO_DONE(H5T_detect_class(dt->shared->parent,cls)); + HGOTO_DONE(H5T_detect_class(dt->shared->parent, cls, from_api)); default: break; @@ -3816,84 +3828,85 @@ H5T_get_size(const H5T_t *dt) * Programmer: Robb Matzke * Wednesday, December 10, 1997 * - * Modifications: - * Robb Matzke, 22 Dec 1998 - * Able to compare enumeration data types. - * - * Robb Matzke, 20 May 1999 - * Compares bitfields and opaque types. - * - * Quincey Koziol, 19 Mar 2005 - * Allow an enumerated datatypes to compare equal, if the "superset" - * flag is set and dt2 has a superset of the enumerated values in dt1 *------------------------------------------------------------------------- */ int H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset) { unsigned *idx1 = NULL, *idx2 = NULL; - int ret_value = 0; + size_t base_size; + hbool_t swapped; int i, j; unsigned u; int tmp; - hbool_t swapped; - size_t base_size; + int ret_value = 0; - FUNC_ENTER_NOAPI(H5T_cmp, 0); + FUNC_ENTER_NOAPI(H5T_cmp, 0) + /* Sanity check */ + HDassert(dt1); + HDassert(dt2); + /* the easy case */ - if (dt1 == dt2) HGOTO_DONE(0); - assert(dt1); - assert(dt2); + if(dt1 == dt2) + HGOTO_DONE(0); /* compare */ - if (dt1->shared->type < dt2->shared->type) HGOTO_DONE(-1); - if (dt1->shared->type > dt2->shared->type) HGOTO_DONE(1); - - if (dt1->shared->size < dt2->shared->size) HGOTO_DONE(-1); - if (dt1->shared->size > dt2->shared->size) HGOTO_DONE(1); - - if (dt1->shared->parent && !dt2->shared->parent) HGOTO_DONE(-1); - if (!dt1->shared->parent && dt2->shared->parent) HGOTO_DONE(1); - if (dt1->shared->parent) { + if(dt1->shared->type < dt2->shared->type) + HGOTO_DONE(-1); + if(dt1->shared->type > dt2->shared->type) + HGOTO_DONE(1); + + if(dt1->shared->size < dt2->shared->size) + HGOTO_DONE(-1); + if(dt1->shared->size > dt2->shared->size) + HGOTO_DONE(1); + + if(dt1->shared->parent && !dt2->shared->parent) + HGOTO_DONE(-1); + if(!dt1->shared->parent && dt2->shared->parent) + HGOTO_DONE(1); + if(dt1->shared->parent) { tmp = H5T_cmp(dt1->shared->parent, dt2->shared->parent, superset); - if (tmp<0) HGOTO_DONE(-1); - if (tmp>0) HGOTO_DONE(1); - } + if(tmp < 0) + HGOTO_DONE(-1); + if(tmp > 0) + HGOTO_DONE(1); + } /* end if */ switch(dt1->shared->type) { case H5T_COMPOUND: /* * Compound data types... */ - if (dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs) + if(dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs) HGOTO_DONE(-1); - if (dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs) + if(dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs) HGOTO_DONE(1); /* Build an index for each type so the names are sorted */ - if (NULL==(idx1 = H5MM_malloc(dt1->shared->u.compnd.nmembs * sizeof(unsigned))) || - NULL==(idx2 = H5MM_malloc(dt2->shared->u.compnd.nmembs * sizeof(unsigned)))) + if(NULL == (idx1 = H5MM_malloc(dt1->shared->u.compnd.nmembs * sizeof(unsigned))) || + NULL == (idx2 = H5MM_malloc(dt2->shared->u.compnd.nmembs * sizeof(unsigned)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed"); - for (u=0; u<dt1->shared->u.compnd.nmembs; u++) + for(u = 0; u < dt1->shared->u.compnd.nmembs; u++) idx1[u] = idx2[u] = u; if(dt1->shared->u.enumer.nmembs > 1) { - for (i=dt1->shared->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i) - for (j=0, swapped=FALSE; j<i; j++) - if (HDstrcmp(dt1->shared->u.compnd.memb[idx1[j]].name, - dt1->shared->u.compnd.memb[idx1[j+1]].name) > 0) { + for(i = dt1->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i) + for(j = 0, swapped=FALSE; j < i; j++) + if(HDstrcmp(dt1->shared->u.compnd.memb[idx1[j]].name, + dt1->shared->u.compnd.memb[idx1[j + 1]].name) > 0) { tmp = idx1[j]; - idx1[j] = idx1[j+1]; - idx1[j+1] = tmp; + idx1[j] = idx1[j + 1]; + idx1[j + 1] = tmp; swapped = TRUE; } - for (i=dt2->shared->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i) - for (j=0, swapped=FALSE; j<i; j++) - if (HDstrcmp(dt2->shared->u.compnd.memb[idx2[j]].name, - dt2->shared->u.compnd.memb[idx2[j+1]].name) > 0) { + for(i = dt2->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i) + for(j = 0, swapped = FALSE; j<i; j++) + if(HDstrcmp(dt2->shared->u.compnd.memb[idx2[j]].name, + dt2->shared->u.compnd.memb[idx2[j + 1]].name) > 0) { tmp = idx2[j]; - idx2[j] = idx2[j+1]; - idx2[j+1] = tmp; + idx2[j] = idx2[j + 1]; + idx2[j + 1] = tmp; swapped = TRUE; } } /* end if */ @@ -4212,13 +4225,13 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset) } /* end switch */ done: - if(idx1!=NULL) + if(NULL != idx1) H5MM_xfree(idx1); - if(idx2!=NULL) + if(NULL != idx2) H5MM_xfree(idx2); - FUNC_LEAVE_NOAPI(ret_value); -} + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_cmp() */ /*------------------------------------------------------------------------- @@ -5124,7 +5137,7 @@ H5T_is_relocatable(const H5T_t *dt) HDassert(dt); /* VL and reference datatypes are relocatable */ - if(H5T_detect_class(dt, H5T_VLEN) || H5T_detect_class(dt, H5T_REFERENCE)) + if(H5T_detect_class(dt, H5T_VLEN, FALSE) || H5T_detect_class(dt, H5T_REFERENCE, FALSE)) ret_value = TRUE; done: diff --git a/src/H5Tcompound.c b/src/H5Tcompound.c index db7a701b..48192d2 100644 --- a/src/H5Tcompound.c +++ b/src/H5Tcompound.c @@ -403,7 +403,7 @@ H5Tpack(hid_t type_id) H5TRACE1("e", "i", type_id); /* Check args */ - if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)) || H5T_detect_class(dt, H5T_COMPOUND) <= 0) + if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)) || H5T_detect_class(dt, H5T_COMPOUND, TRUE) <= 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound datatype") /* Pack */ @@ -534,7 +534,7 @@ H5T_pack(const H5T_t *dt) HDassert(dt); - if(H5T_detect_class(dt, H5T_COMPOUND) > 0) { + if(H5T_detect_class(dt, H5T_COMPOUND, FALSE) > 0) { /* If datatype has been packed, skip packing it and indicate success */ if(TRUE == H5T_is_packed(dt)) HGOTO_DONE(SUCCEED) diff --git a/src/H5Tconv.c b/src/H5Tconv.c index ab9e703..ecf93e1 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -2996,7 +2996,7 @@ H5T_conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, noop_conv = TRUE; /* Check if we need a temporary buffer for this conversion */ - parent_is_vlen = H5T_detect_class(dst->shared->parent, H5T_VLEN); + parent_is_vlen = H5T_detect_class(dst->shared->parent, H5T_VLEN, FALSE); if(tpath->cdata.need_bkg || parent_is_vlen) { /* Set up initial background buffer */ tmp_buf_size = MAX(src_base_size,dst_base_size); diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index 9189f04..afa6ceb 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -111,7 +111,7 @@ H5_DLL herr_t H5T_lock(H5T_t *dt, hbool_t immutable); H5_DLL herr_t H5T_close(H5T_t *dt); H5_DLL H5T_t *H5T_get_super(const H5T_t *dt); H5_DLL H5T_class_t H5T_get_class(const H5T_t *dt, htri_t internal); -H5_DLL htri_t H5T_detect_class(const H5T_t *dt, H5T_class_t cls); +H5_DLL htri_t H5T_detect_class(const H5T_t *dt, H5T_class_t cls, hbool_t from_api); H5_DLL size_t H5T_get_size(const H5T_t *dt); H5_DLL int H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset); H5_DLL herr_t H5T_debug(const H5T_t *dt, FILE * stream); diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c index c0bcd70..c490720 100644 --- a/src/H5Zdeflate.c +++ b/src/H5Zdeflate.c @@ -78,6 +78,11 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, FUNC_ENTER_NOAPI(H5Z_filter_deflate, 0) + /* Sanity check */ + HDassert(*buf_size > 0); + HDassert(buf); + HDassert(*buf); + /* Check arguments */ if (cd_nelmts!=1 || cd_values[0]>9) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid deflate aggression level") diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index 2b35786..1a6988f 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -335,29 +335,29 @@ H5Z_unget_token(H5Z_token *current) /*------------------------------------------------------------------------- * Function: H5Z_get_token + * * Purpose: Determine what the next valid H5Z_token is in the expression * string. The current position within the H5Z_token string is * kept internal to the H5Z_token and handled by this and the * unget_H5Z_token function. + * * Return: Succeess: The passed in H5Z_token with a valid tok_type * field. * Failure: The passed in H5Z_token but with the tok_type * field set to ERROR. + * * Programmer: Bill Wendling * 26. August 2003 - * Modifications: - * Leon Arber: Added FUNC_ENTER / FUNC_LEAVE pairs + * *------------------------------------------------------------------------- */ static H5Z_token * H5Z_get_token(H5Z_token *current) { - - void* ret_value=current; + void *ret_value = current; FUNC_ENTER_NOAPI(H5Z_get_token, NULL) - /* check args */ assert(current); @@ -463,11 +463,11 @@ H5Z_get_token(H5Z_token *current) if (current->tok_begin[0] == '\0') current->tok_type = H5Z_XFORM_END; - HGOTO_DONE(current); + /* Set return value */ + ret_value = (void *)current; done: FUNC_LEAVE_NOAPI(ret_value) - } @@ -498,17 +498,17 @@ H5Z_xform_destroy_parse_tree(H5Z_node *tree) FUNC_LEAVE_NOAPI_VOID } - /*------------------------------------------------------------------------- * Function: H5Z_parse + * * Purpose: Entry function for parsing the expression string. + * * Return: Success: Valid H5Z_node ptr to an expression tree. * NULLure: NULL + * * Programmer: Bill Wendling * 26. August 2003 - * Modifications: - * Leon Arber: Added FUNC_ENTER / FUNC_LEAVE pairs * *------------------------------------------------------------------------- */ @@ -518,11 +518,10 @@ H5Z_xform_parse(const char *expression, H5Z_datval_ptrs* dat_val_pointers) H5Z_token tok; void* ret_value; - FUNC_ENTER_NOAPI_NOFUNC(H5Z_xform_parse) - - if (!expression) - HGOTO_DONE(NULL) + FUNC_ENTER_NOAPI(H5Z_xform_parse, NULL) + if(!expression) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "No expression provided?") /* Set up the initial H5Z_token for parsing */ tok.tok_expr = tok.tok_begin = tok.tok_end = expression; @@ -573,7 +572,7 @@ H5Z_parse_expression(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) if (!new_node) { H5Z_xform_destroy_parse_tree(expr); - HGOTO_DONE(expr) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") } new_node->lchild = expr; @@ -592,7 +591,7 @@ H5Z_parse_expression(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) if (!new_node) { H5Z_xform_destroy_parse_tree(expr); - HGOTO_DONE(expr) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") } new_node->lchild = expr; @@ -643,7 +642,7 @@ static H5Z_node * H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) { H5Z_node *term = NULL; - void* ret_value; + H5Z_node *ret_value; FUNC_ENTER_NOAPI(H5Z_parse_term, NULL); term = H5Z_parse_factor(current, dat_val_pointers); @@ -659,7 +658,7 @@ H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) if (!new_node) { H5Z_xform_destroy_parse_tree(term); - HGOTO_DONE(term) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") } new_node->lchild = term; @@ -678,7 +677,7 @@ H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) if (!new_node) { H5Z_xform_destroy_parse_tree(term); - HGOTO_DONE(term) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") } new_node->lchild = term; @@ -744,7 +743,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) factor = H5Z_new_node(H5Z_XFORM_INTEGER); if (!factor) - HGOTO_DONE(factor) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") sscanf(current->tok_begin, "%ld", &factor->value.int_val); break; @@ -752,7 +751,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) factor = H5Z_new_node(H5Z_XFORM_FLOAT); if (!factor) - HGOTO_DONE(factor) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") sscanf(current->tok_begin, "%lf", &factor->value.float_val); break; @@ -760,7 +759,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) factor = H5Z_new_node(H5Z_XFORM_SYMBOL); if (!factor) - HGOTO_DONE(factor) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") factor->value.dat_val = &(dat_val_pointers->ptr_dat_val[dat_val_pointers->num_ptrs]); dat_val_pointers->num_ptrs++; @@ -770,7 +769,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) factor = H5Z_parse_expression(current, dat_val_pointers); if (!factor) - HGOTO_DONE(factor) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node") current = H5Z_get_token(current); diff --git a/src/H5public.h b/src/H5public.h index 7a9c948..3244800 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -71,10 +71,10 @@ extern "C" { /* Version numbers */ #define H5_VERS_MAJOR 1 /* For major interface/format changes */ #define H5_VERS_MINOR 9 /* For minor interface/format changes */ -#define H5_VERS_RELEASE 52 /* For tweaks, bug-fixes, or development */ +#define H5_VERS_RELEASE 54 /* For tweaks, bug-fixes, or development */ #define H5_VERS_SUBRELEASE "FA_a4" /* For pre-releases like snap0 */ /* Empty string for real releases. */ -#define H5_VERS_INFO "HDF5 library version: 1.9.52-FA_a4" /* Full version string */ +#define H5_VERS_INFO "HDF5 library version: 1.9.54-FA_a4" /* Full version string */ #define H5check() H5check_version(H5_VERS_MAJOR,H5_VERS_MINOR, \ H5_VERS_RELEASE) diff --git a/test/btree2.c b/test/btree2.c index fb24433..eabd208 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -2770,7 +2770,7 @@ test_insert_lots(hid_t fapl, const H5B2_create_t *cparam, curr_time=1109170019; HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); #endif /* QAK */ - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); /* * Test inserting many records into v2 B-tree @@ -6445,7 +6445,7 @@ test_remove_lots(const char *env_h5_drvr, hid_t fapl, const H5B2_create_t *cpara curr_time = 1163537969; HDfprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); #endif /* QAK */ - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); /* * Test removing many records into v2 B-tree diff --git a/test/cmpd_dset.c b/test/cmpd_dset.c index b154f51..d565e82 100644 --- a/test/cmpd_dset.c +++ b/test/cmpd_dset.c @@ -1998,9 +1998,10 @@ error: static int test_ooo_order(char *filename) { - hid_t file; /* File ID */ - hid_t dtype, dtype_tmp; /* Datatype IDs */ - H5T_t *dt; /* Datatype pointer */ + hid_t file = -1; /* File ID */ + hid_t dtype = -1; /* Datatype IDs */ + hid_t dtype_tmp = -1; /* Temp Datatype ID */ + H5T_t *dt = NULL; /* Datatype pointer */ TESTING("that compound member insertion order is preserved") diff --git a/test/dsets.c b/test/dsets.c index 07ee0d0..84b40bb 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -743,7 +743,9 @@ test_max_compact(hid_t fapl) compact_size = (SIXTY_FOUR_KB-64)/sizeof(int); wbuf = (int*)HDmalloc(sizeof(int)*(size_t)compact_size); + assert(wbuf); rbuf = (int*)HDmalloc(sizeof(int)*(size_t)compact_size); + assert(rbuf); n=0; for(i=0; i<(int)compact_size; i++) @@ -800,8 +802,9 @@ test_max_compact(hid_t fapl) if(H5Dclose(dataset) < 0) goto error; if(H5Fclose(file) < 0) goto error; HDfree(wbuf); + wbuf = NULL; HDfree(rbuf); - + rbuf = NULL; /* Test compact dataset of size 64KB */ @@ -835,6 +838,19 @@ test_max_compact(hid_t fapl) return 0; error: + if(wbuf) + HDfree(wbuf); + if(rbuf) + HDfree(rbuf); + + H5E_BEGIN_TRY { + /* Close file */ + H5Sclose(space); + H5Pclose(plist); + H5Fclose(file); + H5Dclose(dataset); + } H5E_END_TRY; + return -1; } @@ -1006,10 +1022,10 @@ error: static herr_t test_tconv(hid_t file) { - char *out=NULL, *in=NULL; - int i; + char *out = NULL, *in = NULL; hsize_t dims[1]; - hid_t space, dataset; + hid_t space = -1, dataset = -1; + int i; out = (char *)HDmalloc((size_t)(4 * 1000 * 1000)); HDassert(out); @@ -1020,11 +1036,11 @@ test_tconv(hid_t file) /* Initialize the dataset */ for(i = 0; i < 1000000; i++) { - out[i*4+0] = 0x11; - out[i*4+1] = 0x22; - out[i*4+2] = 0x33; - out[i*4+3] = 0x44; - } + out[i * 4 + 0] = 0x11; + out[i * 4 + 1] = 0x22; + out[i * 4 + 2] = 0x33; + out[i * 4 + 3] = 0x44; + } /* end for */ /* Create the data space */ dims[0] = 1000000; @@ -1041,27 +1057,39 @@ test_tconv(hid_t file) /* Read data with byte order conversion */ if(H5Dread(dataset, H5T_STD_I32BE, H5S_ALL, H5S_ALL, H5P_DEFAULT, in) < 0) - goto error; + goto error; /* Check */ for(i = 0; i < 1000000; i++) { - if(in[4*i+0]!=out[4*i+3] || - in[4*i+1]!=out[4*i+2] || - in[4*i+2]!=out[4*i+1] || - in[4*i+3]!=out[4*i+0]) { - H5_FAILED(); - puts(" Read with byte order conversion failed."); - goto error; - } + if(in[4 * i + 0] != out[4 * i + 3] || + in[4 * i + 1] != out[4 * i + 2] || + in[4 * i + 2] != out[4 * i + 1] || + in[4 * i + 3] != out[4 * i + 0]) { + H5_FAILED(); + puts(" Read with byte order conversion failed."); + goto error; + } } if(H5Dclose(dataset) < 0) goto error; - free (out); - free (in); + if(H5Sclose(space) < 0) goto error; + HDfree(out); + HDfree(in); + puts(" PASSED"); return 0; - error: +error: + if(out) + HDfree(out); + if(in) + HDfree(in); + + H5E_BEGIN_TRY { + H5Dclose(dataset); + H5Sclose(space); + } H5E_END_TRY; + return -1; } @@ -1274,19 +1302,19 @@ filter_corrupt(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf) { - size_t ret_value = 0; + void *data; unsigned char *dst = (unsigned char*)(*buf); unsigned int offset; unsigned int length; unsigned int value; - void *data; + size_t ret_value = 0; - if(cd_nelmts!=3 || !cd_values) + if(cd_nelmts != 3 || !cd_values) return 0; offset = cd_values[0]; length = cd_values[1]; value = cd_values[2]; - if(offset>nbytes || (offset+length)>nbytes || length<sizeof(unsigned int)) + if(offset > nbytes || (offset + length) > nbytes || length < sizeof(unsigned int)) return 0; data = HDmalloc((size_t)length); @@ -1294,15 +1322,19 @@ filter_corrupt(unsigned int flags, size_t cd_nelmts, if(flags & H5Z_FLAG_REVERSE) { /* Varify data is actually corrupted during read */ dst += offset; - if(HDmemcmp(data, dst, (size_t)length)!=0) return 0; - *buf_size = nbytes; - ret_value = nbytes; - } else { /* Write corrupted data */ + if(HDmemcmp(data, dst, (size_t)length) != 0) + ret_value = 0; + else { + *buf_size = nbytes; + ret_value = nbytes; + } /* end else */ + } /* end if */ + else { /* Write corrupted data */ dst += offset; HDmemcpy(dst, data, (size_t)length); *buf_size = nbytes; - ret_value = *buf_size; - } + ret_value = *buf_size; + } /* end else */ if(data) HDfree(data); @@ -8218,7 +8250,7 @@ main(void) envval = "nomatch"; /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); /* Testing setup */ h5_reset(); diff --git a/test/dt_arith.c b/test/dt_arith.c index 43855a8..420570a 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -5218,7 +5218,7 @@ main(void) unsigned long nerrors = 0; /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); reset_hdf5(); diff --git a/test/dtypes.c b/test/dtypes.c index 2619f1b..04f526a 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -325,7 +325,10 @@ test_copy(void) * Saturday, August 30, 2003 * * Modifications: - * + * Raymond Lu + * 8 December 2009 + * I added a field of VL string in the compound type to test + * H5Tdetect_class correctly detect it as string type. *------------------------------------------------------------------------- */ static int @@ -342,6 +345,7 @@ test_detect(void) hobj_ref_t arr_r[3][3]; int i; hvl_t vl_f; + hvl_t vl_s; char c; short s; }; @@ -441,6 +445,7 @@ test_detect(void) if (H5Tinsert(cplx_cmpd_id, "arr_r", HOFFSET(struct complex, arr_r), atom_arr_id) < 0) TEST_ERROR if (H5Tinsert(cplx_cmpd_id, "i", HOFFSET(struct complex, i), H5T_NATIVE_INT) < 0) TEST_ERROR if (H5Tinsert(cplx_cmpd_id, "vl_f", HOFFSET(struct complex, vl_f), atom_vlf_id) < 0) TEST_ERROR + if (H5Tinsert(cplx_cmpd_id, "vl_s", HOFFSET(struct complex, vl_s), atom_vls_id) < 0) TEST_ERROR if (H5Tinsert(cplx_cmpd_id, "c", HOFFSET(struct complex, c), H5T_NATIVE_CHAR) < 0) TEST_ERROR if (H5Tinsert(cplx_cmpd_id, "s", HOFFSET(struct complex, s), H5T_NATIVE_SHORT) < 0) TEST_ERROR @@ -450,12 +455,12 @@ test_detect(void) if(H5Tdetect_class(cplx_cmpd_id,H5T_REFERENCE)!=TRUE) TEST_ERROR if(H5Tdetect_class(cplx_cmpd_id,H5T_INTEGER)!=TRUE) TEST_ERROR if(H5Tdetect_class(cplx_cmpd_id,H5T_FLOAT)!=TRUE) TEST_ERROR + if(H5Tdetect_class(cplx_cmpd_id,H5T_STRING)!=TRUE) TEST_ERROR if(H5Tdetect_class(cplx_cmpd_id,H5T_VLEN)!=TRUE) TEST_ERROR /* Make certain that an incorrect class is not detected */ if(H5Tdetect_class(cplx_cmpd_id,H5T_TIME)!=FALSE) TEST_ERROR if(H5Tdetect_class(cplx_cmpd_id,H5T_ENUM)!=FALSE) TEST_ERROR - if(H5Tdetect_class(cplx_cmpd_id,H5T_STRING)!=FALSE) TEST_ERROR /* Close complex compound datatype */ if(H5Tclose(cplx_cmpd_id) < 0) TEST_ERROR @@ -6332,7 +6337,7 @@ main(void) hid_t fapl = -1; /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); reset_hdf5(); fapl = h5_fileaccess(); diff --git a/test/external.c b/test/external.c index 25d465c..b3831ad 100644 --- a/test/external.c +++ b/test/external.c @@ -58,21 +58,23 @@ same_contents (const char *name1, const char *name2) fd1 = HDopen(name1, O_RDONLY, 0666); fd2 = HDopen(name2, O_RDONLY, 0666); - assert (fd1>=0 && fd2>=0); - - while (1) { - n1 = HDread(fd1, buf1, sizeof(buf1)); - n2 = HDread(fd2, buf2, sizeof(buf2)); - assert (n1>=0 && (size_t)n1<=sizeof(buf1)); - assert (n2>=0 && (size_t)n2<=sizeof(buf2)); - assert (n1==n2); - - if (n1<=0 && n2<=0) break; - if (memcmp (buf1, buf2, (size_t)n1)) { - HDclose(fd1); - HDclose(fd2); - return 0; - } + assert(fd1 >= 0 && fd2 >= 0); + + while(1) { + /* Asserts will catch negative return values */ + n1 = HDread(fd1, buf1, sizeof(buf1)); + n2 = HDread(fd2, buf2, sizeof(buf2)); + assert(n1 >= 0 && (size_t)n1 <= sizeof(buf1)); + assert(n2 >= 0 && (size_t)n2 <= sizeof(buf2)); + assert(n1 == n2); + + if(n1 == 0 && n2 == 0) + break; + if(HDmemcmp(buf1, buf2, (size_t)n1)) { + HDclose(fd1); + HDclose(fd2); + return 0; + } } HDclose(fd1); HDclose(fd2); @@ -838,10 +840,13 @@ test_3 (hid_t fapl) static int test_4 (hid_t fapl) { - hid_t fid, gid, xid, xid2; - char filename[1024]; /*file name */ - char pathname[1024]; - char *srcdir = getenv("srcdir"); /*where the src code is located*/ + hid_t fid = -1; + hid_t gid = -1; + hid_t xid = -1; + hid_t xid2 = -1; + char filename[1024]; /*file name */ + char pathname[1024]; + char *srcdir = getenv("srcdir"); /*where the src code is located*/ TESTING("opening external link twice"); @@ -911,7 +916,7 @@ test_4 (hid_t fapl) H5Gclose(gid); H5Gclose(xid); H5Gclose(xid2); - H5Fclose(fid); + H5Fclose(fid); } H5E_END_TRY; return 1; } diff --git a/test/hyperslab.c b/test/hyperslab.c index 194c0f6..b756449 100644 --- a/test/hyperslab.c +++ b/test/hyperslab.c @@ -1234,7 +1234,7 @@ main(int argc, char *argv[]) printf("\n"); /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); /* * Open the library explicitly for thread-safe builds, so per-thread diff --git a/test/istore.c b/test/istore.c index fff6706..fb0f3fc 100644 --- a/test/istore.c +++ b/test/istore.c @@ -596,7 +596,7 @@ main(int argc, char *argv[]) printf("\n"); /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); /* Reset library */ h5_reset(); diff --git a/test/links.c b/test/links.c index 37b03cf..deae5ef 100644 --- a/test/links.c +++ b/test/links.c @@ -3571,8 +3571,8 @@ external_set_elink_fapl1(hid_t fapl, hbool_t new_format) filename2B[NAME_BUF_SIZE], tmpname[NAME_BUF_SIZE], cwdpath[NAME_BUF_SIZE]; - hid_t fam_fapl, multi_fapl; - hid_t lapl_idA, lapl_idB; + hid_t fam_fapl=-1, multi_fapl=-1; + hid_t lapl_idA=-1, lapl_idB=-1; H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES]; hid_t memb_fapl[H5FD_MEM_NTYPES]; char sv[H5FD_MEM_NTYPES][500]; @@ -3769,11 +3769,11 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format) { hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group IDs */ + hid_t core_fapl = -1, space = -1, dset = -1, did = -1, dapl_id = -1, dcpl = -1; char filename1[NAME_BUF_SIZE], filename2[NAME_BUF_SIZE], tmpname[NAME_BUF_SIZE], cwdpath[NAME_BUF_SIZE]; - hid_t core_fapl, space, dset, did, dapl_id, dcpl; hsize_t dims[2]; int points[NUM40][NUM40]; h5_stat_size_t filesize, new_filesize; @@ -3806,8 +3806,8 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format) h5_fixname(FILENAME[39], core_fapl, filename2, sizeof filename2); /* Create the target file to be a "core" file */ - if((fid=H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, core_fapl)) < 0) TEST_ERROR - if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + if((fid = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, core_fapl)) < 0) TEST_ERROR + if((gid = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR dims[0] = NUM40; dims[1] = NUM40; @@ -3848,8 +3848,7 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format) /* try to open the external linked target dataset */ did = H5Dopen2(fid, "ext_link", dapl_id); - - if (did < 0) { + if(did < 0) { H5_FAILED(); puts(" Should succeed in opening the target dataset"); goto error; @@ -3871,7 +3870,7 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format) new_filesize = h5_get_file_size(filename2, core_fapl); /* the file size should remain the same since there is no backing store */ - if (new_filesize != filesize) TEST_ERROR + if(new_filesize != filesize) TEST_ERROR if(H5Pclose(core_fapl) < 0) TEST_ERROR @@ -3885,8 +3884,9 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format) H5Dclose(dset); H5Pclose(core_fapl); H5Pclose(dapl_id); - H5Dclose (did); - H5Fclose (fid); + H5Dclose(did); + H5Gclose(gid); + H5Fclose(fid); } H5E_END_TRY; return -1; } /* end external_set_elink_fapl2() */ @@ -3926,8 +3926,8 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format) static int external_set_elink_fapl3(hbool_t new_format) { - hid_t core_fapl, stdio_fapl; - hid_t lapl_id, new_lapl_id, l_fapl, out_fapl; + hid_t core_fapl = -1, stdio_fapl = -1; + hid_t lapl_id = -1, new_lapl_id = -1, l_fapl = -1, out_fapl; int ret; if(new_format) @@ -3950,43 +3950,43 @@ external_set_elink_fapl3(hbool_t new_format) /* Verify that the driver for the link's fapl is the "stdio" driver */ if((l_fapl = H5Pget_elink_fapl(lapl_id)) < 0) TEST_ERROR - if (H5Pget_driver(l_fapl) != H5FD_STDIO) TEST_ERROR - if (H5Pclose(l_fapl) < 0) TEST_ERROR + if(H5Pget_driver(l_fapl) != H5FD_STDIO) TEST_ERROR + if(H5Pclose(l_fapl) < 0) TEST_ERROR /* Set file access property list for link access to use the "core" driver */ if(H5Pset_elink_fapl(lapl_id, core_fapl) < 0) TEST_ERROR /* Make a copy of the link access property */ - if ((new_lapl_id = H5Pcopy(lapl_id)) < 0) TEST_ERROR + if((new_lapl_id = H5Pcopy(lapl_id)) < 0) TEST_ERROR /* get the fapl set in lapl_id */ - if (H5Pget(lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR - if (H5Pclose(lapl_id) < 0) TEST_ERROR + if(H5Pget(lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR + if(H5Pclose(lapl_id) < 0) TEST_ERROR /* Try closing out_fapl should fail since H5Pclose(lapl_id) should also close its fapl */ H5E_BEGIN_TRY { ret = H5Pclose(out_fapl); } H5E_END_TRY; - if (ret != FAIL) TEST_ERROR + if(ret != FAIL) TEST_ERROR /* Verify that the driver for the copied link's fapl is the "core" driver */ if((l_fapl = H5Pget_elink_fapl(new_lapl_id)) < 0) TEST_ERROR - if (H5Pget_driver(l_fapl) != H5FD_CORE) TEST_ERROR + if(H5Pget_driver(l_fapl) != H5FD_CORE) TEST_ERROR /* get the fapl set in new_lapl_id */ - if (H5Pget(new_lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR - if (H5Premove(new_lapl_id, "external link fapl") < 0) TEST_ERROR + if(H5Pget(new_lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR + if(H5Premove(new_lapl_id, "external link fapl") < 0) TEST_ERROR /* Try closing out_fapl should fail since the property is removed from new_lapl_id */ H5E_BEGIN_TRY { ret = H5Pclose(out_fapl); } H5E_END_TRY; - if (ret != FAIL) TEST_ERROR + if(ret != FAIL) TEST_ERROR - if (H5Pclose(l_fapl) < 0) TEST_ERROR - if (H5Pclose(new_lapl_id) < 0) TEST_ERROR - if (H5Pclose(core_fapl) < 0) TEST_ERROR - if (H5Pclose(stdio_fapl) < 0) TEST_ERROR + if(H5Pclose(l_fapl) < 0) TEST_ERROR + if(H5Pclose(new_lapl_id) < 0) TEST_ERROR + if(H5Pclose(core_fapl) < 0) TEST_ERROR + if(H5Pclose(stdio_fapl) < 0) TEST_ERROR PASSED(); return 0; @@ -4021,7 +4021,7 @@ external_set_elink_fapl3(hbool_t new_format) static int external_set_elink_acc_flags(hid_t fapl, hbool_t new_format) { - hid_t file1, file2, group, subgroup, gapl; + hid_t file1 = -1, file2 = -1, group = -1, subgroup = -1, gapl = -1; char filename1[NAME_BUF_SIZE], filename2[NAME_BUF_SIZE]; unsigned flags; @@ -4034,70 +4034,70 @@ external_set_elink_acc_flags(hid_t fapl, hbool_t new_format) /* Create parent and target files, and external link */ h5_fixname(FILENAME[40], fapl, filename1, sizeof filename1); h5_fixname(FILENAME[41], fapl, filename2, sizeof filename2); - if ((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - if ((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - if (H5Lcreate_external(filename2, "/", file1, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + if((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if(H5Lcreate_external(filename2, "/", file1, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR /* Close file2, leave file1 open (should be read-write) */ - if (H5Fclose(file2) < 0) TEST_ERROR + if(H5Fclose(file2) < 0) TEST_ERROR /* Create new gapl, and set elink access flags to be H5F_ACC_RDONLY */ - if ((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR - if (H5Pset_elink_acc_flags(gapl, H5F_ACC_RDONLY) < 0) TEST_ERROR + if((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR + if(H5Pset_elink_acc_flags(gapl, H5F_ACC_RDONLY) < 0) TEST_ERROR /* Verify "get" routine functionality */ - if (H5Pget_elink_acc_flags(gapl, &flags) < 0) TEST_ERROR - if (flags != H5F_ACC_RDONLY) TEST_ERROR + if(H5Pget_elink_acc_flags(gapl, &flags) < 0) TEST_ERROR + if(flags != H5F_ACC_RDONLY) TEST_ERROR /* Attempt to create a group through the external link using gapl (should fail) */ H5E_BEGIN_TRY { group = H5Gcreate2(file1, "/ext_link/group", H5P_DEFAULT, H5P_DEFAULT, gapl); } H5E_END_TRY; - if (group != FAIL) TEST_ERROR + if(group != FAIL) TEST_ERROR /* Close file1 and reopen with read only access */ - if (H5Fclose(file1) < 0) TEST_ERROR - if ((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR + if(H5Fclose(file1) < 0) TEST_ERROR + if((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Set elink access flags on gapl to be H5F_ACC_RDWR */ - if (H5Pset_elink_acc_flags(gapl, H5F_ACC_RDWR) < 0) TEST_ERROR + if(H5Pset_elink_acc_flags(gapl, H5F_ACC_RDWR) < 0) TEST_ERROR /* Create a group through the external link using gapl (should succeed) */ - if ((group = H5Gcreate2(file1, "/ext_link/group", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR + if((group = H5Gcreate2(file1, "/ext_link/group", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR /* Unset elink access flags on gapl */ - if (H5Pset_elink_acc_flags(gapl, H5F_ACC_DEFAULT) < 0) TEST_ERROR + if(H5Pset_elink_acc_flags(gapl, H5F_ACC_DEFAULT) < 0) TEST_ERROR /* Attempt to create a group through the external link using gapl (should fail) */ H5E_BEGIN_TRY { subgroup = H5Gcreate2(file1, "/ext_link/group/subgroup", H5P_DEFAULT, H5P_DEFAULT, gapl); } H5E_END_TRY; - if (subgroup != FAIL) TEST_ERROR + if(subgroup != FAIL) TEST_ERROR /* Close file1 and group */ - if (H5Gclose(group) < 0) TEST_ERROR - if (H5Fclose(file1) < 0) TEST_ERROR + if(H5Gclose(group) < 0) TEST_ERROR + if(H5Fclose(file1) < 0) TEST_ERROR /* Verify that H5Fcreate and H5Fopen reject H5F_ACC_DEFAULT */ H5E_BEGIN_TRY { file1 = H5Fcreate(filename1, H5F_ACC_DEFAULT, H5P_DEFAULT, fapl); } H5E_END_TRY; - if (file1 != FAIL) TEST_ERROR + if(file1 != FAIL) TEST_ERROR H5E_BEGIN_TRY { file1 = H5Fcreate(filename1, H5F_ACC_TRUNC | H5F_ACC_DEFAULT, H5P_DEFAULT, fapl); } H5E_END_TRY; - if (file1 != FAIL) TEST_ERROR + if(file1 != FAIL) TEST_ERROR H5E_BEGIN_TRY { file1 = H5Fopen(filename1, H5F_ACC_DEFAULT, fapl); } H5E_END_TRY; - if (file1 != FAIL) TEST_ERROR + if(file1 != FAIL) TEST_ERROR H5E_BEGIN_TRY { file1 = H5Fopen(filename1, H5F_ACC_RDWR | H5F_ACC_DEFAULT, fapl); } H5E_END_TRY; - if (file1 != FAIL) TEST_ERROR + if(file1 != FAIL) TEST_ERROR /* Close gapl */ - if (H5Pclose(gapl) < 0) TEST_ERROR + if(H5Pclose(gapl) < 0) TEST_ERROR PASSED(); return 0; @@ -4171,7 +4171,7 @@ external_set_elink_cb_cb(const char *parent_file, const char *parent_group, static int external_set_elink_cb(hid_t fapl, hbool_t new_format) { - hid_t file1, file2, group, gapl, fam_fapl, ret_fapl, base_driver; + hid_t file1 = -1, file2 = -1, group = -1, gapl = -1, fam_fapl = -1, ret_fapl = -1, base_driver; set_elink_cb_t op_data, *op_data_p; H5L_elink_traverse_t cb; @@ -4204,44 +4204,44 @@ external_set_elink_cb(hid_t fapl, hbool_t new_format) /* Create parent and target files, group, and external link */ h5_fixname(FILENAME[42], fapl, filename1, sizeof filename1); h5_fixname(FILENAME[43], fam_fapl, filename2, sizeof filename2); - if ((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - if ((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fam_fapl)) < 0) TEST_ERROR - if ((group = H5Gcreate2(file1, "group1",H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR - if (H5Lcreate_external(filename2, "/", group, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + if((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fam_fapl)) < 0) TEST_ERROR + if((group = H5Gcreate2(file1, "group1",H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + if(H5Lcreate_external(filename2, "/", group, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR /* Close files and group */ - if (H5Fclose(file1) < 0) TEST_ERROR - if (H5Fclose(file2) < 0) TEST_ERROR - if (H5Gclose(group) < 0) TEST_ERROR + if(H5Fclose(file1) < 0) TEST_ERROR + if(H5Fclose(file2) < 0) TEST_ERROR + if(H5Gclose(group) < 0) TEST_ERROR /* Create new gapl, and set elink callback */ - if ((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR - if (H5Pset_elink_cb(gapl, external_set_elink_cb_cb, &op_data) < 0) TEST_ERROR + if((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR + if(H5Pset_elink_cb(gapl, external_set_elink_cb_cb, &op_data) < 0) TEST_ERROR /* Verify "get" routine functionality */ - if (H5Pget_elink_cb(gapl, &cb, (void **) &op_data_p) < 0) TEST_ERROR - if (cb != external_set_elink_cb_cb) TEST_ERROR - if (op_data_p != &op_data) TEST_ERROR + if(H5Pget_elink_cb(gapl, &cb, (void **) &op_data_p) < 0) TEST_ERROR + if(cb != external_set_elink_cb_cb) TEST_ERROR + if(op_data_p != &op_data) TEST_ERROR /* Open file1 with read only access */ - if ((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR + if((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Create a group through the external link using gapl */ - if ((group = H5Gcreate2(file1, "/group1/ext_link/group2", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR + if((group = H5Gcreate2(file1, "/group1/ext_link/group2", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR /* Verify that the correct parameters have been set on file2 (somewhat * redundant as the library would be unable to create the group otherwise) */ - if ((file2 = H5Iget_file_id(group)) < 0) TEST_ERROR - if (H5Fget_intent(file2, &flags) < 0) TEST_ERROR - if (!(flags & H5F_ACC_RDWR)) TEST_ERROR - if ((ret_fapl = H5Fget_access_plist(file2)) < 0) TEST_ERROR - if (H5FD_FAMILY != H5Pget_driver(ret_fapl)) TEST_ERROR + if((file2 = H5Iget_file_id(group)) < 0) TEST_ERROR + if(H5Fget_intent(file2, &flags) < 0) TEST_ERROR + if(!(flags & H5F_ACC_RDWR)) TEST_ERROR + if((ret_fapl = H5Fget_access_plist(file2)) < 0) TEST_ERROR + if(H5FD_FAMILY != H5Pget_driver(ret_fapl)) TEST_ERROR - if (H5Gclose(group) < 0) TEST_ERROR - if (H5Fclose(file2) < 0) TEST_ERROR - if (H5Pclose(ret_fapl) < 0) TEST_ERROR - if (H5Pclose(fam_fapl) < 0) TEST_ERROR + if(H5Gclose(group) < 0) TEST_ERROR + if(H5Fclose(file2) < 0) TEST_ERROR + if(H5Pclose(ret_fapl) < 0) TEST_ERROR + if(H5Pclose(fam_fapl) < 0) TEST_ERROR /* Modify the user data structure to cause the callback to fail next time */ op_data.code = 1; @@ -4250,7 +4250,7 @@ external_set_elink_cb(hid_t fapl, hbool_t new_format) H5E_BEGIN_TRY { group = H5Gopen2(file1, "/group1/ext_link/group2", gapl); } H5E_END_TRY; - if (group != FAIL) TEST_ERROR + if(group != FAIL) TEST_ERROR /* Modify the user data structure to cause the callback to return invalid flags */ op_data.code = 2; @@ -4259,11 +4259,11 @@ external_set_elink_cb(hid_t fapl, hbool_t new_format) H5E_BEGIN_TRY { group = H5Gopen2(file1, "/group1/ext_link/group2", gapl); } H5E_END_TRY; - if (group != FAIL) TEST_ERROR + if(group != FAIL) TEST_ERROR /* Close */ - if (H5Fclose(file1) < 0) TEST_ERROR - if (H5Pclose(gapl) < 0) TEST_ERROR + if(H5Fclose(file1) < 0) TEST_ERROR + if(H5Pclose(gapl) < 0) TEST_ERROR PASSED(); return 0; @@ -6409,7 +6409,7 @@ error: *------------------------------------------------------------------------- */ static int -external_symlink(hid_t fapl, hbool_t new_format) +external_symlink(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) { #ifdef H5_HAVE_SYMLINK hid_t file1 = -1, file2 = -1, file3 = -1, file4 = -1, file5 = -1; @@ -6425,6 +6425,7 @@ external_symlink(hid_t fapl, hbool_t new_format) filename5b[NAME_BUF_SIZE], tmpname[NAME_BUF_SIZE], cwdpath[NAME_BUF_SIZE]; + hbool_t have_posix_compat_vfd; /* Whether VFD used is compatible w/POSIX I/O calls */ #endif /* H5_HAVE_SYMLINK */ if(new_format) @@ -6433,145 +6434,158 @@ external_symlink(hid_t fapl, hbool_t new_format) TESTING("external links w/symlink files") #ifdef H5_HAVE_SYMLINK - /* set up name for main file: "extlinks21A" */ - h5_fixname(FILENAME[45], fapl, filename1, sizeof(filename1)); + /* Skip test when using VFDs that can't provide a POSIX compatible file + * descriptor. + */ + have_posix_compat_vfd = (hbool_t)(!HDstrcmp(env_h5_drvr, "sec2") + || !HDstrcmp(env_h5_drvr, "core") + || !HDstrcmp(env_h5_drvr, "nomatch")); + if(have_posix_compat_vfd) { + /* set up name for main file: "extlinks21A" */ + h5_fixname(FILENAME[45], fapl, filename1, sizeof(filename1)); + + /* create tmp directory and get current working directory path */ + if(HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + if(HDmkdir(TMPDIR2, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + if(NULL == HDgetcwd(cwdpath, NAME_BUF_SIZE)) + TEST_ERROR - /* create tmp directory and get current working directory path */ - if(HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) - TEST_ERROR - if(HDmkdir(TMPDIR2, (mode_t)0755) < 0 && errno != EEXIST) - TEST_ERROR - if(NULL == HDgetcwd(cwdpath, NAME_BUF_SIZE)) - TEST_ERROR + /* Set up names for files in the subdirectories */ - /* Set up names for files in the subdirectories */ + /* set up names for file #2 in temporary directory #2: "tmp2/extlinks21B" */ + h5_fixname(FILENAME[46], fapl, filename2a, sizeof(filename2a)); + fix_ext_filename(tmpname, cwdpath, FILENAME[46]); + h5_fixname(tmpname, fapl, filename2b, sizeof(filename2b)); - /* set up names for file #2 in temporary directory #2: "tmp2/extlinks21B" */ - h5_fixname(FILENAME[46], fapl, filename2a, sizeof(filename2a)); - fix_ext_filename(tmpname, cwdpath, FILENAME[46]); - h5_fixname(tmpname, fapl, filename2b, sizeof(filename2b)); + /* Create symbolic link #1 in temporary directory #1 to file #2 in temporary directory #2 */ + /* (i.e. tmp/sym1.h5 -> <full path to>/tmp2/extlinks21B.h5) */ + if(HDsymlink(filename2b, SYMLINK1) < 0 && errno != EEXIST) TEST_ERROR - /* Create symbolic link #1 in temporary directory #1 to file #2 in temporary directory #2 */ - /* (i.e. tmp/sym1.h5 -> <full path to>/tmp2/extlinks21B.h5) */ - if(HDsymlink(filename2b, SYMLINK1) < 0 && errno != EEXIST) TEST_ERROR + /* set up name for file #3 in temporary directory #2: "tmp2/extlinks21C" */ + h5_fixname(FILENAME[47], fapl, filename3a, sizeof(filename3a)); + h5_fixname(FILENAME[48], fapl, filename3b, sizeof(filename3b)); - /* set up name for file #3 in temporary directory #2: "tmp2/extlinks21C" */ - h5_fixname(FILENAME[47], fapl, filename3a, sizeof(filename3a)); - h5_fixname(FILENAME[48], fapl, filename3b, sizeof(filename3b)); + /* set up name for file #4 in temporary directory #1: "tmp/extlinks21D" */ + h5_fixname(FILENAME[49], fapl, filename4a, sizeof(filename4a)); + fix_ext_filename(tmpname, cwdpath, FILENAME[49]); + h5_fixname(tmpname, fapl, filename4b, sizeof(filename4b)); - /* set up name for file #4 in temporary directory #1: "tmp/extlinks21D" */ - h5_fixname(FILENAME[49], fapl, filename4a, sizeof(filename4a)); - fix_ext_filename(tmpname, cwdpath, FILENAME[49]); - h5_fixname(tmpname, fapl, filename4b, sizeof(filename4b)); + /* Create symbolic link #2 in temporary directory #2 to file #4 in temporary directory #1 */ + /* (i.e. tmp2/sym2.h5 -> <full path to>/tmp/extlinks21D.h5) */ + if(HDsymlink(filename4b, SYMLINK2) < 0 && errno != EEXIST) TEST_ERROR - /* Create symbolic link #2 in temporary directory #2 to file #4 in temporary directory #1 */ - /* (i.e. tmp2/sym2.h5 -> <full path to>/tmp/extlinks21D.h5) */ - if(HDsymlink(filename4b, SYMLINK2) < 0 && errno != EEXIST) TEST_ERROR + /* set up name for file #5 in temporary directory #1: "tmp/extlinks21E" */ + h5_fixname(FILENAME[50], fapl, filename5a, sizeof(filename5a)); + h5_fixname(FILENAME[51], fapl, filename5b, sizeof(filename5b)); - /* set up name for file #5 in temporary directory #1: "tmp/extlinks21E" */ - h5_fixname(FILENAME[50], fapl, filename5a, sizeof(filename5a)); - h5_fixname(FILENAME[51], fapl, filename5b, sizeof(filename5b)); + /* Create file #1 in current directory */ + if((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - /* Create file #1 in current directory */ - if((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + /* Create external link to file & object in temporary directory #2, using symlink #1 name */ + if(H5Lcreate_external(SYMLINK1, "group2", file1, "extlink2-sym", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR - /* Create external link to file & object in temporary directory #2, using symlink #1 name */ - if(H5Lcreate_external(SYMLINK1, "group2", file1, "extlink2-sym", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + /* Close file #1 */ + if(H5Fclose(file1) < 0) TEST_ERROR - /* Close file #1 */ - if(H5Fclose(file1) < 0) TEST_ERROR + /* Create file #2 in tmp directory #2 */ + if((file2 = H5Fcreate(filename2a, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if(H5Fclose(file2) < 0) TEST_ERROR - /* Create file #2 in tmp directory #2 */ - if((file2 = H5Fcreate(filename2a, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - if(H5Fclose(file2) < 0) TEST_ERROR + /* Re-open file #2 in tmp directory through symlink */ + if((file2 = H5Fopen(SYMLINK1, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR - /* Re-open file #2 in tmp directory through symlink */ - if((file2 = H5Fopen(SYMLINK1, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR + /* Create group in file #2 in temporary directory */ + if((group2 = H5Gcreate2(file2, "group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR - /* Create group in file #2 in temporary directory */ - if((group2 = H5Gcreate2(file2, "group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + /* Create external link to file #3 & object in temporary directory #2 */ + if(H5Lcreate_external(filename3b, "group3", group2, "extlink3", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR - /* Create external link to file #3 & object in temporary directory #2 */ - if(H5Lcreate_external(filename3b, "group3", group2, "extlink3", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + /* Close group in file #2 */ + if(H5Gclose(group2) < 0) TEST_ERROR - /* Close group in file #2 */ - if(H5Gclose(group2) < 0) TEST_ERROR + /* Close file #2 */ + if(H5Fclose(file2) < 0) TEST_ERROR - /* Close file #2 */ - if(H5Fclose(file2) < 0) TEST_ERROR + /* Create file #3 in temp. directory #2 */ + if((file3 = H5Fcreate(filename3a, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - /* Create file #3 in temp. directory #2 */ - if((file3 = H5Fcreate(filename3a, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + /* Create group in file #3 */ + if((group3 = H5Gcreate2(file3, "group3", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR - /* Create group in file #3 */ - if((group3 = H5Gcreate2(file3, "group3", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + /* Create external link to file & object in temporary directory #1, using symlink #2 name */ + if(H5Lcreate_external(SYMLINK2, "group4", group3, "extlink4-sym", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR - /* Create external link to file & object in temporary directory #1, using symlink #2 name */ - if(H5Lcreate_external(SYMLINK2, "group4", group3, "extlink4-sym", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + /* Close group in file #3 */ + if(H5Gclose(group3) < 0) TEST_ERROR - /* Close group in file #3 */ - if(H5Gclose(group3) < 0) TEST_ERROR + /* Close file #3 */ + if(H5Fclose(file3) < 0) TEST_ERROR - /* Close file #3 */ - if(H5Fclose(file3) < 0) TEST_ERROR + /* Create file #4 in temporary directory #1 */ + if((file4 = H5Fcreate(filename4b, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - /* Create file #4 in temporary directory #1 */ - if((file4 = H5Fcreate(filename4b, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + /* Create group in file #4 in 'temporary' directory */ + if((group4 = H5Gcreate2(file4, "group4", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR - /* Create group in file #4 in 'temporary' directory */ - if((group4 = H5Gcreate2(file4, "group4", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + /* Create external link to file #5 & object in temporary directory #1 */ + if(H5Lcreate_external(filename5b, "group5", group4, "extlink5", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR - /* Create external link to file #5 & object in temporary directory #1 */ - if(H5Lcreate_external(filename5b, "group5", group4, "extlink5", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + /* Close group in file #4 */ + if(H5Gclose(group4) < 0) TEST_ERROR - /* Close group in file #4 */ - if(H5Gclose(group4) < 0) TEST_ERROR + /* Close file #4 */ + if(H5Fclose(file4) < 0) TEST_ERROR - /* Close file #4 */ - if(H5Fclose(file4) < 0) TEST_ERROR + /* Create file #5 in temporary directory #1 */ + if((file5 = H5Fcreate(filename5a, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - /* Create file #5 in temporary directory #1 */ - if((file5 = H5Fcreate(filename5a, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + /* Create group in file #5 in 'temporary' directory #1 */ + if((group5 = H5Gcreate2(file5, "group5", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + if(H5Gclose(group5) < 0) TEST_ERROR - /* Create group in file #5 in 'temporary' directory #1 */ - if((group5 = H5Gcreate2(file5, "group5", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR - if(H5Gclose(group5) < 0) TEST_ERROR + /* Close file #5 */ + if(H5Fclose(file5) < 0) TEST_ERROR - /* Close file #5 */ - if(H5Fclose(file5) < 0) TEST_ERROR + /* Actual tests... */ - /* Actual tests... */ + /* Reopen file #1 */ + if((file1 = H5Fopen(filename1, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR - /* Reopen file #1 */ - if((file1 = H5Fopen(filename1, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR + /* Open group in file #2, through external link w/symlink */ + if((group2 = H5Gopen2(file1, "extlink2-sym", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if(H5Gclose(group2) < 0) TEST_ERROR - /* Open group in file #2, through external link w/symlink */ - if((group2 = H5Gopen2(file1, "extlink2-sym", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR - if(H5Gclose(group2) < 0) TEST_ERROR + /* Open group in file #3, through external link w/symlink to external link */ + if((group3 = H5Gopen2(file1, "extlink2-sym/extlink3", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if(H5Gclose(group3) < 0) TEST_ERROR - /* Open group in file #3, through external link w/symlink to external link */ - if((group3 = H5Gopen2(file1, "extlink2-sym/extlink3", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR - if(H5Gclose(group3) < 0) TEST_ERROR + /* Open group in file #4, through external link w/symlink to external link w/symlink */ + if((group4 = H5Gopen2(file1, "extlink2-sym/extlink3/extlink4-sym", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if(H5Gclose(group4) < 0) TEST_ERROR - /* Open group in file #4, through external link w/symlink to external link w/symlink */ - if((group4 = H5Gopen2(file1, "extlink2-sym/extlink3/extlink4-sym", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR - if(H5Gclose(group4) < 0) TEST_ERROR + /* Open group in file #5, through external link w/symlink to external link w/symlink to external link */ + if((group5 = H5Gopen2(file1, "extlink2-sym/extlink3/extlink4-sym/extlink5", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if(H5Gclose(group5) < 0) TEST_ERROR - /* Open group in file #5, through external link w/symlink to external link w/symlink to external link */ - if((group5 = H5Gopen2(file1, "extlink2-sym/extlink3/extlink4-sym/extlink5", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR - if(H5Gclose(group5) < 0) TEST_ERROR + /* Close file #1 */ + if(H5Fclose(file1) < 0) TEST_ERROR - /* Close file #1 */ - if(H5Fclose(file1) < 0) TEST_ERROR + PASSED(); + } /* end if */ + else { + SKIPPED(); + puts(" Current VFD doesn't support POSIX I/O calls"); + } /* end else */ - PASSED(); return 0; error: @@ -13510,11 +13524,11 @@ main(void) hid_t fapl, fapl2; /* File access property lists */ int nerrors = 0; hbool_t new_format; /* Whether to use the new format or not */ - const char *envval; + const char *env_h5_drvr; /* File Driver value from environment */ - envval = HDgetenv("HDF5_DRIVER"); - if(envval == NULL) - envval = "nomatch"; + env_h5_drvr = HDgetenv("HDF5_DRIVER"); + if(env_h5_drvr == NULL) + env_h5_drvr = "nomatch"; h5_reset(); fapl = h5_fileaccess(); @@ -13557,8 +13571,8 @@ main(void) nerrors += external_link_path(my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_mult(my_fapl, new_format) < 0 ? 1 : 0; #ifndef H5_CANNOT_OPEN_TWICE - nerrors += external_link_self(envval, my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_pingpong(envval, my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_self(env_h5_drvr, my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_pingpong(env_h5_drvr, my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_toomany(my_fapl, new_format) < 0 ? 1 : 0; #endif /* H5_CANNOT_OPEN_TWICE */ nerrors += external_link_dangling(my_fapl, new_format) < 0 ? 1 : 0; @@ -13569,7 +13583,7 @@ main(void) nerrors += external_link_move(my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_ride(my_fapl, new_format) < 0 ? 1 : 0; #ifndef H5_CANNOT_OPEN_TWICE - nerrors += external_link_closing(envval, my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_closing(env_h5_drvr, my_fapl, new_format) < 0 ? 1 : 0; #endif /* H5_CANNOT_OPEN_TWICE */ nerrors += external_link_endian(new_format) < 0 ? 1 : 0; nerrors += external_link_strong(my_fapl, new_format) < 0 ? 1 : 0; @@ -13600,7 +13614,7 @@ main(void) nerrors += external_link_win8(my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_win9(my_fapl, new_format) < 0 ? 1 : 0; #endif - nerrors += external_symlink(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_symlink(env_h5_drvr, my_fapl, new_format) < 0 ? 1 : 0; /* These tests assume that external links are a form of UD links, * so assume that everything that passed for external links diff --git a/test/ntypes.c b/test/ntypes.c index a82f051..87484d9 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -23,8 +23,8 @@ #include "h5test.h" const char *FILENAME[] = { - "ntypes", - NULL + "ntypes", + NULL }; #define DIM0 100 @@ -60,6 +60,7 @@ int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5]; #define SPACE2_DIM1 10 #define SPACE2_DIM2 10 + /*------------------------------------------------------------------------- * Function: test_atomic_dtype @@ -80,11 +81,11 @@ int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5]; static herr_t test_atomic_dtype(hid_t file) { - hid_t dataset, space; - hid_t dtype, native_type; - int i, j, n; - hsize_t dims[2]; - void *tmp; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1; + int i, j, n; + hsize_t dims[2]; + void *tmp = NULL; TESTING("atomic datatype"); @@ -101,7 +102,8 @@ test_atomic_dtype(hid_t file) /*------------------- Test data values ------------------------*/ /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_1, H5T_STD_I32BE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Write the data to the dataset */ if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) @@ -127,18 +129,20 @@ test_atomic_dtype(hid_t file) TEST_ERROR; /* Read the dataset back. The temporary buffer is for special platforms - * like Cray. */ - tmp = malloc((size_t)(DIM0 * DIM1 * H5Tget_size(native_type))); + * like Cray. */ + if(NULL == (tmp = HDmalloc((size_t)(DIM0 * DIM1 * H5Tget_size(native_type))))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) TEST_ERROR; /* Copy data from temporary buffer to destination buffer */ - memcpy(icheck2, tmp, (size_t)(DIM0 * DIM1 * H5Tget_size(native_type))); - free(tmp); + HDmemcpy(icheck2, tmp, (size_t)(DIM0 * DIM1 * H5Tget_size(native_type))); + HDfree(tmp); + tmp = NULL; /* Convert to the integer type */ - if(H5Tconvert(native_type, H5T_NATIVE_INT, (DIM0*DIM1), icheck2, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, H5T_NATIVE_INT, (DIM0 * DIM1), icheck2, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -159,7 +163,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_STD_I64LE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_2, H5T_STD_I64LE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -181,7 +186,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_STD_I8LE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_3, H5T_STD_I8LE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -203,7 +209,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_IEEE_F32BE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_4, H5T_IEEE_F32BE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -225,7 +232,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_IEEE_F64BE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_5, H5T_IEEE_F64BE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -253,6 +261,16 @@ test_atomic_dtype(hid_t file) return 0; error: + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + H5Dclose(dataset); + H5Tclose(native_type); + H5Tclose(dtype); + H5Sclose(space); + } H5E_END_TRY; + return -1; } @@ -286,14 +304,14 @@ test_compound_dtype2(hid_t file) s2 st; unsigned long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid_m, tid_m2, - mem_id, nest_mem_id; - int i, j, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1, + tid_m2 = -1, mem_id = -1, nest_mem_id = -1; + int i, j, n; + hsize_t dims[2]; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL, *bkg = NULL; TESTING("nested compound datatype"); @@ -304,15 +322,15 @@ test_compound_dtype2(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for (i = n = 0, temp_point=points; i < DIM0; i++) { - for (j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->i = n++; - temp_point->st.c2 = (short)(i + j); - temp_point->st.l2 = (i * 5 + j * 50) * n; - temp_point->l = (unsigned long long)((i * 10 + j * 100) * n); - } - } + for(i = n = 0, temp_point = points; i < DIM0; i++) { + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->i = n++; + temp_point->st.c2 = (short)(i + j); + temp_point->st.l2 = (i * 5 + j * 50) * n; + temp_point->l = (unsigned long long)((i * 10 + j * 100) * n); + } /* end for */ + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -353,7 +371,8 @@ test_compound_dtype2(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_2, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for memory */ if((tid_m2 = H5Tcreate(H5T_COMPOUND, sizeof(s2))) < 0) TEST_ERROR; @@ -369,7 +388,7 @@ test_compound_dtype2(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -451,36 +470,39 @@ test_compound_dtype2(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0*DIM1*H5Tget_size(native_type)); - if((bkg=calloc(sizeof(s1),DIM0*DIM1))==NULL) + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) TEST_ERROR; if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; - free(bkg); + HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->i != temp_check->i || - temp_point->st.c2 != temp_check->st.c2 || - temp_point->st.l2 != temp_check->st.l2 || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - } - } + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) { + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) { + if(temp_point->c != temp_check->c || + temp_point->i != temp_check->i || + temp_point->st.c2 != temp_check->st.c2 || + temp_point->st.l2 != temp_check->st.l2 || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ + } /* end for */ + } /* end for */ /* Close temporary datatypes */ if(H5Tclose(tid2) < 0) TEST_ERROR; @@ -494,17 +516,35 @@ test_compound_dtype2(hid_t file) H5Tclose(tid_m); /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; error: - if(points!=NULL) - free(points); - if(check!=NULL) - free(check); + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + H5Tclose(tid_m2); + H5Sclose(space); + H5Tclose(mem_id); + H5Tclose(nest_mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + } H5E_END_TRY; + return -1; } @@ -533,17 +573,19 @@ test_compound_dtype(hid_t file) unsigned int i; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, mem_id; - int i, j, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points, *check; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, mem_id = -1; + int i, j, n; + hsize_t dims[2]; + s1 *temp_point = NULL; + s1 *temp_check = NULL; + s1 *points = NULL; + s1 *check = NULL; + void *tmp = NULL; + void *bkg = NULL; TESTING("compound datatype"); - /* Allocate space for the points & check arrays */ if(NULL == (points = (s1 *)HDmalloc(sizeof(s1) * DIM0 * DIM1))) TEST_ERROR; @@ -551,12 +593,12 @@ test_compound_dtype(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->i = (unsigned int)(n++); - temp_point->l = (i*10+j*100)*n; - } /* end for */ + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->i = (unsigned int)(n++); + temp_point->l = (i * 10 + j * 100) * n; + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -573,7 +615,8 @@ test_compound_dtype(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for datatype in memory */ if((tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR; @@ -583,7 +626,7 @@ test_compound_dtype(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -633,33 +676,35 @@ test_compound_dtype(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0*DIM1*H5Tget_size(native_type)); - bkg = calloc(sizeof(s1),DIM0*DIM1); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid2, (DIM0*DIM1), check, bkg, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid2, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; - free(bkg); + HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->i != temp_check->i || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - } - } + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) + if(temp_point->c != temp_check->c || + temp_point->i != temp_check->i || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ /* Close datatype */ if(H5Tclose(tid) < 0) TEST_ERROR; @@ -670,13 +715,33 @@ test_compound_dtype(hid_t file) H5Tclose(tid2); /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Tclose(tid); + H5Sclose(space); + H5Tclose(mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid2); + } H5E_END_TRY; + return -1; } @@ -705,15 +770,15 @@ test_compound_dtype3(hid_t file) int a[5]; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid_m, tid_m2, - mem_id, nest_mem_id; - hsize_t array_dims[1]={5}; - int i, j, k, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1, + tid_m2 = -1, mem_id = -1, nest_mem_id = -1; + hsize_t array_dims[1] = {5}; + int i, j, k, n; + hsize_t dims[2]; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL, *bkg = NULL; TESTING("compound datatype with array as field"); @@ -724,13 +789,13 @@ test_compound_dtype3(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->l = (i*10+j*100)*n; - for(k = 0; k < 5; k++) - (temp_point->a)[k] = n++; - } /* end for */ + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->l = (i * 10 + j * 100) * n; + for(k = 0; k < 5; k++) + (temp_point->a)[k] = n++; + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -750,7 +815,8 @@ test_compound_dtype3(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_3, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create array datatype */ if((tid_m2 = H5Tarray_create2(H5T_NATIVE_INT, 1, array_dims)) < 0) TEST_ERROR; @@ -763,7 +829,7 @@ test_compound_dtype3(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -825,42 +891,44 @@ test_compound_dtype3(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0*DIM1*H5Tget_size(native_type)); - if((bkg=calloc(sizeof(s1),DIM0*DIM1))==NULL) + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR; + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) TEST_ERROR; if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; - free(bkg); + HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - - for (k = 0; k < 5; k++) { + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) { + if(temp_point->c != temp_check->c || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ + + for(k = 0; k < 5; k++) { if(temp_point->a[k] != temp_check->a[k]) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d,%d\n", i, j, k); - goto error; - } - } - } - } + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d,%d\n", i, j, k); + goto error; + } /* end if */ + } /* end for */ + } /* end for */ H5Dclose(dataset); H5Tclose(dtype); @@ -869,13 +937,36 @@ test_compound_dtype3(hid_t file) H5Tclose(tid_m2); /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Tclose(mem_id); + H5Tclose(nest_mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + H5Tclose(tid_m2); + } H5E_END_TRY; + return -1; } @@ -904,14 +995,14 @@ test_compound_opaque(hid_t file) unsigned char o[5]; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid_m, - mem_id; - int i, j, k, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1, + mem_id = -1; + int i, j, k, n; + hsize_t dims[2]; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL, *bkg = NULL; TESTING("compound datatype with opaque field"); @@ -922,13 +1013,13 @@ test_compound_opaque(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->l = (i*10+j*100)*n; - for(k = 0; k < 5; k++) - (temp_point->o)[k] = (unsigned char)(n++); - } /* end for */ + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->l = (i * 10 + j * 100) * n; + for(k = 0; k < 5; k++) + (temp_point->o)[k] = (unsigned char)(n++); + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -949,7 +1040,8 @@ test_compound_opaque(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_4, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for datatype in memory */ if((tid_m = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR; @@ -959,7 +1051,7 @@ test_compound_opaque(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1014,42 +1106,44 @@ test_compound_opaque(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = HDmalloc(DIM0*DIM1*H5Tget_size(native_type)); - if((bkg=HDcalloc(sizeof(s1),DIM0*DIM1))==NULL) + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR; + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) TEST_ERROR; if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - HDmemcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - - for (k = 0; k < 5; k++) { + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) { + if(temp_point->c != temp_check->c || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ + + for(k = 0; k < 5; k++) { if(temp_point->o[k] != temp_check->o[k]) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d,%d\n", i, j, k); - goto error; - } - } - } - } + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d,%d\n", i, j, k); + goto error; + } /* end if */ + } /* end for */ + } /* end for */ H5Dclose(dataset); H5Tclose(dtype); @@ -1063,7 +1157,28 @@ test_compound_opaque(hid_t file) PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Tclose(mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1087,28 +1202,28 @@ test_compound_opaque(hid_t file) static herr_t test_enum_dtype(hid_t file) { - hid_t dataset, space; - hid_t tid, tid_m, dtype, native_type; - int i, j, n; - hsize_t dims[2]; - void *tmp; - short colors[8]; - unsigned char sub_colors[16]; - const char *mname[] = { "RED", - "GREEN", - "BLUE", - "YELLOW", - "PINK", - "PURPLE", - "ORANGE", - "WHITE" }; + hid_t dataset = -1, space = -1; + hid_t tid = -1, tid_m = -1, dtype = -1, native_type = -1; + int i, j, n; + hsize_t dims[2]; + void *tmp = NULL; + short colors[8]; + unsigned char sub_colors[16]; + const char *mname[] = { "RED", + "GREEN", + "BLUE", + "YELLOW", + "PINK", + "PURPLE", + "ORANGE", + "WHITE" }; TESTING("enum datatype"); /* Initialize the dataset */ for(i = 0; i < DIM0; i++) for(j = 0, n = 0; j < DIM1; j++, n++) - spoints2[i][j] = (short)((i * 10 + j * 100 + n) % 8); + spoints2[i][j] = (short)((i * 10 + j * 100 + n) % 8); /* Create the data space */ dims[0] = DIM0; @@ -1126,7 +1241,8 @@ test_enum_dtype(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ENUM_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Construct enum type based on native type in memory */ if((tid_m = H5Tenum_create(H5T_NATIVE_SHORT)) < 0) TEST_ERROR; @@ -1138,7 +1254,7 @@ test_enum_dtype(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, spoints2) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1159,30 +1275,30 @@ test_enum_dtype(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0 * DIM1 * H5Tget_size(native_type)); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(scheck2, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); - free(tmp); + HDmemcpy(scheck2, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), scheck2, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), scheck2, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ - for (i = 0; i < DIM0; i++) { - for (j = 0; j < DIM1; j++) { - if(spoints2[i][j] != scheck2[i][j]) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); + for(i = 0; i < DIM0; i++) + for(j = 0; j < DIM1; j++) + if(spoints2[i][j] != scheck2[i][j]) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); printf(" spoints2[i][j]=%hd, scheck2[i][j]=%hd\n", spoints2[i][j], scheck2[i][j]); - goto error; - } - } - } + goto error; + } /* end if */ H5Dclose(dataset); H5Tclose(dtype); @@ -1191,7 +1307,20 @@ test_enum_dtype(hid_t file) PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1220,13 +1349,13 @@ test_array_dtype(hid_t file) int i; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid3, tid_m; - int i, j, k, n; - hsize_t space_dims[2], array_dims[1]={5}; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid3 = -1, tid_m = -1; + int i, j, k, n; + hsize_t space_dims[2], array_dims[1]={5}; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL; TESTING("array of compound datatype"); @@ -1237,13 +1366,13 @@ test_array_dtype(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++) + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++) for(k = 0; k < 5; k++,temp_point++) { temp_point->c= 't'; temp_point->i= n++; - temp_point->l= (i*10+j*100)*n; - } + temp_point->l= (i * 10 + j * 100) * n; + } /* end for */ /* Create the data space */ space_dims[0] = DIM0; @@ -1263,7 +1392,8 @@ test_array_dtype(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ARRAY_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for datatype in memory */ if((tid3 = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR; @@ -1276,7 +1406,7 @@ test_array_dtype(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1298,32 +1428,31 @@ test_array_dtype(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++) { - for (k = 0; k < 5; k++, temp_point++,temp_check++) { + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++) + for(k = 0; k < 5; k++, temp_point++, temp_check++) if(temp_point->c != temp_check->c || - temp_point->i != temp_check->i || - temp_point->l != temp_check->l ) { + temp_point->i != temp_check->i || + temp_point->l != temp_check->l ) { H5_FAILED(); printf(" Read different values than written.\n"); printf(" At index %d,%d\n", i, j); goto error; - } - } - } - } + } /* end if */ /* Close HDF5 objects */ if(H5Dclose(dataset)) TEST_ERROR; @@ -1333,17 +1462,32 @@ test_array_dtype(hid_t file) if(H5Tclose(tid3) < 0) TEST_ERROR; /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; error: - if(points!=NULL) - free(points); - if(check!=NULL) - free(check); + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid3); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1367,17 +1511,17 @@ error: static herr_t test_array_dtype2(hid_t file) { - hid_t dataset, space; - hid_t dtype, native_type, tid, tid_m; - int i, j, k, n; - hsize_t space_dims[2], array_dims[1]={5}; - void *tmp; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid_m = -1; + int i, j, k, n; + hsize_t space_dims[2], array_dims[1] = {5}; + void *tmp = NULL; TESTING("array of atomic datatype"); /* Initialize the dataset */ for(i = n = 0;i < DIM0; i++) - for(j = 0; j < DIM1; j++) + for(j = 0; j < DIM1; j++) for(k = 0; k < 5; k++) ipoints3[i][j][k] = n++; @@ -1391,14 +1535,15 @@ test_array_dtype2(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ARRAY2_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create array datatype for memory */ if((tid_m = H5Tarray_create2(H5T_NATIVE_INT, 1, array_dims)) < 0) TEST_ERROR; /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints3) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1409,7 +1554,6 @@ test_array_dtype2(hid_t file) /* Close dataspace */ if(H5Sclose(space) < 0) TEST_ERROR; - /* Open dataset again to check H5Tget_native_type */ if((dataset = H5Dopen2(file, DSET_ARRAY2_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -1420,30 +1564,29 @@ test_array_dtype2(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(icheck3, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); - free(tmp); + HDmemcpy(icheck3, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), icheck3, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), icheck3, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ - for (i = 0; i < DIM0; i++) { - for (j = 0; j < DIM1; j++) { - for (k = 0; k < 5; k++) { + for(i = 0; i < DIM0; i++) + for(j = 0; j < DIM1; j++) + for(k = 0; k < 5; k++) if(icheck3[i][j][k] != ipoints3[i][j][k]) { H5_FAILED(); printf(" Read different values than written.\n"); printf(" At index %d,%d\n", i, j); goto error; - } - } - } - } + } /* end if */ /* Close HDF5 objects */ if(H5Dclose(dataset)) TEST_ERROR; @@ -1455,6 +1598,19 @@ test_array_dtype2(hid_t file) return 0; error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1478,37 +1634,36 @@ error: static herr_t test_vl_dtype(hid_t file) { - hvl_t wdata[SPACE1_DIM1]; /* Information to write */ - hvl_t rdata[SPACE1_DIM1]; /* Information read in */ - hvl_t *t1, *t2; /* Temporary pointer to VL information */ - hsize_t dims1[] = {SPACE1_DIM1}; - hid_t dataset, space; - hid_t dtype, native_type, nat_super_type, tid, tid2, tid_m, tid_m2; - size_t i, j, k; - void* *tmp; + hvl_t wdata[SPACE1_DIM1]; /* Information to write */ + hvl_t rdata[SPACE1_DIM1]; /* Information read in */ + hvl_t *t1, *t2; /* Temporary pointer to VL information */ + hsize_t dims1[] = {SPACE1_DIM1}; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, nat_super_type = -1, tid = -1, tid2 = -1, tid_m = -1, tid_m2 = -1; + size_t i, j, k; + void **tmp = NULL; TESTING("variable length datatype"); /* Allocate and initialize VL data to write */ - for(i=0; i<SPACE1_DIM1; i++) { + for(i = 0; i < SPACE1_DIM1; i++) { wdata[i].p = HDmalloc((i + 1) * sizeof(hvl_t)); - if(wdata[i].p==NULL) { + if(NULL == wdata[i].p) { H5_FAILED(); printf(" Cannot allocate memory for VL data! i=%u\n",(unsigned)i); goto error; } /* end if */ - wdata[i].len=i+1; + wdata[i].len = i + 1; for(t1 = (hvl_t *)wdata[i].p, j = 0; j < (i + 1); j++, t1++) { t1->p = HDmalloc((j + 1) * sizeof(unsigned int)); - if(t1->p==NULL) { + if(NULL == t1->p) { H5_FAILED(); printf(" Cannot allocate memory for VL data! i=%u, j=%u\n",(unsigned)i,(unsigned)j); goto error; } /* end if */ - t1->len=j+1; - for(k=0; k<(j+1); k++) { - ((unsigned int *)t1->p)[k]=(unsigned int)(i*100+j*10+k); - } + t1->len = j + 1; + for(k = 0; k < (j + 1); k++) + ((unsigned int *)t1->p)[k] = (unsigned int)(i * 100 + j * 10 + k); } /* end for */ } /* end for */ @@ -1566,7 +1721,7 @@ test_vl_dtype(hid_t file) printf(" VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len); goto error; } /* end if */ - for(t1 = (hvl_t *)wdata[i].p, t2 = (hvl_t *)rdata[i].p, j = 0; j<rdata[i].len; j++, t1++, t2++) { + for(t1 = (hvl_t *)wdata[i].p, t2 = (hvl_t *)rdata[i].p, j = 0; j < rdata[i].len; j++, t1++, t2++) { if(t1->len != t2->len) { H5_FAILED(); printf(" VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len); @@ -1575,36 +1730,38 @@ test_vl_dtype(hid_t file) /* use temporary buffer to convert datatype. This is for special * platforms like Cray */ - tmp = (void **)HDmalloc(t2->len * sizeof(unsigned int)); + if(NULL == (tmp = (void **)HDmalloc(t2->len * sizeof(unsigned int)))) + TEST_ERROR HDmemcpy(tmp, t2->p, t2->len * H5Tget_size(nat_super_type)); - if(H5Tconvert(nat_super_type, H5T_NATIVE_UINT, t2->len, tmp, NULL, H5P_DEFAULT)) + if(H5Tconvert(nat_super_type, H5T_NATIVE_UINT, t2->len, tmp, NULL, H5P_DEFAULT) < 0) TEST_ERROR; - for(k=0; k<t2->len; k++) { - if( ((unsigned int *)t1->p)[k] != ((unsigned int *)tmp)[k] ) { + for(k = 0; k < t2->len; k++) { + if(((unsigned int *)t1->p)[k] != ((unsigned int *)tmp)[k]) { H5_FAILED(); printf(" VL data don't match!, wdata[%u].p=%d, rdata[%u].p=%u\n", - (unsigned)i,((unsigned int*)t1->p)[k],(unsigned)i,((unsigned int*)tmp)[k]); + (unsigned)i, ((unsigned int*)t1->p)[k], (unsigned)i, ((unsigned int*)tmp)[k]); goto error; - } + } /* end if */ } /* end for */ - free(tmp); + HDfree(tmp); } /* end for */ } /* end for */ /* Reclaim the read VL data */ - if(H5Dvlen_reclaim(native_type,space,H5P_DEFAULT,rdata) < 0) TEST_ERROR; + if(H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, rdata) < 0) TEST_ERROR; /* Reclaim the write VL data */ - if(H5Dvlen_reclaim(native_type,space,H5P_DEFAULT,wdata) < 0) TEST_ERROR; + if(H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, wdata) < 0) TEST_ERROR; /* Close Dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; /* Close datatype */ if(H5Tclose(native_type) < 0) TEST_ERROR; + native_type = -1; /* reset so that error handling can check for VL reclaim */ if(H5Tclose(dtype) < 0) TEST_ERROR; if(H5Tclose(tid_m) < 0) TEST_ERROR; if(H5Tclose(tid_m2) < 0) TEST_ERROR; @@ -1616,7 +1773,27 @@ test_vl_dtype(hid_t file) PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + if(native_type > 0) { + H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, rdata); + H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, wdata); + } /* end if */ + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(nat_super_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + H5Tclose(tid_m2); + } H5E_END_TRY; + return -1; } /* end test_vl_type() */ @@ -1641,17 +1818,18 @@ static herr_t test_vlstr_dtype(hid_t file) { const char *wdata[SPACE1_DIM1]= { - "Four score and seven years ago our forefathers brought forth on this continent a new nation,", - "conceived in liberty and dedicated to the proposition that all men are created equal.", - "Now we are engaged in a great civil war,", - "testing whether that nation or any nation so conceived and so dedicated can long endure." - }; /* Information to write */ - char *rdata[SPACE1_DIM1]; /* Information read in */ - hid_t dataset; /* Dataset ID */ - hid_t sid1; /* Dataspace ID */ - hid_t tid1,dtype,native_type; /* Datatype ID */ - hsize_t dims1[] = {SPACE1_DIM1}; - unsigned i; /* counting variable */ + "Four score and seven years ago our forefathers brought forth on this continent a new nation,", + "conceived in liberty and dedicated to the proposition that all men are created equal.", + "Now we are engaged in a great civil war,", + "testing whether that nation or any nation so conceived and so dedicated can long endure." + }; /* Information to write */ + char *rdata[SPACE1_DIM1]; /* Information read in */ + hbool_t rdata_alloc = FALSE; /* Whether the read data is allocated */ + hid_t dataset = -1; /* Dataset ID */ + hid_t sid1 = -1; /* Dataspace ID */ + hid_t tid1 = -1, dtype = -1, native_type = -1; /* Datatype ID */ + hsize_t dims1[] = {SPACE1_DIM1}; + unsigned i; /* counting variable */ /* Output message about test being performed */ TESTING("variable length string datatype"); @@ -1691,19 +1869,20 @@ test_vlstr_dtype(hid_t file) /* Read dataset from disk */ if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata) < 0) TEST_ERROR; + rdata_alloc = TRUE; /* Compare data read in */ for(i = 0; i < SPACE1_DIM1; i++) { if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) { H5_FAILED(); printf(" VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n", - (int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i])); + (int)i, (int)HDstrlen(wdata[i]), (int)i, (int)HDstrlen(rdata[i])); goto error; } /* end if */ if(HDstrcmp(wdata[i], rdata[i]) != 0 ) { H5_FAILED(); printf(" VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", - (int)i,wdata[i],(int)i,rdata[i]); + (int)i, wdata[i], (int)i, rdata[i]); goto error; } /* end if */ } /* end for */ @@ -1719,14 +1898,28 @@ test_vlstr_dtype(hid_t file) if(H5Sclose(sid1) < 0) TEST_ERROR; /* Free memory for rdata */ - for(i=0; i<SPACE1_DIM1; i++) { + for(i = 0; i < SPACE1_DIM1; i++) HDfree(rdata[i]); - } + rdata_alloc = FALSE; PASSED(); return 0; error: + if(rdata_alloc) { + /* Free memory for rdata */ + for(i = 0; i < SPACE1_DIM1; i++) + HDfree(rdata[i]); + } /* end if */ + + H5E_BEGIN_TRY { + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(sid1); + H5Tclose(tid1); + } H5E_END_TRY; + return -1; } /* end test_vlstr_dtype() */ @@ -1750,18 +1943,18 @@ error: static herr_t test_str_dtype(hid_t file) { - const char wdata[SPACE1_DIM1][4]= { - "one", - "two", - "3rd", - "4th" - }; /* Information to write */ - char rdata[SPACE1_DIM1][4]; /* Information read in */ - hid_t dataset; /* Dataset ID */ - hid_t sid1; /* Dataspace ID */ - hid_t tid1,dtype,native_type; /* Datatype ID */ - hsize_t dims1[] = {SPACE1_DIM1}; - unsigned i; /* counting variable */ + const char wdata[SPACE1_DIM1][4]= { + "one", + "two", + "3rd", + "4th" + }; /* Information to write */ + char rdata[SPACE1_DIM1][4]; /* Information read in */ + hid_t dataset = -1; /* Dataset ID */ + hid_t sid1 = -1; /* Dataspace ID */ + hid_t tid1 = -1, dtype = -1, native_type = -1; /* Datatype ID */ + hsize_t dims1[] = {SPACE1_DIM1}; + unsigned i; /* counting variable */ /* Output message about test being performed */ TESTING("fixed-length string datatype"); @@ -1806,13 +1999,13 @@ test_str_dtype(hid_t file) if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) { H5_FAILED(); printf(" data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n", - (int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i])); + (int)i, (int)HDstrlen(wdata[i]), (int)i, (int)HDstrlen(rdata[i])); goto error; } /* end if */ if(HDstrcmp(wdata[i], rdata[i]) != 0 ) { H5_FAILED(); printf(" data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", - (int)i,wdata[i],(int)i,rdata[i]); + (int)i, wdata[i], (int)i, rdata[i]); goto error; } /* end if */ } /* end for */ @@ -1831,11 +2024,17 @@ test_str_dtype(hid_t file) return 0; error: + H5E_BEGIN_TRY { + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid1); + H5Tclose(sid1); + } H5E_END_TRY; + return -1; } /* end test_str_dtype() */ - - /*------------------------------------------------------------------------- * Function: test_refer_dtype @@ -1856,7 +2055,6 @@ error: static herr_t test_refer_dtype(hid_t file) { - /* Compound datatype */ typedef struct s1_t { unsigned int a; @@ -1864,21 +2062,23 @@ test_refer_dtype(hid_t file) float c; } s1_t; - hid_t dataset; /* Dataset ID */ - hid_t group; /* Group ID */ - hid_t sid1; /* Dataspace ID */ - hid_t tid1, dtype, native_type; /* Datatype ID */ - hsize_t dims1[] = {1}; - H5O_type_t obj_type; /* Object type */ - hobj_ref_t *wbuf, /* buffer to write to disk */ - *rbuf; /* buffer read from disk */ + hid_t dataset = -1; /* Dataset ID */ + hid_t group = -1; /* Group ID */ + hid_t sid1 = -1; /* Dataspace ID */ + hid_t tid1 = -1, dtype = -1, native_type = -1; /* Datatype ID */ + hsize_t dims1[] = {1}; + H5O_type_t obj_type; /* Object type */ + hobj_ref_t *wbuf = NULL, /* buffer to write to disk */ + *rbuf = NULL; /* buffer read from disk */ /* Output message about test being performed */ TESTING("reference datatype"); /* Allocate write & read buffers */ - wbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t))); - rbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t))); + if(NULL == (wbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t))))) + TEST_ERROR + if(NULL == (rbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t))))) + TEST_ERROR /* Create dataspace for datasets */ if((sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL)) < 0) @@ -1937,7 +2137,6 @@ test_refer_dtype(hid_t file) if(H5Dclose(dataset) < 0) TEST_ERROR; - /* Open the dataset */ if((dataset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0) TEST_ERROR; @@ -1973,19 +2172,36 @@ test_refer_dtype(hid_t file) if(H5Tclose(tid1) < 0) TEST_ERROR; + if(H5Tclose(native_type) < 0) + TEST_ERROR; + /* Close Dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; /* Free memory buffers */ - free(wbuf); - free(rbuf); + HDfree(wbuf); + HDfree(rbuf); PASSED(); return 0; error: + if(wbuf) + HDfree(wbuf); + if(rbuf) + HDfree(rbuf); + + H5E_BEGIN_TRY { + H5Sclose(sid1); + H5Gclose(group); + H5Tclose(tid1); + H5Tclose(dtype); + H5Tclose(native_type); + H5Dclose(dataset); + } H5E_END_TRY; + return -1; } /* test_refer_dtype() */ @@ -2009,38 +2225,40 @@ error: static herr_t test_refer_dtype2(hid_t file) { - hid_t dset1, /* Dataset ID */ - dset2; /* Dereferenced dataset ID */ - hid_t sid1, /* Dataspace ID #1 */ - sid2; /* Dataspace ID #2 */ - hid_t dtype, native_type; - hsize_t dims1[] = {1}, - dims2[] = {SPACE2_DIM1, SPACE2_DIM2}; - hsize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ - hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ - hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ - hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ - hdset_reg_ref_t wbuf, /* buffer to write to disk */ - rbuf; /* buffer read from disk */ - uint8_t *dwbuf, /* Buffer for writing numeric data to disk */ - *drbuf; /* Buffer for reading numeric data from disk */ - uint8_t *tu8; /* Temporary pointer to uint8 data */ - H5O_type_t obj_type; /* Object type */ - int i; /* counting variables */ + hid_t dset1 = -1, /* Dataset ID */ + dset2 = -1; /* Dereferenced dataset ID */ + hid_t sid1 = -1, /* Dataspace ID #1 */ + sid2 = -1; /* Dataspace ID #2 */ + hid_t dtype = -1, native_type = -1; + hsize_t dims1[] = { 1 }, dims2[] = { SPACE2_DIM1, SPACE2_DIM2 }; + hsize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + hdset_reg_ref_t wbuf, /* buffer to write to disk */ + rbuf; /* buffer read from disk */ + uint8_t *dwbuf = NULL, /* Buffer for writing numeric data to disk */ + *drbuf = NULL; /* Buffer for reading numeric data from disk */ + uint8_t *tu8 = NULL; /* Temporary pointer to uint8 data */ + H5O_type_t obj_type; /* Object type */ + int i; /* counting variables */ /* Output message about test being performed */ TESTING("dataset region reference"); /* Allocate write & read buffers */ - dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); - drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), SPACE2_DIM1 * SPACE2_DIM2); + if(NULL == (dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2))) + TEST_ERROR + if(NULL == (drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), SPACE2_DIM1 * SPACE2_DIM2))) + TEST_ERROR /* Create dataspace for datasets */ if((sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL)) < 0) TEST_ERROR; /* Create a dataset */ - if((dset2 = H5Dcreate2(file, "Dataset2", H5T_STD_U8LE, sid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + if((dset2 = H5Dcreate2(file, "Dataset2", H5T_STD_U8LE, sid2, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; for(tu8 = dwbuf, i = 0; i < SPACE2_DIM1 * SPACE2_DIM2; i++) @@ -2054,21 +2272,25 @@ test_refer_dtype2(hid_t file) if(H5Dclose(dset2) < 0) TEST_ERROR; - /* Create dataspace for the reference dataset */ if((sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL)) < 0) TEST_ERROR; /* Create a reference dataset */ - if((dset1 = H5Dcreate2(file, "Dataset1", H5T_STD_REF_DSETREG, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + if((dset1 = H5Dcreate2(file, "Dataset1", H5T_STD_REF_DSETREG, sid1, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Create references */ /* Select 6x6 hyperslab for first reference */ - start[0] = 2; start[1] = 2; - stride[0] = 1; stride[1] = 1; - count[0] = 1; count[1] = 1; - block[0] = 6; block[1] = 6; + start[0] = 2; + start[1] = 2; + stride[0] = 1; + stride[1] = 1; + count[0] = 1; + count[1] = 1; + block[0] = 6; + block[1] = 6; if(H5Sselect_hyperslab(sid2, H5S_SELECT_SET, start, stride, count, block) < 0) TEST_ERROR; @@ -2100,9 +2322,6 @@ test_refer_dtype2(hid_t file) if(H5Sclose(sid2) < 0) TEST_ERROR; - - - /* Open the dataset */ if((dset1 = H5Dopen2(file, "/Dataset1", H5P_DEFAULT)) < 0) TEST_ERROR; @@ -2175,13 +2394,28 @@ test_refer_dtype2(hid_t file) TEST_ERROR; /* Free memory buffers */ - free(dwbuf); - free(drbuf); + HDfree(dwbuf); + HDfree(drbuf); PASSED(); return 0; -error: +error: + /* Free memory buffers */ + if(dwbuf) + HDfree(dwbuf); + if(drbuf) + HDfree(drbuf); + + H5E_BEGIN_TRY { + H5Sclose(sid2); + H5Sclose(sid1); + H5Tclose(dtype); + H5Tclose(native_type); + H5Dclose(dset2); + H5Dclose(dset1); + } H5E_END_TRY; + return -1; } /* test_refer_dtype2() */ @@ -2205,21 +2439,21 @@ error: static herr_t test_opaque_dtype(hid_t file) { - hid_t type=-1, space=-1, dset=-1; - hid_t dataset, dtype, native_type; - size_t i; - unsigned char wbuf[32], rbuf[32]; - hsize_t nelmts; + hid_t type = -1, space = -1, dset = -1; + hid_t dataset = -1, dtype = -1, native_type = -1; + size_t i; + unsigned char wbuf[32], rbuf[32]; + hsize_t nelmts; TESTING("opaque datatype"); /* opaque_1 */ nelmts = sizeof(wbuf); - if((type = H5Tcreate(H5T_OPAQUE, 1)) < 0 || - H5Tset_tag(type, "testing 1-byte opaque type") < 0 || - (space = H5Screate_simple(1, &nelmts, NULL)) < 0 || - (dset = H5Dcreate2(file, DSET_OPAQUE_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - TEST_ERROR; + if((type = H5Tcreate(H5T_OPAQUE, 1)) < 0) TEST_ERROR; + if(H5Tset_tag(type, "testing 1-byte opaque type") < 0) TEST_ERROR; + if((space = H5Screate_simple(1, &nelmts, NULL)) < 0) TEST_ERROR; + if((dset = H5Dcreate2(file, DSET_OPAQUE_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; for(i = 0; i < sizeof(wbuf); i++) wbuf[i] = (unsigned char)0xff ^ (unsigned char)i; @@ -2243,11 +2477,11 @@ test_opaque_dtype(hid_t file) TEST_ERROR; for(i = 0; i < sizeof(rbuf); i++) - if(rbuf[i] != wbuf[i]) { - H5_FAILED(); - printf(" Read different values than written.\n"); + if(rbuf[i] != wbuf[i]) { + H5_FAILED(); + printf(" Read different values than written.\n"); printf(" At index %u\n", (unsigned)i); - goto error; + goto error; } /* end if */ if(H5Tclose(type) < 0) TEST_ERROR; @@ -2259,6 +2493,15 @@ test_opaque_dtype(hid_t file) return 0; error: + H5E_BEGIN_TRY { + H5Sclose(space); + H5Tclose(type); + H5Tclose(dtype); + H5Tclose(native_type); + H5Dclose(dset); + H5Dclose(dataset); + } H5E_END_TRY; + return -1; } /* test_opaque_dtype */ @@ -2282,20 +2525,20 @@ error: static herr_t test_bitfield_dtype(hid_t file) { - hid_t type=-1, space=-1, dset=-1; - hid_t dataset, dtype, native_type; - size_t i; - unsigned char wbuf[32]; - hsize_t nelmts; + hid_t type = -1, space = -1, dset = -1; + hid_t dataset = -1, dtype = -1, native_type = -1; + size_t i; + unsigned char wbuf[32]; + hsize_t nelmts; TESTING("bitfield datatype"); /* opaque_1 */ nelmts = sizeof(wbuf); - if((type = H5Tcopy(H5T_STD_B8LE)) < 0 || - (space = H5Screate_simple(1, &nelmts, NULL)) < 0 || - (dset = H5Dcreate2(file, DSET_BITFIELD_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - TEST_ERROR; + if((type = H5Tcopy(H5T_STD_B8LE)) < 0) TEST_ERROR; + if((space = H5Screate_simple(1, &nelmts, NULL)) < 0) TEST_ERROR; + if((dset = H5Dcreate2(file, DSET_BITFIELD_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; for(i = 0; i < sizeof(wbuf); i++) wbuf[i] = (unsigned char)0xff ^ (unsigned char)i; @@ -2327,6 +2570,15 @@ test_bitfield_dtype(hid_t file) return 0; error: + H5E_BEGIN_TRY { + H5Sclose(space); + H5Tclose(type); + H5Tclose(dtype); + H5Tclose(native_type); + H5Dclose(dset); + H5Dclose(dataset); + } H5E_END_TRY; + return -1; } /* test_bitfield_dtype */ @@ -2350,176 +2602,166 @@ error: static herr_t test_ninteger(void) { - hid_t fid1=(-1); /* file ID */ - hid_t fid2=(-1); /* file ID */ - hid_t did1=(-1); /* dataset ID */ - hid_t did2=(-1); /* dataset ID */ - hid_t sid1=(-1); /* dataspace ID */ - hid_t dcpl1=(-1); /* dataset creation property list ID */ - hid_t dcpl2=(-1); /* dataset creation property list ID */ - hid_t tid1=(-1); /* file datatype */ - hid_t tid2=(-1); /* file datatype */ - hid_t nid1=(-1); /* native datatype */ - hid_t nid2=(-1); /* native datatype */ - hsize_t dims[1]={DIM3}; /* dataspace dimensions */ + hid_t fid1 = -1; /* file ID */ + hid_t fid2 = -1; /* file ID */ + hid_t did1 = -1; /* dataset ID */ + hid_t did2 = -1; /* dataset ID */ + hid_t sid1 = -1; /* dataspace ID */ + hid_t dcpl1 = -1; /* dataset creation property list ID */ + hid_t dcpl2 = -1; /* dataset creation property list ID */ + hid_t tid1 = -1; /* file datatype */ + hid_t tid2 = -1; /* file datatype */ + hid_t nid1 = -1; /* native datatype */ + hid_t nid2 = -1; /* native datatype */ + hsize_t dims[1] = {DIM3}; /* dataspace dimensions */ hsize_t nelmts; /* number of elements in dataset */ - int rank=1; /* rank of dataset */ + int rank = 1; /* rank of dataset */ int buf[DIM3]; int chk[DIM3]; int i; - for (i=0; i<DIM3; i++){ - buf[i]=i; - } - TESTING("native integer "); - /*------------------------------------------------------------------------- - * step1: create a file - *------------------------------------------------------------------------- - */ + for(i = 0; i < DIM3; i++) + buf[i] = i; + + /*------------------------------------------------------------------------- + * step1: create a file + *------------------------------------------------------------------------- + */ /* create a file using default properties */ - if((fid1=H5Fcreate("tstint1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT)) < 0) - goto error; + if((fid1 = H5Fcreate("tstint1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + FAIL_STACK_ERROR /* create a data space */ - if((sid1 = H5Screate_simple(rank,dims,NULL)) < 0) goto error; + if((sid1 = H5Screate_simple(rank, dims, NULL)) < 0) FAIL_STACK_ERROR /* create dcpl */ - if((dcpl1 = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; + if((dcpl1 = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR /* create a dataset */ - if((did1 = H5Dcreate2(fid1, "dset", H5T_NATIVE_INT, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) goto error; + if((did1 = H5Dcreate2(fid1, "dset", H5T_NATIVE_INT, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* write */ - if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; + if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) FAIL_STACK_ERROR /* close */ - if(H5Sclose(sid1) < 0) goto error; - if(H5Pclose(dcpl1) < 0) goto error; - if(H5Dclose(did1) < 0) goto error; - if(H5Fclose(fid1) < 0) goto error; + if(H5Sclose(sid1) < 0) FAIL_STACK_ERROR + if(H5Pclose(dcpl1) < 0) FAIL_STACK_ERROR + if(H5Dclose(did1) < 0) FAIL_STACK_ERROR + if(H5Fclose(fid1) < 0) FAIL_STACK_ERROR - /*------------------------------------------------------------------------- - * step 2: open and create another file copying the data from file1 - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * step 2: open and create another file copying the data from file1 + *------------------------------------------------------------------------- + */ - /* open */ - if((fid1 = H5Fopen("tstint1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) goto error; + /* open */ + if((fid1 = H5Fopen("tstint1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* open dataset */ - if((did1 = H5Dopen2(fid1, "dset", H5P_DEFAULT)) < 0) goto error; + if((did1 = H5Dopen2(fid1, "dset", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR - if((sid1 = H5Dget_space(did1)) < 0) goto error; + if((sid1 = H5Dget_space(did1)) < 0) FAIL_STACK_ERROR /* get dcpl */ - if((dcpl1 = H5Dget_create_plist(did1)) < 0) goto error; + if((dcpl1 = H5Dget_create_plist(did1)) < 0) FAIL_STACK_ERROR /* get file datatype */ - if((tid1 = H5Dget_type(did1)) < 0) goto error; + if((tid1 = H5Dget_type(did1)) < 0) FAIL_STACK_ERROR /* get native datatype */ - if((nid1 = H5Tget_native_type(tid1, H5T_DIR_DEFAULT)) < 0) goto error; + if((nid1 = H5Tget_native_type(tid1, H5T_DIR_DEFAULT)) < 0) FAIL_STACK_ERROR /* get size */ - if(H5Tget_size(nid1) == 0) goto error; + if(H5Tget_size(nid1) == 0) FAIL_STACK_ERROR /* get rank */ - if((rank = H5Sget_simple_extent_ndims(sid1)) < 0) goto error; + if((rank = H5Sget_simple_extent_ndims(sid1)) < 0) FAIL_STACK_ERROR HDmemset(dims, 0, sizeof dims); /* get dimension */ - if(H5Sget_simple_extent_dims(sid1, dims, NULL) < 0) goto error; + if(H5Sget_simple_extent_dims(sid1, dims, NULL) < 0) FAIL_STACK_ERROR nelmts = 1; for(i = 0; i < rank; i++) - nelmts *= dims[i]; + nelmts *= dims[i]; /* read */ - if(H5Dread(did1, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0) - goto error; + if(H5Dread(did1, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0) FAIL_STACK_ERROR /* create a file using default properties */ - if((fid2 = H5Fcreate("tstint2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + if((fid2 = H5Fcreate("tstint2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* create a dataset using the native type */ - if((did2 = H5Dcreate2(fid2, "dset", nid1, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) goto error; + if((did2 = H5Dcreate2(fid2, "dset", nid1, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* write */ - if(H5Dwrite(did2, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0) - goto error; + if(H5Dwrite(did2, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0) FAIL_STACK_ERROR /* get dcpl */ - if((dcpl2 = H5Dget_create_plist(did2)) < 0) - goto error; + if((dcpl2 = H5Dget_create_plist(did2)) < 0) FAIL_STACK_ERROR /* get file datatype */ - if((tid2 = H5Dget_type(did2)) < 0) - goto error; + if((tid2 = H5Dget_type(did2)) < 0) FAIL_STACK_ERROR /* get native datatype */ - if((nid2 = H5Tget_native_type(tid2, H5T_DIR_DEFAULT)) < 0) - goto error; + if((nid2 = H5Tget_native_type(tid2, H5T_DIR_DEFAULT)) < 0) FAIL_STACK_ERROR /* check */ if(H5Tget_precision(nid1) != H5Tget_precision(nid2)) { - printf(" Precision differ.\n"); - goto error; - } + printf(" Precision differ.\n"); + TEST_ERROR + } /* end if */ /* compare dataset creation property lists */ if(H5Pequal(dcpl1, dcpl2) <= 0) { - printf(" Property lists differ.\n"); - goto error; - } + printf(" Property lists differ.\n"); + TEST_ERROR + } /* end if */ /* check */ - for (i = 0; i < DIM3; i++) { - if(buf[i] != chk[i]) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d\n", i); - goto error; - } - } + for(i = 0; i < DIM3; i++) + if(buf[i] != chk[i]) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d\n", i); + TEST_ERROR + } /* end if */ /* close */ - if(H5Sclose (sid1) < 0) goto error; - if(H5Pclose (dcpl1) < 0) goto error; - if(H5Pclose (dcpl2) < 0) goto error; - if(H5Tclose (tid1) < 0) goto error; - if(H5Tclose (tid2) < 0) goto error; - if(H5Tclose (nid1) < 0) goto error; - if(H5Tclose (nid2) < 0) goto error; - if(H5Dclose (did1) < 0) goto error; - if(H5Dclose (did2) < 0) goto error; - if(H5Fclose (fid1) < 0) goto error; - if(H5Fclose (fid2) < 0) goto error; - + if(H5Sclose(sid1) < 0) FAIL_STACK_ERROR + if(H5Pclose(dcpl1) < 0) FAIL_STACK_ERROR + if(H5Pclose(dcpl2) < 0) FAIL_STACK_ERROR + if(H5Tclose(tid1) < 0) FAIL_STACK_ERROR + if(H5Tclose(tid2) < 0) FAIL_STACK_ERROR + if(H5Tclose(nid1) < 0) FAIL_STACK_ERROR + if(H5Tclose(nid2) < 0) FAIL_STACK_ERROR + if(H5Dclose(did1) < 0) FAIL_STACK_ERROR + if(H5Dclose(did2) < 0) FAIL_STACK_ERROR + if(H5Fclose(fid1) < 0) FAIL_STACK_ERROR + if(H5Fclose(fid2) < 0) FAIL_STACK_ERROR PASSED(); return 0; error: H5E_BEGIN_TRY { - H5Pclose(dcpl1); - H5Pclose(dcpl2); - H5Tclose(tid1); - H5Tclose(tid2); - H5Tclose(nid1); - H5Tclose(nid2); - H5Dclose(did1); - H5Dclose(did2); - H5Sclose(sid1); - H5Fclose(fid1); - H5Fclose(fid2); + H5Pclose(dcpl1); + H5Pclose(dcpl2); + H5Tclose(tid1); + H5Tclose(tid2); + H5Tclose(nid1); + H5Tclose(nid2); + H5Dclose(did1); + H5Dclose(did2); + H5Sclose(sid1); + H5Fclose(fid1); + H5Fclose(fid2); } H5E_END_TRY; + return -1; } /* end test_ninteger() */ - /*------------------------------------------------------------------------- * Function: main @@ -2536,43 +2778,54 @@ error: int main(void) { - hid_t file, fapl; - int nerrors=0; - char filename[1024]; + hid_t file, fapl; + int nerrors = 0; + char filename[1024]; h5_reset(); fapl = h5_fileaccess(); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); - if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) - goto error; - - nerrors += test_atomic_dtype(file) < 0 ?1:0; - nerrors += test_compound_dtype(file) < 0 ?1:0; - nerrors += test_compound_dtype2(file) < 0 ?1:0; - nerrors += test_compound_dtype3(file) < 0 ?1:0; - nerrors += test_compound_opaque(file) < 0 ?1:0; - nerrors += test_enum_dtype(file) < 0 ?1:0; - nerrors += test_array_dtype(file) < 0 ?1:0; - nerrors += test_array_dtype2(file) < 0 ?1:0; - nerrors += test_vl_dtype(file) < 0 ?1:0; - nerrors += test_vlstr_dtype(file) < 0 ?1:0; - nerrors += test_str_dtype(file) < 0 ?1:0; - nerrors += test_refer_dtype(file) < 0 ?1:0; - nerrors += test_refer_dtype2(file) < 0 ?1:0; - nerrors += test_opaque_dtype(file) < 0 ?1:0; - nerrors += test_bitfield_dtype(file) < 0 ?1:0; - nerrors += test_ninteger() < 0 ?1:0; - - if(H5Fclose(file) < 0) goto error; - if(nerrors) goto error; + if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) + goto error; + + nerrors += test_atomic_dtype(file) < 0 ? 1 : 0; + nerrors += test_compound_dtype(file) < 0 ? 1 : 0; + nerrors += test_compound_dtype2(file) < 0 ? 1 : 0; + nerrors += test_compound_dtype3(file) < 0 ? 1 : 0; + nerrors += test_compound_opaque(file) < 0 ? 1 : 0; + nerrors += test_enum_dtype(file) < 0 ? 1 : 0; + nerrors += test_array_dtype(file) < 0 ? 1 : 0; + nerrors += test_array_dtype2(file) < 0 ? 1 : 0; + nerrors += test_vl_dtype(file) < 0 ? 1 : 0; + nerrors += test_vlstr_dtype(file) < 0 ? 1 : 0; + nerrors += test_str_dtype(file) < 0 ? 1 : 0; + nerrors += test_refer_dtype(file) < 0 ? 1 : 0; + nerrors += test_refer_dtype2(file) < 0 ? 1 : 0; + nerrors += test_opaque_dtype(file) < 0 ? 1 : 0; + nerrors += test_bitfield_dtype(file) < 0 ? 1 : 0; + nerrors += test_ninteger() < 0 ? 1 : 0; + + if(H5Fclose(file) < 0) + goto error; + if(nerrors) + goto error; + printf("All native datatype tests passed.\n"); h5_cleanup(FILENAME, fapl); + return 0; - error: +error: + H5E_BEGIN_TRY { + H5Fclose(file); + h5_cleanup(FILENAME, fapl); + } H5E_END_TRY; + nerrors = MAX(1, nerrors); printf("***** %d DATASET TEST%s FAILED! *****\n", - nerrors, 1 == nerrors ? "" : "S"); + nerrors, 1 == nerrors ? "" : "S"); + return 1; } + diff --git a/test/objcopy.c b/test/objcopy.c index 9d67d3e..493274a 100755 --- a/test/objcopy.c +++ b/test/objcopy.c @@ -721,7 +721,9 @@ compare_attribute(hid_t aid, hid_t aid2, hid_t pid, const void *wbuf, hid_t obj_ /* Release raw data buffers */ HDfree(rbuf); + rbuf = NULL; HDfree(rbuf2); + rbuf2 = NULL; /* close the source dataspace */ if(H5Sclose(sid) < 0) TEST_ERROR @@ -738,11 +740,11 @@ compare_attribute(hid_t aid, hid_t aid2, hid_t pid, const void *wbuf, hid_t obj_ return TRUE; error: + if(rbuf) + HDfree(rbuf); + if(rbuf2) + HDfree(rbuf2); H5E_BEGIN_TRY { - if(rbuf) - HDfree(rbuf); - if(rbuf2) - HDfree(rbuf2); H5Sclose(sid2); H5Sclose(sid); H5Tclose(tid2); @@ -7315,9 +7317,11 @@ static int test_copy_dataset_contig_cmpd_vl(hid_t fcpl_src, hid_t fcpl_dst, hid_t fapl) { hid_t fid_src = -1, fid_dst = -1; /* File IDs */ - hid_t tid = -1, tid2; /* Datatype IDs */ + hid_t tid = -1; /* Datatype ID */ + hid_t tid2 = -1; /* Datatype ID */ hid_t sid = -1; /* Dataspace ID */ - hid_t did = -1, did2 = -1; /* Dataset IDs */ + hid_t did = -1; /* Dataset ID */ + hid_t did2 = -1; /* Dataset ID */ unsigned int i, j; /* Local index variables */ hsize_t dim1d[1]; /* Dataset dimensions */ cmpd_vl_t buf[DIM_SIZE_1]; /* Buffer for writing data */ diff --git a/test/pool.c b/test/pool.c index 22658ec..43e9cfd 100644 --- a/test/pool.c +++ b/test/pool.c @@ -645,7 +645,7 @@ test_allocate_random(void) curr_time=1115412944; HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); #endif /* QAK */ - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); /* Create a memory pool */ if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) diff --git a/test/theap.c b/test/theap.c index 0c39868..230ec4d 100644 --- a/test/theap.c +++ b/test/theap.c @@ -93,7 +93,7 @@ test_heap_init(void) /* Create randomized set of numbers */ curr_time=time(NULL); - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); for(u=0; u<NUM_ELEMS; u++) /* Generate random numbers from -1000 to 1000 */ rand_num[u].val=(int)(HDrandom()%2001)-1001; diff --git a/test/tskiplist.c b/test/tskiplist.c index 7b3dcef..8510db2 100644 --- a/test/tskiplist.c +++ b/test/tskiplist.c @@ -71,7 +71,7 @@ test_skiplist_init(void) /* Initialize random number seed */ curr_time = HDtime(NULL); - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); /* Create randomized set of numbers */ for(u=0; u<NUM_ELEMS; u++) { diff --git a/test/ttst.c b/test/ttst.c index c267404..4ffe4cd 100644 --- a/test/ttst.c +++ b/test/ttst.c @@ -124,7 +124,7 @@ test_tst_init(void) for(u=0; u<num_uniq_words; u++) rand_uniq_words[u]=uniq_words[u]; curr_time=HDtime(NULL); - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); for(u=0; u<num_uniq_words; u++) { v=u+(HDrandom()%(num_uniq_words-u)); if(u!=v) { diff --git a/test/tunicode.c b/test/tunicode.c index efbf80e..892e563 100644 --- a/test/tunicode.c +++ b/test/tunicode.c @@ -807,7 +807,7 @@ void test_unicode(void) MESSAGE(5, ("Testing UTF-8 Encoding\n")); /* Create a random string with length NUM_CHARS */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); HDmemset(test_string, 0, sizeof(test_string)); for(x=0; x<NUM_CHARS; x++) diff --git a/test/unlink.c b/test/unlink.c index 60d6ac5..9bd6f42 100644 --- a/test/unlink.c +++ b/test/unlink.c @@ -1487,8 +1487,8 @@ delete_node(hid_t pid, hid_t id) static int test_unlink_rightleaf(hid_t fid) { - hid_t rootid, /* Group ID for root group */ - *gids; /* Array of IDs for groups created */ + hid_t rootid = -1, /* Group ID for root group */ + *gids = NULL; /* Array of IDs for groups created */ int n, /* Local index variable */ ngroups = 150; /* Number of groups to create */ char name[256]; /* Name of object to create */ @@ -1496,7 +1496,7 @@ test_unlink_rightleaf(hid_t fid) TESTING("deleting right-most child in non-leaf B-tree node"); /* Allocate space for the group IDs */ - if(NULL == (gids = (hid_t *)HDmalloc((size_t)ngroups * sizeof(hid_t)))) TEST_ERROR + if(NULL == (gids = (hid_t *)HDcalloc((size_t)ngroups, sizeof(hid_t)))) TEST_ERROR if((rootid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR @@ -1514,8 +1514,10 @@ test_unlink_rightleaf(hid_t fid) } /* end for */ /* Close all the groups */ - for (n = 0; n < ngroups; n++) + for (n = 0; n < ngroups; n++) { if(H5Gclose(gids[n]) < 0) TEST_ERROR + gids[n] = 0; + } /* end for */ /* Close root group ID */ if(H5Gclose(rootid) < 0) TEST_ERROR @@ -1527,6 +1529,20 @@ test_unlink_rightleaf(hid_t fid) return 0; error: + if(gids) { + /* Close any open groups */ + for (n = 0; n < ngroups; n++) + if(gids[n]) { + H5E_BEGIN_TRY { + H5Gclose(gids[n]); + } H5E_END_TRY; + } /* end if */ + HDfree(gids); + } /* end if */ + H5E_BEGIN_TRY { + H5Gclose(rootid); + } H5E_END_TRY; + return 1; } /* end test_unlink_rightleaf() */ @@ -1550,8 +1566,8 @@ error: static int test_unlink_rightnode(hid_t fid) { - hid_t rootid, /* Group ID for root group */ - *gids; /* Array of IDs for groups created */ + hid_t rootid = -1, /* Group ID for root group */ + *gids = NULL; /* Array of IDs for groups created */ int n, /* Local index variable */ ngroups = 150; /* Number of groups to create */ char name[256]; /* Name of object to create */ @@ -1559,7 +1575,7 @@ test_unlink_rightnode(hid_t fid) TESTING("deleting right-most child in non-leaf B-tree node"); /* Allocate space for the group IDs */ - if(NULL == (gids = (hid_t *)HDmalloc((size_t)ngroups * sizeof(hid_t)))) TEST_ERROR + if(NULL == (gids = (hid_t *)HDcalloc((size_t)ngroups, sizeof(hid_t)))) TEST_ERROR if((rootid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR @@ -1570,8 +1586,10 @@ test_unlink_rightnode(hid_t fid) } /* end for */ /* Close all the groups */ - for (n = 0; n < ngroups; n++) + for (n = 0; n < ngroups; n++) { if(H5Gclose(gids[n]) < 0) FAIL_STACK_ERROR + gids[n] = 0; + } /* end for */ /* Unlink specific objects to trigger deletion of right leaf in non-leaf node */ if(H5Ldelete(fid, "/ZoneB77", H5P_DEFAULT) < 0) FAIL_STACK_ERROR @@ -1590,6 +1608,20 @@ test_unlink_rightnode(hid_t fid) return 0; error: + if(gids) { + /* Close any open groups */ + for (n = 0; n < ngroups; n++) + if(gids[n]) { + H5E_BEGIN_TRY { + H5Gclose(gids[n]); + } H5E_END_TRY; + } /* end if */ + HDfree(gids); + } /* end if */ + H5E_BEGIN_TRY { + H5Gclose(rootid); + } H5E_END_TRY; + return 1; } /* end test_unlink_rightnode() */ @@ -1613,8 +1645,8 @@ error: static int test_unlink_middlenode(hid_t fid) { - hid_t rootid, /* Group ID for root group */ - *gids; /* Array of IDs for groups created */ + hid_t rootid = -1, /* Group ID for root group */ + *gids = NULL; /* Array of IDs for groups created */ int n, /* Local index variable */ ngroups = 250; /* Number of groups to create */ char name[256]; /* Name of object to create */ @@ -1622,7 +1654,7 @@ test_unlink_middlenode(hid_t fid) TESTING("deleting right-most child in non-leaf B-tree node"); /* Allocate space for the group IDs */ - if(NULL == (gids = (hid_t *)HDmalloc((size_t)ngroups * sizeof(hid_t)))) TEST_ERROR + if(NULL == (gids = (hid_t *)HDcalloc((size_t)ngroups, sizeof(hid_t)))) TEST_ERROR if((rootid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR @@ -1633,8 +1665,10 @@ test_unlink_middlenode(hid_t fid) } /* end for */ /* Close all the groups */ - for (n = 0; n < ngroups; n++) + for (n = 0; n < ngroups; n++) { if(H5Gclose(gids[n]) < 0) FAIL_STACK_ERROR + gids[n] = 0; + } /* end for */ /* Unlink specific objects to trigger deletion of all leafs in "interior" non-leaf node */ if(H5Ldelete(fid, "/ZoneC11", H5P_DEFAULT) < 0) FAIL_STACK_ERROR @@ -1796,6 +1830,20 @@ test_unlink_middlenode(hid_t fid) return 0; error: + if(gids) { + /* Close any open groups */ + for (n = 0; n < ngroups; n++) + if(gids[n]) { + H5E_BEGIN_TRY { + H5Gclose(gids[n]); + } H5E_END_TRY; + } /* end if */ + HDfree(gids); + } /* end if */ + H5E_BEGIN_TRY { + H5Gclose(rootid); + } H5E_END_TRY; + return 1; } /* end test_unlink_middlenode() */ @@ -1819,7 +1867,7 @@ error: static int test_resurrect_dataset(hid_t fapl) { - hid_t f =-1, s =-1, d =-1; + hid_t f = -1, s = -1, d = -1; char filename[1024]; TESTING("resurrecting dataset after deletion"); @@ -2404,7 +2452,7 @@ main(void) double rdcc_w0; /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); /* Open */ h5_reset(); @@ -808,7 +808,6 @@ test_family_compat(void) char filename[1024]; char pathname[1024], pathname_individual[1024]; char newname[1024], newname_individual[1024]; - FILE *tmp_fp, *old_fp; /* Pointers to temp & old files */ int counter = 0; TESTING("FAMILY file driver backward compatibility"); @@ -838,10 +837,6 @@ test_family_compat(void) sprintf(pathname_individual, pathname, counter); } - if ((NULL != (old_fp = HDfopen(pathname_individual,"rb"))) && - (NULL != (tmp_fp = HDfopen(newname_individual,"wb")))) - TEST_ERROR; - /* Make sure we can open the file. Use the read and write mode to flush the * superblock. */ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index a437619..abe97ea 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -5749,7 +5749,6 @@ xml_dump_group(hid_t gid, const char *name) char type_name[1024], *tmp = NULL; char *par = NULL; int isRoot = 0; - char *ptrstr; char *t_objname; char *par_name; unsigned crt_order_flags; @@ -5802,6 +5801,7 @@ xml_dump_group(hid_t gid, const char *name) indent += COL; H5Oget_info(gid, &oinfo); + if(oinfo.rc > 1) { obj_t *found_obj; /* Found object */ @@ -5819,6 +5819,8 @@ xml_dump_group(hid_t gid, const char *name) char *parentxid = malloc(100); if(found_obj->displayed) { + char *ptrstr = malloc(100); + /* already seen: enter a groupptr */ if(isRoot) { /* probably can't happen! */ @@ -5839,7 +5841,6 @@ xml_dump_group(hid_t gid, const char *name) } indentation(indent + COL); - ptrstr = malloc(100); t_objname = xml_escape_the_name(found_obj->objname);/* point to the NDT by name */ par_name = xml_escape_the_name(par); xml_name_to_XID(found_obj->objname, ptrstr, 100, 1); @@ -5850,6 +5851,7 @@ xml_dump_group(hid_t gid, const char *name) ptrstr, t_objname, parentxid, par_name); free(t_objname); free(par_name); + free(ptrstr); } else { /* first time this group has been seen -- describe it */ diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index b42b675..ab60807 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -5813,12 +5813,12 @@ gent_binary(void) static void gent_bigdims(void) { - hid_t fid; - hid_t did; - hid_t f_sid; - hid_t m_sid; - hid_t tid; - hid_t dcpl; + hid_t fid = -1; + hid_t did = -1; + hid_t f_sid = -1; + hid_t m_sid = -1; + hid_t tid = -1; + hid_t dcpl = -1; hsize_t dims[1]={DIM_4GB}; /* dataset dimensions */ hsize_t chunk_dims[1]={1024}; /* chunk dimensions */ hsize_t hs_start[1]; @@ -5876,14 +5876,21 @@ gent_bigdims(void) buf=NULL; /* close */ + if(H5Tclose(tid) < 0) + goto out; + tid = -1; if(H5Sclose(f_sid) < 0) goto out; + f_sid = -1; if(H5Sclose(m_sid) < 0) goto out; + m_sid = -1; if(H5Pclose(dcpl) < 0) goto out; + dcpl = -1; if(H5Dclose(did) < 0) goto out; + did = -1; ret = H5Fclose(fid); assert(ret >= 0); @@ -5896,11 +5903,11 @@ out: H5Pclose(dcpl); H5Sclose(f_sid); H5Sclose(m_sid); + H5Tclose(tid); H5Dclose(did); H5Fclose(fid); } H5E_END_TRY; return; - } @@ -5947,10 +5954,10 @@ gent_hyperslab(void) static void gent_group_creation_order(void) { - hid_t fid; /* file ID */ - hid_t gid; /* group ID */ - hid_t gcpl_id; /* group creation property list ID */ - hid_t fcpl_id; /* file creation property list ID (to set root group order) */ + hid_t fid = -1; /* file ID */ + hid_t gid = -1; /* group ID */ + hid_t gcpl_id = -1; /* group creation property list ID */ + hid_t fcpl_id = -1; /* file creation property list ID (to set root group order) */ if((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) goto out; @@ -5976,37 +5983,45 @@ gent_group_creation_order(void) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "2/c", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "2/b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "2/a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "2/a/a2", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "2/a/a1", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "2/a/a2/a22", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "2/a/a2/a21", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; /*------------------------------------------------------------------------- @@ -6021,45 +6036,56 @@ gent_group_creation_order(void) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "1/c", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "1/b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "1/a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "1/a/a2", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "1/a/a1", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "1/a/a2/a22", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if((gid = H5Gcreate2(fid, "1/a/a2/a21", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if(H5Gclose(gid) < 0) goto out; + gid = -1; if(H5Pclose(gcpl_id) < 0) goto out; + gcpl_id = -1; if(H5Pclose(fcpl_id) < 0) goto out; + fcpl_id = -1; if(H5Fclose(fid) < 0) goto out; + fid = -1; return; @@ -6087,15 +6113,15 @@ out: static void gent_attr_creation_order(void) { - hid_t fid; /* file id */ - hid_t gid; /* group id */ - hid_t did; /* dataset id */ - hid_t sid; /* space id */ - hid_t aid; /* attribute id */ - hid_t tid; /* datatype id */ - hid_t gcpl_id; /* group creation property list ID */ - hid_t dcpl_id; /* dataset creation property list ID */ - hid_t tcpl_id; /* datatype creation property list ID */ + hid_t fid = -1; /* file id */ + hid_t gid = -1; /* group id */ + hid_t did = -1; /* dataset id */ + hid_t sid = -1; /* space id */ + hid_t aid = -1; /* attribute id */ + hid_t tid = -1; /* datatype id */ + hid_t gcpl_id = -1; /* group creation property list ID */ + hid_t dcpl_id = -1; /* dataset creation property list ID */ + hid_t tcpl_id = -1; /* datatype creation property list ID */ int i; const char *attr_name[3] = {"c", "b", "a" }; @@ -6148,10 +6174,12 @@ gent_attr_creation_order(void) /* close attribute */ if(H5Aclose(aid) < 0) goto out; + aid = -1; } /* end for */ if(H5Dclose(did) < 0) goto out; + did = -1; /*------------------------------------------------------------------------- @@ -6172,10 +6200,12 @@ gent_attr_creation_order(void) /* close attribute */ if(H5Aclose(aid) < 0) goto out; + aid = -1; } /* end for */ if(H5Dclose(did) < 0) goto out; + did = -1; @@ -6196,11 +6226,12 @@ gent_attr_creation_order(void) /* close attribute */ if(H5Aclose(aid) < 0) goto out; - + aid = -1; } /* end for */ if(H5Gclose(gid) < 0) goto out; + gid = -1; /*------------------------------------------------------------------------- * create a group without creation order tracked for attributes and atributes in it @@ -6219,12 +6250,12 @@ gent_attr_creation_order(void) /* close attribute */ if(H5Aclose(aid) < 0) goto out; - + aid = -1; } /* end for */ if(H5Gclose(gid) < 0) goto out; - + gid = -1; /*------------------------------------------------------------------------- * create a named datatype with creation order tracked for attributes and atributes in it @@ -6246,11 +6277,12 @@ gent_attr_creation_order(void) /* close attribute */ if(H5Aclose(aid) < 0) goto out; - + aid = -1; } /* end for */ if(H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * create a named datatype without creation order tracked for attributes and atributes in it @@ -6272,11 +6304,12 @@ gent_attr_creation_order(void) /* close attribute */ if(H5Aclose(aid) < 0) goto out; - + aid = -1; } /* end for */ if(H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * add some attributes to the root group @@ -6294,12 +6327,12 @@ gent_attr_creation_order(void) /* close attribute */ if(H5Aclose(aid) < 0) goto out; - + aid = -1; } /* end for */ if(H5Gclose(gid) < 0) goto out; - + gid = -1; /*------------------------------------------------------------------------- * close @@ -6307,15 +6340,19 @@ gent_attr_creation_order(void) */ if(H5Sclose(sid) < 0) goto out; - + sid = -1; if(H5Pclose(dcpl_id) < 0) goto out; + dcpl_id = -1; if(H5Pclose(gcpl_id) < 0) goto out; + gcpl_id = -1; if(H5Pclose(tcpl_id) < 0) goto out; + tcpl_id = -1; if(H5Fclose(fid) < 0) goto out; + fid = -1; diff --git a/tools/h5import/h5import.c b/tools/h5import/h5import.c index 3818829..60ef494 100755 --- a/tools/h5import/h5import.c +++ b/tools/h5import/h5import.c @@ -1587,16 +1587,29 @@ static int parsePathInfo(struct path_info *path, char *temp) { const char delimiter[] = "/"; - char *token = (char*) malloc(255*sizeof(char)); + char *token; int i=0; + const char *err1 = "Path string larger than MAX_PATH_NAME_LENGTH.\n"; + + token = HDstrtok (temp, delimiter); + if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH) + { + (void) fprintf(stderr, err1); + return (-1); + } + HDstrcpy(path->group[i++],token); - HDstrcpy(path->group[i++],HDstrtok (temp, delimiter)); while (1) { token = HDstrtok (NULL, delimiter); if (token == NULL) break; + if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH) + { + (void) fprintf(stderr, err1); + return (-1); + } HDstrcpy(path->group[i++],token); } path->count = i; @@ -1608,11 +1621,12 @@ parseDimensions(struct Input *in, char *strm) { const char delimiter[] = ","; char temp[255]; - char *token = (char*) malloc(255*sizeof(char)); + char *token; int i=0; const char *err1 = "Unable to allocate dynamic memory.\n"; - HDstrcpy(temp, strm); + HDstrncpy(temp, strm, sizeof(temp)); + temp[sizeof(temp)-1] = '\0'; HDstrtok (temp, delimiter); while (1) @@ -1631,7 +1645,8 @@ parseDimensions(struct Input *in, char *strm) } i=0; - HDstrcpy(temp, strm); + HDstrncpy(temp, strm, sizeof(temp)); + temp[sizeof(temp)-1] = '\0'; in->sizeOfDimension[i++] = HDstrtol(HDstrtok (temp, delimiter), NULL, BASE_10); while (1) diff --git a/tools/h5import/h5import.h b/tools/h5import/h5import.h index c43b0cf..cbc6bf2 100755 --- a/tools/h5import/h5import.h +++ b/tools/h5import/h5import.h @@ -38,6 +38,7 @@ #define ERR 20 /* invalid token */ #define MAX_GROUPS_IN_PATH 20 +#define MAX_PATH_NAME_LENGTH 255 #define NUM_KEYS 14 #define MIN_NUM_DIMENSION 1 #define MAX_NUM_DIMENSION 32 @@ -73,7 +74,7 @@ struct path_info { - char group[MAX_GROUPS_IN_PATH][255]; + char group[MAX_GROUPS_IN_PATH][MAX_PATH_NAME_LENGTH]; int count; }; diff --git a/tools/h5jam/h5jamgentest.c b/tools/h5jam/h5jamgentest.c index 5a3d828..96d113e 100644 --- a/tools/h5jam/h5jamgentest.c +++ b/tools/h5jam/h5jamgentest.c @@ -345,6 +345,8 @@ create_textfile(const char *name, size_t size) HDwrite(fd, buf, size); + free(buf); + HDclose(fd); } diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index c8a3abe..addcea3 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -114,6 +114,7 @@ h5repack_init(pack_opt_t *options, int verbose, int latest, return (options_table_init(&(options->op_tbl))); } + /*------------------------------------------------------------------------- * Function: h5repack_end * @@ -127,6 +128,7 @@ int h5repack_end (pack_opt_t *options) return options_table_free(options->op_tbl); } + /*------------------------------------------------------------------------- * Function: h5repack_addfilter * @@ -137,7 +139,6 @@ int h5repack_end (pack_opt_t *options) * *------------------------------------------------------------------------- */ - int h5repack_addfilter(const char* str, pack_opt_t *options) { @@ -149,38 +150,33 @@ int h5repack_addfilter(const char* str, /* parse the -f option */ - obj_list=parse_filter(str,&n_objs,&filter,options,&is_glb); - if (obj_list==NULL) - { + if(NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb))) return -1; - } /* if it applies to all objects */ - if (is_glb) + if(is_glb) { - int n; n = options->n_filter_g++; /* increase # of global filters */ - if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) + if(options->n_filter_g > H5_REPACK_MAX_NFILTERS) { - error_msg(progname, "maximum number of filters exceeded for <%s>\n",str); + error_msg(progname, "maximum number of filters exceeded for <%s>\n", str); + free(obj_list); return -1; - } options->filter_g[n] = filter; } - else - options_add_filter(obj_list,n_objs,filter,options->op_tbl); + options_add_filter(obj_list, n_objs, filter, options->op_tbl); free(obj_list); return 0; } - + /*------------------------------------------------------------------------- * Function: h5repack_addlayout * diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index 5b6d5d0..7c87359 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -136,6 +136,7 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs ) return 0; } + /*------------------------------------------------------------------------- * Function: options_table_init * @@ -145,33 +146,34 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs ) * *------------------------------------------------------------------------- */ - int options_table_init( pack_opttbl_t **tbl ) { unsigned int i; - pack_opttbl_t* table = (pack_opttbl_t*) malloc(sizeof(pack_opttbl_t)); - if (table==NULL) { + pack_opttbl_t *table; + + if(NULL == (table = (pack_opttbl_t *)malloc(sizeof(pack_opttbl_t)))) + { error_msg(progname, "not enough memory for options table\n"); return -1; } table->size = 30; table->nelems = 0; - table->objs = (pack_info_t*) malloc(table->size * sizeof(pack_info_t)); - if (table->objs==NULL) { + if(NULL == (table->objs = (pack_info_t*)malloc(table->size * sizeof(pack_info_t)))) + { error_msg(progname, "not enough memory for options table\n"); + free(table); return -1; } - for ( i=0; i<table->size; i++) - { + for(i = 0; i < table->size; i++) init_packobject(&table->objs[i]); - } *tbl = table; return 0; } + /*------------------------------------------------------------------------- * Function: options_table_free * diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index adaef43..aad3df4 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -4105,6 +4105,7 @@ int make_dset_reg_ref(hid_t loc_id) hdset_reg_ref_t *wbuf=NULL; /* buffer to write to disk */ int *dwbuf=NULL; /* Buffer for writing numeric data to disk */ int i; /* counting variables */ + int retval = -1; /* return value */ /* Allocate write & read buffers */ wbuf = (hdset_reg_ref_t *)calloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1); @@ -4160,24 +4161,23 @@ int make_dset_reg_ref(hid_t loc_id) if (H5Dclose(did2) < 0) goto out; - if (wbuf) + retval = 0; + +out: + if(wbuf) free(wbuf); - if (dwbuf) + if(dwbuf) free(dwbuf); - return 0; - -out: H5E_BEGIN_TRY { - H5Sclose(sid1); H5Sclose(sid2); H5Dclose(did1); H5Dclose(did2); - } H5E_END_TRY; - return -1; + + return retval; } /*------------------------------------------------------------------------- @@ -4211,9 +4211,9 @@ int write_attr_in(hid_t loc_id, GREEN } e_t; - hid_t aid; - hid_t sid; - hid_t tid; + hid_t aid = -1; + hid_t sid = -1; + hid_t tid = -1; int val, i, j, k, n; float f; @@ -4295,6 +4295,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_BITFIELD @@ -4324,6 +4325,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_OPAQUE @@ -4350,6 +4352,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_COMPOUND @@ -4387,6 +4390,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_REFERENCE @@ -4435,6 +4439,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_VLEN @@ -4479,10 +4484,13 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Aclose(aid) < 0) goto out; + aid = -1; if (H5Tclose(tid) < 0) goto out; + tid = -1; if (H5Sclose(sid) < 0) goto out; + sid = -1; /*------------------------------------------------------------------------- * H5T_ARRAY @@ -4517,6 +4525,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_INTEGER and H5T_FLOAT @@ -4594,6 +4603,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_BITFIELD @@ -4626,6 +4636,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_OPAQUE @@ -4653,6 +4664,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_COMPOUND @@ -4688,6 +4700,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_REFERENCE @@ -4742,6 +4755,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_VLEN @@ -4791,10 +4805,13 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Aclose(aid) < 0) goto out; + aid = -1; if (H5Tclose(tid) < 0) goto out; + tid = -1; if (H5Sclose(sid) < 0) goto out; + sid = -1; /*------------------------------------------------------------------------- * H5T_ARRAY @@ -4837,6 +4854,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_INTEGER and H5T_FLOAT @@ -4956,6 +4974,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_BITFIELD @@ -5010,6 +5029,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_OPAQUE @@ -5023,6 +5043,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_COMPOUND @@ -5113,6 +5134,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_REFERENCE @@ -5197,6 +5219,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_VLEN @@ -5251,10 +5274,13 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Aclose(aid) < 0) goto out; + aid = -1; if (H5Tclose(tid) < 0) goto out; + tid = -1; if (H5Sclose(sid) < 0) goto out; + sid = -1; /*------------------------------------------------------------------------- * H5T_ARRAY @@ -5288,6 +5314,7 @@ int write_attr_in(hid_t loc_id, goto out; if (H5Tclose(tid) < 0) goto out; + tid = -1; /*------------------------------------------------------------------------- * H5T_INTEGER and H5T_FLOAT diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 848ba90..91acb10 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -5810,6 +5810,51 @@ int print_data(diff_opt_t *options) } /*------------------------------------------------------------------------- + * Function: print_header + * + * Purpose: print header for difference + * + *------------------------------------------------------------------------- + */ + +static +void print_header(int pp, /* print percentage */ + int rank, + hsize_t *dims, + const char *obj1, + const char *obj2 ) +{ + int i; + + /* print header */ + parallel_print("%-16s","size:"); + print_dimensions (rank,dims); + parallel_print("%-11s",""); + print_dimensions (rank,dims); + parallel_print("\n"); + + if (pp) + { + parallel_print("%-15s %-15s %-15s %-15s %-15s\n", + "position", + (obj1!=NULL) ? obj1 : " ", + (obj2!=NULL) ? obj2 : " ", + "difference", + "relative"); + parallel_print("------------------------------------------------------------------------\n"); + } + else + { + parallel_print("%-15s %-15s %-15s %-20s\n", + "position", + (obj1!=NULL) ? obj1 : " ", + (obj2!=NULL) ? obj2 : " ", + "difference"); + parallel_print("------------------------------------------------------------\n"); + } +} + +/*------------------------------------------------------------------------- * Function: print_pos * * Purpose: print in matrix notation, converting from an array index position @@ -5835,31 +5880,7 @@ void print_pos( int *ph, /* print header */ { *ph=0; - parallel_print("%-16s","size:"); - print_dimensions (rank,dims); - parallel_print("%-11s",""); - print_dimensions (rank,dims); - parallel_print("\n"); - - if (pp) - { - parallel_print("%-15s %-15s %-15s %-15s %-15s\n", - "position", - (obj1!=NULL) ? obj1 : " ", - (obj2!=NULL) ? obj2 : " ", - "difference", - "relative"); - parallel_print("------------------------------------------------------------------------\n"); - } - else - { - parallel_print("%-15s %-15s %-15s %-20s\n", - "position", - (obj1!=NULL) ? obj1 : " ", - (obj2!=NULL) ? obj2 : " ", - "difference"); - parallel_print("------------------------------------------------------------\n"); - } + print_header(pp, rank, dims, obj1, obj2); } /* end print header */ for ( i = 0; i < rank; i++) @@ -5912,31 +5933,7 @@ void print_char_pos( int *ph, /* print header */ { *ph=0; - parallel_print("%-16s","size:"); - print_dimensions (rank,dims); - parallel_print("%-11s",""); - print_dimensions (rank,dims); - parallel_print("\n"); - - if (pp) - { - parallel_print("%-15s %-15s %-15s %-15s %-15s\n", - "position", - (obj1!=NULL) ? obj1 : " ", - (obj2!=NULL) ? obj2 : " ", - "difference", - "relative"); - parallel_print("------------------------------------------------------------------------\n"); - } - else - { - parallel_print("%-15s %-15s %-15s %-20s\n", - "position", - (obj1!=NULL) ? obj1 : " ", - (obj2!=NULL) ? obj2 : " ", - "difference"); - parallel_print("------------------------------------------------------------\n"); - } + print_header(pp, rank, dims, obj1, obj2); } /* end print header */ for ( i = 0; i < rank; i++) diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c index 7f2a80a..ad9331d 100644 --- a/tools/lib/h5diff_dset.c +++ b/tools/lib/h5diff_dset.c @@ -462,8 +462,17 @@ hsize_t diff_datasetid( hid_t did1, assert(sm_nbytes > 0); } + /* malloc return code should be verified. + * If fail, need to handle the error. + * This else branch should be recoded as a separate function. + * Note that there are many "goto error" within this branch + * that fails to address freeing other objects created here. + * E.g., sm_space. + */ sm_buf1 = malloc((size_t)sm_nbytes); + assert(sm_buf1); sm_buf2 = malloc((size_t)sm_nbytes); + assert(sm_buf2); sm_nelmts = sm_nbytes / p_type_nbytes; sm_space = H5Screate_simple(1, &sm_nelmts, NULL); @@ -537,18 +546,11 @@ hsize_t diff_datasetid( hid_t did1, H5Sclose(sm_space); /* free */ - if (sm_buf1!=NULL) - { - free(sm_buf1); - sm_buf1=NULL; - } - if (sm_buf2!=NULL) - { - free(sm_buf2); - sm_buf2=NULL; - } - - } /* hyperslab read */ + HDfree(sm_buf1); + sm_buf1 = NULL; + HDfree(sm_buf2); + sm_buf2 = NULL; + } /* hyperslab read */ }/*can_compare*/ /*------------------------------------------------------------------------- diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index fb4bd55..55075a0 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -1307,17 +1307,17 @@ h5tools_print_region_data_blocks(hid_t region_space, hid_t region_id, hsize_t curr_pos; int jndx; int type_size; - hid_t mem_space; + hid_t mem_space = -1; void *region_buf = NULL; int blkndx; - hid_t sid1; + hid_t sid1 = -1; /* Get the dataspace of the dataset */ if((sid1 = H5Dget_space(region_id)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL) + if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); /* find the dimensions of each data space from the block coordinates */ @@ -1334,15 +1334,15 @@ h5tools_print_region_data_blocks(hid_t region_space, hid_t region_id, if((type_size = H5Tget_size(type_id)) == 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - if((region_buf = malloc(type_size * numelem)) == NULL) + if((region_buf = HDmalloc(type_size * numelem)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate region buffer"); /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ /* 1 2 n 1 2 n */ - if((start = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL) + if((start = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for start"); - if((count = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL) + if((count = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for count"); curr_pos = 0; @@ -1408,10 +1408,10 @@ h5tools_print_region_data_blocks(hid_t region_space, hid_t region_id, } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ done: - free(start); - free(count); - free(region_buf); - free(dims1); + HDfree(start); + HDfree(count); + HDfree(region_buf); + HDfree(dims1); if(H5Sclose(mem_space) < 0) HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); @@ -1648,18 +1648,17 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, int indx; int jndx; int type_size; - hid_t mem_space; - hid_t dtype; + hid_t mem_space = -1; void *region_buf = NULL; if((type_size = H5Tget_size(type_id)) == 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - if((region_buf = malloc(type_size * npoints)) == NULL) + if((region_buf = HDmalloc(type_size * npoints)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region"); /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL) + if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); dims1[0] = npoints; @@ -1723,8 +1722,8 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, } /* end for (jndx = 0; jndx < npoints; jndx++, region_elmtno++) */ done: - free(region_buf); - free(dims1); + HDfree(region_buf); + HDfree(dims1); if(H5Sclose(mem_space) < 0) HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); @@ -1972,7 +1971,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c hsize_t sm_nbytes; /* bytes per stripmine */ hsize_t sm_nelmts; /* elements per stripmine*/ unsigned char *sm_buf = NULL; /* buffer for raw data */ - hid_t sm_space; /* stripmine data space */ + hid_t sm_space = -1; /* stripmine data space */ hsize_t size_row_block; /* size for blocks along rows */ hsize_t row_counter = 0; @@ -2025,7 +2024,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c } assert(sm_nbytes == (hsize_t) ((size_t) sm_nbytes)); /*check for overflow*/ - if((sm_buf = malloc((size_t) sm_nelmts * p_type_nbytes)) == NULL) + if((sm_buf = HDmalloc((size_t) sm_nelmts * p_type_nbytes)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine"); if((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0) @@ -2070,7 +2069,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c done: if(H5Sclose(sm_space) < 0) HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); - free(sm_buf); + HDfree(sm_buf); } else H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print"); @@ -3379,14 +3378,18 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type) CATCH - /* Release resources */ - for (i = 0; i < nmembs; i++) - free(name[i]); + if(name) { + /* Release resources */ + for (i = 0; i < nmembs; i++) + if(name[i]) + free(name[i]); + free(name); + } /* end if */ - free(name); - free(value); - - if(H5Tclose(super) < 0) + if(value) + free(value); + + if(super >= 0 && H5Tclose(super) < 0) H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if (0 == nmembs) diff --git a/vms/src/h5pubconf.h b/vms/src/h5pubconf.h index 395feaf..d08e5dd 100644 --- a/vms/src/h5pubconf.h +++ b/vms/src/h5pubconf.h @@ -480,13 +480,13 @@ #define H5_PACKAGE_NAME "HDF5" /* Define to the full name and version of this package. */ -#define H5_PACKAGE_STRING "HDF5 1.9.52-FA_a4" +#define H5_PACKAGE_STRING "HDF5 1.9.54-FA_a4" /* Define to the one symbol short name of this package. */ #define H5_PACKAGE_TARNAME "hdf5" /* Define to the version of this package. */ -#define H5_PACKAGE_VERSION "1.9.52-FA_a4" +#define H5_PACKAGE_VERSION "1.9.54-FA_a4" /* Width for printf() for type `long long' or `__int64', use `ll' */ #define H5_PRINTF_LL_WIDTH "ll" @@ -639,7 +639,7 @@ /* #undef H5_USING_MEMCHECKER */ /* Version number of package */ -#define H5_VERSION "1.9.52-FA_a4" +#define H5_VERSION "1.9.54-FA_a4" /* Define if vsnprintf() returns the correct value for formatted strings that don't fit into size allowed */ diff --git a/windows/proj/hdf5/hdf5.vcproj b/windows/proj/hdf5/hdf5.vcproj index 3cb9708..8c72991 100644 --- a/windows/proj/hdf5/hdf5.vcproj +++ b/windows/proj/hdf5/hdf5.vcproj @@ -1133,6 +1133,10 @@ >
</File>
<File
+ RelativePath="..\..\..\src\H5SMmessage.c"
+ >
+ </File>
+ <File
RelativePath="..\..\..\src\H5Smpio.c"
>
</File>
diff --git a/windows/proj/hdf5dll/hdf5dll.vcproj b/windows/proj/hdf5dll/hdf5dll.vcproj index 7f18944..68a8719 100644 --- a/windows/proj/hdf5dll/hdf5dll.vcproj +++ b/windows/proj/hdf5dll/hdf5dll.vcproj @@ -1224,6 +1224,10 @@ >
</File>
<File
+ RelativePath="..\..\..\src\H5SMmessage.c"
+ >
+ </File>
+ <File
RelativePath="..\..\..\src\H5Smpio.c"
>
</File>
diff --git a/windows/src/H5pubconf.h b/windows/src/H5pubconf.h index 98916a4..9af80ec 100755 --- a/windows/src/H5pubconf.h +++ b/windows/src/H5pubconf.h @@ -479,13 +479,13 @@ #define H5_PACKAGE_NAME "HDF5" /* Define to the full name and version of this package. */ -#define H5_PACKAGE_STRING "HDF5 1.9.52-FA_a4" +#define H5_PACKAGE_STRING "HDF5 1.9.54-FA_a4" /* Define to the one symbol short name of this package. */ #define H5_PACKAGE_TARNAME "hdf5" /* Define to the version of this package. */ -#define H5_PACKAGE_VERSION "1.9.52-FA_a4" +#define H5_PACKAGE_VERSION "1.9.54-FA_a4" /* Width for printf() for type `long long' or `__int64', use `ll' */ #define H5_PRINTF_LL_WIDTH "I64" @@ -642,7 +642,7 @@ /* #undef H5_USING_MEMCHECKER */ /* Version number of package */ -#define H5_VERSION "1.9.52-FA_a4" +#define H5_VERSION "1.9.54-FA_a4" /* Define if vsnprintf() returns the correct value for formatted strings that don't fit into size allowed */ |