diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2020-04-25 23:49:04 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2020-04-25 23:49:04 (GMT) |
commit | a8676d74d9fc50c0da4dcf4cf5646e4a8b2352ba (patch) | |
tree | e10dce719d3ddb94a1a89c9c498a2df23f2df2b2 /tools/test/h5repack/h5repacktst.c | |
parent | e54f5a14d28cf9eb1226ce7feab2e2600d3984b4 (diff) | |
download | hdf5-a8676d74d9fc50c0da4dcf4cf5646e4a8b2352ba.zip hdf5-a8676d74d9fc50c0da4dcf4cf5646e4a8b2352ba.tar.gz hdf5-a8676d74d9fc50c0da4dcf4cf5646e4a8b2352ba.tar.bz2 |
Fixes for warnings in the tools code.
Diffstat (limited to 'tools/test/h5repack/h5repacktst.c')
-rw-r--r-- | tools/test/h5repack/h5repacktst.c | 543 |
1 files changed, 283 insertions, 260 deletions
diff --git a/tools/test/h5repack/h5repacktst.c b/tools/test/h5repack/h5repacktst.c index ac1fbe0..ab0dbb7 100644 --- a/tools/test/h5repack/h5repacktst.c +++ b/tools/test/h5repack/h5repacktst.c @@ -2479,24 +2479,24 @@ int make_szip(hid_t loc_id) unsigned szip_pixels_per_block = 8; hsize_t dims[RANK] = {DIM1, DIM2}; hsize_t chunk_dims[RANK] = {CDIM1, CDIM2}; - int buf[DIM1][DIM2]; - int i, j, n; + int **buf = NULL; int szip_can_encode = 0; - for (i = n = 0; i < DIM1; i++) { - for (j = 0; j < DIM2; j++) { - buf[i][j] = n++; - } - } + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); + /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dcpl */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; /* set up chunk */ if(H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; + goto error; /*------------------------------------------------------------------------- * SZIP @@ -2509,25 +2509,30 @@ int make_szip(hid_t loc_id) if (szip_can_encode) { /* set szip data */ if(H5Pset_szip (dcpl, szip_options_mask, szip_pixels_per_block) < 0) - goto out; - if (make_dset(loc_id, "dset_szip", sid, dcpl, buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_szip", sid, dcpl, buf[0]) < 0) + goto error; } else /* WARNING? SZIP is decoder only, can't generate test files */ if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Pclose(dcpl); H5Sclose(sid); } H5E_END_TRY; + + HDfree(buf); + return -1; } #endif /* H5_HAVE_FILTER_SZIP */ @@ -2548,26 +2553,25 @@ int make_deflate(hid_t loc_id) hid_t sid = H5I_INVALID_HID; /* dataspace ID */ hsize_t dims[RANK] = {DIM1,DIM2}; hsize_t chunk_dims[RANK] = {CDIM1,CDIM2}; - int buf[DIM1][DIM2]; + int **buf = NULL; hobj_ref_t bufref[1]; /* reference */ hsize_t dims1r[1] = {1}; - int i, j, n; - for (i = n = 0; i < DIM1; i++) { - for (j = 0; j < DIM2; j++) { - buf[i][j] = n++; - } - } + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dcpl */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; /* set up chunk */ if(H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; + goto error; /*------------------------------------------------------------------------- * GZIP @@ -2576,16 +2580,16 @@ int make_deflate(hid_t loc_id) #if defined (H5_HAVE_FILTER_DEFLATE) /* set deflate data */ if(H5Pset_deflate(dcpl, 9) < 0) - goto out; - if (make_dset(loc_id, "dset_deflate", sid, dcpl, buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_deflate", sid, dcpl, buf[0]) < 0) + goto error; /* create a reference to the dataset, test second seeep of file for references */ if (H5Rcreate(&bufref[0], loc_id, "dset_deflate", H5R_OBJECT, (hid_t)-1) < 0) - goto out; + goto error; if (write_dset(loc_id, 1, dims1r, "ref", H5T_STD_REF_OBJ, bufref) < 0) - goto out; + goto error; #endif @@ -2594,17 +2598,22 @@ int make_deflate(hid_t loc_id) *------------------------------------------------------------------------- */ if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Pclose(dcpl); H5Sclose(sid); } H5E_END_TRY; + + HDfree(buf); + return -1; } @@ -2619,29 +2628,27 @@ out: static int make_shuffle(hid_t loc_id) { - hid_t dcpl; /* dataset creation property list */ - hid_t sid; /* dataspace ID */ + hid_t dcpl = H5I_INVALID_HID; /* dataset creation property list */ + hid_t sid = H5I_INVALID_HID; /* dataspace ID */ hsize_t dims[RANK]={DIM1,DIM2}; hsize_t chunk_dims[RANK]={CDIM1,CDIM2}; - int buf[DIM1][DIM2]; - int i, j, n; + int **buf = NULL; + + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); - for (i=n=0; i<DIM1; i++) - { - for (j=0; j<DIM2; j++) - { - buf[i][j]=n++; - } - } /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dcpl */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; /* set up chunk */ if(H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; + goto error; /*------------------------------------------------------------------------- * shuffle @@ -2650,9 +2657,9 @@ int make_shuffle(hid_t loc_id) /* set the shuffle filter */ if (H5Pset_shuffle(dcpl) < 0) - goto out; - if (make_dset(loc_id,"dset_shuffle",sid,dcpl,buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_shuffle", sid, dcpl, buf[0]) < 0) + goto error; /*------------------------------------------------------------------------- @@ -2660,17 +2667,22 @@ int make_shuffle(hid_t loc_id) *------------------------------------------------------------------------- */ if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Pclose(dcpl); H5Sclose(sid); } H5E_END_TRY; + + HDfree(buf); + return -1; } @@ -2688,23 +2700,23 @@ int make_fletcher32(hid_t loc_id) hid_t sid = H5I_INVALID_HID; /* dataspace ID */ hsize_t dims[RANK]={DIM1,DIM2}; hsize_t chunk_dims[RANK]={CDIM1,CDIM2}; - int buf[DIM1][DIM2]; - int i, j, n; + int **buf = NULL; + + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); - for (i = n = 0; i < DIM1; i++) { - for (j = 0; j < DIM2; j++) { - buf[i][j] = n++; - } - } /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; /* set up chunk */ if(H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; + goto error; /*------------------------------------------------------------------------- @@ -2714,29 +2726,34 @@ int make_fletcher32(hid_t loc_id) /* remove the filters from the dcpl */ if (H5Premove_filter(dcpl,H5Z_FILTER_ALL) < 0) - goto out; + goto error; /* set the checksum filter */ if (H5Pset_fletcher32(dcpl) < 0) - goto out; - if (make_dset(loc_id,"dset_fletcher32",sid,dcpl,buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_fletcher32", sid, dcpl, buf[0]) < 0) + goto error; /*------------------------------------------------------------------------- * close space and dcpl *------------------------------------------------------------------------- */ if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Pclose(dcpl); H5Sclose(sid); } H5E_END_TRY; + + HDfree(buf); + return -1; } @@ -2757,45 +2774,45 @@ int make_nbit(hid_t loc_id) hid_t dsid = H5I_INVALID_HID; hsize_t dims[RANK]={DIM1,DIM2}; hsize_t chunk_dims[RANK]={CDIM1,CDIM2}; - int buf[DIM1][DIM2]; - int i, j, n; + int **buf = NULL; + + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); - for (i = n = 0; i < DIM1; i++) { - for (j = 0; j < DIM2; j++) { - buf[i][j] = n++; - } - } /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; /* set up chunk */ if(H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; + goto error; dtid = H5Tcopy(H5T_NATIVE_INT); if (H5Tset_precision(dtid,(H5Tget_precision(dtid) - 1)) < 0) - goto out; + goto error; /* remove the filters from the dcpl */ if(H5Premove_filter(dcpl, H5Z_FILTER_ALL) < 0) - goto out; + goto error; if(H5Pset_nbit(dcpl) < 0) - goto out; + goto error; if((dsid = H5Dcreate2(loc_id, "dset_nbit", dtid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - goto out; - if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto out; + goto error; + if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0) + goto error; H5Dclose(dsid); if(H5Premove_filter(dcpl, H5Z_FILTER_ALL) < 0) - goto out; + goto error; if((dsid = H5Dcreate2(loc_id, "dset_int31", dtid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - goto out; - if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto out; + goto error; + if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0) + goto error; H5Dclose(dsid); /*------------------------------------------------------------------------- @@ -2803,21 +2820,26 @@ int make_nbit(hid_t loc_id) *------------------------------------------------------------------------- */ if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; if (H5Tclose(dtid) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Tclose(dtid); H5Pclose(dcpl); H5Sclose(sid); H5Dclose(dsid); } H5E_END_TRY; + + HDfree(buf); + return -1; } @@ -2838,40 +2860,40 @@ int make_scaleoffset(hid_t loc_id) hid_t dsid = H5I_INVALID_HID; hsize_t dims[RANK] = {DIM1,DIM2}; hsize_t chunk_dims[RANK] = {CDIM1,CDIM2}; - int buf[DIM1][DIM2]; - int i, j, n; + int **buf = NULL; + + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); - for (i = n = 0; i < DIM1; i++) { - for (j = 0; j < DIM2; j++) { - buf[i][j] = n++; - } - } /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; /* set up chunk */ if(H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; + goto error; dtid = H5Tcopy(H5T_NATIVE_INT); /* remove the filters from the dcpl */ if(H5Premove_filter(dcpl, H5Z_FILTER_ALL) < 0) - goto out; + goto error; if(H5Pset_scaleoffset(dcpl, H5Z_SO_INT, 31) < 0) - goto out; + goto error; if((dsid = H5Dcreate2(loc_id, "dset_scaleoffset", dtid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - goto out; - if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto out; + goto error; + if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0) + goto error; H5Dclose(dsid); if((dsid = H5Dcreate2(loc_id, "dset_none", dtid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto out; - if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto out; + goto error; + if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0) + goto error; H5Tclose(dtid); H5Dclose(dsid); @@ -2880,19 +2902,24 @@ int make_scaleoffset(hid_t loc_id) *------------------------------------------------------------------------- */ if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Dclose(dsid); H5Tclose(dtid); H5Pclose(dcpl); H5Sclose(sid); } H5E_END_TRY; + + HDfree(buf); + return -1; } @@ -2912,41 +2939,39 @@ int make_all_filters(hid_t loc_id) hid_t dtid = H5I_INVALID_HID; hid_t dsid = H5I_INVALID_HID; #if defined (H5_HAVE_FILTER_SZIP) - unsigned szip_options_mask=H5_SZIP_ALLOW_K13_OPTION_MASK|H5_SZIP_NN_OPTION_MASK; - unsigned szip_pixels_per_block=8; + unsigned szip_options_mask = H5_SZIP_ALLOW_K13_OPTION_MASK | H5_SZIP_NN_OPTION_MASK; + unsigned szip_pixels_per_block = 8; #endif /* H5_HAVE_FILTER_SZIP */ hsize_t dims[RANK]={DIM1,DIM2}; hsize_t chunk_dims[RANK]={CDIM1,CDIM2}; - int buf[DIM1][DIM2]; - int i, j, n; + int **buf = NULL; #if defined (H5_HAVE_FILTER_SZIP) int szip_can_encode = 0; #endif - for (i=n=0; i<DIM1; i++) - { - for (j=0; j<DIM2; j++) - { - buf[i][j]=n++; - } - } + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); + /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; /* set up chunk */ if (H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; + goto error; /* set the shuffle filter */ if (H5Pset_shuffle(dcpl) < 0) - goto out; + goto error; /* set the checksum filter */ if (H5Pset_fletcher32(dcpl) < 0) - goto out; + goto error; #if defined (H5_HAVE_FILTER_SZIP) if (h5tools_can_encode(H5Z_FILTER_SZIP) == 1) @@ -2956,8 +2981,8 @@ int make_all_filters(hid_t loc_id) if (szip_can_encode) { /* set szip data */ - if(H5Pset_szip (dcpl,szip_options_mask,szip_pixels_per_block) < 0) - goto out; + if(H5Pset_szip (dcpl,szip_options_mask, szip_pixels_per_block) < 0) + goto error; } else { /* WARNING? SZIP is decoder only, can't generate test data using szip */ } @@ -2966,20 +2991,20 @@ int make_all_filters(hid_t loc_id) #if defined (H5_HAVE_FILTER_DEFLATE) /* set deflate data */ if(H5Pset_deflate(dcpl, 9) < 0) - goto out; + goto error; #endif - if (make_dset(loc_id,"dset_all",sid,dcpl,buf) < 0) - goto out; + if (make_dset(loc_id, "dset_all", sid, dcpl, buf[0]) < 0) + goto error; /* remove the filters from the dcpl */ if (H5Premove_filter(dcpl,H5Z_FILTER_ALL) < 0) - goto out; + goto error; /* set the checksum filter */ if (H5Pset_fletcher32(dcpl) < 0) - goto out; - if (make_dset(loc_id,"dset_fletcher32",sid,dcpl,buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_fletcher32", sid, dcpl, buf[0]) < 0) + goto error; /* Make sure encoding is enabled */ @@ -2988,12 +3013,12 @@ int make_all_filters(hid_t loc_id) { /* remove the filters from the dcpl */ if (H5Premove_filter(dcpl,H5Z_FILTER_ALL) < 0) - goto out; + goto error; /* set szip data */ if(H5Pset_szip (dcpl,szip_options_mask,szip_pixels_per_block) < 0) - goto out; - if (make_dset(loc_id,"dset_szip",sid,dcpl,buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_szip", sid, dcpl, buf[0]) < 0) + goto error; } else { /* WARNING? SZIP is decoder only, can't generate test dataset */ @@ -3003,56 +3028,58 @@ int make_all_filters(hid_t loc_id) /* remove the filters from the dcpl */ if (H5Premove_filter(dcpl,H5Z_FILTER_ALL) < 0) - goto out; + goto error; /* set the shuffle filter */ if (H5Pset_shuffle(dcpl) < 0) - goto out; - if (make_dset(loc_id,"dset_shuffle",sid,dcpl,buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_shuffle", sid, dcpl, buf[0]) < 0) + goto error; #if defined (H5_HAVE_FILTER_DEFLATE) /* remove the filters from the dcpl */ if (H5Premove_filter(dcpl,H5Z_FILTER_ALL) < 0) - goto out; + goto error; /* set deflate data */ if(H5Pset_deflate(dcpl, 1) < 0) - goto out; - if (make_dset(loc_id,"dset_deflate",sid,dcpl,buf) < 0) - goto out; + goto error; + if (make_dset(loc_id, "dset_deflate", sid, dcpl, buf[0]) < 0) + goto error; #endif /* remove the filters from the dcpl */ if (H5Premove_filter(dcpl, H5Z_FILTER_ALL) < 0) - goto out; + goto error; /* set the shuffle filter */ if (H5Pset_nbit(dcpl) < 0) - goto out; + goto error; if ((dtid = H5Tcopy(H5T_NATIVE_INT)) < 0) - goto out; + goto error; if (H5Tset_precision(dtid, (H5Tget_precision(dtid) - 1)) < 0) - goto out; + goto error; if((dsid = H5Dcreate2(loc_id, "dset_nbit", dtid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - goto out; - if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto out; + goto error; + if(H5Dwrite(dsid, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0) + goto error; /* close */ if(H5Tclose(dtid) < 0) - goto out; + goto error; if(H5Dclose(dsid) < 0) - goto out; + goto error; if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Tclose(dtid); @@ -3060,6 +3087,9 @@ out: H5Pclose(dcpl); H5Sclose(sid); } H5E_END_TRY; + + HDfree(buf); + return -1; } @@ -3176,28 +3206,25 @@ int make_layout(hid_t loc_id) hid_t sid=H5I_INVALID_HID; /* dataspace ID */ hsize_t dims[RANK]={DIM1,DIM2}; hsize_t chunk_dims[RANK]={CDIM1,CDIM2}; - int buf[DIM1][DIM2]; - int i, j, n; + int **buf = NULL; + int i; char name[16]; + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(buf, int, DIM1, DIM2); + if (NULL == buf) + goto error; + H5TEST_FILL_2D_ARRAY(buf, int, DIM1, DIM2); - for (i=n=0; i<DIM1; i++) - { - for (j=0; j<DIM2; j++) - { - buf[i][j]=n++; - } - } /*------------------------------------------------------------------------- * make several dataset with no filters *------------------------------------------------------------------------- */ - for (i=0; i<4; i++) - { + for (i=0; i<4; i++) { HDsprintf(name,"dset%d",i+1); - if (write_dset(loc_id,RANK,dims,name,H5T_NATIVE_INT,buf) < 0) - return -1; + if (write_dset(loc_id, RANK, dims, name, H5T_NATIVE_INT, buf[0]) < 0) + goto error; } @@ -3207,63 +3234,60 @@ int make_layout(hid_t loc_id) */ /* create a space */ if((sid = H5Screate_simple(RANK, dims, NULL)) < 0) - return -1; + goto error; /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - { - goto out; - } + goto error; /*------------------------------------------------------------------------- * H5D_COMPACT *------------------------------------------------------------------------- */ if(H5Pset_layout (dcpl,H5D_COMPACT) < 0) - goto out; - if (make_dset(loc_id,"dset_compact",sid,dcpl,buf) < 0) - { - goto out; - } + goto error; + if (make_dset(loc_id, "dset_compact", sid, dcpl, buf[0]) < 0) + goto error; /*------------------------------------------------------------------------- * H5D_CONTIGUOUS *------------------------------------------------------------------------- */ if(H5Pset_layout (dcpl,H5D_CONTIGUOUS) < 0) - goto out; - if (make_dset(loc_id,"dset_contiguous",sid,dcpl,buf) < 0) - { - goto out; - } + goto error; + if (make_dset(loc_id, "dset_contiguous", sid, dcpl, buf[0]) < 0) + goto error; /*------------------------------------------------------------------------- * H5D_CHUNKED *------------------------------------------------------------------------- */ if(H5Pset_chunk(dcpl, RANK, chunk_dims) < 0) - goto out; - if (make_dset(loc_id,"dset_chunk",sid,dcpl,buf) < 0) - { - goto out; - } + goto error; + if (make_dset(loc_id, "dset_chunk", sid, dcpl, buf[0]) < 0) + goto error; /*------------------------------------------------------------------------- * close space and dcpl *------------------------------------------------------------------------- */ if(H5Sclose(sid) < 0) - goto out; + goto error; if(H5Pclose(dcpl) < 0) - goto out; + goto error; + + HDfree(buf); return 0; -out: +error: H5E_BEGIN_TRY { H5Pclose(dcpl); H5Sclose(sid); } H5E_END_TRY; + + HDfree(buf); + return -1; } @@ -3289,44 +3313,45 @@ int make_layout2(hid_t loc_id) hid_t contig_dcpl = H5I_INVALID_HID; /* dataset creation property list */ hid_t chunked_dcpl = H5I_INVALID_HID; /* dataset creation property list */ - int i, j, n; /* Local index variables */ int ret_value = -1; /* Return value */ hid_t s_sid = H5I_INVALID_HID; /* dataspace ID */ hsize_t s_dims[RANK] = {S_DIM1,S_DIM2}; /* Dataspace (< 1 k) */ hsize_t chunk_dims[RANK] = {S_DIM1/2, S_DIM2/2}; /* Dimension sizes for chunks */ - int s_buf[S_DIM1][S_DIM2]; /* Temporary buffer */ + int **s_buf = NULL; /* Temporary buffer */ - for(i = n = 0; i < S_DIM1; i++) { - for (j = 0; j < S_DIM2; j++) { - s_buf[i][j] = n++; - } - } + /* Create and fill array */ + H5TEST_ALLOCATE_2D_ARRAY(s_buf, int, S_DIM1, S_DIM2); + if (NULL == s_buf) + goto error; + H5TEST_FILL_2D_ARRAY(s_buf, int, S_DIM1, S_DIM2); /* Create dataspaces */ if((s_sid = H5Screate_simple(RANK, s_dims, NULL)) < 0) - goto out; + goto error; /* Create contiguous datasets */ if((contig_dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; if(H5Pset_layout(contig_dcpl, H5D_CONTIGUOUS) < 0) - goto out; - if(make_dset(loc_id, CONTIG_S, s_sid, contig_dcpl, s_buf) < 0) - goto out; + goto error; + if(make_dset(loc_id, CONTIG_S, s_sid, contig_dcpl, s_buf[0]) < 0) + goto error; /* Create chunked datasets */ if((chunked_dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; if(H5Pset_chunk(chunked_dcpl, RANK, chunk_dims) < 0) - goto out; - if(make_dset(loc_id, CHUNKED_S_FIX, s_sid, chunked_dcpl, s_buf) < 0) - goto out; + goto error; + if(make_dset(loc_id, CHUNKED_S_FIX, s_sid, chunked_dcpl, s_buf[0]) < 0) + goto error; + + HDfree(s_buf); ret_value = 0; -out: +error: H5E_BEGIN_TRY { H5Pclose(contig_dcpl); H5Pclose(chunked_dcpl); @@ -3335,6 +3360,8 @@ out: } H5E_END_TRY; + HDfree(s_buf); + return(ret_value); } /* make_layout2() */ @@ -3372,27 +3399,20 @@ int make_layout3(hid_t loc_id) hsize_t chunk_dims1[RANK]={DIM1_L3*2,5}; hsize_t chunk_dims2[RANK]={SDIM1_L3 + 2, SDIM2_L3/2}; hsize_t chunk_dims3[RANK]={SDIM1_L3 - 2, SDIM2_L3/2}; - int buf1[DIM1_L3][DIM2_L3]; - int buf2[SDIM1_L3][SDIM2_L3]; - int i, j, n; + int **buf1 = NULL; + int **buf2 = NULL; - /* init buf1 */ - for (i=n=0; i<DIM1_L3; i++) - { - for (j=0; j<DIM2_L3; j++) - { - buf1[i][j]=n++; - } - } + /* Create and fill arrays */ + H5TEST_ALLOCATE_2D_ARRAY(buf1, int, DIM1_L3, DIM2_L3); + if (NULL == buf1) + goto error; + H5TEST_FILL_2D_ARRAY(buf1, int, DIM1_L3, DIM2_L3); + + H5TEST_ALLOCATE_2D_ARRAY(buf2, int, SDIM1_L3, SDIM2_L3); + if (NULL == buf2) + goto error; + H5TEST_FILL_2D_ARRAY(buf2, int, SDIM1_L3, SDIM2_L3); - /* init buf2 */ - for (i=n=0; i<SDIM1_L3; i++) - { - for (j=0; j<SDIM2_L3; j++) - { - buf2[i][j]=n++; - } - } /*------------------------------------------------------------------------- * make chunked dataset with @@ -3403,19 +3423,15 @@ int make_layout3(hid_t loc_id) */ /* create a space */ if((sid1 = H5Screate_simple(RANK, dims1, maxdims)) < 0) - return -1; + goto error; /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl1 = H5Pcreate(H5P_DATASET_CREATE)) < 0) - { - goto out; - } + goto error; if(H5Pset_chunk(dcpl1, RANK, chunk_dims1) < 0) - goto out; - if (make_dset(loc_id,"chunk_unlimit1",sid1,dcpl1,buf1) < 0) - { - goto out; - } + goto error; + if (make_dset(loc_id, "chunk_unlimit1", sid1, dcpl1, buf1[0]) < 0) + goto error; /*------------------------------------------------------------------------- * make chunked dataset with @@ -3427,16 +3443,16 @@ int make_layout3(hid_t loc_id) /* create a space */ if((sid2 = H5Screate_simple(RANK, dims2, maxdims)) < 0) - return -1; + goto error; /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl2 = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; if(H5Pset_chunk(dcpl2, RANK, chunk_dims2) < 0) - goto out; + goto error; - if (make_dset(loc_id,"chunk_unlimit2",sid2,dcpl2,buf2) < 0) - goto out; + if (make_dset(loc_id, "chunk_unlimit2", sid2, dcpl2, buf2[0]) < 0) + goto error; /*------------------------------------------------------------------------- * make chunked dataset with @@ -3447,32 +3463,35 @@ int make_layout3(hid_t loc_id) */ /* create a dataset creation property list; the same DCPL is used for all dsets */ if ((dcpl3 = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto out; + goto error; if(H5Pset_chunk(dcpl3, RANK, chunk_dims3) < 0) - goto out; + goto error; - if (make_dset(loc_id,"chunk_unlimit3",sid2,dcpl3,buf2) < 0) - goto out; + if (make_dset(loc_id, "chunk_unlimit3", sid2, dcpl3, buf2[0]) < 0) + goto error; /*------------------------------------------------------------------------- * close space and dcpl *------------------------------------------------------------------------- */ if(H5Sclose(sid1) < 0) - goto out; + goto error; if(H5Sclose(sid2) < 0) - goto out; + goto error; if(H5Pclose(dcpl1) < 0) - goto out; + goto error; if(H5Pclose(dcpl2) < 0) - goto out; + goto error; if(H5Pclose(dcpl3) < 0) - goto out; + goto error; + + HDfree(buf1); + HDfree(buf2); return 0; -out: +error: H5E_BEGIN_TRY { H5Sclose(sid1); @@ -3481,6 +3500,10 @@ out: H5Pclose(dcpl2); H5Pclose(dcpl3); } H5E_END_TRY; + + HDfree(buf1); + HDfree(buf2); + return -1; } |