summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-06-08 03:07:44 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-06-08 03:07:44 (GMT)
commitf7649ec8b6febf3a3d521f91ceb9a815fbafff07 (patch)
tree2637e96999508209c84ab8b2060188cc214107e4 /src
parent2c939d20e6dd1e575075b5f6f1fb017567e97d65 (diff)
downloadhdf5-f7649ec8b6febf3a3d521f91ceb9a815fbafff07.zip
hdf5-f7649ec8b6febf3a3d521f91ceb9a815fbafff07.tar.gz
hdf5-f7649ec8b6febf3a3d521f91ceb9a815fbafff07.tar.bz2
[svn-r13843] Description:
Fix compact dataset storage to initialize VL datatype fill values correctly. Also, fix bug in global heap code when the fix action on a global heap is to delete an object in a heap with no free space. Tested on: Mac OS X/32 10.4.9 (amazon) (Will be testing on FreeBSD/32 6.2 (duty))
Diffstat (limited to 'src')
-rw-r--r--src/H5D.c31
-rw-r--r--src/H5Dcompact.c134
-rw-r--r--src/H5Dio.c7
-rw-r--r--src/H5Dpkg.h1
-rw-r--r--src/H5HG.c38
5 files changed, 165 insertions, 46 deletions
diff --git a/src/H5D.c b/src/H5D.c
index 5daec07..c9043ad 100644
--- a/src/H5D.c
+++ b/src/H5D.c
@@ -3162,37 +3162,22 @@ H5D_init_storage(H5D_t *dset, hbool_t full_overwrite, hid_t dxpl_id)
FUNC_ENTER_NOAPI_NOINIT(H5D_init_storage)
- assert(dset);
+ HDassert(dset);
switch (dset->shared->layout.type) {
case H5D_COMPACT:
/* If we will be immediately overwriting the values, don't bother to clear them */
- if(!full_overwrite) {
- /* If the fill value is defined, initialize the data buffer with it */
- if(dset->shared->fill.buf) {
- hssize_t snpoints; /* Number of points in space (for error checking) */
- size_t npoints; /* Number of points in space */
-
- /* Get the number of elements in the dataset's dataspace */
- snpoints = H5S_GET_EXTENT_NPOINTS(dset->shared->space);
- assert(snpoints>=0);
- H5_ASSIGN_OVERFLOW(npoints,snpoints,hssize_t,size_t);
-
- /* Initialize the cached data buffer with the fill value */
- H5V_array_fill(dset->shared->layout.u.compact.buf, dset->shared->fill.buf, dset->shared->fill.size, npoints);
- } /* end if */
- else /* If the fill value is default, zero set data buf. */
- HDmemset(dset->shared->layout.u.compact.buf, 0, dset->shared->layout.u.compact.size);
- } /* end if */
+ if(!full_overwrite)
+ if(H5D_compact_fill(dset, dxpl_id) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize compact dataset storage")
break;
case H5D_CONTIGUOUS:
/* Don't write default fill values to external files */
/* If we will be immediately overwriting the values, don't bother to clear them */
- if((dset->shared->efl.nused==0 || dset->shared->fill.buf) && !full_overwrite) {
- if (H5D_contig_fill(dset, dxpl_id)<0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to allocate all chunks of dataset")
- } /* end if */
+ if((dset->shared->efl.nused == 0 || dset->shared->fill.buf) && !full_overwrite)
+ if(H5D_contig_fill(dset, dxpl_id) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize contiguous dataset storage")
break;
case H5D_CHUNKED:
@@ -3200,7 +3185,7 @@ H5D_init_storage(H5D_t *dset, hbool_t full_overwrite, hid_t dxpl_id)
* Allocate file space
* for all chunks now and initialize each chunk with the fill value.
*/
- if (H5D_istore_allocate(dset, dxpl_id, full_overwrite)<0)
+ if(H5D_istore_allocate(dset, dxpl_id, full_overwrite) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to allocate all chunks of dataset")
break;
diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c
index 38f7cac..562bfb2 100644
--- a/src/H5Dcompact.c
+++ b/src/H5Dcompact.c
@@ -29,9 +29,143 @@
#include "H5Fprivate.h" /* Files */
#include "H5FDprivate.h" /* File drivers */
#include "H5FLprivate.h" /* Free Lists */
+#include "H5Iprivate.h" /* IDs */
#include "H5Oprivate.h" /* Object headers */
#include "H5Vprivate.h" /* Vector and array functions */
+/* Declare a free list to manage blocks of type conversion data */
+H5FL_BLK_EXTERN(type_conv);
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5D_compact_fill
+ *
+ * Purpose: Write fill values to a compactly stored dataset.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * May 6, 2007
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5D_compact_fill(H5D_t *dset, hid_t dxpl_id)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5D_compact_fill, FAIL)
+
+ /* Check args */
+ HDassert(TRUE == H5P_isa_class(dxpl_id, H5P_DATASET_XFER));
+ HDassert(dset && H5D_COMPACT == dset->shared->layout.type);
+ HDassert(dset->shared->layout.u.compact.buf);
+ HDassert(dset->shared->type);
+ HDassert(dset->shared->space);
+
+ /* If the fill value is defined, initialize the data buffer with it */
+ if(dset->shared->fill.buf) {
+ hssize_t snpoints; /* Number of points in space (for error checking) */
+ size_t npoints; /* Number of points in space */
+
+ /* Get the number of elements in the dataset's dataspace */
+ snpoints = H5S_GET_EXTENT_NPOINTS(dset->shared->space);
+ HDassert(snpoints >= 0);
+ H5_ASSIGN_OVERFLOW(npoints, snpoints, hssize_t, size_t);
+
+ /* If necessary, convert fill value datatypes (which copies VL components, etc.) */
+ if(H5T_detect_class(dset->shared->type, H5T_VLEN) > 0) {
+ H5T_path_t *tpath; /* Datatype conversion path */
+ uint8_t *bkg_buf = NULL; /* Background conversion buffer */
+ H5T_t *mem_type; /* Pointer to memory datatype */
+ size_t mem_type_size, file_type_size; /* Size of datatype in memory and on disk */
+ hid_t mem_tid; /* Memory version of disk datatype */
+
+ /* Create temporary datatype for conversion operation */
+ if(NULL == (mem_type = H5T_copy(dset->shared->type, H5T_COPY_REOPEN)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy file datatype")
+ if((mem_tid = H5I_register(H5I_DATATYPE, mem_type)) < 0) {
+ H5T_close(mem_type);
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register memory datatype")
+ } /* end if */
+
+ /* Retrieve sizes of memory & file datatypes */
+ mem_type_size = H5T_get_size(mem_type);
+ HDassert(mem_type_size > 0);
+ file_type_size = H5T_get_size(dset->shared->type);
+ HDassert(file_type_size == dset->shared->fill.size);
+
+ /* Get the datatype conversion path for this operation */
+ if(NULL == (tpath = H5T_path_find(dset->shared->type, mem_type, NULL, NULL, dxpl_id))) {
+ H5I_dec_ref(mem_tid);
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert between src and dst datatypes")
+ } /* end if */
+
+ /* Allocate a background buffer, if necessary */
+ if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (npoints * MAX(mem_type_size, file_type_size))))) {
+ H5I_dec_ref(mem_tid);
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ } /* end if */
+
+ /* Make a copy of the (disk-based) fill value into the compact buffer */
+ HDmemcpy(dset->shared->layout.u.compact.buf, dset->shared->fill.buf, file_type_size);
+
+ /* Type convert the compact dataset buffer, to copy any VL components */
+ if(H5T_convert(tpath, dset->shared->type_id, mem_tid, (size_t)1, (size_t)0, (size_t)0, dset->shared->layout.u.compact.buf, bkg_buf, dxpl_id) < 0) {
+ if(bkg_buf)
+ H5FL_BLK_FREE(type_conv, bkg_buf);
+ H5I_dec_ref(mem_tid);
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed")
+ } /* end if */
+
+ /* Replicate the fill value into the cached buffer */
+ H5V_array_fill(dset->shared->layout.u.compact.buf, dset->shared->layout.u.compact.buf, mem_type_size, npoints);
+
+ /* Get the inverse datatype conversion path for this operation */
+ if(NULL == (tpath = H5T_path_find(mem_type, dset->shared->type, NULL, NULL, dxpl_id))) {
+ if(bkg_buf)
+ H5FL_BLK_FREE(type_conv, bkg_buf);
+ H5I_dec_ref(mem_tid);
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert between src and dst datatypes")
+ } /* end if */
+
+ /* Allocate or reset the background buffer, if necessary */
+ if(H5T_path_bkg(tpath)) {
+ if(bkg_buf)
+ HDmemset(bkg_buf, 0, MAX(mem_type_size, file_type_size));
+ else {
+ if(NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (npoints * MAX(mem_type_size, file_type_size))))) {
+ H5I_dec_ref(mem_tid);
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ } /* end if */
+ } /* end else */
+ } /* end if */
+
+ /* Type convert the compact dataset buffer, to copy any VL components */
+ if(H5T_convert(tpath, mem_tid, dset->shared->type_id, npoints, (size_t)0, (size_t)0, dset->shared->layout.u.compact.buf, bkg_buf, dxpl_id) < 0) {
+ if(bkg_buf)
+ H5FL_BLK_FREE(type_conv, bkg_buf);
+ H5I_dec_ref(mem_tid);
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed")
+ } /* end if */
+
+ /* Release resources used */
+ if(bkg_buf)
+ H5FL_BLK_FREE(type_conv, bkg_buf);
+ H5I_dec_ref(mem_tid);
+ } /* end if */
+ else
+ /* Replicate the fill value into the cached buffer */
+ H5V_array_fill(dset->shared->layout.u.compact.buf, dset->shared->fill.buf, dset->shared->fill.size, npoints);
+
+ } /* end if */
+ else /* If the fill value is default, zero set data buf. */
+ HDmemset(dset->shared->layout.u.compact.buf, 0, dset->shared->layout.u.compact.size);
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5D_compact_fill() */
+
/*-------------------------------------------------------------------------
* Function: H5D_compact_readvv
diff --git a/src/H5Dio.c b/src/H5Dio.c
index fb21ef7..1c06dd3 100644
--- a/src/H5Dio.c
+++ b/src/H5Dio.c
@@ -310,9 +310,10 @@ H5D_fill(const void *fill, const H5T_t *fill_type, void *buf, const H5T_t *buf_t
/* Convert disk buffer into memory buffer */
if(!H5T_path_noop(tpath)) {
/* Allocate a background buffer */
- if(NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (size_t)nelmts * buf_size)))
+ if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (size_t)nelmts * buf_size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ /* Perform datatype conversion */
if(H5T_convert(tpath, src_id, dst_id, (size_t)nelmts, (size_t)0, (size_t)0, tmp_buf, bkg_buf, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed")
} /* end if */
@@ -325,10 +326,10 @@ H5D_fill(const void *fill, const H5T_t *fill_type, void *buf, const H5T_t *buf_t
if(!H5T_path_noop(tpath)) {
/* If there's no VL type of data, do conversion first then fill the data into
* the memory buffer. */
- if(NULL==(bkg_buf = H5FL_BLK_CALLOC(type_elem,buf_size)))
+ if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_elem, buf_size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- /* Perform data type conversion */
+ /* Perform datatype conversion */
if(H5T_convert(tpath, src_id, dst_id, (size_t)1, (size_t)0, (size_t)0, tconv_buf, bkg_buf, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed")
} /* end if */
diff --git a/src/H5Dpkg.h b/src/H5Dpkg.h
index 85473d0..3559a9e 100644
--- a/src/H5Dpkg.h
+++ b/src/H5Dpkg.h
@@ -235,6 +235,7 @@ H5_DLL ssize_t H5D_contig_writevv(const H5D_io_info_t *io_info,
const void *buf);
/* Functions that operate on compact dataset storage */
+H5_DLL herr_t H5D_compact_fill(H5D_t *dset, hid_t dxpl_id);
H5_DLL ssize_t H5D_compact_readvv(const H5D_io_info_t *io_info,
size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_size_arr[], hsize_t dset_offset_arr[],
size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_size_arr[], hsize_t mem_offset_arr[],
diff --git a/src/H5HG.c b/src/H5HG.c
index 57542c3..0a5ebb7 100644
--- a/src/H5HG.c
+++ b/src/H5HG.c
@@ -449,26 +449,24 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
* necessary to make room. We remove the right-most entry that has less
* free space than this heap.
*/
- if (heap->obj[0].size>0) {
- if (!f->shared->cwfs) {
- f->shared->cwfs = H5MM_malloc (H5HG_NCWFS*sizeof(H5HG_heap_t*));
- if (NULL==f->shared->cwfs)
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- f->shared->ncwfs = 1;
- f->shared->cwfs[0] = heap;
- } else if (H5HG_NCWFS==f->shared->ncwfs) {
- for (i=H5HG_NCWFS-1; i>=0; --i) {
- if (f->shared->cwfs[i]->obj[0].size < heap->obj[0].size) {
- HDmemmove (f->shared->cwfs+1, f->shared->cwfs, i * sizeof(H5HG_heap_t*));
- f->shared->cwfs[0] = heap;
- break;
- }
- }
- } else {
- HDmemmove (f->shared->cwfs+1, f->shared->cwfs, f->shared->ncwfs*sizeof(H5HG_heap_t*));
- f->shared->ncwfs += 1;
- f->shared->cwfs[0] = heap;
- }
+ if (!f->shared->cwfs) {
+ f->shared->cwfs = H5MM_malloc (H5HG_NCWFS*sizeof(H5HG_heap_t*));
+ if (NULL==f->shared->cwfs)
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ f->shared->ncwfs = 1;
+ f->shared->cwfs[0] = heap;
+ } else if (H5HG_NCWFS==f->shared->ncwfs) {
+ for (i=H5HG_NCWFS-1; i>=0; --i) {
+ if (f->shared->cwfs[i]->obj[0].size < heap->obj[0].size) {
+ HDmemmove (f->shared->cwfs+1, f->shared->cwfs, i * sizeof(H5HG_heap_t*));
+ f->shared->cwfs[0] = heap;
+ break;
+ }
+ }
+ } else {
+ HDmemmove (f->shared->cwfs+1, f->shared->cwfs, f->shared->ncwfs*sizeof(H5HG_heap_t*));
+ f->shared->ncwfs += 1;
+ f->shared->cwfs[0] = heap;
}
ret_value = heap;