summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-10-25 16:42:00 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-10-25 16:42:00 (GMT)
commit5e2f37f579d4280727a052294dc17e92d070e5c0 (patch)
tree108be405f1d8ca188622dd7f2e155780c6ded518
parentf2205620fe5e868becb8cc8a94a0f5a399ff4f14 (diff)
downloadhdf5-5e2f37f579d4280727a052294dc17e92d070e5c0.zip
hdf5-5e2f37f579d4280727a052294dc17e92d070e5c0.tar.gz
hdf5-5e2f37f579d4280727a052294dc17e92d070e5c0.tar.bz2
[svn-r7735] Purpose:
Bug fix Description: Single hyperslab selections (which were set with only one call to H5Sselect_hyperslab) that had dimensions that could be "flattened" but were interspersed with dimensions that could not be flattened were not correctly handled, causing core dumps. Solution: Re-work "flattening" code to handle this case properly. Platforms tested: FreeBSD 4.9 (sleipnir) h5committest
-rw-r--r--release_docs/RELEASE.txt4
-rw-r--r--src/H5Shyper.c74
-rw-r--r--test/tselect.c145
3 files changed, 191 insertions, 32 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index e78b377..e108856 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -60,6 +60,10 @@ Bug Fixes since HDF5-1.6.1 release
Library
-------
+ - Single hyperslab selections (which were set with only one call to
+ H5Sselect_hyperslab) that had dimensions that could be "flattened"
+ but were interspersed with dimensions that could not be flattened
+ were not correctly handled, causing core dumps. QAK - 2003/10/25
- Avoid metadata cache from preempting current dataset object header
when looking up information about the named datatype that the
dataset uses. QAK - 2003/10/20
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index f3640ac..d8c1500 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -162,7 +162,7 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, size_t elmt_size)
/* Initialize the information needed for regular hyperslab I/O */
const hsize_t *mem_size; /* Temporary pointer to dataspace extent's dimension sizes */
hsize_t acc; /* Accumulator for "flattened" dimension's sizes */
- unsigned cont_dim; /* Maximum contiguous dimension */
+ unsigned cont_dim=0; /* # of contiguous dimensions */
/* Set the temporary pointer to the dataspace extent's dimension sizes */
mem_size=space->extent.u.simple.size;
@@ -174,69 +174,83 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, size_t elmt_size)
* extent in that dimension and all dimensions up to that dimension.
*/
- /* Initialize the number of contiguous dimensions to be the same as the dataspace's rank */
- cont_dim=rank;
-
/* Don't flatten adjacent elements into contiguous block if the
* element size is 0. This is for the H5S_select_shape_same() code.
*/
if(elmt_size>0) {
- /* Check for a "contiguous" block */
+ /* Check for any "contiguous" blocks that can be flattened */
for(u=rank-1; u>0; u--) {
if(tdiminfo[u].count==1 && tdiminfo[u].block==mem_size[u])
- cont_dim=u;
- else
- break;
+ cont_dim++;
} /* end for */
} /* end if */
/* Check if the regular selection can be "flattened" */
- if(cont_dim<rank) {
+ if(cont_dim>0) {
+ unsigned last_dim_flattened=1; /* Flag to indicate that the last dimension was flattened */
+ unsigned flat_rank=rank-cont_dim; /* Number of dimensions after flattening */
+ unsigned curr_dim; /* Current dimension */
+
/* Set the iterator's rank to the contiguous dimensions */
- iter->u.hyp.iter_rank=cont_dim;
+ iter->u.hyp.iter_rank=flat_rank;
/* Allocate the position & initialize to initial location */
- iter->u.hyp.off = H5FL_ARR_MALLOC(hsize_t,cont_dim);
+ iter->u.hyp.off = H5FL_ARR_MALLOC(hsize_t,flat_rank);
assert(iter->u.hyp.off);
- iter->u.hyp.diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,cont_dim);
+ iter->u.hyp.diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,flat_rank);
assert(iter->u.hyp.diminfo);
- iter->u.hyp.size = H5FL_ARR_MALLOC(hsize_t,cont_dim);
+ iter->u.hyp.size = H5FL_ARR_MALLOC(hsize_t,flat_rank);
assert(iter->u.hyp.size);
- iter->u.hyp.sel_off = H5FL_ARR_MALLOC(hssize_t,cont_dim);
+ iter->u.hyp.sel_off = H5FL_ARR_MALLOC(hssize_t,flat_rank);
assert(iter->u.hyp.sel_off);
/* "Flatten" dataspace extent and selection information */
+ curr_dim=flat_rank-1;
for(i=rank-1, acc=1; i>=0; i--) {
if(tdiminfo[i].block==mem_size[i] && i>0) {
+ /* "Flatten" this dimension */
assert(tdiminfo[i].start==0);
acc *= mem_size[i];
+
+ /* Indicate that the dimension was flattened */
+ last_dim_flattened=1;
} /* end if */
else {
- if((unsigned)i==(cont_dim-1)) {
- iter->u.hyp.diminfo[i].start = tdiminfo[i].start*acc;
+ if(last_dim_flattened) {
+ /* First dimension after flattened dimensions */
+ iter->u.hyp.diminfo[curr_dim].start = tdiminfo[i].start*acc;
/* Special case for single block regular selections */
- if(tdiminfo[i].count==1)
- iter->u.hyp.diminfo[i].stride = 1;
+ if(tdiminfo[curr_dim].count==1)
+ iter->u.hyp.diminfo[curr_dim].stride = 1;
else
- iter->u.hyp.diminfo[i].stride = tdiminfo[i].stride*acc;
- iter->u.hyp.diminfo[i].count = tdiminfo[i].count;
- iter->u.hyp.diminfo[i].block = tdiminfo[i].block*acc;
- iter->u.hyp.size[i] = mem_size[i]*acc;
- iter->u.hyp.sel_off[i] = space->select.offset[i]*acc;
+ iter->u.hyp.diminfo[curr_dim].stride = tdiminfo[i].stride*acc;
+ iter->u.hyp.diminfo[curr_dim].count = tdiminfo[i].count;
+ iter->u.hyp.diminfo[curr_dim].block = tdiminfo[i].block*acc;
+ iter->u.hyp.size[curr_dim] = mem_size[i]*acc;
+ iter->u.hyp.sel_off[curr_dim] = space->select.offset[i]*acc;
+
+ /* Reset the "last dim flattened" flag to avoid flattened any further dimensions */
+ last_dim_flattened=0;
+
+ /* Reset the "accumulator" for possible further dimension flattening */
+ acc=1;
} /* end if */
else {
- iter->u.hyp.diminfo[i].start = tdiminfo[i].start;
- iter->u.hyp.diminfo[i].stride = tdiminfo[i].stride;
- iter->u.hyp.diminfo[i].count = tdiminfo[i].count;
- iter->u.hyp.diminfo[i].block = tdiminfo[i].block;
- iter->u.hyp.size[i] = mem_size[i];
- iter->u.hyp.sel_off[i] = space->select.offset[i];
+ iter->u.hyp.diminfo[curr_dim].start = tdiminfo[i].start;
+ iter->u.hyp.diminfo[curr_dim].stride = tdiminfo[i].stride;
+ iter->u.hyp.diminfo[curr_dim].count = tdiminfo[i].count;
+ iter->u.hyp.diminfo[curr_dim].block = tdiminfo[i].block;
+ iter->u.hyp.size[curr_dim] = mem_size[i];
+ iter->u.hyp.sel_off[curr_dim] = space->select.offset[i];
} /* end else */
+
+ /* Decrement "current" flattened dimension */
+ curr_dim--;
} /* end if */
} /* end for */
/* Initialize "flattened" iterator offset to initial location and dataspace extent and selection information to correct values */
- for(u=0; u<cont_dim; u++)
+ for(u=0; u<flat_rank; u++)
iter->u.hyp.off[u]=iter->u.hyp.diminfo[u].start;
} /* end if */
else {
diff --git a/test/tselect.c b/test/tselect.c
index 10265ad..db98f94 100644
--- a/test/tselect.c
+++ b/test/tselect.c
@@ -1325,13 +1325,13 @@ test_select_hyper_contig2(hid_t dset_type, hid_t xfer_plist)
sid2 = H5Screate_simple(SPACE8_RANK, dims2, NULL);
CHECK(sid2, FAIL, "H5Screate_simple");
- /* Select 6x5 count with a stride of 2x6 & 2x6 block hyperslab for disk dataset */
+ /* Select contiguous hyperslab in memory */
start[0]=0; start[1]=0; start[2]=0; start[3]=0;
count[0]=2; count[1]=SPACE8_DIM3; count[2]=SPACE8_DIM2; count[3]=SPACE8_DIM1;
ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,NULL,count,NULL);
CHECK(ret, FAIL, "H5Sselect_hyperslab");
- /* Select 3x15 count with a stride of 4x2 & 4x2 block hyperslab for memory dataset */
+ /* Select contiguous hyperslab in memory */
start[0]=0; start[1]=0; start[2]=0; start[3]=0;
count[0]=2; count[1]=SPACE8_DIM3; count[2]=SPACE8_DIM2; count[3]=SPACE8_DIM1;
ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,NULL,count,NULL);
@@ -1375,6 +1375,143 @@ test_select_hyper_contig2(hid_t dset_type, hid_t xfer_plist)
/****************************************************************
**
+** test_select_hyper_contig3(): Test H5S (dataspace) selection code.
+** Tests contiguous hyperslabs of various sizes and dimensionalities.
+** This test uses a hyperslab that is contiguous in the lowest dimension,
+** not contiguous in a dimension, then has a selection across the entire next
+** dimension (which should be "flattened" out also).
+**
+****************************************************************/
+static void
+test_select_hyper_contig3(hid_t dset_type, hid_t xfer_plist)
+{
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1,sid2; /* Dataspace ID */
+ hsize_t dims2[] = {SPACE8_DIM4, SPACE8_DIM3, SPACE8_DIM2, SPACE8_DIM1};
+ hssize_t start[SPACE8_RANK]; /* Starting location of hyperslab */
+ hsize_t count[SPACE8_RANK]; /* Element count of hyperslab */
+ uint16_t *wbuf, /* Buffer to write to disk */
+ *rbuf, /* Buffer read from disk */
+ *tbuf, *tbuf2; /* Temporary buffer pointers */
+ int i,j,k,l; /* Counters */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Yet More Contiguous Hyperslabs Functionality\n"));
+
+ /* Allocate write & read buffers */
+ wbuf=malloc(sizeof(uint16_t)*SPACE8_DIM1*SPACE8_DIM2*SPACE8_DIM3*SPACE8_DIM4);
+ rbuf=calloc(sizeof(uint16_t),SPACE8_DIM1*SPACE8_DIM2*SPACE8_DIM3*SPACE8_DIM4);
+
+ /* Initialize write buffer */
+ for(i=0, tbuf=wbuf; i<SPACE8_DIM4; i++)
+ for(j=0; j<SPACE8_DIM3; j++)
+ for(k=0; k<SPACE8_DIM2; k++)
+ for(l=0; l<SPACE8_DIM1; l++)
+ *tbuf++=(uint16_t)((k*SPACE8_DIM2)+l);
+
+ /* Create file */
+ fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid1, FAIL, "H5Fcreate");
+
+ /* Create dataspace for dataset */
+ sid1 = H5Screate_simple(SPACE8_RANK, dims2, NULL);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ /* Create dataspace for writing buffer */
+ sid2 = H5Screate_simple(SPACE8_RANK, dims2, NULL);
+ CHECK(sid2, FAIL, "H5Screate_simple");
+
+ /* Select semi-contiguous hyperslab for disk dataset */
+ start[0]=0; start[1]=0; start[2]=SPACE8_DIM2/2; start[3]=0;
+ count[0]=2; count[1]=SPACE8_DIM3; count[2]=SPACE8_DIM2/2; count[3]=SPACE8_DIM1;
+ ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,NULL,count,NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Select semi-contiguous hyperslab in memory */
+ start[0]=0; start[1]=0; start[2]=SPACE8_DIM2/2; start[3]=0;
+ count[0]=2; count[1]=SPACE8_DIM3; count[2]=SPACE8_DIM2/2; count[3]=SPACE8_DIM1;
+ ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,NULL,count,NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Create a dataset */
+ dataset=H5Dcreate(fid1,"Dataset1",dset_type,sid1,H5P_DEFAULT);
+
+ /* Write selection to disk */
+ ret=H5Dwrite(dataset,H5T_NATIVE_USHORT,sid2,sid1,xfer_plist,wbuf);
+ CHECK(ret, FAIL, "H5Dwrite");
+
+ /* Close memory dataspace */
+ ret = H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Create dataspace for reading buffer */
+ sid2 = H5Screate_simple(SPACE8_RANK, dims2, NULL);
+ CHECK(sid2, FAIL, "H5Screate_simple");
+
+ /* Select semi-contiguous hyperslab in memory */
+ start[0]=0; start[1]=0; start[2]=SPACE8_DIM2/2; start[3]=0;
+ count[0]=2; count[1]=SPACE8_DIM3; count[2]=SPACE8_DIM2/2; count[3]=SPACE8_DIM1;
+ ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,NULL,count,NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Select semi-contiguous hyperslab in memory */
+ start[0]=0; start[1]=0; start[2]=SPACE8_DIM2/2; start[3]=0;
+ count[0]=2; count[1]=SPACE8_DIM3; count[2]=SPACE8_DIM2/2; count[3]=SPACE8_DIM1;
+ ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,NULL,count,NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Read selection from disk */
+ ret=H5Dread(dataset,H5T_NATIVE_USHORT,sid2,sid1,xfer_plist,rbuf);
+ CHECK(ret, FAIL, "H5Dread");
+
+ /* Compare data read with data written out */
+ for(i=0, tbuf=wbuf,tbuf2=rbuf; i<SPACE8_DIM4; i++)
+ for(j=0; j<SPACE8_DIM3; j++)
+ for(k=0; k<SPACE8_DIM2; k++)
+ for(l=0; l<SPACE8_DIM1; l++,tbuf++,tbuf2++)
+ if( (i>=start[0] && i<(int)(start[0]+count[0])) &&
+ (j>=start[1] && j<(int)(start[1]+count[1])) &&
+ (k>=start[2] && k<(int)(start[2]+count[2])) &&
+ (l>=start[3] && l<(int)(start[3]+count[3])) ) {
+ if(*tbuf!=*tbuf2) {
+ num_errs++;
+ printf("Error: hyperslab values don't match!\n");
+ printf("Line: %d, i=%d, j=%d, k=%d, l=%d, *tbuf=%u,*tbuf2=%u\n",__LINE__,i,j,k,l,(unsigned)*tbuf,(unsigned)*tbuf2);
+ } /* end if */
+ } /* end if */
+ else {
+ if(*tbuf2!=0) {
+ num_errs++;
+ printf("Error: invalid data in read buffer!\n");
+ printf("Line: %d, i=%d, j=%d, k=%d, l=%d, *tbuf=%u,*tbuf2=%u\n",__LINE__,i,j,k,l,(unsigned)*tbuf,(unsigned)*tbuf2);
+ } /* end if */
+ } /* end else */
+
+ /* Close memory dataspace */
+ ret = H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close disk dataspace */
+ ret = H5Sclose(sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close Dataset */
+ ret = H5Dclose(dataset);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* Close file */
+ ret = H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ /* Free memory buffers */
+ free(wbuf);
+ free(rbuf);
+} /* test_select_hyper_contig3() */
+
+/****************************************************************
+**
** test_select_hyper_copy(): Test H5S (dataspace) selection code.
** Tests copying hyperslab selections
**
@@ -6466,6 +6603,10 @@ test_select(void)
test_select_hyper_contig2(H5T_STD_U16LE,plist_id); /* Test more contiguous hyperslab selection cases */
test_select_hyper_contig2(H5T_STD_U16BE,H5P_DEFAULT); /* Test more contiguous hyperslab selection cases */
test_select_hyper_contig2(H5T_STD_U16BE,plist_id); /* Test more contiguous hyperslab selection cases */
+ test_select_hyper_contig3(H5T_STD_U16LE,H5P_DEFAULT); /* Test yet more contiguous hyperslab selection cases */
+ test_select_hyper_contig3(H5T_STD_U16LE,plist_id); /* Test yet more contiguous hyperslab selection cases */
+ test_select_hyper_contig3(H5T_STD_U16BE,H5P_DEFAULT); /* Test yet more contiguous hyperslab selection cases */
+ test_select_hyper_contig3(H5T_STD_U16BE,plist_id); /* Test yet more contiguous hyperslab selection cases */
test_select_hyper_copy(); /* Test hyperslab selection copying code */
test_select_point_copy(); /* Test point selection copying code */
test_select_hyper_offset(); /* Test selection offset code with hyperslabs */