diff options
Diffstat (limited to 'src/H5Tvlen.c')
-rw-r--r-- | src/H5Tvlen.c | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index f40b075..467327e 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -67,8 +67,9 @@ static H5T_vlen_alloc_info_t H5T_vlen_def_vl_alloc_info ={ H5D_XFER_VLEN_FREE_INFO_DEF }; -/* Declare extern the free list for H5T_t's */ +/* Declare extern the free lists for H5T_t's and H5T_shared_t's */ H5FL_EXTERN(H5T_t); +H5FL_EXTERN(H5T_shared_t); /*-------------------------------------------------------------------------- @@ -168,18 +169,22 @@ H5T_vlen_create(const H5T_t *base) /* Build new type */ if (NULL==(dt = H5FL_CALLOC(H5T_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) { + H5FL_FREE(H5T_t, dt); + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,"memory allocation failed") + } dt->ent.header = HADDR_UNDEF; - dt->type = H5T_VLEN; + dt->shared->type = H5T_VLEN; /* * Force conversions (i.e. memory to memory conversions should duplicate * data, not point to the same VL sequences) */ - dt->force_conv = TRUE; - dt->parent = H5T_copy(base, H5T_COPY_ALL); + dt->shared->force_conv = TRUE; + dt->shared->parent = H5T_copy(base, H5T_COPY_ALL); /* This is a sequence, not a string */ - dt->u.vlen.type = H5T_VLEN_SEQUENCE; + dt->shared->u.vlen.type = H5T_VLEN_SEQUENCE; /* Set up VL information */ if (H5T_set_loc(dt, NULL, H5T_LOC_MEMORY)<0) @@ -223,7 +228,7 @@ H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) assert(loc>H5T_LOC_BADLOC && loc<H5T_LOC_MAXLOC); /* Only change the location if it's different */ - if(loc!=dt->u.vlen.loc) { + if(loc!=dt->shared->u.vlen.loc) { /* Indicate that the location changed */ ret_value=TRUE; @@ -232,62 +237,62 @@ H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) assert(f==NULL); /* Mark this type as being stored in memory */ - dt->u.vlen.loc=H5T_LOC_MEMORY; + dt->shared->u.vlen.loc=H5T_LOC_MEMORY; - if(dt->u.vlen.type==H5T_VLEN_SEQUENCE) { + if(dt->shared->u.vlen.type==H5T_VLEN_SEQUENCE) { /* size in memory, disk size is different */ - dt->size = sizeof(hvl_t); + dt->shared->size = sizeof(hvl_t); /* Set up the function pointers to access the VL sequence in memory */ - dt->u.vlen.getlen=H5T_vlen_seq_mem_getlen; - dt->u.vlen.getptr=H5T_vlen_seq_mem_getptr; - dt->u.vlen.isnull=H5T_vlen_seq_mem_isnull; - dt->u.vlen.read=H5T_vlen_seq_mem_read; - dt->u.vlen.write=H5T_vlen_seq_mem_write; - dt->u.vlen.setnull=H5T_vlen_seq_mem_setnull; - } else if(dt->u.vlen.type==H5T_VLEN_STRING) { + dt->shared->u.vlen.getlen=H5T_vlen_seq_mem_getlen; + dt->shared->u.vlen.getptr=H5T_vlen_seq_mem_getptr; + dt->shared->u.vlen.isnull=H5T_vlen_seq_mem_isnull; + dt->shared->u.vlen.read=H5T_vlen_seq_mem_read; + dt->shared->u.vlen.write=H5T_vlen_seq_mem_write; + dt->shared->u.vlen.setnull=H5T_vlen_seq_mem_setnull; + } else if(dt->shared->u.vlen.type==H5T_VLEN_STRING) { /* size in memory, disk size is different */ - dt->size = sizeof(char *); + dt->shared->size = sizeof(char *); /* Set up the function pointers to access the VL string in memory */ - dt->u.vlen.getlen=H5T_vlen_str_mem_getlen; - dt->u.vlen.getptr=H5T_vlen_str_mem_getptr; - dt->u.vlen.isnull=H5T_vlen_str_mem_isnull; - dt->u.vlen.read=H5T_vlen_str_mem_read; - dt->u.vlen.write=H5T_vlen_str_mem_write; - dt->u.vlen.setnull=H5T_vlen_str_mem_setnull; + dt->shared->u.vlen.getlen=H5T_vlen_str_mem_getlen; + dt->shared->u.vlen.getptr=H5T_vlen_str_mem_getptr; + dt->shared->u.vlen.isnull=H5T_vlen_str_mem_isnull; + dt->shared->u.vlen.read=H5T_vlen_str_mem_read; + dt->shared->u.vlen.write=H5T_vlen_str_mem_write; + dt->shared->u.vlen.setnull=H5T_vlen_str_mem_setnull; } else { assert(0 && "Invalid VL type"); } /* Reset file ID (since this VL is in memory) */ - dt->u.vlen.f=NULL; + dt->shared->u.vlen.f=NULL; break; case H5T_LOC_DISK: /* Disk based VL datatype */ assert(f); /* Mark this type as being stored on disk */ - dt->u.vlen.loc=H5T_LOC_DISK; + dt->shared->u.vlen.loc=H5T_LOC_DISK; /* * Size of element on disk is 4 bytes for the length, plus the size * of an address in this file, plus 4 bytes for the size of a heap * ID. Memory size is different */ - dt->size = 4 + H5F_SIZEOF_ADDR(f) + 4; + dt->shared->size = 4 + H5F_SIZEOF_ADDR(f) + 4; /* Set up the function pointers to access the VL information on disk */ /* VL sequences and VL strings are stored identically on disk, so use the same functions */ - dt->u.vlen.getlen=H5T_vlen_disk_getlen; - dt->u.vlen.getptr=H5T_vlen_disk_getptr; - dt->u.vlen.isnull=H5T_vlen_disk_isnull; - dt->u.vlen.read=H5T_vlen_disk_read; - dt->u.vlen.write=H5T_vlen_disk_write; - dt->u.vlen.setnull=H5T_vlen_disk_setnull; + dt->shared->u.vlen.getlen=H5T_vlen_disk_getlen; + dt->shared->u.vlen.getptr=H5T_vlen_disk_getptr; + dt->shared->u.vlen.isnull=H5T_vlen_disk_isnull; + dt->shared->u.vlen.read=H5T_vlen_disk_read; + dt->shared->u.vlen.write=H5T_vlen_disk_write; + dt->shared->u.vlen.setnull=H5T_vlen_disk_setnull; /* Set file ID (since this VL is on disk) */ - dt->u.vlen.f=f; + dt->shared->u.vlen.f=f; break; default: @@ -1011,16 +1016,16 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi assert(dt); /* Check the datatype of this element */ - switch(dt->type) { + switch(dt->shared->type) { case H5T_ARRAY: /* Recurse on each element, if the array's base type is array, VL, enum or compound */ - if(H5T_IS_COMPLEX(dt->parent->type)) { + if(H5T_IS_COMPLEX(dt->shared->parent->shared->type)) { void *off; /* offset of field */ /* Calculate the offset member and recurse on it */ - for(i=0; i<dt->u.array.nelem; i++) { - off=((uint8_t *)elem)+i*(dt->parent->size); - if(H5T_vlen_reclaim_recurse(off,dt->parent,free_func,free_info)<0) + for(i=0; i<dt->shared->u.array.nelem; i++) { + off=((uint8_t *)elem)+i*(dt->shared->parent->shared->size); + if(H5T_vlen_reclaim_recurse(off,dt->shared->parent,free_func,free_info)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free array element") } /* end for */ } /* end if */ @@ -1028,14 +1033,14 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_COMPOUND: /* Check each field and recurse on VL, compound, enum or array ones */ - for (i=0; i<dt->u.compnd.nmembs; i++) { + for (i=0; i<dt->shared->u.compnd.nmembs; i++) { /* Recurse if it's VL, compound, enum or array */ - if(H5T_IS_COMPLEX(dt->u.compnd.memb[i].type->type)) { + if(H5T_IS_COMPLEX(dt->shared->u.compnd.memb[i].type->shared->type)) { void *off; /* offset of field */ /* Calculate the offset member and recurse on it */ - off=((uint8_t *)elem)+dt->u.compnd.memb[i].offset; - if(H5T_vlen_reclaim_recurse(off,dt->u.compnd.memb[i].type,free_func,free_info)<0) + off=((uint8_t *)elem)+dt->shared->u.compnd.memb[i].offset; + if(H5T_vlen_reclaim_recurse(off,dt->shared->u.compnd.memb[i].type,free_func,free_info)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free compound field") } /* end if */ } /* end for */ @@ -1043,19 +1048,19 @@ 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->u.vlen.type==H5T_VLEN_SEQUENCE) { + if(dt->shared->u.vlen.type==H5T_VLEN_SEQUENCE) { hvl_t *vl=(hvl_t *)elem; /* Temp. ptr to the vl info */ /* Check if there is anything actually in this sequence */ if(vl->len!=0) { /* Recurse if it's VL, array, enum or compound */ - if(H5T_IS_COMPLEX(dt->parent->type)) { + 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->parent->size; - if(H5T_vlen_reclaim_recurse(off,dt->parent,free_func,free_info)<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) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free VL element") vl->len--; } /* end while */ @@ -1067,7 +1072,7 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi else H5MM_xfree(vl->p); } /* end if */ - } else if(dt->u.vlen.type==H5T_VLEN_STRING) { + } else if(dt->shared->u.vlen.type==H5T_VLEN_STRING) { /* Free the VL string */ if(free_func!=NULL) (*free_func)(*(char **)elem,free_info); |