diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-07-03 20:03:09 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-07-03 20:03:09 (GMT) |
commit | 7cac82cf682a8358582dd6f995a018f7a6d1a477 (patch) | |
tree | 48b12feeeb4ac23037b8cb5d09b99557fc58b067 | |
parent | 153444fed7bd9dfb2b7d90a47c79d11bd1188e96 (diff) | |
download | hdf5-7cac82cf682a8358582dd6f995a018f7a6d1a477.zip hdf5-7cac82cf682a8358582dd6f995a018f7a6d1a477.tar.gz hdf5-7cac82cf682a8358582dd6f995a018f7a6d1a477.tar.bz2 |
[svn-r8801] Purpose:
Code optimization
Description:
Set up datatype ID for dataset's datatype on disk. This allows us to avoid
repeatedly copying the datatype when an ID is needed.
Also, clean up a few warnings in various other places.
Platforms tested:
Solaris 2.7 (arabica)
FreeBSD 4.10 (sleipnir) w/parallel
Too minor to require h5committest
-rw-r--r-- | src/H5AC.c | 4 | ||||
-rw-r--r-- | src/H5D.c | 127 | ||||
-rw-r--r-- | src/H5Dio.c | 84 | ||||
-rw-r--r-- | src/H5Dpkg.h | 1 | ||||
-rw-r--r-- | src/H5F.c | 8 | ||||
-rw-r--r-- | src/H5O.c | 2 | ||||
-rw-r--r-- | src/H5T.c | 53 | ||||
-rw-r--r-- | src/H5Tprivate.h | 5 | ||||
-rw-r--r-- | test/ntypes.c | 25 |
9 files changed, 188 insertions, 121 deletions
@@ -962,7 +962,7 @@ H5AC_protect(H5F_t *f, info_ptr = (H5AC_info_t *)thing; - HDassert(info_ptr->dirty == FALSE); + HDassert(info_ptr->is_dirty == FALSE); info_ptr->addr = addr; info_ptr->type = type; @@ -1136,7 +1136,7 @@ H5AC_unprotect(H5F_t *f, /* Flush a thing to the SAP */ if ( thing ) { - if ( ((H5AC_info_t *)thing)->dirty ) { + if ( ((H5AC_info_t *)thing)->is_dirty ) { if ( type->flush(f, dxpl_id, FALSE, addr, thing) < 0 ) { @@ -47,13 +47,14 @@ static haddr_t H5D_get_offset(const H5D_t *dset); static herr_t H5D_extend(H5D_t *dataset, const hsize_t *size, hid_t dxpl_id); static herr_t H5D_set_extent(H5D_t *dataset, const hsize_t *size, hid_t dxpl_id); static herr_t H5D_close(H5D_t *dataset); +static herr_t H5D_init_type(H5F_t *file, H5D_t *dset, hid_t type_id, const H5T_t *type); static int H5D_crt_fill_value_cmp(const void *value1, const void *value2, size_t size); static int H5D_crt_ext_file_list_cmp(const void *value1, const void *value2, size_t size); static int H5D_crt_data_pipeline_cmp(const void *value1, const void *value2, size_t size); static herr_t H5D_xfer_xform_del(hid_t prop_id, const char* name, size_t size, void* value); static herr_t H5D_xfer_xform_copy(const char* name, size_t size, void* value); static herr_t H5D_xfer_xform_close(const char* name, size_t size, void* value); - + /* Internal data structure for computing variable-length dataset's total size */ typedef struct { hid_t dataset_id; /* ID of the dataset we are working on */ @@ -1727,6 +1728,75 @@ done: /*------------------------------------------------------------------------- + * Function: H5D_init_type + * + * Purpose: Copy a datatype for a dataset's use, performing all the + * necessary adjustments, etc. + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Errors: + * + * Programmer: Quincey Koziol + * Thursday, June 24, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D_init_type(H5F_t *file, H5D_t *dset, hid_t type_id, const H5T_t *type) +{ + htri_t relocatable; /* Flag whether the type is relocatable */ + htri_t immutable; /* Flag whether the type is immutable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5D_init_type, FAIL) + + /* Sanity checking */ + assert(file); + assert(dset); + assert(type); + + /* Check whether the datatype is relocatable */ + if((relocatable=H5T_is_relocatable(type))<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check datatype?") + + /* Check whether the datatype is immutable */ + if((immutable=H5T_is_immutable(type))<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't check datatype?") + + /* Copy the datatype if it's a custom datatype or if it'll change when it's location is changed */ + if(!immutable || relocatable) { + /* Copy datatype for dataset */ + if((dset->type = H5T_copy(type, H5T_COPY_ALL))==NULL) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy datatype") + + /* Mark any datatypes as being on disk now */ + if(H5T_set_loc(dset->type, file, H5T_LOC_DISK)<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") + + /* Get a datatype ID for the dataset's datatype */ + if((dset->type_id = H5I_register(H5I_DATATYPE, dset->type))<0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register type") + } /* end if */ + /* Not a custom datatype, just use it directly */ + else { + if(H5I_inc_ref(type_id)<0) + HGOTO_ERROR (H5E_DATASET, H5E_CANTINC, FAIL, "Can't increment datatype ID") + + /* Use existing datatype */ + dset->type_id = type_id; + dset->type = (H5T_t *)type; /* (Cast away const OK - QAK) */ + } /* end else */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_init_type() */ + + +/*------------------------------------------------------------------------- * Function: H5D_update_entry_info * * Purpose: Create and fill an H5G_entry_t object for insertion into @@ -2084,13 +2154,9 @@ H5D_create(H5G_entry_t *loc, const char *name, hid_t type_id, const H5S_t *space HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to locate insertion point") /* Copy datatype for dataset */ - if((new_dset->type = H5T_copy(type, H5T_COPY_ALL))==NULL) + if(H5D_init_type(file, new_dset, type_id, type)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy datatype") - /* Mark any datatypes as being on disk now */ - if(H5T_set_loc(new_dset->type, file, H5T_LOC_DISK)<0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location") - /* Copy dataspace for dataset */ if((new_dset->space = H5S_copy(space, FALSE))==NULL) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy dataspace") @@ -2277,7 +2343,7 @@ H5D_create(H5G_entry_t *loc, const char *name, hid_t type_id, const H5S_t *space HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "compact dataset size is bigger than header message maximum size") } /* end case */ break; - + default: HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, NULL, "not implemented yet") } /* end switch */ @@ -2298,7 +2364,6 @@ H5D_create(H5G_entry_t *loc, const char *name, hid_t type_id, const H5S_t *space if (H5G_insert(loc, name, &new_dset->ent, dxpl_id) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to name dataset") - /* Success */ ret_value = new_dset; @@ -2313,7 +2378,7 @@ done: HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, NULL, "unable to release dataspace") } /* end if */ if (new_dset->type) { - if(H5T_close(new_dset->type)<0) + if(H5I_dec_ref(new_dset->type_id)<0) HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, NULL, "unable to release datatype") } /* end if */ if (H5F_addr_defined(new_dset->ent.header)) { @@ -2512,6 +2577,9 @@ H5D_open_oid(const H5G_entry_t *ent, hid_t dxpl_id) /* Get the type and space */ if (NULL==(dataset->type=H5O_read(&(dataset->ent), H5O_DTYPE_ID, 0, NULL, dxpl_id))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to load type info from dataset header") + /* Get a datatype ID for the dataset's datatype */ + if((dataset->type_id = H5I_register(H5I_DATATYPE, dataset->type))<0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, NULL, "unable to register type") if (NULL==(dataset->space=H5S_read(&(dataset->ent),dxpl_id))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to load space info from dataset header") @@ -2692,7 +2760,7 @@ done: HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, NULL, "unable to release dataspace") } /* end if */ if (dataset->type) { - if(H5T_close(dataset->type)<0) + if(H5I_dec_ref(dataset->type_id)<0) HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, NULL, "unable to release datatype") } /* end if */ dataset->ent.file = NULL; @@ -2779,7 +2847,7 @@ H5D_close(H5D_t *dataset) * Release datatype, dataspace and creation property list -- there isn't * much we can do if one of these fails, so we just continue. */ - free_failed=(H5T_close(dataset->type)<0 || H5S_close(dataset->space)<0 || + free_failed=(H5I_dec_ref(dataset->type_id)<0 || H5S_close(dataset->space)<0 || H5I_dec_ref(dataset->dcpl_id) < 0); /* Remove the dataset from the list of opened objects in the file */ @@ -2821,15 +2889,14 @@ done: * * Modifications: * - * Raymond Lu - * Tuesday, October 2, 2001 - * Changed the way to retrieve property for generic property - * list. - * - * Nat Furrer and James Laird - * June 7, 2004 - * Added check for filter encode capability + * Raymond Lu + * Tuesday, October 2, 2001 + * Changed the way to retrieve property for generic property + * list. * + * Nat Furrer and James Laird + * June 17, 2004 + * Added check for filter encode capability *------------------------------------------------------------------------- */ static herr_t @@ -2851,11 +2918,10 @@ H5D_extend (H5D_t *dataset, const hsize_t *size, hid_t dxpl_id) * Filters need encoding if fill value is defined and a fill policy is set that requires * writing on an extend. */ - if(! dataset->checked_filters) - { - - if(H5P_is_fill_value_defined(&(dataset->fill), &fill_status) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Couldn't retrieve fill value from dataset."); + if(! dataset->checked_filters) + { + if(H5P_is_fill_value_defined(&(dataset->fill), &fill_status) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Couldn't retrieve fill value from dataset."); if(fill_status == H5D_FILL_VALUE_DEFAULT || fill_status == H5D_FILL_VALUE_USER_DEFINED) { @@ -2866,20 +2932,9 @@ H5D_extend (H5D_t *dataset, const hsize_t *size, hid_t dxpl_id) (fill_time == H5D_FILL_TIME_IFSET && fill_status == H5D_FILL_VALUE_USER_DEFINED) ) { /* Filters must have encoding enabled. Ensure that all filters can be applied */ - hid_t type_id; - - type_id = H5I_register(H5I_DATATYPE, dataset->type); - if(type_id < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register data type") - - if(H5Z_can_apply(dataset->dcpl_id, type_id) <0) - { - H5I_remove(type_id); + if(H5Z_can_apply(dataset->dcpl_id, dataset->type_id) <0) HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "can't apply filters") - } - if(H5I_remove(type_id) == NULL) - HGOTO_ERROR(H5E_PLINE, H5E_CANTRELEASE, FAIL, "unable to release data type id") dataset->checked_filters = TRUE; } } diff --git a/src/H5Dio.c b/src/H5Dio.c index 8996431..0d9a91c 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -70,10 +70,10 @@ typedef struct fm_map { } fm_map; /* Local functions */ -static herr_t H5D_read(H5D_t *dataset, const H5T_t *mem_type, +static herr_t H5D_read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_t *file_space, hid_t dset_xfer_plist, void *buf/*out*/); -static herr_t H5D_write(H5D_t *dataset, const H5T_t *mem_type, +static herr_t H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_t *file_space, hid_t dset_xfer_plist, const void *buf); static herr_t @@ -444,7 +444,6 @@ H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, void *buf/*out*/) { H5D_t *dset = NULL; - const H5T_t *mem_type = NULL; const H5S_t *mem_space = NULL; const H5S_t *file_space = NULL; herr_t ret_value=SUCCEED; /* Return value */ @@ -458,8 +457,6 @@ H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") if (NULL == dset->ent.file) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - if (NULL == (mem_type = H5I_object_verify(mem_type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type") if (H5S_ALL != mem_space_id) { if (NULL == (mem_space = H5I_object_verify(mem_space_id, H5I_DATASPACE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") @@ -487,7 +484,7 @@ H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") /* read raw data */ - if (H5D_read(dset, mem_type, mem_space, file_space, plist_id, buf/*out*/) < 0) + if (H5D_read(dset, mem_type_id, mem_space, file_space, plist_id, buf/*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data") done: @@ -535,7 +532,6 @@ H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, const void *buf) { H5D_t *dset = NULL; - const H5T_t *mem_type = NULL; const H5S_t *mem_space = NULL; const H5S_t *file_space = NULL; herr_t ret_value=SUCCEED; /* Return value */ @@ -549,8 +545,6 @@ H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") if (NULL == dset->ent.file) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - if (NULL == (mem_type = H5I_object_verify(mem_type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type") if (H5S_ALL != mem_space_id) { if (NULL == (mem_space = H5I_object_verify(mem_space_id, H5I_DATASPACE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") @@ -578,7 +572,7 @@ H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") /* write raw data */ - if (H5D_write(dset, mem_type, mem_space, file_space, plist_id, buf) < 0) + if (H5D_write(dset, mem_type_id, mem_space, file_space, plist_id, buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") done: @@ -634,13 +628,13 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, +H5D_read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_t *file_space, hid_t dxpl_id, void *buf/*out*/) { hssize_t snelmts; /*total number of elmts (signed) */ hsize_t nelmts; /*total number of elmts */ H5T_path_t *tpath = NULL; /*type conversion info */ - hid_t src_id = -1, dst_id = -1;/*temporary type atoms */ + const H5T_t *mem_type = NULL; /* Memory datatype */ H5S_conv_t *sconv=NULL; /*space conversion funcs*/ hbool_t use_par_opt_io=FALSE; /* Whether the 'optimized' I/O routines with be parallel */ #ifdef H5_HAVE_PARALLEL @@ -655,9 +649,12 @@ H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, /* check args */ assert(dataset && dataset->ent.file); - assert(mem_type); assert(buf); + /* Get memory datatype */ + if (NULL == (mem_type = H5I_object_verify(mem_type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type") + if (!file_space) file_space = dataset->space; if (!mem_space) @@ -727,13 +724,8 @@ H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, * enough value in xfer_parms since turning off data type conversion also * turns off background preservation. */ - if (NULL==(tpath=H5T_path_find(dataset->type, mem_type, NULL, NULL, dxpl_id))) { + if (NULL==(tpath=H5T_path_find(dataset->type, mem_type, NULL, NULL, dxpl_id))) HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types") - } else if (!H5T_path_noop(tpath)) { - if ((src_id=H5I_register(H5I_DATATYPE, H5T_copy(dataset->type, H5T_COPY_ALL)))<0 || - (dst_id=H5I_register(H5I_DATATYPE, H5T_copy(mem_type, H5T_COPY_ALL)))<0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion") - } /* end if */ /* Set the storage flags for the space conversion check */ switch(dataset->layout.type) { @@ -766,12 +758,12 @@ H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, /* Determine correct I/O routine to invoke */ if(dataset->layout.type!=H5D_CHUNKED) { if(H5D_contig_read(nelmts, dataset, mem_type, mem_space, file_space, tpath, sconv, - dxpl_cache, dxpl_id, src_id, dst_id, buf)<0) + dxpl_cache, dxpl_id, dataset->type_id, mem_type_id, buf)<0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data") } /* end if */ else { if(H5D_chunk_read(nelmts, dataset, mem_type, mem_space, file_space, tpath, sconv, - dxpl_cache, dxpl_id, src_id, dst_id, buf)<0) + dxpl_cache, dxpl_id, dataset->type_id, mem_type_id, buf)<0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data") } /* end else */ @@ -781,14 +773,6 @@ done: if (xfer_mode_changed) H5D_io_restore_mpio(dxpl_id); #endif /*H5_HAVE_PARALLEL*/ - if (src_id >= 0) { - if(H5I_dec_ref(src_id)<0) - HDONE_ERROR (H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") - } /* end if */ - if (dst_id >= 0) { - if(H5I_dec_ref(dst_id)<0) - HDONE_ERROR (H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") - } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_read() */ @@ -841,13 +825,13 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, +H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_t *file_space, hid_t dxpl_id, const void *buf) { hssize_t snelmts; /*total number of elmts (signed) */ hsize_t nelmts; /*total number of elmts */ H5T_path_t *tpath = NULL; /*type conversion info */ - hid_t src_id = -1, dst_id = -1;/*temporary type atoms */ + const H5T_t *mem_type = NULL; /* Memory datatype */ H5S_conv_t *sconv=NULL; /*space conversion funcs*/ hbool_t use_par_opt_io=FALSE; /* Whether the 'optimized' I/O routines with be parallel */ #ifdef H5_HAVE_PARALLEL @@ -862,26 +846,17 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, /* check args */ assert(dataset && dataset->ent.file); - assert(mem_type); assert(buf); + /* Get the memory datatype */ + if (NULL == (mem_type = H5I_object_verify(mem_type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type") + /* All filters in the DCPL must have encoding enabled. */ if(! dataset->checked_filters) { - hid_t type_id; - - type_id = H5I_register(H5I_DATATYPE, dataset->type); - if(type_id < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register data type") - - if(H5Z_can_apply(dataset->dcpl_id, type_id) <0) - { - H5I_remove(type_id); + if(H5Z_can_apply(dataset->dcpl_id, dataset->type_id) <0) HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "can't apply filters") - } - - if(H5I_remove(type_id) == NULL) - HGOTO_ERROR(H5E_PLINE, H5E_CANTRELEASE, FAIL, "unable to release data type id") dataset->checked_filters = TRUE; } @@ -966,13 +941,8 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, * enough value in xfer_parms since turning off data type conversion also * turns off background preservation. */ - if (NULL==(tpath=H5T_path_find(mem_type, dataset->type, NULL, NULL, dxpl_id))) { + if (NULL==(tpath=H5T_path_find(mem_type, dataset->type, NULL, NULL, dxpl_id))) HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types") - } else if (!H5T_path_noop(tpath)) { - if ((src_id = H5I_register(H5I_DATATYPE, H5T_copy(mem_type, H5T_COPY_ALL)))<0 || - (dst_id = H5I_register(H5I_DATATYPE, H5T_copy(dataset->type, H5T_COPY_ALL)))<0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion") - } /* end if */ /* Set the storage flags for the space conversion check */ switch(dataset->layout.type) { @@ -1005,12 +975,12 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, /* Determine correct I/O routine to invoke */ if(dataset->layout.type!=H5D_CHUNKED) { if(H5D_contig_write(nelmts, dataset, mem_type, mem_space, file_space, tpath, sconv, - dxpl_cache, dxpl_id, src_id, dst_id, buf)<0) + dxpl_cache, dxpl_id, mem_type_id, dataset->type_id, buf)<0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") } /* end if */ else { if(H5D_chunk_write(nelmts, dataset, mem_type, mem_space, file_space, tpath, sconv, - dxpl_cache, dxpl_id, src_id, dst_id, buf)<0) + dxpl_cache, dxpl_id, mem_type_id, dataset->type_id, buf)<0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") } /* end else */ @@ -1035,14 +1005,6 @@ done: if (xfer_mode_changed) H5D_io_restore_mpio(dxpl_id); #endif /*H5_HAVE_PARALLEL*/ - if (src_id >= 0) { - if(H5I_dec_ref(src_id)<0) - HDONE_ERROR (H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") - } /* end if */ - if (dst_id >= 0) { - if(H5I_dec_ref(dst_id)<0) - HDONE_ERROR (H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") - } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_write() */ diff --git a/src/H5Dpkg.h b/src/H5Dpkg.h index 18af011..e1d4b71 100644 --- a/src/H5Dpkg.h +++ b/src/H5Dpkg.h @@ -78,6 +78,7 @@ typedef struct H5D_rdcdc_t { */ struct H5D_t { H5G_entry_t ent; /* cached object header stuff */ + hid_t type_id; /* ID for dataset's datatype */ H5T_t *type; /* datatype of this dataset */ H5S_t *space; /* dataspace of this dataset */ hid_t dcpl_id; /* dataset creation property id */ @@ -4731,16 +4731,16 @@ H5Fget_filesize(hid_t file_id) H5F_t *file=NULL; /* File object for file ID */ haddr_t ret_value; /* Return value */ - FUNC_ENTER_API(H5Fget_filesize, FAIL) + FUNC_ENTER_API(H5Fget_filesize, HADDR_UNDEF) H5TRACE1("a","i",file_id); /* Check args */ if(NULL==(file=H5I_object_verify(file_id, H5I_FILE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, HADDR_UNDEF, "not a file ID") /* Go get the actual file size */ - if((ret_value = H5FDget_eof(file->shared->lf))<0) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file size") + if((ret_value = H5FDget_eof(file->shared->lf))==HADDR_UNDEF) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, HADDR_UNDEF, "unable to get file size") done: FUNC_LEAVE_API(ret_value) @@ -922,7 +922,7 @@ H5O_compute_size(H5F_t *f, H5O_t *oh, size_t *size_ptr) unsigned u; size_t size; - FUNC_ENTER_NOAPI_NOINIT(H5O_compute_size); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_compute_size); /* check args */ HDassert(f); @@ -470,11 +470,11 @@ H5T_init(void) { herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5T_init,FAIL); + FUNC_ENTER_NOAPI(H5T_init, FAIL); /* FUNC_ENTER() does all the work */ done: - FUNC_LEAVE_NOAPI(SUCCEED); + FUNC_LEAVE_NOAPI(ret_value); } @@ -2875,12 +2875,14 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) case H5T_COPY_REOPEN: /* * Return a transient type (locked or unlocked) or an opened named - * type. + * type. Immutable transient types are degraded to read-only. */ if (H5F_addr_defined(new_dt->ent.header)) { if (H5O_open (&(new_dt->ent))<0) HGOTO_ERROR (H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reopen named data type"); new_dt->state = H5T_STATE_OPEN; + } else if (H5T_STATE_IMMUTABLE==new_dt->state) { + new_dt->state = H5T_STATE_RDONLY; } break; } /* end switch */ @@ -4203,7 +4205,7 @@ done: *------------------------------------------------------------------------- */ htri_t -H5T_is_immutable(H5T_t *dt) +H5T_is_immutable(const H5T_t *dt) { htri_t ret_value = FALSE; @@ -4236,7 +4238,7 @@ done: *------------------------------------------------------------------------- */ htri_t -H5T_is_named(H5T_t *dt) +H5T_is_named(const H5T_t *dt) { htri_t ret_value = FALSE; @@ -4488,6 +4490,47 @@ done: /*------------------------------------------------------------------------- + * Function: H5T_is_relocatable + * + * Purpose: Check if a datatype will change between disk and memory. + * + * Notes: Currently, only variable-length and object references change + * between disk & memory (see cases where things are changed in + * the H5T_set_loc() code above). + * + * Return: + * One of two values on success: + * TRUE - If the location of any vlen types changed + * FALSE - If the location of any vlen types is the same + * <0 is returned on failure + * + * Programmer: Quincey Koziol + * Thursday, June 24, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +htri_t +H5T_is_relocatable(const H5T_t *dt) +{ + htri_t ret_value = FALSE; + + FUNC_ENTER_NOAPI(H5T_is_relocatable, FAIL); + + assert(dt); + + if(H5T_detect_class(dt, H5T_VLEN)) + ret_value = TRUE; + else if(H5T_detect_class(dt, H5T_REFERENCE)) + ret_value = TRUE; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5T_is_relocatable() */ + + +/*------------------------------------------------------------------------- * Function: H5T_print_stats * * Purpose: Print statistics about a conversion path. Statistics are diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index 1e4893b..965ca93 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -77,8 +77,9 @@ H5_DLL size_t H5T_get_size(const H5T_t *dt); H5_DLL int H5T_cmp(const H5T_t *dt1, const H5T_t *dt2); H5_DLL herr_t H5T_debug(const H5T_t *dt, FILE * stream); H5_DLL H5G_entry_t *H5T_entof(H5T_t *dt); -H5_DLL htri_t H5T_is_immutable(H5T_t *dt); -H5_DLL htri_t H5T_is_named(H5T_t *dt); +H5_DLL htri_t H5T_is_immutable(const H5T_t *dt); +H5_DLL htri_t H5T_is_named(const H5T_t *dt); +H5_DLL htri_t H5T_is_relocatable(const H5T_t *dt); H5_DLL H5T_path_t *H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name, H5T_conv_t func, hid_t dxpl_id); H5_DLL hbool_t H5T_path_noop(const H5T_path_t *p); diff --git a/test/ntypes.c b/test/ntypes.c index 952c90c..1427f85 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -137,7 +137,7 @@ test_atomic_dtype(hid_t file) free(tmp); /* Convert to the integer type */ - if(H5Tconvert(native_type, H5T_NATIVE_INT, (hsize_t)(DIM0*DIM1), icheck2, NULL, H5P_DEFAULT)<0) + if(H5Tconvert(native_type, H5T_NATIVE_INT, (DIM0*DIM1), icheck2, NULL, H5P_DEFAULT)<0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -152,8 +152,9 @@ test_atomic_dtype(hid_t file) } } - H5Dclose(dataset); - H5Tclose(dtype); + if(H5Dclose(dataset)<0) TEST_ERROR; + if(H5Tclose(native_type)<0) TEST_ERROR; + if(H5Tclose(dtype)<0) TEST_ERROR; /*------------------ Test different data types ----------------*/ @@ -175,6 +176,7 @@ test_atomic_dtype(hid_t file) TEST_ERROR; if(H5Dclose(dataset)<0) TEST_ERROR; + if(H5Tclose(native_type)<0) TEST_ERROR; if(H5Tclose(dtype)<0) TEST_ERROR; @@ -196,6 +198,7 @@ test_atomic_dtype(hid_t file) TEST_ERROR; if(H5Dclose(dataset)<0) TEST_ERROR; + if(H5Tclose(native_type)<0) TEST_ERROR; if(H5Tclose(dtype)<0) TEST_ERROR; @@ -217,6 +220,7 @@ test_atomic_dtype(hid_t file) TEST_ERROR; if(H5Dclose(dataset)<0) TEST_ERROR; + if(H5Tclose(native_type)<0) TEST_ERROR; if(H5Tclose(dtype)<0) TEST_ERROR; @@ -238,6 +242,7 @@ test_atomic_dtype(hid_t file) TEST_ERROR; if(H5Dclose(dataset)<0) TEST_ERROR; + if(H5Tclose(native_type)<0) TEST_ERROR; if(H5Tclose(dtype)<0) TEST_ERROR; @@ -456,7 +461,7 @@ test_compound_dtype2(hid_t file) memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); free(tmp); - if (H5Tconvert(native_type, tid_m, (hsize_t)(DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if (H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) TEST_ERROR; free(bkg); @@ -638,7 +643,7 @@ test_compound_dtype(hid_t file) memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); free(tmp); - if (H5Tconvert(native_type, tid2, (hsize_t)(DIM0*DIM1), check, bkg, H5P_DEFAULT)<0) + if (H5Tconvert(native_type, tid2, (DIM0*DIM1), check, bkg, H5P_DEFAULT)<0) TEST_ERROR; free(bkg); @@ -832,7 +837,7 @@ test_compound_dtype3(hid_t file) memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); free(tmp); - if (H5Tconvert(native_type, tid_m, (hsize_t)(DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if (H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) TEST_ERROR; free(bkg); @@ -1022,7 +1027,7 @@ test_compound_opaque(hid_t file) HDmemcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); HDfree(tmp); - if (H5Tconvert(native_type, tid_m, (hsize_t)(DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if (H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) TEST_ERROR; HDfree(bkg); @@ -1166,7 +1171,7 @@ test_enum_dtype(hid_t file) memcpy(scheck2, tmp, DIM0*DIM1*H5Tget_size(native_type)); free(tmp); - if (H5Tconvert(native_type, tid_m, (hsize_t)(DIM0*DIM1), scheck2, NULL, H5P_DEFAULT)<0) + if (H5Tconvert(native_type, tid_m, (DIM0*DIM1), scheck2, NULL, H5P_DEFAULT)<0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -1305,7 +1310,7 @@ test_array_dtype(hid_t file) memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); free(tmp); - if (H5Tconvert(native_type, tid_m, (hsize_t)(DIM0*DIM1), check, NULL, H5P_DEFAULT)<0) + if (H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, NULL, H5P_DEFAULT)<0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -1427,7 +1432,7 @@ test_array_dtype2(hid_t file) memcpy(icheck3, tmp, DIM0*DIM1*H5Tget_size(native_type)); free(tmp); - if (H5Tconvert(native_type, tid_m, (hsize_t)(DIM0*DIM1), icheck3, NULL, H5P_DEFAULT)<0) + if (H5Tconvert(native_type, tid_m, (DIM0*DIM1), icheck3, NULL, H5P_DEFAULT)<0) TEST_ERROR; /* Check that the values read are the same as the values written */ |