diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5D.c | 54 | ||||
-rw-r--r-- | src/H5Dio.c | 22 | ||||
-rw-r--r-- | src/H5Distore.c | 2 | ||||
-rw-r--r-- | src/H5Oattr.c | 2 | ||||
-rw-r--r-- | src/H5Ofill.c | 42 | ||||
-rw-r--r-- | src/H5Pdcpl.c | 30 | ||||
-rw-r--r-- | src/H5S.c | 11 | ||||
-rw-r--r-- | src/H5Sall.c | 28 | ||||
-rw-r--r-- | src/H5Sprivate.h | 3 |
9 files changed, 157 insertions, 37 deletions
@@ -90,6 +90,9 @@ H5D_dxpl_cache_t H5D_def_dxpl_cache; /* Library Private Variables */ /*****************************/ +/* Declare extern the free list to manage blocks of type conversion data */ +H5FL_BLK_EXTERN(type_conv); + /*******************/ /* Local Variables */ @@ -869,11 +872,56 @@ H5Dget_create_plist(hid_t dset_id) if(H5P_get(new_plist, H5D_CRT_FILL_VALUE_NAME, &copied_fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") - /* Copy the dataset type into the fill value message, if there's actually a fill value */ - if(copied_fill.buf != NULL && copied_fill.type == NULL) + /* Check if there is a fill value, but no type yet */ + if(copied_fill.buf != NULL && copied_fill.type == NULL) { + H5T_path_t *tpath; /* Conversion information*/ + + /* Copy the dataset type into the fill value message */ if(NULL == (copied_fill.type = H5T_copy(dset->shared->type, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to copy dataset datatype for fill value") + /* Set up type conversion function */ + if(NULL == (tpath = H5T_path_find(dset->shared->type, copied_fill.type, NULL, NULL, H5AC_ind_dxpl_id, FALSE))) + HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types") + + /* Convert disk form of fill value into memory form */ + if(!H5T_path_noop(tpath)) { + hid_t dst_id, src_id; /* Source & destination datatypes for type conversion */ + uint8_t *bkg_buf = NULL; /* Background conversion buffer */ + size_t bkg_size; /* Size of background buffer */ + + /* Wrap copies of types to convert */ + dst_id = H5I_register(H5I_DATATYPE, H5T_copy(copied_fill.type, H5T_COPY_TRANSIENT)); + if(dst_id < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy/register datatype") + src_id = H5I_register(H5I_DATATYPE, H5T_copy(dset->shared->type, H5T_COPY_ALL)); + if(src_id < 0) { + H5I_dec_ref(dst_id); + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy/register datatype") + } /* end if */ + + /* Allocate a background buffer */ + bkg_size = MAX(H5T_get_size(copied_fill.type), H5T_get_size(dset->shared->type)); + if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, bkg_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + + /* Convert fill value */ + if(H5T_convert(tpath, src_id, dst_id, (size_t)1, (size_t)0, (size_t)0, copied_fill.buf, bkg_buf, H5AC_ind_dxpl_id) < 0) { + H5I_dec_ref(src_id); + H5I_dec_ref(dst_id); + if(bkg_buf) + H5FL_BLK_FREE(type_conv, bkg_buf); + HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "datatype conversion failed") + } /* end if */ + + /* Release local resources */ + H5I_dec_ref(src_id); + H5I_dec_ref(dst_id); + if(bkg_buf) + H5FL_BLK_FREE(type_conv, bkg_buf); + } /* end if */ + } /* end if */ + /* Set back the fill value property to property list */ if(H5P_set(new_plist, H5D_CRT_FILL_VALUE_NAME, &copied_fill) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to set property list fill value") @@ -1384,7 +1432,7 @@ H5D_create(H5F_t *file, hid_t type_id, const H5S_t *space, hid_t dcpl_id, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy dataspace") /* Set the dataset's dataspace to 'all' selection */ - if(H5S_select_all(new_dset->shared->space,1) < 0) + if(H5S_select_all(new_dset->shared->space, TRUE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") /* Make the "set local" filter callbacks for this dataset */ diff --git a/src/H5Dio.c b/src/H5Dio.c index f172c70..9fd24d3 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -269,16 +269,24 @@ H5D_fill(const void *fill, const H5T_t *fill_type, void *buf, const H5T_t *buf_t /* Get the number of elements */ nelmts = H5S_get_simple_extent_npoints(space); - /* Allocate a temporary buffer and background buffer */ - if(NULL == (tmp_buf = H5FL_BLK_MALLOC(type_conv, (size_t)nelmts * buf_size)) || NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (size_t)nelmts * buf_size))) + /* Allocate a temporary buffer */ + if(NULL == (tmp_buf = H5FL_BLK_MALLOC(type_conv, (size_t)nelmts * buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") +/* XXX: Should replicate the fill value into the temp. buffer elements, then + * type convert the temp. buffer, then scatter the temp. buffer elements + * to the user's buffer. - QAK, 2007/05/31 + */ /* Fill the selection in the temporary buffer */ if(H5S_select_fill(tconv_buf, src_type_size, space, tmp_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTENCODE, FAIL, "filling selection failed") /* 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))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + 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, "datatype conversion failed") } /* end if */ @@ -286,13 +294,13 @@ H5D_fill(const void *fill, const H5T_t *fill_type, void *buf, const H5T_t *buf_t /* Copy the final data into the memory buffer */ HDmemcpy(buf, tmp_buf, (size_t)nelmts * dst_type_size); } else { - /* 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))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - /* Convert disk buffer into memory buffer */ 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))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + /* 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, "datatype conversion failed") diff --git a/src/H5Distore.c b/src/H5Distore.c index 702b887..0807a76 100644 --- a/src/H5Distore.c +++ b/src/H5Distore.c @@ -3403,7 +3403,7 @@ H5D_istore_initialize_by_extent(H5D_io_info_t *io_info) if(NULL == (chunk = H5D_istore_lock(io_info, NULL, FALSE, &idx_hint))) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "unable to read raw data chunk") - if(H5S_select_all(space_chunk, 1) < 0) + if(H5S_select_all(space_chunk, TRUE) < 0) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "unable to select space") for(u = 0; u < rank; u++) diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 29c4abd..476721b 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -221,7 +221,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, unsigned UNUSED mesg_flags, H5FL_FREE(H5S_extent_t, extent); /* Default to entire dataspace being selected */ - if(H5S_select_all(attr->ds, 0) < 0) + if(H5S_select_all(attr->ds, FALSE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") if(version < H5O_ATTR_VERSION_2) diff --git a/src/H5Ofill.c b/src/H5Ofill.c index b718002..2135cb7 100644 --- a/src/H5Ofill.c +++ b/src/H5Ofill.c @@ -23,12 +23,14 @@ #define H5O_PACKAGE /*suppress error about including H5Opkg */ #include "H5private.h" /* Generic Functions */ +#include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object headers */ #include "H5Pprivate.h" /* Property lists */ +#include "H5Sprivate.h" /* Dataspaces */ static void *H5O_fill_old_decode(H5F_t *f, hid_t dxpl_id, unsigned mesg_flags, const uint8_t *p); @@ -659,19 +661,53 @@ H5O_fill_old_size(const H5F_t UNUSED *f, const void *_mesg) herr_t H5O_fill_reset_dyn(H5O_fill_t *fill) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_fill_reset_dyn) + hid_t fill_type_id = -1; /* Datatype ID for fill value datatype when reclaiming VL fill values */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_fill_reset_dyn, FAIL) HDassert(fill); - if(fill->buf) + if(fill->buf) { + if(fill->type && H5T_detect_class(fill->type, H5T_VLEN) > 0) { + H5T_t *fill_type; /* Copy of fill value datatype */ + H5S_t *fill_space; /* Scalar dataspace for fill value element */ + + /* Copy the fill value datatype and get an ID for it */ + if(NULL == (fill_type = H5T_copy(fill->type, H5T_COPY_TRANSIENT))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy fill value datatype") + if((fill_type_id = H5I_register(H5I_DATATYPE, fill_type)) < 0) { + H5T_close(fill_type); + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register fill value datatype") + } /* end if */ + + /* Create a scalar dataspace for the fill value element */ + if(NULL == (fill_space = H5S_create(H5S_SCALAR))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create scalar dataspace") + + /* Reclaim any variable length components of the fill value */ + if(H5D_vlen_reclaim(fill_type_id, fill_space, H5P_DATASET_XFER_DEFAULT, fill->buf) < 0) { + H5S_close(fill_space); + HGOTO_ERROR(H5E_DATASET, H5E_BADITER, FAIL, "unable to reclaim variable-length fill value data") + } /* end if */ + + /* Release the scalar fill value dataspace */ + H5S_close(fill_space); + } /* end if */ + + /* Release the fill value buffer now */ fill->buf = H5MM_xfree(fill->buf); + } /* end if */ fill->size = 0; if(fill->type) { H5T_close(fill->type); fill->type = NULL; } /* end if */ - FUNC_LEAVE_NOAPI(SUCCEED) +done: + if(fill_type_id > 0) + H5I_dec_ref(fill_type_id); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_fill_reset_dyn() */ diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index c16a2c5..be1c3e0 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -126,6 +126,9 @@ const H5P_libclass_t H5P_CLS_DCRT[1] = {{ /* Library Private Variables */ /*****************************/ +/* Declare extern the free list to manage blocks of type conversion data */ +H5FL_BLK_EXTERN(type_conv); + /*------------------------------------------------------------------------- @@ -2022,7 +2025,8 @@ H5Pset_fill_value(hid_t plist_id, hid_t type_id, const void *value) H5O_fill_reset_dyn(&fill); if(value) { - H5T_t *type; /* Datatype for fill value */ + H5T_t *type; /* Datatype for fill value */ + H5T_path_t *tpath; /* Conversion information */ /* Retrieve pointer to datatype */ if(NULL == (type = H5I_object_verify(type_id, H5I_DATATYPE))) @@ -2035,6 +2039,30 @@ H5Pset_fill_value(hid_t plist_id, hid_t type_id, const void *value) if(NULL == (fill.buf = H5MM_malloc((size_t)fill.size))) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "memory allocation failed for fill value") HDmemcpy(fill.buf, value, (size_t)fill.size); + + /* Set up type conversion function */ + if(NULL == (tpath = H5T_path_find(type, type, NULL, NULL, H5AC_ind_dxpl_id, FALSE))) + HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types") + + /* If necessary, convert fill value datatypes (which copies VL components, etc.) */ + if(!H5T_path_noop(tpath)) { + uint8_t *bkg_buf = NULL; /* Background conversion buffer */ + + /* Allocate a background buffer */ + if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (size_t)fill.size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + + /* Convert the fill value */ + if(H5T_convert(tpath, type_id, type_id, (size_t)1, (size_t)0, (size_t)0, fill.buf, bkg_buf, H5AC_ind_dxpl_id) < 0) { + if(bkg_buf) + H5FL_BLK_FREE(type_conv, bkg_buf); + HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "datatype conversion failed") + } /* end if */ + + /* Release the background buffer */ + if(bkg_buf) + H5FL_BLK_FREE(type_conv, bkg_buf); + } /* end if */ } /* end if */ else fill.size = (-1); @@ -38,7 +38,6 @@ #define H5S_ENCODE_VERSION 0 /* Local static function prototypes */ -static H5S_t * H5S_create(H5S_class_t type); static herr_t H5S_set_extent_simple (H5S_t *space, unsigned rank, const hsize_t *dims, const hsize_t *max); static htri_t H5S_is_simple(const H5S_t *sdim); @@ -300,13 +299,13 @@ H5S_term_interface(void) EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static H5S_t * +H5S_t * H5S_create(H5S_class_t type) { H5S_t *new_ds = NULL; /* New dataspace created */ H5S_t *ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5S_create) + FUNC_ENTER_NOAPI(H5S_create, NULL) /* Create a new data space */ if(NULL == (new_ds = H5FL_MALLOC(H5S_t))) @@ -333,7 +332,7 @@ H5S_create(H5S_class_t type) } /* end switch */ /* Start with "all" selection */ - if(H5S_select_all(new_ds, 0) < 0) + if(H5S_select_all(new_ds, FALSE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") /* Reset common selection info pointer */ @@ -1159,7 +1158,7 @@ H5S_read(const H5O_loc_t *loc, hid_t dxpl_id) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, NULL, "unable to load dataspace info from dataset header") /* Default to entire dataspace being selected */ - if(H5S_select_all(ds, 0) < 0) + if(H5S_select_all(ds, FALSE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") /* Set the value for successful return */ @@ -1895,7 +1894,7 @@ H5S_decode(const unsigned char *buf) H5FL_FREE(H5S_extent_t, extent); /* Initialize to "all" selection. Deserialization relies on valid existing selection. */ - if(H5S_select_all(ds, 0) < 0) + if(H5S_select_all(ds, FALSE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") /* Decode the select part of dataspace. I believe this part always exists. */ diff --git a/src/H5Sall.c b/src/H5Sall.c index 962a5f4..c216323 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -547,8 +547,8 @@ H5S_all_deserialize (H5S_t *space, const uint8_t UNUSED *buf) assert(space); /* Change to "all" selection */ - if((ret_value=H5S_select_all(space,1))<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection"); + if((ret_value = H5S_select_all(space, TRUE)) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") done: FUNC_LEAVE_NOAPI(ret_value); @@ -702,7 +702,7 @@ H5S_all_is_regular(const H5S_t UNUSED *space) USAGE herr_t H5S_select_all(dsid) hid_t dsid; IN: Dataspace ID of selection to modify - unsigned rel_prev; IN: Flag whether to release previous selection or not + hbool_t rel_prev; IN: Flag whether to release previous selection or not RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -713,28 +713,28 @@ H5S_all_is_regular(const H5S_t UNUSED *space) REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_select_all (H5S_t *space, unsigned rel_prev) +H5S_select_all(H5S_t *space, hbool_t rel_prev) { - herr_t ret_value=SUCCEED; /* return value */ + herr_t ret_value = SUCCEED; /* return value */ - FUNC_ENTER_NOAPI(H5S_select_all, FAIL); + FUNC_ENTER_NOAPI(H5S_select_all, FAIL) /* Check args */ - assert(space); + HDassert(space); /* Remove current selection first */ if(rel_prev) - if(H5S_SELECT_RELEASE(space)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection"); + if(H5S_SELECT_RELEASE(space) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection") /* Set number of elements in selection */ - space->select.num_elem=(hsize_t)H5S_GET_EXTENT_NPOINTS(space); + space->select.num_elem = (hsize_t)H5S_GET_EXTENT_NPOINTS(space); /* Set selection type */ - space->select.type=H5S_sel_all; + space->select.type = H5S_sel_all; done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* H5S_select_all() */ @@ -767,8 +767,8 @@ herr_t H5Sselect_all (hid_t spaceid) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space"); /* Call internal routine to do the work */ - if((ret_value=H5S_select_all(space,1))<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection"); + if((ret_value = H5S_select_all(space, TRUE)) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") done: FUNC_LEAVE_API(ret_value); diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 7b57f06..4a40bee 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -211,6 +211,7 @@ H5_DLL H5S_t *H5S_read(const struct H5O_loc_t *loc, hid_t dxpl_id); H5_DLL int H5S_extend(H5S_t *space, const hsize_t *size); H5_DLL int H5S_set_extent(H5S_t *space, const hsize_t *size); H5_DLL herr_t H5S_set_extent_real(H5S_t *space, const hsize_t *size); +H5_DLL H5S_t *H5S_create(H5S_class_t type); H5_DLL H5S_t *H5S_create_simple(unsigned rank, const hsize_t dims[/*rank*/], const hsize_t maxdims[/*rank*/]); H5_DLL herr_t H5S_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE *stream, @@ -242,7 +243,7 @@ H5_DLL htri_t H5S_select_is_single(const H5S_t *space); H5_DLL htri_t H5S_select_is_regular(const H5S_t *space); /* Operations on all selections */ -H5_DLL herr_t H5S_select_all(H5S_t *space, unsigned rel_prev); +H5_DLL herr_t H5S_select_all(H5S_t *space, hbool_t rel_prev); /* Operations on none selections */ H5_DLL herr_t H5S_select_none(H5S_t *space); |