diff options
Diffstat (limited to 'src/H5Dcompact.c')
-rw-r--r-- | src/H5Dcompact.c | 119 |
1 files changed, 21 insertions, 98 deletions
diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index a9b2007..38e6cad 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -80,6 +80,8 @@ H5FL_BLK_EXTERN(type_conv); herr_t H5D_compact_fill(H5D_t *dset, hid_t dxpl_id) { + H5D_fill_buf_info_t fb_info; /* Dataset's fill buffer info */ + hbool_t fb_info_init = FALSE; /* Whether the fill value buffer has been initialized */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5D_compact_fill, FAIL) @@ -91,106 +93,27 @@ H5D_compact_fill(H5D_t *dset, hid_t dxpl_id) HDassert(dset->shared->type); HDassert(dset->shared->space); - /* If the fill value is defined, initialize the data buffer with it */ - if(dset->shared->dcpl_cache.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((ssize_t)file_type_size == dset->shared->dcpl_cache.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, FALSE))) { - 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->dcpl_cache.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, FALSE))) { - 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->dcpl_cache.fill.buf, (size_t)dset->shared->dcpl_cache.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); + /* Initialize the fill value buffer */ + /* (use the compact dataset storage buffer as the fill value buffer) */ + if(H5D_fill_init(&fb_info, dset->shared->layout.u.compact.buf, FALSE, + NULL, NULL, NULL, NULL, + &dset->shared->dcpl_cache.fill, dset->shared->type, + dset->shared->type_id, (size_t)0, dset->shared->layout.u.compact.size, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize fill buffer info") + fb_info_init = TRUE; + + /* Check for VL datatype & non-default fill value */ + if(fb_info.has_vlen_fill_type) + /* Fill the buffer with VL datatype fill values */ + if(H5D_fill_refill_vl(&fb_info, fb_info.elmts_per_buf, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "can't refill fill value buffer") done: + /* Release the fill buffer info, if it's been initialized */ + if(fb_info_init) + if(H5D_fill_term(&fb_info) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release fill buffer info") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_compact_fill() */ |