diff options
author | Quincey Koziol <koziol@koziol.gov> | 2020-06-26 23:57:38 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@koziol.gov> | 2020-06-26 23:57:38 (GMT) |
commit | e767f44e953047297fece364218147c908e8b585 (patch) | |
tree | d4b6909f14b78bb732b6947adc46ac3cd3ca54f6 /src/H5Tvlen.c | |
parent | 949649a2b6e00297cbdc49437e70a27e455e92d2 (diff) | |
parent | a08ab621febde7b09e4d86eab80cb029c123e9f6 (diff) | |
download | hdf5-e767f44e953047297fece364218147c908e8b585.zip hdf5-e767f44e953047297fece364218147c908e8b585.tar.gz hdf5-e767f44e953047297fece364218147c908e8b585.tar.bz2 |
Merge remote-tracking branch 'origin/develop' into monotonic_timer
Diffstat (limited to 'src/H5Tvlen.c')
-rw-r--r-- | src/H5Tvlen.c | 980 |
1 files changed, 460 insertions, 520 deletions
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 00e61e5..9d098c6 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -16,47 +16,119 @@ * datatypes in the H5T interface. */ +/****************/ +/* Module Setup */ +/****************/ + #include "H5Tmodule.h" /* This source code file is part of the H5T module */ +#define H5F_FRIEND /*suppress error about including H5Fpkg */ + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fpkg.h" /* File */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Tpkg.h" /* Datatypes */ +#include "H5VLprivate.h" /* Virtual Object Layer */ + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + +/* Memory-based VL sequence callbacks */ +static herr_t H5T__vlen_mem_seq_getlen(H5VL_object_t *file, const void *_vl, size_t *len); +static void * H5T__vlen_mem_seq_getptr(void *_vl); +static herr_t H5T__vlen_mem_seq_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_mem_seq_setnull(H5VL_object_t *file, void *_vl, void *_bg); +static herr_t H5T__vlen_mem_seq_read(H5VL_object_t *file, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_mem_seq_write(H5VL_object_t *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); + +/* Memory-based VL string callbacks */ +static herr_t H5T__vlen_mem_str_getlen(H5VL_object_t *file, const void *_vl, size_t *len); +static void * H5T__vlen_mem_str_getptr(void *_vl); +static herr_t H5T__vlen_mem_str_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_mem_str_setnull(H5VL_object_t *file, void *_vl, void *_bg); +static herr_t H5T__vlen_mem_str_read(H5VL_object_t *file, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_mem_str_write(H5VL_object_t *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); + +/* Disk-based VL sequence (and string) callbacks */ +static herr_t H5T__vlen_disk_getlen(H5VL_object_t *file, const void *_vl, size_t *len); +static herr_t H5T__vlen_disk_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_disk_setnull(H5VL_object_t *file, void *_vl, void *_bg); +static herr_t H5T__vlen_disk_read(H5VL_object_t *file, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_disk_write(H5VL_object_t *file, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); +static herr_t H5T__vlen_disk_delete(H5VL_object_t *file, const void *_vl); + + +/*********************/ +/* Public Variables */ +/*********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + +/* Class for VL sequences in memory */ +static const H5T_vlen_class_t H5T_vlen_mem_seq_g = { + H5T__vlen_mem_seq_getlen, /* 'getlen' */ + H5T__vlen_mem_seq_getptr, /* 'getptr' */ + H5T__vlen_mem_seq_isnull, /* 'isnull' */ + H5T__vlen_mem_seq_setnull, /* 'setnull' */ + H5T__vlen_mem_seq_read, /* 'read' */ + H5T__vlen_mem_seq_write, /* 'write' */ + NULL /* 'delete' */ +}; +/* Class for VL strings in memory */ +static const H5T_vlen_class_t H5T_vlen_mem_str_g = { + H5T__vlen_mem_str_getlen, /* 'getlen' */ + H5T__vlen_mem_str_getptr, /* 'getptr' */ + H5T__vlen_mem_str_isnull, /* 'isnull' */ + H5T__vlen_mem_str_setnull, /* 'setnull' */ + H5T__vlen_mem_str_read, /* 'read' */ + H5T__vlen_mem_str_write, /* 'write' */ + NULL /* 'delete' */ +}; -#include "H5private.h" /* Generic Functions */ -#include "H5Dprivate.h" /* Dataset functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5HGprivate.h" /* Global Heaps */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Pprivate.h" /* Property lists */ -#include "H5Tpkg.h" /* Datatypes */ - -/* Local functions */ -static herr_t H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, void *free_info); -static ssize_t H5T_vlen_seq_mem_getlen(const void *_vl); -static void * H5T_vlen_seq_mem_getptr(void *_vl); -static htri_t H5T_vlen_seq_mem_isnull(const H5F_t *f, void *_vl); -static herr_t H5T_vlen_seq_mem_read(H5F_t *f, hid_t dxpl_id, void *_vl, void *_buf, size_t len); -static herr_t H5T_vlen_seq_mem_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); -static herr_t H5T_vlen_seq_mem_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg); -static ssize_t H5T_vlen_str_mem_getlen(const void *_vl); -static void * H5T_vlen_str_mem_getptr(void *_vl); -static htri_t H5T_vlen_str_mem_isnull(const H5F_t *f, void *_vl); -static herr_t H5T_vlen_str_mem_read(H5F_t *f, hid_t dxpl_id, void *_vl, void *_buf, size_t len); -static herr_t H5T_vlen_str_mem_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); -static herr_t H5T_vlen_str_mem_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg); -static ssize_t H5T_vlen_disk_getlen(const void *_vl); -static void * H5T_vlen_disk_getptr(void *_vl); -static htri_t H5T_vlen_disk_isnull(const H5F_t *f, void *_vl); -static herr_t H5T_vlen_disk_read(H5F_t *f, hid_t dxpl_id, void *_vl, void *_buf, size_t len); -static herr_t H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); -static herr_t H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg); - -/* Local variables */ - -/* Default settings for variable-length allocation routines */ -static H5T_vlen_alloc_info_t H5T_vlen_def_vl_alloc_info ={ - H5D_VLEN_ALLOC, - H5D_VLEN_ALLOC_INFO, - H5D_VLEN_FREE, - H5D_VLEN_FREE_INFO +/* Class for both VL strings and sequences in file */ +static const H5T_vlen_class_t H5T_vlen_disk_g = { + H5T__vlen_disk_getlen, /* 'getlen' */ + NULL, /* 'getptr' */ + H5T__vlen_disk_isnull, /* 'isnull' */ + H5T__vlen_disk_setnull, /* 'setnull' */ + H5T__vlen_disk_read, /* 'read' */ + H5T__vlen_disk_write, /* 'write' */ + H5T__vlen_disk_delete /* 'delete' */ }; @@ -157,7 +229,7 @@ H5T__vlen_create(const H5T_t *base) done: if(!ret_value) - if(dt && H5T_close(dt) < 0) + if(dt && H5T_close_real(dt) < 0) HDONE_ERROR(H5E_DATATYPE, H5E_CANTRELEASE, NULL, "unable to release datatype info") FUNC_LEAVE_NOAPI(ret_value) @@ -181,8 +253,9 @@ done: *------------------------------------------------------------------------- */ htri_t -H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) +H5T__vlen_set_loc(const H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc) { + H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0}; htri_t ret_value = FALSE; /* Indicate success, but no location change */ FUNC_ENTER_PACKAGE @@ -192,74 +265,68 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) HDassert(loc >= H5T_LOC_BADLOC && loc < H5T_LOC_MAXLOC); /* Only change the location if it's different */ - if(loc != dt->shared->u.vlen.loc || f != dt->shared->u.vlen.f) { + if(loc != dt->shared->u.vlen.loc || file != dt->shared->u.vlen.file) { switch(loc) { case H5T_LOC_MEMORY: /* Memory based VL datatype */ - HDassert(NULL == f); + HDassert(NULL == file); /* Mark this type as being stored in memory */ dt->shared->u.vlen.loc = H5T_LOC_MEMORY; if(dt->shared->u.vlen.type == H5T_VLEN_SEQUENCE) { - /* size in memory, disk size is different */ + /* Size in memory, disk size is different */ dt->shared->size = sizeof(hvl_t); /* Set up the function pointers to access the VL sequence in memory */ - 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->shared->u.vlen.cls = &H5T_vlen_mem_seq_g; + } /* end if */ + else if(dt->shared->u.vlen.type == H5T_VLEN_STRING) { + /* Size in memory, disk size is different */ dt->shared->size = sizeof(char *); /* Set up the function pointers to access the VL string in memory */ - 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 { + dt->shared->u.vlen.cls = &H5T_vlen_mem_str_g; + } /* end else-if */ + else HDassert(0 && "Invalid VL type"); - } - /* Reset file ID (since this VL is in memory) */ - dt->shared->u.vlen.f = NULL; + /* Reset file pointer (since this VL is in memory) */ + dt->shared->u.vlen.file = NULL; break; case H5T_LOC_DISK: /* Disk based VL datatype */ - HDassert(f); + HDassert(file); /* Mark this type as being stored on 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->shared->size = 4 + (size_t)H5F_SIZEOF_ADDR(f) + 4; + /* Get container info */ + if(H5VL_file_get(file, H5VL_FILE_GET_CONT_INFO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &cont_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get container info") + + /* The datatype size is equal to 4 bytes for the sequence length + * plus the size of a blob id */ + dt->shared->size = 4 + cont_info.blob_id_size; /* 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->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; + dt->shared->u.vlen.cls = &H5T_vlen_disk_g; /* Set file ID (since this VL is on disk) */ - dt->shared->u.vlen.f = f; + dt->shared->u.vlen.file = file; break; case H5T_LOC_BADLOC: /* Allow undefined location. In H5Odtype.c, H5O_dtype_decode sets undefined * location for VL type and leaves it for the caller to decide. */ + dt->shared->u.vlen.loc = H5T_LOC_BADLOC; + + /* Reset the function pointers to access the VL information */ + dt->shared->u.vlen.cls = NULL; + + /* Reset file pointer */ + dt->shared->u.vlen.file = NULL; break; case H5T_LOC_MAXLOC: @@ -274,11 +341,11 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T__vlen_set_loc() */ +} /* end H5T__vlen_set_loc() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_getlen + * Function: H5T__vlen_mem_seq_getlen * * Purpose: Retrieves the length of a memory based VL element. * @@ -289,33 +356,35 @@ done: * *------------------------------------------------------------------------- */ -static ssize_t -H5T_vlen_seq_mem_getlen(const void *_vl) +static herr_t +H5T__vlen_mem_seq_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, size_t *len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* check parameters, return result */ -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - HDassert(vl); + /* Check parameter */ + HDassert(_vl); + HDassert(len); - FUNC_LEAVE_NOAPI((ssize_t)vl->len) +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + *len = vl->len; #else - HDassert(_vl); - HDmemcpy(&vl, _vl, sizeof(hvl_t)); + H5MM_memcpy(&vl, _vl, sizeof(hvl_t)); - FUNC_LEAVE_NOAPI((ssize_t)vl.len) + *len = vl.len; #endif -} /* end H5T_vlen_seq_mem_getlen() */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_seq_getlen() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_getptr + * Function: H5T__vlen_mem_seq_getptr * * Purpose: Retrieves the pointer for a memory based VL element. * @@ -327,15 +396,15 @@ H5T_vlen_seq_mem_getlen(const void *_vl) *------------------------------------------------------------------------- */ static void * -H5T_vlen_seq_mem_getptr(void *_vl) +H5T__vlen_mem_seq_getptr(void *_vl) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters, return result */ #ifdef H5_NO_ALIGNMENT_RESTRICTIONS @@ -344,52 +413,86 @@ H5T_vlen_seq_mem_getptr(void *_vl) FUNC_LEAVE_NOAPI(vl->p) #else HDassert(_vl); - HDmemcpy(&vl, _vl, sizeof(hvl_t)); + H5MM_memcpy(&vl, _vl, sizeof(hvl_t)); FUNC_LEAVE_NOAPI(vl.p) #endif -} /* end H5T_vlen_seq_mem_getptr() */ +} /* end H5T__vlen_mem_seq_getptr() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_isnull + * Function: H5T__vlen_mem_seq_isnull * * Purpose: Checks if a memory sequence is the "null" sequence * - * Return: TRUE/FALSE on success/Negative on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static htri_t -H5T_vlen_seq_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) +static herr_t +H5T__vlen_mem_seq_isnull(const H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, hbool_t *isnull) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* check parameters, return result */ -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - HDassert(vl); + /* Check parameters */ + HDassert(_vl); - FUNC_LEAVE_NOAPI((vl->len==0 || vl->p==NULL) ? TRUE : FALSE) +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + *isnull = ((vl->len == 0 || vl->p == NULL) ? TRUE : FALSE); #else - HDassert(_vl); - HDmemcpy(&vl, _vl, sizeof(hvl_t)); + H5MM_memcpy(&vl, _vl, sizeof(hvl_t)); - FUNC_LEAVE_NOAPI((vl.len==0 || vl.p==NULL) ? TRUE : FALSE) + *isnull = ((vl.len == 0 || vl.p == NULL) ? TRUE : FALSE); #endif -} /* end H5T_vlen_seq_mem_isnull() */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_seq_isnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_read + * Function: H5T__vlen_mem_seq_setnull + * + * Purpose: Sets a VL info object in memory to the "nil" value + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Saturday, November 8, 2003 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__vlen_mem_seq_setnull(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void H5_ATTR_UNUSED *_bg) +{ + hvl_t vl; /* Temporary hvl_t to use during operation */ + + FUNC_ENTER_STATIC_NOERR + + /* check parameters */ + HDassert(_vl); + + /* Set the "nil" hvl_t */ + vl.len = 0; + vl.p = NULL; + + /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ + H5MM_memcpy(_vl, &vl, sizeof(hvl_t)); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_seq_setnull() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__vlen_mem_seq_read * * Purpose: "Reads" the memory based VL sequence into a buffer * @@ -401,36 +504,36 @@ H5T_vlen_seq_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_seq_mem_read(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, void *_vl, void *buf, size_t len) +H5T__vlen_mem_seq_read(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void *buf, size_t len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters, copy data */ HDassert(buf); #ifdef H5_NO_ALIGNMENT_RESTRICTIONS HDassert(vl && vl->p); - HDmemcpy(buf,vl->p,len); + H5MM_memcpy(buf, vl->p, len); #else HDassert(_vl); - HDmemcpy(&vl, _vl, sizeof(hvl_t)); + H5MM_memcpy(&vl, _vl, sizeof(hvl_t)); HDassert(vl.p); - HDmemcpy(buf,vl.p,len); + H5MM_memcpy(buf, vl.p, len); #endif FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5T_vlen_seq_mem_read() */ +} /* end H5T__vlen_mem_seq_read() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_write + * Function: H5T__vlen_mem_seq_write * * Purpose: "Writes" the memory based VL sequence from a buffer * @@ -442,185 +545,179 @@ H5T_vlen_seq_mem_read(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, voi *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_seq_mem_write(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) +H5T__vlen_mem_seq_write(H5VL_object_t H5_ATTR_UNUSED *file, const H5T_vlen_alloc_info_t *vl_alloc_info, + void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) { hvl_t vl; /* Temporary hvl_t to use during operation */ - size_t len; - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* check parameters */ HDassert(_vl); HDassert(buf); - if(seq_len!=0) { - len=seq_len*base_size; + if(seq_len) { + size_t len = seq_len * base_size; /* Sequence size */ /* Use the user's memory allocation routine is one is defined */ - if(vl_alloc_info->alloc_func!=NULL) { - if(NULL==(vl.p=(vl_alloc_info->alloc_func)(len,vl_alloc_info->alloc_info))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") + if(vl_alloc_info->alloc_func != NULL) { + if(NULL == (vl.p = (vl_alloc_info->alloc_func)(len, vl_alloc_info->alloc_info))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "application memory allocation routine failed for VL data") } /* end if */ - else { /* Default to system malloc */ + else /* Default to system malloc */ if(NULL == (vl.p = HDmalloc(len))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") - } /* end else */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed for VL data") /* Copy the data into the newly allocated buffer */ - HDmemcpy(vl.p,buf,len); - + H5MM_memcpy(vl.p, buf, len); } /* end if */ else - vl.p=NULL; + vl.p = NULL; /* Set the sequence length */ - vl.len=seq_len; + vl.len = seq_len; /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - HDmemcpy(_vl,&vl,sizeof(hvl_t)); + H5MM_memcpy(_vl, &vl, sizeof(hvl_t)); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_seq_mem_write() */ +} /* end H5T__vlen_mem_seq_write() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_setnull + * Function: H5T__vlen_mem_str_getlen * - * Purpose: Sets a VL info object in memory to the "nil" value + * Purpose: Retrieves the length of a memory based VL string. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * Saturday, November 8, 2003 + * Wednesday, June 2, 1999 * *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_seq_mem_setnull(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, void *_vl, void H5_ATTR_UNUSED *_bg) +H5T__vlen_mem_str_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, size_t *len) { - hvl_t vl; /* Temporary hvl_t to use during operation */ +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + const char *s = *(const char * const *)_vl; /* Pointer to the user's string information */ +#else + const char *s = NULL; /* Pointer to the user's string information */ +#endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters */ HDassert(_vl); - /* Set the "nil" hvl_t */ - vl.len=0; - vl.p=NULL; +#ifndef H5_NO_ALIGNMENT_RESTRICTIONS + H5MM_memcpy(&s, _vl, sizeof(char *)); +#endif - /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - HDmemcpy(_vl,&vl,sizeof(hvl_t)); + *len = HDstrlen(s); FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5T_vlen_seq_mem_setnull() */ +} /* end H5T__vlen_mem_str_getlen() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_getlen + * Function: H5T__vlen_mem_str_getptr * - * Purpose: Retrieves the length of a memory based VL string. + * Purpose: Retrieves the pointer for a memory based VL string. * - * Return: Non-negative on success/Negative on failure + * Return: Non-NULL on success/NULL on failure * * Programmer: Quincey Koziol - * Wednesday, June 2, 1999 + * Saturday, June 12, 2004 * *------------------------------------------------------------------------- */ -static ssize_t -H5T_vlen_str_mem_getlen(const void *_vl) +static void * +H5T__vlen_mem_str_getptr(void *_vl) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const char *s=*(const char * const *)_vl; /* Pointer to the user's string information */ + char *s = *(char **)_vl; /* Pointer to the user's string information */ #else - const char *s; /* Pointer to the user's string information */ + char *s = NULL; /* Pointer to the user's string information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters */ #ifdef H5_NO_ALIGNMENT_RESTRICTIONS HDassert(s); #else HDassert(_vl); - HDmemcpy(&s, _vl, sizeof(char *)); + H5MM_memcpy(&s, _vl, sizeof(char *)); #endif - FUNC_LEAVE_NOAPI((ssize_t)HDstrlen(s)) -} /* end H5T_vlen_str_mem_getlen() */ + FUNC_LEAVE_NOAPI(s) +} /* end H5T__vlen_mem_str_getptr() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_getptr + * Function: H5T__vlen_mem_str_isnull * - * Purpose: Retrieves the pointer for a memory based VL string. + * Purpose: Checks if a memory string is a NULL pointer * - * Return: Non-NULL on success/NULL on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol - * Saturday, June 12, 2004 + * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static void * -H5T_vlen_str_mem_getptr(void *_vl) +static herr_t +H5T__vlen_mem_str_isnull(const H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, hbool_t *isnull) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - char *s=*(char **)_vl; /* Pointer to the user's string information */ + char *s = *(char **)_vl; /* Pointer to the user's string information */ #else - char *s; /* Pointer to the user's string information */ + char *s = NULL; /* Pointer to the user's string information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* check parameters */ -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - HDassert(s); -#else - HDassert(_vl); - HDmemcpy(&s, _vl, sizeof(char *)); +#ifndef H5_NO_ALIGNMENT_RESTRICTIONS + H5MM_memcpy(&s, _vl, sizeof(char *)); #endif - FUNC_LEAVE_NOAPI(s) -} /* end H5T_vlen_str_mem_getptr() */ + *isnull = (s == NULL ? TRUE : FALSE); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_str_isnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_isnull + * Function: H5T__vlen_mem_str_setnull * - * Purpose: Checks if a memory string is a NULL pointer + * Purpose: Sets a VL info object in memory to the "null" value * - * Return: TRUE/FALSE on success/Negative on failure + * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static htri_t -H5T_vlen_str_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) +static herr_t +H5T__vlen_mem_str_setnull(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void H5_ATTR_UNUSED *_bg) { -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - char *s=*(char **)_vl; /* Pointer to the user's string information */ -#else - char *s; /* Pointer to the user's string information */ -#endif + char *t = NULL; /* Pointer to temporary buffer allocated */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR -#ifndef H5_NO_ALIGNMENT_RESTRICTIONS - HDmemcpy(&s, _vl, sizeof(char *)); -#endif + /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ + H5MM_memcpy(_vl, &t, sizeof(char *)); - FUNC_LEAVE_NOAPI(s==NULL ? TRUE : FALSE) -} /* end H5T_vlen_str_mem_isnull() */ + FUNC_LEAVE_NOAPI(SUCCEED) /*lint !e429 The pointer in 't' has been copied */ +} /* end H5T__vlen_mem_str_setnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_read + * Function: H5T__vlen_mem_str_read * * Purpose: "Reads" the memory based VL string into a buffer * @@ -632,35 +729,36 @@ H5T_vlen_str_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_str_mem_read(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, void *_vl, void *buf, size_t len) +H5T__vlen_mem_str_read(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void *buf, + size_t len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - char *s=*(char **)_vl; /* Pointer to the user's string information */ + char *s = *(char **)_vl; /* Pointer to the user's string information */ #else char *s; /* Pointer to the user's string information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - if(len>0) { + if(len > 0) { /* check parameters */ HDassert(buf); #ifdef H5_NO_ALIGNMENT_RESTRICTIONS HDassert(s); #else HDassert(_vl); - HDmemcpy(&s, _vl, sizeof(char *)); + H5MM_memcpy(&s, _vl, sizeof(char *)); #endif - HDmemcpy(buf,s,len); + H5MM_memcpy(buf, s, len); } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5T_vlen_str_mem_read() */ +} /* end H5T__vlen_mem_str_read() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_write + * Function: H5T__vlen_mem_str_write * * Purpose: "Writes" the memory based VL string from a buffer * @@ -672,67 +770,42 @@ H5T_vlen_str_mem_read(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, voi *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_str_mem_write(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) +H5T__vlen_mem_str_write(H5VL_object_t H5_ATTR_UNUSED *file, const H5T_vlen_alloc_info_t *vl_alloc_info, + void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) { char *t; /* Pointer to temporary buffer allocated */ size_t len; /* Maximum length of the string to copy */ - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* check parameters */ HDassert(buf); /* Use the user's memory allocation routine if one is defined */ - if(vl_alloc_info->alloc_func!=NULL) { - if(NULL==(t = (char *)(vl_alloc_info->alloc_func)((seq_len+1)*base_size,vl_alloc_info->alloc_info))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") - } /* end if */ - else { /* Default to system malloc */ + if(vl_alloc_info->alloc_func != NULL) { + if(NULL == (t = (char *)(vl_alloc_info->alloc_func)((seq_len + 1) * base_size, vl_alloc_info->alloc_info))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "application memory allocation routine failed for VL data") + } /* end if */ + else /* Default to system malloc */ if(NULL == (t = (char *)HDmalloc((seq_len + 1) * base_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") - } /* end else */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed for VL data") - len=(seq_len*base_size); - HDmemcpy(t,buf,len); - t[len]='\0'; + /* 'write' the string into the buffer, with memcpy() */ + len = (seq_len * base_size); + H5MM_memcpy(t, buf, len); + t[len] = '\0'; /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - HDmemcpy(_vl,&t,sizeof(char *)); + H5MM_memcpy(_vl, &t, sizeof(char *)); done: FUNC_LEAVE_NOAPI(ret_value) /*lint !e429 The pointer in 't' has been copied */ -} /* end H5T_vlen_str_mem_write() */ +} /* end H5T__vlen_mem_str_write() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_setnull - * - * Purpose: Sets a VL info object in memory to the "null" value - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Quincey Koziol - * Saturday, November 8, 2003 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5T_vlen_str_mem_setnull(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, void *_vl, void H5_ATTR_UNUSED *_bg) -{ - char *t=NULL; /* Pointer to temporary buffer allocated */ - - FUNC_ENTER_NOAPI_NOINIT_NOERR - - /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - HDmemcpy(_vl,&t,sizeof(char *)); - - FUNC_LEAVE_NOAPI(SUCCEED) /*lint !e429 The pointer in 't' has been copied */ -} /* end H5T_vlen_str_mem_setnull() */ - - -/*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_getlen + * Function: H5T__vlen_disk_getlen * * Purpose: Retrieves the length of a disk based VL element. * @@ -743,82 +816,105 @@ H5T_vlen_str_mem_setnull(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, * *------------------------------------------------------------------------- */ -static ssize_t -H5T_vlen_disk_getlen(const void *_vl) +static herr_t +H5T__vlen_disk_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, size_t *seq_len) { - const uint8_t *vl=(const uint8_t *)_vl; /* Pointer to the disk VL information */ - size_t seq_len = 0; /* Sequence length */ + const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* check parameters */ + /* Check parameters */ HDassert(vl); + HDassert(seq_len); - UINT32DECODE(vl, seq_len); + /* Get length of sequence (different from blob size) */ + UINT32DECODE(vl, *seq_len); - FUNC_LEAVE_NOAPI((ssize_t)seq_len) -} /* end H5T_vlen_disk_getlen() */ + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_disk_getlen() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_getptr + * Function: H5T__vlen_disk_isnull * - * Purpose: Retrieves the pointer to a disk based VL element. + * Purpose: Checks if a disk VL info object is the "nil" object * - * Return: Non-NULL on success/NULL on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol - * Saturday, June 12, 2004 + * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static void * -H5T_vlen_disk_getptr(void H5_ATTR_UNUSED *vl) +static herr_t +H5T__vlen_disk_isnull(const H5VL_object_t *file, void *_vl, hbool_t *isnull) { - FUNC_ENTER_NOAPI_NOINIT_NOERR + uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + herr_t ret_value = SUCCEED; /* Return value */ - /* check parameters */ + FUNC_ENTER_STATIC + + /* Check parameters */ + HDassert(file); HDassert(vl); + HDassert(isnull); + + /* Skip the sequence's length */ + vl += 4; - FUNC_LEAVE_NOAPI(NULL) -} /* end H5T_vlen_disk_getptr() */ + /* Check if blob ID is "nil" */ + if(H5VL_blob_specific(file, vl, H5VL_BLOB_ISNULL, isnull) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to check if a blob ID is 'nil'") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__vlen_disk_isnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_isnull + * Function: H5T__vlen_disk_setnull * - * Purpose: Checks if a disk VL info object is the "nil" object + * Purpose: Sets a VL info object on disk to the "nil" value * - * Return: TRUE/FALSE on success/Negative on failure + * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static htri_t -H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) +static herr_t +H5T__vlen_disk_setnull(H5VL_object_t *file, void *_vl, void *bg) { - uint8_t *vl = (uint8_t *)_vl; /* Pointer to the disk VL information */ - haddr_t addr; /* Sequence's heap address */ + uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC /* check parameters */ + HDassert(file); HDassert(vl); - /* Skip the sequence's length */ - vl += 4; + /* Free heap object for old data */ + if(bg != NULL) + /* Delete sequence in destination location */ + if(H5T__vlen_disk_delete(file, bg) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove background heap object") - /* Get the heap address */ - H5F_addr_decode(f, (const uint8_t **)&vl, &addr); + /* Set the length of the sequence */ + UINT32ENCODE(vl, 0); - FUNC_LEAVE_NOAPI(addr == 0 ? TRUE : FALSE) -} /* end H5T_vlen_disk_isnull() */ + /* Set blob ID to "nil" */ + if(H5VL_blob_specific(file, vl, H5VL_BLOB_SETNULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to set a blob ID to 'nil'") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__vlen_disk_setnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_read + * Function: H5T__vlen_disk_read * * Purpose: Reads the disk based VL element into a buffer * @@ -830,40 +926,32 @@ H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_disk_read(H5F_t *f, hid_t dxpl_id, void *_vl, void *buf, size_t H5_ATTR_UNUSED len) +H5T__vlen_disk_read(H5VL_object_t *file, void *_vl, void *buf, size_t len) { - uint8_t *vl=(uint8_t *)_vl; /* Pointer to the user's hvl_t information */ - H5HG_t hobjid; - herr_t ret_value=SUCCEED; /* Return value */ + const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC - /* check parameters */ + /* Check parameters */ + HDassert(file); HDassert(vl); HDassert(buf); - HDassert(f); /* Skip the length of the sequence */ vl += 4; - /* Get the heap information */ - H5F_addr_decode(f,(const uint8_t **)&vl,&(hobjid.addr)); - UINT32DECODE(vl,hobjid.idx); - - /* Check if this sequence actually has any data */ - if(hobjid.addr>0) { - /* Read the VL information from disk */ - if(H5HG_read(f,dxpl_id,&hobjid,buf, NULL)==NULL) - HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "Unable to read VL information") - } /* end if */ + /* Retrieve blob */ + if(H5VL_blob_get(file, vl, buf, len, NULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get blob") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_disk_read() */ +} /* end H5T__vlen_disk_read() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_write + * Function: H5T__vlen_disk_write * * Purpose: Writes the disk based VL element from a buffer * @@ -875,146 +963,108 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t H5_ATTR_UNUSED *vl_alloc_info, - void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size) +H5T__vlen_disk_write(H5VL_object_t *file, + const H5T_vlen_alloc_info_t H5_ATTR_UNUSED *vl_alloc_info, void *_vl, + void *buf, void *_bg, size_t seq_len, size_t base_size) { - uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ - H5HG_t hobjid; /* New VL sequence's heap ID */ - size_t len; /* Size of new sequence on disk (in bytes) */ - herr_t ret_value = SUCCEED; /* Return value */ + uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + const uint8_t *bg = (const uint8_t *)_bg; /* Pointer to the old data hvl_t */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* check parameters */ HDassert(vl); HDassert(seq_len == 0 || buf); - HDassert(f); - - /* Free heap object for old data. */ - if(bg!=NULL) { - H5HG_t bg_hobjid; /* "Background" VL info sequence's ID info */ + HDassert(file); - /* Skip the length of the sequence and heap object ID from background data. */ - bg += 4; - - /* Get heap information */ - H5F_addr_decode(f, (const uint8_t **)&bg, &(bg_hobjid.addr)); - UINT32DECODE(bg, bg_hobjid.idx); - - /* Free heap object for old data */ - if(bg_hobjid.addr > 0) { - /* Free heap object */ - if(H5HG_remove(f, dxpl_id, &bg_hobjid) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") - } /* end if */ - } /* end if */ + /* Free heap object for old data, if non-NULL */ + if(bg != NULL) + if(H5T__vlen_disk_delete(file, bg) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove background heap object") /* Set the length of the sequence */ UINT32ENCODE(vl, seq_len); - /* Write the VL information to disk (allocates space also) */ - len = (seq_len*base_size); - if(H5HG_insert(f, dxpl_id, len, buf, &hobjid) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to write VL information") - - /* Encode the heap information */ - H5F_addr_encode(f, &vl, hobjid.addr); - UINT32ENCODE(vl, hobjid.idx); + /* Store blob */ + if(H5VL_blob_put(file, buf, (seq_len * base_size), vl, NULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to put blob") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_disk_write() */ +} /* end H5T__vlen_disk_write() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_setnull + * Function: H5T__vlen_disk_delete * - * Purpose: Sets a VL info object on disk to the "nil" value + * Purpose: Deletes a disk-based VL element * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol - * Saturday, November 8, 2003 + * Friday, August 15, 2019 * *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) +H5T__vlen_disk_delete(H5VL_object_t *file, const void *_vl) { - uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ - uint32_t seq_len = 0; /* Sequence length */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT + const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + herr_t ret_value = SUCCEED; /* Return value */ - /* check parameters */ - HDassert(f); - HDassert(vl); + FUNC_ENTER_STATIC - /* Free heap object for old data. */ - if(bg != NULL) { - H5HG_t bg_hobjid; /* "Background" VL info sequence's ID info */ + /* Check parameters */ + HDassert(file); - /* Skip the length of the sequence and heap object ID from background data. */ - bg += 4; + /* Free heap object for old data */ + if(vl != NULL) { + size_t seq_len; /* VL sequence's length */ - /* Get heap information */ - H5F_addr_decode(f, (const uint8_t **)&bg, &(bg_hobjid.addr)); - UINT32DECODE(bg, bg_hobjid.idx); + /* Get length of sequence */ + UINT32DECODE(vl, seq_len); - /* Free heap object for old data */ - if(bg_hobjid.addr > 0) { - /* Free heap object */ - if(H5HG_remove(f, dxpl_id, &bg_hobjid) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") - } /* end if */ + /* Delete object, if length > 0 */ + if(seq_len > 0) + if(H5VL_blob_specific(file, (void *)vl, H5VL_BLOB_DELETE) < 0) /* Casting away 'const' OK -QAK */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to delete blob") } /* end if */ - /* Set the length of the sequence */ - UINT32ENCODE(vl, seq_len); - - /* Encode the "nil" heap pointer information */ - H5F_addr_encode(f, &vl, (haddr_t)0); - UINT32ENCODE(vl, 0); - done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_disk_setnull() */ +} /* end H5T__vlen_disk_delete() */ -/*-------------------------------------------------------------------------- - NAME - H5T_vlen_reclaim_recurse - PURPOSE - Internal recursive routine to free VL datatypes - USAGE - herr_t H5T_vlen_reclaim(elem,dt) - void *elem; IN/OUT: Pointer to the dataset element - H5T_t *dt; IN: Datatype of dataset element - - RETURNS - SUCCEED/FAIL - DESCRIPTION - Frees any dynamic memory used by VL datatypes in the current dataset - element. Performs a recursive depth-first traversal of all compound - datatypes to free all VL datatype information allocated by any field. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static herr_t -H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, void *free_info) +/*------------------------------------------------------------------------- + * Function: H5T_vlen_reclaim + * + * Purpose: Internal recursive routine to free VL datatypes + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Quincey Koziol + * Friday, August 15, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_vlen_reclaim(void *elem, const H5T_t *dt, H5T_vlen_alloc_info_t *alloc_info) { unsigned u; /* Local index variable */ + H5MM_free_t free_func; /* Free function */ + void *free_info; /* Free info */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_NOAPI(FAIL) + /* Sanity checks */ HDassert(elem); HDassert(dt); + HDassert(alloc_info); + + free_func = alloc_info->free_func; + free_info = alloc_info->free_info; /* Check the datatype of this element */ switch(dt->shared->type) { @@ -1026,8 +1076,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi /* Calculate the offset member and recurse on it */ for(u = 0; u < dt->shared->u.array.nelem; u++) { off = ((uint8_t *)elem) + u * (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") + if(H5T_reclaim_cb(off, dt->shared->parent, 0, NULL, alloc_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free array element") } /* end for */ } /* end if */ break; @@ -1041,8 +1091,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi /* Calculate the offset member and recurse on it */ off = ((uint8_t *)elem) + dt->shared->u.compnd.memb[u].offset; - if(H5T_vlen_reclaim_recurse(off, dt->shared->u.compnd.memb[u].type, free_func, free_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free compound field") + if(H5T_reclaim_cb(off, dt->shared->u.compnd.memb[u].type, 0, NULL, alloc_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free compound field") } /* end if */ } /* end for */ break; @@ -1061,8 +1111,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi /* 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) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free VL element") + if(H5T_reclaim_cb(off, dt->shared->parent, 0, NULL, alloc_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free VL element") vl->len--; } /* end while */ } /* end if */ @@ -1091,11 +1141,11 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_STRING: case H5T_BITFIELD: case H5T_OPAQUE: - case H5T_REFERENCE: case H5T_ENUM: break; /* Should never have these values */ + case H5T_REFERENCE: case H5T_NO_CLASS: case H5T_NCLASSES: default: @@ -1106,124 +1156,16 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_reclaim_recurse() */ - - -/*-------------------------------------------------------------------------- - NAME - H5T_vlen_reclaim - PURPOSE - Default method to reclaim any VL data for a buffer element - USAGE - herr_t H5T_vlen_reclaim(elem,type_id,ndim,point,op_data) - void *elem; IN/OUT: Pointer to the dataset element - hid_t type_id; IN: Datatype of dataset element - unsigned ndim; IN: Number of dimensions in dataspace - hsize_t *point; IN: Coordinate location of element in dataspace - void *op_data IN: Operator data - - RETURNS - SUCCEED/FAIL - DESCRIPTION - Frees any dynamic memory used by VL datatypes in the current dataset - element. Recursively descends compound datatypes to free all VL datatype - information allocated by any field. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -herr_t -H5T_vlen_reclaim(void *elem, hid_t type_id, unsigned H5_ATTR_UNUSED ndim, const hsize_t H5_ATTR_UNUSED *point, void *op_data) -{ - H5T_vlen_alloc_info_t *vl_alloc_info = (H5T_vlen_alloc_info_t *)op_data; /* VL allocation info from iterator */ - H5T_t *dt; - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - HDassert(elem); - HDassert(vl_alloc_info); - HDassert(H5I_DATATYPE == H5I_get_type(type_id)); - - /* Check args */ - if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - - /* Pull the free function and free info pointer out of the op_data and call the recurse datatype free function */ - if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info->free_func, vl_alloc_info->free_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_reclaim() */ - - -/*-------------------------------------------------------------------------- - NAME - H5T_vlen_get_alloc_info - PURPOSE - Retrieve allocation info for VL datatypes - USAGE - herr_t H5T_vlen_get_alloc_info(dxpl_id,vl_alloc_info) - hid_t dxpl_id; IN: Data transfer property list to query - H5T_vlen_alloc_info_t *vl_alloc_info; IN/OUT: Pointer to VL allocation information to fill - - RETURNS - SUCCEED/FAIL - DESCRIPTION - Retrieve the VL allocation functions and information from a dataset - transfer property list. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - The VL_ALLOC_INFO pointer should point at already allocated memory to place - non-default property list info. If a default property list is used, the - VL_ALLOC_INFO pointer will be changed to point at the default information. - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -herr_t -H5T_vlen_get_alloc_info(hid_t dxpl_id, H5T_vlen_alloc_info_t **vl_alloc_info) -{ - H5P_genplist_t *plist; /* DX property list */ - herr_t ret_value=SUCCEED; - - FUNC_ENTER_NOAPI(FAIL) - - HDassert(H5I_GENPROP_LST == H5I_get_type(dxpl_id)); - HDassert(vl_alloc_info); - - /* Check for the default DXPL */ - if(dxpl_id==H5P_DATASET_XFER_DEFAULT) - *vl_alloc_info=&H5T_vlen_def_vl_alloc_info; - else { - /* Check args */ - if(NULL == (plist = H5P_object_verify(dxpl_id,H5P_DATASET_XFER))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset transfer property list") - - /* Get the allocation functions & information */ - if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_NAME,&(*vl_alloc_info)->alloc_func) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_INFO_NAME,&(*vl_alloc_info)->alloc_info) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_FREE_NAME,&(*vl_alloc_info)->free_func) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_FREE_INFO_NAME,&(*vl_alloc_info)->free_info) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - } /* end else */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_get_alloc_info() */ +} /* end H5T_vlen_reclaim() */ /*------------------------------------------------------------------------- * Function: H5T_vlen_reclaim_elmt * * Purpose: Alternative method to reclaim any VL data for a buffer element. - * - * Use this function when the datatype is already available, but - * the allocation info is needed from the dxpl_id before jumping + * + * Use this function when the datatype is already available, but + * the allocation info is needed from the context before jumping * into recursion. * * Return: Non-negative on success/Negative on failure @@ -1234,11 +1176,10 @@ done: *------------------------------------------------------------------------- */ herr_t -H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt, hid_t dxpl_id) +H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt) { - H5T_vlen_alloc_info_t _vl_alloc_info; /* VL allocation info buffer */ - H5T_vlen_alloc_info_t *vl_alloc_info = &_vl_alloc_info; /* VL allocation info */ - herr_t ret_value = SUCCEED; /* return value */ + H5T_vlen_alloc_info_t vl_alloc_info; /* VL allocation info */ + herr_t ret_value = SUCCEED; /* return value */ HDassert(dt); HDassert(elem); @@ -1246,14 +1187,13 @@ H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt, hid_t dxpl_id) FUNC_ENTER_NOAPI(FAIL) /* Get VL allocation info */ - if(H5T_vlen_get_alloc_info(dxpl_id, &vl_alloc_info) < 0) + if(H5CX_get_vlen_alloc_info(&vl_alloc_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info") /* Recurse on buffer to free dynamic fields */ - if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info->free_func, vl_alloc_info->free_info) < 0) + if(H5T_vlen_reclaim(elem, dt, &vl_alloc_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5T_vlen_reclaim_elmt */ - +} /* H5T_vlen_reclaim_elmt() */ |