From 4ba8f63b57a6c9df10c12dfb8be23bcca6cd749d Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 19 Oct 2000 12:41:30 -0500 Subject: [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) --- src/H5T.c | 30 +++++++++++++++++++++++------- 1 file 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; iu.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; ju.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; -- cgit v0.12