summaryrefslogtreecommitdiffstats
path: root/src/H5Tvlen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Tvlen.c')
-rw-r--r--src/H5Tvlen.c192
1 files changed, 157 insertions, 35 deletions
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c
index ea341db..c6cdd34 100644
--- a/src/H5Tvlen.c
+++ b/src/H5Tvlen.c
@@ -50,28 +50,40 @@ static herr_t H5T_vlen_reclaim_recurse(void *elem, H5T_t *dt, H5MM_free_t free_f
*-------------------------------------------------------------------------
*/
static herr_t
-H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_vlen_type_t loc)
+H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_vlen_loc_t loc)
{
FUNC_ENTER (H5T_vlen_set_loc, FAIL);
/* check parameters */
assert(dt);
- assert(loc>H5T_VLEN_BADTYPE && loc<H5T_VLEN_MAXTYPE);
+ assert(loc>H5T_VLEN_BADLOC && loc<H5T_VLEN_MAXLOC);
switch(loc) {
case H5T_VLEN_MEMORY: /* Memory based VL datatype */
assert(f==NULL);
/* Mark this type as being stored in memory */
- dt->u.vlen.type=H5T_VLEN_MEMORY;
-
- /* size in memory, disk size is different */
- dt->size = sizeof(hvl_t);
-
- /* Set up the function pointers to access the VL information (in memory) */
- dt->u.vlen.getlen=H5T_vlen_mem_getlen;
- dt->u.vlen.read=H5T_vlen_mem_read;
- dt->u.vlen.write=H5T_vlen_mem_write;
+ dt->u.vlen.loc=H5T_VLEN_MEMORY;
+
+ if(dt->u.vlen.type==H5T_VLEN_SEQUENCE) {
+ /* size in memory, disk size is different */
+ dt->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.read=H5T_vlen_seq_mem_read;
+ dt->u.vlen.write=H5T_vlen_seq_mem_write;
+ } else if(dt->u.vlen.type==H5T_VLEN_STRING) {
+ /* size in memory, disk size is different */
+ dt->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.read=H5T_vlen_str_mem_read;
+ dt->u.vlen.write=H5T_vlen_str_mem_write;
+ } else {
+ assert(0 && "Invalid VL type");
+ }
/* Reset file ID (since this VL is in memory) */
dt->u.vlen.f=NULL;
@@ -81,7 +93,7 @@ H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_vlen_type_t loc)
assert(f);
/* Mark this type as being stored on disk */
- dt->u.vlen.type=H5T_VLEN_DISK;
+ dt->u.vlen.loc=H5T_VLEN_DISK;
/*
* Size of element on disk is 4 bytes for the length, plus the size
@@ -90,7 +102,8 @@ H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_vlen_type_t loc)
*/
dt->size = 4 + H5F_SIZEOF_ADDR(f) + 4;
- /* Set up the function pointers to access the VL information (in memory) */
+ /* 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.read=H5T_vlen_disk_read;
dt->u.vlen.write=H5T_vlen_disk_write;
@@ -108,7 +121,7 @@ H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_vlen_type_t loc)
/*-------------------------------------------------------------------------
- * Function: H5T_vlen_mem_getlen
+ * Function: H5T_vlen_seq_mem_getlen
*
* Purpose: Retrieves the length of a memory based VL element.
*
@@ -121,12 +134,12 @@ H5T_vlen_set_loc(H5T_t *dt, H5F_t *f, H5T_vlen_type_t loc)
*
*-------------------------------------------------------------------------
*/
-hsize_t H5T_vlen_mem_getlen(H5F_t UNUSED *f, void *vl_addr)
+hssize_t H5T_vlen_seq_mem_getlen(H5F_t UNUSED *f, void *vl_addr)
{
hvl_t *vl=(hvl_t *)vl_addr; /* Pointer to the user's hvl_t information */
- hsize_t ret_value = FAIL; /*return value */
+ hssize_t ret_value = FAIL; /*return value */
- FUNC_ENTER (H5T_vlen_mem_getlen, FAIL);
+ FUNC_ENTER (H5T_vlen_seq_mem_getlen, FAIL);
/* check parameters */
assert(vl);
@@ -134,11 +147,11 @@ hsize_t H5T_vlen_mem_getlen(H5F_t UNUSED *f, void *vl_addr)
ret_value=vl->len;
FUNC_LEAVE (ret_value);
-} /* end H5T_vlen_mem_getlen() */
+} /* end H5T_vlen_seq_mem_getlen() */
/*-------------------------------------------------------------------------
- * Function: H5T_vlen_mem_read
+ * Function: H5T_vlen_seq_mem_read
*
* Purpose: "Reads" the memory based VL sequence into a buffer
*
@@ -151,11 +164,11 @@ hsize_t H5T_vlen_mem_getlen(H5F_t UNUSED *f, void *vl_addr)
*
*-------------------------------------------------------------------------
*/
-herr_t H5T_vlen_mem_read(H5F_t UNUSED *f, void *vl_addr, void *buf, size_t len)
+herr_t H5T_vlen_seq_mem_read(H5F_t UNUSED *f, void *vl_addr, void *buf, size_t len)
{
hvl_t *vl=(hvl_t *)vl_addr; /* Pointer to the user's hvl_t information */
- FUNC_ENTER (H5T_vlen_mem_read, FAIL);
+ FUNC_ENTER (H5T_vlen_seq_mem_read, FAIL);
/* check parameters */
assert(vl && vl->p);
@@ -164,11 +177,11 @@ herr_t H5T_vlen_mem_read(H5F_t UNUSED *f, void *vl_addr, void *buf, size_t len)
HDmemcpy(buf,vl->p,len);
FUNC_LEAVE (SUCCEED);
-} /* end H5T_vlen_mem_read() */
+} /* end H5T_vlen_seq_mem_read() */
/*-------------------------------------------------------------------------
- * Function: H5T_vlen_mem_write
+ * Function: H5T_vlen_seq_mem_write
*
* Purpose: "Writes" the memory based VL sequence from a buffer
*
@@ -181,12 +194,12 @@ herr_t H5T_vlen_mem_read(H5F_t UNUSED *f, void *vl_addr, void *buf, size_t len)
*
*-------------------------------------------------------------------------
*/
-herr_t H5T_vlen_mem_write(const H5F_xfer_t *xfer_parms, H5F_t UNUSED *f, void *vl_addr, void *buf, hsize_t seq_len, hsize_t base_size)
+herr_t H5T_vlen_seq_mem_write(const H5F_xfer_t *xfer_parms, H5F_t UNUSED *f, void *vl_addr, void *buf, hsize_t seq_len, hsize_t base_size)
{
hvl_t *vl=(hvl_t *)vl_addr; /* Pointer to the user's hvl_t information */
size_t len=seq_len*base_size;
- FUNC_ENTER (H5T_vlen_mem_write, FAIL);
+ FUNC_ENTER (H5T_vlen_seq_mem_write, FAIL);
/* check parameters */
assert(vl);
@@ -206,13 +219,114 @@ herr_t H5T_vlen_mem_write(const H5F_xfer_t *xfer_parms, H5F_t UNUSED *f, void *v
HDmemcpy(vl->p,buf,len);
FUNC_LEAVE (SUCCEED);
-} /* end H5T_vlen_mem_write() */
+} /* end H5T_vlen_seq_mem_write() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_vlen_str_mem_getlen
+ *
+ * Purpose: Retrieves the length of a memory based VL string.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, June 2, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hssize_t H5T_vlen_str_mem_getlen(H5F_t UNUSED *f, void *vl_addr)
+{
+ char *s=*(char **)vl_addr; /* Pointer to the user's hvl_t information */
+ hssize_t ret_value = FAIL; /*return value */
+
+ FUNC_ENTER (H5T_vlen_str_mem_getlen, FAIL);
+
+ /* check parameters */
+ assert(s);
+
+ ret_value=HDstrlen(s);
+
+ FUNC_LEAVE (ret_value);
+} /* end H5T_vlen_str_mem_getlen() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_vlen_str_mem_read
+ *
+ * Purpose: "Reads" the memory based VL string into a buffer
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, June 2, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5T_vlen_str_mem_read(H5F_t UNUSED *f, void *vl_addr, void *buf, size_t len)
+{
+ char *s=*(char **)vl_addr; /* Pointer to the user's hvl_t information */
+
+ FUNC_ENTER (H5T_vlen_str_mem_read, FAIL);
+
+ /* check parameters */
+ assert(s);
+ assert(buf);
+
+ HDmemcpy(buf,s,len);
+
+ FUNC_LEAVE (SUCCEED);
+} /* end H5T_vlen_str_mem_read() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_vlen_str_mem_write
+ *
+ * Purpose: "Writes" the memory based VL string from a buffer
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, June 2, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5T_vlen_str_mem_write(const H5F_xfer_t *xfer_parms, H5F_t UNUSED *f, void *vl_addr, void *buf, hsize_t seq_len, hsize_t base_size)
+{
+ char **s=(char **)vl_addr; /* Pointer to the user's hvl_t information */
+ size_t len=seq_len*base_size;
+
+ FUNC_ENTER (H5T_vlen_str_mem_write, FAIL);
+
+ /* check parameters */
+ assert(buf);
+
+ /* Use the user's memory allocation routine is one is defined */
+ if(xfer_parms->vlen_alloc!=NULL) {
+ if(NULL==(*s=(xfer_parms->vlen_alloc)((seq_len+1)*base_size,xfer_parms->alloc_info)))
+ HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data");
+ } /* end if */
+ else { /* Default to system malloc */
+ if(NULL==(*s=H5MM_malloc((seq_len+1)*base_size)))
+ HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data");
+ } /* end else */
+
+ HDmemcpy(*s,buf,len);
+ (*s)[len]='\0';
+
+ FUNC_LEAVE (SUCCEED);
+} /* end H5T_vlen_str_mem_write() */
/*-------------------------------------------------------------------------
* Function: H5T_vlen_disk_getlen
*
- * Purpose: Retrieves the length of a memory based VL element.
+ * Purpose: Retrieves the length of a disk based VL element.
*
* Return: Non-negative on success/Negative on failure
*
@@ -223,10 +337,10 @@ herr_t H5T_vlen_mem_write(const H5F_xfer_t *xfer_parms, H5F_t UNUSED *f, void *v
*
*-------------------------------------------------------------------------
*/
-hsize_t H5T_vlen_disk_getlen(H5F_t UNUSED *f, void *vl_addr)
+hssize_t H5T_vlen_disk_getlen(H5F_t UNUSED *f, void *vl_addr)
{
uint8_t *vl=(uint8_t *)vl_addr; /* Pointer to the disk VL information */
- hsize_t ret_value = FAIL; /*return value */
+ hssize_t ret_value = FAIL; /*return value */
FUNC_ENTER (H5T_vlen_disk_getlen, FAIL);
@@ -242,7 +356,7 @@ hsize_t H5T_vlen_disk_getlen(H5F_t UNUSED *f, void *vl_addr)
/*-------------------------------------------------------------------------
* Function: H5T_vlen_disk_read
*
- * Purpose: Reads the disk based VL sequence into a buffer
+ * Purpose: Reads the disk based VL element into a buffer
*
* Return: Non-negative on success/Negative on failure
*
@@ -284,7 +398,7 @@ herr_t H5T_vlen_disk_read(H5F_t *f, void *vl_addr, void *buf, size_t UNUSED len)
/*-------------------------------------------------------------------------
* Function: H5T_vlen_disk_write
*
- * Purpose: Writes the disk based VL sequence from a buffer
+ * Purpose: Writes the disk based VL element from a buffer
*
* Return: Non-negative on success/Negative on failure
*
@@ -382,7 +496,7 @@ H5T_vlen_reclaim_recurse(void *elem, H5T_t *dt, H5MM_free_t free_func, void *fre
/* Recurse on the VL information if it's VL or compound, then free VL sequence */
case H5T_VLEN:
- {
+ if(dt->u.vlen.type==H5T_VLEN_SEQUENCE) {
hvl_t *vl=(hvl_t *)elem; /* Temp. ptr to the vl info */
/* Recurse if it's VL or compound */
@@ -403,7 +517,15 @@ H5T_vlen_reclaim_recurse(void *elem, H5T_t *dt, H5MM_free_t free_func, void *fre
(*free_func)(vl->p,free_info);
else
H5MM_xfree(vl->p);
- } /* end case */
+ } else if(dt->u.vlen.type==H5T_VLEN_STRING) {
+ /* Free the VL string */
+ if(free_func!=NULL)
+ (*free_func)(*(char **)elem,free_info);
+ else
+ H5MM_xfree(*(char **)elem);
+ } else {
+ assert(0 && "Invalid VL type");
+ } /* end else */
break;
default:
@@ -487,7 +609,7 @@ done:
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
-H5T_vlen_mark(H5T_t *dt, H5F_t *f, H5T_vlen_type_t loc)
+H5T_vlen_mark(H5T_t *dt, H5F_t *f, H5T_vlen_loc_t loc)
{
intn i; /* local counting variable */
herr_t ret_value = SUCCEED;
@@ -495,7 +617,7 @@ H5T_vlen_mark(H5T_t *dt, H5F_t *f, H5T_vlen_type_t loc)
FUNC_ENTER(H5T_vlen_mark, FAIL);
assert(dt);
- assert(loc>H5T_VLEN_BADTYPE && loc<H5T_VLEN_MAXTYPE);
+ assert(loc>H5T_VLEN_BADLOC && loc<H5T_VLEN_MAXLOC);
/* Check the datatype of this element */
switch(dt->type) {