summaryrefslogtreecommitdiffstats
path: root/src/H5S.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-04-13 16:14:16 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-04-13 16:14:16 (GMT)
commit2815eefb6b0ea608712e0abbc1d3db0910b4cd80 (patch)
tree94051a5190c521b35601a023cec1509867a72742 /src/H5S.c
parent49a607c438d7e0135be61d4cb98d5de013f73fa3 (diff)
downloadhdf5-2815eefb6b0ea608712e0abbc1d3db0910b4cd80.zip
hdf5-2815eefb6b0ea608712e0abbc1d3db0910b4cd80.tar.gz
hdf5-2815eefb6b0ea608712e0abbc1d3db0910b4cd80.tar.bz2
[svn-r20489] Bug 1386 - allow dimension size to be zero even though it isn't unlimited. I brought the changes from the trunk as below:
1. I added test cases for contiguous, compact, and chunked, and external storage datasets, and also attribute. The test includes dataspace selections. 2. I added a test case of extending dataset of zero dimension size and shrinking back to zero dimension size. 3. I updated the Makefile to include the new data file to be cleaned up. 4. The dataspace code has another bug - when the maximal dimension isn't passed in for H5Sset_extent_simple, it is supposed to be same as the dimension. The current library sets NULL to it. I corrected it and added a test case to it. 5. I corrected the tests of Fortran and C++ for the problem in point 3. Tested on jam, heiwa, and amani.
Diffstat (limited to 'src/H5S.c')
-rw-r--r--src/H5S.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/H5S.c b/src/H5S.c
index e7cac9d..f002500 100644
--- a/src/H5S.c
+++ b/src/H5S.c
@@ -1160,14 +1160,22 @@ H5Sis_simple(hid_t space_id)
Christian Chilan 01/17/2007
Verifies that each element of DIMS is not equal to H5S_UNLIMITED.
+ Raymond Lu 03/30/2011
+ We allow 0-dimension for non-unlimited dimension starting from 1.8.7
+ release.
+
+ Raymond Lu 04/11/2011
+ I added a condition check to make sure the new size won't exceed the
+ current maximal size when this function is called to change the
+ dimension size of an existent dataspace.
--------------------------------------------------------------------------*/
herr_t
H5Sset_extent_simple(hid_t space_id, int rank, const hsize_t dims[/*rank*/],
const hsize_t max[/*rank*/])
{
H5S_t *space; /* dataspace to modify */
- int u; /* local counting variable */
- herr_t ret_value=SUCCEED; /* Return value */
+ int u; /* local counting variable */
+ herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(H5Sset_extent_simple, FAIL)
H5TRACE4("e", "iIs*[a1]h*[a1]h", space_id, rank, dims, max);
@@ -1183,8 +1191,6 @@ H5Sset_extent_simple(hid_t space_id, int rank, const hsize_t dims[/*rank*/],
for (u=0; u<rank; u++) {
if (H5S_UNLIMITED==dims[u])
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "current dimension must have a specific size, not H5S_UNLIMITED")
- if (((max!=NULL && max[u]!=H5S_UNLIMITED) || max==NULL) && dims[u]==0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid dimension size")
}
}
if (max!=NULL) {
@@ -1196,6 +1202,14 @@ H5Sset_extent_simple(hid_t space_id, int rank, const hsize_t dims[/*rank*/],
}
}
+ /* Check through all the dimensions to see if the new dimension size exceeds the current
+ * size or if the new maximal size exceeds the current maximal size */
+ for(u = 0; u < space->extent.rank; u++) {
+ if(space->extent.max && H5S_UNLIMITED!=space->extent.max[u] &&
+ (space->extent.max[u]<dims[u] || (max && space->extent.max[u]<max[u])))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "new size exceeds current maximal size")
+ } /* end for */
+
/* Do it */
if (H5S_set_extent_simple(space, (unsigned)rank, dims, max)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to set simple extent")
@@ -1258,13 +1272,15 @@ H5S_set_extent_simple(H5S_t *space, unsigned rank, const hsize_t *dims,
} /* end for */
space->extent.nelem = nelem;
- /* Copy the maximum dimensions if specified */
+ /* Copy the maximum dimensions if specified. Otherwise, the maximal dimensions are the
+ * same as the dimension */
+ space->extent.max = (hsize_t *)H5FL_ARR_MALLOC(hsize_t, (size_t)rank);
if(max != NULL) {
- space->extent.max = (hsize_t *)H5FL_ARR_MALLOC(hsize_t, (size_t)rank);
HDmemcpy(space->extent.max, max, sizeof(hsize_t) * rank);
- } /* end if */
- else
- space->extent.max = NULL;
+ } else {
+ for(u = 0; u < space->extent.rank; u++)
+ space->extent.max[u] = dims[u];
+ }
} /* end else */
/* Selection related cleanup */
@@ -1303,6 +1319,11 @@ done:
* Programmer: Quincey Koziol
* Tuesday, January 27, 1998
*
+ * Modification:
+ * Raymond Lu 03/30/2011
+ * We allow 0-dimension for non-unlimited dimension starting
+ * from 1.8.7 release.
+ *
*-------------------------------------------------------------------------
*/
hid_t
@@ -1332,17 +1353,9 @@ H5Screate_simple(int rank, const hsize_t dims[/*rank*/],
for(i = 0; i < rank; i++) {
if(H5S_UNLIMITED == dims[i])
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "current dimension must have a specific size, not H5S_UNLIMITED")
- if(maxdims) {
- if(H5S_UNLIMITED != maxdims[i] && maxdims[i]<dims[i])
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "maxdims is smaller than dims")
- if(H5S_UNLIMITED != maxdims[i] && dims[i] == 0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "zero sized dimension for non-unlimited dimension")
- } /* end if */
- else {
- if(dims[i] == 0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "zero sized dimension for non-unlimited dimension")
- } /* end else */
- } /* end else */
+ if(maxdims && H5S_UNLIMITED != maxdims[i] && maxdims[i]<dims[i])
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "maxdims is smaller than dims")
+ } /* end for */
/* Create the space and set the extent */
if(NULL == (space = H5S_create_simple((unsigned)rank,dims,maxdims)))
@@ -1906,7 +1919,7 @@ H5S_set_extent_real(H5S_t *space, const hsize_t *size)
/* Change the dataspace size & re-compute the number of elements in the extent */
for(u = 0, nelem = 1; u < space->extent.rank; u++ ) {
space->extent.size[u] = size[u];
- nelem *= space->extent.size[u];
+ nelem *= size[u];
} /* end for */
space->extent.nelem = nelem;