summaryrefslogtreecommitdiffstats
path: root/src/H5Tref.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Tref.c')
-rw-r--r--src/H5Tref.c63
1 files changed, 40 insertions, 23 deletions
diff --git a/src/H5Tref.c b/src/H5Tref.c
index b357baa..7c59e75 100644
--- a/src/H5Tref.c
+++ b/src/H5Tref.c
@@ -144,7 +144,9 @@ H5T__ref_set_loc(const H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc)
switch(loc) {
case H5T_LOC_MEMORY: /* Memory based reference datatype */
- HDassert(NULL == file);
+
+ /* NB. We allow for the file to be non-NULL when doing
+ * memory-to-memory conversion */
/* Mark this type as being stored in memory */
dt->shared->u.atomic.u.r.loc = H5T_LOC_MEMORY;
@@ -364,9 +366,8 @@ static size_t
H5T__ref_mem_getsize(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf,
size_t H5_ATTR_UNUSED src_size, H5VL_object_t *dst_file, hbool_t *dst_copy)
{
- H5VL_object_t *vol_obj; /* VOL object for src ref's location */
+ H5VL_object_t *vol_obj = NULL; /* VOL object for src ref's location */
const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf;
- hbool_t files_equal = FALSE; /* Whether src & dst references are in same file */
char *file_name_buf_dyn = NULL; /* Pointer to dynamically allocated buffer for file name, if static buffer is too small */
unsigned flags = 0; /* References flags */
size_t ret_value = 0; /* Return value */
@@ -377,14 +378,18 @@ H5T__ref_mem_getsize(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf
HDassert(src_buf);
HDassert(src_size == H5T_REF_MEM_SIZE);
- /* Retrieve VOL object */
- if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier")
+ if(NULL != dst_file) {
+ hbool_t files_equal = TRUE; /* Whether src & dst references are in same file */
- /* Set external flag if referenced file is not destination file */
- if(H5VL_file_is_same(vol_obj, dst_file, &files_equal) < 0)
- HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOMPARE, 0, "can't check if files are equal")
- flags |= !files_equal ? H5R_IS_EXTERNAL : 0;
+ /* Retrieve VOL object */
+ if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier")
+
+ /* Set external flag if referenced file is not destination file */
+ if(H5VL_file_is_same(vol_obj, dst_file, &files_equal) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOMPARE, 0, "can't check if files are equal")
+ flags |= !files_equal ? H5R_IS_EXTERNAL : 0;
+ }
/* Force re-calculating encoding size if any flags are set */
if(flags || !src_ref->encode_size) {
@@ -458,8 +463,8 @@ H5T__ref_mem_read(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf,
{
H5VL_object_t *vol_obj; /* VOL object for src ref's location */
const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf;
- hbool_t files_equal = FALSE; /* Whether src & dst references are in same file */
- char file_name_buf_static[256]; /* File name */
+ hbool_t files_equal = TRUE; /* Whether src & dst references are in same file */
+ char file_name_buf_static[256] = {'\0'}; /* File name */
char *file_name_buf_dyn = NULL; /* Pointer to dynamically allocated buffer for file name, if static buffer is too small */
ssize_t file_name_len; /* Size of file name buffer */
unsigned flags = 0; /* References flags */
@@ -470,10 +475,15 @@ H5T__ref_mem_read(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf,
/* Sanity check */
HDassert(src_buf);
HDassert(src_size == H5T_REF_MEM_SIZE);
- HDassert(dst_file);
HDassert(dst_buf);
HDassert(dst_size);
+ /* Memory-to-memory conversion to support vlen conversion */
+ if(NULL == dst_file) {
+ HDmemcpy(dst_buf, src_buf, dst_size);
+ HGOTO_DONE(ret_value);
+ }
+
/* Retrieve VOL object */
if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier")
@@ -504,14 +514,16 @@ H5T__ref_mem_read(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf,
H5CX_set_libver_bounds(NULL);
} /* end if */
- /* Get file name */
- if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, H5I_FILE, sizeof(file_name_buf_static), file_name_buf_static, &file_name_len) < 0)
- HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, 0, "can't get file name")
- if(file_name_len >= (ssize_t)sizeof(file_name_buf_static)) {
- if(NULL == (file_name_buf_dyn = (char *)H5MM_malloc((size_t)file_name_len + 1)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, 0, "can't allocate space for file name")
- if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, H5I_FILE, (size_t)file_name_len + 1, file_name_buf_dyn, &file_name_len) < 0)
+ /* Get file name (if external reference) */
+ if(flags) {
+ if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, H5I_FILE, sizeof(file_name_buf_static), file_name_buf_static, &file_name_len) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, 0, "can't get file name")
+ if(file_name_len >= (ssize_t)sizeof(file_name_buf_static)) {
+ if(NULL == (file_name_buf_dyn = (char *)H5MM_malloc((size_t)file_name_len + 1)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, 0, "can't allocate space for file name")
+ if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, H5I_FILE, (size_t)file_name_len + 1, file_name_buf_dyn, &file_name_len) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, 0, "can't get file name")
+ } /* end if */
} /* end if */
/* Encode reference */
@@ -539,7 +551,7 @@ H5T__ref_mem_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size
H5R_type_t src_type, H5VL_object_t H5_ATTR_UNUSED *dst_file, void *dst_buf,
size_t dst_size, void H5_ATTR_UNUSED *bg_buf)
{
- H5F_t *src_f;
+ H5F_t *src_f = NULL;
hid_t file_id = H5I_INVALID_HID;
H5R_ref_priv_t *dst_ref = (H5R_ref_priv_t *)dst_buf;
herr_t ret_value = SUCCEED;
@@ -547,14 +559,19 @@ H5T__ref_mem_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size
FUNC_ENTER_STATIC
/* Sanity check */
- HDassert(src_file);
HDassert(src_buf);
HDassert(src_size);
HDassert(dst_buf);
HDassert(dst_size == H5T_REF_MEM_SIZE);
+ /* Memory-to-memory conversion to support vlen conversion */
+ if(NULL == src_file) {
+ HDmemcpy(dst_buf, src_buf, src_size);
+ HGOTO_DONE(ret_value);
+ }
+
#ifndef NDEBUG
- {
+ if((src_type == H5R_OBJECT1) || (src_type == H5R_DATASET_REGION1)) {
hbool_t is_native = FALSE; /* Whether the src file is using the native VOL connector */
/* Check if using native VOL connector */