summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Aint.c16
-rw-r--r--test/objcopy.c80
-rw-r--r--tools/h5copy/h5copygentest.c93
3 files changed, 112 insertions, 77 deletions
diff --git a/src/H5Aint.c b/src/H5Aint.c
index 3cc8115..5c5be39 100644
--- a/src/H5Aint.c
+++ b/src/H5Aint.c
@@ -2098,11 +2098,11 @@ H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_si
HDmemcpy(buf, attr_src->shared->data, attr_src->shared->data_size);
- /* Allocate background memory */
- if(H5T_path_bkg(tpath_src_mem) || H5T_path_bkg(tpath_mem_dst)) {
- if(NULL == (bkg_buf = H5FL_BLK_CALLOC(attr_buf, buf_size)))
- HGOTO_ERROR(H5E_ATTR, H5E_CANTALLOC, FAIL, "memory allocation failed")
- }
+ /* Allocate background memory */
+ if(H5T_path_bkg(tpath_src_mem) || H5T_path_bkg(tpath_mem_dst)) {
+ if(NULL == (bkg_buf = H5FL_BLK_CALLOC(attr_buf, buf_size)))
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTALLOC, FAIL, "memory allocation failed")
+ }
/* Convert from source file to memory */
if(H5T_convert(tpath_src_mem, tid_src, tid_mem, nelmts, (size_t)0, (size_t)0, buf, bkg_buf, dxpl_id) < 0)
@@ -2110,9 +2110,9 @@ H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_si
HDmemcpy(reclaim_buf, buf, buf_size);
- /* Set background buffer to all zeros */
- if(bkg_buf)
- HDmemset(bkg_buf, 0, buf_size);
+ /* Set background buffer to all zeros */
+ if(bkg_buf)
+ HDmemset(bkg_buf, 0, buf_size);
/* Convert from memory to destination file */
if(H5T_convert(tpath_mem_dst, tid_mem, tid_dst, nelmts, (size_t)0, (size_t)0, buf, bkg_buf, dxpl_id) < 0)
diff --git a/test/objcopy.c b/test/objcopy.c
index 44d673d..3e20ac4 100644
--- a/test/objcopy.c
+++ b/test/objcopy.c
@@ -21,7 +21,7 @@
*/
#include "testhdf5.h"
-#include "H5srcdir.h"
+#include "h5test.h"
/*
* This file needs to access private information from the H5S package.
@@ -4635,35 +4635,35 @@ compare_attribute_compound_vlstr(hid_t loc, hid_t loc2)
/* Open the attributes attached to the objects */
if((aid = H5Aopen_by_idx(loc, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
if((aid2 = H5Aopen_by_idx(loc2, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Get the attributes' datatypes */
if((tid = H5Aget_type(aid)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
if((tid2 = H5Aget_type(aid2)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Read the attributes */
if(H5Aread(aid, tid, &rbuf) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
if(H5Aread(aid2, tid2, &rbuf2) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Compare the attributes' data */
if(rbuf.i != rbuf2.i)
- FAIL_STACK_ERROR
+ TEST_ERROR
if(HDstrlen(rbuf.v) != HDstrlen(rbuf2.v))
- FAIL_STACK_ERROR
+ TEST_ERROR
if(HDmemcmp(rbuf.v, rbuf2.v, HDstrlen(rbuf.v)))
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Close the attributes */
if(H5Aclose(aid) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
if(H5Aclose(aid2) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
return TRUE;
error:
@@ -4716,7 +4716,7 @@ test_copy_attribute_compound_vlstr(hid_t fcpl_src, hid_t fcpl_dst, hid_t src_fap
/* create source file */
if((fid_src = H5Fcreate(src_filename, H5F_ACC_TRUNC, fcpl_src, src_fapl)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* set dataspace dimensions */
dim2d[0] = DIM_SIZE_1;
@@ -4724,103 +4724,103 @@ test_copy_attribute_compound_vlstr(hid_t fcpl_src, hid_t fcpl_dst, hid_t src_fap
/* create 2D dataspace */
if((sid = H5Screate_simple(2, dim2d, NULL)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* create 2D int dataset at SRC file */
if((did = H5Dcreate2(fid_src, NAME_DATASET_SIMPLE, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close dataspace */
if(H5Sclose(sid) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* attach an attribute to the dataset */
if(attach_attribute_compound_vlstr(did) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close the dataset */
if(H5Dclose(did) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* create a group */
if((gid = H5Gcreate2(fid_src, NAME_GROUP_EMPTY, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* attach attribute to the group */
if(attach_attribute_compound_vlstr(gid) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close the group */
if(H5Gclose(gid) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close the SRC file */
if(H5Fclose(fid_src) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* open the source file with read-only */
if((fid_src = H5Fopen(src_filename, H5F_ACC_RDONLY, src_fapl)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* create destination file */
if((fid_dst = H5Fcreate(dst_filename, H5F_ACC_TRUNC, fcpl_dst, dst_fapl)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Create an uncopied object in destination file so that addresses in source and destination files aren't the same */
if(H5Gclose(H5Gcreate2(fid_dst, NAME_GROUP_UNCOPIED, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* copy the dataset from SRC to DST */
if(H5Ocopy(fid_src, NAME_DATASET_SIMPLE, fid_dst, NAME_DATASET_SIMPLE, H5P_DEFAULT, H5P_DEFAULT) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* open the src dataset */
if((did = H5Dopen2(fid_src, NAME_DATASET_SIMPLE, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* open the destination dataset */
if((did2 = H5Dopen2(fid_dst, NAME_DATASET_SIMPLE, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* compare the data of the attributes attached to the two datasets */
if(compare_attribute_compound_vlstr(did, did2) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close the datasets */
if(H5Dclose(did2) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
if(H5Dclose(did) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Copy the group */
if(H5Ocopy(fid_src, NAME_GROUP_EMPTY, fid_dst, NAME_GROUP_EMPTY, H5P_DEFAULT, H5P_DEFAULT) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Open the src group */
if((gid = H5Gopen2(fid_src, NAME_GROUP_EMPTY, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Open the destination group */
if((gid2 = H5Gopen2(fid_dst, NAME_GROUP_EMPTY, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* compare the data of the attributes attached to the two groups */
if(compare_attribute_compound_vlstr(gid, gid2) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close the groups */
if(H5Gclose(gid) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
if(H5Gclose(gid2) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close the SRC file */
if(H5Fclose(fid_src) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* close the DST file */
if(H5Fclose(fid_dst) < 0)
- FAIL_STACK_ERROR
+ TEST_ERROR
PASSED();
return 0;
@@ -9428,7 +9428,7 @@ test_copy_committed_dt_merge_attr(hid_t fcpl_src, hid_t fcpl_dst, hid_t src_fapl
if((aid = H5Acreate2(gid, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
/* write data into file */
- //if(H5Awrite(aid, tid, buf) < 0) TEST_ERROR
+ if(H5Awrite(aid, tid, buf) < 0) TEST_ERROR
/* close the datatype */
if(H5Tclose(tid) < 0) TEST_ERROR
diff --git a/tools/h5copy/h5copygentest.c b/tools/h5copy/h5copygentest.c
index f15a2d8..2a127a7 100644
--- a/tools/h5copy/h5copygentest.c
+++ b/tools/h5copy/h5copygentest.c
@@ -34,12 +34,12 @@
#define DATASET_COMPRESSED "compressed"
#define DATASET_NAMED_VL "named_vl"
#define DATASET_NESTED_VL "nested_vl"
-#define DATASET_ATTR "dset_attr"
-#define ATTR "attr"
+#define DATASET_ATTR "dset_attr"
+#define ATTR "attr"
#define GROUP_EMPTY "grp_empty"
#define GROUP_DATASETS "grp_dsets"
#define GROUP_NESTED "grp_nested"
-#define GROUP_ATTR "grp_attr"
+#define GROUP_ATTR "grp_attr"
/* Obj reference */
#define OBJ_REF_DS "Dset1"
@@ -328,8 +328,8 @@ static void gent_nested_vl(hid_t loc_id)
* Function: gent_att_compound_vlstr
*
* Purpose: Generate a dataset and a group.
- * Both has an attribute with a compound datatype consisting
- * of a variable length string
+ * Both has an attribute with a compound datatype consisting
+ * of a variable length string
*
*-------------------------------------------------------------------------
*/
@@ -348,59 +348,94 @@ static void gent_att_compound_vlstr(hid_t loc_id)
hid_t vl_str_tid = -1; /* Variable length datatype ID */
hid_t cmpd_tid = -1; /* Compound datatype ID */
hid_t null_sid = -1; /* Null dataspace ID */
- s1 buf; /* Buffer */
+ s1 buf; /* Buffer */
buf.i = 9;
buf.v = "ThisIsAString";
/* Create an integer datatype */
- tid = H5Tcopy(H5T_NATIVE_INT);
+ if((tid = H5Tcopy(H5T_NATIVE_INT)) < 0)
+ goto error;
/* Create a variable length string */
- vl_str_tid = H5Tcopy(H5T_C_S1);
- H5Tset_size(vl_str_tid, H5T_VARIABLE);
+ if((vl_str_tid = H5Tcopy(H5T_C_S1)) < 0)
+ goto error;
+ if(H5Tset_size(vl_str_tid, H5T_VARIABLE) < 0)
+ goto error;
/* Create a compound datatype with a variable length string and an integer */
- cmpd_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1));
- H5Tinsert(cmpd_tid, "i", HOFFSET(s1, i), tid);
- H5Tinsert(cmpd_tid, "v", HOFFSET(s1, v), vl_str_tid);
+ if((cmpd_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0)
+ goto error;
+ if(H5Tinsert(cmpd_tid, "i", HOFFSET(s1, i), tid) < 0)
+ goto error;
+ if(H5Tinsert(cmpd_tid, "v", HOFFSET(s1, v), vl_str_tid) < 0)
+ goto error;
/* Create a dataset */
- null_sid = H5Screate(H5S_NULL);
- did = H5Dcreate2(loc_id, DATASET_ATTR, H5T_NATIVE_INT, null_sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if((null_sid = H5Screate(H5S_NULL)) < 0)
+ goto error;
+ if((did = H5Dcreate2(loc_id, DATASET_ATTR, H5T_NATIVE_INT, null_sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
/* Attach an attribute with the compound datatype to the dataset */
- sid = H5Screate_simple(1, dim, dim);
- aid = H5Acreate2(did, ATTR, cmpd_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
+ if((sid = H5Screate_simple(1, dim, dim)) < 0)
+ goto error;
+ if((aid = H5Acreate2(did, ATTR, cmpd_tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
/* Write the attribute */
buf.i = 9;
buf.v = "ThisIsAString";
- H5Awrite(aid, cmpd_tid, &buf);
+ if(H5Awrite(aid, cmpd_tid, &buf) < 0)
+ goto error;
/* Close the dataset and its attribute */
- H5Dclose(did);
- H5Aclose(aid);
+ if(H5Dclose(did) < 0)
+ goto error;
+ if(H5Aclose(aid) < 0)
+ goto error;
/* Create a group */
- gid = H5Gcreate2(loc_id, GROUP_ATTR, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if((gid = H5Gcreate2(loc_id, GROUP_ATTR, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
/* Attach an attribute with the compound datatype to the group */
- aid = H5Acreate2(gid, ATTR, cmpd_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
- H5Awrite(aid, cmpd_tid, &buf);
+ if((aid = H5Acreate2(gid, ATTR, cmpd_tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ if(H5Awrite(aid, cmpd_tid, &buf) < 0)
+ goto error;
/* Close the group and its attribute */
- H5Aclose(aid);
- H5Gclose(gid);
+ if(H5Aclose(aid) < 0)
+ goto error;
+ if(H5Gclose(gid) < 0)
+ goto error;
/* Close dataspaces */
- H5Sclose(sid);
- H5Sclose(null_sid);
+ if(H5Sclose(sid) < 0)
+ goto error;
+ if(H5Sclose(null_sid) < 0)
+ goto error;
/* Close datatypes */
- H5Tclose(tid);
- H5Tclose(vl_str_tid);
- H5Tclose(cmpd_tid);
+ if(H5Tclose(tid) < 0)
+ goto error;
+ if(H5Tclose(vl_str_tid) < 0)
+ goto error;
+ if(H5Tclose(cmpd_tid) < 0)
+ goto error;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Tclose(tid);
+ H5Tclose(vl_str_tid);
+ H5Tclose(cmpd_tid);
+ H5Sclose(null_sid);
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Aclose(aid);
+ H5Gclose(gid);
+ } H5E_END_TRY;
} /* gen_att_compound_vlstr() */