summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-04-07 21:56:38 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-04-07 21:56:38 (GMT)
commit4b7f286a45b24de8cb5d08780df21fc7b79542ed (patch)
tree7d02277da5b03000fcc25ef6b6d4f2356e77e634 /src
parentbaba8a3d59da7ab265900a4e94a7ee47d8856a4e (diff)
downloadhdf5-4b7f286a45b24de8cb5d08780df21fc7b79542ed.zip
hdf5-4b7f286a45b24de8cb5d08780df21fc7b79542ed.tar.gz
hdf5-4b7f286a45b24de8cb5d08780df21fc7b79542ed.tar.bz2
[svn-r20440] Bug 1386 - allow dimension size to be zero even though it isn't unlimited. I added test cases for contiguous, compact, and chunked, and external storage datasets, and also attribute. The test includes dataspace selections. I'll handle the tools in the next step.
Tested on jam, amani, and heiwa.
Diffstat (limited to 'src')
-rw-r--r--src/H5Dchunk.c12
-rw-r--r--src/H5Dint.c27
-rw-r--r--src/H5Pdcpl.c7
-rw-r--r--src/H5S.c30
-rw-r--r--src/H5Spoint.c4
5 files changed, 45 insertions, 35 deletions
diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c
index e7a5bf1..64efc8a 100644
--- a/src/H5Dchunk.c
+++ b/src/H5Dchunk.c
@@ -378,8 +378,9 @@ done:
static herr_t
H5D_chunk_construct(H5F_t UNUSED *f, H5D_t *dset)
{
- const H5T_t *type = dset->shared->type; /* Convenience pointer to dataset's datatype */
- hsize_t max_dim[H5O_LAYOUT_NDIMS]; /* Maximum size of data in elements */
+ const H5T_t *type = dset->shared->type; /* Convenience pointer to dataset's datatype */
+ hsize_t max_dims[H5O_LAYOUT_NDIMS]; /* Maximum size of data in elements */
+ hsize_t dims[H5O_LAYOUT_NDIMS]; /* Dimension size of data in elements */
uint64_t chunk_size; /* Size of chunk in bytes */
int ndims; /* Rank of dataspace */
unsigned u; /* Local index variable */
@@ -413,7 +414,7 @@ H5D_chunk_construct(H5F_t UNUSED *f, H5D_t *dset)
dset->shared->layout.u.chunk.dim[dset->shared->layout.u.chunk.ndims - 1] = (uint32_t)H5T_GET_SIZE(type);
/* Get local copy of dataset dimensions (for sanity checking) */
- if(H5S_get_simple_extent_dims(dset->shared->space, NULL, max_dim) < 0)
+ if(H5S_get_simple_extent_dims(dset->shared->space, dims, max_dims) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to query maximum dimensions")
/* Sanity check dimensions */
@@ -424,9 +425,10 @@ H5D_chunk_construct(H5F_t UNUSED *f, H5D_t *dset)
/*
* The chunk size of a dimension with a fixed size cannot exceed
- * the maximum dimension size
+ * the maximum dimension size. If any dimension size is zero, there
+ * will be no such restriction.
*/
- if(max_dim[u] != H5S_UNLIMITED && max_dim[u] < dset->shared->layout.u.chunk.dim[u])
+ if(dims[u] && max_dims[u] != H5S_UNLIMITED && max_dims[u] < dset->shared->layout.u.chunk.dim[u])
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "chunk size must be <= maximum dimension size for fixed-sized dimensions")
} /* end for */
diff --git a/src/H5Dint.c b/src/H5Dint.c
index 40f262c..8c73888 100644
--- a/src/H5Dint.c
+++ b/src/H5Dint.c
@@ -1628,16 +1628,23 @@ H5D_alloc_storage(H5D_t *dset/*in,out*/, hid_t dxpl_id, H5D_time_alloc_t time_al
case H5D_COMPACT:
/* Check if space is already allocated */
if(NULL == layout->storage.u.compact.buf) {
- /* Reserve space in layout header message for the entire array. */
- HDassert(layout->storage.u.compact.size > 0);
- if(NULL == (layout->storage.u.compact.buf = H5MM_malloc(layout->storage.u.compact.size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for compact dataset")
- if(!full_overwrite)
- HDmemset(layout->storage.u.compact.buf, 0, layout->storage.u.compact.size);
- layout->storage.u.compact.dirty = TRUE;
-
- /* Indicate that we should initialize storage space */
- must_init_space = TRUE;
+ /* Reserve space in layout header message for the entire array.
+ * Starting from the 1.8.7 release, we allow dataspace to have
+ * zero dimension size. So the storage size can be zero.
+ * SLU 2011/4/4 */
+ if(layout->storage.u.compact.size > 0) {
+ if(NULL == (layout->storage.u.compact.buf = H5MM_malloc(layout->storage.u.compact.size)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for compact dataset")
+ if(!full_overwrite)
+ HDmemset(layout->storage.u.compact.buf, 0, layout->storage.u.compact.size);
+ layout->storage.u.compact.dirty = TRUE;
+
+ /* Indicate that we should initialize storage space */
+ must_init_space = TRUE;
+ } else {
+ layout->storage.u.compact.dirty = FALSE;
+ must_init_space = FALSE;
+ }
} /* end if */
break;
diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c
index d2aa8d5..6e20aed 100644
--- a/src/H5Pdcpl.c
+++ b/src/H5Pdcpl.c
@@ -966,6 +966,11 @@ done:
* Changed the way to check parameter and set property for
* generic property list.
*
+ * Raymond Lu
+ * 7 April 2011
+ * Starting from the 1.8.7 release, we allow dataspace to have
+ * zero dimension size. So the external storage size for
+ * dataset can be zero.
*-------------------------------------------------------------------------
*/
herr_t
@@ -985,8 +990,6 @@ H5Pset_external(hid_t plist_id, const char *name, off_t offset, hsize_t size)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no name given")
if (offset<0)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "negative external file offset")
- if (size<=0)
- HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "zero size")
/* Get the plist structure */
if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE)))
diff --git a/src/H5S.c b/src/H5S.c
index e7cac9d..94fd72b 100644
--- a/src/H5S.c
+++ b/src/H5S.c
@@ -1160,14 +1160,17 @@ 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.
--------------------------------------------------------------------------*/
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 +1186,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) {
@@ -1303,6 +1304,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 +1338,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 +1904,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;
diff --git a/src/H5Spoint.c b/src/H5Spoint.c
index cb7e98f..e544371 100644
--- a/src/H5Spoint.c
+++ b/src/H5Spoint.c
@@ -1551,8 +1551,8 @@ herr_t
H5Sselect_elements(hid_t spaceid, H5S_seloper_t op, size_t num_elem,
const hsize_t *coord)
{
- H5S_t *space; /* Dataspace to modify selection of */
- herr_t ret_value; /* Return value */
+ H5S_t *space; /* Dataspace to modify selection of */
+ herr_t ret_value; /* Return value */
FUNC_ENTER_API(H5Sselect_elements, FAIL)
H5TRACE4("e", "iSsz*h", spaceid, op, num_elem, coord);