diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 1999-11-17 21:59:53 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 1999-11-17 21:59:53 (GMT) |
commit | 9e014467b62df66322de63e21be565ed59a079b3 (patch) | |
tree | e6b01ab36a0f2a67c1e3a68b5be10dc5e15f481d /src/H5Tconv.c | |
parent | cd313a16456934b336902ca509d10187b4d975de (diff) | |
download | hdf5-9e014467b62df66322de63e21be565ed59a079b3.zip hdf5-9e014467b62df66322de63e21be565ed59a079b3.tar.gz hdf5-9e014467b62df66322de63e21be565ed59a079b3.tar.bz2 |
[svn-r1836] Mainly fixed a bug in VL datatype comparisons which was causing non-equal
VL types to compare as equal. Added some asserts to make certain nothing
slips through again. Also cleaned up a few warnings from the SGI compiler.
Diffstat (limited to 'src/H5Tconv.c')
-rw-r--r-- | src/H5Tconv.c | 904 |
1 files changed, 451 insertions, 453 deletions
diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 652e658..cf1c7d1 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -788,96 +788,96 @@ H5T_conv_struct_init (H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata) FUNC_ENTER (H5T_conv_struct_init, FAIL); if (!priv) { - /* - * Allocate private data structure and arrays. - */ - if (NULL==(priv=cdata->priv=H5MM_calloc(sizeof(H5T_conv_struct_t))) || - NULL==(priv->src2dst=H5MM_malloc(src->u.compnd.nmembs * - sizeof(intn))) || - NULL==(priv->src_memb_id=H5MM_malloc(src->u.compnd.nmembs * - sizeof(hid_t))) || - NULL==(priv->dst_memb_id=H5MM_malloc(dst->u.compnd.nmembs * - sizeof(hid_t))) || - NULL==(priv->memb_nelmts=H5MM_malloc(src->u.compnd.nmembs * - sizeof(size_t)))) { - HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, - "memory allocation failed"); - } - src2dst = priv->src2dst; - - /* - * Insure that members are sorted. - */ - H5T_sort_value(src, NULL); - H5T_sort_value(dst, NULL); - - /* - * Build a mapping from source member number to destination member - * number. If some source member is not a destination member then that - * mapping element will be negative. Also create atoms for each - * source and destination member data type so we can look up the - * member data type conversion functions later. - */ - for (i=0; i<src->u.compnd.nmembs; i++) { - src2dst[i] = -1; - for (j=0; j<dst->u.compnd.nmembs; j++) { - if (!HDstrcmp (src->u.compnd.memb[i].name, - dst->u.compnd.memb[j].name)) { - src2dst[i] = j; - break; - } - } - if (src2dst[i]>=0) { - type = H5T_copy (src->u.compnd.memb[i].type, H5T_COPY_ALL); - tid = H5I_register (H5I_DATATYPE, type); - assert (tid>=0); - priv->src_memb_id[i] = tid; - - type = H5T_copy (dst->u.compnd.memb[src2dst[i]].type, - H5T_COPY_ALL); - tid = H5I_register (H5I_DATATYPE, type); - assert (tid>=0); - priv->dst_memb_id[src2dst[i]] = tid; - } - } - - /* - * Those members which are in both the source and destination must be - * the same size and shape arrays. - */ - for (i=0; i<src->u.compnd.nmembs; i++) { - if (src2dst[i]>=0) { - H5T_cmemb_t *src_memb = src->u.compnd.memb + i; - H5T_cmemb_t *dst_memb = dst->u.compnd.memb + src2dst[i]; - if (src_memb->ndims != dst_memb->ndims) { - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "source and dest members have incompatible " - "size or shape"); - } - for (j=0; j<src_memb->ndims; j++) { - if (src_memb->dim[j] != dst_memb->dim[j]) { - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "source and dest members have " - "incompatible size or shape"); - } + /* + * Allocate private data structure and arrays. + */ + if (NULL==(priv=cdata->priv=H5MM_calloc(sizeof(H5T_conv_struct_t))) || + NULL==(priv->src2dst=H5MM_malloc(src->u.compnd.nmembs * + sizeof(intn))) || + NULL==(priv->src_memb_id=H5MM_malloc(src->u.compnd.nmembs * + sizeof(hid_t))) || + NULL==(priv->dst_memb_id=H5MM_malloc(dst->u.compnd.nmembs * + sizeof(hid_t))) || + NULL==(priv->memb_nelmts=H5MM_malloc(src->u.compnd.nmembs * + sizeof(size_t)))) { + HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + src2dst = priv->src2dst; + + /* + * Insure that members are sorted. + */ + H5T_sort_value(src, NULL); + H5T_sort_value(dst, NULL); + + /* + * Build a mapping from source member number to destination member + * number. If some source member is not a destination member then that + * mapping element will be negative. Also create atoms for each + * source and destination member data type so we can look up the + * member data type conversion functions later. + */ + for (i=0; i<src->u.compnd.nmembs; i++) { + src2dst[i] = -1; + for (j=0; j<dst->u.compnd.nmembs; j++) { + if (!HDstrcmp (src->u.compnd.memb[i].name, + dst->u.compnd.memb[j].name)) { + src2dst[i] = j; + break; + } + } + if (src2dst[i]>=0) { + type = H5T_copy (src->u.compnd.memb[i].type, H5T_COPY_ALL); + tid = H5I_register (H5I_DATATYPE, type); + assert (tid>=0); + priv->src_memb_id[i] = tid; + + type = H5T_copy (dst->u.compnd.memb[src2dst[i]].type, + H5T_COPY_ALL); + tid = H5I_register (H5I_DATATYPE, type); + assert (tid>=0); + priv->dst_memb_id[src2dst[i]] = tid; + } + } + + /* + * Those members which are in both the source and destination must be + * the same size and shape arrays. + */ + for (i=0; i<src->u.compnd.nmembs; i++) { + if (src2dst[i]>=0) { + H5T_cmemb_t *src_memb = src->u.compnd.memb + i; + H5T_cmemb_t *dst_memb = dst->u.compnd.memb + src2dst[i]; + if (src_memb->ndims != dst_memb->ndims) { + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "source and dest members have incompatible " + "size or shape"); + } + for (j=0; j<src_memb->ndims; j++) { + if (src_memb->dim[j] != dst_memb->dim[j]) { + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "source and dest members have " + "incompatible size or shape"); + } #ifndef LATER - /* Their permutation vectors must be equal */ - if (src_memb->perm[j]!=dst_memb->perm[j]) { - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "member permutations must be equal"); - } + /* Their permutation vectors must be equal */ + if (src_memb->perm[j]!=dst_memb->perm[j]) { + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "member permutations must be equal"); + } #endif - } - } - } + } + } + } - /* Calculate number of elements of each member */ - for (i=0; i<src->u.compnd.nmembs; i++) { - priv->memb_nelmts[i] = 1; - for (j=0; j<src->u.compnd.memb[i].ndims; j++) { - priv->memb_nelmts[i] *= src->u.compnd.memb[i].dim[j]; - } - } + /* Calculate number of elements of each member */ + for (i=0; i<src->u.compnd.nmembs; i++) { + priv->memb_nelmts[i] = 1; + for (j=0; j<src->u.compnd.memb[i].ndims; j++) { + priv->memb_nelmts[i] *= src->u.compnd.memb[i].dim[j]; + } + } } /* @@ -888,27 +888,26 @@ H5T_conv_struct_init (H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata) H5MM_xfree(priv->memb_path); if (NULL==(priv->memb_path=H5MM_malloc(src->u.compnd.nmembs * sizeof(H5T_path_t*)))) { - HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, + HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); } for (i=0; i<src->u.compnd.nmembs; i++) { - if (src2dst[i]>=0) { - H5T_path_t *tpath; - tpath = H5T_path_find(src->u.compnd.memb[i].type, - dst->u.compnd.memb[src2dst[i]].type, - NULL, NULL); - if (NULL==(priv->memb_path[i] = tpath)) { - H5MM_xfree(priv->src2dst); - H5MM_xfree(priv->src_memb_id); - H5MM_xfree(priv->dst_memb_id); - H5MM_xfree(priv->memb_path); - H5MM_xfree(priv->memb_nelmts); - cdata->priv = priv = H5MM_xfree (priv); - HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "unable to convert member data type"); - } - } + if (src2dst[i]>=0) { + H5T_path_t *tpath = H5T_path_find(src->u.compnd.memb[i].type, + dst->u.compnd.memb[src2dst[i]].type, NULL, NULL); + + if (NULL==(priv->memb_path[i] = tpath)) { + H5MM_xfree(priv->src2dst); + H5MM_xfree(priv->src_memb_id); + H5MM_xfree(priv->dst_memb_id); + H5MM_xfree(priv->memb_path); + H5MM_xfree(priv->memb_nelmts); + cdata->priv = priv = H5MM_xfree (priv); + HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "unable to convert member data type"); + } + } } cdata->need_bkg = H5T_BKG_TEMP; @@ -968,166 +967,165 @@ H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, FUNC_ENTER (H5T_conv_struct, FAIL); switch (cdata->command) { - case H5T_CONV_INIT: - /* - * First, determine if this conversion function applies to the - * conversion path SRC_ID-->DST_ID. If not, return failure; - * otherwise initialize the `priv' field of `cdata' with information - * that remains (almost) constant for this conversion path. - */ - if (H5I_DATATYPE != H5I_get_type(src_id) || - NULL == (src = H5I_object(src_id)) || - H5I_DATATYPE != H5I_get_type(dst_id) || - NULL == (dst = H5I_object(dst_id))) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); - } - assert (H5T_COMPOUND==src->type); - assert (H5T_COMPOUND==dst->type); + case H5T_CONV_INIT: + /* + * First, determine if this conversion function applies to the + * conversion path SRC_ID-->DST_ID. If not, return failure; + * otherwise initialize the `priv' field of `cdata' with information + * that remains (almost) constant for this conversion path. + */ + if (H5I_DATATYPE != H5I_get_type(src_id) || + NULL == (src = H5I_object(src_id)) || + H5I_DATATYPE != H5I_get_type(dst_id) || + NULL == (dst = H5I_object(dst_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + assert (H5T_COMPOUND==src->type); + assert (H5T_COMPOUND==dst->type); - if (H5T_conv_struct_init (src, dst, cdata)<0) { - HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to initialize conversion data"); - } - break; + if (H5T_conv_struct_init (src, dst, cdata)<0) { + HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to initialize conversion data"); + } + break; - case H5T_CONV_FREE: - /* - * Free the private conversion data. - */ - H5MM_xfree(priv->src2dst); - H5MM_xfree(priv->src_memb_id); - H5MM_xfree(priv->dst_memb_id); - H5MM_xfree(priv->memb_path); - H5MM_xfree(priv->memb_nelmts); - cdata->priv = priv = H5MM_xfree (priv); - break; + case H5T_CONV_FREE: + /* + * Free the private conversion data. + */ + H5MM_xfree(priv->src2dst); + H5MM_xfree(priv->src_memb_id); + H5MM_xfree(priv->dst_memb_id); + H5MM_xfree(priv->memb_path); + H5MM_xfree(priv->memb_nelmts); + cdata->priv = priv = H5MM_xfree (priv); + break; - case H5T_CONV_CONV: - /* - * Conversion. - */ - if (H5I_DATATYPE != H5I_get_type(src_id) || - NULL == (src = H5I_object(src_id)) || - H5I_DATATYPE != H5I_get_type(dst_id) || - NULL == (dst = H5I_object(dst_id))) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); - } - assert (priv); - assert (bkg && cdata->need_bkg>=H5T_BKG_TEMP); + case H5T_CONV_CONV: + /* + * Conversion. + */ + if (H5I_DATATYPE != H5I_get_type(src_id) || + NULL == (src = H5I_object(src_id)) || + H5I_DATATYPE != H5I_get_type(dst_id) || + NULL == (dst = H5I_object(dst_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + assert (priv); + assert (bkg && cdata->need_bkg>=H5T_BKG_TEMP); - if (cdata->recalc && - H5T_conv_struct_init (src, dst, cdata)<0) { - HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to initialize conversion data"); - } + if (cdata->recalc && H5T_conv_struct_init (src, dst, cdata)<0) { + HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to initialize conversion data"); + } - /* - * Insure that members are sorted. - */ - H5T_sort_value(src, NULL); - H5T_sort_value(dst, NULL); - src2dst = priv->src2dst; + /* + * Insure that members are sorted. + */ + H5T_sort_value(src, NULL); + H5T_sort_value(dst, NULL); + src2dst = priv->src2dst; - /* - * Direction of conversion. - */ - if (stride) { - src_delta = dst_delta = stride; - } else if (dst->size <= src->size) { - src_delta = src->size; - dst_delta = dst->size; - } else { - src_delta = -(src->size); - dst_delta = -(dst->size); - buf += (nelmts-1) * src->size; - bkg += (nelmts-1) * dst->size; - } + /* + * Direction of conversion. + */ + if (stride) { + src_delta = dst_delta = stride; + } else if (dst->size <= src->size) { + src_delta = src->size; + dst_delta = dst->size; + } else { + src_delta = -(src->size); + dst_delta = -(dst->size); + buf += (nelmts-1) * src->size; + bkg += (nelmts-1) * dst->size; + } - for (elmtno=0; elmtno<nelmts; elmtno++) { - /* - * For each source member which will be present in the - * destination, convert the member to the destination type unless - * it is larger than the source type. Then move the member to the - * left-most unoccupied position in the buffer. This makes the - * data point as small as possible with all the free space on the - * right side. - */ - for (i=0, offset=0; i<src->u.compnd.nmembs; i++) { - if (src2dst[i]<0) continue; - src_memb = src->u.compnd.memb + i; - dst_memb = dst->u.compnd.memb + src2dst[i]; - - if (dst_memb->size <= src_memb->size) { - if (H5T_convert(priv->memb_path[i], - priv->src_memb_id[i], - priv->dst_memb_id[src2dst[i]], - priv->memb_nelmts[i], - 0, /*no striding*/ - buf + src_memb->offset, - bkg + dst_memb->offset,dset_xfer_plist)<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to convert compound data type " - "member"); - } - HDmemmove (buf+offset, buf+src_memb->offset, - dst_memb->size); - offset += dst_memb->size; - } else { - HDmemmove (buf+offset, buf+src_memb->offset, - src_memb->size); - offset += src_memb->size; - } - } + for (elmtno=0; elmtno<nelmts; elmtno++) { + /* + * For each source member which will be present in the + * destination, convert the member to the destination type unless + * it is larger than the source type. Then move the member to the + * left-most unoccupied position in the buffer. This makes the + * data point as small as possible with all the free space on the + * right side. + */ + for (i=0, offset=0; i<src->u.compnd.nmembs; i++) { + if (src2dst[i]<0) + continue; + src_memb = src->u.compnd.memb + i; + dst_memb = dst->u.compnd.memb + src2dst[i]; + + if (dst_memb->size <= src_memb->size) { + if (H5T_convert(priv->memb_path[i], + priv->src_memb_id[i], + priv->dst_memb_id[src2dst[i]], + priv->memb_nelmts[i], + 0, /*no striding*/ + buf + src_memb->offset, + bkg + dst_memb->offset,dset_xfer_plist)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to convert compound data type member"); + } + HDmemmove (buf+offset, buf+src_memb->offset, + dst_memb->size); + offset += dst_memb->size; + } else { + HDmemmove (buf+offset, buf+src_memb->offset, + src_memb->size); + offset += src_memb->size; + } + } - /* - * For each source member which will be present in the - * destination, convert the member to the destination type if it - * is larger than the source type (that is, has not been converted - * yet). Then copy the member to the destination offset in the - * background buffer. - */ - for (i=src->u.compnd.nmembs-1; i>=0; --i) { - if (src2dst[i]<0) continue; - src_memb = src->u.compnd.memb + i; - dst_memb = dst->u.compnd.memb + src2dst[i]; - - if (dst_memb->size > src_memb->size) { - offset -= src_memb->size; - if (H5T_convert(priv->memb_path[i], - priv->src_memb_id[i], - priv->dst_memb_id[src2dst[i]], - priv->memb_nelmts[i], - 0, /*no striding*/ - buf+offset, bkg+dst_memb->offset,dset_xfer_plist)<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to convert compound data type " - "member"); - } - } else { - offset -= dst_memb->size; - } - HDmemmove (bkg+dst_memb->offset, buf+offset, dst_memb->size); - } - assert (0==offset); + /* + * For each source member which will be present in the + * destination, convert the member to the destination type if it + * is larger than the source type (that is, has not been converted + * yet). Then copy the member to the destination offset in the + * background buffer. + */ + for (i=src->u.compnd.nmembs-1; i>=0; --i) { + if (src2dst[i]<0) + continue; + src_memb = src->u.compnd.memb + i; + dst_memb = dst->u.compnd.memb + src2dst[i]; + + if (dst_memb->size > src_memb->size) { + offset -= src_memb->size; + if (H5T_convert(priv->memb_path[i], + priv->src_memb_id[i], + priv->dst_memb_id[src2dst[i]], + priv->memb_nelmts[i], + 0, /*no striding*/ + buf+offset, bkg+dst_memb->offset,dset_xfer_plist)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to convert compound data type member"); + } + } else { + offset -= dst_memb->size; + } + HDmemmove (bkg+dst_memb->offset, buf+offset, dst_memb->size); + } + assert (0==offset); - /* - * Update buf and background. - */ - buf += src_delta; - bkg += dst_delta; - } + /* + * Update buf and background. + */ + buf += src_delta; + bkg += dst_delta; + } - /* - * Copy the background buffer back into the in-place conversion - * buffer. - */ - HDmemcpy (_buf, _bkg, nelmts*dst->size); - break; + /* + * Copy the background buffer back into the in-place conversion + * buffer. + */ + HDmemcpy (_buf, _bkg, nelmts*dst->size); + break; - default: - /* Some other command we don't know about yet.*/ - HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "unknown conversion command"); + default: + /* Some other command we don't know about yet.*/ + HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "unknown conversion command"); } FUNC_LEAVE (SUCCEED); @@ -1202,214 +1200,214 @@ H5T_conv_struct_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, FUNC_ENTER (H5T_conv_struct_opt, FAIL); switch (cdata->command) { - case H5T_CONV_INIT: - /* - * First, determine if this conversion function applies to the - * conversion path SRC_ID-->DST_ID. If not, return failure; - * otherwise initialize the `priv' field of `cdata' with information - * that remains (almost) constant for this conversion path. - */ - if (H5I_DATATYPE != H5I_get_type(src_id) || - NULL == (src = H5I_object(src_id)) || - H5I_DATATYPE != H5I_get_type(dst_id) || - NULL == (dst = H5I_object(dst_id))) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); - } - assert (H5T_COMPOUND==src->type); - assert (H5T_COMPOUND==dst->type); + case H5T_CONV_INIT: + /* + * First, determine if this conversion function applies to the + * conversion path SRC_ID-->DST_ID. If not, return failure; + * otherwise initialize the `priv' field of `cdata' with information + * that remains (almost) constant for this conversion path. + */ + if (H5I_DATATYPE != H5I_get_type(src_id) || + NULL == (src = H5I_object(src_id)) || + H5I_DATATYPE != H5I_get_type(dst_id) || + NULL == (dst = H5I_object(dst_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + assert (H5T_COMPOUND==src->type); + assert (H5T_COMPOUND==dst->type); - /* Initialize data which is relatively constant */ - if (H5T_conv_struct_init (src, dst, cdata)<0) { - HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to initialize conversion data"); - } - priv = (H5T_conv_struct_t *)(cdata->priv); - src2dst = priv->src2dst; - - /* - * If the destination type is not larger than the source type then - * this conversion function is guaranteed to work (provided all - * members can be converted also). Otherwise the determination is - * quite a bit more complicated. Essentially we have to make sure - * that there is always room in the source buffer to do the - * conversion of a member in place. This is basically the same pair - * of loops as in the actual conversion except it checks that there - * is room for each conversion instead of actually doing anything. - */ - if (dst->size > src->size) { - for (i=0, offset=0; i<src->u.compnd.nmembs; i++) { - if (src2dst[i]<0) continue; - src_memb = src->u.compnd.memb + i; - dst_memb = dst->u.compnd.memb + src2dst[i]; - src_memb_size = src_memb->size / priv->memb_nelmts[i]; - dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; - for (j=0; j<(intn)(priv->memb_nelmts[i]); j++) { - if (dst_memb_size > src_memb_size) { - offset += src_memb_size; - } - } - } - for (i=src->u.compnd.nmembs-1; i>=0; --i) { - if (src2dst[i]<0) continue; - src_memb = src->u.compnd.memb + i; - dst_memb = dst->u.compnd.memb + src2dst[i]; - src_memb_size = src_memb->size / priv->memb_nelmts[i]; - dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; - - for (j=priv->memb_nelmts[i]-1; j>=0; --j) { - if (dst_memb_size > src_memb_size) { - offset -= src_memb_size; - if (dst_memb_size > src->size-offset) { - H5MM_xfree(priv->src2dst); - H5MM_xfree(priv->src_memb_id); - H5MM_xfree(priv->dst_memb_id); - H5MM_xfree(priv->memb_path); - H5MM_xfree(priv->memb_nelmts); - cdata->priv = priv = H5MM_xfree (priv); - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "convertion is unsupported by this " - "function"); - } - } - } - } - } - break; + /* Initialize data which is relatively constant */ + if (H5T_conv_struct_init (src, dst, cdata)<0) { + HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to initialize conversion data"); + } + priv = (H5T_conv_struct_t *)(cdata->priv); + src2dst = priv->src2dst; + + /* + * If the destination type is not larger than the source type then + * this conversion function is guaranteed to work (provided all + * members can be converted also). Otherwise the determination is + * quite a bit more complicated. Essentially we have to make sure + * that there is always room in the source buffer to do the + * conversion of a member in place. This is basically the same pair + * of loops as in the actual conversion except it checks that there + * is room for each conversion instead of actually doing anything. + */ + if (dst->size > src->size) { + for (i=0, offset=0; i<src->u.compnd.nmembs; i++) { + if (src2dst[i]<0) + continue; + src_memb = src->u.compnd.memb + i; + dst_memb = dst->u.compnd.memb + src2dst[i]; + src_memb_size = src_memb->size / priv->memb_nelmts[i]; + dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; + for (j=0; j<(intn)(priv->memb_nelmts[i]); j++) { + if (dst_memb_size > src_memb_size) + offset += src_memb_size; + } + } + for (i=src->u.compnd.nmembs-1; i>=0; --i) { + if (src2dst[i]<0) + continue; + src_memb = src->u.compnd.memb + i; + dst_memb = dst->u.compnd.memb + src2dst[i]; + src_memb_size = src_memb->size / priv->memb_nelmts[i]; + dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; + + for (j=(intn)(priv->memb_nelmts[i]-1); j>=0; --j) { + if (dst_memb_size > src_memb_size) { + offset -= src_memb_size; + if (dst_memb_size > src->size-offset) { + H5MM_xfree(priv->src2dst); + H5MM_xfree(priv->src_memb_id); + H5MM_xfree(priv->dst_memb_id); + H5MM_xfree(priv->memb_path); + H5MM_xfree(priv->memb_nelmts); + cdata->priv = priv = H5MM_xfree (priv); + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "convertion is unsupported by this " + "function"); + } + } + } + } + } + break; - case H5T_CONV_FREE: - /* - * Free the private conversion data. - */ - priv = (H5T_conv_struct_t *)(cdata->priv); - H5MM_xfree(priv->src2dst); - H5MM_xfree(priv->src_memb_id); - H5MM_xfree(priv->dst_memb_id); - H5MM_xfree(priv->memb_path); - H5MM_xfree(priv->memb_nelmts); - cdata->priv = priv = H5MM_xfree (priv); - break; + case H5T_CONV_FREE: + /* + * Free the private conversion data. + */ + priv = (H5T_conv_struct_t *)(cdata->priv); + H5MM_xfree(priv->src2dst); + H5MM_xfree(priv->src_memb_id); + H5MM_xfree(priv->dst_memb_id); + H5MM_xfree(priv->memb_path); + H5MM_xfree(priv->memb_nelmts); + cdata->priv = priv = H5MM_xfree (priv); + break; - case H5T_CONV_CONV: - /* - * Conversion. - */ - if (H5I_DATATYPE != H5I_get_type(src_id) || - NULL == (src = H5I_object(src_id)) || - H5I_DATATYPE != H5I_get_type(dst_id) || - NULL == (dst = H5I_object(dst_id))) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); - } + case H5T_CONV_CONV: + /* + * Conversion. + */ + if (H5I_DATATYPE != H5I_get_type(src_id) || + NULL == (src = H5I_object(src_id)) || + H5I_DATATYPE != H5I_get_type(dst_id) || + NULL == (dst = H5I_object(dst_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } - /* Update cached data if necessary */ - if (cdata->recalc && - H5T_conv_struct_init (src, dst, cdata)<0) { - HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to initialize conversion data"); - } - priv = (H5T_conv_struct_t *)(cdata->priv); - src2dst = priv->src2dst; - assert(priv); - assert(bkg && cdata->need_bkg>=H5T_BKG_TEMP); + /* Update cached data if necessary */ + if (cdata->recalc && H5T_conv_struct_init (src, dst, cdata)<0) { + HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to initialize conversion data"); + } + priv = (H5T_conv_struct_t *)(cdata->priv); + src2dst = priv->src2dst; + assert(priv); + assert(bkg && cdata->need_bkg>=H5T_BKG_TEMP); - /* - * Insure that members are sorted. - */ - H5T_sort_value(src, NULL); - H5T_sort_value(dst, NULL); + /* + * Insure that members are sorted. + */ + H5T_sort_value(src, NULL); + H5T_sort_value(dst, NULL); - /* - * For each member where the destination is not larger than the - * source, stride through all the elements converting only that member - * in each element and then copying the element to its final - * destination in the bkg buffer. Otherwise move the element as far - * left as possible in the buffer. - */ - for (i=0, offset=0; i<src->u.compnd.nmembs; i++) { - if (src2dst[i]<0) continue; - src_memb = src->u.compnd.memb + i; - dst_memb = dst->u.compnd.memb + src2dst[i]; - src_memb_size = src_memb->size / priv->memb_nelmts[i]; - dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; - - for (j=0; j<(intn)(priv->memb_nelmts[i]); j++) { - if (dst_memb_size <= src_memb_size) { - xbuf = buf + src_memb->offset + j*src_memb_size; - xbkg = bkg + dst_memb->offset + j*dst_memb_size; - if (H5T_convert(priv->memb_path[i], - priv->src_memb_id[i], - priv->dst_memb_id[src2dst[i]], - nelmts, - stride?stride:src->size, - xbuf, xbkg,dset_xfer_plist)<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to convert compound data " - "type member"); - } - for (elmtno=0; elmtno<nelmts; elmtno++) { - HDmemmove(xbkg, xbuf, dst_memb_size); - xbuf += stride ? stride : src->size; - xbkg += stride ? stride : dst->size; - } - } else { - for (xbuf=buf, elmtno=0; elmtno<nelmts; elmtno++) { - HDmemmove(xbuf+offset, - xbuf+src_memb->offset+j*src_memb_size, - src_memb_size); - xbuf += stride ? stride : src->size; - } - offset += src_memb_size; - } - } - } + /* + * For each member where the destination is not larger than the + * source, stride through all the elements converting only that member + * in each element and then copying the element to its final + * destination in the bkg buffer. Otherwise move the element as far + * left as possible in the buffer. + */ + for (i=0, offset=0; i<src->u.compnd.nmembs; i++) { + if (src2dst[i]<0) + continue; + src_memb = src->u.compnd.memb + i; + dst_memb = dst->u.compnd.memb + src2dst[i]; + src_memb_size = src_memb->size / priv->memb_nelmts[i]; + dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; + + for (j=0; j<(intn)(priv->memb_nelmts[i]); j++) { + if (dst_memb_size <= src_memb_size) { + xbuf = buf + src_memb->offset + j*src_memb_size; + xbkg = bkg + dst_memb->offset + j*dst_memb_size; + if (H5T_convert(priv->memb_path[i], + priv->src_memb_id[i], + priv->dst_memb_id[src2dst[i]], + nelmts, + stride?stride:src->size, + xbuf, xbkg,dset_xfer_plist)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to convert compound data " + "type member"); + } + for (elmtno=0; elmtno<nelmts; elmtno++) { + HDmemmove(xbkg, xbuf, dst_memb_size); + xbuf += stride ? stride : src->size; + xbkg += stride ? stride : dst->size; + } + } else { + for (xbuf=buf, elmtno=0; elmtno<nelmts; elmtno++) { + HDmemmove(xbuf+offset, + xbuf+src_memb->offset+j*src_memb_size, src_memb_size); + xbuf += stride ? stride : src->size; + } + offset += src_memb_size; + } + } + } - /* - * Work from right to left, converting those members that weren't - * converted in the previous loop (those members where the destination - * is larger than the source) and them to their final position in the - * bkg buffer. - */ - for (i=src->u.compnd.nmembs-1; i>=0; --i) { - if (src2dst[i]<0) continue; - src_memb = src->u.compnd.memb + i; - dst_memb = dst->u.compnd.memb + src2dst[i]; - src_memb_size = src_memb->size / priv->memb_nelmts[i]; - dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; - - for (j=priv->memb_nelmts[i]-1; j>=0; --j) { - if (dst_memb_size > src_memb_size) { - offset -= src_memb_size; - xbuf = buf + offset; - xbkg = bkg + dst_memb->offset + j*dst_memb_size; - if (H5T_convert(priv->memb_path[i], - priv->src_memb_id[i], - priv->dst_memb_id[src2dst[i]], - nelmts, stride?stride:src->size, - xbuf, xbkg, dset_xfer_plist)<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to convert compound data " - "type member"); - } - for (elmtno=0; elmtno<nelmts; elmtno++) { - HDmemmove(xbkg, xbuf, dst_memb_size); - xbuf += stride ? stride : src->size; - xbkg += stride ? stride : dst->size; - } - } - } - } + /* + * Work from right to left, converting those members that weren't + * converted in the previous loop (those members where the destination + * is larger than the source) and them to their final position in the + * bkg buffer. + */ + for (i=src->u.compnd.nmembs-1; i>=0; --i) { + if (src2dst[i]<0) + continue; + src_memb = src->u.compnd.memb + i; + dst_memb = dst->u.compnd.memb + src2dst[i]; + src_memb_size = src_memb->size / priv->memb_nelmts[i]; + dst_memb_size = dst_memb->size / priv->memb_nelmts[i]; + + for (j=(intn)(priv->memb_nelmts[i]-1); j>=0; --j) { + if (dst_memb_size > src_memb_size) { + offset -= src_memb_size; + xbuf = buf + offset; + xbkg = bkg + dst_memb->offset + j*dst_memb_size; + if (H5T_convert(priv->memb_path[i], + priv->src_memb_id[i], + priv->dst_memb_id[src2dst[i]], + nelmts, stride?stride:src->size, + xbuf, xbkg, dset_xfer_plist)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to convert compound data type member"); + } + for (elmtno=0; elmtno<nelmts; elmtno++) { + HDmemmove(xbkg, xbuf, dst_memb_size); + xbuf += stride ? stride : src->size; + xbkg += stride ? stride : dst->size; + } + } + } + } - /* Move background into buffer */ - for (xbuf=buf, xbkg=bkg, elmtno=0; elmtno<nelmts; elmtno++) { - HDmemmove(xbuf, xbkg, dst->size); - xbuf += stride ? stride : dst->size; - xbkg += stride ? stride : dst->size; - } - break; + /* Move background into buffer */ + for (xbuf=buf, xbkg=bkg, elmtno=0; elmtno<nelmts; elmtno++) { + HDmemmove(xbuf, xbkg, dst->size); + xbuf += stride ? stride : dst->size; + xbkg += stride ? stride : dst->size; + } + break; - default: - /* Some other command we don't know about yet.*/ - HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "unknown conversion command"); + default: + /* Some other command we don't know about yet.*/ + HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "unknown conversion command"); } FUNC_LEAVE (SUCCEED); @@ -1654,7 +1652,7 @@ H5T_conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * Direction of conversion. */ if (stride) { - src_delta = dst_delta = stride; + src_delta = dst_delta = (intn)stride; s = d = buf; } else if (dst->size <= src->size) { src_delta = (int)src->size; /*overflow shouldn't be possible*/ |