diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2015-03-04 00:27:40 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2015-03-04 00:27:40 (GMT) |
commit | 5b294640c003dac45c2cc489793950207bf63c8f (patch) | |
tree | ef451f922a5242888c2cd63552212fa278284162 /src | |
parent | dc059968de3823ffa1b0008c14b7e7e46c1fb8d8 (diff) | |
parent | 6ee9ea656fad6f408e81bd995eb465e0dd4ce0db (diff) | |
download | hdf5-5b294640c003dac45c2cc489793950207bf63c8f.zip hdf5-5b294640c003dac45c2cc489793950207bf63c8f.tar.gz hdf5-5b294640c003dac45c2cc489793950207bf63c8f.tar.bz2 |
[svn-r26350] Merge of r26273-26348 from the trunk.
Tested on: h5committest
Diffstat (limited to 'src')
-rw-r--r-- | src/H5.c | 80 | ||||
-rw-r--r-- | src/H5MFaggr.c | 2 | ||||
-rw-r--r-- | src/H5Osdspace.c | 4 | ||||
-rw-r--r-- | src/H5R.c | 4 | ||||
-rw-r--r-- | src/H5S.c | 10 | ||||
-rw-r--r-- | src/H5Sall.c | 41 | ||||
-rw-r--r-- | src/H5Shyper.c | 188 | ||||
-rw-r--r-- | src/H5Snone.c | 35 | ||||
-rw-r--r-- | src/H5Spkg.h | 4 | ||||
-rw-r--r-- | src/H5Spoint.c | 56 | ||||
-rw-r--r-- | src/H5Sprivate.h | 4 | ||||
-rw-r--r-- | src/H5Spublic.h | 3 | ||||
-rw-r--r-- | src/H5Sselect.c | 81 | ||||
-rw-r--r-- | src/H5detect.c | 24 | ||||
-rw-r--r-- | src/H5private.h | 42 | ||||
-rw-r--r-- | src/H5timer.c | 89 | ||||
-rw-r--r-- | src/H5trace.c | 14 |
17 files changed, 469 insertions, 212 deletions
@@ -52,7 +52,9 @@ /* Local Prototypes */ /********************/ static void H5_debug_mask(const char*); - +#ifdef H5_HAVE_PARALLEL +static int H5_mpi_delete_cb(MPI_Comm comm, int keyval, void *attr_val, int *flag); +#endif /*H5_HAVE_PARALLEL*/ /*********************/ /* Package Variables */ @@ -109,6 +111,43 @@ H5_init_library(void) herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) + +#ifdef H5_HAVE_PARALLEL + { + int mpi_initialized; + int mpi_code; + + MPI_Initialized(&mpi_initialized); + +#ifdef H5_HAVE_MPE + /* Initialize MPE instrumentation library. */ + if (!H5_MPEinit_g) + { + int mpe_code; + if (mpi_initialized){ + mpe_code = MPE_Init_log(); + HDassert(mpe_code >=0); + H5_MPEinit_g = TRUE; + } + } +#endif /*H5_HAVE_MPE*/ + + /* add an attribute on MPI_COMM_SELF to call H5_term_library + when it is destroyed, i.e. on MPI_Finalize */ + if (mpi_initialized) { + int key_val; + + if(MPI_SUCCESS != (mpi_code = MPI_Comm_create_keyval(MPI_NULL_COPY_FN, + (MPI_Comm_delete_attr_function *)H5_mpi_delete_cb, + &key_val, NULL))) + HMPI_GOTO_ERROR(FAIL, "MPI_Comm_create_keyval failed", mpi_code) + + if(MPI_SUCCESS != (mpi_code = MPI_Comm_set_attr(MPI_COMM_SELF, key_val, NULL))) + HMPI_GOTO_ERROR(FAIL, "MPI_Comm_set_attr failed", mpi_code) + } + } +#endif /*H5_HAVE_PARALLEL*/ + /* * Make sure the package information is updated. */ @@ -132,24 +171,6 @@ H5_init_library(void) H5_debug_g.pkg[H5_PKG_V].name = "v"; H5_debug_g.pkg[H5_PKG_Z].name = "z"; -#ifdef H5_HAVE_MPE - /* Initialize MPE instrumentation library. May need to move this - * up earlier if any of the above initialization involves using - * the instrumentation code. - */ - if (!H5_MPEinit_g) - { - int mpe_code; - int mpi_initialized; - MPI_Initialized(&mpi_initialized); - if (mpi_initialized){ - mpe_code = MPE_Init_log(); - HDassert(mpe_code >=0); - H5_MPEinit_g = TRUE; - } - } -#endif - /* * Install atexit() library cleanup routines unless the H5dont_atexit() * has been called. Once we add something to the atexit() list it stays @@ -580,6 +601,27 @@ H5_debug_mask(const char *s) } } /* end H5_debug_mask() */ +#ifdef H5_HAVE_PARALLEL + +/*------------------------------------------------------------------------- + * Function: H5_mpi_delete_cb + * + * Purpose: Callback attribute on MPI_COMM_SELF to terminate the HDF5 + * library when the communicator is destroyed, i.e. on MPI_Finalize. + * + * Return: MPI_SUCCESS + * + * Programmer: Mohamad Chaarawi, February 2015 + * + *------------------------------------------------------------------------- + */ +static int H5_mpi_delete_cb(MPI_Comm UNUSED comm, int UNUSED keyval, void UNUSED *attr_val, int UNUSED *flag) +{ + H5_term_library(); + return MPI_SUCCESS; +} +#endif /*H5_HAVE_PARALLEL*/ + /*------------------------------------------------------------------------- * Function: H5get_libversion diff --git a/src/H5MFaggr.c b/src/H5MFaggr.c index f015b19..29d21fd 100644 --- a/src/H5MFaggr.c +++ b/src/H5MFaggr.c @@ -46,7 +46,7 @@ /******************/ /* Local Typedefs */ /******************/ -#define EXTEND_THRESHOLD .10 +#define EXTEND_THRESHOLD 0.10F /********************/ diff --git a/src/H5Osdspace.c b/src/H5Osdspace.c index 9ca8436..875cd56 100644 --- a/src/H5Osdspace.c +++ b/src/H5Osdspace.c @@ -308,7 +308,7 @@ H5O_sdspace_copy(const void *_mesg, void *_dest) /* check args */ HDassert(mesg); - if(!dest && NULL == (dest = H5FL_MALLOC(H5S_extent_t))) + if(!dest && NULL == (dest = H5FL_CALLOC(H5S_extent_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy extent information */ @@ -463,7 +463,7 @@ H5O_sdspace_pre_copy_file(H5F_t UNUSED *file_src, const void *mesg_src, */ if(udata) { /* Allocate copy of dataspace extent */ - if(NULL == (udata->src_space_extent = H5FL_MALLOC(H5S_extent_t))) + if(NULL == (udata->src_space_extent = H5FL_CALLOC(H5S_extent_t))) HGOTO_ERROR(H5E_DATASPACE, H5E_NOSPACE, FAIL, "dataspace extent allocation failed") /* Create a copy of the dataspace extent */ @@ -291,7 +291,7 @@ H5R_create(void *_ref, H5G_loc_t *loc, const char *name, H5R_type_t ref_type, H5 H5F_addr_encode(loc->oloc->file, &p, obj_loc.oloc->addr); /* Serialize the selection into heap buffer */ - if(H5S_SELECT_SERIALIZE(space, p) < 0) + if(H5S_SELECT_SERIALIZE(space, &p) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "Unable to serialize selection") /* Save the serialized buffer for later */ @@ -659,7 +659,7 @@ H5R_get_region(H5F_t *file, hid_t dxpl_id, const void *_ref) HGOTO_ERROR(H5E_DATASPACE, H5E_NOTFOUND, NULL, "not found") /* Unserialize the selection */ - if(H5S_select_deserialize(ret_value, p) < 0) + if(H5S_SELECT_DESERIALIZE(&ret_value, &p) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, NULL, "can't deserialize selection") done: @@ -509,6 +509,10 @@ H5S_extent_copy(H5S_extent_t *dst, const H5S_extent_t *src, hbool_t copy_max) FUNC_ENTER_NOAPI(FAIL) + /* Release destination extent before we copy over it */ + if(H5S_extent_release(dst) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release dataspace extent") + /* Copy the regular fields */ dst->type = src->type; dst->version = src->version; @@ -583,7 +587,7 @@ H5S_copy(const H5S_t *src, hbool_t share_selection, hbool_t copy_max) FUNC_ENTER_NOAPI(NULL) - if(NULL == (dst = H5FL_MALLOC(H5S_t))) + if(NULL == (dst = H5FL_CALLOC(H5S_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy the source dataspace's extent */ @@ -1536,7 +1540,7 @@ H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc) buf += extent_size; /* Encode the selection part of dataspace. */ - if(H5S_SELECT_SERIALIZE(obj, buf) < 0) + if(H5S_SELECT_SERIALIZE(obj, &buf) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode select space") } /* end else */ @@ -1655,7 +1659,7 @@ H5S_decode(const unsigned char *buf) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") /* Decode the select part of dataspace. I believe this part always exists. */ - if(H5S_SELECT_DESERIALIZE(ds, buf) < 0) + if(H5S_SELECT_DESERIALIZE(&ds, &buf) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode space selection") /* Set return value */ diff --git a/src/H5Sall.c b/src/H5Sall.c index 24caad2..1105915 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -39,8 +39,8 @@ static herr_t H5S_all_get_seq_list(const H5S_t *space, unsigned flags, static herr_t H5S_all_release(H5S_t *space); static htri_t H5S_all_is_valid(const H5S_t *space); static hssize_t H5S_all_serial_size(const H5S_t *space); -static herr_t H5S_all_serialize(const H5S_t *space, uint8_t *buf); -static herr_t H5S_all_deserialize(H5S_t *space, const uint8_t *buf); +static herr_t H5S_all_serialize(const H5S_t *space, uint8_t **p); +static herr_t H5S_all_deserialize(H5S_t *space, const uint8_t **p); static herr_t H5S_all_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S_all_offset(const H5S_t *space, hsize_t *off); static htri_t H5S_all_is_contiguous(const H5S_t *space); @@ -496,9 +496,11 @@ H5S_all_serial_size (const H5S_t UNUSED *space) PURPOSE Serialize the current selection into a user-provided buffer. USAGE - herr_t H5S_all_serialize(space, buf) - H5S_t *space; IN: Dataspace pointer of selection to serialize - uint8 *buf; OUT: Buffer to put serialized selection into + herr_t H5S_all_serialize(space, p) + const H5S_t *space; IN: Dataspace with selection to serialize + uint8_t **p; OUT: Pointer to buffer to put serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -510,17 +512,19 @@ H5S_all_serial_size (const H5S_t UNUSED *space) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_all_serialize (const H5S_t *space, uint8_t *buf) +H5S_all_serialize (const H5S_t *space, uint8_t **p) { FUNC_ENTER_NOAPI_NOINIT_NOERR HDassert(space); + HDassert(p); + HDassert(*p); /* Store the preamble information */ - UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ - UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ - UINT32ENCODE(buf, (uint32_t)0); /* Store the additional information length */ + UINT32ENCODE(*p, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ + UINT32ENCODE(*p, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(*p, (uint32_t)0); /* Store the un-used padding */ + UINT32ENCODE(*p, (uint32_t)0); /* Store the additional information length */ FUNC_LEAVE_NOAPI(SUCCEED) } /* H5S_all_serialize() */ @@ -532,9 +536,12 @@ H5S_all_serialize (const H5S_t *space, uint8_t *buf) PURPOSE Deserialize the current selection from a user-provided buffer. USAGE - herr_t H5S_all_deserialize(space, buf) - H5S_t *space; IN/OUT: Dataspace pointer to place selection into - uint8 *buf; IN: Buffer to retrieve serialized selection from + herr_t H5S_all_deserialize(space, p) + H5S_t *space; IN/OUT: Dataspace pointer to place + selection into + uint8 **p; OUT: Pointer to buffer holding serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -546,16 +553,18 @@ H5S_all_serialize (const H5S_t *space, uint8_t *buf) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_all_deserialize(H5S_t *space, const uint8_t UNUSED *buf) +H5S_all_deserialize(H5S_t *space, const uint8_t UNUSED **p) { - herr_t ret_value; /* return value */ + herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_NOAPI(FAIL) HDassert(space); + HDassert(p); + HDassert(*p); /* Change to "all" selection */ - if((ret_value = H5S_select_all(space, TRUE)) < 0) + if(H5S_select_all(space, TRUE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") done: diff --git a/src/H5Shyper.c b/src/H5Shyper.c index c97c9b6..9b1562f 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -54,8 +54,8 @@ static herr_t H5S_hyper_get_seq_list(const H5S_t *space, unsigned flags, static herr_t H5S_hyper_release(H5S_t *space); static htri_t H5S_hyper_is_valid(const H5S_t *space); static hssize_t H5S_hyper_serial_size(const H5S_t *space); -static herr_t H5S_hyper_serialize(const H5S_t *space, uint8_t *buf); -static herr_t H5S_hyper_deserialize(H5S_t *space, const uint8_t *buf); +static herr_t H5S_hyper_serialize(const H5S_t *space, uint8_t **p); +static herr_t H5S_hyper_deserialize(H5S_t *space, const uint8_t **p); static herr_t H5S_hyper_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S_hyper_offset(const H5S_t *space, hsize_t *offset); static htri_t H5S_hyper_is_contiguous(const H5S_t *space); @@ -1994,7 +1994,7 @@ H5S_hyper_serial_size(const H5S_t *space) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans, hsize_t *start, hsize_t *end, hsize_t rank, uint8_t **buf) +H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans, hsize_t *start, hsize_t *end, hsize_t rank, uint8_t **p) { H5S_hyper_span_t *curr; /* Pointer to current hyperslab span */ hsize_t u; /* Index variable */ @@ -2007,7 +2007,7 @@ H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans, hsize_t *start, HDassert(start); HDassert(end); HDassert(rank < H5O_LAYOUT_NDIMS); - HDassert(buf && *buf); + HDassert(p && *p); /* Walk through the list of spans, recursing or outputing them */ curr=spans->head; @@ -2019,7 +2019,7 @@ H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans, hsize_t *start, end[rank]=curr->high; /* Recurse down to the next dimension */ - if(H5S_hyper_serialize_helper(curr->down,start,end,rank+1,buf)<0) + if(H5S_hyper_serialize_helper(curr->down,start,end,rank+1,p)<0) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab spans") } /* end if */ else { @@ -2027,17 +2027,17 @@ H5S_hyper_serialize_helper (const H5S_hyper_span_info_t *spans, hsize_t *start, /* Encode previous starting points */ for(u=0; u<rank; u++) - UINT32ENCODE(*buf, (uint32_t)start[u]); + UINT32ENCODE(*p, (uint32_t)start[u]); /* Encode starting point for this span */ - UINT32ENCODE(*buf, (uint32_t)curr->low); + UINT32ENCODE(*p, (uint32_t)curr->low); /* Encode previous ending points */ for(u=0; u<rank; u++) - UINT32ENCODE(*buf, (uint32_t)end[u]); + UINT32ENCODE(*p, (uint32_t)end[u]); /* Encode starting point for this span */ - UINT32ENCODE(*buf, (uint32_t)curr->high); + UINT32ENCODE(*p, (uint32_t)curr->high); } /* end else */ /* Advance to next node */ @@ -2055,9 +2055,11 @@ done: PURPOSE Serialize the current selection into a user-provided buffer. USAGE - herr_t H5S_hyper_serialize(space, buf) - H5S_t *space; IN: Dataspace pointer of selection to serialize - uint8 *buf; OUT: Buffer to put serialized selection into + herr_t H5S_hyper_serialize(space, p) + const H5S_t *space; IN: Dataspace with selection to serialize + uint8_t **p; OUT: Pointer to buffer to put serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -2069,7 +2071,7 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) +H5S_hyper_serialize (const H5S_t *space, uint8_t **p) { const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ hsize_t tmp_count[H5O_LAYOUT_NDIMS]; /* Temporary hyperslab counts */ @@ -2089,14 +2091,14 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) HDassert(space); /* Store the preamble information */ - UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ - UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ - lenp = buf; /* keep the pointer to the length location for later */ - buf += 4; /* skip over space for length */ + UINT32ENCODE(*p, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ + UINT32ENCODE(*p, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(*p, (uint32_t)0); /* Store the un-used padding */ + lenp = *p; /* keep the pointer to the length location for later */ + *p += 4; /* skip over space for length */ /* Encode number of dimensions */ - UINT32ENCODE(buf, (uint32_t)space->extent.rank); + UINT32ENCODE(*p, (uint32_t)space->extent.rank); len += 4; /* Check for a "regular" hyperslab selection */ @@ -2114,7 +2116,7 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) /* Encode number of hyperslabs */ H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t); - UINT32ENCODE(buf, (uint32_t)block_count); + UINT32ENCODE(*p, (uint32_t)block_count); len+=4; /* Now serialize the information for the regular hyperslab */ @@ -2137,11 +2139,11 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) /* Encode hyperslab starting location */ for(u = 0; u < ndims; u++) - UINT32ENCODE(buf, (uint32_t)offset[u]); + UINT32ENCODE(*p, (uint32_t)offset[u]); /* Encode hyperslab ending location */ for(u = 0; u < ndims; u++) - UINT32ENCODE(buf, (uint32_t)(offset[u] + (diminfo[u].block - 1))); + UINT32ENCODE(*p, (uint32_t)(offset[u] + (diminfo[u].block - 1))); /* Move the offset to the next sequence to start */ offset[fast_dim]+=diminfo[fast_dim].stride; @@ -2192,15 +2194,15 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) /* Encode number of hyperslabs */ block_count = H5S_hyper_span_nblocks(space->select.sel_info.hslab->span_lst); H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t); - UINT32ENCODE(buf, (uint32_t)block_count); + UINT32ENCODE(*p, (uint32_t)block_count); len+=4; /* Add 8 bytes times the rank for each hyperslab selected */ H5_CHECK_OVERFLOW((8 * space->extent.rank * block_count), hsize_t, size_t); - len += (size_t)(8 * space->extent.rank * block_count); + len += (uint32_t)(8 * space->extent.rank * block_count); /* Encode each hyperslab in selection */ - H5S_hyper_serialize_helper(space->select.sel_info.hslab->span_lst, start, end, (hsize_t)0, &buf); + H5S_hyper_serialize_helper(space->select.sel_info.hslab->span_lst, start, end, (hsize_t)0, p); } /* end else */ /* Encode length */ @@ -2216,9 +2218,12 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) PURPOSE Deserialize the current selection from a user-provided buffer. USAGE - herr_t H5S_hyper_deserialize(space, buf) - H5S_t *space; IN/OUT: Dataspace pointer to place selection into - uint8 *buf; IN: Buffer to retrieve serialized selection from + herr_t H5S_hyper_deserialize(space, p) + H5S_t *space; IN/OUT: Dataspace pointer to place + selection into + uint8 **p; OUT: Pointer to buffer holding serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -2230,9 +2235,9 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_hyper_deserialize (H5S_t *space, const uint8_t *buf) +H5S_hyper_deserialize (H5S_t *space, const uint8_t **p) { - uint32_t rank; /* rank of points */ + unsigned rank; /* rank of points */ size_t num_elem=0; /* number of elements in selection */ hsize_t start[H5O_LAYOUT_NDIMS]; /* hyperslab start information */ hsize_t end[H5O_LAYOUT_NDIMS]; /* hyperslab end information */ @@ -2251,14 +2256,13 @@ H5S_hyper_deserialize (H5S_t *space, const uint8_t *buf) /* Check args */ HDassert(space); - HDassert(buf); + HDassert(p); + HDassert(*p); /* Deserialize slabs to select */ - buf+=16; /* Skip over selection header */ - UINT32DECODE(buf,rank); /* decode the rank of the point selection */ - if(rank!=space->extent.rank) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "rank of pointer does not match dataspace") - UINT32DECODE(buf,num_elem); /* decode the number of points */ + /* (The header and rank have already beed decoded) */ + rank = space->extent.rank; /* Retrieve rank from space */ + UINT32DECODE(*p,num_elem); /* decode the number of points */ /* Set the count & stride for all blocks */ for(tcount=count,tstride=stride,j=0; j<rank; j++,tstride++,tcount++) { @@ -2270,14 +2274,14 @@ H5S_hyper_deserialize (H5S_t *space, const uint8_t *buf) for(i=0; i<num_elem; i++) { /* Decode the starting points */ for(tstart=start,j=0; j<rank; j++,tstart++) - UINT32DECODE(buf, *tstart); + UINT32DECODE(*p, *tstart); /* Decode the ending points */ for(tend=end,j=0; j<rank; j++,tend++) - UINT32DECODE(buf, *tend); + UINT32DECODE(*p, *tend); /* Change the ending points into blocks */ - for(tblock=block,tstart=start,tend=end,j=0; j<(unsigned)rank; j++,tstart++,tend++,tblock++) + for(tblock=block,tstart=start,tend=end,j=0; j<rank; j++,tstart++,tend++,tblock++) *tblock=(*tend-*tstart)+1; /* Select or add the hyperslab to the current selection */ @@ -8856,3 +8860,109 @@ H5S_hyper_get_seq_list(const H5S_t *space, unsigned UNUSED flags, H5S_sel_iter_t FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_hyper_get_seq_list() */ + +/*-------------------------------------------------------------------------- + NAME + H5Sis_regular_hyperslab + PURPOSE + Determine if a hyperslab selection is regular + USAGE + htri_t H5Sis_regular_hyperslab(dsid) + hid_t dsid; IN: Dataspace ID of hyperslab selection to query + RETURNS + TRUE/FALSE for hyperslab selection, FAIL on error or when querying other + selection types. + DESCRIPTION + If a hyperslab can be represented as a single call to H5Sselect_hyperslab, + with the H5S_SELECT_SET option, it is regular. If the hyperslab selection + would require multiple calls to H5Sselect_hyperslab, it is irregular. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +htri_t +H5Sis_regular_hyperslab(hid_t spaceid) +{ + H5S_t *space; /* Dataspace to query */ + htri_t ret_value; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("t", "i", spaceid); + + /* Check args */ + if(NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + if(H5S_GET_SELECT_TYPE(space) != H5S_SEL_HYPERSLABS) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a hyperslab selection") + + ret_value = H5S_hyper_is_regular(space); + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Sis_regular_hyperslab() */ + + +/*-------------------------------------------------------------------------- + NAME + H5Sgetregular_hyperslab + PURPOSE + Retrieve a regular hyperslab selection + USAGE + herr_t H5Sget_regular_hyperslab(dsid, start, stride, block, count) + hid_t dsid; IN: Dataspace ID of hyperslab selection to query + hsize_t start[]; OUT: Offset of start of hyperslab + hsize_t stride[]; OUT: Hyperslab stride + hsize_t count[]; OUT: Number of blocks included in hyperslab + hsize_t block[]; OUT: Size of block in hyperslab + RETURNS + Non-negative on success/Negative on failure. (It is an error to query + the regular hyperslab selections for non-regular hyperslab selections) + DESCRIPTION + Retrieve the start/stride/count/block for a regular hyperslab selection. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + Note that if a hyperslab is originally regular, then becomes irregular + through selection operations, and then becomes regular again, the new + final regular selection may be equivalent but not identical to the + original regular selection. + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +herr_t +H5Sget_regular_hyperslab(hid_t spaceid, hsize_t start[], hsize_t stride[], + hsize_t count[], hsize_t block[]) +{ + H5S_t *space; /* Dataspace to query */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE5("e", "i*h*h*h*h", spaceid, start, stride, count, block); + + /* Check args */ + if(NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + if(H5S_GET_SELECT_TYPE(space) != H5S_SEL_HYPERSLABS) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a hyperslab selection") + if(TRUE != H5S_hyper_is_regular(space)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a regular hyperslab selection") + + /* Retrieve hyperslab parameters */ + if(start) + for(u = 0; u < space->extent.rank; u++) + start[u] = space->select.sel_info.hslab->app_diminfo[u].start; + if(stride) + for(u = 0; u < space->extent.rank; u++) + stride[u] = space->select.sel_info.hslab->app_diminfo[u].stride; + if(count) + for(u = 0; u < space->extent.rank; u++) + count[u] = space->select.sel_info.hslab->app_diminfo[u].count; + if(block) + for(u = 0; u < space->extent.rank; u++) + block[u] = space->select.sel_info.hslab->app_diminfo[u].block; + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Sget_regular_hyperslab() */ + diff --git a/src/H5Snone.c b/src/H5Snone.c index 3c5eccc..c5ec2de 100644 --- a/src/H5Snone.c +++ b/src/H5Snone.c @@ -40,8 +40,8 @@ static herr_t H5S_none_get_seq_list(const H5S_t *space, unsigned flags, static herr_t H5S_none_release(H5S_t *space); static htri_t H5S_none_is_valid(const H5S_t *space); static hssize_t H5S_none_serial_size(const H5S_t *space); -static herr_t H5S_none_serialize(const H5S_t *space, uint8_t *buf); -static herr_t H5S_none_deserialize(H5S_t *space, const uint8_t *buf); +static herr_t H5S_none_serialize(const H5S_t *space, uint8_t **p); +static herr_t H5S_none_deserialize(H5S_t *space, const uint8_t **p); static herr_t H5S_none_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S_none_offset(const H5S_t *space, hsize_t *off); static htri_t H5S_none_is_contiguous(const H5S_t *space); @@ -464,9 +464,11 @@ H5S_none_serial_size(const H5S_t UNUSED *space) PURPOSE Serialize the current selection into a user-provided buffer. USAGE - herr_t H5S_none_serialize(space, buf) - H5S_t *space; IN: Dataspace pointer of selection to serialize - uint8 *buf; OUT: Buffer to put serialized selection into + herr_t H5S_none_serialize(space, p) + const H5S_t *space; IN: Dataspace with selection to serialize + uint8_t **p; OUT: Pointer to buffer to put serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -478,17 +480,17 @@ H5S_none_serial_size(const H5S_t UNUSED *space) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_none_serialize(const H5S_t *space, uint8_t *buf) +H5S_none_serialize(const H5S_t *space, uint8_t **p) { FUNC_ENTER_NOAPI_NOINIT_NOERR HDassert(space); /* Store the preamble information */ - UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ - UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ - UINT32ENCODE(buf, (uint32_t)0); /* Store the additional information length */ + UINT32ENCODE(*p, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ + UINT32ENCODE(*p, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(*p, (uint32_t)0); /* Store the un-used padding */ + UINT32ENCODE(*p, (uint32_t)0); /* Store the additional information length */ FUNC_LEAVE_NOAPI(SUCCEED) } /* H5S_none_serialize() */ @@ -500,9 +502,12 @@ H5S_none_serialize(const H5S_t *space, uint8_t *buf) PURPOSE Deserialize the current selection from a user-provided buffer. USAGE - herr_t H5S_none_deserialize(space, buf) - H5S_t *space; IN/OUT: Dataspace pointer to place selection into - uint8 *buf; IN: Buffer to retrieve serialized selection from + herr_t H5S_none_deserialize(space, p) + H5S_t *space; IN/OUT: Dataspace pointer to place + selection into + uint8 **p; OUT: Pointer to buffer holding serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -514,13 +519,15 @@ H5S_none_serialize(const H5S_t *space, uint8_t *buf) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_none_deserialize(H5S_t *space, const uint8_t UNUSED *buf) +H5S_none_deserialize(H5S_t *space, const uint8_t UNUSED **p) { herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_NOAPI_NOINIT HDassert(space); + HDassert(p); + HDassert(*p); /* Change to "none" selection */ if(H5S_select_none(space) < 0) diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 0a9df69..5f84717 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -130,9 +130,9 @@ typedef htri_t (*H5S_sel_is_valid_func_t)(const H5S_t *space); /* Method to determine number of bytes required to store current selection */ typedef hssize_t (*H5S_sel_serial_size_func_t)(const H5S_t *space); /* Method to store current selection in "serialized" form (a byte sequence suitable for storing on disk) */ -typedef herr_t (*H5S_sel_serialize_func_t)(const H5S_t *space, uint8_t *buf); +typedef herr_t (*H5S_sel_serialize_func_t)(const H5S_t *space, uint8_t **p); /* Method to store create selection from "serialized" form (a byte sequence suitable for storing on disk) */ -typedef herr_t (*H5S_sel_deserialize_func_t)(H5S_t *space, const uint8_t *buf); +typedef herr_t (*H5S_sel_deserialize_func_t)(H5S_t *space, const uint8_t **p); /* Method to determine smallest n-D bounding box containing the current selection */ typedef herr_t (*H5S_sel_bounds_func_t)(const H5S_t *space, hsize_t *start, hsize_t *end); /* Method to determine linear offset of initial element in selection within dataspace */ diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 70842df..44e0510 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -41,8 +41,8 @@ static herr_t H5S_point_get_seq_list(const H5S_t *space, unsigned flags, static herr_t H5S_point_release(H5S_t *space); static htri_t H5S_point_is_valid(const H5S_t *space); static hssize_t H5S_point_serial_size(const H5S_t *space); -static herr_t H5S_point_serialize(const H5S_t *space, uint8_t *buf); -static herr_t H5S_point_deserialize(H5S_t *space, const uint8_t *buf); +static herr_t H5S_point_serialize(const H5S_t *space, uint8_t **p); +static herr_t H5S_point_deserialize(H5S_t *space, const uint8_t **p); static herr_t H5S_point_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S_point_offset(const H5S_t *space, hsize_t *off); static htri_t H5S_point_is_contiguous(const H5S_t *space); @@ -804,9 +804,11 @@ H5S_point_serial_size (const H5S_t *space) PURPOSE Serialize the current selection into a user-provided buffer. USAGE - herr_t H5S_point_serialize(space, buf) - H5S_t *space; IN: Dataspace pointer of selection to serialize - uint8 *buf; OUT: Buffer to put serialized selection into + herr_t H5S_point_serialize(space, p) + const H5S_t *space; IN: Dataspace with selection to serialize + uint8_t **p; OUT: Pointer to buffer to put serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -818,7 +820,7 @@ H5S_point_serial_size (const H5S_t *space) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_point_serialize (const H5S_t *space, uint8_t *buf) +H5S_point_serialize (const H5S_t *space, uint8_t **p) { H5S_pnt_node_t *curr; /* Point information nodes */ uint8_t *lenp; /* pointer to length location for later storage */ @@ -830,18 +832,18 @@ H5S_point_serialize (const H5S_t *space, uint8_t *buf) HDassert(space); /* Store the preamble information */ - UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(buf, (uint32_t)1); /* Store the version number */ - UINT32ENCODE(buf, (uint32_t)0); /* Store the un-used padding */ - lenp=buf; /* keep the pointer to the length location for later */ - buf+=4; /* skip over space for length */ + UINT32ENCODE(*p, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ + UINT32ENCODE(*p, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(*p, (uint32_t)0); /* Store the un-used padding */ + lenp=*p; /* keep the pointer to the length location for later */ + *p+=4; /* skip over space for length */ /* Encode number of dimensions */ - UINT32ENCODE(buf, (uint32_t)space->extent.rank); + UINT32ENCODE(*p, (uint32_t)space->extent.rank); len+=4; /* Encode number of elements */ - UINT32ENCODE(buf, (uint32_t)space->select.num_elem); + UINT32ENCODE(*p, (uint32_t)space->select.num_elem); len+=4; /* Encode each point in selection */ @@ -852,7 +854,7 @@ H5S_point_serialize (const H5S_t *space, uint8_t *buf) /* Encode each point */ for(u=0; u<space->extent.rank; u++) - UINT32ENCODE(buf, (uint32_t)curr->pnt[u]); + UINT32ENCODE(*p, (uint32_t)curr->pnt[u]); curr=curr->next; } /* end while */ @@ -870,9 +872,12 @@ H5S_point_serialize (const H5S_t *space, uint8_t *buf) PURPOSE Deserialize the current selection from a user-provided buffer. USAGE - herr_t H5S_point_deserialize(space, buf) - H5S_t *space; IN/OUT: Dataspace pointer to place selection into - uint8 *buf; IN: Buffer to retrieve serialized selection from + herr_t H5S_point_deserialize(space, p) + H5S_t *space; IN/OUT: Dataspace pointer to place + selection into + uint8 **p; OUT: Pointer to buffer holding serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -884,10 +889,10 @@ H5S_point_serialize (const H5S_t *space, uint8_t *buf) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_point_deserialize (H5S_t *space, const uint8_t *buf) +H5S_point_deserialize (H5S_t *space, const uint8_t **p) { H5S_seloper_t op=H5S_SELECT_SET; /* Selection operation */ - uint32_t rank; /* Rank of points */ + unsigned rank; /* Rank of points */ size_t num_elem=0; /* Number of elements in selection */ hsize_t *coord=NULL, *tcoord; /* Pointer to array of elements */ unsigned i, j; /* local counting variables */ @@ -897,14 +902,13 @@ H5S_point_deserialize (H5S_t *space, const uint8_t *buf) /* Check args */ HDassert(space); - HDassert(buf); + HDassert(p); + HDassert(*p); /* Deserialize points to select */ - buf += 16; /* Skip over selection header */ - UINT32DECODE(buf, rank); /* decode the rank of the point selection */ - if(rank != space->extent.rank) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "rank of pointer does not match dataspace") - UINT32DECODE(buf, num_elem); /* decode the number of points */ + /* (The header and rank have already beed decoded) */ + rank = space->extent.rank; /* Retrieve rank from space */ + UINT32DECODE(*p, num_elem); /* decode the number of points */ /* Allocate space for the coordinates */ if(NULL == (coord = (hsize_t *)H5MM_malloc(num_elem * rank * sizeof(hsize_t)))) @@ -913,7 +917,7 @@ H5S_point_deserialize (H5S_t *space, const uint8_t *buf) /* Retrieve the coordinates from the buffer */ for(tcoord = coord, i = 0; i < num_elem; i++) for(j = 0; j < (unsigned)rank; j++, tcoord++) - UINT32DECODE(buf, *tcoord); + UINT32DECODE(*p, *tcoord); /* Select points */ if(H5S_select_elements(space, op, num_elem, (const hsize_t *)coord) < 0) diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 44cd6c3..7b7b8c6 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -206,7 +206,7 @@ H5_DLL int H5S_extent_get_dims(const H5S_extent_t *ext, hsize_t dims[], hsize_t H5_DLL htri_t H5S_extent_equal(const H5S_t *ds1, const H5S_t *ds2); /* Operations on selections */ -H5_DLL herr_t H5S_select_deserialize(H5S_t *space, const uint8_t *buf); +H5_DLL herr_t H5S_select_deserialize(H5S_t **space, const uint8_t **p); H5_DLL H5S_sel_type H5S_get_select_type(const H5S_t *space); H5_DLL herr_t H5S_select_iterate(void *buf, hid_t type_id, const H5S_t *space, H5D_operator_t op, void *operator_data); @@ -227,7 +227,7 @@ H5_DLL herr_t H5S_select_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); H5_DLL hssize_t H5S_select_serial_size(const H5S_t *space); -H5_DLL herr_t H5S_select_serialize(const H5S_t *space, uint8_t *buf); +H5_DLL herr_t H5S_select_serialize(const H5S_t *space, uint8_t **p); H5_DLL htri_t H5S_select_is_contiguous(const H5S_t *space); H5_DLL htri_t H5S_select_is_single(const H5S_t *space); H5_DLL htri_t H5S_select_is_regular(const H5S_t *space); diff --git a/src/H5Spublic.h b/src/H5Spublic.h index 0a39ce1..37d3866 100644 --- a/src/H5Spublic.h +++ b/src/H5Spublic.h @@ -137,6 +137,9 @@ H5_DLL herr_t H5Sselect_all(hid_t spaceid); H5_DLL herr_t H5Sselect_none(hid_t spaceid); H5_DLL herr_t H5Soffset_simple(hid_t space_id, const hssize_t *offset); H5_DLL htri_t H5Sselect_valid(hid_t spaceid); +H5_DLL htri_t H5Sis_regular_hyperslab(hid_t spaceid); +H5_DLL htri_t H5Sget_regular_hyperslab(hid_t spaceid, hsize_t start[], + hsize_t stride[], hsize_t count[], hsize_t block[]); H5_DLL hssize_t H5Sget_select_hyper_nblocks(hid_t spaceid); H5_DLL hssize_t H5Sget_select_elem_npoints(hid_t spaceid); H5_DLL herr_t H5Sget_select_hyper_blocklist(hid_t spaceid, hsize_t startblock, diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 2cb4b38..a4f13d7 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -239,9 +239,11 @@ H5S_select_serial_size(const H5S_t *space) PURPOSE Serialize the selection for a dataspace into a buffer USAGE - herr_t H5S_select_serialize(space, buf) + herr_t H5S_select_serialize(space, p) const H5S_t *space; IN: Dataspace with selection to serialize - uint8_t *buf; OUT: Buffer to put serialized selection + uint8_t **p; OUT: Pointer to buffer to put serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -256,17 +258,17 @@ H5S_select_serial_size(const H5S_t *space) REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_select_serialize(const H5S_t *space, uint8_t *buf) +H5S_select_serialize(const H5S_t *space, uint8_t **p) { herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR HDassert(space); - HDassert(buf); + HDassert(p); /* Call the selection type's serialize function */ - ret_value=(*space->select.type->serialize)(space,buf); + ret_value=(*space->select.type->serialize)(space,p); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_serialize() */ @@ -428,9 +430,13 @@ H5S_select_valid(const H5S_t *space) Deserialize the current selection from a user-provided buffer into a real selection in the dataspace. USAGE - herr_t H5S_select_deserialize(space, buf) - H5S_t *space; IN/OUT: Dataspace pointer to place selection into - uint8 *buf; IN: Buffer to retrieve serialized selection from + herr_t H5S_select_deserialize(space, p) + H5S_t **space; IN/OUT: Dataspace pointer to place + selection into. Will be allocated if not + provided. + uint8 **p; OUT: Pointer to buffer holding serialized + selection. Will be advanced to end of + serialized selection. RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -444,42 +450,81 @@ H5S_select_valid(const H5S_t *space) REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_select_deserialize (H5S_t *space, const uint8_t *buf) +H5S_select_deserialize (H5S_t **space, const uint8_t **p) { - const uint8_t *tbuf; /* Temporary pointer to the selection type */ - uint32_t sel_type; /* Pointer to the selection type */ + H5S_t *tmp_space; /* Pointer to actual dataspace to use, either + *space or a newly allocated one */ + uint32_t sel_type; /* Pointer to the selection type */ herr_t ret_value=FAIL; /* return value */ FUNC_ENTER_NOAPI(FAIL) HDassert(space); - tbuf=buf; - UINT32DECODE(tbuf, sel_type); + /* Allocate space if not provided */ + if(!*space) { + if(NULL == (tmp_space = H5S_create(H5S_SIMPLE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace") + } /* end if */ + else + tmp_space = *space; + + /* Decode selection type */ + UINT32DECODE(*p, sel_type); + + /* Skip over the remainder of the header */ + *p += 12; + + /* Decode and check or patch rank for point and hyperslab selections */ + if((sel_type == H5S_SEL_POINTS) || (sel_type == H5S_SEL_HYPERSLABS)) { + uint32_t rank; /* Rank of dataspace */ + + /* Decode the rank of the point selection */ + UINT32DECODE(*p,rank); + + if(!*space) + /* Patch the rank of the allocated dataspace */ + tmp_space->extent.rank = rank; + else + /* Verify the rank of the provided dataspace */ + if(rank != tmp_space->extent.rank) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "rank of serialized selection does not match dataspace") + } /* end if */ + + /* Make routine for selection type */ switch(sel_type) { case H5S_SEL_POINTS: /* Sequence of points selected */ - ret_value=(*H5S_sel_point->deserialize)(space,buf); + ret_value = (*H5S_sel_point->deserialize)(tmp_space, p); break; case H5S_SEL_HYPERSLABS: /* Hyperslab selection defined */ - ret_value=(*H5S_sel_hyper->deserialize)(space,buf); + ret_value = (*H5S_sel_hyper->deserialize)(tmp_space, p); break; case H5S_SEL_ALL: /* Entire extent selected */ - ret_value=(*H5S_sel_all->deserialize)(space,buf); + ret_value = (*H5S_sel_all->deserialize)(tmp_space, p); break; case H5S_SEL_NONE: /* Nothing selected */ - ret_value=(*H5S_sel_none->deserialize)(space,buf); + ret_value = (*H5S_sel_none->deserialize)(tmp_space, p); break; default: break; } - if(ret_value<0) + if(ret_value < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTLOAD, FAIL, "can't deserialize selection") + /* Return space to the caller if allocated */ + if(!*space) + *space = tmp_space; + done: + /* Free temporary space if not passed to caller (only happens on error) */ + if(!*space && tmp_space) + if(H5S_close(tmp_space) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace") + FUNC_LEAVE_NOAPI(ret_value) } /* H5S_select_deserialize() */ diff --git a/src/H5detect.c b/src/H5detect.c index aed7514..b902af4 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -323,7 +323,7 @@ precision (detected_t *d) * steps). This is necessary because padding bits can change arbitrarily \ * and interfere with detection of the various properties below unless we \ * know to ignore them. */ \ - _v1 = 4.0; \ + _v1 = (TYPE)4.0L; \ HDmemcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ for(_i = 0; _i < (int)sizeof(TYPE); _i++) \ for(_byte_mask = (unsigned char)1; _byte_mask; _byte_mask <<= 1) { \ @@ -335,10 +335,10 @@ precision (detected_t *d) } /* end for */ \ \ /* Byte Order */ \ - for(_i = 0, _v1 = 0.0, _v2 = 1.0; _i < (int)sizeof(TYPE); _i++) { \ + for(_i = 0, _v1 = (TYPE)0.0L, _v2 = (TYPE)1.0L; _i < (int)sizeof(TYPE); _i++) { \ _v3 = _v1; \ _v1 += _v2; \ - _v2 /= 256.0; \ + _v2 /= (TYPE)256.0L; \ HDmemcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ HDmemcpy(_buf3, (const void *)&_v3, sizeof(TYPE)); \ _j = byte_cmp(sizeof(TYPE), _buf3, _buf1, _pad_mask); \ @@ -353,20 +353,20 @@ precision (detected_t *d) INFO.is_vax = TRUE; \ \ /* Implicit mantissa bit */ \ - _v1 = 0.5; \ - _v2 = 1.0; \ + _v1 = (TYPE)0.5L; \ + _v2 = (TYPE)1.0L; \ INFO.imp = imp_bit (sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ \ /* Sign bit */ \ - _v1 = 1.0; \ - _v2 = -1.0; \ + _v1 = (TYPE)1.0L; \ + _v2 = (TYPE)-1.0L; \ INFO.sign = bit_cmp (sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ \ /* Mantissa */ \ INFO.mpos = 0; \ \ - _v1 = 1.0; \ - _v2 = 1.5; \ + _v1 = (TYPE)1.0L; \ + _v2 = (TYPE)1.5L; \ INFO.msize = bit_cmp (sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ INFO.msize += 1 + (INFO.imp?0:1) - INFO.mpos; \ \ @@ -375,7 +375,7 @@ precision (detected_t *d) \ INFO.esize = INFO.sign - INFO.epos; \ \ - _v1 = 1.0; \ + _v1 = (TYPE)1.0L; \ INFO.bias = find_bias (INFO.epos, INFO.esize, INFO.perm, &_v1); \ precision (&(INFO)); \ ALIGNMENT(TYPE, INFO); \ @@ -1381,8 +1381,8 @@ detect_C89_integers(void) static void detect_C89_floats(void) { - DETECT_F(float, FLOAT, d_g[nd_g]); nd_g++; - DETECT_F(double, DOUBLE, d_g[nd_g]); nd_g++; + DETECT_F(float, FLOAT, d_g[nd_g]); nd_g++; + DETECT_F(double, DOUBLE, d_g[nd_g]); nd_g++; } diff --git a/src/H5private.h b/src/H5private.h index a532c79..1164a2d 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -480,6 +480,48 @@ # define H5_DEC_ENUM(TYPE,VAR) (VAR)=((TYPE)((VAR)-1)) #endif +/* Double constant wrapper + * + * Quiets gcc warnings from -Wunsuffixed-float-constants. + * + * This is a really annoying warning since the standard specifies that + * constants of type double do NOT get a suffix so there's no way + * to specify a constant of type double. To quiet gcc, we specify floating + * point constants as type long double and cast to double. + * + * Note that this macro only needs to be used where using a double + * is important. For most code, suffixing constants with F will quiet the + * compiler and not produce erroneous code. + */ +#define H5_DOUBLE(S) ((double) S ## L) + +/* + * Methods to compare the equality of floating-point values: + * + * 1. H5_XXX_ABS_EQUAL - check if the difference is smaller than the + * Epsilon value. The Epsilon values, FLT_EPSILON, DBL_EPSILON, + * and LDBL_EPSILON, are defined by compiler in float.h. + * + * 2. H5_XXX_REL_EQUAL - check if the relative difference is smaller than a + * predefined value M. See if two values are relatively equal. + * It's the developer's responsibility not to pass in the value 0, which + * may cause the equation to fail. + */ +#define H5_FLT_ABS_EQUAL(X,Y) (HDfabsf(X-Y) < FLT_EPSILON) +#define H5_DBL_ABS_EQUAL(X,Y) (HDfabs (X-Y) < DBL_EPSILON) +#define H5_LDBL_ABS_EQUAL(X,Y) (HDfabsl(X-Y) < LDBL_EPSILON) + +#define H5_FLT_REL_EQUAL(X,Y,M) (HDfabsf((Y-X) / X) < M) +#define H5_DBL_REL_EQUAL(X,Y,M) (HDfabs ((Y-X) / X) < M) +#define H5_LDBL_REL_EQUAL(X,Y,M) (HDfabsl((Y-X) / X) < M) + +/* KiB, MiB, GiB, TiB, EiB - Used in profiling and timing code */ +#define H5_KB (1024.0F) +#define H5_MB (1024.0F * 1024.0F) +#define H5_GB (1024.0F * 1024.0F * 1024.0F) +#define H5_TB (1024.0F * 1024.0F * 1024.0F * 1024.0F) +#define H5_EB (1024.0F * 1024.0F * 1024.0F * 1024.0F * 1024.0F) + /* * Data types and functions for timing certain parts of the library. */ diff --git a/src/H5timer.c b/src/H5timer.c index 301d98b..94f2883 100644 --- a/src/H5timer.c +++ b/src/H5timer.c @@ -90,8 +90,6 @@ * Programmer: Robb Matzke * Thursday, April 16, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ void @@ -112,8 +110,6 @@ H5_timer_reset (H5_timer_t *timer) * Programmer: Robb Matzke * Thursday, April 16, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ void @@ -131,18 +127,18 @@ H5_timer_begin (H5_timer_t *timer) #ifdef H5_HAVE_GETRUSAGE HDgetrusage (RUSAGE_SELF, &rusage); timer->utime = (double)rusage.ru_utime.tv_sec + - ((double)rusage.ru_utime.tv_usec / 1e6); + ((double)rusage.ru_utime.tv_usec / 1e6F); timer->stime = (double)rusage.ru_stime.tv_sec + - ((double)rusage.ru_stime.tv_usec / 1e6); + ((double)rusage.ru_stime.tv_usec / 1e6F); #else - timer->utime = 0.0; - timer->stime = 0.0; + timer->utime = 0.0F; + timer->stime = 0.0F; #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday (&etime, NULL); - timer->etime = (double)etime.tv_sec + ((double)etime.tv_usec / 1e6); + timer->etime = (double)etime.tv_sec + ((double)etime.tv_usec / 1e6F); #else - timer->etime = 0.0; + timer->etime = 0.0F; #endif } /* end H5_timer_begin() */ @@ -160,8 +156,6 @@ H5_timer_begin (H5_timer_t *timer) * Programmer: Robb Matzke * Thursday, April 16, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ void @@ -170,16 +164,16 @@ H5_timer_end (H5_timer_t *sum/*in,out*/, H5_timer_t *timer/*in,out*/) H5_timer_t now; HDassert(timer); - H5_timer_begin (&now); + H5_timer_begin(&now); - timer->utime = MAX(0.0, now.utime - timer->utime); - timer->stime = MAX(0.0, now.stime - timer->stime); - timer->etime = MAX(0.0, now.etime - timer->etime); + timer->utime = MAX(0.0F, now.utime - timer->utime); + timer->stime = MAX(0.0F, now.stime - timer->stime); + timer->etime = MAX(0.0F, now.etime - timer->etime); if (sum) { - sum->utime += timer->utime; - sum->stime += timer->stime; - sum->etime += timer->etime; + sum->utime += timer->utime; + sum->stime += timer->stime; + sum->etime += timer->etime; } } /* end H5_timer_end() */ @@ -207,8 +201,6 @@ H5_timer_end (H5_timer_t *sum/*in,out*/, H5_timer_t *timer/*in,out*/) * Programmer: Robb Matzke * Wednesday, August 5, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ void @@ -216,35 +208,34 @@ H5_bandwidth(char *buf/*out*/, double nbytes, double nseconds) { double bw; - if(nseconds <= 0.0) - HDstrcpy(buf, " NaN"); + if(nseconds <= 0.0F) + HDstrcpy(buf, " NaN"); else { - bw = nbytes/nseconds; - if(HDfabs(bw) < 0.0000000001) - /* That is == 0.0, but direct comparison between floats is bad */ - HDstrcpy(buf, "0.000 B/s"); - else if(bw < 1.0) - sprintf(buf, "%10.4e", bw); - else if(bw < 1024.0) { - sprintf(buf, "%05.4f", bw); - HDstrcpy(buf+5, " B/s"); - } else if(bw < (1024.0 * 1024.0)) { - sprintf(buf, "%05.4f", bw / 1024.0); - HDstrcpy(buf+5, " kB/s"); - } else if(bw < (1024.0 * 1024.0 * 1024.0)) { - sprintf(buf, "%05.4f", bw / (1024.0 * 1024.0)); - HDstrcpy(buf+5, " MB/s"); - } else if(bw < (1024.0 * 1024.0 * 1024.0 * 1024.0)) { - sprintf(buf, "%05.4f", bw / (1024.0 * 1024.0 * 1024.0)); - HDstrcpy(buf+5, " GB/s"); - } else if(bw < (1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0)) { - sprintf(buf, "%05.4f", bw / (1024.0 * 1024.0 * 1024.0 * 1024.0)); - HDstrcpy(buf+5, " TB/s"); - } else { - sprintf(buf, "%10.4e", bw); - if(HDstrlen(buf) > 10) - sprintf(buf, "%10.3e", bw); - } + bw = nbytes/nseconds; + if(H5_DBL_ABS_EQUAL(bw, 0.0F)) + HDstrcpy(buf, "0.000 B/s"); + else if(bw < 1.0F) + sprintf(buf, "%10.4e", bw); + else if(bw < H5_KB) { + sprintf(buf, "%05.4f", bw); + HDstrcpy(buf+5, " B/s"); + } else if(bw < H5_MB) { + sprintf(buf, "%05.4f", bw / H5_KB); + HDstrcpy(buf+5, " kB/s"); + } else if(bw < H5_GB) { + sprintf(buf, "%05.4f", bw / H5_MB); + HDstrcpy(buf+5, " MB/s"); + } else if(bw < H5_TB) { + sprintf(buf, "%05.4f", bw / H5_GB); + HDstrcpy(buf+5, " GB/s"); + } else if(bw < H5_EB) { + sprintf(buf, "%05.4f", bw / H5_TB); + HDstrcpy(buf+5, " TB/s"); + } else { + sprintf(buf, "%10.4e", bw); + if(HDstrlen(buf) > 10) + sprintf(buf, "%10.3e", bw); + } } } /* end H5_bandwidth() */ diff --git a/src/H5trace.c b/src/H5trace.c index 7e10a84..9efc7f9 100644 --- a/src/H5trace.c +++ b/src/H5trace.c @@ -110,7 +110,7 @@ * SO MAY CAUSE H5_trace() TO BE INVOKED RECURSIVELY OR MAY * CAUSE LIBRARY INITIALIZATIONS THAT ARE NOT DESIRED. * - * Return: void + * Return: Execution time for an API call * * Programmer: Robb Matzke * Tuesday, June 16, 1998 @@ -129,34 +129,34 @@ H5_trace(const double *returning, const char *func, const char *type, ...) void *vp = NULL; FILE *out = H5_debug_g.trace; H5_timer_t event_time; - static H5_timer_t first_time = {0.0, 0.0, 0.0}; + static H5_timer_t first_time = {0.0F, 0.0F, 0.0F}; static int current_depth = 0; static int last_call_depth = 0; /* FUNC_ENTER() should not be called */ if(!out) - return 0.0; /*tracing is off*/ + return 0.0F; /*tracing is off*/ va_start(ap, type); if(H5_debug_g.ttop) { if(returning) { if(current_depth > 1) { --current_depth; - return 0.0; + return 0.0F; } /* end if */ } /* end if */ else { if(current_depth > 0) { /*do not update last_call_depth*/ current_depth++; - return 0.0; + return 0.0F; } /* end if */ } /* end else */ } /* end if */ - /* Get tim for event */ - if(HDfabs(first_time.etime) < 0.0000000001) + /* Get time for event */ + if(HDfabs(first_time.etime) < 0.0000000001F) /* That is == 0.0, but direct comparison between floats is bad */ H5_timer_begin(&first_time); if(H5_debug_g.ttimes) |