diff --git a/config/cmake/ConversionTests.c b/config/cmake/ConversionTests.c index 321d879..a2cf0e4 100644 --- a/config/cmake/ConversionTests.c +++ b/config/cmake/ConversionTests.c @@ -259,13 +259,13 @@ main () char *chp = "beefs"; char **chpp = malloc (2 * sizeof (char *)); - char **chpp2; + char * volatile *chpp2; hvl_t vl = { 12345, (void *) chp }; hvl_t *vlp; - hvl_t *vlp2; + hvl_t * volatile vlp2; memcpy ((void *) ((char *) chpp + 1), &chp, sizeof (char *)); - chpp2 = (char **) ((char *) chpp + 1); + chpp2 = (char * volatile *) (chpp + 1); if (strcmp (*chpp2, chp)) { free (chpp); return 1; @@ -274,7 +274,7 @@ main () vlp = malloc (2 * sizeof (hvl_t)); memcpy ((void *) ((char *) vlp + 1), &vl, sizeof (hvl_t)); - vlp2 = (hvl_t *) ((char *) vlp + 1); + vlp2 = (hvl_t * volatile) ((char *) vlp + 1); if (vlp2->len != vl.len || vlp2->p != vl.p) { free (vlp); return 1; diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index ba31cd1..7bbf451 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -1044,35 +1044,64 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_VLEN: /* Recurse on the VL information if it's VL, compound, enum or array, then free VL sequence */ if(dt->shared->u.vlen.type == H5T_VLEN_SEQUENCE) { + void *p; + size_t len; +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS hvl_t *vl = (hvl_t *)elem; /* Temp. ptr to the vl info */ + p = vl->p; + len = vl->len; +#else + hvl_t vl; /* The vl info */ + HDmemcpy(&vl, elem, sizeof(hvl_t)); + p = vl.p; + len = vl.len; +#endif /* Check if there is anything actually in this sequence */ - if(vl->len!=0) { + if(len!=0) { /* Recurse if it's VL, array, enum or compound */ if(H5T_IS_COMPLEX(dt->shared->parent->shared->type)) { void *off; /* offset of field */ /* Calculate the offset of each array element and recurse on it */ - while(vl->len > 0) { - off = ((uint8_t *)vl->p) + (vl->len - 1) * dt->shared->parent->shared->size; - if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) + while(len > 0) { + off = ((uint8_t *)p) + (len - 1) * dt->shared->parent->shared->size; + if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) { +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + vl->len = len; +#else + HDmemcpy(((uint8_t *)elem)+HOFFSET(hvl_t, len), &len, sizeof(size_t)); +#endif HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free VL element") - vl->len--; + } + len--; } /* end while */ +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + vl->len = 0; +#else + HDmemset(((uint8_t *)elem)+HOFFSET(hvl_t, len), 0, sizeof(size_t)); +#endif } /* end if */ /* Free the VL sequence */ if(free_func != NULL) - (*free_func)(vl->p, free_info); + (*free_func)(p, free_info); else - HDfree(vl->p); + HDfree(p); } /* end if */ } else if(dt->shared->u.vlen.type == H5T_VLEN_STRING) { /* Free the VL string */ +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + char *s=*(char **)elem; /* Pointer to the user's string information */ +#else + char *s; /* Pointer to the user's string information */ + HDmemcpy(&s, elem, sizeof(char *)); +#endif + if(free_func != NULL) - (*free_func)(*(char **)elem, free_info); + (*free_func)(s, free_info); else - HDfree(*(char **)elem); + HDfree(s); } else { HDassert(0 && "Invalid VL type"); } /* end else */