summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2000-10-19 17:41:30 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2000-10-19 17:41:30 (GMT)
commit4ba8f63b57a6c9df10c12dfb8be23bcca6cd749d (patch)
treeaed08bf971dd2f3ba18516c8e0e90bbfe821484f /src/H5T.c
parent76443fe47725a40a8671aad237bd3cde9190ed67 (diff)
downloadhdf5-4ba8f63b57a6c9df10c12dfb8be23bcca6cd749d.zip
hdf5-4ba8f63b57a6c9df10c12dfb8be23bcca6cd749d.tar.gz
hdf5-4ba8f63b57a6c9df10c12dfb8be23bcca6cd749d.tar.bz2
[svn-r2702] Purpose:
Code cleanup Description: There's been a compiler warning about modifying a 'const' object in the H5T_copy routine for several years now, which a few users have reported. Solution: Removed call to sort the old datatype (the const object) and changed the code to work with unsorted datatypes. Platforms tested: FreeBSD 4.1.1 (hawkwind)
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 1562666..b15f1d9 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -4873,13 +4873,13 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
"memory allocation failed");
}
- /* Sort the fields based on offsets */
- H5T_sort_value((H5T_t *)old_dt,NULL);
-
HDmemcpy(new_dt->u.compnd.memb, old_dt->u.compnd.memb,
new_dt->u.compnd.nmembs * sizeof(H5T_cmemb_t));
for (i=0; i<new_dt->u.compnd.nmembs; i++) {
+ intn j;
+ intn old_match;
+
s = new_dt->u.compnd.memb[i].name;
new_dt->u.compnd.memb[i].name = H5MM_xstrdup(s);
tmp = H5T_copy (old_dt->u.compnd.memb[i].type, method);
@@ -4888,14 +4888,30 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
/* Apply the accumulated size change to the offset of the field */
new_dt->u.compnd.memb[i].offset += accum_change;
+ if(old_dt->u.compnd.sorted != H5T_SORT_VALUE) {
+ for (old_match=-1, j=0; j<old_dt->u.compnd.nmembs; j++) {
+ if(!HDstrcmp(new_dt->u.compnd.memb[i].name,old_dt->u.compnd.memb[j].name)) {
+ old_match=j;
+ break;
+ } /* end if */
+ } /* end for */
+
+ /* check if we couldn't find a match */
+ if(old_match<0)
+ HRETURN_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "fields in datatype corrupted");
+ } /* end if */
+ else {
+ old_match=i;
+ } /* end else */
+
/* If the field changed size, add that change to the accumulated size change */
- if(new_dt->u.compnd.memb[i].type->size != old_dt->u.compnd.memb[i].type->size) {
+ if(new_dt->u.compnd.memb[i].type->size != old_dt->u.compnd.memb[old_match].type->size) {
/* Adjust the size of the member */
- new_dt->u.compnd.memb[i].size = (old_dt->u.compnd.memb[i].size*tmp->size)/old_dt->u.compnd.memb[i].type->size;
+ new_dt->u.compnd.memb[i].size = (old_dt->u.compnd.memb[old_match].size*tmp->size)/old_dt->u.compnd.memb[old_match].type->size;
- accum_change += (new_dt->u.compnd.memb[i].type->size - old_dt->u.compnd.memb[i].type->size);
+ accum_change += (new_dt->u.compnd.memb[i].type->size - old_dt->u.compnd.memb[old_match].type->size);
} /* end if */
- }
+ } /* end for */
/* Apply the accumulated size change to the size of the compound struct */
new_dt->size += accum_change;