diff options
Diffstat (limited to 'src')
153 files changed, 4541 insertions, 1347 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83240bd..9730436 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -533,6 +533,7 @@ set (H5S_SOURCES ${HDF5_SRC_DIR}/H5S.c ${HDF5_SRC_DIR}/H5Sall.c ${HDF5_SRC_DIR}/H5Sdbg.c + ${HDF5_SRC_DIR}/H5Sdeprec.c ${HDF5_SRC_DIR}/H5Shyper.c ${HDF5_SRC_DIR}/H5Smpio.c ${HDF5_SRC_DIR}/H5Snone.c @@ -1120,7 +1121,7 @@ target_link_libraries (${HDF5_LIB_TARGET} ) if (NOT WIN32) target_link_libraries (${HDF5_LIB_TARGET} - PUBLIC $<$<BOOL:${HDF5_ENABLE_THREADSAFE}>:Threads::Threads> + PRIVATE $<$<BOOL:${HDF5_ENABLE_THREADSAFE}>:Threads::Threads> ) endif () set_global_variable (HDF5_LIBRARIES_TO_EXPORT ${HDF5_LIB_TARGET}) @@ -1152,8 +1153,8 @@ if (BUILD_SHARED_LIBS) ) TARGET_C_PROPERTIES (${HDF5_LIBSH_TARGET} SHARED) target_link_libraries (${HDF5_LIBSH_TARGET} - PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS} "$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_LIBRARIES}>" - PUBLIC $<$<NOT:$<PLATFORM_ID:Windows>>:${CMAKE_DL_LIBS}> $<$<BOOL:${HDF5_ENABLE_THREADSAFE}>:Threads::Threads> + PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS} "$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_LIBRARIES}>" $<$<BOOL:${HDF5_ENABLE_THREADSAFE}>:Threads::Threads> + PUBLIC $<$<NOT:$<PLATFORM_ID:Windows>>:${CMAKE_DL_LIBS}> ) set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_LIBSH_TARGET}") H5_SET_LIB_OPTIONS (${HDF5_LIBSH_TARGET} ${HDF5_LIB_NAME} SHARED "LIB") @@ -214,7 +214,7 @@ H5_init_library(void) */ if(H5E_init() < 0) HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize error interface") - if(H5VL_init() < 0) + if(H5VL_init_phase1() < 0) HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize vol interface") if(H5P_init() < 0) HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize property list interface") @@ -229,6 +229,10 @@ H5_init_library(void) if(H5FS_init() < 0) HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize FS interface") + /* Finish initializing interfaces that depend on the interfaces above */ + if(H5VL_init_phase2() < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize vol interface") + /* Debugging? */ H5_debug_mask("-all"); H5_debug_mask(HDgetenv("HDF5_DEBUG")); diff --git a/src/H5Abtree2.c b/src/H5Abtree2.c index 07da8e2..3377aa2 100644 --- a/src/H5Abtree2.c +++ b/src/H5Abtree2.c @@ -35,6 +35,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Apkg.h" /* Attributes */ #include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ #include "H5SMprivate.h" /* Shared object header messages */ @@ -318,7 +319,7 @@ H5A__dense_btree2_name_encode(uint8_t *raw, const void *_nrecord, void H5_ATTR_U FUNC_ENTER_STATIC_NOERR /* Encode the record's fields */ - HDmemcpy(raw, nrecord->id.id, (size_t)H5O_FHEAP_ID_LEN); + H5MM_memcpy(raw, nrecord->id.id, (size_t)H5O_FHEAP_ID_LEN); raw += H5O_FHEAP_ID_LEN; *raw++ = nrecord->flags; UINT32ENCODE(raw, nrecord->corder) @@ -349,7 +350,7 @@ H5A__dense_btree2_name_decode(const uint8_t *raw, void *_nrecord, void H5_ATTR_U FUNC_ENTER_STATIC_NOERR /* Decode the record's fields */ - HDmemcpy(nrecord->id.id, raw, (size_t)H5O_FHEAP_ID_LEN); + H5MM_memcpy(nrecord->id.id, raw, (size_t)H5O_FHEAP_ID_LEN); raw += H5O_FHEAP_ID_LEN; nrecord->flags = *raw++; UINT32DECODE(raw, nrecord->corder) @@ -477,7 +478,7 @@ H5A__dense_btree2_corder_encode(uint8_t *raw, const void *_nrecord, void H5_ATTR FUNC_ENTER_STATIC_NOERR /* Encode the record's fields */ - HDmemcpy(raw, nrecord->id.id, (size_t)H5O_FHEAP_ID_LEN); + H5MM_memcpy(raw, nrecord->id.id, (size_t)H5O_FHEAP_ID_LEN); raw += H5O_FHEAP_ID_LEN; *raw++ = nrecord->flags; UINT32ENCODE(raw, nrecord->corder) @@ -507,7 +508,7 @@ H5A__dense_btree2_corder_decode(const uint8_t *raw, void *_nrecord, void H5_ATTR FUNC_ENTER_STATIC_NOERR /* Decode the record's fields */ - HDmemcpy(nrecord->id.id, raw, (size_t)H5O_FHEAP_ID_LEN); + H5MM_memcpy(nrecord->id.id, raw, (size_t)H5O_FHEAP_ID_LEN); raw += H5O_FHEAP_ID_LEN; nrecord->flags = *raw++; UINT32DECODE(raw, nrecord->corder) diff --git a/src/H5Adense.c b/src/H5Adense.c index 021fa76..81e0dc5 100644 --- a/src/H5Adense.c +++ b/src/H5Adense.c @@ -899,6 +899,7 @@ H5A__dense_rename(H5F_t *f, const H5O_ainfo_t *ainfo, const char *old_name, H5HF_t *fheap = NULL; /* Fractal heap handle */ H5HF_t *shared_fheap = NULL; /* Fractal heap handle for shared header messages */ H5B2_t *bt2_name = NULL; /* v2 B-tree handle for name index */ + H5B2_t *bt2_corder = NULL; /* v2 B-tree handle for creation order ndex */ H5A_t *attr_copy = NULL; /* Copy of attribute to rename */ htri_t attr_sharable; /* Flag indicating attributes are sharable */ htri_t shared_mesg; /* Should this message be stored in the Shared Message table? */ @@ -976,6 +977,33 @@ H5A__dense_rename(H5F_t *f, const H5O_ainfo_t *ainfo, const char *old_name, if(H5A__set_version(f, attr_copy) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "unable to update attribute version") + /* Need to remove the attribute from the creation order index v2 B-tree */ + if(ainfo->index_corder) { + htri_t corder_attr_exists; /* Attribute exists in v2 B-tree */ + + /* Open the creation order index v2 B-tree */ + HDassert(H5F_addr_defined(ainfo->corder_bt2_addr)); + if(NULL == (bt2_corder = H5B2_open(f, ainfo->corder_bt2_addr, NULL))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open v2 B-tree for creation index") + + /* Set up the creation order to search for */ + udata.corder = attr_copy->shared->crt_idx; + + if((corder_attr_exists = H5B2_find(bt2_corder, &udata, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "can't search for attribute in name index") + + if(corder_attr_exists) { + H5A_bt2_ud_rm_t rm_udata; + + /* Set up the creation order in user data for the v2 B-tree 'record remove' callback */ + rm_udata.common.corder = attr_copy->shared->crt_idx; + + /* Remove the record from the creation order index v2 B-tree */ + if(H5B2_remove(bt2_corder, &rm_udata, NULL, NULL) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTREMOVE, FAIL, "unable to remove attribute from creation order index v2 B-tree") + } + } + /* Insert renamed attribute back into dense storage */ /* (Possibly making it shared) */ if(H5A__dense_insert(f, ainfo, attr_copy) < 0) @@ -1023,6 +1051,8 @@ done: HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap") if(bt2_name && H5B2_close(bt2_name) < 0) HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for name index") + if(bt2_corder && H5B2_close(bt2_corder) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for creation order index") if(attr_copy) H5O_msg_free(H5O_ATTR_ID, attr_copy); diff --git a/src/H5Aint.c b/src/H5Aint.c index 6502fa4..d8ba92a 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -108,6 +108,7 @@ static herr_t H5A__iterate_common(hid_t loc_id, H5_index_t idx_type, const unsigned H5O_attr_ver_bounds[] = { H5O_ATTR_VERSION_1, /* H5F_LIBVER_EARLIEST */ H5O_ATTR_VERSION_3, /* H5F_LIBVER_V18 */ + H5O_ATTR_VERSION_3, /* H5F_LIBVER_V110 */ H5O_ATTR_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; @@ -646,21 +647,21 @@ H5A__read(const H5A_t *attr, const H5T_t *mem_type, void *buf) HGOTO_ERROR(H5E_ATTR, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy the attribute data into the buffer for conversion */ - HDmemcpy(tconv_buf, attr->shared->data, (src_type_size * nelmts)); + H5MM_memcpy(tconv_buf, attr->shared->data, (src_type_size * nelmts)); /* Perform datatype conversion. */ if(H5T_convert(tpath, src_id, dst_id, nelmts, (size_t)0, (size_t)0, tconv_buf, bkg_buf) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "datatype conversion failed") /* Copy the converted data into the user's buffer */ - HDmemcpy(buf, tconv_buf, (dst_type_size * nelmts)); + H5MM_memcpy(buf, tconv_buf, (dst_type_size * nelmts)); } /* end if */ /* No type conversion necessary */ else { HDassert(dst_type_size == src_type_size); /* Copy the attribute data into the user's buffer */ - HDmemcpy(buf, attr->shared->data, (dst_type_size * nelmts)); + H5MM_memcpy(buf, attr->shared->data, (dst_type_size * nelmts)); } /* end else */ } /* end else */ } /* end if */ @@ -747,7 +748,7 @@ H5A__write(H5A_t *attr, const H5T_t *mem_type, const void *buf) HGOTO_ERROR(H5E_ATTR, H5E_CANTALLOC, FAIL, "memory allocation failed") /* Copy the user's data into the buffer for conversion */ - HDmemcpy(tconv_buf, buf, (src_type_size * nelmts)); + H5MM_memcpy(tconv_buf, buf, (src_type_size * nelmts)); /* Perform datatype conversion */ if(H5T_convert(tpath, src_id, dst_id, nelmts, (size_t)0, (size_t)0, tconv_buf, bkg_buf) < 0) @@ -771,7 +772,7 @@ H5A__write(H5A_t *attr, const H5T_t *mem_type, const void *buf) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy the attribute data into the user's buffer */ - HDmemcpy(attr->shared->data, buf, (dst_type_size * nelmts)); + H5MM_memcpy(attr->shared->data, buf, (dst_type_size * nelmts)); } /* end else */ /* Modify the attribute in the object header */ @@ -827,7 +828,7 @@ H5A__get_name(H5A_t *attr, size_t buf_size, char *buf) /* Copy all/some of the name */ if(buf && copy_len > 0) { - HDmemcpy(buf, attr->shared->name, copy_len); + H5MM_memcpy(buf, attr->shared->name, copy_len); /* Terminate the string */ buf[copy_len]='\0'; @@ -2240,7 +2241,7 @@ H5A__attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_s if(NULL == (buf = H5FL_BLK_MALLOC(attr_buf, buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation NULLed for raw data chunk") - HDmemcpy(buf, attr_src->shared->data, attr_src->shared->data_size); + H5MM_memcpy(buf, attr_src->shared->data, attr_src->shared->data_size); /* Allocate background memory */ if(H5T_path_bkg(tpath_src_mem) || H5T_path_bkg(tpath_mem_dst)) @@ -2251,7 +2252,7 @@ H5A__attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_s if(H5T_convert(tpath_src_mem, tid_src, tid_mem, nelmts, (size_t)0, (size_t)0, buf, bkg_buf) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "datatype conversion NULLed") - HDmemcpy(reclaim_buf, buf, buf_size); + H5MM_memcpy(reclaim_buf, buf, buf_size); /* Set background buffer to all zeros */ if(bkg_buf) @@ -2261,14 +2262,14 @@ H5A__attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_s if(H5T_convert(tpath_mem_dst, tid_mem, tid_dst, nelmts, (size_t)0, (size_t)0, buf, bkg_buf) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "datatype conversion NULLed") - HDmemcpy(attr_dst->shared->data, buf, attr_dst->shared->data_size); + H5MM_memcpy(attr_dst->shared->data, buf, attr_dst->shared->data_size); if(H5D_vlen_reclaim(tid_mem, buf_space, reclaim_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_BADITER, NULL, "unable to reclaim variable-length data") } /* end if */ else { HDassert(attr_dst->shared->data_size == attr_src->shared->data_size); - HDmemcpy(attr_dst->shared->data, attr_src->shared->data, attr_src->shared->data_size); + H5MM_memcpy(attr_dst->shared->data, attr_src->shared->data, attr_src->shared->data_size); } /* end else */ } /* end if(attr_src->shared->data) */ @@ -107,6 +107,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Iprivate.h" /* IDs */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ @@ -484,10 +485,10 @@ H5B__split(H5F_t *f, H5B_ins_ud_t *bt_ud, unsigned idx, */ split_bt_ud->cache_flags = H5AC__DIRTIED_FLAG; - HDmemcpy(split_bt_ud->bt->native, + H5MM_memcpy(split_bt_ud->bt->native, bt_ud->bt->native + nleft * shared->type->sizeof_nkey, (nright + 1) * shared->type->sizeof_nkey); - HDmemcpy(split_bt_ud->bt->child, + H5MM_memcpy(split_bt_ud->bt->child, &bt_ud->bt->child[nleft], nright * sizeof(haddr_t)); @@ -612,9 +613,9 @@ H5B_insert(H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata) /* update left and right keys */ if(!lt_key_changed) - HDmemcpy(lt_key, H5B_NKEY(bt_ud.bt,shared,0), type->sizeof_nkey); + H5MM_memcpy(lt_key, H5B_NKEY(bt_ud.bt,shared,0), type->sizeof_nkey); if(!rt_key_changed) - HDmemcpy(rt_key, H5B_NKEY(split_bt_ud.bt,shared,split_bt_ud.bt->nchildren), type->sizeof_nkey); + H5MM_memcpy(rt_key, H5B_NKEY(split_bt_ud.bt,shared,split_bt_ud.bt->nchildren), type->sizeof_nkey); /* * Copy the old root node to some other file location and make the new root @@ -657,11 +658,11 @@ H5B_insert(H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata) new_root_bt->nchildren = 2; new_root_bt->child[0] = bt_ud.addr; - HDmemcpy(H5B_NKEY(new_root_bt, shared, 0), lt_key, shared->type->sizeof_nkey); + H5MM_memcpy(H5B_NKEY(new_root_bt, shared, 0), lt_key, shared->type->sizeof_nkey); new_root_bt->child[1] = split_bt_ud.addr; - HDmemcpy(H5B_NKEY(new_root_bt, shared, 1), md_key, shared->type->sizeof_nkey); - HDmemcpy(H5B_NKEY(new_root_bt, shared, 2), rt_key, shared->type->sizeof_nkey); + H5MM_memcpy(H5B_NKEY(new_root_bt, shared, 1), md_key, shared->type->sizeof_nkey); + H5MM_memcpy(H5B_NKEY(new_root_bt, shared, 2), rt_key, shared->type->sizeof_nkey); /* Insert the modified copy of the old root into the file again */ if(H5AC_insert_entry(f, H5AC_BT, addr, new_root_bt, H5AC__NO_FLAGS_SET) < 0) @@ -726,9 +727,9 @@ H5B__insert_child(H5B_t *bt, unsigned *bt_flags, unsigned idx, base = H5B_NKEY(bt, shared, (idx + 1)); if((idx + 1) == bt->nchildren) { /* Make room for the new key */ - HDmemcpy(base + shared->type->sizeof_nkey, base, + H5MM_memcpy(base + shared->type->sizeof_nkey, base, shared->type->sizeof_nkey); /* No overlap possible - memcpy() OK */ - HDmemcpy(base, md_key, shared->type->sizeof_nkey); + H5MM_memcpy(base, md_key, shared->type->sizeof_nkey); /* The MD_KEY is the left key of the new node */ if(H5B_INS_RIGHT == anchor) @@ -741,7 +742,7 @@ H5B__insert_child(H5B_t *bt, unsigned *bt_flags, unsigned idx, /* Make room for the new key */ HDmemmove(base + shared->type->sizeof_nkey, base, (bt->nchildren - idx) * shared->type->sizeof_nkey); - HDmemcpy(base, md_key, shared->type->sizeof_nkey); + H5MM_memcpy(base, md_key, shared->type->sizeof_nkey); /* The MD_KEY is the left key of the new node */ if(H5B_INS_RIGHT == anchor) @@ -915,7 +916,7 @@ H5B__insert_helper(H5F_t *f, H5B_ins_ud_t *bt_ud, const H5B_class_t *type, * node. This node is not empty (handled above). */ my_ins = H5B_INS_LEFT; - HDmemcpy(md_key, H5B_NKEY(bt,shared,idx), type->sizeof_nkey); + H5MM_memcpy(md_key, H5B_NKEY(bt,shared,idx), type->sizeof_nkey); if((type->new_node)(f, H5B_INS_LEFT, H5B_NKEY(bt, shared, idx), udata, md_key, &new_child_bt_ud.addr/*out*/) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum leaf node") @@ -963,7 +964,7 @@ H5B__insert_helper(H5F_t *f, H5B_ins_ud_t *bt_ud, const H5B_class_t *type, */ idx = bt->nchildren - 1; my_ins = H5B_INS_RIGHT; - HDmemcpy(md_key, H5B_NKEY(bt, shared, idx + 1), type->sizeof_nkey); + H5MM_memcpy(md_key, H5B_NKEY(bt, shared, idx + 1), type->sizeof_nkey); if((type->new_node)(f, H5B_INS_RIGHT, md_key, udata, H5B_NKEY(bt, shared, idx + 1), &new_child_bt_ud.addr/*out*/) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum leaf node") @@ -1021,7 +1022,7 @@ H5B__insert_helper(H5F_t *f, H5B_ins_ud_t *bt_ud, const H5B_class_t *type, *lt_key_changed = FALSE; } /* end if */ else - HDmemcpy(lt_key, H5B_NKEY(bt, shared, idx), type->sizeof_nkey); + H5MM_memcpy(lt_key, H5B_NKEY(bt, shared, idx), type->sizeof_nkey); } /* end if */ if(*rt_key_changed) { bt_ud->cache_flags |= H5AC__DIRTIED_FLAG; @@ -1031,7 +1032,7 @@ H5B__insert_helper(H5F_t *f, H5B_ins_ud_t *bt_ud, const H5B_class_t *type, *rt_key_changed = FALSE; } /* end if */ else - HDmemcpy(rt_key, H5B_NKEY(bt, shared, idx + 1), type->sizeof_nkey); + H5MM_memcpy(rt_key, H5B_NKEY(bt, shared, idx + 1), type->sizeof_nkey); } /* end if */ /* @@ -1080,7 +1081,7 @@ H5B__insert_helper(H5F_t *f, H5B_ins_ud_t *bt_ud, const H5B_class_t *type, * by the left and right node). */ if(split_bt_ud->bt) { - HDmemcpy(md_key, H5B_NKEY(split_bt_ud->bt, shared, 0), type->sizeof_nkey); + H5MM_memcpy(md_key, H5B_NKEY(split_bt_ud->bt, shared, 0), type->sizeof_nkey); ret_value = H5B_INS_RIGHT; #ifdef H5B_DEBUG /* @@ -1339,7 +1340,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, /* Don't propagate change out of this B-tree node */ *lt_key_changed = FALSE; else - HDmemcpy(lt_key, H5B_NKEY(bt, shared, idx), type->sizeof_nkey); + H5MM_memcpy(lt_key, H5B_NKEY(bt, shared, idx), type->sizeof_nkey); } /* end if */ if(*rt_key_changed) { HDassert(type->critical_key == H5B_RIGHT); @@ -1348,7 +1349,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, /* Don't propagate change out of this B-tree node */ *rt_key_changed = FALSE; else - HDmemcpy(rt_key, H5B_NKEY(bt, shared, idx + 1), type->sizeof_nkey); + H5MM_memcpy(rt_key, H5B_NKEY(bt, shared, idx + 1), type->sizeof_nkey); } /* end if */ /* @@ -1383,7 +1384,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, * in its left neighbor, but only if it is not the critical * key for the right-most child of the left neighbor */ if(type->critical_key == H5B_LEFT) - HDmemcpy(H5B_NKEY(sibling, shared, sibling->nchildren), + H5MM_memcpy(H5B_NKEY(sibling, shared, sibling->nchildren), H5B_NKEY(bt, shared, 1), type->sizeof_nkey); sibling->right = bt->right; @@ -1400,7 +1401,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, * its right neighbor, but only if it is not the critical * key for the left-most child of the right neighbor */ if(type->critical_key == H5B_RIGHT) - HDmemcpy(H5B_NKEY(sibling, shared, 0), + H5MM_memcpy(H5B_NKEY(sibling, shared, 0), H5B_NKEY(bt, shared, 0), type->sizeof_nkey); sibling->left = bt->left; @@ -1442,7 +1443,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, /* Slide all keys down 1, update lt_key */ HDmemmove(H5B_NKEY(bt, shared, 0), H5B_NKEY(bt, shared, 1), bt->nchildren * type->sizeof_nkey); - HDmemcpy(lt_key, H5B_NKEY(bt, shared, 0), type->sizeof_nkey); + H5MM_memcpy(lt_key, H5B_NKEY(bt, shared, 0), type->sizeof_nkey); *lt_key_changed = TRUE; } else /* Slide all but the leftmost 2 keys down, leaving the leftmost @@ -1471,7 +1472,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, H5B_NKEY(bt, shared, bt->nchildren), type->sizeof_nkey); else { /* Just update rt_key */ - HDmemcpy(rt_key, H5B_NKEY(bt, shared, bt->nchildren - 1), + H5MM_memcpy(rt_key, H5B_NKEY(bt, shared, bt->nchildren - 1), type->sizeof_nkey); *rt_key_changed = TRUE; } /* end else */ @@ -1516,7 +1517,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, if(NULL == (sibling = (H5B_t *)H5AC_protect(f, H5AC_BT, bt->left, &cache_udata, H5AC__NO_FLAGS_SET))) HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, H5B_INS_ERROR, "unable to protect node") - HDmemcpy(H5B_NKEY(sibling, shared, sibling->nchildren), + H5MM_memcpy(H5B_NKEY(sibling, shared, sibling->nchildren), H5B_NKEY(bt, shared, 0), type->sizeof_nkey); if(H5AC_unprotect(f, H5AC_BT, bt->left, sibling, H5AC__DIRTIED_FLAG) < 0) @@ -1531,7 +1532,7 @@ H5B__remove_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, int level, if(NULL == (sibling = (H5B_t *)H5AC_protect(f, H5AC_BT, bt->right, &cache_udata, H5AC__NO_FLAGS_SET))) HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, H5B_INS_ERROR, "unable to protect node") - HDmemcpy(H5B_NKEY(sibling, shared, 0), + H5MM_memcpy(H5B_NKEY(sibling, shared, 0), H5B_NKEY(bt, shared, bt->nchildren), type->sizeof_nkey); if(H5AC_unprotect(f, H5AC_BT, bt->right, sibling, H5AC__DIRTIED_FLAG) < 0) @@ -1811,7 +1812,7 @@ H5B__copy(const H5B_t *old_bt) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for B-tree root node") /* Copy the main structure */ - HDmemcpy(new_node, old_bt, sizeof(H5B_t)); + H5MM_memcpy(new_node, old_bt, sizeof(H5B_t)); /* Reset cache info */ HDmemset(&new_node->cache_info, 0, sizeof(H5AC_info_t)); @@ -1821,8 +1822,8 @@ H5B__copy(const H5B_t *old_bt) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for B-tree root node") /* Copy the other structures */ - HDmemcpy(new_node->native, old_bt->native, shared->sizeof_keys); - HDmemcpy(new_node->child, old_bt->child, (sizeof(haddr_t) * shared->two_k)); + H5MM_memcpy(new_node->native, old_bt->native, shared->sizeof_keys); + H5MM_memcpy(new_node->child, old_bt->child, (sizeof(haddr_t) * shared->two_k)); /* Increment the ref-count on the raw page */ H5UC_INC(new_node->rc_shared); @@ -662,7 +662,7 @@ H5B2_find(H5B2_t *bt2, void *udata, H5B2_found_t op, void *op_data) if(hdr->min_native_rec == NULL) if(NULL == (hdr->min_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info") - HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ if(idx == (unsigned)(leaf->nrec - 1)) { @@ -670,7 +670,7 @@ H5B2_find(H5B2_t *bt2, void *udata, H5B2_found_t op, void *op_data) if(hdr->max_native_rec == NULL) if(NULL == (hdr->max_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info") - HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ } /* end if */ @@ -1343,7 +1343,7 @@ H5B2_modify(H5B2_t *bt2, void *udata, H5B2_modify_t op, void *op_data) if(hdr->min_native_rec == NULL) if(NULL == (hdr->min_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info") - HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ if(idx == (unsigned)(leaf->nrec - 1)) { @@ -1351,7 +1351,7 @@ H5B2_modify(H5B2_t *bt2, void *udata, H5B2_modify_t op, void *op_data) if(hdr->max_native_rec == NULL) if(NULL == (hdr->max_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info") - HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ } /* end if */ diff --git a/src/H5B2cache.c b/src/H5B2cache.c index 2e1d37b..2a77bd5 100644 --- a/src/H5B2cache.c +++ b/src/H5B2cache.c @@ -391,7 +391,7 @@ H5B2__cache_hdr_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED le HDassert(hdr); /* Magic number */ - HDmemcpy(image, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -811,7 +811,7 @@ H5B2__cache_int_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED le HDassert(internal->hdr); /* Magic number */ - HDmemcpy(image, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -1212,7 +1212,7 @@ H5B2__cache_leaf_serialize(const H5F_t H5_ATTR_UNUSED *f, void *_image, size_t H HDassert(leaf->hdr); /* magic number */ - HDmemcpy(image, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* version # */ diff --git a/src/H5B2int.c b/src/H5B2int.c index b3f855f..9940cd7 100644 --- a/src/H5B2int.c +++ b/src/H5B2int.c @@ -35,6 +35,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5B2pkg.h" /* v2 B-trees */ #include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vectors and arrays */ @@ -241,17 +242,17 @@ H5B2__split1(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node_ptr, mid_record = old_node_nrec / 2; /* Copy "upper half" of records to new child */ - HDmemcpy(H5B2_NAT_NREC(right_native, hdr, 0), + H5MM_memcpy(H5B2_NAT_NREC(right_native, hdr, 0), H5B2_NAT_NREC(left_native, hdr, mid_record + (unsigned)1), hdr->cls->nrec_size * (old_node_nrec - (mid_record + (unsigned)1))); /* Copy "upper half" of node pointers, if the node is an internal node */ if(depth > 1) - HDmemcpy(&(right_node_ptrs[0]), &(left_node_ptrs[mid_record + (unsigned)1]), + H5MM_memcpy(&(right_node_ptrs[0]), &(left_node_ptrs[mid_record + (unsigned)1]), sizeof(H5B2_node_ptr_t) * (size_t)(old_node_nrec - mid_record)); /* Copy "middle" record to internal node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(left_native, hdr, mid_record), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(left_native, hdr, mid_record), hdr->cls->nrec_size); /* Mark nodes as dirty */ left_child_flags |= H5AC__DIRTIED_FLAG; @@ -510,14 +511,14 @@ H5B2__redistribute2(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, uint16_t move_nrec = (uint16_t)(*right_nrec - new_right_nrec); /* Number of records to move from right node to left */ /* Copy record from parent node down into left child */ - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); /* See if we need to move records from right node */ if(move_nrec > 1) - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, (*left_nrec + 1)), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (size_t)(move_nrec - 1)); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, (*left_nrec + 1)), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (size_t)(move_nrec - 1)); /* Move record from right node into parent node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(right_native, hdr, (move_nrec - 1)), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(right_native, hdr, (move_nrec - 1)), hdr->cls->nrec_size); /* Slide records in right node down */ HDmemmove(H5B2_NAT_NREC(right_native, hdr, 0), H5B2_NAT_NREC(right_native, hdr, move_nrec), hdr->cls->nrec_size * new_right_nrec); @@ -534,7 +535,7 @@ H5B2__redistribute2(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, right_moved_nrec -= (hssize_t)moved_nrec; /* Copy node pointers from right node to left */ - HDmemcpy(&(left_node_ptrs[*left_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * move_nrec); + H5MM_memcpy(&(left_node_ptrs[*left_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * move_nrec); /* Slide node pointers in right node down */ HDmemmove(&(right_node_ptrs[0]), &(right_node_ptrs[move_nrec]), sizeof(H5B2_node_ptr_t) * (new_right_nrec + (unsigned)1)); @@ -569,14 +570,14 @@ H5B2__redistribute2(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, hdr->cls->nrec_size * (*right_nrec)); /* Copy record from parent node down into right child */ - HDmemcpy(H5B2_NAT_NREC(right_native, hdr, (move_nrec - 1)), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(right_native, hdr, (move_nrec - 1)), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); /* See if we need to move records from left node */ if(move_nrec > 1) - HDmemcpy(H5B2_NAT_NREC(right_native, hdr, 0), H5B2_NAT_NREC(left_native, hdr, ((*left_nrec - move_nrec) + 1)), hdr->cls->nrec_size * (size_t)(move_nrec - 1)); + H5MM_memcpy(H5B2_NAT_NREC(right_native, hdr, 0), H5B2_NAT_NREC(left_native, hdr, ((*left_nrec - move_nrec) + 1)), hdr->cls->nrec_size * (size_t)(move_nrec - 1)); /* Move record from left node into parent node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(left_native, hdr, (*left_nrec - move_nrec)), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(left_native, hdr, (*left_nrec - move_nrec)), hdr->cls->nrec_size); /* Handle node pointers, if we have an internal node */ if(depth > 1) { @@ -587,7 +588,7 @@ H5B2__redistribute2(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, HDmemmove(&(right_node_ptrs[move_nrec]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * (size_t)(*right_nrec + 1)); /* Copy node pointers from left node to right */ - HDmemcpy(&(right_node_ptrs[0]), &(left_node_ptrs[new_left_nrec + 1]), sizeof(H5B2_node_ptr_t) * move_nrec); + H5MM_memcpy(&(right_node_ptrs[0]), &(left_node_ptrs[new_left_nrec + 1]), sizeof(H5B2_node_ptr_t) * move_nrec); /* Count the number of records being moved */ for(u = 0; u < move_nrec; u++) @@ -775,16 +776,16 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, uint16_t moved_middle_nrec = 0; /* Number of records moved into left node */ /* Move left parent record down to left node */ - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx - 1), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx - 1), hdr->cls->nrec_size); /* Move records from middle node into left node */ if((new_left_nrec - 1) > *left_nrec) { moved_middle_nrec = (uint16_t)(new_left_nrec - (*left_nrec + 1)); - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec + 1), H5B2_NAT_NREC(middle_native, hdr, 0), hdr->cls->nrec_size * moved_middle_nrec); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec + 1), H5B2_NAT_NREC(middle_native, hdr, 0), hdr->cls->nrec_size * moved_middle_nrec); } /* end if */ /* Move record from middle node up to parent node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx - 1), H5B2_NAT_NREC(middle_native, hdr, moved_middle_nrec), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx - 1), H5B2_NAT_NREC(middle_native, hdr, moved_middle_nrec), hdr->cls->nrec_size); moved_middle_nrec++; /* Slide records in middle node down */ @@ -798,7 +799,7 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, /* Move middle node pointers into left node */ move_nptrs = (unsigned)(new_left_nrec - *left_nrec); - HDmemcpy(&(left_node_ptrs[*left_nrec + 1]), &(middle_node_ptrs[0]), sizeof(H5B2_node_ptr_t)*move_nptrs); + H5MM_memcpy(&(left_node_ptrs[*left_nrec + 1]), &(middle_node_ptrs[0]), sizeof(H5B2_node_ptr_t)*move_nptrs); /* Count the number of records being moved into the left node */ for(u = 0, moved_nrec = 0; u < move_nptrs; u++) @@ -832,14 +833,14 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, HDmemmove(H5B2_NAT_NREC(right_native, hdr, right_nrec_move), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (*right_nrec)); /* Move right parent record down to right node */ - HDmemcpy(H5B2_NAT_NREC(right_native, hdr, right_nrec_move - 1), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(right_native, hdr, right_nrec_move - 1), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); /* Move records from middle node into right node */ if(right_nrec_move > 1) - HDmemcpy(H5B2_NAT_NREC(right_native, hdr, 0), H5B2_NAT_NREC(middle_native, hdr, ((curr_middle_nrec - right_nrec_move) + 1)), hdr->cls->nrec_size * (right_nrec_move - 1)); + H5MM_memcpy(H5B2_NAT_NREC(right_native, hdr, 0), H5B2_NAT_NREC(middle_native, hdr, ((curr_middle_nrec - right_nrec_move) + 1)), hdr->cls->nrec_size * (right_nrec_move - 1)); /* Move record from middle node up to parent node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(middle_native, hdr, (curr_middle_nrec - right_nrec_move)), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(middle_native, hdr, (curr_middle_nrec - right_nrec_move)), hdr->cls->nrec_size); /* Move node pointers also if this is an internal node */ if(depth > 1) { @@ -850,7 +851,7 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, HDmemmove(&(right_node_ptrs[right_nrec_move]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * (size_t)(*right_nrec + 1)); /* Move middle node pointers into right node */ - HDmemcpy(&(right_node_ptrs[0]), &(middle_node_ptrs[(curr_middle_nrec - right_nrec_move) + 1]), sizeof(H5B2_node_ptr_t) * right_nrec_move); + H5MM_memcpy(&(right_node_ptrs[0]), &(middle_node_ptrs[(curr_middle_nrec - right_nrec_move) + 1]), sizeof(H5B2_node_ptr_t) * right_nrec_move); /* Count the number of records being moved into the right node */ for(u = 0, moved_nrec = 0; u < right_nrec_move; u++) @@ -881,14 +882,14 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, HDmemmove(H5B2_NAT_NREC(middle_native, hdr, left_nrec_move), H5B2_NAT_NREC(middle_native, hdr, 0), hdr->cls->nrec_size * curr_middle_nrec); /* Move left parent record down to middle node */ - HDmemcpy(H5B2_NAT_NREC(middle_native, hdr, left_nrec_move - 1), H5B2_INT_NREC(internal, hdr, idx - 1), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(middle_native, hdr, left_nrec_move - 1), H5B2_INT_NREC(internal, hdr, idx - 1), hdr->cls->nrec_size); /* Move left records to middle node */ if(left_nrec_move > 1) HDmemmove(H5B2_NAT_NREC(middle_native, hdr, 0), H5B2_NAT_NREC(left_native, hdr, new_left_nrec + 1), hdr->cls->nrec_size * (left_nrec_move - 1)); /* Move left parent record up from left node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx - 1), H5B2_NAT_NREC(left_native, hdr, new_left_nrec), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx - 1), H5B2_NAT_NREC(left_native, hdr, new_left_nrec), hdr->cls->nrec_size); /* Move node pointers also if this is an internal node */ if(depth > 1) { @@ -899,7 +900,7 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, HDmemmove(&(middle_node_ptrs[left_nrec_move]), &(middle_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * (size_t)(curr_middle_nrec + 1)); /* Move left node pointers into middle node */ - HDmemcpy(&(middle_node_ptrs[0]), &(left_node_ptrs[new_left_nrec + 1]), sizeof(H5B2_node_ptr_t) * left_nrec_move); + H5MM_memcpy(&(middle_node_ptrs[0]), &(left_node_ptrs[new_left_nrec + 1]), sizeof(H5B2_node_ptr_t) * left_nrec_move); /* Count the number of records being moved into the left node */ for(u = 0, moved_nrec = 0; u < left_nrec_move; u++) @@ -927,13 +928,13 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, unsigned right_nrec_move = (unsigned)(*right_nrec - new_right_nrec); /* Number of records to move out of right node */ /* Move right parent record down to middle node */ - HDmemcpy(H5B2_NAT_NREC(middle_native, hdr, curr_middle_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(middle_native, hdr, curr_middle_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); /* Move right records to middle node */ HDmemmove(H5B2_NAT_NREC(middle_native, hdr, (curr_middle_nrec + 1)), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (right_nrec_move - 1)); /* Move right parent record up from right node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(right_native, hdr, right_nrec_move - 1), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx), H5B2_NAT_NREC(right_native, hdr, right_nrec_move - 1), hdr->cls->nrec_size); /* Slide right records down */ HDmemmove(H5B2_NAT_NREC(right_native, hdr, 0), H5B2_NAT_NREC(right_native, hdr, right_nrec_move), hdr->cls->nrec_size * new_right_nrec); @@ -944,7 +945,7 @@ H5B2__redistribute3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, unsigned u; /* Local index variable */ /* Move right node pointers into middle node */ - HDmemcpy(&(middle_node_ptrs[curr_middle_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * right_nrec_move); + H5MM_memcpy(&(middle_node_ptrs[curr_middle_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * right_nrec_move); /* Count the number of records being moved into the right node */ for(u = 0, moved_nrec = 0; u < right_nrec_move; u++) @@ -1113,14 +1114,14 @@ H5B2__merge2(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node_ptr, /* Redistribute records into left node */ { /* Copy record from parent node to proper location */ - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); /* Copy records from right node to left node */ - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec + 1), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (*right_nrec)); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec + 1), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (*right_nrec)); /* Copy node pointers from right node into left node */ if(depth > 1) - HDmemcpy(&(left_node_ptrs[*left_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * (size_t)(*right_nrec + 1)); + H5MM_memcpy(&(left_node_ptrs[*left_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * (size_t)(*right_nrec + 1)); /* Update flush dependencies for grandchildren, if using SWMR */ if(hdr->swmr_write && depth > 1) @@ -1304,13 +1305,13 @@ H5B2__merge3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node_ptr, middle_moved_nrec = middle_nrec_move; /* Copy record from parent node to proper location in left node */ - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx - 1), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec), H5B2_INT_NREC(internal, hdr, idx - 1), hdr->cls->nrec_size); /* Copy records from middle node to left node */ - HDmemcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec + 1), H5B2_NAT_NREC(middle_native, hdr, 0), hdr->cls->nrec_size * (middle_nrec_move - 1)); + H5MM_memcpy(H5B2_NAT_NREC(left_native, hdr, *left_nrec + 1), H5B2_NAT_NREC(middle_native, hdr, 0), hdr->cls->nrec_size * (middle_nrec_move - 1)); /* Copy record from middle node to proper location in parent node */ - HDmemcpy(H5B2_INT_NREC(internal, hdr, idx - 1), H5B2_NAT_NREC(middle_native, hdr, (middle_nrec_move - 1)), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_INT_NREC(internal, hdr, idx - 1), H5B2_NAT_NREC(middle_native, hdr, (middle_nrec_move - 1)), hdr->cls->nrec_size); /* Slide records in middle node down */ HDmemmove(H5B2_NAT_NREC(middle_native, hdr, 0), H5B2_NAT_NREC(middle_native, hdr, middle_nrec_move), hdr->cls->nrec_size * (*middle_nrec - middle_nrec_move)); @@ -1320,7 +1321,7 @@ H5B2__merge3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node_ptr, unsigned u; /* Local index variable */ /* Copy node pointers from middle node into left node */ - HDmemcpy(&(left_node_ptrs[*left_nrec + 1]), &(middle_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * middle_nrec_move); + H5MM_memcpy(&(left_node_ptrs[*left_nrec + 1]), &(middle_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * middle_nrec_move); /* Count the number of records being moved into the left node */ for(u = 0; u < middle_nrec_move; u++) @@ -1348,15 +1349,15 @@ H5B2__merge3(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node_ptr, /* Redistribute records into middle node */ { /* Copy record from parent node to proper location in middle node */ - HDmemcpy(H5B2_NAT_NREC(middle_native, hdr, *middle_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(middle_native, hdr, *middle_nrec), H5B2_INT_NREC(internal, hdr, idx), hdr->cls->nrec_size); /* Copy records from right node to middle node */ - HDmemcpy(H5B2_NAT_NREC(middle_native, hdr, *middle_nrec + 1), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (*right_nrec)); + H5MM_memcpy(H5B2_NAT_NREC(middle_native, hdr, *middle_nrec + 1), H5B2_NAT_NREC(right_native, hdr, 0), hdr->cls->nrec_size * (*right_nrec)); /* Move node pointers also if this is an internal node */ if(depth > 1) /* Copy node pointers from right node into middle node */ - HDmemcpy(&(middle_node_ptrs[*middle_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * (size_t)(*right_nrec + 1)); + H5MM_memcpy(&(middle_node_ptrs[*middle_nrec + 1]), &(right_node_ptrs[0]), sizeof(H5B2_node_ptr_t) * (size_t)(*right_nrec + 1)); /* Update flush dependencies for grandchildren, if using SWMR */ if(hdr->swmr_write && depth > 1) @@ -1539,7 +1540,7 @@ H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree internal node pointers") /* Copy the node pointers */ - HDmemcpy(node_ptrs, internal->node_ptrs, (sizeof(H5B2_node_ptr_t) * (size_t)(curr_node->node_nrec + 1))); + H5MM_memcpy(node_ptrs, internal->node_ptrs, (sizeof(H5B2_node_ptr_t) * (size_t)(curr_node->node_nrec + 1))); } /* end if */ else { H5B2_leaf_t *leaf; /* Pointer to leaf node */ @@ -1559,7 +1560,7 @@ H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree internal native keys") /* Copy the native keys */ - HDmemcpy(native, node_native, (hdr->cls->nrec_size * curr_node->node_nrec)); + H5MM_memcpy(native, node_native, (hdr->cls->nrec_size * curr_node->node_nrec)); /* Unlock the node */ if(H5AC_unprotect(hdr->f, curr_node_class, curr_node->addr, node, (unsigned)(hdr->swmr_write ? H5AC__PIN_ENTRY_FLAG : H5AC__NO_FLAGS_SET)) < 0) diff --git a/src/H5B2leaf.c b/src/H5B2leaf.c index 54d40ea..beca40c 100644 --- a/src/H5B2leaf.c +++ b/src/H5B2leaf.c @@ -412,7 +412,7 @@ H5B2__insert_leaf(H5B2_hdr_t *hdr, H5B2_node_ptr_t *curr_node_ptr, if(hdr->min_native_rec == NULL) if(NULL == (hdr->min_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info") - HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ if(idx == (unsigned)(leaf->nrec - 1)) { @@ -420,7 +420,7 @@ H5B2__insert_leaf(H5B2_hdr_t *hdr, H5B2_node_ptr_t *curr_node_ptr, if(hdr->max_native_rec == NULL) if(NULL == (hdr->max_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info") - HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ } /* end if */ @@ -561,7 +561,7 @@ H5B2__update_leaf(H5B2_hdr_t *hdr, H5B2_node_ptr_t *curr_node_ptr, if(hdr->min_native_rec == NULL) if(NULL == (hdr->min_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info") - HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ if(idx == (unsigned)(leaf->nrec - 1)) { @@ -569,7 +569,7 @@ H5B2__update_leaf(H5B2_hdr_t *hdr, H5B2_node_ptr_t *curr_node_ptr, if(hdr->max_native_rec == NULL) if(NULL == (hdr->max_native_rec = H5MM_malloc(hdr->cls->nrec_size))) HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info") - HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); + H5MM_memcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size); } /* end if */ } /* end if */ } /* end if */ @@ -664,9 +664,9 @@ H5B2__swap_leaf(H5B2_hdr_t *hdr, uint16_t depth, H5B2_internal_t *internal, } /* end else */ /* Swap records (use disk page as temporary buffer) */ - HDmemcpy(hdr->page, H5B2_NAT_NREC(child_native, hdr, 0), hdr->cls->nrec_size); - HDmemcpy(H5B2_NAT_NREC(child_native, hdr, 0), swap_loc, hdr->cls->nrec_size); - HDmemcpy(swap_loc, hdr->page, hdr->cls->nrec_size); + H5MM_memcpy(hdr->page, H5B2_NAT_NREC(child_native, hdr, 0), hdr->cls->nrec_size); + H5MM_memcpy(H5B2_NAT_NREC(child_native, hdr, 0), swap_loc, hdr->cls->nrec_size); + H5MM_memcpy(swap_loc, hdr->page, hdr->cls->nrec_size); /* Mark parent as dirty */ *internal_flags_ptr |= H5AC__DIRTIED_FLAG; diff --git a/src/H5Bcache.c b/src/H5Bcache.c index a0a75c8..c2c7a80 100644 --- a/src/H5Bcache.c +++ b/src/H5Bcache.c @@ -35,6 +35,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Bpkg.h" /* B-link trees */ #include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -304,7 +305,7 @@ H5B__cache_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, HDassert(shared->type->encode); /* magic number */ - HDmemcpy(image, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += 4; /* node type and level */ @@ -2285,7 +2285,7 @@ H5C_protect(H5F_t * f, if(NULL == (entry_ptr->image_ptr = H5MM_malloc(entry_ptr->size + H5C_IMAGE_EXTRA_SPACE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "memory allocation failed for on disk image buffer") #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(((uint8_t *)entry_ptr->image_ptr) + entry_ptr->size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(((uint8_t *)entry_ptr->image_ptr) + entry_ptr->size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ if(0 == mpi_rank) if(H5C__generate_image(f, cache_ptr, entry_ptr) < 0) @@ -6042,7 +6042,7 @@ H5C__flush_single_entry(H5F_t *f, H5C_cache_entry_t *entry_ptr, unsigned flags) if(NULL == (entry_ptr->image_ptr = H5MM_malloc(entry_ptr->size + H5C_IMAGE_EXTRA_SPACE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed for on disk image buffer") #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(((uint8_t *)entry_ptr->image_ptr) + entry_ptr->size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(((uint8_t *)entry_ptr->image_ptr) + entry_ptr->size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ } /* end if */ @@ -6542,7 +6542,7 @@ H5C_load_entry(H5F_t * f, if(NULL == (image = (uint8_t *)H5MM_malloc(len + H5C_IMAGE_EXTRA_SPACE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "memory allocation failed for on disk image buffer") #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(image + len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(image + len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ #ifdef H5_HAVE_PARALLEL @@ -6580,7 +6580,7 @@ H5C_load_entry(H5F_t * f, HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "image null after H5MM_realloc()") image = (uint8_t *)new_image; #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(image + len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(image + len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ } /* end if */ @@ -6624,7 +6624,7 @@ H5C_load_entry(H5F_t * f, HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "image null after H5MM_realloc()") image = (uint8_t *)new_image; #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(image + actual_len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(image + actual_len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ if(actual_len > len) { @@ -8456,7 +8456,7 @@ H5C__serialize_single_entry(H5F_t *f, H5C_t *cache_ptr, H5C_cache_entry_t *entry if(NULL == (entry_ptr->image_ptr = H5MM_malloc(entry_ptr->size + H5C_IMAGE_EXTRA_SPACE)) ) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed for on disk image buffer") #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(((uint8_t *)entry_ptr->image_ptr) + image_size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(((uint8_t *)entry_ptr->image_ptr) + image_size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ } /* end if */ @@ -8573,7 +8573,7 @@ H5C__generate_image(H5F_t *f, H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr) if(NULL == (entry_ptr->image_ptr = H5MM_realloc(entry_ptr->image_ptr, new_len + H5C_IMAGE_EXTRA_SPACE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed for on disk image buffer") #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(((uint8_t *)entry_ptr->image_ptr) + new_len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(((uint8_t *)entry_ptr->image_ptr) + new_len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ /* Update statistics for resizing the entry */ @@ -64,17 +64,22 @@ #define H5CX_get_my_context() (&H5CX_head_g) #endif /* H5_HAVE_THREADSAFE */ +/* Common macro for the retrieving the pointer to a property list */ +#define H5CX_RETRIEVE_PLIST(PL, FAILVAL) \ + /* Check if the property list is already available */ \ + if(NULL == (*head)->ctx.PL) \ + /* Get the property list pointer */ \ + if(NULL == ((*head)->ctx.PL = (H5P_genplist_t *)H5I_object((*head)->ctx.H5_GLUE(PL,_id)))) \ + HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, (FAILVAL), "can't get property list") + /* Common macro for the duplicated code to retrieve properties from a property list */ #define H5CX_RETRIEVE_PROP_COMMON(PL, DEF_PL, PROP_NAME, PROP_FIELD) \ /* Check for default property list */ \ if((*head)->ctx.H5_GLUE(PL,_id) == (DEF_PL)) \ - HDmemcpy(&(*head)->ctx.PROP_FIELD, &H5_GLUE3(H5CX_def_,PL,_cache).PROP_FIELD, sizeof(H5_GLUE3(H5CX_def_,PL,_cache).PROP_FIELD)); \ + H5MM_memcpy(&(*head)->ctx.PROP_FIELD, &H5_GLUE3(H5CX_def_,PL,_cache).PROP_FIELD, sizeof(H5_GLUE3(H5CX_def_,PL,_cache).PROP_FIELD)); \ else { \ - /* Check if the property list is already available */ \ - if(NULL == (*head)->ctx.PL) \ - /* Get the dataset transfer property list pointer */ \ - if(NULL == ((*head)->ctx.PL = (H5P_genplist_t *)H5I_object((*head)->ctx.H5_GLUE(PL,_id)))) \ - HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "can't get default dataset transfer property list") \ + /* Retrieve the property list */ \ + H5CX_RETRIEVE_PLIST(PL, FAIL) \ \ /* Get the property */ \ if(H5P_get((*head)->ctx.PL, (PROP_NAME), &(*head)->ctx.PROP_FIELD) < 0) \ @@ -108,11 +113,8 @@ \ /* Check if property exists in DXPL */ \ if(!(*head)->ctx.H5_GLUE(PROP_FIELD,_set)) { \ - /* Check if the property list is already available */ \ - if(NULL == (*head)->ctx.dxpl) \ - /* Get the dataset transfer property list pointer */ \ - if(NULL == ((*head)->ctx.dxpl = (H5P_genplist_t *)H5I_object((*head)->ctx.dxpl_id))) \ - HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "can't get default dataset transfer property list") \ + /* Retrieve the dataset transfer property list */ \ + H5CX_RETRIEVE_PLIST(dxpl, FAIL) \ \ if((check_prop = H5P_exist_plist((*head)->ctx.dxpl, PROP_NAME)) < 0) \ HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "error checking for property") \ @@ -129,15 +131,12 @@ /* Macro for the duplicated code to test and set properties for a property list */ #define H5CX_SET_PROP(PROP_NAME, PROP_FIELD) \ if((*head)->ctx.H5_GLUE(PROP_FIELD,_set)) { \ - /* Check if the property list is already available */ \ - if(NULL == (*head)->ctx.dxpl) \ - /* Get the dataset transfer property list pointer */ \ - if(NULL == ((*head)->ctx.dxpl = (H5P_genplist_t *)H5I_object((*head)->ctx.dxpl_id))) \ - HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, NULL, "can't get default dataset transfer property list") \ + /* Retrieve the dataset transfer property list */ \ + H5CX_RETRIEVE_PLIST(dxpl, NULL) \ \ - /* Set the chunk filter mask property */ \ + /* Set the property */ \ if(H5P_set((*head)->ctx.dxpl, PROP_NAME, &(*head)->ctx.PROP_FIELD) < 0) \ - HGOTO_ERROR(H5E_CONTEXT, H5E_CANTSET, NULL, "error setting filter mask xfer property") \ + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTSET, NULL, "error setting data xfer property") \ } /* end if */ #endif /* H5_HAVE_PARALLEL */ @@ -175,7 +174,7 @@ * corresponding property in the property list to be set when the API * context is popped, when returning from the API routine. Note that the * naming of these fields, <foo> and <foo>_set, is important for the -* H5CX_TEST_SET_PROP and H5CX_SET_PROP macros to work properly. + * H5CX_TEST_SET_PROP and H5CX_SET_PROP macros to work properly. */ typedef struct H5CX_t { /* DXPL */ @@ -190,6 +189,14 @@ typedef struct H5CX_t { hid_t dcpl_id; /* DCPL ID for API operation */ H5P_genplist_t *dcpl; /* Dataset Creation Property List */ + /* DAPL */ + hid_t dapl_id; /* DAPL ID for API operation */ + H5P_genplist_t *dapl; /* Dataset Access Property List */ + + /* FAPL */ + hid_t fapl_id; /* FAPL ID for API operation */ + H5P_genplist_t *fapl; /* File Access Property List */ + /* Internal: Object tagging info */ haddr_t tag; /* Current object's tag (ohdr chunk #0 address) */ @@ -276,8 +283,20 @@ typedef struct H5CX_t { hbool_t nlinks_valid; /* Whether number of soft / UD links to traverse is valid */ /* Cached DCPL properties */ - hbool_t do_min_dset_ohdr; /* Whether to minimize dataset object header */ - hbool_t do_min_dset_ohdr_valid; /* Whether minimize dataset object header flag is valid */ + hbool_t do_min_dset_ohdr; /* Whether to minimize dataset object header */ + hbool_t do_min_dset_ohdr_valid; /* Whether minimize dataset object header flag is valid */ + + /* Cached DAPL properties */ + char *extfile_prefix; /* Prefix for external file */ + hbool_t extfile_prefix_valid; /* Whether the prefix for external file is valid */ + char *vds_prefix; /* Prefix for VDS */ + hbool_t vds_prefix_valid; /* Whether the prefix for VDS is valid */ + + /* Cached FAPL properties */ + H5F_libver_t low_bound; /* low_bound property for H5Pset_libver_bounds() */ + hbool_t low_bound_valid; /* Whether low_bound property is valid */ + H5F_libver_t high_bound; /* high_bound property for H5Pset_libver_bounds */ + hbool_t high_bound_valid; /* Whether high_bound property is valid */ /* Cached VOL settings */ H5VL_connector_prop_t vol_connector_prop; /* Property for VOL connector ID & info */ @@ -339,6 +358,19 @@ typedef struct H5CX_dcpl_cache_t { hbool_t do_min_dset_ohdr; /* Whether to minimize dataset object header */ } H5CX_dcpl_cache_t; +/* Typedef for cached default dataset access property list information */ +/* (Same as the cached DXPL struct, above, except for the default DXPL) */ +typedef struct H5CX_dapl_cache_t { + char *extfile_prefix; /* Prefix for external file */ + char *vds_prefix; /* Prefix for VDS */ +} H5CX_dapl_cache_t; + +/* Typedef for cached default file access property list information */ +/* (Same as the cached DXPL struct, above, except for the default DCPL) */ +typedef struct H5CX_fapl_cache_t { + H5F_libver_t low_bound; /* low_bound property for H5Pset_libver_bounds() */ + H5F_libver_t high_bound; /* high_bound property for H5Pset_libver_bounds */ +} H5CX_fapl_cache_t; /********************/ /* Local Prototypes */ @@ -375,9 +407,18 @@ static H5CX_lapl_cache_t H5CX_def_lapl_cache; /* Define a "default" dataset creation property list cache structure to use for default DCPLs */ static H5CX_dcpl_cache_t H5CX_def_dcpl_cache; +/* Define a "default" dataset access property list cache structure to use for default DAPLs */ +static H5CX_dapl_cache_t H5CX_def_dapl_cache; + +/* Define a "default" file access property list cache structure to use for default FAPLs */ +static H5CX_fapl_cache_t H5CX_def_fapl_cache; + /* Declare a static free list to manage H5CX_node_t structs */ H5FL_DEFINE_STATIC(H5CX_node_t); +/* Declare a static free list to manage H5CX_state_t structs */ +H5FL_DEFINE_STATIC(H5CX_state_t); + /*-------------------------------------------------------------------------- @@ -396,6 +437,8 @@ H5CX__init_package(void) H5P_genplist_t *dx_plist; /* Data transfer property list */ H5P_genplist_t *la_plist; /* Link access property list */ H5P_genplist_t *dc_plist; /* Dataset creation property list */ + H5P_genplist_t *da_plist; /* Dataset access property list */ + H5P_genplist_t *fa_plist; /* File access property list */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -509,6 +552,39 @@ H5CX__init_package(void) if(H5P_get(dc_plist, H5D_CRT_MIN_DSET_HDR_SIZE_NAME, &H5CX_def_dcpl_cache.do_min_dset_ohdr) < 0) HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve dataset minimize flag") + /* Reset the "default DAPL cache" information */ + HDmemset(&H5CX_def_dapl_cache, 0, sizeof(H5CX_dapl_cache_t)); + + /* Get the default DAPL cache information */ + + /* Get the default dataset access property list */ + if(NULL == (da_plist = (H5P_genplist_t *)H5I_object(H5P_DATASET_ACCESS_DEFAULT))) + HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "not a dataset create property list") + + /* Get the prefix for the external file */ + if(H5P_peek(da_plist, H5D_ACS_EFILE_PREFIX_NAME, &H5CX_def_dapl_cache.extfile_prefix) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve prefix for external file") + + /* Get the prefix for the VDS file */ + if(H5P_peek(da_plist, H5D_ACS_VDS_PREFIX_NAME, &H5CX_def_dapl_cache.vds_prefix) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve prefix for VDS") + + /* Reset the "default FAPL cache" information */ + HDmemset(&H5CX_def_fapl_cache, 0, sizeof(H5CX_fapl_cache_t)); + + /* Get the default FAPL cache information */ + + /* Get the default file access property list */ + if(NULL == (fa_plist = (H5P_genplist_t *)H5I_object(H5P_FILE_ACCESS_DEFAULT))) + HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "not a dataset create property list") + + /* Get low_bound */ + if(H5P_get(fa_plist, H5F_ACS_LIBVER_LOW_BOUND_NAME, &H5CX_def_fapl_cache.low_bound) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve dataset minimize flag") + + if(H5P_get(fa_plist, H5F_ACS_LIBVER_HIGH_BOUND_NAME, &H5CX_def_fapl_cache.high_bound) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve dataset minimize flag") + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX__init_package() */ @@ -632,7 +708,10 @@ H5CX__push_common(H5CX_node_t *cnode) /* Set non-zero context info */ cnode->ctx.dxpl_id = H5P_DATASET_XFER_DEFAULT; + cnode->ctx.dcpl_id = H5P_DATASET_CREATE_DEFAULT; + cnode->ctx.dapl_id = H5P_DATASET_ACCESS_DEFAULT; cnode->ctx.lapl_id = H5P_LINK_ACCESS_DEFAULT; + cnode->ctx.fapl_id = H5P_FILE_ACCESS_DEFAULT; cnode->ctx.tag = H5AC__INVALID_TAG; cnode->ctx.ring = H5AC_RING_USER; @@ -709,6 +788,226 @@ H5CX_push_special(void) /*------------------------------------------------------------------------- + * Function: H5CX_retrieve_state + * + * Purpose: Retrieve the state of an API context, for later resumption. + * + * Note: This routine _only_ tracks the state of API context information + * set before the VOL callback is invoked, not values that are + * set internal to the library. It's main purpose is to provide + * API context state to VOL connectors. + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Quincey Koziol + * January 8, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5CX_retrieve_state(H5CX_state_t **api_state) +{ + H5CX_node_t **head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(head && *head); + HDassert(api_state); + + /* Allocate & clear API context state */ + if(NULL == (*api_state = H5FL_CALLOC(H5CX_state_t))) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTALLOC, FAIL, "unable to allocate new API context state") + + /* Check for non-default DXPL */ + if(H5P_DATASET_XFER_DEFAULT != (*head)->ctx.dxpl_id) { + /* Retrieve the DXPL property list */ + H5CX_RETRIEVE_PLIST(dxpl, FAIL) + + /* Copy the DXPL ID */ + if(((*api_state)->dxpl_id = H5P_copy_plist((H5P_genplist_t *)(*head)->ctx.dxpl, FALSE)) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTCOPY, FAIL, "can't copy property list") + } /* end if */ + else + (*api_state)->dxpl_id = H5P_DATASET_XFER_DEFAULT; + + /* Check for non-default LAPL */ + if(H5P_LINK_ACCESS_DEFAULT != (*head)->ctx.lapl_id) { + /* Retrieve the LAPL property list */ + H5CX_RETRIEVE_PLIST(lapl, FAIL) + + /* Copy the LAPL ID */ + if(((*api_state)->lapl_id = H5P_copy_plist((H5P_genplist_t *)(*head)->ctx.lapl, FALSE)) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTCOPY, FAIL, "can't copy property list") + } /* end if */ + else + (*api_state)->lapl_id = H5P_LINK_ACCESS_DEFAULT; + + /* Keep a reference to the current VOL wrapping context */ + (*api_state)->vol_wrap_ctx = (*head)->ctx.vol_wrap_ctx; + if(NULL != (*api_state)->vol_wrap_ctx) + if(H5VL_inc_vol_wrapper((*api_state)->vol_wrap_ctx) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTINC, FAIL, "can't increment refcount on VOL wrapping context") + + /* Keep a copy of the VOL connector property, if there is one */ + if((*head)->ctx.vol_connector_prop_valid && (*head)->ctx.vol_connector_prop.connector_id > 0) { + /* Get the connector property */ + H5MM_memcpy(&(*api_state)->vol_connector_prop, &(*head)->ctx.vol_connector_prop, sizeof(H5VL_connector_prop_t)); + + /* Check for actual VOL connector property */ + if((*api_state)->vol_connector_prop.connector_id) { + /* Copy connector info, if it exists */ + if((*api_state)->vol_connector_prop.connector_info) { + H5VL_class_t *connector; /* Pointer to connector */ + void *new_connector_info = NULL; /* Copy of connector info */ + + /* Retrieve the connector for the ID */ + if(NULL == (connector = (H5VL_class_t *)H5I_object((*api_state)->vol_connector_prop.connector_id))) + HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* Allocate and copy connector info */ + if(H5VL_copy_connector_info(connector, &new_connector_info, (*api_state)->vol_connector_prop.connector_info) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTCOPY, FAIL, "connector info copy failed") + (*api_state)->vol_connector_prop.connector_info = new_connector_info; + } /* end if */ + + /* Increment the refcount on the connector ID */ + if(H5I_inc_ref((*api_state)->vol_connector_prop.connector_id, FALSE) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTINC, FAIL, "incrementing VOL connector ID failed") + } /* end if */ + } /* end if */ + +#ifdef H5_HAVE_PARALLEL + /* Save parallel I/O settings */ + (*api_state)->coll_metadata_read = (*head)->ctx.coll_metadata_read; +#endif /* H5_HAVE_PARALLEL */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5CX_retrieve_state() */ + + +/*------------------------------------------------------------------------- + * Function: H5CX_restore_state + * + * Purpose: Restore an API context, from a previously retrieved state. + * + * Note: This routine _only_ resets the state of API context information + * set before the VOL callback is invoked, not values that are + * set internal to the library. It's main purpose is to restore + * API context state from VOL connectors. + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Quincey Koziol + * January 9, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5CX_restore_state(const H5CX_state_t *api_state) +{ + H5CX_node_t **head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ + + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Sanity check */ + HDassert(head && *head); + HDassert(api_state); + + /* Restore the DXPL info */ + (*head)->ctx.dxpl_id = api_state->dxpl_id; + (*head)->ctx.dxpl = NULL; + + /* Restore the LAPL info */ + (*head)->ctx.lapl_id = api_state->lapl_id; + (*head)->ctx.lapl = NULL; + + /* Restore the VOL wrapper context */ + (*head)->ctx.vol_wrap_ctx = api_state->vol_wrap_ctx; + + /* Restore the VOL connector info */ + if(api_state->vol_connector_prop.connector_id) { + H5MM_memcpy(&(*head)->ctx.vol_connector_prop, &api_state->vol_connector_prop, sizeof(H5VL_connector_prop_t)); + (*head)->ctx.vol_connector_prop_valid = TRUE; + } /* end if */ + +#ifdef H5_HAVE_PARALLEL + /* Restore parallel I/O settings */ + (*head)->ctx.coll_metadata_read = api_state->coll_metadata_read; +#endif /* H5_HAVE_PARALLEL */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5CX_restore_state() */ + + +/*------------------------------------------------------------------------- + * Function: H5CX_free_state + * + * Purpose: Free a previously retrievedAPI context state + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Quincey Koziol + * January 9, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5CX_free_state(H5CX_state_t *api_state) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(api_state); + + /* Release the DXPL */ + if(api_state->dxpl_id != H5P_DATASET_XFER_DEFAULT) + if(H5I_dec_ref(api_state->dxpl_id) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTDEC, FAIL, "can't decrement refcount on DXPL") + + /* Release the LAPL */ + if(api_state->lapl_id != H5P_LINK_ACCESS_DEFAULT) + if(H5I_dec_ref(api_state->lapl_id) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTDEC, FAIL, "can't decrement refcount on LAPL") + + /* Release the VOL wrapper context */ + if(api_state->vol_wrap_ctx) + if(H5VL_dec_vol_wrapper(api_state->vol_wrap_ctx) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTDEC, FAIL, "can't decrement refcount on VOL wrapping context") + + /* Release the VOL connector property, if it was set */ + if(api_state->vol_connector_prop.connector_id) { + /* Clean up any VOL connector info */ + if(api_state->vol_connector_prop.connector_info) { + H5VL_class_t *connector; /* Pointer to connector */ + + /* Retrieve the connector for the ID */ + if(NULL == (connector = (H5VL_class_t *)H5I_object(api_state->vol_connector_prop.connector_id))) + HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* Free the connector info */ + if(H5VL_free_connector_info(connector, api_state->vol_connector_prop.connector_info) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object") + } /* end if */ + + /* Decrement connector ID */ + if(H5I_dec_ref(api_state->vol_connector_prop.connector_id) < 0) + HDONE_ERROR(H5E_CONTEXT, H5E_CANTDEC, FAIL, "can't close VOL connector ID") + } /* end if */ + + /* Free the state */ + api_state = H5FL_FREE(H5CX_state_t, api_state); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5CX_free_state() */ + + +/*------------------------------------------------------------------------- * Function: H5CX_is_def_dxpl * * Purpose: Checks if the API context is using the library's default DXPL @@ -791,6 +1090,42 @@ H5CX_set_dcpl(hid_t dcpl_id) FUNC_LEAVE_NOAPI_VOID } /* end H5CX_set_dcpl() */ +/*------------------------------------------------------------------------- + * Function: H5CX_set_libver_bounds + * + * Purpose: Sets the low/high bounds according to "f" for the current API call context. + * When "f" is NULL, the low/high bounds are set to latest format. + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Vailin Choi + * March 27, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5CX_set_libver_bounds(H5F_t *f) +{ + H5CX_node_t **head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(head && *head); + + /* Set the API context value */ + (*head)->ctx.low_bound = (f == NULL) ? H5F_LIBVER_LATEST : H5F_LOW_BOUND(f); + (*head)->ctx.high_bound = (f == NULL) ? H5F_LIBVER_LATEST : H5F_HIGH_BOUND(f); + + /* Mark the values as valid */ + (*head)->ctx.low_bound_valid = TRUE; + (*head)->ctx.high_bound_valid = TRUE; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5CX_set_libver_bounds() */ + /*------------------------------------------------------------------------- * Function: H5CX_set_lapl @@ -861,6 +1196,8 @@ H5CX_set_apl(hid_t *acspl_id, const H5P_libclass_t *libclass, *acspl_id = *libclass->def_plist_id; else { htri_t is_lapl; /* Whether the access property list is (or is derived from) a link access property list */ + htri_t is_dapl; /* Whether the access property list is (or is derived from) a dataset access property list */ + htri_t is_fapl; /* Whether the access property list is (or is derived from) a file access property list */ #ifdef H5CX_DEBUG /* Sanity check the access property list class */ @@ -874,6 +1211,18 @@ H5CX_set_apl(hid_t *acspl_id, const H5P_libclass_t *libclass, else if(is_lapl) (*head)->ctx.lapl_id = *acspl_id; + /* Check for dataset access property and set API context if so */ + if((is_dapl = H5P_class_isa(*libclass->pclass, *H5P_CLS_DACC->pclass)) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "can't check for dataset access class") + else if(is_dapl) + (*head)->ctx.dapl_id = *acspl_id; + + /* Check for file access property and set API context if so */ + if((is_fapl = H5P_class_isa(*libclass->pclass, *H5P_CLS_FACC->pclass)) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "can't check for file access class") + else if(is_fapl) + (*head)->ctx.fapl_id = *acspl_id; + #ifdef H5_HAVE_PARALLEL /* If this routine is not guaranteed to be collective (i.e. it doesn't * modify the structural metadata in a file), check if the application @@ -951,6 +1300,7 @@ H5CX_set_loc(hid_t #endif /* H5_HAVE_PARALLEL */ loc_id) { +#ifdef H5_HAVE_PARALLEL H5CX_node_t **head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ herr_t ret_value = SUCCEED; /* Return value */ @@ -959,7 +1309,6 @@ H5CX_set_loc(hid_t /* Sanity check */ HDassert(head && *head); -#ifdef H5_HAVE_PARALLEL /* Set collective metadata read flag */ (*head)->ctx.coll_metadata_read = TRUE; @@ -980,10 +1329,14 @@ H5CX_set_loc(hid_t if(mpi_comm != MPI_COMM_NULL) MPI_Barrier(mpi_comm); } /* end if */ -#endif /* H5_HAVE_PARALLEL */ done: FUNC_LEAVE_NOAPI(ret_value) +#else /* H5_HAVE_PARALLEL */ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + FUNC_LEAVE_NOAPI(SUCCEED) +#endif /* H5_HAVE_PARALLEL */ } /* end H5CX_set_loc() */ @@ -1045,7 +1398,7 @@ H5CX_set_vol_connector_prop(const H5VL_connector_prop_t *vol_connector_prop) HDassert(head && *head); /* Set the API context value */ - HDmemcpy(&(*head)->ctx.vol_connector_prop, vol_connector_prop, sizeof(H5VL_connector_prop_t)); + H5MM_memcpy(&(*head)->ctx.vol_connector_prop, vol_connector_prop, sizeof(H5VL_connector_prop_t)); /* Mark the value as valid */ (*head)->ctx.vol_connector_prop_valid = TRUE; @@ -1170,7 +1523,7 @@ H5CX_get_vol_connector_prop(H5VL_connector_prop_t *vol_connector_prop) /* Check for value that was set */ if((*head)->ctx.vol_connector_prop_valid) /* Get the value */ - HDmemcpy(vol_connector_prop, &(*head)->ctx.vol_connector_prop, sizeof(H5VL_connector_prop_t)); + H5MM_memcpy(vol_connector_prop, &(*head)->ctx.vol_connector_prop, sizeof(H5VL_connector_prop_t)); else HDmemset(vol_connector_prop, 0, sizeof(H5VL_connector_prop_t)); @@ -1375,7 +1728,7 @@ H5CX_get_btree_split_ratios(double split_ratio[3]) H5CX_RETRIEVE_PROP_VALID(dxpl, H5P_DATASET_XFER_DEFAULT, H5D_XFER_BTREE_SPLIT_RATIO_NAME, btree_split_ratio) /* Get the B-tree split ratio values */ - HDmemcpy(split_ratio, &(*head)->ctx.btree_split_ratio, sizeof((*head)->ctx.btree_split_ratio)); + H5MM_memcpy(split_ratio, &(*head)->ctx.btree_split_ratio, sizeof((*head)->ctx.btree_split_ratio)); done: FUNC_LEAVE_NOAPI(ret_value) @@ -2060,6 +2413,43 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5CX_get_nlinks() */ +/*------------------------------------------------------------------------- + * Function: H5CX_get_libver_bounds + * + * Purpose: Retrieves the low/high bounds for the current API call context. + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Vailin Choi + * March 27, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5CX_get_libver_bounds(H5F_libver_t *low_bound, H5F_libver_t *high_bound) +{ + H5CX_node_t **head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(low_bound); + HDassert(high_bound); + HDassert(head && *head); + HDassert(H5P_DEFAULT != (*head)->ctx.fapl_id); + + H5CX_RETRIEVE_PROP_VALID(fapl, H5P_FILE_ACCESS_DEFAULT, H5F_ACS_LIBVER_LOW_BOUND_NAME, low_bound) + H5CX_RETRIEVE_PROP_VALID(fapl, H5P_FILE_ACCESS_DEFAULT, H5F_ACS_LIBVER_HIGH_BOUND_NAME, high_bound) + + /* Get the values */ + *low_bound = (*head)->ctx.low_bound; + *high_bound = (*head)->ctx.high_bound; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5CX_get_libver_bounds() */ + /*------------------------------------------------------------------------- * Function: H5CX_get_dset_min_ohdr_flag @@ -2098,6 +2488,120 @@ done: /*------------------------------------------------------------------------- + * Function: H5CX_get_ext_file_prefix + * + * Purpose: Retrieves the prefix for external file + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Raymond Lu + * March 6, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5CX_get_ext_file_prefix(char **extfile_prefix) +{ + H5CX_node_t **head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(extfile_prefix); + HDassert(head && *head); + HDassert(H5P_DEFAULT != (*head)->ctx.dapl_id); + + /* Check if the value has been retrieved already */ + if(!(*head)->ctx.extfile_prefix_valid) { + /* Check for default DAPL */ + if((*head)->ctx.dapl_id == H5P_DATASET_ACCESS_DEFAULT) + (*head)->ctx.extfile_prefix = H5CX_def_dapl_cache.extfile_prefix; + else { + /* Check if the property list is already available */ + if(NULL == (*head)->ctx.dapl) + /* Get the dataset access property list pointer */ + if(NULL == ((*head)->ctx.dapl = (H5P_genplist_t *)H5I_object((*head)->ctx.dapl_id))) + HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "can't get default dataset access property list") + + /* Get the prefix for the external file */ + /* (Note: 'peek', not 'get' - if this turns out to be a problem, we may need + * to copy it and free this in the H5CX pop routine. -QAK) + */ + if(H5P_peek((*head)->ctx.dapl, H5D_ACS_EFILE_PREFIX_NAME, &(*head)->ctx.extfile_prefix) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve external file prefix") + } /* end else */ + + /* Mark the value as valid */ + (*head)->ctx.extfile_prefix_valid = TRUE; + } /* end if */ + + /* Get the value */ + *extfile_prefix = (*head)->ctx.extfile_prefix; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5CX_get_ext_file_prefix() */ + + +/*------------------------------------------------------------------------- + * Function: H5CX_get_vds_prefix + * + * Purpose: Retrieves the prefix for VDS + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Raymond Lu + * March 6, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5CX_get_vds_prefix(char **vds_prefix) +{ + H5CX_node_t **head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(vds_prefix); + HDassert(head && *head); + HDassert(H5P_DEFAULT != (*head)->ctx.dapl_id); + + /* Check if the value has been retrieved already */ + if(!(*head)->ctx.vds_prefix_valid) { + /* Check for default DAPL */ + if((*head)->ctx.dapl_id == H5P_DATASET_ACCESS_DEFAULT) + (*head)->ctx.vds_prefix = H5CX_def_dapl_cache.vds_prefix; + else { + /* Check if the property list is already available */ + if(NULL == (*head)->ctx.dapl) + /* Get the dataset access property list pointer */ + if(NULL == ((*head)->ctx.dapl = (H5P_genplist_t *)H5I_object((*head)->ctx.dapl_id))) + HGOTO_ERROR(H5E_CONTEXT, H5E_BADTYPE, FAIL, "can't get default dataset access property list") + + /* Get the prefix for the VDS */ + /* (Note: 'peek', not 'get' - if this turns out to be a problem, we may need + * to copy it and free this in the H5CX pop routine. -QAK) + */ + if(H5P_peek((*head)->ctx.dapl, H5D_ACS_VDS_PREFIX_NAME, &(*head)->ctx.vds_prefix) < 0) + HGOTO_ERROR(H5E_CONTEXT, H5E_CANTGET, FAIL, "Can't retrieve VDS prefix") + } /* end else */ + + /* Mark the value as valid */ + (*head)->ctx.vds_prefix_valid = TRUE; + } /* end if */ + + /* Get the value */ + *vds_prefix = (*head)->ctx.vds_prefix; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5CX_get_vds_prefix() */ + + +/*------------------------------------------------------------------------- * Function: H5CX_set_tag * * Purpose: Sets the object tag for the current API call context. diff --git a/src/H5CXprivate.h b/src/H5CXprivate.h index 51ee96b..638c32a 100644 --- a/src/H5CXprivate.h +++ b/src/H5CXprivate.h @@ -39,6 +39,19 @@ /* Library Private Typedefs */ /****************************/ +/* API context state */ +typedef struct H5CX_state_t { + hid_t dxpl_id; /* DXPL for operation */ + hid_t lapl_id; /* LAPL for operation */ + void *vol_wrap_ctx; /* VOL connector's "wrap context" for creating IDs */ + H5VL_connector_prop_t vol_connector_prop; /* VOL connector property */ + +#ifdef H5_HAVE_PARALLEL + /* Internal: Parallel I/O settings */ + hbool_t coll_metadata_read; /* Whether to use collective I/O for metadata read */ +#endif /* H5_HAVE_PARALLEL */ +} H5CX_state_t; + /*****************************/ /* Library-private Variables */ @@ -57,10 +70,16 @@ H5_DLL herr_t H5CX_pop(void); H5_DLL void H5CX_push_special(void); H5_DLL hbool_t H5CX_is_def_dxpl(void); +/* API context state routines */ +H5_DLL herr_t H5CX_retrieve_state(H5CX_state_t **api_state); +H5_DLL herr_t H5CX_restore_state(const H5CX_state_t *api_state); +H5_DLL herr_t H5CX_free_state(H5CX_state_t *api_state); + /* "Setter" routines for API context info */ H5_DLL void H5CX_set_dxpl(hid_t dxpl_id); H5_DLL void H5CX_set_lapl(hid_t lapl_id); H5_DLL void H5CX_set_dcpl(hid_t dcpl_id); +H5_DLL herr_t H5CX_set_libver_bounds(H5F_t *f); H5_DLL herr_t H5CX_set_apl(hid_t *acspl_id, const H5P_libclass_t *libclass, hid_t loc_id, hbool_t is_collective); H5_DLL herr_t H5CX_set_loc(hid_t loc_id); @@ -109,6 +128,13 @@ H5_DLL herr_t H5CX_get_nlinks(size_t *nlinks); /* "Getter" routines for DCPL properties cached in API context */ H5_DLL herr_t H5CX_get_dset_min_ohdr_flag(hbool_t *dset_min_ohdr_flag); +/* "Getter" routines for DAPL properties cached in API context */ +H5_DLL herr_t H5CX_get_ext_file_prefix(char **prefix_extfile); +H5_DLL herr_t H5CX_get_vds_prefix(char **prefix_vds); + +/* "Getter" routines for FAPL properties cached in API context */ +H5_DLL herr_t H5CX_get_libver_bounds(H5F_libver_t *low_bound, H5F_libver_t *high_bound); + /* "Setter" routines for API context info */ H5_DLL void H5CX_set_tag(haddr_t tag); H5_DLL void H5CX_set_ring(H5AC_ring_t ring); diff --git a/src/H5Cimage.c b/src/H5Cimage.c index 4684630..db44c7a 100644 --- a/src/H5Cimage.c +++ b/src/H5Cimage.c @@ -2020,11 +2020,11 @@ H5C__decode_cache_image_entry(const H5F_t *f, const H5C_t *cache_ptr, HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed for on disk image buffer") #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(((uint8_t *)image_ptr) + size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(((uint8_t *)image_ptr) + size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ /* Copy the entry image from the cache image block */ - HDmemcpy(image_ptr, p, size); + H5MM_memcpy(image_ptr, p, size); p += size; /* Copy data into target */ @@ -2219,7 +2219,7 @@ H5C__encode_cache_image_header(const H5F_t *f, const H5C_t *cache_ptr, p = *buf; /* write signature */ - HDmemcpy(p, H5C__MDCI_BLOCK_SIGNATURE, (size_t)H5C__MDCI_BLOCK_SIGNATURE_LEN); + H5MM_memcpy(p, H5C__MDCI_BLOCK_SIGNATURE, (size_t)H5C__MDCI_BLOCK_SIGNATURE_LEN); p += H5C__MDCI_BLOCK_SIGNATURE_LEN; /* write version */ @@ -2355,7 +2355,7 @@ H5C__encode_cache_image_entry(H5F_t *f, H5C_t *cache_ptr, uint8_t **buf, H5F_addr_encode(f, &p, ie_ptr->fd_parent_addrs[u]); /* Copy entry image */ - HDmemcpy(p, ie_ptr->image_ptr, ie_ptr->size); + H5MM_memcpy(p, ie_ptr->image_ptr, ie_ptr->size); p += ie_ptr->size; /* Update buffer pointer */ @@ -3422,11 +3422,11 @@ H5C__reconstruct_cache_entry(const H5F_t *f, H5C_t *cache_ptr, if(NULL == (pf_entry_ptr->image_ptr = H5MM_malloc(pf_entry_ptr->size + H5C_IMAGE_EXTRA_SPACE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "memory allocation failed for on disk image buffer") #if H5C_DO_MEMORY_SANITY_CHECKS - HDmemcpy(((uint8_t *)pf_entry_ptr->image_ptr) + size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); + H5MM_memcpy(((uint8_t *)pf_entry_ptr->image_ptr) + size, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE); #endif /* H5C_DO_MEMORY_SANITY_CHECKS */ /* Copy the entry image from the cache image block */ - HDmemcpy(pf_entry_ptr->image_ptr, p, pf_entry_ptr->size); + H5MM_memcpy(pf_entry_ptr->image_ptr, p, pf_entry_ptr->size); p += pf_entry_ptr->size; /* Initialize the rest of the fields in the prefetched entry */ @@ -135,6 +135,9 @@ H5Dcreate2(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, if(TRUE != H5P_isa_class(dcpl_id, H5P_DATASET_CREATE)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "dcpl_id is not a dataset create property list ID") + /* Set the DCPL for the API context */ + H5CX_set_dcpl(dcpl_id); + /* Verify access property list and set up collective metadata if appropriate */ if(H5CX_set_apl(&dapl_id, H5P_CLS_DACC, loc_id, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") @@ -228,6 +231,9 @@ H5Dcreate_anon(hid_t loc_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, if(TRUE != H5P_isa_class(dcpl_id, H5P_DATASET_CREATE)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not dataset create property list ID") + /* Set the DCPL for the API context */ + H5CX_set_dcpl(dcpl_id); + /* Verify access property list and set up collective metadata if appropriate */ if(H5CX_set_apl(&dapl_id, H5P_CLS_DACC, loc_id, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") diff --git a/src/H5Dbtree.c b/src/H5Dbtree.c index b61aed4..c13c36a 100644 --- a/src/H5Dbtree.c +++ b/src/H5Dbtree.c @@ -39,6 +39,7 @@ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MFprivate.h" /* File space management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Oprivate.h" /* Object headers */ #include "H5Sprivate.h" /* Dataspaces */ #include "H5VMprivate.h" /* Vector and array functions */ @@ -847,7 +848,7 @@ H5D__btree_shared_create(const H5F_t *f, H5O_storage_chunk_t *store, /* Set up the "local" information for this dataset's chunks */ if(NULL == (my_layout = H5FL_MALLOC(H5O_layout_chunk_t))) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk layout") - HDmemcpy(my_layout, layout, sizeof(H5O_layout_chunk_t)); + H5MM_memcpy(my_layout, layout, sizeof(H5O_layout_chunk_t)); shared->udata = my_layout; /* Make shared B-tree info reference counted */ @@ -1087,7 +1088,7 @@ H5D__btree_idx_iterate_cb(H5F_t H5_ATTR_UNUSED *f, const void *_lt_key, HDcompile_assert(sizeof(chunk_rec.filter_mask) == sizeof(lt_key->filter_mask)); /* Compose generic chunk record for callback */ - HDmemcpy(&chunk_rec, lt_key, sizeof(*lt_key)); + H5MM_memcpy(&chunk_rec, lt_key, sizeof(*lt_key)); chunk_rec.chunk_addr = addr; /* Make "generic chunk" callback */ diff --git a/src/H5Dbtree2.c b/src/H5Dbtree2.c index b32f395..d25e0f0 100644 --- a/src/H5Dbtree2.c +++ b/src/H5Dbtree2.c @@ -32,6 +32,7 @@ #include "H5Dpkg.h" /* Datasets */ #include "H5FLprivate.h" /* Free Lists */ #include "H5MFprivate.h" /* File space management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vector and array functions */ @@ -248,7 +249,7 @@ H5D__bt2_crt_context(void *_udata) /* Set up the "local" information for this dataset's chunk dimension sizes */ if(NULL == (my_dim = (uint32_t *)H5FL_BLK_MALLOC(chunk_dim, H5O_LAYOUT_NDIMS * sizeof(uint32_t)))) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, NULL, "can't allocate chunk dims") - HDmemcpy(my_dim, udata->dim, H5O_LAYOUT_NDIMS * sizeof(uint32_t)); + H5MM_memcpy(my_dim, udata->dim, H5O_LAYOUT_NDIMS * sizeof(uint32_t)); ctx->dim = my_dim; /* diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index dcd3a8d..93b4427 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -313,6 +313,7 @@ const H5D_layout_ops_t H5D_LOPS_CHUNK[1] = {{ H5D__chunk_construct, H5D__chunk_init, H5D__chunk_is_space_alloc, + H5D__chunk_is_data_cached, H5D__chunk_io_init, H5D__chunk_read, H5D__chunk_write, @@ -340,6 +341,7 @@ const H5D_layout_ops_t H5D_LOPS_NONEXISTENT[1] = {{ NULL, NULL, NULL, + NULL, #ifdef H5_HAVE_PARALLEL NULL, NULL, @@ -394,10 +396,13 @@ H5D__chunk_direct_write(const H5D_t *dset, uint32_t filters, hsize_t *offset, FUNC_ENTER_PACKAGE_TAG(dset->oloc.addr) + /* Sanity checks */ + HDassert(layout->type == H5D_CHUNKED); + io_info.dset = dset; /* Allocate dataspace and initialize it if it hasn't been. */ - if(!(*layout->ops->is_space_alloc)(&layout->storage)) + if(!H5D__chunk_is_space_alloc(&layout->storage)) /* Allocate storage */ if(H5D__alloc_storage(&io_info, H5D_ALLOC_WRITE, FALSE, NULL) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize storage") @@ -435,13 +440,17 @@ H5D__chunk_direct_write(const H5D_t *dset, uint32_t filters, hsize_t *offset, if(0 == idx_info.pline->nused && H5F_addr_defined(old_chunk.offset)) /* If there are no filters and we are overwriting the chunk we can just set values */ need_insert = FALSE; - else + else { /* Otherwise, create the chunk it if it doesn't exist, or reallocate the chunk * if its size has changed. */ if(H5D__chunk_file_alloc(&idx_info, &old_chunk, &udata.chunk_block, &need_insert, scaled) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "unable to allocate chunk") + /* Cache the new chunk information */ + H5D__chunk_cinfo_cache_update(&dset->shared->cache.chunk.last, &udata); + } /* end else */ + /* Make sure the address of the chunk is returned. */ if(!H5F_addr_defined(udata.chunk_block.offset)) HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "chunk address isn't defined") @@ -506,7 +515,8 @@ H5D__chunk_direct_read(const H5D_t *dset, hsize_t *offset, uint32_t* filters, *filters = 0; /* Allocate dataspace and initialize it if it hasn't been. */ - if(!(*layout->ops->is_space_alloc)(&layout->storage)) + if(!H5D__chunk_is_space_alloc(&layout->storage) + && !H5D__chunk_is_data_cached(dset->shared)) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "storage is not initialized") /* Calculate the index of this chunk */ @@ -1019,6 +1029,30 @@ H5D__chunk_is_space_alloc(const H5O_storage_t *storage) /*------------------------------------------------------------------------- + * Function: H5D__chunk_is_data_cached + * + * Purpose: Query if raw data is cached for dataset + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Neil Fortner + * Wednessday, March 6, 2016 + * + *------------------------------------------------------------------------- + */ +hbool_t +H5D__chunk_is_data_cached(const H5D_shared_t *shared_dset) +{ + FUNC_ENTER_PACKAGE_NOERR + + /* Sanity checks */ + HDassert(shared_dset); + + FUNC_LEAVE_NOAPI(shared_dset->cache.chunk.nused > 0) +} /* end H5D__chunk_is_data_cached() */ + + +/*------------------------------------------------------------------------- * Function: H5D__chunk_io_init * * Purpose: Performs initialization before any sort of I/O on the raw data @@ -1654,7 +1688,7 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t new_chunk_info->mspace_shared = FALSE; /* Copy the chunk's scaled coordinates */ - HDmemcpy(new_chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); + H5MM_memcpy(new_chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); new_chunk_info->scaled[fm->f_ndims] = 0; /* Insert the new chunk into the skip list */ @@ -1914,9 +1948,9 @@ H5D__chunk_file_cb(void H5_ATTR_UNUSED *elem, const H5T_t H5_ATTR_UNUSED *type, chunk_info->chunk_points = 0; /* Set the chunk's scaled coordinates */ - HDmemcpy(chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); + H5MM_memcpy(chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); chunk_info->scaled[fm->f_ndims] = 0; - HDmemcpy(chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); + H5MM_memcpy(chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); /* Insert the new chunk into the skip list */ if(H5SL_insert(fm->sel_chunks,chunk_info,&chunk_info->index) < 0) { @@ -2157,11 +2191,11 @@ H5D__chunk_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, HDassert(fm); /* Set up "nonexistent" I/O info object */ - HDmemcpy(&nonexistent_io_info, io_info, sizeof(nonexistent_io_info)); + H5MM_memcpy(&nonexistent_io_info, io_info, sizeof(nonexistent_io_info)); nonexistent_io_info.layout_ops = *H5D_LOPS_NONEXISTENT; /* Set up contiguous I/O info object */ - HDmemcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); + H5MM_memcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); ctg_io_info.store = &ctg_store; ctg_io_info.layout_ops = *H5D_LOPS_CONTIG; @@ -2169,7 +2203,7 @@ H5D__chunk_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, H5_CHECKED_ASSIGN(ctg_store.contig.dset_size, hsize_t, io_info->dset->shared->layout.u.chunk.size, uint32_t); /* Set up compact I/O info object */ - HDmemcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); + H5MM_memcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); cpt_io_info.store = &cpt_store; cpt_io_info.layout_ops = *H5D_LOPS_COMPACT; @@ -2307,7 +2341,7 @@ H5D__chunk_write(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, HDassert(fm); /* Set up contiguous I/O info object */ - HDmemcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); + H5MM_memcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); ctg_io_info.store = &ctg_store; ctg_io_info.layout_ops = *H5D_LOPS_CONTIG; @@ -2315,7 +2349,7 @@ H5D__chunk_write(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, H5_CHECKED_ASSIGN(ctg_store.contig.dset_size, hsize_t, io_info->dset->shared->layout.u.chunk.size, uint32_t); /* Set up compact I/O info object */ - HDmemcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); + H5MM_memcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); cpt_io_info.store = &cpt_store; cpt_io_info.layout_ops = *H5D_LOPS_COMPACT; @@ -2670,7 +2704,7 @@ H5D__chunk_cinfo_cache_update(H5D_chunk_cached_t *last, const H5D_chunk_ud_t *ud HDassert(udata->common.scaled); /* Stored the information to cache */ - HDmemcpy(last->scaled, udata->common.scaled, sizeof(hsize_t) * udata->common.layout->ndims); + H5MM_memcpy(last->scaled, udata->common.scaled, sizeof(hsize_t) * udata->common.layout->ndims); last->addr = udata->chunk_block.offset; H5_CHECKED_ASSIGN(last->nbytes, uint32_t, udata->chunk_block.length, hsize_t); last->chunk_idx = udata->chunk_idx; @@ -3039,7 +3073,7 @@ H5D__chunk_flush_entry(const H5D_t *dset, H5D_rdcc_ent_t *ent, hbool_t reset) */ if(NULL == (buf = H5MM_malloc(alloc))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for pipeline") - HDmemcpy(buf, ent->chunk, alloc); + H5MM_memcpy(buf, ent->chunk, alloc); } /* end if */ else { /* @@ -3452,7 +3486,7 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, */ if(NULL == (chunk = H5D__chunk_mem_alloc(chunk_size, pline))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk") - HDmemcpy(chunk, ent->chunk, chunk_size); + H5MM_memcpy(chunk, ent->chunk, chunk_size); ent->chunk = (uint8_t *)H5D__chunk_mem_xfree(ent->chunk, old_pline); ent->chunk = (uint8_t *)chunk; chunk = NULL; @@ -3478,7 +3512,7 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, */ if(NULL == (chunk = H5D__chunk_mem_alloc(chunk_size, pline))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk") - HDmemcpy(chunk, ent->chunk, chunk_size); + H5MM_memcpy(chunk, ent->chunk, chunk_size); ent->chunk = (uint8_t *)H5D__chunk_mem_xfree(ent->chunk, old_pline); ent->chunk = (uint8_t *)chunk; @@ -3607,7 +3641,7 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, (void)H5D__chunk_mem_xfree(tmp_chunk, old_pline); HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk") } /* end if */ - HDmemcpy(chunk, tmp_chunk, chunk_size); + H5MM_memcpy(chunk, tmp_chunk, chunk_size); (void)H5D__chunk_mem_xfree(tmp_chunk, old_pline); } /* end if */ } /* end if */ @@ -3688,7 +3722,7 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, ent->chunk_block.offset = chunk_addr; ent->chunk_block.length = chunk_alloc; ent->chunk_idx = udata->chunk_idx; - HDmemcpy(ent->scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); + H5MM_memcpy(ent->scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); H5_CHECKED_ASSIGN(ent->rd_count, uint32_t, chunk_size, size_t); H5_CHECKED_ASSIGN(ent->wr_count, uint32_t, chunk_size, size_t); ent->chunk = (uint8_t *)chunk; @@ -3816,7 +3850,7 @@ H5D__chunk_unlock(const H5D_io_info_t *io_info, const H5D_chunk_ud_t *udata, fake_ent.edge_chunk_state = H5D_RDCC_DISABLE_FILTERS; if(udata->new_unfilt_chunk) fake_ent.edge_chunk_state |= H5D_RDCC_NEWLY_DISABLED_FILTERS; - HDmemcpy(fake_ent.scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); + H5MM_memcpy(fake_ent.scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); HDassert(layout->u.chunk.size > 0); fake_ent.chunk_idx = udata->chunk_idx; fake_ent.chunk_block.offset = udata->chunk_block.offset; @@ -4103,7 +4137,7 @@ H5D__chunk_allocate(const H5D_io_info_t *io_info, hbool_t full_overwrite, hsize_ if(has_unfilt_edge_chunks) { if(NULL == (unfilt_fill_buf = H5D__chunk_mem_alloc(orig_chunk_size, &def_pline))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for raw data chunk") - HDmemcpy(unfilt_fill_buf, fb_info.fill_buf, orig_chunk_size); + H5MM_memcpy(unfilt_fill_buf, fb_info.fill_buf, orig_chunk_size); } /* end if */ /* Retrieve filter settings from API context */ @@ -5637,7 +5671,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) if(udata->chunk_in_cache && udata->chunk) { HDassert(!H5F_addr_defined(chunk_rec->chunk_addr)); - HDmemcpy(buf, udata->chunk, nbytes); + H5MM_memcpy(buf, udata->chunk, nbytes); udata->chunk = NULL; } else { @@ -5671,7 +5705,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) HDassert(H5F_addr_defined(ent->chunk_block.offset)); H5_CHECKED_ASSIGN(nbytes, size_t, shared_fo->layout.u.chunk.size, uint32_t); - HDmemcpy(buf, ent->chunk, nbytes); + H5MM_memcpy(buf, ent->chunk, nbytes); } else { /* read chunk data from the source file */ @@ -5705,7 +5739,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5_ITER_ERROR, "datatype conversion failed") /* Copy into another buffer, to reclaim memory later */ - HDmemcpy(reclaim_buf, buf, reclaim_buf_size); + H5MM_memcpy(reclaim_buf, buf, reclaim_buf_size); /* Set background buffer to all zeros */ HDmemset(bkg, 0, buf_size); @@ -5736,7 +5770,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) } /* end if */ /* After fix ref, copy the new reference elements to the buffer to write out */ - HDmemcpy(buf, bkg, buf_size); + H5MM_memcpy(buf, bkg, buf_size); } /* end if */ /* Set up destination chunk callback information for insertion */ @@ -6036,7 +6070,7 @@ H5D__chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, for(ent = shared_fo->cache.chunk.head; ent; ent = next) { if(!H5F_addr_defined(ent->chunk_block.offset)) { - HDmemcpy(chunk_rec.scaled, ent->scaled, sizeof(chunk_rec.scaled)); + H5MM_memcpy(chunk_rec.scaled, ent->scaled, sizeof(chunk_rec.scaled)); udata.chunk = ent->chunk; udata.chunk_in_cache = TRUE; if(H5D__chunk_copy_cb(&chunk_rec, &udata) < 0) diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index c0c2a80..df61856 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -80,6 +80,7 @@ const H5D_layout_ops_t H5D_LOPS_COMPACT[1] = {{ H5D__compact_construct, NULL, H5D__compact_is_space_alloc, + NULL, H5D__compact_io_init, H5D__contig_read, H5D__contig_write, @@ -528,7 +529,7 @@ H5D__compact_copy(H5F_t *f_src, H5O_storage_compact_t *_storage_src, H5F_t *f_ds if(NULL == (buf = H5FL_BLK_MALLOC(type_conv, buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - HDmemcpy(buf, storage_src->buf, storage_src->size); + H5MM_memcpy(buf, storage_src->buf, storage_src->size); /* allocate temporary bkg buff for data conversion */ if(NULL == (bkg = H5FL_BLK_MALLOC(type_conv, buf_size))) @@ -539,7 +540,7 @@ H5D__compact_copy(H5F_t *f_src, H5O_storage_compact_t *_storage_src, H5F_t *f_ds HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed") /* Copy into another buffer, to reclaim memory later */ - HDmemcpy(reclaim_buf, buf, buf_size); + H5MM_memcpy(reclaim_buf, buf, buf_size); /* Set background buffer to all zeros */ HDmemset(bkg, 0, buf_size); @@ -548,7 +549,7 @@ H5D__compact_copy(H5F_t *f_src, H5O_storage_compact_t *_storage_src, H5F_t *f_ds if(H5T_convert(tpath_mem_dst, tid_mem, tid_dst, nelmts, (size_t)0, (size_t)0, buf, bkg) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed") - HDmemcpy(storage_dst->buf, buf, storage_dst->size); + H5MM_memcpy(storage_dst->buf, buf, storage_dst->size); if(H5D_vlen_reclaim(tid_mem, buf_space, reclaim_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_BADITER, FAIL, "unable to reclaim variable-length data") @@ -573,11 +574,11 @@ H5D__compact_copy(H5F_t *f_src, H5O_storage_compact_t *_storage_src, H5F_t *f_ds } /* end if */ else /* Type conversion not necessary */ - HDmemcpy(storage_dst->buf, storage_src->buf, storage_src->size); + H5MM_memcpy(storage_dst->buf, storage_src->buf, storage_src->size); } /* end if */ else /* Type conversion not necessary */ - HDmemcpy(storage_dst->buf, storage_src->buf, storage_src->size); + H5MM_memcpy(storage_dst->buf, storage_src->buf, storage_src->size); /* Mark destination buffer as dirty */ storage_dst->dirty = TRUE; diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index ad12ba0..8733633 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -40,6 +40,7 @@ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5FOprivate.h" /* File objects */ #include "H5Oprivate.h" /* Object headers */ #include "H5Pprivate.h" /* Property lists */ @@ -118,6 +119,7 @@ const H5D_layout_ops_t H5D_LOPS_CONTIG[1] = {{ H5D__contig_construct, H5D__contig_init, H5D__contig_is_space_alloc, + H5D__contig_is_data_cached, H5D__contig_io_init, H5D__contig_read, H5D__contig_write, @@ -538,6 +540,30 @@ H5D__contig_is_space_alloc(const H5O_storage_t *storage) /*------------------------------------------------------------------------- + * Function: H5D__contig_is_data_cached + * + * Purpose: Query if raw data is cached for dataset + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Neil Fortner + * Wednessday, March 6, 2016 + * + *------------------------------------------------------------------------- + */ +hbool_t +H5D__contig_is_data_cached(const H5D_shared_t *shared_dset) +{ + FUNC_ENTER_PACKAGE_NOERR + + /* Sanity checks */ + HDassert(shared_dset); + + FUNC_LEAVE_NOAPI(shared_dset->cache.contig.sieve_size > 0) +} /* end H5D__contig_is_data_cached() */ + + +/*------------------------------------------------------------------------- * Function: H5D__contig_io_init * * Purpose: Performs initialization before any sort of I/O on the raw data @@ -751,15 +777,10 @@ H5D__contig_readvv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(buf, dset_contig->sieve_buf, len); + H5MM_memcpy(buf, dset_contig->sieve_buf, len); /* Reset sieve buffer dirty flag */ dset_contig->sieve_dirty = FALSE; - - /* Stash local copies of these value */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start+sieve_size; } /* end else */ } /* end if */ else { @@ -771,7 +792,7 @@ H5D__contig_readvv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, unsigned char *base_sieve_buf = dset_contig->sieve_buf + (addr - sieve_start); /* Grab the data out of the buffer */ - HDmemcpy(buf, base_sieve_buf, len); + H5MM_memcpy(buf, base_sieve_buf, len); } /* end if */ /* Entire request is not within this data sieve buffer */ else { @@ -825,17 +846,12 @@ H5D__contig_readvv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, min = MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size); H5_CHECKED_ASSIGN(dset_contig->sieve_size, size_t, min, hsize_t); - /* Update local copies of sieve information */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start + sieve_size; - /* Read the new sieve buffer */ if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, dset_contig->sieve_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(buf, dset_contig->sieve_buf, len); + H5MM_memcpy(buf, dset_contig->sieve_buf, len); /* Reset sieve buffer dirty flag */ dset_contig->sieve_dirty = FALSE; @@ -1033,7 +1049,7 @@ H5D__contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, } /* end if */ /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(dset_contig->sieve_buf, buf, len); + H5MM_memcpy(dset_contig->sieve_buf, buf, len); /* Set sieve buffer dirty flag */ dset_contig->sieve_dirty = TRUE; @@ -1053,7 +1069,7 @@ H5D__contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, unsigned char *base_sieve_buf = dset_contig->sieve_buf + (addr - sieve_start); /* Put the data into the sieve buffer */ - HDmemcpy(base_sieve_buf, buf, len); + H5MM_memcpy(base_sieve_buf, buf, len); /* Set sieve buffer dirty flag */ dset_contig->sieve_dirty = TRUE; @@ -1096,7 +1112,7 @@ H5D__contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, HDmemmove(dset_contig->sieve_buf + len, dset_contig->sieve_buf, dset_contig->sieve_size); /* Copy in new information (must be first in sieve buffer) */ - HDmemcpy(dset_contig->sieve_buf, buf, len); + H5MM_memcpy(dset_contig->sieve_buf, buf, len); /* Adjust sieve location */ dset_contig->sieve_loc = addr; @@ -1105,16 +1121,11 @@ H5D__contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, /* Append to existing sieve buffer */ else { /* Copy in new information */ - HDmemcpy(dset_contig->sieve_buf + sieve_size, buf, len); + H5MM_memcpy(dset_contig->sieve_buf + sieve_size, buf, len); } /* end else */ /* Adjust sieve size */ dset_contig->sieve_size += len; - - /* Update local copies of sieve information */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start + sieve_size; } /* end if */ /* Can't add the new data onto the existing sieve buffer */ else { @@ -1146,11 +1157,6 @@ H5D__contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, min = MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size); H5_CHECKED_ASSIGN(dset_contig->sieve_size, size_t, min, hsize_t); - /* Update local copies of sieve information */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start + sieve_size; - /* Check if there is any point in reading the data from the file */ if(dset_contig->sieve_size > len) { /* Read the new sieve buffer */ @@ -1159,7 +1165,7 @@ H5D__contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, } /* end if */ /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(dset_contig->sieve_buf, buf, len); + H5MM_memcpy(dset_contig->sieve_buf, buf, len); /* Set sieve buffer dirty flag */ dset_contig->sieve_dirty = TRUE; @@ -1514,7 +1520,7 @@ H5D__contig_copy(H5F_t *f_src, const H5O_storage_contig_t *storage_src, if(try_sieve && (addr_src >= sieve_start) && ((addr_src + src_nbytes -1) < sieve_end)) { unsigned char *base_sieve_buf = shared_fo->cache.contig.sieve_buf + (addr_src - sieve_start); - HDmemcpy(buf, base_sieve_buf, src_nbytes); + H5MM_memcpy(buf, base_sieve_buf, src_nbytes); } else /* Read raw data from source file */ if(H5F_block_read(f_src, H5FD_MEM_DRAW, addr_src, src_nbytes, buf) < 0) @@ -1527,7 +1533,7 @@ H5D__contig_copy(H5F_t *f_src, const H5O_storage_contig_t *storage_src, HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed") /* Copy into another buffer, to reclaim memory later */ - HDmemcpy(reclaim_buf, buf, mem_nbytes); + H5MM_memcpy(reclaim_buf, buf, mem_nbytes); /* Set background buffer to all zeros */ HDmemset(bkg, 0, buf_size); @@ -1553,7 +1559,7 @@ H5D__contig_copy(H5F_t *f_src, const H5O_storage_contig_t *storage_src, HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "unable to copy reference attribute") /* After fix ref, copy the new reference elements to the buffer to write out */ - HDmemcpy(buf, bkg, buf_size); + H5MM_memcpy(buf, bkg, buf_size); } /* end if */ else /* Reset value to zero */ diff --git a/src/H5Ddeprec.c b/src/H5Ddeprec.c index 76827b4..85371ae 100644 --- a/src/H5Ddeprec.c +++ b/src/H5Ddeprec.c @@ -136,6 +136,9 @@ H5Dcreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, if(TRUE != H5P_isa_class(dcpl_id, H5P_DATASET_CREATE)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not dataset create property list ID") + /* Set the DCPL for the API context */ + H5CX_set_dcpl(dcpl_id); + /* Verify access property list and set up collective metadata if appropriate */ if(H5CX_set_apl(&dapl_id, H5P_CLS_DACC, loc_id, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") diff --git a/src/H5Dearray.c b/src/H5Dearray.c index a8fffbc..b23ac46 100644 --- a/src/H5Dearray.c +++ b/src/H5Dearray.c @@ -37,6 +37,7 @@ #include "H5EAprivate.h" /* Extensible arrays */ #include "H5FLprivate.h" /* Free Lists */ #include "H5MFprivate.h" /* File space management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vector functions */ @@ -1197,11 +1198,11 @@ H5D__earray_idx_resize(H5O_layout_chunk_t *layout) hsize_t swizzled_max_chunks[H5O_LAYOUT_NDIMS]; /* Swizzled form of max # of chunks in each dimension */ /* Get the swizzled chunk dimensions */ - HDmemcpy(layout->u.earray.swizzled_dim, layout->dim, (layout->ndims - 1) * sizeof(layout->dim[0])); + H5MM_memcpy(layout->u.earray.swizzled_dim, layout->dim, (layout->ndims - 1) * sizeof(layout->dim[0])); H5VM_swizzle_coords(uint32_t, layout->u.earray.swizzled_dim, layout->u.earray.unlim_dim); /* Get the swizzled number of chunks in each dimension */ - HDmemcpy(swizzled_chunks, layout->chunks, (layout->ndims - 1) * sizeof(swizzled_chunks[0])); + H5MM_memcpy(swizzled_chunks, layout->chunks, (layout->ndims - 1) * sizeof(swizzled_chunks[0])); H5VM_swizzle_coords(hsize_t, swizzled_chunks, layout->u.earray.unlim_dim); /* Get the swizzled "down" sizes for each dimension */ @@ -1209,7 +1210,7 @@ H5D__earray_idx_resize(H5O_layout_chunk_t *layout) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't compute swizzled 'down' chunk size value") /* Get the swizzled max number of chunks in each dimension */ - HDmemcpy(swizzled_max_chunks, layout->max_chunks, (layout->ndims - 1) * sizeof(swizzled_max_chunks[0])); + H5MM_memcpy(swizzled_max_chunks, layout->max_chunks, (layout->ndims - 1) * sizeof(swizzled_max_chunks[0])); H5VM_swizzle_coords(hsize_t, swizzled_max_chunks, layout->u.earray.unlim_dim); /* Get the swizzled max "down" sizes for each dimension */ diff --git a/src/H5Defl.c b/src/H5Defl.c index b2f9b29..91caa61 100644 --- a/src/H5Defl.c +++ b/src/H5Defl.c @@ -91,6 +91,7 @@ const H5D_layout_ops_t H5D_LOPS_EFL[1] = {{ H5D__efl_construct, NULL, H5D__efl_is_space_alloc, + NULL, H5D__efl_io_init, H5D__contig_read, H5D__contig_write, @@ -226,7 +227,7 @@ H5D__efl_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t H5_ATTR_UNU { FUNC_ENTER_STATIC_NOERR - HDmemcpy(&io_info->store->efl, &(io_info->dset->shared->dcpl_cache.efl), sizeof(H5O_efl_t)); + H5MM_memcpy(&io_info->store->efl, &(io_info->dset->shared->dcpl_cache.efl), sizeof(H5O_efl_t)); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5D__efl_io_init() */ @@ -476,7 +477,6 @@ H5D__efl_readvv(const H5D_io_info_t *io_info, HDassert(io_info->u.rbuf); HDassert(io_info->dset); HDassert(io_info->dset->shared); - HDassert(io_info->dset->shared->extfile_prefix); HDassert(dset_curr_seq); HDassert(dset_len_arr); HDassert(dset_off_arr); @@ -560,7 +560,6 @@ H5D__efl_writevv(const H5D_io_info_t *io_info, HDassert(io_info->u.wbuf); HDassert(io_info->dset); HDassert(io_info->dset->shared); - HDassert(io_info->dset->shared->extfile_prefix); HDassert(dset_curr_seq); HDassert(dset_len_arr); HDassert(dset_off_arr); diff --git a/src/H5Dfill.c b/src/H5Dfill.c index 619f699..69f4ff8 100644 --- a/src/H5Dfill.c +++ b/src/H5Dfill.c @@ -38,6 +38,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vector and array functions */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -300,7 +301,7 @@ H5D__fill(const void *fill, const H5T_t *fill_type, void *buf, HGOTO_ERROR(H5E_DATASET, H5E_NOSPACE, FAIL, "can't get actual buffer") /* Copy the user's data into the buffer for conversion */ - HDmemcpy(elem_ptr, fill, src_type_size); + H5MM_memcpy(elem_ptr, fill, src_type_size); /* If there's no VL type of data, do conversion first then fill the data into * the memory buffer. */ @@ -577,7 +578,7 @@ H5D__fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts) HDassert(fb_info->fill_buf); /* Make a copy of the (disk-based) fill value into the buffer */ - HDmemcpy(fb_info->fill_buf, fb_info->fill->buf, fb_info->file_elmt_size); + H5MM_memcpy(fb_info->fill_buf, fb_info->fill->buf, fb_info->file_elmt_size); /* Reset first element of background buffer, if necessary */ if(H5T_path_bkg(fb_info->fill_to_mem_tpath)) @@ -603,7 +604,7 @@ H5D__fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts) if(!buf) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "memory allocation failed for temporary fill buffer") - HDmemcpy(buf, fb_info->fill_buf, fb_info->fill_buf_size); + H5MM_memcpy(buf, fb_info->fill_buf, fb_info->fill_buf_size); /* Type convert the dataset buffer, to copy any VL components */ if(H5T_convert(fb_info->mem_to_dset_tpath, fb_info->mem_tid, fb_info->file_tid, nelmts, (size_t)0, (size_t)0, fb_info->fill_buf, fb_info->bkg_buf) < 0) diff --git a/src/H5Dint.c b/src/H5Dint.c index 384c66b..220f026 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -54,7 +54,7 @@ static herr_t H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, cons static herr_t H5D__cache_dataspace_info(const H5D_t *dset); static herr_t H5D__init_space(H5F_t *file, const H5D_t *dset, const H5S_t *space); static herr_t H5D__update_oh_info(H5F_t *file, H5D_t *dset, hid_t dapl_id); -static herr_t H5D__build_file_prefix(const H5D_t *dset, hid_t dapl_id, const char *prefix_type, char **file_prefix); +static herr_t H5D__build_file_prefix(const H5D_t *dset, H5F_prefix_open_t prefix_type, char **file_prefix); static herr_t H5D__open_oid(H5D_t *dataset, hid_t dapl_id); static herr_t H5D__init_storage(const H5D_io_info_t *io_info, hbool_t full_overwrite, hsize_t old_dim[]); @@ -112,6 +112,10 @@ static const H5I_class_t H5I_DATASET_CLS[1] = {{ /* Flag indicating "top" of interface has been initialized */ static hbool_t H5D_top_package_initialize_s = FALSE; +/* Prefixes of VDS and external file from the environment variables + * HDF5_EXTFILE_PREFIX and HDF5_VDS_PREFIX */ +const static char *H5D_prefix_ext_env = NULL; +const static char *H5D_prefix_vds_env = NULL; /*------------------------------------------------------------------------- @@ -188,6 +192,10 @@ H5D__init_package(void) /* Mark "top" of interface as initialized, too */ H5D_top_package_initialize_s = TRUE; + /* Retrieve the prefixes of VDS and external file from the environment variable */ + H5D_prefix_vds_env = HDgetenv("HDF5_VDS_PREFIX"); + H5D_prefix_ext_env = HDgetenv("HDF5_EXTFILE_PREFIX"); + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__init_package() */ @@ -470,7 +478,7 @@ H5D__new(hid_t dcpl_id, hbool_t creating, hbool_t vl_type) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy the default dataset information */ - HDmemcpy(new_dset, &H5D_def_dset, sizeof(H5D_shared_t)); + H5MM_memcpy(new_dset, &H5D_def_dset, sizeof(H5D_shared_t)); /* If we are using the default dataset creation property list, during creation * don't bother to copy it, just increment the reference count @@ -488,9 +496,6 @@ H5D__new(hid_t dcpl_id, hbool_t creating, hbool_t vl_type) new_dset->dcpl_id = H5P_copy_plist(plist, FALSE); } /* end else */ - /* Set the DCPL for the API context */ - H5CX_set_dcpl(new_dset->dcpl_id); - /* Set return value */ ret_value = new_dset; @@ -774,7 +779,7 @@ H5D__calculate_minimum_header_size(H5F_t *file, H5D_t *dset, H5O_t *ohdr) /* Shallow copy the fill value property */ /* guards against shared component modification */ - HDmemcpy(&old_fill_prop, fill_prop, sizeof(old_fill_prop)); + H5MM_memcpy(&old_fill_prop, fill_prop, sizeof(old_fill_prop)); if (H5O_msg_reset_share(H5O_FILL_ID, &old_fill_prop) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, 0, "can't reset the copied fill property") @@ -1000,7 +1005,7 @@ H5D__update_oh_info(H5F_t *file, H5D_t *dset, hid_t dapl_id) /* Shallow copy the fill value property */ /* (we only want to make certain that the shared component isn't modified) */ - HDmemcpy(&old_fill_prop, fill_prop, sizeof(old_fill_prop)); + H5MM_memcpy(&old_fill_prop, fill_prop, sizeof(old_fill_prop)); /* Reset shared component info */ H5O_msg_reset_share(H5O_FILL_ID, &old_fill_prop); @@ -1083,8 +1088,7 @@ done: *-------------------------------------------------------------------------- */ static herr_t -H5D__build_file_prefix(const H5D_t *dset, hid_t dapl_id, const char *prefix_type, - char **file_prefix /*out*/) +H5D__build_file_prefix(const H5D_t *dset, H5F_prefix_open_t prefix_type, char **file_prefix /*out*/) { char *prefix = NULL; /* prefix used to look for the file */ char *filepath = NULL; /* absolute path of directory the HDF5 file is in */ @@ -1105,20 +1109,22 @@ H5D__build_file_prefix(const H5D_t *dset, hid_t dapl_id, const char *prefix_type /* XXX: Future thread-safety note - getenv is not required * to be reentrant. */ - if(HDstrcmp(prefix_type, H5D_ACS_VDS_PREFIX_NAME) == 0) - prefix = HDgetenv("HDF5_VDS_PREFIX"); - else if(HDstrcmp(prefix_type, H5D_ACS_EFILE_PREFIX_NAME) == 0) - prefix = HDgetenv("HDF5_EXTFILE_PREFIX"); - else - HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "prefix name is not sensible") - - if(prefix == NULL || *prefix == '\0') { - /* Set prefix to value of prefix_type property */ - if(NULL == (plist = H5P_object_verify(dapl_id, H5P_DATASET_ACCESS))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - if(H5P_peek(plist, prefix_type, &prefix) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get file prefix") - } /* end if */ + if(H5F_PREFIX_VDS == prefix_type) { + prefix = (char *)H5D_prefix_vds_env; + + if(prefix == NULL || *prefix == '\0') { + if(H5CX_get_vds_prefix(&prefix) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get the prefix for vds file") + } + } else if(H5F_PREFIX_EFILE == prefix_type) { + prefix = (char *)H5D_prefix_ext_env; + + if(prefix == NULL || *prefix == '\0') { + if(H5CX_get_ext_file_prefix(&prefix) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get the prefix for the external file") + } + } else + HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "prefix name is not sensible") /* Prefix has to be checked for NULL / empty string again because the * code above might have updated it. @@ -1127,8 +1133,7 @@ H5D__build_file_prefix(const H5D_t *dset, hid_t dapl_id, const char *prefix_type /* filename is interpreted as relative to the current directory, * does not need to be expanded */ - if(NULL == (*file_prefix = (char *)H5MM_strdup(""))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + *file_prefix = NULL; } /* end if */ else { if(HDstrncmp(prefix, "${ORIGIN}", HDstrlen("${ORIGIN}")) == 0) { @@ -1326,11 +1331,11 @@ H5D__create(H5F_t *file, hid_t type_id, const H5S_t *space, hid_t dcpl_id, HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to set up flush append property") /* Set the external file prefix */ - if(H5D__build_file_prefix(new_dset, dapl_id, H5D_ACS_EFILE_PREFIX_NAME, &new_dset->shared->extfile_prefix) < 0) + if(H5D__build_file_prefix(new_dset, H5F_PREFIX_EFILE, &new_dset->shared->extfile_prefix) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to initialize external file prefix") /* Set the VDS file prefix */ - if(H5D__build_file_prefix(new_dset, dapl_id, H5D_ACS_VDS_PREFIX_NAME, &new_dset->shared->vds_prefix) < 0) + if(H5D__build_file_prefix(new_dset, H5F_PREFIX_VDS, &new_dset->shared->vds_prefix) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to initialize VDS prefix") /* Add the dataset to the list of opened objects in the file */ @@ -1485,11 +1490,11 @@ H5D_open(const H5G_loc_t *loc, hid_t dapl_id) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, NULL, "can't copy path") /* Get the external file prefix */ - if(H5D__build_file_prefix(dataset, dapl_id, H5D_ACS_EFILE_PREFIX_NAME, &extfile_prefix) < 0) + if(H5D__build_file_prefix(dataset, H5F_PREFIX_EFILE, &extfile_prefix) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to initialize external file prefix") /* Get the VDS prefix */ - if(H5D__build_file_prefix(dataset, dapl_id, H5D_ACS_VDS_PREFIX_NAME, &vds_prefix) < 0) + if(H5D__build_file_prefix(dataset, H5F_PREFIX_VDS, &vds_prefix) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to initialize VDS prefix") /* Check if dataset was already open */ @@ -1533,8 +1538,13 @@ H5D_open(const H5G_loc_t *loc, hid_t dapl_id) /* Check whether the external file prefix of the already open dataset * matches the new external file prefix */ - if(HDstrcmp(extfile_prefix, dataset->shared->extfile_prefix) != 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, NULL, "new external file prefix does not match external file prefix of already open dataset") + if(extfile_prefix && dataset->shared->extfile_prefix) { + if(HDstrcmp(extfile_prefix, dataset->shared->extfile_prefix) != 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, NULL, "new external file prefix does not match external file prefix of already open dataset") + } else { + if(extfile_prefix || dataset->shared->extfile_prefix) + HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, NULL, "new external file prefix does not match external file prefix of already open dataset") + } /* Check if the object has been opened through the top file yet */ if(H5FO_top_count(dataset->oloc.file, dataset->oloc.addr) == 0) { @@ -1642,7 +1652,7 @@ H5D__append_flush_setup(H5D_t *dset, hid_t dapl_id) dset->shared->append_flush.ndims = info.ndims; dset->shared->append_flush.func = info.func; dset->shared->append_flush.udata = info.udata; - HDmemcpy(dset->shared->append_flush.boundary, info.boundary, sizeof(info.boundary)); + H5MM_memcpy(dset->shared->append_flush.boundary, info.boundary, sizeof(info.boundary)); } /* end if */ } /* end if */ } /* end if */ @@ -2778,7 +2788,7 @@ H5D__set_extent(H5D_t *dset, const hsize_t *size) /* Keep the current dataspace dimensions for later */ HDcompile_assert(sizeof(curr_dims) == sizeof(dset->shared->curr_dims)); - HDmemcpy(curr_dims, dset->shared->curr_dims, H5S_MAX_RANK * sizeof(curr_dims[0])); + H5MM_memcpy(curr_dims, dset->shared->curr_dims, H5S_MAX_RANK * sizeof(curr_dims[0])); /* Modify the size of the dataspace */ if((changed = H5S_set_extent(dset->shared->space, size)) < 0) @@ -2872,7 +2882,7 @@ H5D__set_extent(H5D_t *dset, const hsize_t *size) dset->shared->layout.storage.u.virt.list[u].virtual_space_status = H5O_VIRTUAL_STATUS_CORRECT; /* Patch sub-source datasets */ - for(v = 0; v < dset->shared->layout.storage.u.virt.list[u].sub_dset_nalloc; v++) + for(v = 0; v < dset->shared->layout.storage.u.virt.list[u].sub_dset_nused; v++) if(H5S_set_extent(dset->shared->layout.storage.u.virt.list[u].sub_dset[v].virtual_select, size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to modify size of dataspace") } /* end for */ @@ -2898,7 +2908,8 @@ H5D__set_extent(H5D_t *dset, const hsize_t *size) *------------------------------------------------------------------------- */ if(H5D_CHUNKED == dset->shared->layout.type) { - if(shrink && (*dset->shared->layout.ops->is_space_alloc)(&dset->shared->layout.storage)) + if(shrink && ((*dset->shared->layout.ops->is_space_alloc)(&dset->shared->layout.storage) + || (dset->shared->layout.ops->is_data_cached && (*dset->shared->layout.ops->is_data_cached)(dset->shared)))) /* Remove excess chunks */ if(H5D__chunk_prune_by_extent(dset, curr_dims) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "unable to remove chunks") @@ -3062,7 +3073,7 @@ H5D__format_convert(H5D_t *dataset) idx_info.storage = &dataset->shared->layout.storage.u.chunk; /* Copy the current layout info to the new layout */ - HDmemcpy(newlayout, &dataset->shared->layout, sizeof(H5O_layout_t)); + H5MM_memcpy(newlayout, &dataset->shared->layout, sizeof(H5O_layout_t)); /* Set up info for version 1 B-tree in the new layout */ newlayout->version = H5O_LAYOUT_VERSION_3; @@ -3113,7 +3124,7 @@ H5D__format_convert(H5D_t *dataset) HGOTO_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "unable to release chunk index info") /* Copy the new layout to the dataset's layout */ - HDmemcpy(&dataset->shared->layout, newlayout, sizeof(H5O_layout_t)); + H5MM_memcpy(&dataset->shared->layout, newlayout, sizeof(H5O_layout_t)); break; diff --git a/src/H5Dio.c b/src/H5Dio.c index 2f87e38..9343b80 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -518,7 +518,8 @@ H5D__read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, * has been overwritten. So just proceed in reading. */ if(nelmts > 0 && dataset->shared->dcpl_cache.efl.nused == 0 && - !(*dataset->shared->layout.ops->is_space_alloc)(&dataset->shared->layout.storage)) { + !(*dataset->shared->layout.ops->is_space_alloc)(&dataset->shared->layout.storage) && + !(dataset->shared->layout.ops->is_data_cached && (*dataset->shared->layout.ops->is_data_cached)(dataset->shared))) { H5D_fill_value_t fill_status; /* Whether/How the fill value is defined */ /* Retrieve dataset's fill-value properties */ @@ -550,6 +551,7 @@ H5D__read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, /* Sanity check that space is allocated, if there are elements */ if(nelmts > 0) HDassert((*dataset->shared->layout.ops->is_space_alloc)(&dataset->shared->layout.storage) + || (dataset->shared->layout.ops->is_data_cached && (*dataset->shared->layout.ops->is_data_cached)(dataset->shared)) || dataset->shared->dcpl_cache.efl.nused > 0 || dataset->shared->layout.type == H5D_COMPACT); diff --git a/src/H5Dlayout.c b/src/H5Dlayout.c index 494d2c8..fb28489 100644 --- a/src/H5Dlayout.c +++ b/src/H5Dlayout.c @@ -50,6 +50,7 @@ const unsigned H5O_layout_ver_bounds[] = { H5O_LAYOUT_VERSION_1, /* H5F_LIBVER_EARLIEST */ H5O_LAYOUT_VERSION_3, /* H5F_LIBVER_V18 */ /* H5O_LAYOUT_VERSION_DEFAULT */ + H5O_LAYOUT_VERSION_4, /* H5F_LIBVER_V110 */ H5O_LAYOUT_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; diff --git a/src/H5Dmpio.c b/src/H5Dmpio.c index 2a6c05f..7019362 100644 --- a/src/H5Dmpio.c +++ b/src/H5Dmpio.c @@ -1427,7 +1427,7 @@ H5D__link_chunk_filtered_collective_io(H5D_io_info_t *io_info, const H5D_type_in for (i = 0, offset = 0; i < (size_t) mpi_rank; i++) offset += num_chunks_selected_array[i]; - HDmemcpy(chunk_list, &collective_chunk_list[offset], num_chunks_selected_array[mpi_rank] * sizeof(H5D_filtered_collective_io_info_t)); + H5MM_memcpy(chunk_list, &collective_chunk_list[offset], num_chunks_selected_array[mpi_rank] * sizeof(H5D_filtered_collective_io_info_t)); /* Create single MPI type encompassing each selection in the dataspace */ if (H5D__mpio_filtered_collective_write_type(chunk_list, chunk_list_num_entries, @@ -1553,7 +1553,7 @@ if(H5DEBUG(D)) HGOTO_ERROR(H5E_DATASET, H5E_CANTRECV, FAIL, "unable to obtain MPIO mode") /* Set up contiguous I/O info object */ - HDmemcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); + H5MM_memcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); ctg_io_info.store = &ctg_store; ctg_io_info.layout_ops = *H5D_LOPS_CONTIG; @@ -1561,7 +1561,7 @@ if(H5DEBUG(D)) ctg_store.contig.dset_size = (hsize_t)io_info->dset->shared->layout.u.chunk.size; /* Set up compact I/O info object */ - HDmemcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); + H5MM_memcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); cpt_io_info.store = &cpt_store; cpt_io_info.layout_ops = *H5D_LOPS_COMPACT; @@ -1788,7 +1788,7 @@ H5D__multi_chunk_filtered_collective_io(H5D_io_info_t *io_info, const H5D_type_i HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "couldn't construct filtered I/O info list") /* Set up contiguous I/O info object */ - HDmemcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); + H5MM_memcpy(&ctg_io_info, io_info, sizeof(ctg_io_info)); ctg_io_info.store = &ctg_store; ctg_io_info.layout_ops = *H5D_LOPS_CONTIG; @@ -1893,7 +1893,7 @@ H5D__multi_chunk_filtered_collective_io(H5D_io_info_t *io_info, const H5D_type_i /* Collect the new chunk info back to the local copy, since only the record in the * collective array gets updated by the chunk re-allocation */ - HDmemcpy(&chunk_list[i].chunk_states.new_chunk, &collective_chunk_list[offset].chunk_states.new_chunk, sizeof(chunk_list[i].chunk_states.new_chunk)); + H5MM_memcpy(&chunk_list[i].chunk_states.new_chunk, &collective_chunk_list[offset].chunk_states.new_chunk, sizeof(chunk_list[i].chunk_states.new_chunk)); H5_CHECKED_ASSIGN(mpi_type_count, int, chunk_list[i].chunk_states.new_chunk.length, hsize_t); @@ -2517,8 +2517,8 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm, /* merge buffer io_mode info and chunk addr into one */ - HDmemcpy(mergebuf, assign_io_mode, total_chunks); - HDmemcpy(tempbuf, chunk_addr, sizeof(haddr_t) * total_chunks); + H5MM_memcpy(mergebuf, assign_io_mode, total_chunks); + H5MM_memcpy(tempbuf, chunk_addr, sizeof(haddr_t) * total_chunks); H5MM_free(nproc_per_chunk); } /* end if */ @@ -2527,8 +2527,8 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm, if(MPI_SUCCESS != (mpi_code = MPI_Bcast(mergebuf, ((sizeof(haddr_t) + 1) * total_chunks), MPI_BYTE, root, comm))) HMPI_GOTO_ERROR(FAIL, "MPI_BCast failed", mpi_code) - HDmemcpy(assign_io_mode, mergebuf, total_chunks); - HDmemcpy(chunk_addr, tempbuf, sizeof(haddr_t) * total_chunks); + H5MM_memcpy(assign_io_mode, mergebuf, total_chunks); + H5MM_memcpy(chunk_addr, tempbuf, sizeof(haddr_t) * total_chunks); #ifdef H5_HAVE_INSTRUMENTED_LIBRARY { @@ -2630,7 +2630,7 @@ H5D__construct_filtered_io_info_list(const H5D_io_info_t *io_info, const H5D_typ local_info_array[i].async_info.receive_buffer_array = NULL; local_info_array[i].async_info.receive_requests_array = NULL; - HDmemcpy(local_info_array[i].scaled, chunk_info->scaled, sizeof(chunk_info->scaled)); + H5MM_memcpy(local_info_array[i].scaled, chunk_info->scaled, sizeof(chunk_info->scaled)); if ((select_npoints = H5S_GET_SELECT_NPOINTS(chunk_info->mspace)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "dataspace is invalid") @@ -2742,6 +2742,9 @@ H5D__chunk_redistribute_shared_chunks(const H5D_io_info_t *io_info, const H5D_ty if ((mpi_size = H5F_mpi_get_size(io_info->dset->oloc.file)) < 0) HGOTO_ERROR(H5E_IO, H5E_MPI, FAIL, "unable to obtain mpi size") + /* Set to latest format for encoding dataspace */ + H5CX_set_libver_bounds(NULL); + if (*local_chunk_array_num_entries) if (NULL == (send_requests = (MPI_Request *) H5MM_malloc(*local_chunk_array_num_entries * sizeof(MPI_Request)))) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate send requests buffer") diff --git a/src/H5Dpkg.h b/src/H5Dpkg.h index 2767aa1..e7c623b 100644 --- a/src/H5Dpkg.h +++ b/src/H5Dpkg.h @@ -113,12 +113,14 @@ typedef struct H5D_type_info_t { /* Forward declaration of structs used below */ struct H5D_io_info_t; struct H5D_chunk_map_t; +typedef struct H5D_shared_t H5D_shared_t; /* Function pointers for I/O on particular types of dataset layouts */ typedef herr_t (*H5D_layout_construct_func_t)(H5F_t *f, H5D_t *dset); typedef herr_t (*H5D_layout_init_func_t)(H5F_t *f, const H5D_t *dset, hid_t dapl_id); typedef hbool_t (*H5D_layout_is_space_alloc_func_t)(const H5O_storage_t *storage); +typedef hbool_t (*H5D_layout_is_data_cached_func_t)(const H5D_shared_t *shared_dset); typedef herr_t (*H5D_layout_io_init_func_t)(const struct H5D_io_info_t *io_info, const H5D_type_info_t *type_info, hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space, @@ -144,6 +146,7 @@ typedef struct H5D_layout_ops_t { H5D_layout_construct_func_t construct; /* Layout constructor for new datasets */ H5D_layout_init_func_t init; /* Layout initializer for dataset */ H5D_layout_is_space_alloc_func_t is_space_alloc; /* Query routine to determine if storage is allocated */ + H5D_layout_is_data_cached_func_t is_data_cached; /* Query routine to determine if any raw data is cached. If routine is not present then the layout type never caches raw data. */ H5D_layout_io_init_func_t io_init; /* I/O initialization routine */ H5D_layout_read_func_t ser_read; /* High-level I/O routine for reading data in serial */ H5D_layout_write_func_t ser_write; /* High-level I/O routine for writing data in serial */ @@ -429,7 +432,7 @@ typedef struct H5D_rdcdc_t { * created once for a given dataset. Thus, if a dataset is opened twice, * there will be two IDs and two H5D_t structs, both sharing one H5D_shared_t. */ -typedef struct H5D_shared_t { +struct H5D_shared_t { size_t fo_count; /* Reference count */ hbool_t closing; /* Flag to indicate dataset is closing */ hid_t type_id; /* ID for dataset's datatype */ @@ -459,7 +462,7 @@ typedef struct H5D_shared_t { H5D_append_flush_t append_flush; /* Append flush property information */ char *extfile_prefix; /* expanded external file prefix */ char *vds_prefix; /* expanded vds prefix */ -} H5D_shared_t; +}; struct H5D_t { H5O_loc_t oloc; /* Object header location */ @@ -618,6 +621,7 @@ H5_DLL herr_t H5D__layout_oh_write(const H5D_t *dataset, H5O_t *oh, unsigned upd /* Functions that operate on contiguous storage */ H5_DLL herr_t H5D__contig_alloc(H5F_t *f, H5O_storage_contig_t *storage); H5_DLL hbool_t H5D__contig_is_space_alloc(const H5O_storage_t *storage); +H5_DLL hbool_t H5D__contig_is_data_cached(const H5D_shared_t *shared_dset); H5_DLL herr_t H5D__contig_fill(const H5D_io_info_t *io_info); H5_DLL herr_t H5D__contig_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space, @@ -636,6 +640,7 @@ H5_DLL htri_t H5D__chunk_cacheable(const H5D_io_info_t *io_info, haddr_t caddr, H5_DLL herr_t H5D__chunk_create(const H5D_t *dset /*in,out*/); H5_DLL herr_t H5D__chunk_set_info(const H5D_t *dset); H5_DLL hbool_t H5D__chunk_is_space_alloc(const H5O_storage_t *storage); +H5_DLL hbool_t H5D__chunk_is_data_cached(const H5D_shared_t *shared_dset); H5_DLL herr_t H5D__chunk_lookup(const H5D_t *dset, const hsize_t *scaled, H5D_chunk_ud_t *udata); H5_DLL herr_t H5D__chunk_allocated(const H5D_t *dset, hsize_t *nbytes); diff --git a/src/H5Dscatgath.c b/src/H5Dscatgath.c index 266f5f5..0e0edf7 100644 --- a/src/H5Dscatgath.c +++ b/src/H5Dscatgath.c @@ -27,6 +27,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -117,7 +118,7 @@ H5D__scatter_file(const H5D_io_info_t *_io_info, HDassert(_buf); /* Set up temporary I/O info object */ - HDmemcpy(&tmp_io_info, _io_info, sizeof(*_io_info)); + H5MM_memcpy(&tmp_io_info, _io_info, sizeof(*_io_info)); tmp_io_info.op_type = H5D_IO_OP_WRITE; tmp_io_info.u.wbuf = _buf; @@ -220,7 +221,7 @@ H5D__gather_file(const H5D_io_info_t *_io_info, HDassert(_buf); /* Set up temporary I/O info object */ - HDmemcpy(&tmp_io_info, _io_info, sizeof(*_io_info)); + H5MM_memcpy(&tmp_io_info, _io_info, sizeof(*_io_info)); tmp_io_info.op_type = H5D_IO_OP_READ; tmp_io_info.u.rbuf = _buf; @@ -337,7 +338,7 @@ H5D__scatter_mem (const void *_tscat_buf, const H5S_t *space, /* Get the number of bytes in sequence */ curr_len = len[curr_seq]; - HDmemcpy(buf + off[curr_seq], tscat_buf, curr_len); + H5MM_memcpy(buf + off[curr_seq], tscat_buf, curr_len); /* Advance offset in destination buffer */ tscat_buf += curr_len; @@ -425,7 +426,7 @@ H5D__gather_mem(const void *_buf, const H5S_t *space, /* Get the number of bytes in sequence */ curr_len = len[curr_seq]; - HDmemcpy(tgath_buf, buf + off[curr_seq], curr_len); + H5MM_memcpy(tgath_buf, buf + off[curr_seq], curr_len); /* Advance offset in gather buffer */ tgath_buf += curr_len; diff --git a/src/H5Dselect.c b/src/H5Dselect.c index 0ec3423..4ffce62 100644 --- a/src/H5Dselect.c +++ b/src/H5Dselect.c @@ -227,6 +227,8 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, /* Decrement number of elements left to process */ HDassert(((size_t)tmp_file_len % elmt_size) == 0); + if(elmt_size == 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "Resulted in division by zero") nelmts -= ((size_t)tmp_file_len / elmt_size); } /* end while */ } /* end else */ diff --git a/src/H5Dvirtual.c b/src/H5Dvirtual.c index c0d49d8..e3e0aa5 100644 --- a/src/H5Dvirtual.c +++ b/src/H5Dvirtual.c @@ -78,6 +78,7 @@ /********************/ /* Layout operation callbacks */ +static hbool_t H5D__virtual_is_data_cached(const H5D_shared_t *shared_dset); static herr_t H5D__virtual_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space, H5D_chunk_map_t *fm); @@ -121,6 +122,7 @@ const H5D_layout_ops_t H5D_LOPS_VIRTUAL[1] = {{ NULL, H5D__virtual_init, H5D__virtual_is_space_alloc, + H5D__virtual_is_data_cached, NULL, H5D__virtual_read, H5D__virtual_write, @@ -428,6 +430,10 @@ H5D__virtual_store_layout(H5F_t *f, H5O_layout_t *layout) /* Create block if # of used entries > 0 */ if(layout->storage.u.virt.list_nused > 0) { + + /* Set the low/high bounds according to 'f' for the API context */ + H5CX_set_libver_bounds(f); + /* Allocate array for caching results of strlen */ if(NULL == (str_size = (size_t *)H5MM_malloc(2 * layout->storage.u.virt.list_nused * sizeof(size_t)))) HGOTO_ERROR(H5E_OHDR, H5E_RESOURCE, FAIL, "unable to allocate string length array") @@ -491,11 +497,11 @@ H5D__virtual_store_layout(H5F_t *f, H5O_layout_t *layout) /* Encode each entry */ for(i = 0; i < layout->storage.u.virt.list_nused; i++) { /* Source file name */ - HDmemcpy((char *)heap_block_p, layout->storage.u.virt.list[i].source_file_name, str_size[2 * i]); + H5MM_memcpy((char *)heap_block_p, layout->storage.u.virt.list[i].source_file_name, str_size[2 * i]); heap_block_p += str_size[2 * i]; /* Source dataset name */ - HDmemcpy((char *)heap_block_p, layout->storage.u.virt.list[i].source_dset_name, str_size[(2 * i) + 1]); + H5MM_memcpy((char *)heap_block_p, layout->storage.u.virt.list[i].source_dset_name, str_size[(2 * i) + 1]); heap_block_p += str_size[(2 * i) + 1]; /* Source selection */ @@ -1107,7 +1113,7 @@ H5D__virtual_str_append(const char *src, size_t src_len, char **p, char **buf, /* Copy string to *p. Note that since src in not NULL terminated, we must * use memcpy */ - (void)HDmemcpy(*p, src, src_len); + (void)H5MM_memcpy(*p, src, src_len); /* Advance *p */ *p += src_len; @@ -2207,6 +2213,54 @@ H5D__virtual_is_space_alloc(const H5O_storage_t H5_ATTR_UNUSED *storage) /*------------------------------------------------------------------------- + * Function: H5D__virtual_is_data_cached + * + * Purpose: Query if raw data is cached for dataset + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Neil Fortner + * Wednessday, March 6, 2016 + * + *------------------------------------------------------------------------- + */ +static hbool_t +H5D__virtual_is_data_cached(const H5D_shared_t *shared_dset) +{ + const H5O_storage_virtual_t *storage; /* Convenience pointer */ + size_t i, j; /* Local index variables */ + hbool_t ret_value = FALSE; /* Return value */ + + FUNC_ENTER_PACKAGE_NOERR + + /* Sanity checks */ + HDassert(shared_dset); + storage = &shared_dset->layout.storage.u.virt; + + /* Iterate over mappings */ + for(i = 0; i < storage->list_nused; i++) + /* Check for "printf" source dataset resolution */ + if(storage->list[i].psfn_nsubs || storage->list[i].psdn_nsubs) { + /* Iterate over sub-source dsets */ + for(j = storage->list[i].sub_dset_io_start; j < storage->list[i].sub_dset_io_end; j++) + /* Check for cahced data in source dset */ + if(storage->list[i].sub_dset[j].dset + && storage->list[i].sub_dset[j].dset->shared->layout.ops->is_data_cached + && storage->list[i].sub_dset[j].dset->shared->layout.ops->is_data_cached(storage->list[i].sub_dset[j].dset->shared)) + HGOTO_DONE(TRUE); + } /* end if */ + else + if(storage->list[i].source_dset.dset + && storage->list[i].source_dset.dset->shared->layout.ops->is_data_cached + && storage->list[i].source_dset.dset->shared->layout.ops->is_data_cached(storage->list[i].source_dset.dset->shared)) + HGOTO_DONE(TRUE); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D__virtual_is_data_cached() */ + + +/*------------------------------------------------------------------------- * Function: H5D__virtual_pre_io * * Purpose: Project all virtual mappings onto mem_space, with the @@ -2981,7 +3035,7 @@ H5D__virtual_refresh_source_dset(H5D_t **dset) /* Discard the identifier & replace the dataset */ if(NULL == (vol_obj = (H5VL_object_t *)H5I_remove(temp_id))) HGOTO_ERROR(H5E_DATASET, H5E_CANTREMOVE, FAIL, "can't unregister source dataset ID") - if(NULL == (*dset = (H5D_t *)H5VL_object_data(vol_obj))) + if(NULL == (*dset = (H5D_t *)H5VL_object_unwrap(vol_obj))) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't retrieve library object from VOL object") vol_obj->data = NULL; @@ -46,6 +46,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5EApkg.h" /* Extensible Arrays */ #include "H5FLprivate.h" /* Free Lists */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vector functions */ @@ -693,7 +694,7 @@ H5EA_set(const H5EA_t *ea, hsize_t idx, const void *elmt)) HDassert(thing_unprot_func); /* Set element in thing's element buffer */ - HDmemcpy(thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), elmt, hdr->cparam.cls->nat_elmt_size); + H5MM_memcpy(thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), elmt, hdr->cparam.cls->nat_elmt_size); thing_cache_flags |= H5AC__DIRTIED_FLAG; /* Update max. element set in array, if appropriate */ @@ -765,7 +766,7 @@ H5EA_get(const H5EA_t *ea, hsize_t idx, void *elmt)) } /* end if */ else /* Get element from thing's element buffer */ - HDmemcpy(elmt, thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), hdr->cparam.cls->nat_elmt_size); + H5MM_memcpy(elmt, thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), hdr->cparam.cls->nat_elmt_size); } /* end else */ CATCH diff --git a/src/H5EAcache.c b/src/H5EAcache.c index 8138991..da67e6b 100644 --- a/src/H5EAcache.c +++ b/src/H5EAcache.c @@ -41,6 +41,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5EApkg.h" /* Extensible Arrays */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vectors and arrays */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -479,7 +480,7 @@ H5EA__cache_hdr_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED le HDassert(hdr); /* Magic number */ - HDmemcpy(image, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -867,7 +868,7 @@ H5EA__cache_iblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED /* Get temporary pointer to serialized info */ /* Magic number */ - HDmemcpy(image, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -1179,7 +1180,7 @@ H5EA__cache_sblock_deserialize(const void *_image, size_t len, size_t tot_page_init_size = sblock->ndblks * sblock->dblk_page_init_size; /* Compute total size of 'page init' buffer */ /* Retrieve the 'page init' bitmasks */ - HDmemcpy(sblock->page_init, image, tot_page_init_size); + H5MM_memcpy(sblock->page_init, image, tot_page_init_size); image += tot_page_init_size; } /* end if */ @@ -1276,7 +1277,7 @@ H5EA__cache_sblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED HDassert(sblock->hdr); /* Magic number */ - HDmemcpy(image, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -1298,7 +1299,7 @@ H5EA__cache_sblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED size_t tot_page_init_size = sblock->ndblks * sblock->dblk_page_init_size; /* Compute total size of 'page init' buffer */ /* Store the 'page init' bitmasks */ - HDmemcpy(image, sblock->page_init, tot_page_init_size); + H5MM_memcpy(image, sblock->page_init, tot_page_init_size); image += tot_page_init_size; } /* end if */ @@ -1690,7 +1691,7 @@ H5EA__cache_dblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED HDassert(dblock->hdr); /* Magic number */ - HDmemcpy(image, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ diff --git a/src/H5EAhdr.c b/src/H5EAhdr.c index 62a23b8..18d642f 100644 --- a/src/H5EAhdr.c +++ b/src/H5EAhdr.c @@ -41,6 +41,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5EApkg.h" /* Extensible Arrays */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vectors and arrays */ @@ -407,7 +408,7 @@ H5EA__hdr_create(H5F_t *f, const H5EA_create_t *cparam, void *ctx_udata)) hdr->idx_blk_addr = HADDR_UNDEF; /* Set the creation parameters for the array */ - HDmemcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); + H5MM_memcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); /* Finish initializing extensible array header */ if(H5EA__hdr_init(hdr, ctx_udata) < 0) diff --git a/src/H5EAstat.c b/src/H5EAstat.c index 72c4d14..509d3f8 100644 --- a/src/H5EAstat.c +++ b/src/H5EAstat.c @@ -40,6 +40,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5EApkg.h" /* Extensible Arrays */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -108,7 +109,7 @@ HDfprintf(stderr, "%s: Called\n", FUNC); HDassert(stats); /* Copy extensible array statistics */ - HDmemcpy(stats, &ea->hdr->stats, sizeof(ea->hdr->stats)); + H5MM_memcpy(stats, &ea->hdr->stats, sizeof(ea->hdr->stats)); END_FUNC(PRIV) /* end H5EA_get_stats() */ @@ -921,6 +921,42 @@ done: /*------------------------------------------------------------------------- + * Function: H5Fget_fileno + * + * Purpose: Public API to retrieve the file's 'file number' that uniquely + * identifies each open file. + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5Fget_fileno(hid_t file_id, unsigned long *fileno) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_API(FAIL) + H5TRACE2("e", "i*Ul", file_id, fileno); + + /* If no fileno pointer was passed in, exit quietly */ + if(fileno) { + H5VL_object_t *vol_obj; /* File info */ + + /* Get the internal file structure */ + if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + + /* Get the flags */ + if((ret_value = H5VL_file_get(vol_obj, H5VL_FILE_GET_FILENO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, fileno)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file's 'file number'") + } /* end if */ + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Fget_fileno() */ + + +/*------------------------------------------------------------------------- * Function: H5Fget_freespace * * Purpose: Retrieves the amount of free space in the file. @@ -41,6 +41,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FApkg.h" /* Fixed Arrays */ #include "H5FLprivate.h" /* Free Lists */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vector functions */ @@ -371,7 +372,7 @@ H5FA_set(const H5FA_t *fa, hsize_t idx, const void *elmt)) /* Check for paging data block */ if(!dblock->npages) { /* Set element in data block */ - HDmemcpy(((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), elmt, hdr->cparam.cls->nat_elmt_size); + H5MM_memcpy(((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), elmt, hdr->cparam.cls->nat_elmt_size); dblock_cache_flags |= H5AC__DIRTIED_FLAG; } /* end if */ else { /* paging */ @@ -410,7 +411,7 @@ H5FA_set(const H5FA_t *fa, hsize_t idx, const void *elmt)) H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", (unsigned long long)dblk_page_addr) /* Set the element in the data block page */ - HDmemcpy(((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), elmt, hdr->cparam.cls->nat_elmt_size); + H5MM_memcpy(((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), elmt, hdr->cparam.cls->nat_elmt_size); dblk_page_cache_flags |= H5AC__DIRTIED_FLAG; } /* end else */ @@ -474,7 +475,7 @@ H5FA_get(const H5FA_t *fa, hsize_t idx, void *elmt)) /* Check for paged data block */ if(!dblock->npages) /* Retrieve element from data block */ - HDmemcpy(elmt, ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), hdr->cparam.cls->nat_elmt_size); + H5MM_memcpy(elmt, ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), hdr->cparam.cls->nat_elmt_size); else { /* paging */ size_t page_idx; /* Index of page within data block */ @@ -512,7 +513,7 @@ H5FA_get(const H5FA_t *fa, hsize_t idx, void *elmt)) H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", (unsigned long long)dblk_page_addr) /* Retrieve element from data block */ - HDmemcpy(elmt, ((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), hdr->cparam.cls->nat_elmt_size); + H5MM_memcpy(elmt, ((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), hdr->cparam.cls->nat_elmt_size); } /* end else */ } /* end else */ } /* end else */ diff --git a/src/H5FAcache.c b/src/H5FAcache.c index 1f199e9..f440efe 100644 --- a/src/H5FAcache.c +++ b/src/H5FAcache.c @@ -41,6 +41,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FApkg.h" /* Fixed Arrays */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vectors and arrays */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -409,7 +410,7 @@ H5FA__cache_hdr_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED le HDassert(hdr); /* Magic number */ - HDmemcpy(image, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -693,7 +694,7 @@ H5FA__cache_dblock_deserialize(const void *_image, size_t len, /* Page initialization flags */ if(dblock->npages > 0) { - HDmemcpy(dblock->dblk_page_init, image, dblock->dblk_page_init_size); + H5MM_memcpy(dblock->dblk_page_init, image, dblock->dblk_page_init_size); image += dblock->dblk_page_init_size; } /* end if */ @@ -797,7 +798,7 @@ H5FA__cache_dblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED HDassert(dblock->hdr); /* Magic number */ - HDmemcpy(image, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -812,7 +813,7 @@ H5FA__cache_dblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED /* Page init flags */ if(dblock->npages > 0) { /* Store the 'page init' bitmasks */ - HDmemcpy(image, dblock->dblk_page_init, dblock->dblk_page_init_size); + H5MM_memcpy(image, dblock->dblk_page_init, dblock->dblk_page_init_size); image += dblock->dblk_page_init_size; } /* end if */ diff --git a/src/H5FAhdr.c b/src/H5FAhdr.c index 2e3db0b..8f29b83 100644 --- a/src/H5FAhdr.c +++ b/src/H5FAhdr.c @@ -39,6 +39,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FApkg.h" /* Fixed Arrays */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -207,7 +208,7 @@ H5FA__hdr_create(H5F_t *f, const H5FA_create_t *cparam, void *ctx_udata)) hdr->dblk_addr = HADDR_UNDEF; /* Set the creation parameters for the array */ - HDmemcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); + H5MM_memcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); /* Finish initializing fixed array header */ if(H5FA__hdr_init(hdr, ctx_udata) < 0) diff --git a/src/H5FAstat.c b/src/H5FAstat.c index 3c06855..49a56a9 100644 --- a/src/H5FAstat.c +++ b/src/H5FAstat.c @@ -38,6 +38,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5FApkg.h" /* Fixed Arrays */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -105,7 +106,7 @@ HDfprintf(stderr, "%s: Called\n", FUNC); HDassert(stats); /* Copy fixed array statistics */ - HDmemcpy(stats, &fa->hdr->stats, sizeof(fa->hdr->stats)); + H5MM_memcpy(stats, &fa->hdr->stats, sizeof(fa->hdr->stats)); END_FUNC(PRIV) /* end H5FA_get_stats() */ @@ -293,7 +293,7 @@ H5FD_register(const void *_cls, size_t size, hbool_t app_ref) /* Copy the class structure so the caller can reuse or free it */ if(NULL == (saved = (H5FD_class_t *)H5MM_malloc(size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5I_INVALID_HID, "memory allocation failed for file driver class struct") - HDmemcpy(saved, cls, size); + H5MM_memcpy(saved, cls, size); /* Create the new class ID */ if((ret_value = H5I_register(H5I_VFL, saved, app_ref)) < 0) @@ -1367,7 +1367,7 @@ H5FD_get_fs_type_map(const H5FD_t *file, H5FD_mem_t *type_map) } /* end if */ else /* Copy class's default free space type mapping */ - HDmemcpy(type_map, file->cls->fl_map, sizeof(file->cls->fl_map)); + H5MM_memcpy(type_map, file->cls->fl_map, sizeof(file->cls->fl_map)); done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5FDcore.c b/src/H5FDcore.c index d1a17cd..6db8af6 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -848,7 +848,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, NULL, "image_memcpy callback failed") } /* end if */ else - HDmemcpy(file->mem, file_image_info.buffer, size); + H5MM_memcpy(file->mem, file_image_info.buffer, size); } /* end if */ /* Read in existing data from the file if there is no image */ else { @@ -1300,7 +1300,7 @@ H5FD__core_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU nbytes = MIN(size,(size_t)(file->eof-addr)); #endif /* NDEBUG */ - HDmemcpy(buf, file->mem + addr, nbytes); + H5MM_memcpy(buf, file->mem + addr, nbytes); size -= nbytes; addr += nbytes; buf = (char *)buf + nbytes; @@ -1386,7 +1386,7 @@ H5FD__core_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN } /* Write from BUF to memory */ - HDmemcpy(file->mem + addr, buf, size); + H5MM_memcpy(file->mem + addr, buf, size); /* Mark memory buffer as modified */ file->dirty = TRUE; diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c index 10c368a..33a0ef4 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -422,7 +422,7 @@ H5FD_direct_fapl_copy(const void *_old_fa) HDassert(new_fa); /* Copy the general information */ - HDmemcpy(new_fa, old_fa, sizeof(H5FD_direct_fapl_t)); + H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_direct_fapl_t)); FUNC_LEAVE_NOAPI(new_fa) } /* end H5FD_direct_fapl_copy() */ @@ -976,12 +976,12 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN * next section of data. */ p2 = (unsigned char*)copy_buf + copy_offset; if((copy_size + copy_offset) <= alloc_size) { - HDmemcpy(buf, p2, copy_size); + H5MM_memcpy(buf, p2, copy_size); buf = (unsigned char *)buf + copy_size; copy_size = 0; } /* end if */ else { - HDmemcpy(buf, p2, alloc_size - copy_offset); + H5MM_memcpy(buf, p2, alloc_size - copy_offset); buf = (unsigned char*)buf + alloc_size - copy_offset; copy_size -= alloc_size - copy_offset; copy_offset = 0; @@ -1189,11 +1189,11 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_U */ p1 = (unsigned char *)copy_buf + copy_offset; if((copy_size + copy_offset) <= alloc_size) { - HDmemcpy(p1, p3, copy_size); + H5MM_memcpy(p1, p3, copy_size); copy_size = 0; } /* end if */ else { - HDmemcpy(p1, p3, alloc_size - copy_offset); + H5MM_memcpy(p1, p3, alloc_size - copy_offset); p3 = (const unsigned char *)p3 + (alloc_size - copy_offset); copy_size -= alloc_size - copy_offset; copy_offset = 0; diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index 4d40cf3..047fb25 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -411,7 +411,7 @@ H5FD_family_fapl_copy(const void *_old_fa) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy the fields of the structure */ - HDmemcpy(new_fa, old_fa, sizeof(H5FD_family_fapl_t)); + H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_family_fapl_t)); /* Deep copy the property list objects in the structure */ if(old_fa->memb_fapl_id==H5P_FILE_ACCESS_DEFAULT) { diff --git a/src/H5FDlog.c b/src/H5FDlog.c index 655d7d3..06a0e61 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -405,7 +405,7 @@ H5FD_log_fapl_copy(const void *_old_fa) HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "unable to allocate log file FAPL") /* Copy the general information */ - HDmemcpy(new_fa, old_fa, sizeof(H5FD_log_fapl_t)); + H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_log_fapl_t)); /* Deep copy the log file name */ if(old_fa->logfile != NULL) diff --git a/src/H5FDmpio.c b/src/H5FDmpio.c index 3ab90aa..d5aa170 100644 --- a/src/H5FDmpio.c +++ b/src/H5FDmpio.c @@ -745,7 +745,7 @@ if(H5FD_mpio_Debug[(int)'t']) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy the general information */ - HDmemcpy(new_fa, old_fa, sizeof(H5FD_mpio_fapl_t)); + H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_mpio_fapl_t)); /* Duplicate communicator and Info object. */ if(H5FD_mpi_comm_info_dup(old_fa->comm, old_fa->info, &new_fa->comm, &new_fa->info) < 0) @@ -1142,7 +1142,7 @@ H5FL_blk_realloc(H5FL_blk_head_t *head, void *block, size_t new_size H5FL_TRACK_ if((ret_value=H5FL_blk_malloc(head,new_size H5FL_TRACK_INFO_INT))==NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for block") blk_size=MIN(new_size,temp->size); - HDmemcpy(ret_value,block,blk_size); + H5MM_memcpy(ret_value,block,blk_size); H5FL_blk_free(head,block); } /* end if */ else { @@ -1630,7 +1630,7 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void * obj, size_t new_elem) /* Copy the appropriate amount of elements */ blk_size = head->list_arr[MIN(temp->nelem, new_elem)].size; - HDmemcpy(ret_value, obj, blk_size); + H5MM_memcpy(ret_value, obj, blk_size); /* Free the old block */ H5FL_arr_free(head, obj); @@ -36,6 +36,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FSpkg.h" /* File free space */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -615,7 +616,7 @@ H5FS__new(const H5F_t *f, uint16_t nclasses, const H5FS_section_class_t *classes HDassert(u == classes[u]->type); /* Copy the class information into the free space manager */ - HDmemcpy(&fspace->sect_cls[u], classes[u], sizeof(H5FS_section_class_t)); + H5MM_memcpy(&fspace->sect_cls[u], classes[u], sizeof(H5FS_section_class_t)); /* Call the class initialization routine, if there is one */ if(fspace->sect_cls[u].init_cls) diff --git a/src/H5FScache.c b/src/H5FScache.c index ac0874e..7525a9a 100644 --- a/src/H5FScache.c +++ b/src/H5FScache.c @@ -38,6 +38,7 @@ #include "H5Fprivate.h" /* File */ #include "H5FSpkg.h" /* File free space */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vectors and arrays */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -707,7 +708,7 @@ H5FS__cache_hdr_serialize(const H5F_t *f, void *_image, size_t len, (fspace->alloc_sect_size == (size_t)fspace->sect_size))); /* Magic number */ - HDmemcpy(image, H5FS_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5FS_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -1265,7 +1266,7 @@ H5FS__cache_sinfo_serialize(const H5F_t *f, void *_image, size_t len, HDassert(fspace->sect_cls); /* Magic number */ - HDmemcpy(image, H5FS_SINFO_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5FS_SINFO_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ diff --git a/src/H5Faccum.c b/src/H5Faccum.c index 0b33f8e..8d7852b 100644 --- a/src/H5Faccum.c +++ b/src/H5Faccum.c @@ -38,6 +38,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Fpkg.h" /* File access */ #include "H5FDprivate.h" /* File drivers */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vectors and arrays */ @@ -198,7 +199,7 @@ H5F__accum_read(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, } /* end if */ /* Copy the data out of the buffer */ - HDmemcpy(buf, accum->buf + (addr - new_addr), size); + H5MM_memcpy(buf, accum->buf + (addr - new_addr), size); /* Adjust the accumulator address & size */ accum->loc = new_addr; @@ -250,7 +251,7 @@ H5F__accum_read(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, } /* end else */ /* Copy the dirty region to buffer */ - HDmemcpy((unsigned char *)buf + buf_off, (unsigned char *)accum->buf + accum->dirty_off + dirty_off, overlap_size); + H5MM_memcpy((unsigned char *)buf + buf_off, (unsigned char *)accum->buf + accum->dirty_off + dirty_off, overlap_size); } /* end if */ } /* end else */ } /* end if */ @@ -457,7 +458,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, HDmemmove(accum->buf + size, accum->buf, accum->size); /* Copy the new metadata at the front */ - HDmemcpy(accum->buf, buf, size); + H5MM_memcpy(accum->buf, buf, size); /* Set the new size & location of the metadata accumulator */ accum->loc = addr; @@ -479,7 +480,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, HGOTO_ERROR(H5E_IO, H5E_CANTRESIZE, FAIL, "can't adjust metadata accumulator") /* Copy the new metadata to the end */ - HDmemcpy(accum->buf + accum->size, buf, size); + H5MM_memcpy(accum->buf + accum->size, buf, size); /* Adjust the dirty region and mark accumulator dirty */ if(accum->dirty) @@ -502,7 +503,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, size_t dirty_off = (size_t)(addr - accum->loc); /* Copy the new metadata to the proper location within the accumulator */ - HDmemcpy(accum->buf + dirty_off, buf, size); + H5MM_memcpy(accum->buf + dirty_off, buf, size); /* Adjust the dirty region and mark accumulator dirty */ if(accum->dirty) { @@ -545,7 +546,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, HDmemmove(accum->buf + size, accum->buf + old_offset, (accum->size - old_offset)); /* Copy the new metadata at the front */ - HDmemcpy(accum->buf, buf, size); + H5MM_memcpy(accum->buf, buf, size); /* Set the new size & location of the metadata accumulator */ accum->loc = addr; @@ -582,7 +583,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, dirty_off = (size_t)(addr - accum->loc); /* Copy the new metadata to the end */ - HDmemcpy(accum->buf + dirty_off, buf, size); + H5MM_memcpy(accum->buf + dirty_off, buf, size); /* Set the new size of the metadata accumulator */ accum->size += add_size; @@ -625,7 +626,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, } /* end if */ /* Copy the new metadata to the buffer */ - HDmemcpy(accum->buf, buf, size); + H5MM_memcpy(accum->buf, buf, size); /* Set the new size & location of the metadata accumulator */ accum->loc = addr; @@ -688,7 +689,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, accum->size = size; /* Store the piece of metadata in the accumulator */ - HDmemcpy(accum->buf, buf, size); + H5MM_memcpy(accum->buf, buf, size); /* Adjust the dirty region and mark accumulator dirty */ accum->dirty_off = 0; @@ -721,7 +722,7 @@ H5F__accum_write(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, accum->size = size; /* Store the piece of metadata in the accumulator */ - HDmemcpy(accum->buf, buf, size); + H5MM_memcpy(accum->buf, buf, size); /* Adjust the dirty region and mark accumulator dirty */ accum->dirty_off = 0; diff --git a/src/H5Fint.c b/src/H5Fint.c index 8a7019d..5d03b3b 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -1362,19 +1362,10 @@ H5F__dest(H5F_t *f, hbool_t flush) HDONE_ERROR(H5E_FILE, H5E_CANTDEC, FAIL, "can't close property list") /* Clean up the cached VOL connector ID & info */ - if(f->shared->vol_info) { - H5VL_class_t *connector; /* Pointer to connector */ - - /* Retrieve the connector for the ID */ - if(NULL == (connector = (H5VL_class_t *)H5I_object(f->shared->vol_id))) - /* Push error, but keep going*/ - HDONE_ERROR(H5E_FILE, H5E_BADTYPE, FAIL, "not a VOL connector ID") - - /* Free the connector info */ - if(H5VL_free_connector_info(connector, f->shared->vol_info) < 0) + if(f->shared->vol_info) + if(H5VL_free_connector_info(f->shared->vol_id, f->shared->vol_info) < 0) /* Push error, but keep going*/ HDONE_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object") - } /* end if */ if(f->shared->vol_id > 0) if(H5I_dec_ref(f->shared->vol_id) < 0) /* Push error, but keep going*/ @@ -3254,7 +3245,7 @@ H5F_get_metadata_read_retry_info(H5F_t *file, H5F_retry_info_t *info) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy the information */ - HDmemcpy(info->retries[j], file->shared->retries[i], tot_size); + H5MM_memcpy(info->retries[j], file->shared->retries[i], tot_size); } /* Increment location in info->retries[] array */ @@ -3336,7 +3327,7 @@ H5F__start_swmr_write(H5F_t *f) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "file superblock version - should be at least 3") /* Check for correct file format version */ - if((f->shared->low_bound != H5F_LIBVER_V110) || (f->shared->high_bound != H5F_LIBVER_V110)) + if((f->shared->low_bound < H5F_LIBVER_V110) || (f->shared->high_bound < H5F_LIBVER_V110)) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "file format version does not support SWMR - needs to be 1.10 or greater") /* Should not be marked for SWMR writing mode already */ diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 5f7a1b2..0fa2214 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -28,6 +28,7 @@ typedef struct H5F_t H5F_t; #include "H5FDpublic.h" /* File drivers */ /* Private headers needed by this file */ +#include "H5MMprivate.h" /* Memory management */ #ifdef H5_HAVE_PARALLEL #include "H5Pprivate.h" /* Property lists */ #endif /* H5_HAVE_PARALLEL */ @@ -134,7 +135,7 @@ typedef struct H5F_t H5F_t; \ HDcompile_assert(sizeof(double) == 8); \ HDcompile_assert(sizeof(double) == sizeof(uint64_t)); \ - HDmemcpy(&_n, &n, sizeof(double)); \ + H5MM_memcpy(&_n, &n, sizeof(double)); \ for(_u = 0; _u < sizeof(uint64_t); _u++, _n >>= 8) \ *_p++ = (uint8_t)(_n & 0xff); \ (p) = (uint8_t *)(p) + 8; \ @@ -240,7 +241,7 @@ typedef struct H5F_t H5F_t; (p) += 8; \ for(_u = 0; _u < sizeof(uint64_t); _u++) \ _n = (_n << 8) | *(--p); \ - HDmemcpy(&(n), &_n, sizeof(double)); \ + H5MM_memcpy(&(n), &_n, sizeof(double)); \ (p) += 8; \ } @@ -701,8 +702,9 @@ typedef enum H5F_mem_page_t { /* Type of prefix for opening prefixed files */ typedef enum H5F_prefix_open_t { - H5F_PREFIX_VDS, /* Virtual dataset prefix */ - H5F_PREFIX_ELINK /* External link prefix */ + H5F_PREFIX_VDS = 0, /* Virtual dataset prefix */ + H5F_PREFIX_ELINK = 1, /* External link prefix */ + H5F_PREFIX_EFILE = 2 /* External file prefix */ } H5F_prefix_open_t; diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h index 9f1ed01..52f1ee2 100644 --- a/src/H5Fpublic.h +++ b/src/H5Fpublic.h @@ -178,11 +178,12 @@ typedef enum H5F_libver_t { H5F_LIBVER_ERROR = -1, H5F_LIBVER_EARLIEST = 0, /* Use the earliest possible format for storing objects */ H5F_LIBVER_V18 = 1, /* Use the latest v18 format for storing objects */ - H5F_LIBVER_V110 = 2, /* Use the latest v10 format for storing objects */ + H5F_LIBVER_V110 = 2, /* Use the latest v110 format for storing objects */ + H5F_LIBVER_V112 = 3, /* Use the latest v112 format for storing objects */ H5F_LIBVER_NBOUNDS } H5F_libver_t; -#define H5F_LIBVER_LATEST H5F_LIBVER_V110 +#define H5F_LIBVER_LATEST H5F_LIBVER_V112 /* File space handling strategy */ typedef enum H5F_fspace_strategy_t { @@ -235,6 +236,7 @@ H5_DLL herr_t H5Fclose(hid_t file_id); H5_DLL hid_t H5Fget_create_plist(hid_t file_id); H5_DLL hid_t H5Fget_access_plist(hid_t file_id); H5_DLL herr_t H5Fget_intent(hid_t file_id, unsigned *intent); +H5_DLL herr_t H5Fget_fileno(hid_t file_id, unsigned long *fileno); H5_DLL ssize_t H5Fget_obj_count(hid_t file_id, unsigned types); H5_DLL ssize_t H5Fget_obj_ids(hid_t file_id, unsigned types, size_t max_objs, hid_t *obj_id_list); H5_DLL herr_t H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle); diff --git a/src/H5Fsuper.c b/src/H5Fsuper.c index 489cc21..aa5a85d 100644 --- a/src/H5Fsuper.c +++ b/src/H5Fsuper.c @@ -76,6 +76,7 @@ H5FL_DEFINE(H5F_super_t); static const unsigned HDF5_superblock_ver_bounds[] = { HDF5_SUPERBLOCK_VERSION_DEF, /* H5F_LIBVER_EARLIEST */ HDF5_SUPERBLOCK_VERSION_2, /* H5F_LIBVER_V18 */ + HDF5_SUPERBLOCK_VERSION_3, /* H5F_LIBVER_V110 */ HDF5_SUPERBLOCK_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; @@ -555,7 +556,7 @@ H5F__super_read(H5F_t *f, H5P_genplist_t *fa_plist, hbool_t initial_read) /* Set the B-tree internal node values, etc */ if(H5P_set(c_plist, H5F_CRT_BTREE_RANK_NAME, udata.btree_k) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set rank for btree internal nodes") - HDmemcpy(sblock->btree_k, udata.btree_k, sizeof(unsigned) * (size_t)H5B_NUM_BTREE_ID); + H5MM_memcpy(sblock->btree_k, udata.btree_k, sizeof(unsigned) * (size_t)H5B_NUM_BTREE_ID); } /* end if */ else { /* Get the (default) B-tree internal node values, etc */ diff --git a/src/H5Fsuper_cache.c b/src/H5Fsuper_cache.c index 361f8a1..125d6cf 100644 --- a/src/H5Fsuper_cache.c +++ b/src/H5Fsuper_cache.c @@ -269,7 +269,7 @@ H5F__drvrinfo_prefix_decode(H5O_drvinfo_t *drvrinfo, char *drv_name, /* Driver name and/or version */ if(drv_name) { - HDmemcpy(drv_name, (const char *)image, (size_t)8); + H5MM_memcpy(drv_name, (const char *)image, (size_t)8); drv_name[8] = '\0'; image += 8; /* advance past name/version */ } /* end if */ @@ -682,7 +682,7 @@ H5F__cache_superblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNU HDassert(sblock->cache_info.flush_me_last); /* Encode the common portion of the file superblock for all versions */ - HDmemcpy(image, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN); + H5MM_memcpy(image, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN); image += H5F_SIGNATURE_LEN; *image++ = (uint8_t)sblock->super_vers; diff --git a/src/H5Gbtree2.c b/src/H5Gbtree2.c index 721d591..71e0b2d 100644 --- a/src/H5Gbtree2.c +++ b/src/H5Gbtree2.c @@ -35,6 +35,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Gpkg.h" /* Groups */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -206,7 +207,7 @@ H5G_dense_btree2_name_store(void *_nrecord, const void *_udata) /* Copy user information info native record */ nrecord->hash = udata->common.name_hash; - HDmemcpy(nrecord->id, udata->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); + H5MM_memcpy(nrecord->id, udata->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5G_dense_btree2_name_store() */ @@ -305,7 +306,7 @@ H5G_dense_btree2_name_encode(uint8_t *raw, const void *_nrecord, void H5_ATTR_UN /* Encode the record's fields */ UINT32ENCODE(raw, nrecord->hash) - HDmemcpy(raw, nrecord->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); + H5MM_memcpy(raw, nrecord->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5G_dense_btree2_name_encode() */ @@ -333,7 +334,7 @@ H5G_dense_btree2_name_decode(const uint8_t *raw, void *_nrecord, void H5_ATTR_UN /* Decode the record's fields */ UINT32DECODE(raw, nrecord->hash) - HDmemcpy(nrecord->id, raw, (size_t)H5G_DENSE_FHEAP_ID_LEN); + H5MM_memcpy(nrecord->id, raw, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5G_dense_btree2_name_decode() */ @@ -393,7 +394,7 @@ H5G_dense_btree2_corder_store(void *_nrecord, const void *_udata) /* Copy user information info native record */ nrecord->corder = udata->common.corder; - HDmemcpy(nrecord->id, udata->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); + H5MM_memcpy(nrecord->id, udata->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5G_dense_btree2_corder_store() */ @@ -469,7 +470,7 @@ H5G_dense_btree2_corder_encode(uint8_t *raw, const void *_nrecord, void H5_ATTR_ /* Encode the record's fields */ INT64ENCODE(raw, nrecord->corder) - HDmemcpy(raw, nrecord->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); + H5MM_memcpy(raw, nrecord->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5G_dense_btree2_corder_encode() */ @@ -497,7 +498,7 @@ H5G_dense_btree2_corder_decode(const uint8_t *raw, void *_nrecord, void H5_ATTR_ /* Decode the record's fields */ INT64DECODE(raw, nrecord->corder) - HDmemcpy(nrecord->id, raw, (size_t)H5G_DENSE_FHEAP_ID_LEN); + H5MM_memcpy(nrecord->id, raw, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5G_dense_btree2_corder_decode() */ diff --git a/src/H5Gcache.c b/src/H5Gcache.c index b447cad..0ffdc53 100644 --- a/src/H5Gcache.c +++ b/src/H5Gcache.c @@ -36,6 +36,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Gpkg.h" /* Groups */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -287,7 +288,7 @@ H5G__cache_node_serialize(const H5F_t *f, void *_image, size_t len, HDassert(len == sym->node_size); /* magic number */ - HDmemcpy(image, H5G_NODE_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5G_NODE_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* version number */ diff --git a/src/H5Gent.c b/src/H5Gent.c index baee35c..19aef10 100644 --- a/src/H5Gent.c +++ b/src/H5Gent.c @@ -32,6 +32,7 @@ #include "H5FLprivate.h" /* Free Lists */ #include "H5Gpkg.h" /* Groups */ #include "H5HLprivate.h" /* Local Heaps */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -331,7 +332,7 @@ H5G__ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5_copy_depth_t depth) HDassert(depth == H5_COPY_SHALLOW || depth == H5_COPY_DEEP); /* Copy the top level information */ - HDmemcpy(dst, src, sizeof(H5G_entry_t)); + H5MM_memcpy(dst, src, sizeof(H5G_entry_t)); /* Deep copy the names */ if(depth == H5_COPY_DEEP) { diff --git a/src/H5Gname.c b/src/H5Gname.c index 2aece2b..fa0a925 100644 --- a/src/H5Gname.c +++ b/src/H5Gname.c @@ -522,7 +522,7 @@ H5G_name_copy(H5G_name_t *dst, const H5G_name_t *src, H5_copy_depth_t depth) HDassert(depth == H5_COPY_SHALLOW || depth == H5_COPY_DEEP); /* Copy the top level information */ - HDmemcpy(dst, src, sizeof(H5G_name_t)); + H5MM_memcpy(dst, src, sizeof(H5G_name_t)); /* Deep copy the names */ if(depth == H5_COPY_DEEP) { diff --git a/src/H5Gnode.c b/src/H5Gnode.c index 72b3633..b79b7d2 100644 --- a/src/H5Gnode.c +++ b/src/H5Gnode.c @@ -672,7 +672,7 @@ H5G__node_insert(H5F_t *f, haddr_t addr, void H5_ATTR_UNUSED *_lt_key, if(NULL == (snrt = (H5G_node_t *)H5AC_protect(f, H5AC_SNODE, *new_node_p, f, H5AC__NO_FLAGS_SET))) HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5B_INS_ERROR, "unable to split symbol table node") - HDmemcpy(snrt->entry, sn->entry + H5F_SYM_LEAF_K(f), + H5MM_memcpy(snrt->entry, sn->entry + H5F_SYM_LEAF_K(f), H5F_SYM_LEAF_K(f) * sizeof(H5G_entry_t)); snrt->nsyms = H5F_SYM_LEAF_K(f); snrt_flags |= H5AC__DIRTIED_FLAG; @@ -1262,7 +1262,7 @@ H5G__node_copy(H5F_t *f, const void H5_ATTR_UNUSED *_lt_key, haddr_t addr, char *link_name; /* Pointer to value of soft link */ /* Make a temporary copy, so that it will not change the info in the cache */ - HDmemcpy(&tmp_src_ent, src_ent, sizeof(H5G_entry_t)); + H5MM_memcpy(&tmp_src_ent, src_ent, sizeof(H5G_entry_t)); /* Set up group location for soft link to start in */ H5G_name_reset(&grp_path); diff --git a/src/H5Gtraverse.c b/src/H5Gtraverse.c index d029bea..492b5b9 100644 --- a/src/H5Gtraverse.c +++ b/src/H5Gtraverse.c @@ -555,7 +555,7 @@ H5G__traverse_real(const H5G_loc_t *_loc, const char *name, unsigned target, * Copy the component name into a null-terminated buffer so * we can pass it down to the other symbol table functions. */ - HDmemcpy(comp, name, nchars); + H5MM_memcpy(comp, name, nchars); comp[nchars] = '\0'; /* @@ -670,7 +670,7 @@ H5G__traverse_real(const H5G_loc_t *_loc, const char *name, unsigned target, /* Only keep the creation order information from the parent * group's link info */ - HDmemcpy(&tmp_linfo, &def_linfo, sizeof(H5O_linfo_t)); + H5MM_memcpy(&tmp_linfo, &def_linfo, sizeof(H5O_linfo_t)); tmp_linfo.track_corder = par_linfo.track_corder; tmp_linfo.index_corder = par_linfo.index_corder; linfo = &tmp_linfo; @@ -42,6 +42,8 @@ #include "H5FOprivate.h" /* File objects */ #include "H5HFpkg.h" /* Fractal heaps */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ + /****************/ /* Local Macros */ @@ -104,7 +106,7 @@ H5HF_op_read(const void *obj, size_t obj_len, void *op_data) FUNC_ENTER_NOAPI_NOINIT_NOERR /* Perform "read", using memcpy() */ - HDmemcpy(op_data, obj, obj_len); + H5MM_memcpy(op_data, obj, obj_len); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HF_op_read() */ @@ -129,7 +131,7 @@ H5HF_op_write(const void *obj, size_t obj_len, void *op_data) FUNC_ENTER_NOAPI_NOINIT_NOERR /* Perform "write", using memcpy() */ - HDmemcpy((void *)obj, op_data, obj_len); /* Casting away const OK -QAK */ + H5MM_memcpy((void *)obj, op_data, obj_len); /* Casting away const OK -QAK */ FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HF_op_write() */ diff --git a/src/H5HFcache.c b/src/H5HFcache.c index 0c5d3aa..2d1c1f2 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -772,7 +772,7 @@ H5HF__cache_hdr_serialize(const H5F_t *f, void *_image, size_t len, hdr->f = f; /* Magic number */ - HDmemcpy(image, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -1362,7 +1362,7 @@ H5HF__cache_iblock_serialize(const H5F_t *f, void *_image, size_t len, hdr->f = f; /* Magic number */ - HDmemcpy(image, H5HF_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5HF_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -1677,7 +1677,7 @@ H5HF__cache_dblock_verify_chksum(const void *_image, size_t len, void *_udata) /* Set up parameters for filter pipeline */ nbytes = len; filter_mask = udata->filter_mask; - HDmemcpy(read_buf, image, len); + H5MM_memcpy(read_buf, image, len); /* Push direct block data through I/O filter pipeline */ if(H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_ENABLE_EDC, filter_cb, &nbytes, &len, &read_buf) < 0) @@ -1724,7 +1724,7 @@ H5HF__cache_dblock_verify_chksum(const void *_image, size_t len, void *_udata) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy un-filtered data into block's buffer */ - HDmemcpy(udata->dblk, read_buf, len); + H5MM_memcpy(udata->dblk, read_buf, len); } /* end if */ done: @@ -1829,7 +1829,7 @@ H5HF__cache_dblock_deserialize(const void *_image, size_t len, void *_udata, HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "memory allocation failed for pipeline buffer") /* Copy compressed image into buffer */ - HDmemcpy(read_buf, image, len); + H5MM_memcpy(read_buf, image, len); /* Push direct block data through I/O filter pipeline */ nbytes = len; @@ -1841,7 +1841,7 @@ H5HF__cache_dblock_deserialize(const void *_image, size_t len, void *_udata, HDassert(nbytes == dblock->size); /* Copy un-filtered data into block's buffer */ - HDmemcpy(dblock->blk, read_buf, dblock->size); + H5MM_memcpy(dblock->blk, read_buf, dblock->size); } /* end if */ } /* end if */ else { @@ -1856,7 +1856,7 @@ H5HF__cache_dblock_deserialize(const void *_image, size_t len, void *_udata, /* Copy image to dblock->blk */ HDassert(dblock->size == len); - HDmemcpy(dblock->blk, image, dblock->size); + H5MM_memcpy(dblock->blk, image, dblock->size); } /* end else */ /* Start decoding direct block */ @@ -2146,7 +2146,7 @@ H5HF__cache_dblock_pre_serialize(H5F_t *f, void *_thing, image = dblock->blk; /* Magic number */ - HDmemcpy(image, H5HF_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5HF_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Version # */ @@ -2201,7 +2201,7 @@ H5HF__cache_dblock_pre_serialize(H5F_t *f, void *_thing, HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for pipeline buffer") /* Copy the direct block's image into the buffer to compress */ - HDmemcpy(write_buf, dblock->blk, write_size); + H5MM_memcpy(write_buf, dblock->blk, write_size); /* Push direct block data through I/O filter pipeline */ nbytes = write_size; @@ -2460,7 +2460,7 @@ H5HF__cache_dblock_serialize(const H5F_t *f, void *image, size_t len, HDassert(dblock->write_size == len); /* Copy the image from *(dblock->write_buf) to *image */ - HDmemcpy(image, dblock->write_buf, dblock->write_size); + H5MM_memcpy(image, dblock->write_buf, dblock->write_size); /* Free *(dblock->write_buf) if it was allocated by the * pre-serialize function diff --git a/src/H5HFhdr.c b/src/H5HFhdr.c index b014017..5750a03 100644 --- a/src/H5HFhdr.c +++ b/src/H5HFhdr.c @@ -36,6 +36,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5HFpkg.h" /* Fractal heaps */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5VMprivate.h" /* Vectors and arrays */ /****************/ @@ -387,7 +388,7 @@ H5HF_hdr_create(H5F_t *f, const H5HF_create_t *cparam) /* Set the creation parameters for the heap */ hdr->max_man_size = cparam->max_man_size; hdr->checksum_dblocks = cparam->checksum_dblocks; - HDmemcpy(&(hdr->man_dtable.cparam), &(cparam->managed), sizeof(H5HF_dtable_cparam_t)); + H5MM_memcpy(&(hdr->man_dtable.cparam), &(cparam->managed), sizeof(H5HF_dtable_cparam_t)); /* Set root table address to indicate that the heap is empty currently */ hdr->man_dtable.table_addr = HADDR_UNDEF; diff --git a/src/H5HFhuge.c b/src/H5HFhuge.c index 6e475ad..d496d62 100644 --- a/src/H5HFhuge.c +++ b/src/H5HFhuge.c @@ -355,7 +355,7 @@ HDfprintf(stderr, "%s: obj_size = %Zu\n", FUNC, obj_size); write_size = obj_size; if(NULL == (write_buf = H5MM_malloc(write_size))) HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for pipeline buffer") - HDmemcpy(write_buf, obj, write_size); + H5MM_memcpy(write_buf, obj, write_size); /* Push direct block data through I/O filter pipeline */ nbytes = write_size; @@ -794,7 +794,7 @@ H5HF__huge_op_real(H5HF_hdr_t *hdr, const uint8_t *id, hbool_t is_read, /* Copy object to user's buffer if there's filters on heap data */ /* (if there's no filters, the object was read directly into the user's buffer) */ if(hdr->filter_len > 0) - HDmemcpy(op_data, read_buf, (size_t)obj_size); + H5MM_memcpy(op_data, read_buf, (size_t)obj_size); } /* end if */ else { /* Call the user's 'op' callback */ diff --git a/src/H5HFman.c b/src/H5HFman.c index 7f90f49..e5b5cb8 100644 --- a/src/H5HFman.c +++ b/src/H5HFman.c @@ -183,7 +183,7 @@ H5HF__man_insert(H5HF_hdr_t *hdr, size_t obj_size, const void *obj, void *_id) p = dblock->blk + blk_off; /* Copy the object's data into the heap */ - HDmemcpy(p, obj, obj_size); + H5MM_memcpy(p, obj, obj_size); p += obj_size; /* Sanity check */ diff --git a/src/H5HFsection.c b/src/H5HFsection.c index 36e966e..f5ac8e5 100644 --- a/src/H5HFsection.c +++ b/src/H5HFsection.c @@ -3082,7 +3082,7 @@ H5HF__sect_indirect_reduce_row(H5HF_hdr_t *hdr, H5HF_free_section_t *row_sect, HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "allocation failed for row section pointer array") /* Transfer row sections between current & peer sections */ - HDmemcpy(&peer_sect->u.indirect.dir_rows[0], + H5MM_memcpy(&peer_sect->u.indirect.dir_rows[0], §->u.indirect.dir_rows[0], (sizeof(H5HF_free_section_t *) * peer_dir_nrows)); HDmemmove(§->u.indirect.dir_rows[0], @@ -3321,7 +3321,7 @@ H5HF__sect_indirect_reduce(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "allocation failed for indirect section pointer array") /* Transfer child indirect sections between current & peer sections */ - HDmemcpy(&peer_sect->u.indirect.indir_ents[0], + H5MM_memcpy(&peer_sect->u.indirect.indir_ents[0], §->u.indirect.indir_ents[sect->u.indirect.indir_nents - peer_nentries], (sizeof(H5HF_free_section_t *) * peer_nentries)); sect->u.indirect.indir_nents -= (peer_nentries + 1); /* Transferred blocks, plus child entry */ @@ -3636,7 +3636,7 @@ H5HF__sect_indirect_merge_row(H5HF_hdr_t *hdr, H5HF_free_section_t *row_sect1, sect1->u.indirect.dir_rows = new_dir_rows; /* Transfer the second section's rows to first section */ - HDmemcpy(§1->u.indirect.dir_rows[sect1->u.indirect.dir_nrows], + H5MM_memcpy(§1->u.indirect.dir_rows[sect1->u.indirect.dir_nrows], §2->u.indirect.dir_rows[src_row2], (sizeof(H5HF_free_section_t *) * nrows_moved2)); @@ -3682,7 +3682,7 @@ H5HF__sect_indirect_merge_row(H5HF_hdr_t *hdr, H5HF_free_section_t *row_sect1, sect1->u.indirect.indir_ents = new_indir_ents; /* Transfer the second section's entries to first section */ - HDmemcpy(§1->u.indirect.indir_ents[sect1->u.indirect.indir_nents], + H5MM_memcpy(§1->u.indirect.indir_ents[sect1->u.indirect.indir_nents], §2->u.indirect.indir_ents[0], (sizeof(H5HF_free_section_t *) * sect2->u.indirect.indir_nents)); } /* end else */ diff --git a/src/H5HFtest.c b/src/H5HFtest.c index 1b1f688..6f174bb 100644 --- a/src/H5HFtest.c +++ b/src/H5HFtest.c @@ -32,6 +32,8 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5HFpkg.h" /* Fractal heaps */ +#include "H5MMprivate.h" /* Memory management */ + /****************/ /* Local Macros */ @@ -100,7 +102,7 @@ H5HF_get_cparam_test(const H5HF_t *fh, H5HF_create_t *cparam) else H5_CHECKED_ASSIGN(cparam->id_len, uint16_t, fh->hdr->id_len, unsigned); cparam->max_man_size = fh->hdr->max_man_size; - HDmemcpy(&(cparam->managed), &(fh->hdr->man_dtable.cparam), sizeof(H5HF_dtable_cparam_t)); + H5MM_memcpy(&(cparam->managed), &(fh->hdr->man_dtable.cparam), sizeof(H5HF_dtable_cparam_t)); H5O_msg_copy(H5O_PLINE_ID, &(fh->hdr->pline), &(cparam->pline)); FUNC_LEAVE_NOAPI(SUCCEED) diff --git a/src/H5HFtiny.c b/src/H5HFtiny.c index 5cf1c08..0c27180 100644 --- a/src/H5HFtiny.c +++ b/src/H5HFtiny.c @@ -35,6 +35,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5HFpkg.h" /* Fractal heaps */ +#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -176,7 +177,7 @@ HDfprintf(stderr, "%s: obj_size = %Zu\n", FUNC, obj_size); *id++ = enc_obj_size & H5HF_TINY_MASK_EXT_2; } /* end else */ - HDmemcpy(id, obj, obj_size); + H5MM_memcpy(id, obj, obj_size); HDmemset(id + obj_size, 0, (hdr->id_len - ((size_t)1 + (size_t)hdr->tiny_len_extended + obj_size))); /* Update statistics about heap */ @@ -168,7 +168,7 @@ H5HG__create(H5F_t *f, size_t size) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "memory allocation failed") /* Initialize the header */ - HDmemcpy(heap->chunk, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(heap->chunk, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC); p = heap->chunk + H5_SIZEOF_MAGIC; *p++ = H5HG_VERSION; *p++ = 0; /*reserved*/ @@ -553,7 +553,7 @@ H5HG_insert(H5F_t *f, size_t size, void *obj, H5HG_t *hobj/*out*/) /* Copy data into the heap */ if(size > 0) { - HDmemcpy(heap->obj[idx].begin + H5HG_SIZEOF_OBJHDR(f), obj, size); + H5MM_memcpy(heap->obj[idx].begin + H5HG_SIZEOF_OBJHDR(f), obj, size); #ifdef OLD_WAY /* Don't bother zeroing out the rest of the info in the heap -QAK */ HDmemset(heap->obj[idx].begin + H5HG_SIZEOF_OBJHDR(f) + size, 0, @@ -618,7 +618,7 @@ H5HG_read(H5F_t *f, H5HG_t *hobj, void *object/*out*/, size_t *buf_size) /* Allocate a buffer for the object read in, if the user didn't give one */ if(!object && NULL == (object = H5MM_malloc(size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(object, p, size); + H5MM_memcpy(object, p, size); /* * Advance the heap in the CWFS list. We might have done this already diff --git a/src/H5HGcache.c b/src/H5HGcache.c index beaea7b..29e88df 100644 --- a/src/H5HGcache.c +++ b/src/H5HGcache.c @@ -271,7 +271,7 @@ H5HG__cache_heap_deserialize(const void *_image, size_t len, void *_udata, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy the image buffer into the newly allocate chunk */ - HDmemcpy(heap->chunk, _image, len); + H5MM_memcpy(heap->chunk, _image, len); /* Deserialize the heap's header */ if(H5HG__hdr_deserialize(heap, (const uint8_t *)heap->chunk, f) < 0) @@ -448,7 +448,7 @@ H5HG__cache_heap_serialize(const H5F_t *f, void *image, size_t len, HDassert(heap->chunk); /* copy the image into the buffer */ - HDmemcpy(image, heap->chunk, len); + H5MM_memcpy(image, heap->chunk, len); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HG__cache_heap_serialize() */ @@ -725,7 +725,7 @@ H5HL_insert(H5F_t *f, H5HL_t *heap, size_t buf_size, const void *buf)) } /* end if */ /* Copy the data into the heap */ - HDmemcpy(heap->dblk_image + offset, buf, buf_size); + H5MM_memcpy(heap->dblk_image + offset, buf, buf_size); /* Set return value */ ret_value = offset; diff --git a/src/H5HLcache.c b/src/H5HLcache.c index 926f787..8b04b47 100644 --- a/src/H5HLcache.c +++ b/src/H5HLcache.c @@ -36,6 +36,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5HLpkg.h" /* Local Heaps */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -464,7 +465,7 @@ H5HL__cache_prefix_deserialize(const void *_image, size_t len, void *_udata, image = ((const uint8_t *)_image) + heap->prfx_size; /* Copy the heap data from the speculative read buffer */ - HDmemcpy(heap->dblk_image, image, heap->dblk_size); + H5MM_memcpy(heap->dblk_image, image, heap->dblk_size); /* Build free list */ if(H5HL__fl_deserialize(heap) < 0) @@ -587,7 +588,7 @@ H5HL__cache_prefix_serialize(const H5F_t *f, void *_image, size_t len, heap->free_block = heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL; /* Serialize the heap prefix */ - HDmemcpy(image, H5HL_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5HL_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; *image++ = H5HL_VERSION; *image++ = 0; /*reserved*/ @@ -615,7 +616,7 @@ H5HL__cache_prefix_serialize(const H5F_t *f, void *_image, size_t len, H5HL__fl_serialize(heap); /* Copy the heap data block into the cache image */ - HDmemcpy(image, heap->dblk_image, heap->dblk_size); + H5MM_memcpy(image, heap->dblk_image, heap->dblk_size); /* Sanity check */ HDassert((size_t)(image - (uint8_t *)_image) + heap->dblk_size == len); @@ -756,7 +757,7 @@ H5HL__cache_datablock_deserialize(const void *image, size_t len, void *_udata, HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "can't allocate data block image buffer"); /* copy the datablock from the read buffer */ - HDmemcpy(heap->dblk_image, image, len); + H5MM_memcpy(heap->dblk_image, image, len); /* Build free list */ if(FAIL == H5HL__fl_deserialize(heap)) @@ -851,7 +852,7 @@ H5HL__cache_datablock_serialize(const H5F_t *f, void *image, size_t len, H5HL__fl_serialize(heap); /* Copy the heap's data block into the cache's image */ - HDmemcpy(image, heap->dblk_image, heap->dblk_size); + H5MM_memcpy(image, heap->dblk_image, heap->dblk_size); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HL__cache_datablock_serialize() */ @@ -355,6 +355,9 @@ H5Itype_exists(H5I_type_t type) FUNC_ENTER_API(FAIL) H5TRACE1("t", "It", type); + if(H5I_IS_LIB_TYPE(type)) + HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "cannot call public function on library type") + if (type <= H5I_BADID || type >= H5I_next_type) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid type number") @@ -1131,7 +1134,7 @@ done: * *------------------------------------------------------------------------- */ -void * +static void * H5I__remove_verify(hid_t id, H5I_type_t id_type) { void * ret_value = NULL; /*return value */ @@ -1940,6 +1943,8 @@ H5I__iterate_pub_cb(void H5_ATTR_UNUSED *obj, hid_t id, void *_udata) ret_value = H5_ITER_STOP; /* terminate iteration early */ else if(cb_ret_val < 0) ret_value = H5_ITER_ERROR; /* indicate failure (which terminates iteration) */ + else + ret_value = H5_ITER_CONT; /* continue iteration */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5I__iterate_pub_cb() */ @@ -1676,7 +1676,7 @@ H5L_register(const H5L_class_t *cls) } /* end if */ /* Copy link class info into table */ - HDmemcpy(H5L_table_g + i, cls, sizeof(H5L_class_t)); + H5MM_memcpy(H5L_table_g + i, cls, sizeof(H5L_class_t)); done: FUNC_LEAVE_NOAPI(ret_value) @@ -2217,7 +2217,7 @@ H5L__create_ud(const H5G_loc_t *link_loc, const char *link_name, /* Fill in UD link-specific information in the link struct*/ if(ud_data_size > 0) { lnk.u.ud.udata = H5MM_malloc((size_t)ud_data_size); - HDmemcpy(lnk.u.ud.udata, ud_data, (size_t) ud_data_size); + H5MM_memcpy(lnk.u.ud.udata, ud_data, (size_t) ud_data_size); } /* end if */ else lnk.u.ud.udata = NULL; diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index 0f3296f..d838d77 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -306,7 +306,7 @@ H5L__extern_query(const char H5_ATTR_UNUSED * link_name, const void *_udata, siz buf_size = udata_size; /* Copy the udata verbatim up to buf_size */ - HDmemcpy(buf, udata, buf_size); + H5MM_memcpy(buf, udata, buf_size); } /* end if */ /* Set return value */ @@ -274,7 +274,7 @@ H5MM_malloc(size_t size) #if defined H5_MEMORY_ALLOC_SANITY_CHECK /* Initialize block list head singleton */ if(!H5MM_init_s) { - HDmemcpy(H5MM_block_head_s.sig, H5MM_block_signature_s, H5MM_SIG_SIZE); + H5MM_memcpy(H5MM_block_head_s.sig, H5MM_block_signature_s, H5MM_SIG_SIZE); H5MM_block_head_s.next = &H5MM_block_head_s; H5MM_block_head_s.prev = &H5MM_block_head_s; H5MM_block_head_s.u.info.size = SIZET_MAX; @@ -291,15 +291,15 @@ H5MM_malloc(size_t size) if(NULL != (block = (H5MM_block_t *)HDmalloc(alloc_size))) { /* Set up block */ - HDmemcpy(block->sig, H5MM_block_signature_s, H5MM_SIG_SIZE); + H5MM_memcpy(block->sig, H5MM_block_signature_s, H5MM_SIG_SIZE); block->next = H5MM_block_head_s.next; H5MM_block_head_s.next = block; block->next->prev = block; block->prev = &H5MM_block_head_s; block->u.info.size = size; block->u.info.in_use = TRUE; - HDmemcpy(block->b, H5MM_block_head_guard_s, H5MM_HEAD_GUARD_SIZE); - HDmemcpy(block->b + H5MM_HEAD_GUARD_SIZE + size, H5MM_block_tail_guard_s, H5MM_TAIL_GUARD_SIZE); + H5MM_memcpy(block->b, H5MM_block_head_guard_s, H5MM_HEAD_GUARD_SIZE); + H5MM_memcpy(block->b + H5MM_HEAD_GUARD_SIZE + size, H5MM_block_tail_guard_s, H5MM_TAIL_GUARD_SIZE); /* Update statistics */ H5MM_total_alloc_bytes_s += size; @@ -417,7 +417,7 @@ H5MM_realloc(void *mem, size_t size) H5MM__sanity_check(mem); ret_value = H5MM_malloc(size); - HDmemcpy(ret_value, mem, MIN(size, old_size)); + H5MM_memcpy(ret_value, mem, MIN(size, old_size)); H5MM_xfree(mem); } /* end if */ else @@ -564,3 +564,41 @@ H5MM_xfree(void *mem) FUNC_LEAVE_NOAPI(NULL) } /* end H5MM_xfree() */ + +/*------------------------------------------------------------------------- + * Function: H5MM_memcpy + * + * Purpose: Like memcpy(3) but with sanity checks on the parameters, + * particularly buffer overlap. + * + * Return: Success: pointer to dest + * Failure: NULL + * + * Programmer: Dana Robinson + * Spring 2019 + * + *------------------------------------------------------------------------- + */ +void * +H5MM_memcpy(void *dest, const void *src, size_t n) +{ + void *ret = NULL; + + /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + HDassert(dest); + HDassert(src); +#if 0 + /* Commented out while we investigate overlapping buffers in the + * parallel filter code (HDFFV-10735). + */ + HDassert((char *)dest >= (const char *)src + n || (const char *)src >= (char *)dest + n); +#endif + + ret = HDmemcpy(dest, src, n); + + FUNC_LEAVE_NOAPI(ret) + +} /* end H5MM_memcpy() */ + diff --git a/src/H5MMprivate.h b/src/H5MMprivate.h index 0524601..2053215 100644 --- a/src/H5MMprivate.h +++ b/src/H5MMprivate.h @@ -45,6 +45,7 @@ H5_DLL void *H5MM_realloc(void *mem, size_t size); H5_DLL char *H5MM_xstrdup(const char *s); H5_DLL char *H5MM_strdup(const char *s); H5_DLL void *H5MM_xfree(void *mem); +H5_DLL void *H5MM_memcpy(void *dest, const void *src, size_t n); #if defined H5_MEMORY_ALLOC_SANITY_CHECK H5_DLL void H5MM_sanity_check_all(void); H5_DLL void H5MM_final_sanity_check(void); diff --git a/src/H5Oalloc.c b/src/H5Oalloc.c index 23dd928..c1f90cb 100644 --- a/src/H5Oalloc.c +++ b/src/H5Oalloc.c @@ -36,6 +36,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free lists */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object headers */ /****************/ @@ -949,7 +950,7 @@ H5O__alloc_chunk(H5F_t *f, H5O_t *oh, size_t size, size_t found_null, * # at the beginning of the chunk image. */ if(oh->version > H5O_VERSION_1) { - HDmemcpy(p, H5O_CHK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(p, H5O_CHK_MAGIC, (size_t)H5_SIZEOF_MAGIC); p += H5_SIZEOF_MAGIC; } /* end if */ @@ -988,7 +989,7 @@ H5O__alloc_chunk(H5F_t *f, H5O_t *oh, size_t size, size_t found_null, HDassert(curr_msg->type->id != H5O_CONT_ID); /* Copy the raw data */ - HDmemcpy(p, curr_msg->raw - (size_t)H5O_SIZEOF_MSGHDR_OH(oh), + H5MM_memcpy(p, curr_msg->raw - (size_t)H5O_SIZEOF_MSGHDR_OH(oh), curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); /* Update the message info */ @@ -1044,7 +1045,7 @@ H5O__alloc_chunk(H5F_t *f, H5O_t *oh, size_t size, size_t found_null, null_msg->chunkno = oh->mesg[found_msg->msgno].chunkno; /* Copy the message to move (& its prefix) to its new location */ - HDmemcpy(p, oh->mesg[found_msg->msgno].raw - H5O_SIZEOF_MSGHDR_OH(oh), + H5MM_memcpy(p, oh->mesg[found_msg->msgno].raw - H5O_SIZEOF_MSGHDR_OH(oh), oh->mesg[found_msg->msgno].raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); /* Switch moved message to point to new location */ @@ -1519,7 +1520,7 @@ H5O__move_cont(H5F_t *f, H5O_t *oh, unsigned cont_u) move_size = curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh); /* Move message out of deleted chunk */ - HDmemcpy(move_start, curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), move_size); + H5MM_memcpy(move_start, curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), move_size); curr_msg->raw = move_start + H5O_SIZEOF_MSGHDR_OH(oh); curr_msg->chunkno = cont_chunkno; chk_dirtied = TRUE; @@ -1791,7 +1792,7 @@ H5O__move_msgs_forward(H5F_t *f, H5O_t *oh) } /* end if */ /* Copy raw data for non-null message to new chunk */ - HDmemcpy(null_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); + H5MM_memcpy(null_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); /* Point non-null message at null message's space */ curr_msg->chunkno = null_msg->chunkno; diff --git a/src/H5Oattr.c b/src/H5Oattr.c index c420046..0a7c4bf 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -208,7 +208,7 @@ H5O_attr_decode(H5F_t *f, H5O_t *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute dataspace") /* Copy the extent information to the dataspace */ - HDmemcpy(&(attr->shared->ds->extent), extent, sizeof(H5S_extent_t)); + H5MM_memcpy(&(attr->shared->ds->extent), extent, sizeof(H5S_extent_t)); /* Release temporary extent information */ extent = H5FL_FREE(H5S_extent_t, extent); @@ -240,7 +240,7 @@ H5O_attr_decode(H5F_t *f, H5O_t *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, if(attr->shared->data_size) { if(NULL == (attr->shared->data = H5FL_BLK_MALLOC(attr_buf, attr->shared->data_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(attr->shared->data, p, attr->shared->data_size); + H5MM_memcpy(attr->shared->data, p, attr->shared->data_size); } /* end if */ /* Increment the reference count for this object header message in cache(compact @@ -336,7 +336,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) *p++ = attr->shared->encoding; /* Write the name including null terminator */ - HDmemcpy(p, attr->shared->name, name_len); + H5MM_memcpy(p, attr->shared->name, name_len); if(attr->shared->version < H5O_ATTR_VERSION_2) { /* Pad to the correct number of bytes */ HDmemset(p + name_len, 0, H5O_ALIGN_OLD(name_len) - name_len); @@ -369,7 +369,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) /* Store attribute data. If there's no data, store 0 as fill value. */ if(attr->shared->data) - HDmemcpy(p, attr->shared->data, attr->shared->data_size); + H5MM_memcpy(p, attr->shared->data, attr->shared->data_size); else HDmemset(p, 0, attr->shared->data_size); diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index 6e135c5..57ec9b8 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -862,7 +862,7 @@ H5O__attr_write_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, /* (Needs to occur before updating the shared message, or the hash * value on the old & new messages will be the same) */ - HDmemcpy(((H5A_t *)mesg->native)->shared->data, udata->attr->shared->data, udata->attr->shared->data_size); + H5MM_memcpy(((H5A_t *)mesg->native)->shared->data, udata->attr->shared->data, udata->attr->shared->data_size); } /* end if */ /* Mark the message as modified */ diff --git a/src/H5Ocache.c b/src/H5Ocache.c index 578cff0..683d155 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -36,6 +36,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free lists */ #include "H5MFprivate.h" /* File memory management */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object headers */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -542,7 +543,7 @@ H5O__cache_serialize(const H5F_t *f, void *image, size_t len, void *_thing) * Can we rework things so that the object header and the cache * share a buffer? */ - HDmemcpy(image, oh->chunk[0].image, len); + H5MM_memcpy(image, oh->chunk[0].image, len); done: FUNC_LEAVE_NOAPI(ret_value) @@ -900,7 +901,7 @@ H5O__cache_chk_serialize(const H5F_t *f, void *image, size_t len, void *_thing) /* copy the chunk into the image -- this is potentially expensive. * Can we rework things so that the chunk and the cache share a buffer? */ - HDmemcpy(image, chk_proxy->oh->chunk[chk_proxy->chunkno].image, len); + H5MM_memcpy(image, chk_proxy->oh->chunk[chk_proxy->chunkno].image, len); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1352,7 +1353,7 @@ H5O__chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image oh->chunk[chunkno].chunk_proxy = NULL; /* Copy disk image into chunk's image */ - HDmemcpy(oh->chunk[chunkno].image, image, oh->chunk[chunkno].size); + H5MM_memcpy(oh->chunk[chunkno].image, image, oh->chunk[chunkno].size); /* Point into chunk image to decode */ chunk_image = oh->chunk[chunkno].image; diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c index a3d4884..9578f95 100644 --- a/src/H5Ocopy.c +++ b/src/H5Ocopy.c @@ -732,7 +732,7 @@ H5O__copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out*/, * header. This will be written when the header is flushed to disk. */ if(oh_dst->version > H5O_VERSION_1) - HDmemcpy(current_pos, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(current_pos, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); current_pos += H5O_SIZEOF_HDR(oh_dst) - H5O_SIZEOF_CHKSUM_OH(oh_dst); /* Loop through destination messages, updating their "raw" info */ @@ -755,7 +755,7 @@ H5O__copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out*/, /* Copy each message that wasn't dirtied above */ if(!mesg_dst->dirty) /* Copy the message header plus the message's raw data. */ - HDmemcpy(current_pos, mesg_src->raw - msghdr_size, msghdr_size + mesg_src->raw_size); + H5MM_memcpy(current_pos, mesg_src->raw - msghdr_size, msghdr_size + mesg_src->raw_size); /* Set message's raw pointer to destination chunk's new "image" */ mesg_dst->raw = current_pos + msghdr_size; diff --git a/src/H5Odrvinfo.c b/src/H5Odrvinfo.c index 159c950..eb678e4 100644 --- a/src/H5Odrvinfo.c +++ b/src/H5Odrvinfo.c @@ -101,7 +101,7 @@ H5O_drvinfo_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for driver info message") /* Retrieve driver name */ - HDmemcpy(mesg->name, p, 8); + H5MM_memcpy(mesg->name, p, 8); mesg->name[8] = '\0'; p += 8; @@ -116,7 +116,7 @@ H5O_drvinfo_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, } /* end if */ /* Copy encoded driver info into buffer */ - HDmemcpy(mesg->buf, p, mesg->len); + H5MM_memcpy(mesg->buf, p, mesg->len); /* Set return value */ ret_value = (void *)mesg; @@ -152,11 +152,11 @@ H5O_drvinfo_encode(H5F_t H5_ATTR_UNUSED *f, hbool_t H5_ATTR_UNUSED disable_share /* Store version, driver name, buffer length, & encoded buffer */ *p++ = H5O_DRVINFO_VERSION; - HDmemcpy(p, mesg->name, 8); + H5MM_memcpy(p, mesg->name, 8); p += 8; HDassert(mesg->len <= 65535); UINT16ENCODE(p, mesg->len); - HDmemcpy(p, mesg->buf, mesg->len); + H5MM_memcpy(p, mesg->buf, mesg->len); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5O_drvinfo_encode() */ @@ -200,7 +200,7 @@ H5O_drvinfo_copy(const void *_mesg, void *_dest) dest = (H5O_drvinfo_t *)H5MM_xfree(dest); HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") } /* end if */ - HDmemcpy(dest->buf, mesg->buf, mesg->len); + H5MM_memcpy(dest->buf, mesg->buf, mesg->len); /* Set return value */ ret_value = dest; diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 28970d1..39d8bac 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -250,7 +250,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p HDassert(0 == (z & 0x7)); /*must be aligned*/ if(NULL == (dt->shared->u.opaque.tag = (char *)H5MM_malloc(z + 1))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - HDmemcpy(dt->shared->u.opaque.tag, *pp, z); + H5MM_memcpy(dt->shared->u.opaque.tag, *pp, z); dt->shared->u.opaque.tag[z] = '\0'; *pp += z; break; @@ -483,7 +483,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p } /* end for */ /* Values */ - HDmemcpy(dt->shared->u.enumer.value, *pp, + H5MM_memcpy(dt->shared->u.enumer.value, *pp, dt->shared->u.enumer.nmembs * dt->shared->parent->shared->size); *pp += dt->shared->u.enumer.nmembs * dt->shared->parent->shared->size; break; @@ -882,7 +882,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) z = HDstrlen(dt->shared->u.opaque.tag); aligned = (z + 7) & (H5T_OPAQUE_TAG_MAX - 8); flags = (unsigned)(flags | aligned); - HDmemcpy(*pp, dt->shared->u.opaque.tag, MIN(z,aligned)); + H5MM_memcpy(*pp, dt->shared->u.opaque.tag, MIN(z,aligned)); for(n = MIN(z, aligned); n < aligned; n++) (*pp)[n] = 0; *pp += aligned; @@ -997,7 +997,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) } /* end for */ /* Values */ - HDmemcpy(*pp, dt->shared->u.enumer.value, dt->shared->u.enumer.nmembs * dt->shared->parent->shared->size); + H5MM_memcpy(*pp, dt->shared->u.enumer.value, dt->shared->u.enumer.nmembs * dt->shared->parent->shared->size); *pp += dt->shared->u.enumer.nmembs * dt->shared->parent->shared->size; break; diff --git a/src/H5Oefl.c b/src/H5Oefl.c index 6a81a46..b18d819 100644 --- a/src/H5Oefl.c +++ b/src/H5Oefl.c @@ -461,7 +461,7 @@ H5O__efl_copy_file(H5F_t H5_ATTR_UNUSED *file_src, void *mesg_src, H5F_t *file_d HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy the "top level" information */ - HDmemcpy(efl_dst, efl_src, sizeof(H5O_efl_t)); + H5MM_memcpy(efl_dst, efl_src, sizeof(H5O_efl_t)); /* Determine size needed for destination heap */ heap_size = H5HL_ALIGN(1); /* "empty" name */ @@ -488,7 +488,7 @@ H5O__efl_copy_file(H5F_t H5_ATTR_UNUSED *file_src, void *mesg_src, H5F_t *file_d HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* copy content from the source. Need to update later */ - HDmemcpy(efl_dst->slot, efl_src->slot, size); + H5MM_memcpy(efl_dst->slot, efl_src->slot, size); } /* end if */ /* copy the name from the source */ diff --git a/src/H5Ofill.c b/src/H5Ofill.c index fd50cb9..d87dc84 100644 --- a/src/H5Ofill.c +++ b/src/H5Ofill.c @@ -157,6 +157,7 @@ const H5O_msg_class_t H5O_MSG_FILL_NEW[1] = {{ const unsigned H5O_fill_ver_bounds[] = { H5O_FILL_VERSION_1, /* H5F_LIBVER_EARLIEST */ H5O_FILL_VERSION_2, /* H5F_LIBVER_V18 */ + H5O_FILL_VERSION_3, /* H5F_LIBVER_V110 */ H5O_FILL_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; @@ -232,7 +233,7 @@ H5O_fill_new_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "destination buffer too small") if(NULL == (fill->buf = H5MM_malloc((size_t)fill->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for fill value") - HDmemcpy(fill->buf, p, (size_t)fill->size); + H5MM_memcpy(fill->buf, p, (size_t)fill->size); } /* end if */ } /* end if */ else @@ -270,7 +271,7 @@ H5O_fill_new_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, H5_CHECK_OVERFLOW(fill->size, ssize_t, size_t); if(NULL == (fill->buf = H5MM_malloc((size_t)fill->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for fill value") - HDmemcpy(fill->buf, p, (size_t)fill->size); + H5MM_memcpy(fill->buf, p, (size_t)fill->size); /* Set the "defined" flag */ fill->fill_defined = TRUE; @@ -353,7 +354,7 @@ H5O_fill_old_decode(H5F_t *f, H5O_t *open_oh, if(NULL == (fill->buf = H5MM_malloc((size_t)fill->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for fill value") - HDmemcpy(fill->buf, p, (size_t)fill->size); + H5MM_memcpy(fill->buf, p, (size_t)fill->size); fill->fill_defined = TRUE; } /* end if */ else @@ -420,7 +421,7 @@ H5O_fill_new_encode(H5F_t H5_ATTR_UNUSED *f, uint8_t *p, const void *_fill) if(fill->size > 0) if(fill->buf) { H5_CHECK_OVERFLOW(fill->size, ssize_t, size_t); - HDmemcpy(p, fill->buf, (size_t)fill->size); + H5MM_memcpy(p, fill->buf, (size_t)fill->size); } /* end if */ } /* end if */ } /* end if */ @@ -459,7 +460,7 @@ H5O_fill_new_encode(H5F_t H5_ATTR_UNUSED *f, uint8_t *p, const void *_fill) /* Encode the fill value */ HDassert(fill->buf); H5_CHECK_OVERFLOW(fill->size, ssize_t, size_t); - HDmemcpy(p, fill->buf, (size_t)fill->size); + H5MM_memcpy(p, fill->buf, (size_t)fill->size); } /* end if */ else { /* Flags */ @@ -499,7 +500,7 @@ H5O_fill_old_encode(H5F_t H5_ATTR_UNUSED *f, uint8_t *p, const void *_fill) UINT32ENCODE(p, fill->size); if(fill->buf) - HDmemcpy(p, fill->buf, (size_t)fill->size); + H5MM_memcpy(p, fill->buf, (size_t)fill->size); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5O_fill_old_encode() */ @@ -551,7 +552,7 @@ H5O_fill_copy(const void *_src, void *_dst) H5_CHECK_OVERFLOW(src->size, ssize_t, size_t); if(NULL == (dst->buf = H5MM_malloc((size_t)src->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for fill value") - HDmemcpy(dst->buf, src->buf, (size_t)src->size); + H5MM_memcpy(dst->buf, src->buf, (size_t)src->size); /* Check for needing to convert/copy fill value */ if(src->type) { @@ -1025,7 +1026,7 @@ H5O_fill_convert(H5O_fill_t *fill, H5T_t *dset_type, hbool_t *fill_changed) else { if(NULL == (buf = H5MM_malloc(H5T_get_size(dset_type)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion") - HDmemcpy(buf, fill->buf, H5T_get_size(fill->type)); + H5MM_memcpy(buf, fill->buf, H5T_get_size(fill->type)); } /* end else */ /* Use CALLOC here to clear the buffer in case later the library thinks there's diff --git a/src/H5Oint.c b/src/H5Oint.c index d3a409c..60aae45 100644 --- a/src/H5Oint.c +++ b/src/H5Oint.c @@ -38,9 +38,7 @@ #include "H5Iprivate.h" /* IDs */ #include "H5Lprivate.h" /* Links */ #include "H5MFprivate.h" /* File memory management */ -#ifdef H5O_ENABLE_BOGUS #include "H5MMprivate.h" /* Memory management */ -#endif /* H5O_ENABLE_BOGUS */ #include "H5Opkg.h" /* Object headers */ #include "H5VLprivate.h" /* Virtual Object Layer */ @@ -132,6 +130,7 @@ const H5O_msg_class_t *const H5O_msg_class_g[] = { const unsigned H5O_obj_ver_bounds[] = { H5O_VERSION_1, /* H5F_LIBVER_EARLIEST */ H5O_VERSION_2, /* H5F_LIBVER_V18 */ + H5O_VERSION_2, /* H5F_LIBVER_V110 */ H5O_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; @@ -496,7 +495,7 @@ H5O__apply_ohdr(H5F_t *f, H5O_t *oh, hid_t ocpl_id, size_t size_hint, size_t ini /* Put magic # for object header in first chunk */ if(H5O_VERSION_1 < oh->version) - HDmemcpy(oh->chunk[0].image, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(oh->chunk[0].image, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); /* Create the message list */ oh->nmesgs = 1; @@ -1921,7 +1920,7 @@ H5O_loc_copy(H5O_loc_t *dst, H5O_loc_t *src, H5_copy_depth_t depth) HDassert(depth == H5_COPY_SHALLOW || depth == H5_COPY_DEEP); /* Copy the top level information */ - HDmemcpy(dst, src, sizeof(H5O_loc_t)); + H5MM_memcpy(dst, src, sizeof(H5O_loc_t)); /* Deep copy the names */ if(depth == H5_COPY_DEEP) { diff --git a/src/H5Olayout.c b/src/H5Olayout.c index 2b65e0c..138f219 100644 --- a/src/H5Olayout.c +++ b/src/H5Olayout.c @@ -189,7 +189,7 @@ H5O__layout_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, if(mesg->storage.u.compact.size > 0) { if(NULL == (mesg->storage.u.compact.buf = H5MM_malloc(mesg->storage.u.compact.size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for compact data buffer") - HDmemcpy(mesg->storage.u.compact.buf, p, mesg->storage.u.compact.size); + H5MM_memcpy(mesg->storage.u.compact.buf, p, mesg->storage.u.compact.size); p += mesg->storage.u.compact.size; } /* end if */ } /* end if */ @@ -210,7 +210,7 @@ H5O__layout_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "memory allocation failed for compact data buffer") /* Compact data */ - HDmemcpy(mesg->storage.u.compact.buf, p, mesg->storage.u.compact.size); + H5MM_memcpy(mesg->storage.u.compact.buf, p, mesg->storage.u.compact.size); p += mesg->storage.u.compact.size; } /* end if */ @@ -425,14 +425,14 @@ H5O__layout_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, tmp_size = HDstrlen((const char *)heap_block_p) + 1; if(NULL == (mesg->storage.u.virt.list[i].source_file_name = (char *)H5MM_malloc(tmp_size))) HGOTO_ERROR(H5E_OHDR, H5E_RESOURCE, NULL, "unable to allocate memory for source file name") - (void)HDmemcpy(mesg->storage.u.virt.list[i].source_file_name, heap_block_p, tmp_size); + (void)H5MM_memcpy(mesg->storage.u.virt.list[i].source_file_name, heap_block_p, tmp_size); heap_block_p += tmp_size; /* Source dataset name */ tmp_size = HDstrlen((const char *)heap_block_p) + 1; if(NULL == (mesg->storage.u.virt.list[i].source_dset_name = (char *)H5MM_malloc(tmp_size))) HGOTO_ERROR(H5E_OHDR, H5E_RESOURCE, NULL, "unable to allocate memory for source dataset name") - (void)HDmemcpy(mesg->storage.u.virt.list[i].source_dset_name, heap_block_p, tmp_size); + (void)H5MM_memcpy(mesg->storage.u.virt.list[i].source_dset_name, heap_block_p, tmp_size); heap_block_p += tmp_size; /* Source selection */ @@ -581,7 +581,7 @@ H5O__layout_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, /* Raw data */ if(mesg->storage.u.compact.size > 0) { if(mesg->storage.u.compact.buf) - HDmemcpy(p, mesg->storage.u.compact.buf, mesg->storage.u.compact.size); + H5MM_memcpy(p, mesg->storage.u.compact.buf, mesg->storage.u.compact.size); else HDmemset(p, 0, mesg->storage.u.compact.size); p += mesg->storage.u.compact.size; @@ -742,7 +742,7 @@ H5O__layout_copy(const void *_mesg, void *_dest) HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, NULL, "unable to allocate memory for compact dataset") /* Copy over the raw data */ - HDmemcpy(dest->storage.u.compact.buf, mesg->storage.u.compact.buf, dest->storage.u.compact.size); + H5MM_memcpy(dest->storage.u.compact.buf, mesg->storage.u.compact.buf, dest->storage.u.compact.size); } /* end if */ else HDassert(dest->storage.u.compact.buf == NULL); @@ -1039,7 +1039,8 @@ H5O__layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, layout_dst->storage.u.contig.size = H5S_extent_nelem(udata->src_space_extent) * H5T_get_size(udata->src_dtype); - if(H5D__contig_is_space_alloc(&layout_src->storage)) { + if(H5D__contig_is_space_alloc(&layout_src->storage) + || (cpy_info->shared_fo && H5D__contig_is_data_cached((const H5D_shared_t *)cpy_info->shared_fo))) { /* copy contiguous raw data */ if(H5D__contig_copy(file_src, &layout_src->storage.u.contig, file_dst, &layout_dst->storage.u.contig, udata->src_dtype, cpy_info) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy contiguous storage") @@ -1048,7 +1049,8 @@ H5O__layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, break; case H5D_CHUNKED: - if(H5D__chunk_is_space_alloc(&layout_src->storage)) { + if(H5D__chunk_is_space_alloc(&layout_src->storage) + || (cpy_info->shared_fo && H5D__chunk_is_data_cached((const H5D_shared_t *)cpy_info->shared_fo))) { /* Create chunked layout */ if(H5D__chunk_copy(file_src, &layout_src->storage.u.chunk, &layout_src->u.chunk, file_dst, &layout_dst->storage.u.chunk, udata->src_space_extent, udata->src_dtype, udata->common.src_pline, cpy_info) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage") diff --git a/src/H5Olink.c b/src/H5Olink.c index 55e1aee..4bd952b 100644 --- a/src/H5Olink.c +++ b/src/H5Olink.c @@ -202,7 +202,7 @@ H5O__link_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, /* Get the link's name */ if(NULL == (lnk->name = (char *)H5MM_malloc(len + 1))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(lnk->name, p, len); + H5MM_memcpy(lnk->name, p, len); lnk->name[len] = '\0'; p += len; @@ -220,7 +220,7 @@ H5O__link_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "invalid link length") if(NULL == (lnk->u.soft.name = (char *)H5MM_malloc((size_t)len + 1))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(lnk->u.soft.name, p, len); + H5MM_memcpy(lnk->u.soft.name, p, len); lnk->u.soft.name[len] = '\0'; p += len; break; @@ -240,7 +240,7 @@ H5O__link_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, { if(NULL == (lnk->u.ud.udata = H5MM_malloc((size_t)len))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(lnk->u.ud.udata, p, len); + H5MM_memcpy(lnk->u.ud.udata, p, len); p += len; } else @@ -349,7 +349,7 @@ H5O_link_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, con } /* end switch */ /* Store the link's name */ - HDmemcpy(p, lnk->name, (size_t)len); + H5MM_memcpy(p, lnk->name, (size_t)len); p += len; /* Store the appropriate information for each type of link */ @@ -364,7 +364,7 @@ H5O_link_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, con len = (uint16_t)HDstrlen(lnk->u.soft.name); HDassert(len > 0); UINT16ENCODE(p, len) - HDmemcpy(p, lnk->u.soft.name, (size_t)len); + H5MM_memcpy(p, lnk->u.soft.name, (size_t)len); p += len; break; @@ -380,7 +380,7 @@ H5O_link_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, con UINT16ENCODE(p, len) if(len > 0) { - HDmemcpy(p, lnk->u.ud.udata, (size_t)len); + H5MM_memcpy(p, lnk->u.ud.udata, (size_t)len); p+=len; } break; @@ -437,7 +437,7 @@ H5O_link_copy(const void *_mesg, void *_dest) if(lnk->u.ud.size > 0) { if(NULL == (dest->u.ud.udata = H5MM_malloc(lnk->u.ud.size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(dest->u.ud.udata, lnk->u.ud.udata, lnk->u.ud.size); + H5MM_memcpy(dest->u.ud.udata, lnk->u.ud.udata, lnk->u.ud.size); } /* end if */ } /* end if */ diff --git a/src/H5Opline.c b/src/H5Opline.c index 1fae1b8..609f2eb 100644 --- a/src/H5Opline.c +++ b/src/H5Opline.c @@ -93,6 +93,7 @@ const H5O_msg_class_t H5O_MSG_PLINE[1] = {{ const unsigned H5O_pline_ver_bounds[] = { H5O_PLINE_VERSION_1, /* H5F_LIBVER_EARLIEST */ H5O_PLINE_VERSION_2, /* H5F_LIBVER_V18 */ + H5O_PLINE_VERSION_2, /* H5F_LIBVER_V110 */ H5O_PLINE_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; @@ -318,7 +319,7 @@ H5O_pline_encode(H5F_t H5_ATTR_UNUSED *f, uint8_t *p/*out*/, const void *mesg) /* Encode name, if there is one to encode */ if(name_length > 0) { /* Store name, with null terminator */ - HDmemcpy(p, name, name_length); + H5MM_memcpy(p, name, name_length); p += name_length; /* Pad out name to alignment, in older versions */ @@ -409,7 +410,7 @@ H5O_pline_copy(const void *_src, void *_dst/*out*/) if(NULL == (dst->filter[i].cd_values = (unsigned *)H5MM_malloc(src->filter[i].cd_nelmts* sizeof(unsigned)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(dst->filter[i].cd_values, src->filter[i].cd_values, + H5MM_memcpy(dst->filter[i].cd_values, src->filter[i].cd_values, src->filter[i].cd_nelmts * sizeof(unsigned)); } /* end if */ else diff --git a/src/H5Oshared.c b/src/H5Oshared.c index 4fc0488..67ca76f 100644 --- a/src/H5Oshared.c +++ b/src/H5Oshared.c @@ -39,6 +39,7 @@ #include "H5Fprivate.h" /* File access */ #include "H5Gprivate.h" /* Groups */ #include "H5HFprivate.h" /* Fractal heap */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object headers */ #include "H5SMprivate.h" /* Shared object header messages */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -358,7 +359,7 @@ H5O__shared_decode(H5F_t *f, H5O_t *open_oh, unsigned *ioflags, const uint8_t *b */ if(sh_mesg.type == H5O_SHARE_TYPE_SOHM) { HDassert(version >= H5O_SHARED_VERSION_3); - HDmemcpy(&sh_mesg.u.heap_id, buf, sizeof(sh_mesg.u.heap_id)); + H5MM_memcpy(&sh_mesg.u.heap_id, buf, sizeof(sh_mesg.u.heap_id)); } /* end if */ else { /* The H5O_COMMITTED_FLAG should be set if this message @@ -426,7 +427,7 @@ H5O__shared_encode(const H5F_t *f, uint8_t *buf/*out*/, const H5O_shared_t *sh_m * object header that holds it. */ if(sh_mesg->type == H5O_SHARE_TYPE_SOHM) - HDmemcpy(buf, &(sh_mesg->u.heap_id), sizeof(sh_mesg->u.heap_id)); + H5MM_memcpy(buf, &(sh_mesg->u.heap_id), sizeof(sh_mesg->u.heap_id)); else H5F_addr_encode(f, &buf, sh_mesg->u.loc.oh_addr); @@ -817,14 +817,17 @@ done: /*-------------------------------------------------------------------------- NAME - H5Pencode + H5Pencode2 PURPOSE - Routine to convert the property values in a property list into a binary buffer + Routine to convert the property values in a property list into a binary buffer. + The encoding of property values will be done according to the file format + setting in fapl_id. USAGE - herr_t H5Pencode(plist_id, buf, nalloc) + herr_t H5Pencode(plist_id, buf, nalloc, fapl_id) hid_t plist_id; IN: Identifier to property list to encode void *buf: OUT: buffer to gold the encoded plist size_t *nalloc; IN/OUT: size of buffer needed to encode plist + hid_t fapl_id; IN: File access property list ID RETURNS Returns non-negative on success, negative on failure. DESCRIPTION @@ -837,25 +840,29 @@ done: REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5Pencode(hid_t plist_id, void *buf, size_t *nalloc) +H5Pencode2(hid_t plist_id, void *buf, size_t *nalloc, hid_t fapl_id) { H5P_genplist_t *plist; /* Property list to query */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) - H5TRACE3("e", "i*x*z", plist_id, buf, nalloc); + H5TRACE4("e", "i*x*zi", plist_id, buf, nalloc, fapl_id); /* Check arguments. */ if(NULL == (plist = (H5P_genplist_t *)H5I_object_verify(plist_id, H5I_GENPROP_LST))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list"); + /* Verify access property list and set up collective metadata if appropriate */ + if(H5CX_set_apl(&fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") + /* Call the internal encode routine */ if((ret_value = H5P__encode(plist, TRUE, buf, nalloc)) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTENCODE, FAIL, "unable to encode property list"); done: FUNC_LEAVE_API(ret_value) -} /* H5Pencode() */ +} /* H5Pencode2() */ /*-------------------------------------------------------------------------- @@ -36,6 +36,7 @@ #include "H5Fpkg.h" /* Files */ #include "H5FDprivate.h" /* File drivers */ #include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ #include "H5PBpkg.h" /* File access */ #include "H5SLprivate.h" /* Skip List */ @@ -609,7 +610,7 @@ H5PB_update_entry(H5PB_t *page_buf, haddr_t addr, size_t size, const void *buf) HDassert(addr + size <= page_addr + page_buf->page_size); offset = addr - page_addr; - HDmemcpy((uint8_t *)page_entry->page_buf_ptr + offset, buf, size); + H5MM_memcpy((uint8_t *)page_entry->page_buf_ptr + offset, buf, size); /* move to top of LRU list */ H5PB__MOVE_TO_TOP_LRU(page_buf, page_entry) @@ -818,7 +819,7 @@ H5PB_read(H5F_t *f, H5FD_mem_t type, haddr_t addr, size_t size, void *buf/*out*/ offset = addr - first_page_addr; HDassert(page_buf->page_size > offset); - HDmemcpy(buf, (uint8_t *)page_entry->page_buf_ptr + offset, + H5MM_memcpy(buf, (uint8_t *)page_entry->page_buf_ptr + offset, page_buf->page_size - (size_t)offset); /* move to top of LRU list */ @@ -829,7 +830,7 @@ H5PB_read(H5F_t *f, H5FD_mem_t type, haddr_t addr, size_t size, void *buf/*out*/ offset = (num_touched_pages-2)*page_buf->page_size + (page_buf->page_size - (addr - first_page_addr)); - HDmemcpy((uint8_t *)buf + offset, page_entry->page_buf_ptr, + H5MM_memcpy((uint8_t *)buf + offset, page_entry->page_buf_ptr, (size_t)((addr + size) - last_page_addr)); /* move to top of LRU list */ @@ -839,7 +840,7 @@ H5PB_read(H5F_t *f, H5FD_mem_t type, haddr_t addr, size_t size, void *buf/*out*/ else { offset = i*page_buf->page_size; - HDmemcpy((uint8_t *)buf+(i*page_buf->page_size) , page_entry->page_buf_ptr, + H5MM_memcpy((uint8_t *)buf+(i*page_buf->page_size) , page_entry->page_buf_ptr, page_buf->page_size); } /* end else */ } /* end if */ @@ -872,7 +873,7 @@ H5PB_read(H5F_t *f, H5FD_mem_t type, haddr_t addr, size_t size, void *buf/*out*/ buf_offset = (0 == i ? 0 : size - access_size); /* copy the requested data from the page into the input buffer */ - HDmemcpy((uint8_t *)buf + buf_offset, (uint8_t *)page_entry->page_buf_ptr + offset, access_size); + H5MM_memcpy((uint8_t *)buf + buf_offset, (uint8_t *)page_entry->page_buf_ptr + offset, access_size); /* Update LRU */ H5PB__MOVE_TO_TOP_LRU(page_buf, page_entry) @@ -937,7 +938,7 @@ H5PB_read(H5F_t *f, H5FD_mem_t type, haddr_t addr, size_t size, void *buf/*out*/ /* Copy the requested data from the page into the input buffer */ offset = (0 == i ? addr - search_addr : 0); buf_offset = (0 == i ? 0 : size - access_size); - HDmemcpy((uint8_t *)buf + buf_offset, (uint8_t *)new_page_buf + offset, access_size); + H5MM_memcpy((uint8_t *)buf + buf_offset, (uint8_t *)new_page_buf + offset, access_size); /* Create the new PB entry */ if(NULL == (page_entry = H5FL_CALLOC(H5PB_entry_t))) @@ -1102,7 +1103,7 @@ H5PB_write(H5F_t *f, H5FD_mem_t type, haddr_t addr, HDassert(page_buf->page_size > offset); /* Update page's data */ - HDmemcpy((uint8_t *)page_entry->page_buf_ptr + offset, buf, page_buf->page_size - (size_t)offset); + H5MM_memcpy((uint8_t *)page_entry->page_buf_ptr + offset, buf, page_buf->page_size - (size_t)offset); /* Mark page dirty and push to top of LRU */ page_entry->is_dirty = TRUE; @@ -1121,7 +1122,7 @@ H5PB_write(H5F_t *f, H5FD_mem_t type, haddr_t addr, (page_buf->page_size - (addr - first_page_addr)); /* Update page's data */ - HDmemcpy(page_entry->page_buf_ptr, (const uint8_t *)buf + offset, + H5MM_memcpy(page_entry->page_buf_ptr, (const uint8_t *)buf + offset, (size_t)((addr + size) - last_page_addr)); /* Mark page dirty and push to top of LRU */ @@ -1173,7 +1174,7 @@ H5PB_write(H5F_t *f, H5FD_mem_t type, haddr_t addr, buf_offset = (0 == i ? 0 : size - access_size); /* Copy the requested data from the input buffer into the page */ - HDmemcpy((uint8_t *)page_entry->page_buf_ptr + offset, (const uint8_t *)buf + buf_offset, access_size); + H5MM_memcpy((uint8_t *)page_entry->page_buf_ptr + offset, (const uint8_t *)buf + buf_offset, access_size); /* Mark page dirty and push to top of LRU */ page_entry->is_dirty = TRUE; @@ -1289,7 +1290,7 @@ H5PB_write(H5F_t *f, H5FD_mem_t type, haddr_t addr, } /* end else */ /* Copy the requested data from the page into the input buffer */ - HDmemcpy((uint8_t *)new_page_buf + offset, (const uint8_t *)buf+buf_offset, access_size); + H5MM_memcpy((uint8_t *)new_page_buf + offset, (const uint8_t *)buf+buf_offset, access_size); /* Page is dirty now */ page_entry->is_dirty = TRUE; diff --git a/src/H5Pdapl.c b/src/H5Pdapl.c index 00e598f..5ce12b4 100644 --- a/src/H5Pdapl.c +++ b/src/H5Pdapl.c @@ -37,8 +37,8 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* Files */ #include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Ppkg.h" /* Property lists */ -#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -341,7 +341,7 @@ H5P__dapl_vds_file_pref_enc(const void *value, void **_pp, size_t *size) /* encode the prefix */ if(NULL != vds_file_pref) { - HDmemcpy(*(char **)pp, vds_file_pref, len); + H5MM_memcpy(*(char **)pp, vds_file_pref, len); *pp += len; } /* end if */ } /* end if */ @@ -589,7 +589,7 @@ H5P__dapl_efile_pref_enc(const void *value, void **_pp, size_t *size) /* encode the prefix */ if(NULL != efile_pref) { - HDmemcpy(*(char **)pp, efile_pref, len); + H5MM_memcpy(*(char **)pp, efile_pref, len); *pp += len; } /* end if */ } /* end if */ diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index b85f105..41d7c78 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -439,13 +439,13 @@ H5P__dcrt_layout_enc(const void *value, void **_pp, size_t *size) for(u = 0; u < layout->storage.u.virt.list_nused; u++) { /* Source file name */ tmp_size = HDstrlen(layout->storage.u.virt.list[u].source_file_name) + (size_t)1; - (void)HDmemcpy(*pp, layout->storage.u.virt.list[u].source_file_name, tmp_size); + (void)H5MM_memcpy(*pp, layout->storage.u.virt.list[u].source_file_name, tmp_size); *pp += tmp_size; *size += tmp_size; /* Source dataset name */ tmp_size = HDstrlen(layout->storage.u.virt.list[u].source_dset_name) + (size_t)1; - (void)HDmemcpy(*pp, layout->storage.u.virt.list[u].source_dset_name, tmp_size); + (void)H5MM_memcpy(*pp, layout->storage.u.virt.list[u].source_dset_name, tmp_size); *pp += tmp_size; *size += tmp_size; @@ -615,14 +615,14 @@ H5P__dcrt_layout_dec(const void **_pp, void *value) tmp_size = HDstrlen((const char *)*pp) + 1; if(NULL == (tmp_layout.storage.u.virt.list[u].source_file_name = (char *)H5MM_malloc(tmp_size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "unable to allocate memory for source file name") - (void)HDmemcpy(tmp_layout.storage.u.virt.list[u].source_file_name, *pp, tmp_size); + (void)H5MM_memcpy(tmp_layout.storage.u.virt.list[u].source_file_name, *pp, tmp_size); *pp += tmp_size; /* Source dataset name */ tmp_size = HDstrlen((const char *)*pp) + 1; if(NULL == (tmp_layout.storage.u.virt.list[u].source_dset_name = (char *)H5MM_malloc(tmp_size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "unable to allocate memory for source dataset name") - (void)HDmemcpy(tmp_layout.storage.u.virt.list[u].source_dset_name, *pp, tmp_size); + (void)H5MM_memcpy(tmp_layout.storage.u.virt.list[u].source_dset_name, *pp, tmp_size); *pp += tmp_size; /* Source selection */ @@ -687,7 +687,7 @@ H5P__dcrt_layout_dec(const void **_pp, void *value) } /* end switch */ /* Set the value */ - HDmemcpy(value, layout, sizeof(H5O_layout_t)); + H5MM_memcpy(value, layout, sizeof(H5O_layout_t)); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1036,7 +1036,7 @@ H5P__dcrt_fill_value_enc(const void *value, void **_pp, size_t *size) /* Encode the fill value & datatype */ if(fill->size > 0) { /* Encode the fill value itself */ - HDmemcpy(*pp, (uint8_t *)fill->buf, (size_t)fill->size); + H5MM_memcpy(*pp, (uint8_t *)fill->buf, (size_t)fill->size); *pp += fill->size; /* Encode fill value datatype */ @@ -1133,7 +1133,7 @@ H5P__dcrt_fill_value_dec(const void **_pp, void *_value) /* Allocate fill buffer and copy the contents in it */ if(NULL == (fill->buf = H5MM_malloc((size_t)fill->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for fill value buffer") - HDmemcpy((uint8_t *)fill->buf, *pp, (size_t)fill->size); + H5MM_memcpy((uint8_t *)fill->buf, *pp, (size_t)fill->size); *pp += fill->size; enc_size = *(*pp)++; @@ -1448,7 +1448,7 @@ H5P__dcrt_ext_file_list_enc(const void *value, void **_pp, size_t *size) UINT64ENCODE_VAR(*pp, enc_value, enc_size); /* Encode name */ - HDmemcpy(*pp, (uint8_t *)(efl->slot[u].name), len); + H5MM_memcpy(*pp, (uint8_t *)(efl->slot[u].name), len); *pp += len; /* Encode offset */ @@ -2035,7 +2035,7 @@ H5Pset_chunk(hid_t plist_id, int ndims, const hsize_t dim[/*ndims*/]) #endif /* H5_HAVE_C99_DESIGNATED_INITIALIZER */ /* Verify & initialize property's chunk dims */ - HDmemcpy(&chunk_layout, &H5D_def_layout_chunk_g, sizeof(H5D_def_layout_chunk_g)); + H5MM_memcpy(&chunk_layout, &H5D_def_layout_chunk_g, sizeof(H5D_def_layout_chunk_g)); HDmemset(&chunk_layout.u.chunk.dim, 0, sizeof(chunk_layout.u.chunk.dim)); chunk_nelmts = 1; for(u = 0; u < (unsigned)ndims; u++) { @@ -2204,7 +2204,7 @@ H5Pset_virtual(hid_t dcpl_id, hid_t vspace_id, const char *src_file_name, HGOTO_ERROR(H5E_PLIST, H5E_CANTRESET, FAIL, "can't release layout message") /* Copy the default virtual layout */ - HDmemcpy(&virtual_layout, &H5D_def_layout_virtual_g, sizeof(H5D_def_layout_virtual_g)); + H5MM_memcpy(&virtual_layout, &H5D_def_layout_virtual_g, sizeof(H5D_def_layout_virtual_g)); /* Sanity check */ HDassert(virtual_layout.storage.u.virt.list_nalloc == 0); @@ -3243,7 +3243,7 @@ H5Pset_fill_value(hid_t plist_id, hid_t type_id, const void *value) fill.size = (ssize_t)H5T_get_size(type); if(NULL == (fill.buf = H5MM_malloc((size_t)fill.size))) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "memory allocation failed for fill value") - HDmemcpy(fill.buf, value, (size_t)fill.size); + H5MM_memcpy(fill.buf, value, (size_t)fill.size); /* Set up type conversion function */ if(NULL == (tpath = H5T_path_find(type, type))) @@ -3351,7 +3351,7 @@ H5P_get_fill_value(H5P_genplist_t *plist, const H5T_t *type, void *value/*out*/) if(H5T_path_bkg(tpath) && NULL == (bkg = H5MM_malloc(H5T_get_size(fill.type)))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for type conversion") } /* end else */ - HDmemcpy(buf, fill.buf, H5T_get_size(fill.type)); + H5MM_memcpy(buf, fill.buf, H5T_get_size(fill.type)); /* Do the conversion */ if((dst_id = H5I_register(H5I_DATATYPE, H5T_copy(type, H5T_COPY_TRANSIENT), FALSE)) < 0) @@ -3359,7 +3359,7 @@ H5P_get_fill_value(H5P_genplist_t *plist, const H5T_t *type, void *value/*out*/) if(H5T_convert(tpath, src_id, dst_id, (size_t)1, (size_t)0, (size_t)0, buf, bkg) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "datatype conversion failed") if(buf != value) - HDmemcpy(value, buf, H5T_get_size(type)); + H5MM_memcpy(value, buf, H5T_get_size(type)); done: if(buf != value) diff --git a/src/H5Pdeprec.c b/src/H5Pdeprec.c index 4a63b36..f6c2a3c 100644 --- a/src/H5Pdeprec.c +++ b/src/H5Pdeprec.c @@ -486,6 +486,54 @@ done: FUNC_LEAVE_API(ret_value) } /* end H5Pget_version() */ + +/*-------------------------------------------------------------------------- + NAME + H5Pencode1 + PURPOSE + Routine to convert the property values in a property list into a binary buffer + USAGE + herr_t H5Pencode1(plist_id, buf, nalloc) + hid_t plist_id; IN: Identifier to property list to encode + void *buf: OUT: buffer to gold the encoded plist + size_t *nalloc; IN/OUT: size of buffer needed to encode plist + RETURNS + Returns non-negative on success, negative on failure. + DESCRIPTION + Encodes a property list into a binary buffer. If the buffer is NULL, then + the call will set the size needed to encode the plist in nalloc. Otherwise + the routine will encode the plist in buf. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +herr_t +H5Pencode1(hid_t plist_id, void *buf, size_t *nalloc) +{ + H5P_genplist_t *plist; /* Property list to query */ + hid_t temp_fapl_id = H5P_DEFAULT; + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE3("e", "i*x*z", plist_id, buf, nalloc); + + /* Check arguments. */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object_verify(plist_id, H5I_GENPROP_LST))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list"); + + /* Verify access property list and set up collective metadata if appropriate */ + if(H5CX_set_apl(&temp_fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") + + /* Call the internal encode routine */ + if((ret_value = H5P__encode(plist, TRUE, buf, nalloc)) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTENCODE, FAIL, "unable to encode property list"); + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Pencode1() */ + /*------------------------------------------------------------------------- * Function: H5Pset_file_space * diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c index 8338d84..df9cf4e 100644 --- a/src/H5Pdxpl.c +++ b/src/H5Pdxpl.c @@ -695,7 +695,7 @@ H5P__dxfr_xform_enc(const void *value, void **_pp, size_t *size) HDassert(pexp); /* Copy the expression into the buffer */ - HDmemcpy(*pp, (const uint8_t *)pexp, len); + H5MM_memcpy(*pp, (const uint8_t *)pexp, len); *pp += len; *pp[0] = '\0'; } /* end if */ diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index bfb52ff..585e913 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -1064,7 +1064,7 @@ H5P__file_driver_copy(void *value) else if(driver->fapl_size > 0) { if(NULL == (new_pl = H5MM_malloc(driver->fapl_size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "driver info allocation failed") - HDmemcpy(new_pl, info->driver_info, driver->fapl_size); + H5MM_memcpy(new_pl, info->driver_info, driver->fapl_size); } /* end else-if */ else HGOTO_ERROR(H5E_PLIST, H5E_UNSUPPORTED, FAIL, "no way to copy driver info") @@ -2597,7 +2597,7 @@ H5Pset_file_image(hid_t fapl_id, void *buf_ptr, size_t buf_len) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCOPY, FAIL, "image_memcpy callback failed") } /* end if */ else - HDmemcpy(image_info.buffer, buf_ptr, buf_len); + H5MM_memcpy(image_info.buffer, buf_ptr, buf_len); } /* end if */ else image_info.buffer = NULL; @@ -2691,7 +2691,7 @@ H5Pget_file_image(hid_t fapl_id, void **buf_ptr_ptr, size_t *buf_len_ptr) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCOPY, FAIL, "image_memcpy callback failed") } /* end if */ else - HDmemcpy(copy_ptr, image_info.buffer, image_info.size); + H5MM_memcpy(copy_ptr, image_info.buffer, image_info.size); } /* end if */ *buf_ptr_ptr = copy_ptr; @@ -2894,7 +2894,7 @@ H5P__file_image_info_copy(void *value) HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "image_memcpy callback failed") } /* end if */ else - HDmemcpy(info->buffer, old_buffer, info->size); + H5MM_memcpy(info->buffer, old_buffer, info->size); } /* end if */ /* Copy udata if it exists */ @@ -3089,7 +3089,7 @@ H5P__facc_cache_image_config_dec(const void **_pp, void *_value) HDcompile_assert(sizeof(size_t) <= sizeof(uint64_t)); /* Set property to default value */ - HDmemcpy(config, &H5F_def_mdc_initCacheImageCfg_g, sizeof(H5AC_cache_image_config_t)); + H5MM_memcpy(config, &H5F_def_mdc_initCacheImageCfg_g, sizeof(H5AC_cache_image_config_t)); /* Decode type sizes */ enc_size = *(*pp)++; @@ -3480,7 +3480,7 @@ H5P__facc_cache_config_enc(const void *value, void **_pp, size_t *size) H5_ENCODE_UNSIGNED(*pp, config->close_trace_file); - HDmemcpy(*pp, (const uint8_t *)(config->trace_file_name), (size_t)(H5AC__MAX_TRACE_FILE_NAME_LEN + 1)); + H5MM_memcpy(*pp, (const uint8_t *)(config->trace_file_name), (size_t)(H5AC__MAX_TRACE_FILE_NAME_LEN + 1)); *pp += H5AC__MAX_TRACE_FILE_NAME_LEN + 1; H5_ENCODE_UNSIGNED(*pp, config->evictions_enabled); @@ -3615,7 +3615,7 @@ H5P__facc_cache_config_dec(const void **_pp, void *_value) HDcompile_assert(sizeof(size_t) <= sizeof(uint64_t)); /* Set property to default value */ - HDmemcpy(config, &H5F_def_mdc_initCacheCfg_g, sizeof(H5AC_cache_config_t)); + H5MM_memcpy(config, &H5F_def_mdc_initCacheCfg_g, sizeof(H5AC_cache_config_t)); /* Decode type sizes */ enc_size = *(*pp)++; @@ -4195,7 +4195,7 @@ H5Pget_mdc_log_options(hid_t plist_id, hbool_t *is_enabled, char *location, /* Copy log location to output buffer */ if(location_ptr && location) - HDmemcpy(location, location_ptr, *location_size); + H5MM_memcpy(location, location_ptr, *location_size); /* Get location size, including terminating NULL */ if(location_size) { @@ -4250,7 +4250,7 @@ H5P_facc_mdc_log_location_enc(const void *value, void **_pp, size_t *size) /* encode the prefix */ if(NULL != log_location) { - HDmemcpy(*(char **)pp, log_location, len); + H5MM_memcpy(*(char **)pp, log_location, len); *pp += len; } /* end if */ } /* end if */ @@ -4536,7 +4536,7 @@ H5P__encode_coll_md_read_flag_t(const void *value, void **_pp, size_t *size) if(NULL != *pp) { /* Encode the value */ - HDmemcpy(*pp, coll_md_read_flag, sizeof(H5P_coll_md_read_flag_t)); + H5MM_memcpy(*pp, coll_md_read_flag, sizeof(H5P_coll_md_read_flag_t)); *pp += sizeof(H5P_coll_md_read_flag_t); } /* end if */ @@ -4907,6 +4907,43 @@ done: /*------------------------------------------------------------------------- + * Function: H5P_reset_vol_class + * + * Purpose: Change the VOL connector for a file access property class. + * + * Note: The VOL property will be copied into the property list and + * the reference count on the previous VOL will _NOT_ be decremented. + * The reference count on the new VOL will _NOT_ be incremented. + * + * Return: SUCCEED/FAIL + * + * Programmer: Quincey Koziol + * March 8, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5P_reset_vol_class(const H5P_genclass_t *pclass, const H5VL_connector_prop_t *vol_prop) +{ + H5VL_connector_prop_t old_vol_prop; /* Previous VOL connector property */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Get the connector ID & info property */ + if(H5P__class_get(pclass, H5F_ACS_VOL_CONN_NAME, &old_vol_prop) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get VOL connector ID & info") + + /* Set the new connector ID & info property */ + if(H5P__class_set(pclass, H5F_ACS_VOL_CONN_NAME, vol_prop) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set VOL connector ID & info") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P_set_vol_class() */ + + +/*------------------------------------------------------------------------- * Function: H5Pset_vol * * Purpose: Set the file VOL connector (VOL_ID) for a file access diff --git a/src/H5Pint.c b/src/H5Pint.c index e2ae792..b07f42d 100644 --- a/src/H5Pint.c +++ b/src/H5Pint.c @@ -631,7 +631,7 @@ H5P__do_prop_cb1(H5SL_t *slist, H5P_genprop_t *prop, H5P_prp_cb1_t cb) /* Allocate space for a temporary copy of the property value */ if(NULL == (tmp_value = H5MM_malloc(prop->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for temporary property value") - HDmemcpy(tmp_value, prop->value, prop->size); + H5MM_memcpy(tmp_value, prop->value, prop->size); /* Call "type 1" callback ('create', 'copy' or 'close') */ if(cb(prop->name, prop->size, tmp_value) < 0) @@ -642,7 +642,7 @@ H5P__do_prop_cb1(H5SL_t *slist, H5P_genprop_t *prop, H5P_prp_cb1_t cb) HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "Can't copy property") /* Copy the changed value into the new property */ - HDmemcpy(pcopy->value, tmp_value, prop->size); + H5MM_memcpy(pcopy->value, tmp_value, prop->size); /* Insert the changed property into the property list */ if(H5P__add_prop(slist, pcopy) < 0) @@ -990,7 +990,7 @@ H5P__dup_prop(H5P_genprop_t *oprop, H5P_prop_within_t type) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Copy basic property information */ - HDmemcpy(prop, oprop, sizeof(H5P_genprop_t)); + H5MM_memcpy(prop, oprop, sizeof(H5P_genprop_t)); /* Check if we should duplicate the name or share it */ @@ -1030,7 +1030,7 @@ H5P__dup_prop(H5P_genprop_t *oprop, H5P_prop_within_t type) HDassert(prop->size > 0); if(NULL == (prop->value = H5MM_malloc(prop->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(prop->value, oprop->value, prop->size); + H5MM_memcpy(prop->value, oprop->value, prop->size); } /* end if */ /* Set return value */ @@ -1117,7 +1117,7 @@ H5P__create_prop(const char *name, size_t size, H5P_prop_within_t type, if(value != NULL) { if(NULL == (prop->value = H5MM_malloc (prop->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(prop->value, value, prop->size); + H5MM_memcpy(prop->value, value, prop->size); } /* end if */ else prop->value = NULL; @@ -2727,7 +2727,7 @@ H5P__poke_plist_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "property has zero size") /* Overwrite value in property */ - HDmemcpy(prop->value, udata->value, prop->size); + H5MM_memcpy(prop->value, udata->value, prop->size); done: FUNC_LEAVE_NOAPI(ret_value) @@ -2779,7 +2779,7 @@ H5P__poke_pclass_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop if(NULL == (pcopy = H5P__dup_prop(prop, H5P_PROP_WITHIN_LIST))) HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "Can't copy property") - HDmemcpy(pcopy->value, udata->value, pcopy->size); + H5MM_memcpy(pcopy->value, udata->value, pcopy->size); /* Insert the changed property into the property list */ if(H5P__add_prop(plist->props, pcopy) < 0) @@ -2888,7 +2888,7 @@ H5P__set_plist_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, /* Make a copy of the current value, in case the callback fails */ if(NULL == (tmp_value = H5MM_malloc(prop->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed temporary property value") - HDmemcpy(tmp_value, udata->value, prop->size); + H5MM_memcpy(tmp_value, udata->value, prop->size); /* Call user's callback */ if((*(prop->set))(plist->plist_id, name, prop->size, tmp_value) < 0) @@ -2909,7 +2909,7 @@ H5P__set_plist_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, } /* end if */ /* Copy new [possibly unchanged] value into property value */ - HDmemcpy(prop->value, prp_value, prop->size); + H5MM_memcpy(prop->value, prp_value, prop->size); done: /* Free the temporary value buffer */ @@ -2968,7 +2968,7 @@ H5P__set_pclass_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, /* Make a copy of the current value, in case the callback fails */ if(NULL == (tmp_value = H5MM_malloc(prop->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed temporary property value") - HDmemcpy(tmp_value, udata->value, prop->size); + H5MM_memcpy(tmp_value, udata->value, prop->size); /* Call user's callback */ if((*(prop->set))(plist->plist_id, name, prop->size, tmp_value) < 0) @@ -2985,7 +2985,7 @@ H5P__set_pclass_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, if(NULL == (pcopy = H5P__dup_prop(prop, H5P_PROP_WITHIN_LIST))) HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "Can't copy property") - HDmemcpy(pcopy->value, prp_value, pcopy->size); + H5MM_memcpy(pcopy->value, prp_value, pcopy->size); /* Insert the changed property into the property list */ if(H5P__add_prop(plist->props, pcopy) < 0) @@ -3061,6 +3061,116 @@ done: /*-------------------------------------------------------------------------- NAME + H5P__class_get + PURPOSE + Internal routine to get a property's value from a property class. + USAGE + herr_t H5P__class_get(pclass, name, value) + const H5P_genclass_t *pclass; IN: Property class to find property in + const char *name; IN: Name of property to get + void *value; IN: Pointer to the value for the property + RETURNS + Returns non-negative on success, negative on failure. + DESCRIPTION + Gets the current value for a property in a property class. The property + name must exist or this routine will fail. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + The 'get' callback routine registered for this property will _NOT_ be + called, this routine is designed for internal library use only! + + This routine may not be called for zero-sized properties and will + return an error in that case. + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +herr_t +H5P__class_get(const H5P_genclass_t *pclass, const char *name, void *value) +{ + H5P_genprop_t *prop; /* Temporary property pointer */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Sanity check */ + HDassert(pclass); + HDassert(name); + HDassert(value); + + /* Find property in list */ + if(NULL == (prop = (H5P_genprop_t *)H5SL_search(pclass->props, name))) + HGOTO_ERROR(H5E_PLIST, H5E_NOTFOUND, FAIL, "property doesn't exist") + + /* Check for property size >0 */ + if(0 == prop->size) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "property has zero size") + + /* Copy the property value */ + HDmemcpy(value, prop->value, prop->size); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5P__class_get() */ + + +/*-------------------------------------------------------------------------- + NAME + H5P__class_set + PURPOSE + Internal routine to set a property's value in a property class. + USAGE + herr_t H5P__class_set(pclass, name, value) + const H5P_genclass_t *pclass; IN: Property class to find property in + const char *name; IN: Name of property to set + const void *value; IN: Pointer to the value for the property + RETURNS + Returns non-negative on success, negative on failure. + DESCRIPTION + Sets a new value for a property in a property class. The property name + must exist or this routine will fail. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + The 'set' callback routine registered for this property will _NOT_ be + called, this routine is designed for internal library use only! + + This routine may not be called for zero-sized properties and will + return an error in that case. + + The previous value is overwritten, not released in any way. + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +herr_t +H5P__class_set(const H5P_genclass_t *pclass, const char *name, const void *value) +{ + H5P_genprop_t *prop; /* Temporary property pointer */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Sanity check */ + HDassert(pclass); + HDassert(name); + HDassert(value); + + /* Find property in list */ + if(NULL == (prop = (H5P_genprop_t *)H5SL_search(pclass->props, name))) + HGOTO_ERROR(H5E_PLIST, H5E_NOTFOUND, FAIL, "property doesn't exist") + + /* Check for property size >0 */ + if(0 == prop->size) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "property has zero size") + + /* Copy the property value */ + HDmemcpy(prop->value, value, prop->size); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5P__class_set() */ + + +/*-------------------------------------------------------------------------- + NAME H5P_exist_plist PURPOSE Internal routine to query the existance of a property in a property list. @@ -4234,7 +4344,7 @@ H5P__peek_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "property has zero size") /* Make a (shallow) copy of the value */ - HDmemcpy(udata->value, prop->value, prop->size); + H5MM_memcpy(udata->value, prop->value, prop->size); done: FUNC_LEAVE_NOAPI(ret_value) @@ -4334,18 +4444,18 @@ H5P__get_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, /* Make a copy of the current value, in case the callback fails */ if(NULL == (tmp_value = H5MM_malloc(prop->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed temporary property value") - HDmemcpy(tmp_value, prop->value, prop->size); + H5MM_memcpy(tmp_value, prop->value, prop->size); /* Call user's callback */ if((*(prop->get))(plist->plist_id, name, prop->size, tmp_value) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "can't set property value") /* Copy new [possibly unchanged] value into return value */ - HDmemcpy(udata->value, tmp_value, prop->size); + H5MM_memcpy(udata->value, tmp_value, prop->size); } /* end if */ /* No 'get' callback, just copy value */ else - HDmemcpy(udata->value, prop->value, prop->size); + H5MM_memcpy(udata->value, prop->value, prop->size); done: /* Free the temporary value buffer */ @@ -4518,7 +4628,7 @@ H5P__del_pclass_cb(H5P_genplist_t *plist, const char *name, H5P_genprop_t *prop, /* Allocate space for a temporary copy of the property value */ if(NULL == (tmp_value = H5MM_malloc(prop->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for temporary property value") - HDmemcpy(tmp_value, prop->value, prop->size); + H5MM_memcpy(tmp_value, prop->value, prop->size); /* Call user's callback */ if((*(prop->del))(plist->plist_id, name, prop->size, tmp_value) < 0) @@ -4967,7 +5077,7 @@ H5P_close(void *_plist) /* Allocate space for a temporary copy of the property value */ if(NULL==(tmp_value=H5MM_malloc(tmp->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for temporary property value") - HDmemcpy(tmp_value,tmp->value,tmp->size); + H5MM_memcpy(tmp_value,tmp->value,tmp->size); /* Call the 'close' callback */ (tmp->close)(tmp->name,tmp->size,tmp_value); diff --git a/src/H5Plapl.c b/src/H5Plapl.c index bedeed9..7a7cc23 100644 --- a/src/H5Plapl.c +++ b/src/H5Plapl.c @@ -715,7 +715,7 @@ H5P__lacc_elink_pref_enc(const void *value, void **_pp, size_t *size) /* encode the prefix */ if(NULL != elink_pref) { - HDmemcpy(*(char **)pp, elink_pref, len); + H5MM_memcpy(*(char **)pp, elink_pref, len); *pp += len; } /* end if */ } /* end if */ diff --git a/src/H5Pocpl.c b/src/H5Pocpl.c index c2bf6cb..a60c593 100644 --- a/src/H5Pocpl.c +++ b/src/H5Pocpl.c @@ -1501,7 +1501,7 @@ H5P__ocrt_pipeline_enc(const void *value, void **_pp, size_t *size) *(*pp)++ = (uint8_t)TRUE; /* encode filter name */ - HDmemcpy(*pp, (uint8_t *)(pline->filter[u].name), H5Z_COMMON_NAME_LEN); + H5MM_memcpy(*pp, (uint8_t *)(pline->filter[u].name), H5Z_COMMON_NAME_LEN); *pp += H5Z_COMMON_NAME_LEN; } /* end if */ else diff --git a/src/H5Pocpypl.c b/src/H5Pocpypl.c index 666a945..2dc92f9 100644 --- a/src/H5Pocpypl.c +++ b/src/H5Pocpypl.c @@ -384,7 +384,7 @@ H5P__ocpy_merge_comm_dt_list_enc(const void *value, void **_pp, size_t *size) /* Encode merge committed dtype list */ if(*pp) { - HDmemcpy(*(char **)pp, dt_list->path, len); + H5MM_memcpy(*(char **)pp, dt_list->path, len); *pp += len; } /* end if */ diff --git a/src/H5Ppkg.h b/src/H5Ppkg.h index 13f3b13..c8e5e98 100644 --- a/src/H5Ppkg.h +++ b/src/H5Ppkg.h @@ -151,6 +151,10 @@ H5_DLL herr_t H5P__register(H5P_genclass_t **pclass, const char *name, size_t si H5P_prp_close_func_t prp_close); H5_DLL herr_t H5P__add_prop(H5SL_t *props, H5P_genprop_t *prop); H5_DLL herr_t H5P__access_class(H5P_genclass_t *pclass, H5P_class_mod_t mod); +H5_DLL herr_t H5P__class_get(const H5P_genclass_t *pclass, const char *name, + void *value); +H5_DLL herr_t H5P__class_set(const H5P_genclass_t *pclass, const char *name, + const void *value); H5_DLL htri_t H5P__exist_pclass(H5P_genclass_t *pclass, const char *name); H5_DLL herr_t H5P__get_size_plist(const H5P_genplist_t *plist, const char *name, size_t *size); diff --git a/src/H5Pprivate.h b/src/H5Pprivate.h index 866f088..49f7a12 100644 --- a/src/H5Pprivate.h +++ b/src/H5Pprivate.h @@ -148,6 +148,7 @@ H5_DLLVAR const struct H5P_libclass_t H5P_CLS_OCPY[1]; /* Object copy */ /* Forward declaration of structs used below */ struct H5O_fill_t; struct H5T_t; +struct H5VL_connector_prop_t; /* Package initialization routine */ H5_DLL herr_t H5P_init(void); @@ -178,6 +179,8 @@ H5_DLL const void *H5P_peek_driver_info(H5P_genplist_t *plist); H5_DLL herr_t H5P_set_driver(H5P_genplist_t *plist, hid_t new_driver_id, const void *new_driver_info); H5_DLL herr_t H5P_set_vol(H5P_genplist_t *plist, hid_t vol_id, const void *vol_info); +H5_DLL herr_t H5P_reset_vol_class(const H5P_genclass_t *pclass, + const struct H5VL_connector_prop_t *vol_prop); H5_DLL herr_t H5P_set_vlen_mem_manager(H5P_genplist_t *plist, H5MM_allocate_t alloc_func, void *alloc_info, H5MM_free_t free_func, void *free_info); diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index 078fe74..90e6618 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -236,7 +236,7 @@ H5_DLL herr_t H5Pinsert2(hid_t plist_id, const char *name, size_t size, H5P_prp_compare_func_t prp_cmp, H5P_prp_close_func_t prp_close); H5_DLL herr_t H5Pset(hid_t plist_id, const char *name, const void *value); H5_DLL htri_t H5Pexist(hid_t plist_id, const char *name); -H5_DLL herr_t H5Pencode(hid_t plist_id, void *buf, size_t *nalloc); +H5_DLL herr_t H5Pencode2(hid_t plist_id, void *buf, size_t *nalloc, hid_t fapl_id); H5_DLL hid_t H5Pdecode(const void *buf); H5_DLL herr_t H5Pget_size(hid_t id, const char *name, size_t *size); H5_DLL herr_t H5Pget_nprops(hid_t id, size_t *nprops); @@ -536,6 +536,7 @@ H5_DLL herr_t H5Pinsert1(hid_t plist_id, const char *name, size_t size, void *value, H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get, H5P_prp_delete_func_t prp_delete, H5P_prp_copy_func_t prp_copy, H5P_prp_close_func_t prp_close); +H5_DLL herr_t H5Pencode1(hid_t plist_id, void *buf, size_t *nalloc); H5_DLL H5Z_filter_t H5Pget_filter1(hid_t plist_id, unsigned filter, unsigned int *flags/*out*/, size_t *cd_nelmts/*out*/, unsigned cd_values[]/*out*/, size_t namelen, char name[]); diff --git a/src/H5Rint.c b/src/H5Rint.c index a4f76ce..9098a03 100644 --- a/src/H5Rint.c +++ b/src/H5Rint.c @@ -215,6 +215,9 @@ H5R__create(void *_ref, H5G_loc_t *loc, const char *name, H5R_type_t ref_type, H obj_loc.path = &path; H5G_loc_reset(&obj_loc); + /* Set the FAPL for the API context */ + H5CX_set_libver_bounds(loc->oloc->file); + /* Find the object */ if(H5G_loc_find(loc, name, &obj_loc) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_NOTFOUND, FAIL, "object not found") @@ -23,9 +23,11 @@ /***********/ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ +#include "H5CXprivate.h" /* API Contexts */ #include "H5Fprivate.h" /* Files */ #include "H5FLprivate.h" /* Free lists */ #include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Oprivate.h" /* Object headers */ #include "H5Spkg.h" /* Dataspaces */ @@ -65,6 +67,7 @@ hbool_t H5_PKG_INIT_VAR = FALSE; const unsigned H5O_sdspace_ver_bounds[] = { H5O_SDSPACE_VERSION_1, /* H5F_LIBVER_EARLIEST */ H5O_SDSPACE_VERSION_2, /* H5F_LIBVER_V18 */ + H5O_SDSPACE_VERSION_2, /* H5F_LIBVER_V110 */ H5O_SDSPACE_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; @@ -1359,7 +1362,7 @@ H5S_set_extent_simple(H5S_t *space, unsigned rank, const hsize_t *dims, * same as the dimension */ space->extent.max = (hsize_t *)H5FL_ARR_MALLOC(hsize_t, (size_t)rank); if(max != NULL) - HDmemcpy(space->extent.max, max, sizeof(hsize_t) * rank); + H5MM_memcpy(space->extent.max, max, sizeof(hsize_t) * rank); else for(u = 0; u < space->extent.rank; u++) space->extent.max[u] = dims[u]; @@ -1485,13 +1488,15 @@ done: /*------------------------------------------------------------------------- - * Function: H5Sencode + * Function: H5Sencode2 * * Purpose: Given a dataspace ID, converts the object description * (including selection) into binary in a buffer. + * The selection will be encoded according to the file + * format setting in fapl. * * Return: Success: non-negative - * Failure: negative + * Failure: negative * * Programmer: Raymond Lu * slu@ncsa.uiuc.edu @@ -1500,24 +1505,29 @@ done: *------------------------------------------------------------------------- */ herr_t -H5Sencode(hid_t obj_id, void *buf, size_t *nalloc) +H5Sencode2(hid_t obj_id, void *buf, size_t *nalloc, hid_t fapl_id) { H5S_t *dspace; herr_t ret_value=SUCCEED; FUNC_ENTER_API(FAIL) - H5TRACE3("e", "i*x*z", obj_id, buf, nalloc); + H5TRACE4("e", "i*x*zi", obj_id, buf, nalloc, fapl_id); /* Check argument and retrieve object */ if(NULL == (dspace = (H5S_t *)H5I_object_verify(obj_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + + /* Verify access property list and set up collective metadata if appropriate */ + if(H5CX_set_apl(&fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") + if(H5S_encode(dspace, (unsigned char **)&buf, nalloc) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode dataspace") + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode dataspace") done: FUNC_LEAVE_API(ret_value) -} /* end H5Sencode() */ +} /* H5Sencode2() */ /*------------------------------------------------------------------------- @@ -240,7 +240,7 @@ /* Allocate space for new forward pointers */ \ if(NULL == (_tmp = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[X->log_nalloc]))) \ HGOTO_ERROR(H5E_SLIST, H5E_CANTALLOC, ERR, "memory allocation failed") \ - HDmemcpy((void *)_tmp, (const void *)X->forward, (LVL + 1) * sizeof(H5SL_node_t *)); \ + H5MM_memcpy((void *)_tmp, (const void *)X->forward, (LVL + 1) * sizeof(H5SL_node_t *)); \ X->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[X->log_nalloc-1], (void *)X->forward); \ X->forward = _tmp; \ } /* end if */ \ @@ -262,7 +262,7 @@ /* Allocate space for new forward pointers */ \ if(NULL == (_tmp = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[X->log_nalloc]))) \ HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed") \ - HDmemcpy((void *)_tmp, (const void *)X->forward, (LVL) * sizeof(H5SL_node_t *)); \ + H5MM_memcpy((void *)_tmp, (const void *)X->forward, (LVL) * sizeof(H5SL_node_t *)); \ X->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[X->log_nalloc+1], (void *)X->forward); \ X->forward = _tmp; \ } /* end if */ \ @@ -2318,7 +2318,7 @@ H5SM__read_iter_op(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, unsigned sequence, HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, H5_ITER_ERROR, "memory allocation failed") /* Copy the encoded message into the buffer to return */ - HDmemcpy(udata->encoding_buf, mesg->raw, udata->buf_size); + H5MM_memcpy(udata->encoding_buf, mesg->raw, udata->buf_size); /* Found the message we were looking for */ ret_value = H5_ITER_STOP; @@ -2356,7 +2356,7 @@ H5SM__read_mesg_fh_cb(const void *obj, size_t obj_len, void *_udata) HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy the message from the heap */ - HDmemcpy(udata->encoding_buf, obj, obj_len); + H5MM_memcpy(udata->encoding_buf, obj, obj_len); udata->buf_size = obj_len; done: diff --git a/src/H5SMbtree2.c b/src/H5SMbtree2.c index f0c4963..7f6c804 100644 --- a/src/H5SMbtree2.c +++ b/src/H5SMbtree2.c @@ -24,6 +24,7 @@ /***********/ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object Headers */ #include "H5SMpkg.h" /* Shared object header messages */ @@ -248,7 +249,7 @@ H5SM_bt2_convert_to_list_op(const void * record, void *op_data) /* Insert this message at the end of the list */ HDassert(list->messages[mesg_idx].location == H5SM_NO_LOC); HDassert(message->location != H5SM_NO_LOC); - HDmemcpy(&(list->messages[mesg_idx]), message, sizeof(H5SM_sohm_t)); + H5MM_memcpy(&(list->messages[mesg_idx]), message, sizeof(H5SM_sohm_t)); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5SM_bt2_convert_to_list_op() */ diff --git a/src/H5SMcache.c b/src/H5SMcache.c index f0b469a..49ce2b4 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -388,7 +388,7 @@ H5SM__cache_table_serialize(const H5F_t *f, void *_image, size_t len, HDassert(H5F_SOHM_VERS(f) == HDF5_SHAREDHEADER_VERSION); /* Encode magic number */ - HDmemcpy(image, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* Encode each index header */ @@ -710,7 +710,7 @@ H5SM__cache_list_serialize(const H5F_t *f, void *_image, size_t len, HDassert(list->header->list_size == len); /* Encode magic number */ - HDmemcpy(image, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC); + H5MM_memcpy(image, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC); image += H5_SIZEOF_MAGIC; /* serialize messages from the messages array */ diff --git a/src/H5SMmessage.c b/src/H5SMmessage.c index ad84b24..0cca6bb 100644 --- a/src/H5SMmessage.c +++ b/src/H5SMmessage.c @@ -24,6 +24,7 @@ /***********/ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object Headers */ #include "H5SMpkg.h" /* Shared object header messages */ @@ -302,7 +303,7 @@ H5SM__message_encode(uint8_t *raw, const void *_nrecord, void *_ctx) if(message->location == H5SM_IN_HEAP) { UINT32ENCODE(raw, message->u.heap_loc.ref_count); - HDmemcpy(raw, message->u.heap_loc.fheap_id.id, (size_t)H5O_FHEAP_ID_LEN); + H5MM_memcpy(raw, message->u.heap_loc.fheap_id.id, (size_t)H5O_FHEAP_ID_LEN); } /* end if */ else { HDassert(message->location == H5SM_IN_OH); @@ -343,7 +344,7 @@ H5SM__message_decode(const uint8_t *raw, void *_nrecord, void *_ctx) if(message->location == H5SM_IN_HEAP) { UINT32DECODE(raw, message->u.heap_loc.ref_count); - HDmemcpy(message->u.heap_loc.fheap_id.id, raw, (size_t)H5O_FHEAP_ID_LEN); + H5MM_memcpy(message->u.heap_loc.fheap_id.id, raw, (size_t)H5O_FHEAP_ID_LEN); } /* end if */ else { HDassert(message->location == H5SM_IN_OH); diff --git a/src/H5Sall.c b/src/H5Sall.c index 0aa2f05..7aa9644 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -58,8 +58,7 @@ static herr_t H5S__all_release(H5S_t *space); static htri_t H5S__all_is_valid(const H5S_t *space); static hssize_t H5S__all_serial_size(const H5S_t *space); static herr_t H5S__all_serialize(const H5S_t *space, uint8_t **p); -static herr_t H5S__all_deserialize(H5S_t *space, uint32_t version, uint8_t flags, - const uint8_t **p); +static herr_t H5S__all_deserialize(H5S_t **space, const uint8_t **p); static herr_t H5S__all_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S__all_offset(const H5S_t *space, hsize_t *off); static int H5S__all_unlim_dim(const H5S_t *space); @@ -630,7 +629,7 @@ H5S__all_serialize(const H5S_t *space, uint8_t **p) /* Store the preamble information */ UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(pp, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(pp, (uint32_t)H5S_ALL_VERSION_1); /* Store the version number */ UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */ UINT32ENCODE(pp, (uint32_t)0); /* Store the additional information length */ @@ -648,10 +647,8 @@ H5S__all_serialize(const H5S_t *space, uint8_t **p) Deserialize the current selection from a user-provided buffer. USAGE herr_t H5S_all_deserialize(space, p) - H5S_t *space; IN/OUT: Dataspace pointer to place + H5S_t **space; IN/OUT: Dataspace pointer to place selection into - uint32_t version IN: Selection version - uint8_t flags IN: Selection flags uint8 **p; OUT: Pointer to buffer holding serialized selection. Will be advanced to end of serialized selection. @@ -666,22 +663,51 @@ H5S__all_serialize(const H5S_t *space, uint8_t **p) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__all_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, uint8_t H5_ATTR_UNUSED flags, - const uint8_t H5_ATTR_UNUSED **p) +H5S__all_deserialize(H5S_t **space, const uint8_t **p) { + uint32_t version; /* Version number */ + H5S_t *tmp_space = NULL; /* Pointer to actual dataspace to use, + either *space or a newly allocated one */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_STATIC - HDassert(space); HDassert(p); HDassert(*p); + /* As part of the efforts to push all selection-type specific coding + to the callbacks, the coding for the allocation of a null dataspace + is moved from H5S_select_deserialize() in H5Sselect.c. + This is needed for decoding virtual layout in H5O__layout_decode() */ + + /* Allocate space if not provided */ + if(!*space) { + if(NULL == (tmp_space = H5S_create(H5S_SIMPLE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace") + } /* end if */ + else + tmp_space = *space; + + /* Decode version */ + UINT32DECODE(*p, version); + + /* Skip over the remainder of the header */ + *p += 8; + /* Change to "all" selection */ - if(H5S_select_all(space, TRUE) < 0) + if(H5S_select_all(tmp_space, TRUE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") + /* Return space to the caller if allocated */ + if(!*space) + *space = tmp_space; + done: + /* Free temporary space if not passed to caller (only happens on error) */ + if(!*space && tmp_space) + if(H5S_close(tmp_space) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__all_deserialize() */ diff --git a/src/H5Sdeprec.c b/src/H5Sdeprec.c new file mode 100644 index 0000000..e4ec1b0 --- /dev/null +++ b/src/H5Sdeprec.c @@ -0,0 +1,121 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*------------------------------------------------------------------------- + * + * Created: H5Sdeprec.c + * + * Purpose: Deprecated functions from the H5S interface. These + * functions are here for compatibility purposes and may be + * removed in the future. Applications should switch to the + * newer APIs. + * + *------------------------------------------------------------------------- + */ + +/****************/ +/* Module Setup */ +/****************/ + +#include "H5Smodule.h" /* This source code file is part of the H5S module */ + + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ +#include "H5Spkg.h" /* Dataspaces */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Iprivate.h" /* IDs */ + + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + +#ifndef H5_NO_DEPRECATED_SYMBOLS + +/*------------------------------------------------------------------------- + * Function: H5Sencode1 + * + * Purpose: Given a dataspace ID, converts the object description + * (including selection) into binary in a buffer. + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 14, 2004 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Sencode1(hid_t obj_id, void *buf, size_t *nalloc) +{ + H5S_t *dspace; + hid_t temp_fapl_id = H5P_DEFAULT; + herr_t ret_value=SUCCEED; + + FUNC_ENTER_API(FAIL) + H5TRACE3("e", "i*x*z", obj_id, buf, nalloc); + + /* Check argument and retrieve object */ + if (NULL == (dspace = (H5S_t *)H5I_object_verify(obj_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + + /* Verify access property list and set up collective metadata if appropriate */ + if(H5CX_set_apl(&temp_fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") + + /* Use (earliest, latest) i.e. not latest format */ + if(H5S_encode(dspace, (unsigned char **)&buf, nalloc)<0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode dataspace") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Sencode1() */ +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + diff --git a/src/H5Shyper.c b/src/H5Shyper.c index c9fab38..a6494d9 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -28,12 +28,14 @@ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* ID Functions */ -#include "H5Spkg.h" /* Dataspace functions */ -#include "H5VMprivate.h" /* Vector functions */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Spkg.h" /* Dataspace functions */ +#include "H5VMprivate.h" /* Vector functions */ /****************/ @@ -94,8 +96,7 @@ static herr_t H5S__hyper_release(H5S_t *space); static htri_t H5S__hyper_is_valid(const H5S_t *space); static hssize_t H5S__hyper_serial_size(const H5S_t *space); static herr_t H5S__hyper_serialize(const H5S_t *space, uint8_t **p); -static herr_t H5S__hyper_deserialize(H5S_t *space, uint32_t version, uint8_t flags, - const uint8_t **p); +static herr_t H5S__hyper_deserialize(H5S_t **space, const uint8_t **p); static herr_t H5S__hyper_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S__hyper_offset(const H5S_t *space, hsize_t *offset); static int H5S__hyper_unlim_dim(const H5S_t *space); @@ -157,6 +158,13 @@ const H5S_select_class_t H5S_sel_hyper[1] = {{ H5S__hyper_iter_init, }}; +/* Format version bounds for dataspace hyperslab selection */ +const unsigned H5O_sds_hyper_ver_bounds[] = { + H5S_HYPER_VERSION_1, /* H5F_LIBVER_EARLIEST */ + H5S_HYPER_VERSION_1, /* H5F_LIBVER_V18 */ + H5S_HYPER_VERSION_2, /* H5F_LIBVER_V110 */ + H5S_HYPER_VERSION_3 /* H5F_LIBVER_LATEST */ +}; /*******************/ /* Local Variables */ @@ -554,10 +562,10 @@ H5S__hyper_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords) HDassert(v < 0); } /* end if */ else - HDmemcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); + H5MM_memcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); } /* end if */ else - HDmemcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); + H5MM_memcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__hyper_iter_coords() */ @@ -3204,8 +3212,9 @@ H5S__hyper_span_nblocks(const H5S_hyper_span_info_t *spans) PURPOSE Get the number of hyperslab blocks in current hyperslab selection USAGE - hsize_t H5S__get_select_hyper_nblocks(space) + hsize_t H5S__get_select_hyper_nblocks(space, app_ref) H5S_t *space; IN: Dataspace ptr of selection to query + hbool_t app_ref; IN: Whether this is an appl. ref. call RETURNS The number of hyperslab blocks in selection on success, negative on failure DESCRIPTION @@ -3216,7 +3225,7 @@ H5S__hyper_span_nblocks(const H5S_hyper_span_info_t *spans) REVISION LOG --------------------------------------------------------------------------*/ static hsize_t -H5S__get_select_hyper_nblocks(const H5S_t *space) +H5S__get_select_hyper_nblocks(const H5S_t *space, hbool_t app_ref) { hsize_t ret_value = 0; /* Return value */ @@ -3231,7 +3240,8 @@ H5S__get_select_hyper_nblocks(const H5S_t *space) /* Check each dimension */ for(ret_value = 1, u = 0; u < space->extent.rank; u++) - ret_value *= space->select.sel_info.hslab->app_diminfo[u].count; + ret_value *= (app_ref ? space->select.sel_info.hslab->app_diminfo[u].count : + space->select.sel_info.hslab->opt_diminfo[u].count); } /* end if */ else ret_value = H5S__hyper_span_nblocks(space->select.sel_info.hslab->span_lst); @@ -3274,7 +3284,7 @@ H5Sget_select_hyper_nblocks(hid_t spaceid) if(space->select.sel_info.hslab->unlim_dim >= 0) HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "cannot get number of blocks for unlimited selection") - ret_value = (hssize_t)H5S__get_select_hyper_nblocks(space); + ret_value = (hssize_t)H5S__get_select_hyper_nblocks(space, TRUE); done: FUNC_LEAVE_API(ret_value) @@ -3283,6 +3293,210 @@ done: /*-------------------------------------------------------------------------- NAME + H5S__hyper_get_enc_size_real + PURPOSE + Determine the size to encode the hyperslab selection info + USAGE + hssize_t H5S__hyper_get_enc_size_real(max_size, enc_size) + hsize_t max_size: IN: The maximum size of the hyperslab selection info + unint8_t *enc_size: OUT:The encoding size + RETURNS + The size to encode hyperslab selection info + DESCRIPTION + Determine the size by comparing "max_size" with (2^32 - 1) and (2^16 - 1). + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static uint8_t +H5S__hyper_get_enc_size_real(hsize_t max_size) +{ + uint8_t ret_value = H5S_SELECT_INFO_ENC_SIZE_2; + + FUNC_ENTER_STATIC_NOERR + + if(max_size > H5S_UINT32_MAX) + ret_value = H5S_SELECT_INFO_ENC_SIZE_8; + else if(max_size > H5S_UINT16_MAX) + ret_value = H5S_SELECT_INFO_ENC_SIZE_4; + else + ret_value = H5S_SELECT_INFO_ENC_SIZE_2; + + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__hyper_get_enc_size_real() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_get_version_enc_size + PURPOSE + Determine the version and encoded size to use for encoding hyperslab selection info + USAGE + hssize_t H5S__hyper_get_version_enc_size(space, block_count, version, enc_size) + const H5S_t *space: IN: The dataspace + hsize_t block_count: IN: The number of blocks in the selection + uint32_t *version: OUT: The version to use for encoding + uint8_t *enc_size: OUT: The encoded size to use + + RETURNS + The version and the size to encode hyperslab selection info + DESCRIPTION + Determine the version to use for encoding hyperslab selection info based + on the following: + (1) the file format setting in fapl + (2) whether the number of blocks or selection high bounds exceeds H5S_UINT32_MAX or not + + Determine the encoded size based on version: + For version 3, the encoded size is determined according to: + (a) regular hyperslab + (1) The maximum needed to store start/stride/count/block + (2) Special handling for count/block: need to provide room for H5S_UNLIMITED + (b) irregular hyperslab + The maximum size needed to store: + (1) the number of blocks + (2) the selection high bounds + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__hyper_get_version_enc_size(const H5S_t *space, hsize_t block_count, uint32_t *version, uint8_t *enc_size) +{ + hsize_t bounds_start[H5S_MAX_RANK]; /* Starting coordinate of bounding box */ + hsize_t bounds_end[H5S_MAX_RANK]; /* Opposite coordinate of bounding box */ + hbool_t count_up_version = FALSE; /* Whether number of blocks exceed H5S_UINT32_MAX */ + hbool_t bound_up_version = FALSE; /* Whether high bounds exceed H5S_UINT32_MAX */ + H5F_libver_t low_bound; /* The 'low' bound of library format versions */ + H5F_libver_t high_bound; /* The 'high' bound of library format versions */ + htri_t is_regular; /* A regular hyperslab or not */ + uint32_t tmp_version; /* Local temporay version */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Get bounding box for the selection */ + HDmemset(bounds_end, 0, sizeof(bounds_end)); + + if(space->select.sel_info.hslab->unlim_dim < 0) { /* ! H5S_UNLIMITED */ + /* Get bounding box for the selection */ + if(H5S__hyper_bounds(space, bounds_start, bounds_end) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get selection bounds") + } + + /* Determine whether the number of blocks or the high bounds in the selection exceed (2^32 - 1) */ + if(block_count > H5S_UINT32_MAX) + count_up_version = TRUE; + else { + for(u = 0; u < space->extent.rank; u++) + if(bounds_end[u] > H5S_UINT32_MAX) { + bound_up_version = TRUE; + break; + } + } + + /* Get the file's low_bound and high_bound */ + if(H5CX_get_libver_bounds(&low_bound, &high_bound) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get low/high bounds from API context") + + /* Determine regular hyperslab */ + is_regular = H5S__hyper_is_regular(space); + + if(low_bound >= H5F_LIBVER_V112 || space->select.sel_info.hslab->unlim_dim >= 0) + tmp_version = MAX(H5S_HYPER_VERSION_2, H5O_sds_hyper_ver_bounds[low_bound]); + + else { + if(count_up_version || bound_up_version) + tmp_version = is_regular ? H5S_HYPER_VERSION_2 : H5S_HYPER_VERSION_3; + else + tmp_version = (is_regular && block_count >= 4) ? H5O_sds_hyper_ver_bounds[low_bound] : H5S_HYPER_VERSION_1; + + } + + /* Version bounds check */ + if(tmp_version > H5O_sds_hyper_ver_bounds[high_bound]) { + /* Fail for irregular hyperslab if exceeds 32 bits */ + if(count_up_version) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "The number of blocks in hyperslab selection exceeds 2^32") + else if(bound_up_version) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "The end of bounding box in hyperslab selection exceeds 2^32") + else + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "Dataspace hyperslab selection version out of bounds") + } + + /* Set the message version */ + *version = tmp_version; + + /* Determine the encoded size based on version */ + switch(tmp_version) { + case H5S_HYPER_VERSION_1: + *enc_size = H5S_SELECT_INFO_ENC_SIZE_4; + break; + + case H5S_HYPER_VERSION_2: + *enc_size = H5S_SELECT_INFO_ENC_SIZE_8; + break; + + case H5S_HYPER_VERSION_3: + if(is_regular) { + uint8_t enc1, enc2; + hsize_t max1 = 0; + hsize_t max2 = 0; + + /* Find max for count[] and block[] */ + for(u = 0; u < space->extent.rank; u++) { + if(space->select.sel_info.hslab->opt_diminfo[u].count != H5S_UNLIMITED && + space->select.sel_info.hslab->opt_diminfo[u].count > max1) + max1 = space->select.sel_info.hslab->opt_diminfo[u].count; + if(space->select.sel_info.hslab->opt_diminfo[u].block != H5S_UNLIMITED && + space->select.sel_info.hslab->opt_diminfo[u].block > max1) + max1 = space->select.sel_info.hslab->opt_diminfo[u].block; + } + + /* +1 to provide room for H5S_UNLIMITED */ + enc1 = H5S__hyper_get_enc_size_real(++max1); + + /* Find max for start[] and stride[] */ + for(u = 0; u < space->extent.rank; u++) { + if(space->select.sel_info.hslab->opt_diminfo[u].start > max2) + max2 = space->select.sel_info.hslab->opt_diminfo[u].start; + if(space->select.sel_info.hslab->opt_diminfo[u].stride > max2) + max2 = space->select.sel_info.hslab->opt_diminfo[u].stride; + } + + /* Determine the encoding size */ + enc2 = H5S__hyper_get_enc_size_real(max2); + + *enc_size = MAX(enc1, enc2); + } else { + hsize_t max_size = block_count; + HDassert(space->select.sel_info.hslab->unlim_dim < 0); + + /* Find max for block_count and bounds_end[] */ + for(u = 0; u < space->extent.rank; u++) + if(bounds_end[u] > max_size) + max_size = bounds_end[u]; + + /* Determine the encoding size */ + *enc_size = H5S__hyper_get_enc_size_real(max_size); + } + break; + + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown hyperslab selection version") + break; + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__hyper_get_version_enc_size() */ + + + +/*-------------------------------------------------------------------------- + NAME H5S__hyper_serial_size PURPOSE Determine the number of bytes needed to store the serialized hyperslab @@ -3303,49 +3517,73 @@ done: static hssize_t H5S__hyper_serial_size(const H5S_t *space) { - hsize_t block_count; /* block counter for regular hyperslabs */ - unsigned u; /* Counter */ - hssize_t ret_value = -1; /* return value */ + hsize_t block_count = 0; /* block counter for regular hyperslabs */ + uint32_t version; /* Version number */ + uint8_t enc_size; /* Encoded size of hyerslab selection info */ + hssize_t ret_value = -1; /* return value */ - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_STATIC HDassert(space); - /* Check for version (right now, an unlimited dimension is the only thing - * that would bump the version) */ - if(space->select.sel_info.hslab->unlim_dim >= 0) + if(space->select.sel_info.hslab->unlim_dim < 0) /* ! H5S_UNLIMITED */ + block_count = H5S__get_select_hyper_nblocks(space, FALSE); + + /* Determine the version and the encoded size */ + if(H5S__hyper_get_version_enc_size(space, block_count, &version, &enc_size) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't determine hyper version & enc_size") + + if(version == H5S_HYPER_VERSION_3) { + /* Version 3: regular */ + /* Size required is always: + * <type (4 bytes)> + <version (4 bytes)> + <flags (1 byte)> + + * <size of offset info (1 byte)> + <rank (4 bytes)> + + * (4 (start/stride/count/block) * <enc_size> * <rank>) = + * 14 + (4 * enc_size * rank) bytes + */ + if(H5S__hyper_is_regular(space)) + ret_value = (hssize_t)14 + + ((hssize_t)4 * (hssize_t)enc_size * (hssize_t)space->extent.rank); + else { + /* Version 3: irregular */ + /* Size required is always: + * <type (4 bytes)> + <version (4 bytes)> + <flags (1 byte)> + + * <size of offset info (1 byte)> + <rank (4 bytes)> + + * < # of blocks (depend on enc_size) > + + * (2 (starting/ending offset) * <rank> * <enc_size> * <# of blocks) = + * = 14 bytes + enc_size (block_count) + (2 * enc_size * rank * block_count) bytes + */ + ret_value = 14 + enc_size; + H5_CHECK_OVERFLOW(((unsigned)2 * enc_size * space->extent.rank * block_count), hsize_t, hssize_t); + ret_value += (hssize_t)((unsigned)2 * enc_size * space->extent.rank * block_count); + } + } else if(version == H5S_HYPER_VERSION_2) { /* Version 2 */ /* Size required is always: * <type (4 bytes)> + <version (4 bytes)> + <flags (1 byte)> + * <length (4 bytes)> + <rank (4 bytes)> + - * (4 (start/stride/count/block) * <rank> * <value (8 bytes)>) = - * 17 + (4 * rank * 8) bytes + * (4 (start/stride/count/block) * <enc_size (8 bytes)> * <rank>) = + * 17 + (4 * 8 * rank) bytes */ - ret_value = (hssize_t)17 + ((hssize_t)4 * (hssize_t)space->extent.rank - * (hssize_t)8); - else { + HDassert(enc_size == 8); + ret_value = (hssize_t)17 + ((hssize_t)4 * (hssize_t)8 * (hssize_t)space->extent.rank); + } else { + HDassert(version == H5S_HYPER_VERSION_1); + HDassert(enc_size == 4); /* Version 1 */ /* Basic number of bytes required to serialize hyperslab selection: * <type (4 bytes)> + <version (4 bytes)> + <padding (4 bytes)> + - * <length (4 bytes)> + <rank (4 bytes)> + <# of blocks (4 bytes)> - * = 24 bytes + * <length (4 bytes)> + <rank (4 bytes)> + <# of blocks (4 bytes)> + + * (2 (starting/ending offset) * <enc_size (4 bytes)> * <rank> * <# of blocks) = + * = 24 bytes + (2 * 4 * rank * block_count) */ ret_value = 24; - - /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab->diminfo_valid) { - /* Check each dimension */ - for(block_count = 1, u = 0; u < space->extent.rank; u++) - block_count *= space->select.sel_info.hslab->opt_diminfo[u].count; - } /* end if */ - else - /* Spin through hyperslab spans, adding 8 * rank bytes for each block */ - block_count = H5S__hyper_span_nblocks(space->select.sel_info.hslab->span_lst); - H5_CHECK_OVERFLOW((8 * space->extent.rank * block_count), hsize_t, hssize_t); - ret_value += (hssize_t)(8 * block_count * space->extent.rank); + ret_value += (hssize_t)(8 * space->extent.rank * block_count); } /* end else */ +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_serial_size() */ @@ -3356,12 +3594,13 @@ H5S__hyper_serial_size(const H5S_t *space) PURPOSE Serialize the current selection into a user-provided buffer. USAGE - void H5S__hyper_serialize_helper(spans, start, end, rank, buf) + void H5S__hyper_serialize_helper(spans, start, end, rank, enc_size, buf) H5S_hyper_span_info_t *spans; IN: Hyperslab span tree to serialize hssize_t start[]; IN/OUT: Accumulated start points hssize_t end[]; IN/OUT: Accumulated end points hsize_t rank; IN: Current rank looking at - uint8 *buf; OUT: Buffer to put serialized selection into + uint8_t enc_size IN: Encoded size of hyperslab selection info + uint8_t *buf; OUT: Buffer to put serialized selection into RETURNS None DESCRIPTION @@ -3374,7 +3613,7 @@ H5S__hyper_serial_size(const H5S_t *space) --------------------------------------------------------------------------*/ static void H5S__hyper_serialize_helper(const H5S_hyper_span_info_t *spans, - hsize_t *start, hsize_t *end, hsize_t rank, uint8_t **p) + hsize_t *start, hsize_t *end, hsize_t rank, uint8_t enc_size, uint8_t **p) { H5S_hyper_span_t *curr; /* Pointer to current hyperslab span */ uint8_t *pp = (*p); /* Local pointer for decoding */ @@ -3398,26 +3637,65 @@ H5S__hyper_serialize_helper(const H5S_hyper_span_info_t *spans, end[rank] = curr->high; /* Recurse down to the next dimension */ - H5S__hyper_serialize_helper(curr->down, start, end, rank + 1, &pp); + H5S__hyper_serialize_helper(curr->down, start, end, rank + 1, enc_size, &pp); } /* end if */ else { hsize_t u; /* Index variable */ /* Encode all the previous dimensions starting & ending points */ + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + /* Encode previous starting points */ + for(u=0; u<rank; u++) + UINT16ENCODE(pp, (uint16_t)start[u]); + + /* Encode starting point for this span */ + UINT16ENCODE(pp, (uint16_t)curr->low); - /* Encode previous starting points */ - for(u = 0; u < rank; u++) - UINT32ENCODE(pp, (uint32_t)start[u]); + /* Encode previous ending points */ + for(u=0; u<rank; u++) + UINT16ENCODE(pp, (uint16_t)end[u]); + + /* Encode starting point for this span */ + UINT16ENCODE(pp, (uint16_t)curr->high); + break; - /* Encode starting point for this span */ - UINT32ENCODE(pp, (uint32_t)curr->low); + case H5S_SELECT_INFO_ENC_SIZE_4: + /* Encode previous starting points */ + for(u=0; u<rank; u++) + UINT32ENCODE(pp, (uint32_t)start[u]); + + /* Encode starting point for this span */ + UINT32ENCODE(pp, (uint32_t)curr->low); + + /* Encode previous ending points */ + for(u=0; u<rank; u++) + UINT32ENCODE(pp, (uint32_t)end[u]); + + /* Encode starting point for this span */ + UINT32ENCODE(pp, (uint32_t)curr->high); + break; - /* Encode previous ending points */ - for(u = 0; u < rank; u++) - UINT32ENCODE(pp, (uint32_t)end[u]); + case H5S_SELECT_INFO_ENC_SIZE_8: + /* Encode previous starting points */ + for(u=0; u<rank; u++) + UINT64ENCODE(pp, (uint64_t)start[u]); - /* Encode starting point for this span */ - UINT32ENCODE(pp, (uint32_t)curr->high); + /* Encode starting point for this span */ + UINT64ENCODE(pp, (uint64_t)curr->low); + + /* Encode previous ending points */ + for(u=0; u<rank; u++) + UINT64ENCODE(pp, (uint64_t)end[u]); + + /* Encode starting point for this span */ + UINT64ENCODE(pp, (uint64_t)curr->high); + break; + + default: + HDassert(0 && "Unknown enc size?!?"); + + } /* end switch */ } /* end else */ /* Advance to next node */ @@ -3455,14 +3733,26 @@ H5S__hyper_serialize_helper(const H5S_hyper_span_info_t *spans, static herr_t H5S__hyper_serialize(const H5S_t *space, uint8_t **p) { - uint8_t *pp; /* Local pointer for decoding */ - uint8_t *lenp; /* Pointer to length location for later storage */ - uint32_t len = 0; /* Number of bytes used */ + const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ + hsize_t tmp_count[H5S_MAX_RANK]; /* Temporary hyperslab counts */ + hsize_t offset[H5S_MAX_RANK]; /* Offset of element in dataspace */ + hsize_t start[H5S_MAX_RANK]; /* Location of start of hyperslab */ + hsize_t end[H5S_MAX_RANK]; /* Location of end of hyperslab */ + uint8_t *pp; /* Local pointer for decoding */ + uint8_t *lenp = NULL; /* pointer to length location for later storage */ + uint32_t len = 0; /* number of bytes used */ uint32_t version; /* Version number */ uint8_t flags = 0; /* Flags for message */ - hsize_t block_count; /* Block counter for regular hyperslabs */ + hsize_t block_count = 0; /* block counter for regular hyperslabs */ + unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ + unsigned ndims; /* Rank of the dataspace */ + unsigned i, u; /* Local counting variable */ + hbool_t complete = FALSE; /* Whether we are done with the iteration */ + hbool_t is_regular; /* Whether selection is regular */ + uint8_t enc_size; + herr_t ret_value = SUCCEED; /* return value */ - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_STATIC /* Sanity checks */ HDassert(space); @@ -3470,162 +3760,243 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) pp = (*p); HDassert(pp); - /* Calculate version */ - if(space->select.sel_info.hslab->unlim_dim >= 0) { - version = 2; - flags |= H5S_SELECT_FLAG_UNLIM; - } /* end if */ - else - version = 1; + /* Set some convienence values */ + ndims = space->extent.rank; + diminfo = space->select.sel_info.hslab->opt_diminfo; + + if(space->select.sel_info.hslab->unlim_dim < 0) /* ! H5S_UNLIMITED */ + block_count = H5S__get_select_hyper_nblocks(space, FALSE); + + /* Determine the version and the encoded size */ + if(H5S__hyper_get_version_enc_size(space, block_count, &version, &enc_size) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't determine hyper version & enc_size") + + is_regular = H5S__hyper_is_regular(space); + if(is_regular && + (version == H5S_HYPER_VERSION_2 || version == H5S_HYPER_VERSION_3)) + flags |= H5S_HYPER_REGULAR; /* Store the preamble information */ UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ UINT32ENCODE(pp, version); /* Store the version number */ - if(version >= 2) - *(pp)++ = flags; /* Store the flags */ - else - UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */ - lenp = pp; /* keep the pointer to the length location for later */ - pp += 4; /* skip over space for length */ + + if(version >= 3) { + *(pp)++ = flags; /* Store the flags */ + *(pp)++ = enc_size; /* Store size of offset info */ + + } else { + if(version == 2) + *(pp)++ = flags; /* Store the flags */ + else + UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */ + lenp = pp; /* keep the pointer to the length location for later */ + pp += 4; /* skip over space for length */ + + len += 4; /* ndims */ + } /* Encode number of dimensions */ - UINT32ENCODE(pp, (uint32_t)space->extent.rank); - len += 4; + UINT32ENCODE(pp, (uint32_t)ndims); - /* If there is an unlimited dimension, only encode opt_unlim_diminfo */ - if(flags & H5S_SELECT_FLAG_UNLIM) { - unsigned i; + if(is_regular) { - HDassert(H5S_UNLIMITED == HSIZE_UNDEF); + if(version >= H5S_HYPER_VERSION_2) { + + HDassert(H5S_UNLIMITED == HSIZE_UNDEF); - /* Iterate over dimensions */ - for(i = 0; i < space->extent.rank; i++) { + /* Iterate over dimensions */ /* Encode start/stride/block/count */ - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].start); - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].stride); - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].count); - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].block); - } /* end for */ - } /* end if */ - /* Check for a "regular" hyperslab selection */ - else if(space->select.sel_info.hslab->diminfo_valid) { - const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ - hsize_t offset[H5S_MAX_RANK]; /* Offset of element in dataspace */ - hsize_t tmp_count[H5S_MAX_RANK]; /* Temporary hyperslab counts */ - unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ - unsigned ndims; /* Rank of the dataspace */ - unsigned u; /* Local counting variable */ - hbool_t done; /* Whether we are done with the iteration */ + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + HDassert(version == H5S_HYPER_VERSION_3); + for(i = 0; i < space->extent.rank; i++) { + UINT16ENCODE(pp, diminfo[i].start); + UINT16ENCODE(pp, diminfo[i].stride); + if(diminfo[i].count == H5S_UNLIMITED) { + UINT16ENCODE(pp, H5S_UINT16_MAX); + } else { + UINT16ENCODE(pp, diminfo[i].count); + } + + if(diminfo[i].block == H5S_UNLIMITED) { + UINT16ENCODE(pp, H5S_UINT16_MAX); + } else { + UINT16ENCODE(pp, diminfo[i].block); + } + } /* end for */ + break; - /* Set some convenience values */ - ndims = space->extent.rank; - fast_dim = ndims - 1; - diminfo = space->select.sel_info.hslab->opt_diminfo; + case H5S_SELECT_INFO_ENC_SIZE_4: + HDassert(version == H5S_HYPER_VERSION_3); + for(i = 0; i < space->extent.rank; i++) { + UINT32ENCODE(pp, diminfo[i].start); + UINT32ENCODE(pp, diminfo[i].stride); + if(diminfo[i].count == H5S_UNLIMITED) { + UINT32ENCODE(pp, H5S_UINT32_MAX); + } else { + UINT32ENCODE(pp, diminfo[i].count); + } + if(diminfo[i].block == H5S_UNLIMITED) { + UINT32ENCODE(pp, H5S_UINT32_MAX); + } else { + UINT32ENCODE(pp, diminfo[i].block); + } + } /* end for */ + break; - /* Check each dimension */ - for(block_count = 1, u = 0; u < ndims; u++) - block_count *= diminfo[u].count; + case H5S_SELECT_INFO_ENC_SIZE_8: + HDassert(version == H5S_HYPER_VERSION_2 || version == H5S_HYPER_VERSION_3); + for(i = 0; i < space->extent.rank; i++) { + UINT64ENCODE(pp, diminfo[i].start); + UINT64ENCODE(pp, diminfo[i].stride); + if(diminfo[i].count == H5S_UNLIMITED) { + UINT64ENCODE(pp, H5S_UINT64_MAX); + } else { + UINT64ENCODE(pp, diminfo[i].count); + } + if(diminfo[i].block == H5S_UNLIMITED) { + UINT64ENCODE(pp, H5S_UINT64_MAX); + } else { + UINT64ENCODE(pp, diminfo[i].block); + } + } /* end for */ + if(version == H5S_HYPER_VERSION_2) + len += (4 * space->extent.rank * 8); + break; + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown offset info size for hyperslab") + break; + } /* end switch */ - /* Encode number of hyperslabs */ - H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t); - UINT32ENCODE(pp, (uint32_t)block_count); - len += 4; + } else { - /* Now serialize the information for the regular hyperslab */ + HDassert(version == H5S_HYPER_VERSION_1); + + /* Set some convienence values */ + fast_dim = ndims - 1; - /* Build the tables of count sizes as well as the initial offset */ - for(u = 0; u < ndims; u++) { - tmp_count[u] = diminfo[u].count; - offset[u] = diminfo[u].start; - } /* end for */ + /* Encode number of hyperslabs */ + H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t); + UINT32ENCODE(pp, (uint32_t)block_count); + len += 4; - /* We're not done with the iteration */ - done = FALSE; + /* Now serialize the information for the regular hyperslab */ - /* Go iterate over the hyperslabs */ - while(done == FALSE) { - /* Iterate over the blocks in the fastest dimension */ - while(tmp_count[fast_dim] > 0) { - /* Add 8 bytes times the rank for each hyperslab selected */ - len += 8 * ndims; + /* Build the tables of count sizes as well as the initial offset */ + for(u = 0; u < ndims; u++) { + tmp_count[u] = diminfo[u].count; + offset[u] = diminfo[u].start; + } /* end for */ - /* Encode hyperslab starting location */ - for(u = 0; u < ndims; u++) - UINT32ENCODE(pp, (uint32_t)offset[u]); + /* Go iterate over the hyperslabs */ + while(complete == FALSE) { + /* Iterate over the blocks in the fastest dimension */ + while(tmp_count[fast_dim] > 0) { + /* Add 8 bytes times the rank for each hyperslab selected */ + len += 8 * ndims; - /* Encode hyperslab ending location */ - for(u = 0; u < ndims; u++) - UINT32ENCODE(pp, (uint32_t)(offset[u] + (diminfo[u].block - 1))); + /* Encode hyperslab starting location */ + for(u = 0; u < ndims; u++) + UINT32ENCODE(pp, (uint32_t)offset[u]); - /* Move the offset to the next sequence to start */ - offset[fast_dim]+=diminfo[fast_dim].stride; + /* Encode hyperslab ending location */ + for(u = 0; u < ndims; u++) + UINT32ENCODE(pp, (uint32_t)(offset[u] + (diminfo[u].block - 1))); - /* Decrement the block count */ - tmp_count[fast_dim]--; - } /* end while */ + /* Move the offset to the next sequence to start */ + offset[fast_dim]+=diminfo[fast_dim].stride; + + /* Decrement the block count */ + tmp_count[fast_dim]--; + } /* end while */ - /* Work on other dimensions if necessary */ - if(fast_dim > 0) { - int temp_dim; /* Temporary rank holder */ + /* Work on other dimensions if necessary */ + if(fast_dim > 0) { + int temp_dim; /* Temporary rank holder */ - /* Reset the block counts */ - tmp_count[fast_dim] = diminfo[fast_dim].count; + /* Reset the block counts */ + tmp_count[fast_dim] = diminfo[fast_dim].count; - /* Bubble up the decrement to the slower changing dimensions */ - temp_dim = (int)fast_dim - 1; - while(temp_dim >= 0 && done == FALSE) { - /* Decrement the block count */ - tmp_count[temp_dim]--; + /* Bubble up the decrement to the slower changing dimensions */ + temp_dim = (int)fast_dim - 1; + while(temp_dim >= 0 && complete == FALSE) { + /* Decrement the block count */ + tmp_count[temp_dim]--; - /* Check if we have more blocks left */ - if(tmp_count[temp_dim] > 0) - break; + /* Check if we have more blocks left */ + if(tmp_count[temp_dim] > 0) + break; - /* Check for getting out of iterator */ - if(temp_dim == 0) - done = TRUE; + /* Check for getting out of iterator */ + if(temp_dim == 0) + complete = TRUE; - /* Reset the block count in this dimension */ - tmp_count[temp_dim] = diminfo[temp_dim].count; + /* Reset the block count in this dimension */ + tmp_count[temp_dim] = diminfo[temp_dim].count; - /* Wrapped a dimension, go up to next dimension */ - temp_dim--; - } /* end while */ - } /* end if */ - else - break; /* Break out now, for 1-D selections */ + /* Wrapped a dimension, go up to next dimension */ + temp_dim--; + } /* end while */ + } /* end if */ + else + break; /* Break out now, for 1-D selections */ - /* Re-compute offset array */ - for(u = 0; u < ndims; u++) - offset[u] = diminfo[u].start + diminfo[u].stride * (diminfo[u].count - tmp_count[u]); - } /* end while */ - } /* end if */ - else { - hsize_t start[H5S_MAX_RANK]; /* Location of start of hyperslab */ - hsize_t end[H5S_MAX_RANK]; /* Location of end of hyperslab */ + /* Re-compute offset array */ + for(u = 0; u < ndims; u++) + offset[u] = diminfo[u].start + diminfo[u].stride * (diminfo[u].count - tmp_count[u]); + } /* end while */ + + } /* end else */ + + } else { /* irregular */ /* Encode number of hyperslabs */ - block_count = H5S__hyper_span_nblocks(space->select.sel_info.hslab->span_lst); - H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t); - UINT32ENCODE(pp, (uint32_t)block_count); - len += 4; + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + HDassert(version == H5S_HYPER_VERSION_3); + H5_CHECK_OVERFLOW(block_count, hsize_t, uint16_t); + UINT16ENCODE(pp, (uint16_t)block_count); + break; - /* Add 8 bytes times the rank for each hyperslab selected */ - H5_CHECK_OVERFLOW((8 * space->extent.rank * block_count), hsize_t, size_t); - len += (uint32_t)(8 * space->extent.rank * block_count); + case H5S_SELECT_INFO_ENC_SIZE_4: + HDassert(version == H5S_HYPER_VERSION_1 || version == H5S_HYPER_VERSION_3); + H5_CHECK_OVERFLOW(block_count, hsize_t, uint32_t); + UINT32ENCODE(pp, (uint32_t)block_count); + break; - /* Encode each hyperslab in selection */ - H5S__hyper_serialize_helper(space->select.sel_info.hslab->span_lst, start, end, (hsize_t)0, &pp); - } /* end else */ + case H5S_SELECT_INFO_ENC_SIZE_8: + HDassert(version == H5S_HYPER_VERSION_3); + UINT64ENCODE(pp, block_count); + break; + + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown offset info size for hyperslab") + break; + } /* end switch */ + + if(version == H5S_HYPER_VERSION_1) { + len+=4; /* block_count */ + + /* Add 8 bytes times the rank for each hyperslab selected */ + H5_CHECK_OVERFLOW((8 * ndims * block_count), hsize_t, size_t); + len += (uint32_t)(8 * ndims * block_count); + } + + H5S__hyper_serialize_helper(space->select.sel_info.hslab->span_lst, start, end, (hsize_t)0, enc_size, &pp); + + } /* Encode length */ - UINT32ENCODE(lenp, (uint32_t)len); /* Store the length of the extra information */ + if(version <= H5S_HYPER_VERSION_2) + UINT32ENCODE(lenp, (uint32_t)len); /* Store the length of the extra information */ /* Update encoding pointer */ *p = pp; - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__hyper_serialize() */ +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__hyper_serialize() */ + /*-------------------------------------------------------------------------- @@ -3635,10 +4006,8 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) Deserialize the current selection from a user-provided buffer. USAGE herr_t H5S__hyper_deserialize(space, p) - H5S_t *space; IN/OUT: Dataspace pointer to place + H5S_t **space; IN/OUT: Dataspace pointer to place selection into - uint32_t version IN: Selection version - uint8_t flags IN: Selection flags uint8 **p; OUT: Pointer to buffer holding serialized selection. Will be advanced to end of serialized selection. @@ -3653,82 +4022,216 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__hyper_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, uint8_t flags, - const uint8_t **p) +H5S__hyper_deserialize(H5S_t **space, const uint8_t **p) { - unsigned rank; /* Rank of points */ - const uint8_t *pp; /* Local pointer for decoding */ - hsize_t start[H5S_MAX_RANK]; /* Hyperslab start information */ - hsize_t block[H5S_MAX_RANK]; /* Hyperslab block information */ - unsigned u; /* Local counting variable */ - herr_t ret_value = FAIL; /* Return value */ + H5S_t *tmp_space = NULL; /* Pointer to actual dataspace to use, + either *space or a newly allocated one */ + hsize_t dims[H5S_MAX_RANK]; /* Dimenion sizes */ + hsize_t start[H5S_MAX_RANK]; /* hyperslab start information */ + hsize_t block[H5S_MAX_RANK]; /* hyperslab block information */ + uint32_t version; /* Version number */ + uint8_t flags = 0; /* Flags */ + uint8_t enc_size = 0; /* Encoded size of selection info */ + unsigned rank; /* rank of points */ + const uint8_t *pp; /* Local pointer for decoding */ + unsigned u; /* Local counting variable */ + herr_t ret_value=FAIL; /* return value */ FUNC_ENTER_STATIC /* Check args */ - HDassert(space); HDassert(p); pp = (*p); HDassert(pp); - /* Deserialize slabs to select */ - /* (The header and rank have already beed decoded) */ - rank = space->extent.rank; /* Retrieve rank from space */ + /* As part of the efforts to push all selection-type specific coding + to the callbacks, the coding for the allocation of a null dataspace + is moved from H5S_select_deserialize() in H5Sselect.c to here. + This is needed for decoding virtual layout in H5O__layout_decode() */ + /* Allocate space if not provided */ + if(!*space) { + if(NULL == (tmp_space = H5S_create(H5S_SIMPLE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace") + } /* end if */ + else + tmp_space = *space; + + /* Decode version */ + UINT32DECODE(pp, version); + + if(version >= (uint32_t)H5S_HYPER_VERSION_2) { + /* Decode flags */ + flags = *(pp)++; + + if(version >= (uint32_t)H5S_HYPER_VERSION_3) + /* decode size of offset info */ + enc_size = *(pp)++; + else { + /* Skip over the remainder of the header */ + pp += 4; + enc_size = H5S_SELECT_INFO_ENC_SIZE_8; + } + + /* Check for unknown flags */ + if(flags & ~H5S_SELECT_FLAG_BITS) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTLOAD, FAIL, "unknown flag for selection") + } else { + /* Skip over the remainder of the header */ + pp += 8; + enc_size = H5S_SELECT_INFO_ENC_SIZE_4; + } + + /* Check encoded */ + if(enc_size & ~H5S_SELECT_INFO_ENC_SIZE_BITS) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTLOAD, FAIL, "unknown size of point/offset info for selection") + + /* Decode the rank of the point selection */ + UINT32DECODE(pp,rank); + + if(!*space) { + /* Patch the rank of the allocated dataspace */ + (void)HDmemset(dims, 0, (size_t)rank * sizeof(dims[0])); + if(H5S_set_extent_simple(tmp_space, rank, dims, NULL) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't set dimensions") + } /* end if */ + else + /* Verify the rank of the provided dataspace */ + if(rank != tmp_space->extent.rank) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "rank of serialized selection does not match dataspace") - /* If there is an unlimited dimension, only encode opt_unlim_diminfo */ - if(flags & H5S_SELECT_FLAG_UNLIM) { + if(flags & H5S_HYPER_REGULAR) { hsize_t stride[H5S_MAX_RANK]; /* Hyperslab stride information */ - hsize_t count[H5S_MAX_RANK]; /* Hyperslab count information */ + hsize_t count[H5S_MAX_RANK]; /* Hyperslab count information */ /* Sanity checks */ HDassert(H5S_UNLIMITED == HSIZE_UNDEF); HDassert(version >= 2); - /* Iterate over dimensions */ - for(u = 0; u < rank; u++) { - /* Decode start/stride/block/count */ - UINT64DECODE(pp, start[u]); - UINT64DECODE(pp, stride[u]); - UINT64DECODE(pp, count[u]); - UINT64DECODE(pp, block[u]); - } /* end for */ + /* Decode start/stride/block/count */ + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + for(u = 0; u < tmp_space->extent.rank; u++) { + UINT16DECODE(pp, start[u]); + UINT16DECODE(pp, stride[u]); + + UINT16DECODE(pp, count[u]); + if((uint16_t)count[u] == H5S_UINT16_MAX) + count[u] = H5S_UNLIMITED; + + UINT16DECODE(pp, block[u]); + if((uint16_t)block[u] == H5S_UINT16_MAX) + block[u] = H5S_UNLIMITED; + } /* end for */ + break; + + case H5S_SELECT_INFO_ENC_SIZE_4: + for(u = 0; u < tmp_space->extent.rank; u++) { + UINT32DECODE(pp, start[u]); + UINT32DECODE(pp, stride[u]); + + UINT32DECODE(pp, count[u]); + if((uint32_t)count[u] == H5S_UINT32_MAX) + count[u] = H5S_UNLIMITED; + + UINT32DECODE(pp, block[u]); + if((uint32_t)block[u] == H5S_UINT32_MAX) + block[u] = H5S_UNLIMITED; + } /* end for */ + break; + + case H5S_SELECT_INFO_ENC_SIZE_8: + for(u = 0; u < tmp_space->extent.rank; u++) { + UINT64DECODE(pp, start[u]); + UINT64DECODE(pp, stride[u]); + UINT64DECODE(pp, count[u]); + if((uint64_t)count[u] == H5S_UINT64_MAX) + count[u] = H5S_UNLIMITED; + + UINT64DECODE(pp, block[u]); + if((uint64_t)block[u] == H5S_UINT64_MAX) + block[u] = H5S_UNLIMITED; + } /* end for */ + break; + + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown offset info size for hyperslab") + break; + } /* end switch */ + /* Select the hyperslab to the current selection */ - if((ret_value = H5S_select_hyperslab(space, H5S_SELECT_SET, start, stride, count, block)) < 0) + if((ret_value = H5S_select_hyperslab(tmp_space, H5S_SELECT_SET, start, stride, count, block)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't change selection") } /* end if */ else { const hsize_t *stride; /* Hyperslab stride information */ const hsize_t *count; /* Hyperslab count information */ - hsize_t end[H5S_MAX_RANK]; /* Hyperslab end information */ - hsize_t *tstart; /* Temporary hyperslab pointers */ - hsize_t *tend; /* Temporary hyperslab pointers */ - hsize_t *tblock; /* Temporary hyperslab pointers */ - size_t block_count; /* Number of blocks in selection */ - unsigned v; /* Local counting variable */ + hsize_t end[H5S_MAX_RANK]; /* Hyperslab end information */ + hsize_t *tstart; /* Temporary hyperslab pointers */ + hsize_t *tend; /* Temporary hyperslab pointers */ + hsize_t *tblock; /* Temporary hyperslab pointers */ + size_t num_elem; /* Number of elements in selection */ + unsigned v; /* Local counting variable */ + + /* decode the number of blocks */ + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + UINT16DECODE(pp, num_elem); + break; + + case H5S_SELECT_INFO_ENC_SIZE_4: + UINT32DECODE(pp, num_elem); + break; + + case H5S_SELECT_INFO_ENC_SIZE_8: + UINT64DECODE(pp, num_elem); + break; - /* Decode the number of blocks */ - UINT32DECODE(pp, block_count); + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown offset info size for hyperslab") + break; + } /* Set the count & stride for all blocks */ stride = count = H5S_hyper_ones_g; /* Retrieve the coordinates from the buffer */ - for(u = 0; u < block_count; u++) { - /* Decode the starting points */ - for(tstart = start, v = 0; v < rank; v++, tstart++) - UINT32DECODE(pp, *tstart); + for(u = 0; u < num_elem; u++) { + + /* Decode the starting and ending points */ + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + for(tstart = start, v = 0; v < rank; v++, tstart++) + UINT16DECODE(pp, *tstart); + for(tend = end, v = 0; v < rank; v++, tend++) + UINT16DECODE(pp, *tend); + break; - /* Decode the ending points */ - for(tend = end, v = 0; v < rank; v++, tend++) - UINT32DECODE(pp, *tend); + case H5S_SELECT_INFO_ENC_SIZE_4: + for(tstart = start,v = 0; v < rank; v++, tstart++) + UINT32DECODE(pp, *tstart); + for(tend = end, v = 0; v < rank; v++, tend++) + UINT32DECODE(pp, *tend); + break; + + case H5S_SELECT_INFO_ENC_SIZE_8: + for(tstart = start, v = 0; v < rank; v++, tstart++) + UINT64DECODE(pp, *tstart); + for(tend = end, v = 0; v < rank; v++, tend++) + UINT64DECODE(pp, *tend); + break; + + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown offset info size for hyperslab") + break; + } /* Change the ending points into blocks */ for(tblock = block, tstart = start, tend = end, v = 0; v < rank; v++, tstart++, tend++, tblock++) *tblock = (*tend - *tstart) + 1; /* Select or add the hyperslab to the current selection */ - if((ret_value = H5S_select_hyperslab(space, (u == 0 ? H5S_SELECT_SET : H5S_SELECT_OR), start, stride, count, block)) < 0) + if((ret_value = H5S_select_hyperslab(tmp_space, (u == 0 ? H5S_SELECT_SET : H5S_SELECT_OR), start, stride, count, block)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't change selection") } /* end for */ } /* end else */ @@ -3736,7 +4239,16 @@ H5S__hyper_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, uint8_t fl /* Update decoding pointer */ *p = pp; + /* Return space to the caller if allocated */ + if(!*space) + *space = tmp_space; + done: + /* Free temporary space if not passed to caller (only happens on error) */ + if(!*space && tmp_space) + if(H5S_close(tmp_space) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_deserialize() */ @@ -3819,18 +4331,18 @@ H5S__hyper_span_blocklist(const H5S_hyper_span_info_t *spans, hsize_t start[], /* Copy previous starting points */ for(u = 0; u < rank; u++, (*buf)++) - HDmemcpy(*buf, &start[u], sizeof(hsize_t)); + H5MM_memcpy(*buf, &start[u], sizeof(hsize_t)); /* Copy starting point for this span */ - HDmemcpy(*buf, &curr->low, sizeof(hsize_t)); + H5MM_memcpy(*buf, &curr->low, sizeof(hsize_t)); (*buf)++; /* Copy previous ending points */ for(u = 0; u < rank; u++, (*buf)++) - HDmemcpy(*buf, &end[u], sizeof(hsize_t)); + H5MM_memcpy(*buf, &end[u], sizeof(hsize_t)); /* Copy starting point for this span */ - HDmemcpy(*buf, &curr->high, sizeof(hsize_t)); + H5MM_memcpy(*buf, &curr->high, sizeof(hsize_t)); (*buf)++; /* Decrement the number of blocks processed */ @@ -3943,11 +4455,11 @@ H5S__get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startblo /* Check if we should copy this block information */ if(startblock == 0) { /* Copy the starting location */ - HDmemcpy(buf, offset, sizeof(hsize_t) * ndims); + H5MM_memcpy(buf, offset, sizeof(hsize_t) * ndims); buf += ndims; /* Compute the ending location */ - HDmemcpy(buf, offset, sizeof(hsize_t) * ndims); + H5MM_memcpy(buf, offset, sizeof(hsize_t) * ndims); for(u = 0; u < ndims; u++) buf[u] += (diminfo[u].block - 1); buf += ndims; @@ -6029,7 +6541,7 @@ H5S_hyper_denormalize_offset(H5S_t *space, const hssize_t *old_offset) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't adjust selection") /* Copy the selection offset over */ - HDmemcpy(space->select.offset, old_offset, sizeof(hssize_t) * space->extent.rank); + H5MM_memcpy(space->select.offset, old_offset, sizeof(hssize_t) * space->extent.rank); done: FUNC_LEAVE_NOAPI(ret_value) @@ -7255,7 +7767,7 @@ H5S__hyper_rebuild_helper(const H5S_hyper_span_t *span, H5S_hyper_dim_t span_sla if(!H5S__hyper_rebuild_helper(span->down->head, span_slab_info, rank - 1)) HGOTO_DONE(FALSE) - HDmemcpy(canon_down_span_slab_info, span_slab_info, sizeof(H5S_hyper_dim_t) * rank); + H5MM_memcpy(canon_down_span_slab_info, span_slab_info, sizeof(H5S_hyper_dim_t) * rank); } /* end if */ /* Assign the initial starting point & block size */ diff --git a/src/H5Snone.c b/src/H5Snone.c index 86994dd..6219bb1 100644 --- a/src/H5Snone.c +++ b/src/H5Snone.c @@ -58,8 +58,7 @@ static herr_t H5S__none_release(H5S_t *space); static htri_t H5S__none_is_valid(const H5S_t *space); static hssize_t H5S__none_serial_size(const H5S_t *space); static herr_t H5S__none_serialize(const H5S_t *space, uint8_t **p); -static herr_t H5S__none_deserialize(H5S_t *space, uint32_t version, uint8_t flags, - const uint8_t **p); +static herr_t H5S__none_deserialize(H5S_t **space, const uint8_t **p); static herr_t H5S__none_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S__none_offset(const H5S_t *space, hsize_t *off); static int H5S__none_unlim_dim(const H5S_t *space); @@ -584,7 +583,7 @@ H5S__none_serialize(const H5S_t *space, uint8_t **p) /* Store the preamble information */ UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(pp, (uint32_t)1); /* Store the version number */ + UINT32ENCODE(pp, (uint32_t)H5S_NONE_VERSION_1); /* Store the version number */ UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */ UINT32ENCODE(pp, (uint32_t)0); /* Store the additional information length */ @@ -602,10 +601,8 @@ H5S__none_serialize(const H5S_t *space, uint8_t **p) Deserialize the current selection from a user-provided buffer. USAGE herr_t H5S__none_deserialize(space, version, flags, p) - H5S_t *space; IN/OUT: Dataspace pointer to place + H5S_t **space; IN/OUT: Dataspace pointer to place selection into - uint32_t version IN: Selection version - uint8_t flags IN: Selection flags uint8 **p; OUT: Pointer to buffer holding serialized selection. Will be advanced to end of serialized selection. @@ -620,22 +617,50 @@ H5S__none_serialize(const H5S_t *space, uint8_t **p) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__none_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, - uint8_t H5_ATTR_UNUSED flags, const uint8_t H5_ATTR_UNUSED **p) +H5S__none_deserialize(H5S_t **space, const uint8_t **p) { - herr_t ret_value = SUCCEED; /* return value */ + H5S_t *tmp_space = NULL; /* Pointer to actual dataspace to use, + either *space or a newly allocated one */ + uint32_t version; /* Version number */ + herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_STATIC - HDassert(space); HDassert(p); HDassert(*p); + /* As part of the efforts to push all selection-type specific coding + to the callbacks, the coding for the allocation of a null dataspace + is moved from H5S_select_deserialize() in H5Sselect.c to here. + This is needed for decoding virtual layout in H5O__layout_decode() */ + /* Allocate space if not provided */ + if(!*space) { + if(NULL == (tmp_space = H5S_create(H5S_SIMPLE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace") + } /* end if */ + else + tmp_space = *space; + + /* Decode version */ + UINT32DECODE(*p, version); + + /* Skip over the remainder of the header */ + *p += 8; + /* Change to "none" selection */ - if(H5S_select_none(space) < 0) + if(H5S_select_none(tmp_space) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") + /* Return space to the caller if allocated */ + if(!*space) + *space = tmp_space; + done: + /* Free temporary space if not passed to caller (only happens on error) */ + if(!*space && tmp_space) + if(H5S_close(tmp_space) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__none_deserialize() */ diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 0575f03..56b1f30 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -37,8 +37,35 @@ #define H5S_VALID_PERM 0x02 /* Flags for serialization of selections */ -#define H5S_SELECT_FLAG_UNLIM 0x01 -#define H5S_SELECT_FLAG_BITS (H5S_SELECT_FLAG_UNLIM) +#define H5S_HYPER_REGULAR 0x01 +#define H5S_SELECT_FLAG_BITS (H5S_HYPER_REGULAR) + +/* Versions for H5S_SEL_HYPER selection info */ +#define H5S_HYPER_VERSION_1 1 +#define H5S_HYPER_VERSION_2 2 +#define H5S_HYPER_VERSION_3 3 + +/* Versions for H5S_SEL_POINTS selection info */ +#define H5S_POINT_VERSION_1 1 +#define H5S_POINT_VERSION_2 2 + +/* Versions for H5S_SEL_NONE selection info */ +#define H5S_NONE_VERSION_1 1 + +/* Versions for H5S_SEL_ALL selection info */ +#define H5S_ALL_VERSION_1 1 + +/* Encoded size of selection info for H5S_SEL_POINTS/H5S_SEL_HYPER */ +#define H5S_SELECT_INFO_ENC_SIZE_2 0x02 /* 2 bytes: 16 bits */ +#define H5S_SELECT_INFO_ENC_SIZE_4 0x04 /* 4 bytes: 32 bits */ +#define H5S_SELECT_INFO_ENC_SIZE_8 0x08 /* 8 bytes: 64 bits */ +#define H5S_SELECT_INFO_ENC_SIZE_BITS ( H5S_SELECT_INFO_ENC_SIZE_2 | \ + H5S_SELECT_INFO_ENC_SIZE_4 | \ + H5S_SELECT_INFO_ENC_SIZE_8 ) + +#define H5S_UINT16_MAX 0x0000FFFF /* 2^16 - 1 = 65,535 */ +#define H5S_UINT32_MAX 0xFFFFFFFF /* 2^32 - 1 = 4,294,967,295 */ +#define H5S_UINT64_MAX ((hsize_t)(-1L)) /* 2^64 - 1 = 18,446,744,073,709,551,615 */ /* Length of stack-allocated sequences for "project intersect" routines */ #define H5S_PROJECT_INTERSECT_NSEQS 256 @@ -148,8 +175,7 @@ typedef hssize_t (*H5S_sel_serial_size_func_t)(const H5S_t *space); /* Method to store current selection in "serialized" form (a byte sequence suitable for storing on disk) */ typedef herr_t (*H5S_sel_serialize_func_t)(const H5S_t *space, uint8_t **p); /* Method to create selection from "serialized" form (a byte sequence suitable for storing on disk) */ -typedef herr_t (*H5S_sel_deserialize_func_t)(H5S_t *space, uint32_t version, uint8_t flags, - const uint8_t **p); +typedef herr_t (*H5S_sel_deserialize_func_t)(H5S_t **space, const uint8_t **p); /* Method to determine smallest n-D bounding box containing the current selection */ typedef herr_t (*H5S_sel_bounds_func_t)(const H5S_t *space, hsize_t *start, hsize_t *end); /* Method to determine linear offset of initial element in selection within dataspace */ diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 6411b94..0bdabb4 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -28,13 +28,14 @@ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free Lists */ -#include "H5Iprivate.h" /* ID Functions */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Spkg.h" /* Dataspace functions */ -#include "H5VMprivate.h" /* Vector functions */ +#include "H5Iprivate.h" /* ID Functions */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Spkg.h" /* Dataspace functions */ +#include "H5VMprivate.h" /* Vector functions */ /****************/ @@ -60,8 +61,7 @@ static herr_t H5S__point_release(H5S_t *space); static htri_t H5S__point_is_valid(const H5S_t *space); static hssize_t H5S__point_serial_size(const H5S_t *space); static herr_t H5S__point_serialize(const H5S_t *space, uint8_t **p); -static herr_t H5S__point_deserialize(H5S_t *space, uint32_t version, uint8_t flags, - const uint8_t **p); +static herr_t H5S__point_deserialize(H5S_t **space, const uint8_t **p); static herr_t H5S__point_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); static herr_t H5S__point_offset(const H5S_t *space, hsize_t *off); static int H5S__point_unlim_dim(const H5S_t *space); @@ -73,6 +73,8 @@ static herr_t H5S__point_project_scalar(const H5S_t *space, hsize_t *offset); static herr_t H5S__point_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset); static herr_t H5S__point_iter_init(H5S_sel_iter_t *iter, const H5S_t *space); +static herr_t + H5S__point_get_version_enc_size(const H5S_t *space, uint32_t *version, uint8_t *enc_size); /* Selection iteration callbacks */ static herr_t H5S__point_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords); @@ -119,6 +121,13 @@ const H5S_select_class_t H5S_sel_point[1] = {{ H5S__point_iter_init, }}; +/* Format version bounds for dataspace hyperslab selection */ +const unsigned H5O_sds_point_ver_bounds[] = { + H5S_POINT_VERSION_1, /* H5F_LIBVER_EARLIEST */ + H5S_POINT_VERSION_1, /* H5F_LIBVER_V18 */ + H5S_POINT_VERSION_1, /* H5F_LIBVER_V110 */ + H5S_POINT_VERSION_2 /* H5F_LIBVER_LATEST */ +}; /*******************/ /* Local Variables */ @@ -203,7 +212,7 @@ H5S__point_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords) HDassert(coords); /* Copy the offset of the current point */ - HDmemcpy(coords, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); + H5MM_memcpy(coords, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__point_iter_coords() */ @@ -233,8 +242,8 @@ H5S__point_iter_block(const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end) HDassert(end); /* Copy the current point as a block */ - HDmemcpy(start, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); - HDmemcpy(end, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); + H5MM_memcpy(start, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); + H5MM_memcpy(end, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__point_iter_block() */ @@ -581,7 +590,7 @@ H5S__point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *c HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate coordinate information") /* Copy over the coordinates */ - HDmemcpy(new_node->pnt, coord + (u * space->extent.rank), (space->extent.rank * sizeof(hsize_t))); + H5MM_memcpy(new_node->pnt, coord + (u * space->extent.rank), (space->extent.rank * sizeof(hsize_t))); /* Link into list */ if(top == NULL) @@ -799,7 +808,7 @@ H5S__point_copy(H5S_t *dst, const H5S_t *src, hbool_t H5_ATTR_UNUSED share_selec } /* end if */ /* Copy over the point's coordinates */ - HDmemcpy(new_node->pnt, curr->pnt, (src->extent.rank * sizeof(hsize_t))); + H5MM_memcpy(new_node->pnt, curr->pnt, (src->extent.rank * sizeof(hsize_t))); /* Keep the order the same when copying */ if(NULL == new_tail) @@ -920,6 +929,124 @@ done: FUNC_LEAVE_API(ret_value) } /* end H5Sget_select_elem_npoints() */ +/*-------------------------------------------------------------------------- + NAME + H5S__point_get_version_enc_size + PURPOSE + Determine the version and the size (2, 4 or 8 bytes) to encode point selection info + USAGE + hssize_t H5S__point_set_enc_size(space, version, enc_size) + const H5S_t *space: IN: Dataspace ID of selection to query + uint32_t *version: OUT: The version to use for encoding + uint8_t *enc_size: OUT: The size to use for encoding + RETURNS + The version and the size to encode point selection info + DESCRIPTION + Determine the version to use for encoding points selection info based + on the following: + (1) the low/high bounds setting in fapl + (2) whether the number of points or selection high bounds exceeds H5S_UINT32_MAX or not + + Determine the encoded size based on version: + --For version 2, the encoded size of point selection info is determined + by the maximum size for: + (a) storing the number of points + (b) storing the selection high bounds + + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__point_get_version_enc_size(const H5S_t *space, uint32_t *version, uint8_t *enc_size) +{ + hbool_t count_up_version = FALSE; /* Whether number of points exceed H5S_UINT32_MAX */ + hbool_t bound_up_version = FALSE; /* Whether high bounds exceed H5S_UINT32_MAX */ + H5F_libver_t low_bound; /* The 'low' bound of library format versions */ + H5F_libver_t high_bound; /* The 'high' bound of library format versions */ + uint32_t tmp_version; /* Local temporary version */ + hsize_t bounds_start[H5S_MAX_RANK]; /* Starting coordinate of bounding box */ + hsize_t bounds_end[H5S_MAX_RANK]; /* Opposite coordinate of bounding box */ + hsize_t max_size = 0; /* Maximum selection size */ + unsigned u; /* Local index veriable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Get bounding box for the selection */ + HDmemset(bounds_end, 0, sizeof(bounds_end)); + if(H5S__point_bounds(space, bounds_start, bounds_end) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get selection bounds") + + /* Determine whether number of points or high bounds exceeds (2^32 - 1) */ + if(space->select.num_elem > H5S_UINT32_MAX) + count_up_version = TRUE; + else { + for(u = 0; u < space->extent.rank; u++) + if(bounds_end[u] > H5S_UINT32_MAX) { + bound_up_version = TRUE; + break; + } + } + + /* If exceed (2^32 -1) */ + if(count_up_version || bound_up_version) + tmp_version = H5S_POINT_VERSION_2; + else + tmp_version = H5S_POINT_VERSION_1; + + /* Get the file's low/high bounds */ + if(H5CX_get_libver_bounds(&low_bound, &high_bound) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get low/high bounds from API context") + + /* Upgrade to the version indicated by the file's low bound if higher */ + tmp_version = MAX(tmp_version, H5O_sds_point_ver_bounds[low_bound]); + + /* Version bounds check */ + if(tmp_version > H5O_sds_point_ver_bounds[high_bound]) { + if(count_up_version) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "The number of points in point selection exceeds 2^32") + else if(bound_up_version) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "The end of bounding box in point selection exceeds 2^32") + else + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "Dataspace point selection version out of bounds") + } + + /* Set the version to return */ + *version = tmp_version; + + /* Get the encoded size use based on version */ + switch(tmp_version) { + case H5S_POINT_VERSION_1: + *enc_size = H5S_SELECT_INFO_ENC_SIZE_4; + break; + + case H5S_POINT_VERSION_2: + /* Find max for num_elem and bounds_end[] */ + max_size = space->select.num_elem; + for(u = 0; u < space->extent.rank; u++) + if(bounds_end[u] > max_size) + max_size = bounds_end[u]; + + /* Determine the encoding size */ + if(max_size > H5S_UINT32_MAX) + *enc_size = H5S_SELECT_INFO_ENC_SIZE_8; + else if(max_size > H5S_UINT16_MAX) + *enc_size = H5S_SELECT_INFO_ENC_SIZE_4; + else + *enc_size = H5S_SELECT_INFO_ENC_SIZE_2; + break; + + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size") + break; + } /* end switch */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__point_get_version_enc_size() */ + /*-------------------------------------------------------------------------- NAME @@ -943,22 +1070,39 @@ done: static hssize_t H5S__point_serial_size(const H5S_t *space) { + uint32_t version; /* Version number */ + uint8_t enc_size; /* Encoded size of point selection info */ hssize_t ret_value = -1; /* Return value */ - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_STATIC HDassert(space); - /* Basic number of bytes required to serialize point selection: - * <type (4 bytes)> + <version (4 bytes)> + <padding (4 bytes)> + - * <length (4 bytes)> + <rank (4 bytes)> + <# of points (4 bytes)> = 24 bytes - */ - ret_value = 24; + /* Determine the version and encoded size for point selection */ + if(H5S__point_get_version_enc_size(space, &version, &enc_size) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't determine hyper version") + + /* Basic number of bytes required to serialize point selection: */ + if(version >= H5S_POINT_VERSION_2) + /* + * <type (4 bytes)> + <version (4 bytes)> + + * <size of point info (1 byte)> + rank (4 bytes)> + */ + ret_value=13; + else + /* + * <type (4 bytes)> + <version (4 bytes)> + <padding (4 bytes)> + + * <length (4 bytes)> + <rank (4 bytes)> + */ + ret_value = 20; + + /* <num points (depend on enc_size)> */ + ret_value += enc_size; /* Count points in selection */ - /* (Add 4 bytes times the rank for each element selected) */ - ret_value += (4 * space->extent.rank) * (hssize_t)H5S_GET_SELECT_NPOINTS(space); + ret_value += (hssize_t) (enc_size * space->extent.rank * space->select.num_elem); +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__point_serial_size() */ @@ -988,54 +1132,112 @@ static herr_t H5S__point_serialize(const H5S_t *space, uint8_t **p) { H5S_pnt_node_t *curr; /* Point information nodes */ - uint8_t *pp = (*p); /* Local pointer for decoding */ - uint8_t *lenp; /* Pointer to length location for later storage */ - uint32_t len = 0; /* Number of bytes used */ - unsigned u; /* Local counting variable */ + uint8_t *pp; /* Local pointer for decoding */ + uint8_t *lenp = NULL; /* pointer to length location for later storage */ + uint32_t len=0; /* number of bytes used */ + unsigned u; /* local counting variable */ + uint32_t version; /* Version number */ + uint8_t enc_size; /* Encoded size of point selection info */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_STATIC /* Check args */ HDassert(space); HDassert(p); + pp = (*p); HDassert(pp); + /* Determine the version and encoded size for point selection info */ + if(H5S__point_get_version_enc_size(space, &version, &enc_size) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't determine hyper version") + /* Store the preamble information */ UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ - UINT32ENCODE(pp, (uint32_t)1); /* Store the version number */ - UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */ - lenp = pp; /* Keep the pointer to the length location for later */ - pp += 4; /* Skip over space for length */ + + UINT32ENCODE(pp, version); /* Store the version number */ + if(version >= 2) { + *(pp)++ = enc_size; /* Store size of point info */ + } else { + HDassert(version == H5S_POINT_VERSION_1); + UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */ + lenp = pp; /* Keep the pointer to the length location for later */ + pp += 4; /* Skip over space for length */ + len += 8; /* Add in advance # of bytes for num of dimensions and num elements */ + } /* Encode number of dimensions */ UINT32ENCODE(pp, (uint32_t)space->extent.rank); - len += 4; - /* Encode number of elements */ - UINT32ENCODE(pp, (uint32_t)space->select.num_elem); - len += 4; + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + HDassert(version == H5S_POINT_VERSION_2); + + /* Encode number of elements */ + UINT16ENCODE(pp, (uint16_t)space->select.num_elem); + + /* Encode each point in selection */ + curr=space->select.sel_info.pnt_lst->head; + while(curr!=NULL) { + /* Encode each point */ + for(u=0; u<space->extent.rank; u++) + UINT16ENCODE(pp, (uint16_t)curr->pnt[u]); + curr=curr->next; + } /* end while */ + break; - /* Encode each point in selection */ - curr = space->select.sel_info.pnt_lst->head; - while(curr != NULL) { - /* Add 4 bytes times the rank for each element selected */ - len += 4 * space->extent.rank; + case H5S_SELECT_INFO_ENC_SIZE_4: + HDassert(version == H5S_POINT_VERSION_1 || version == H5S_POINT_VERSION_2); - /* Encode each point */ - for(u = 0; u < space->extent.rank; u++) - UINT32ENCODE(pp, (uint32_t)curr->pnt[u]); + /* Encode number of elements */ + UINT32ENCODE(pp, (uint32_t)space->select.num_elem); - curr = curr->next; - } /* end while */ + /* Encode each point in selection */ + curr=space->select.sel_info.pnt_lst->head; + while(curr!=NULL) { + /* Encode each point */ + for(u=0; u<space->extent.rank; u++) + UINT32ENCODE(pp, (uint32_t)curr->pnt[u]); + curr=curr->next; + } /* end while */ + + /* Add 4 bytes times the rank for each element selected */ + if(version == H5S_POINT_VERSION_1) + len += (uint32_t)space->select.num_elem * 4 * space->extent.rank; + break; + + case H5S_SELECT_INFO_ENC_SIZE_8: + HDassert(version == H5S_POINT_VERSION_2); + + /* Encode number of elements */ + UINT64ENCODE(pp, space->select.num_elem); + + /* Encode each point in selection */ + curr=space->select.sel_info.pnt_lst->head; + while(curr!=NULL) { + /* Encode each point */ + for(u=0; u<space->extent.rank; u++) + UINT64ENCODE(pp, curr->pnt[u]); + curr=curr->next; + } /* end while */ + break; + + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size") + break; - /* Encode length */ - UINT32ENCODE(lenp, (uint32_t)len); /* Store the length of the extra information */ + } /* end switch */ + + if(version == H5S_POINT_VERSION_1) + UINT32ENCODE(lenp, (uint32_t)len); /* Store the length of the extra information */ /* Update encoding pointer */ *p = pp; - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__point_serialize() */ +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__point_serialize() */ + /*-------------------------------------------------------------------------- @@ -1045,10 +1247,8 @@ H5S__point_serialize(const H5S_t *space, uint8_t **p) Deserialize the current selection from a user-provided buffer. USAGE herr_t H5S__point_deserialize(space, p) - H5S_t *space; IN/OUT: Dataspace pointer to place + H5S_t **space; IN/OUT: Dataspace pointer to place selection into - uint32_t version IN: Selection version - uint8_t flags IN: Selection flags uint8 **p; OUT: Pointer to buffer holding serialized selection. Will be advanced to end of serialized selection. @@ -1063,12 +1263,16 @@ H5S__point_serialize(const H5S_t *space, uint8_t **p) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__point_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, uint8_t H5_ATTR_UNUSED flags, - const uint8_t **p) +H5S__point_deserialize(H5S_t **space, const uint8_t **p) { + H5S_t *tmp_space = NULL; /* Pointer to actual dataspace to use, + either *space or a newly allocated one */ + hsize_t dims[H5S_MAX_RANK]; /* Dimension sizes */ + uint32_t version; /* Version number */ + uint8_t enc_size = 0; /* Encoded size of selection info */ hsize_t *coord = NULL, *tcoord; /* Pointer to array of elements */ - const uint8_t *pp = (*p); /* Local pointer for decoding */ - size_t num_elem = 0; /* Number of elements in selection */ + const uint8_t *pp; /* Local pointer for decoding */ + uint64_t num_elem = 0; /* Number of elements in selection */ unsigned rank; /* Rank of points */ unsigned i, j; /* local counting variables */ herr_t ret_value = SUCCEED; /* Return value */ @@ -1076,14 +1280,68 @@ H5S__point_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, uint8_t H5 FUNC_ENTER_STATIC /* Check args */ - HDassert(space); HDassert(p); + pp = (*p); HDassert(pp); - /* Deserialize points to select */ - /* (The header and rank have already beed decoded) */ - rank = space->extent.rank; /* Retrieve rank from space */ - UINT32DECODE(pp, num_elem); /* decode the number of points */ + /* As part of the efforts to push all selection-type specific coding + to the callbacks, the coding for the allocation of a null dataspace + is moved from H5S_select_deserialize() in H5Sselect.c to here. + This is needed for decoding virtual layout in H5O__layout_decode() */ + /* Allocate space if not provided */ + if(!*space) { + if(NULL == (tmp_space = H5S_create(H5S_SIMPLE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace") + } /* end if */ + else + tmp_space = *space; + + /* Decode version */ + UINT32DECODE(pp, version); + + if(version >= (uint32_t)H5S_POINT_VERSION_2) + /* Decode size of point info */ + enc_size = *(pp)++; + else { + /* Skip over the remainder of the header */ + pp += 8; + enc_size = H5S_SELECT_INFO_ENC_SIZE_4; + } + + /* Check encoded size */ + if(enc_size & ~H5S_SELECT_INFO_ENC_SIZE_BITS) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTLOAD, FAIL, "unknown size of point/offset info for selection") + + /* Decode the rank of the point selection */ + UINT32DECODE(pp,rank); + + if(!*space) { + /* Patch the rank of the allocated dataspace */ + (void)HDmemset(dims, 0, (size_t)rank * sizeof(dims[0])); + if(H5S_set_extent_simple(tmp_space, rank, dims, NULL) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't set dimensions") + } /* end if */ + else + /* Verify the rank of the provided dataspace */ + if(rank != tmp_space->extent.rank) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "rank of serialized selection does not match dataspace") + + /* decode the number of points */ + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + UINT16DECODE(pp, num_elem); + break; + case H5S_SELECT_INFO_ENC_SIZE_4: + UINT32DECODE(pp, num_elem); + break; + case H5S_SELECT_INFO_ENC_SIZE_8: + UINT64DECODE(pp, num_elem); + break; + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size") + break; + } /* end switch */ + /* Allocate space for the coordinates */ if(NULL == (coord = (hsize_t *)H5MM_malloc(num_elem * rank * sizeof(hsize_t)))) @@ -1092,16 +1350,40 @@ H5S__point_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, uint8_t H5 /* Retrieve the coordinates from the buffer */ for(tcoord = coord, i = 0; i < num_elem; i++) for(j = 0; j < (unsigned)rank; j++, tcoord++) - UINT32DECODE(pp, *tcoord); + switch(enc_size) { + case H5S_SELECT_INFO_ENC_SIZE_2: + UINT16DECODE(pp, *tcoord); + break; + + case H5S_SELECT_INFO_ENC_SIZE_4: + UINT32DECODE(pp, *tcoord); + break; + + case H5S_SELECT_INFO_ENC_SIZE_8: + UINT64DECODE(pp, *tcoord); + break; + default: + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size") + break; + } /* end switch */ /* Select points */ - if(H5S_select_elements(space, H5S_SELECT_SET, num_elem, (const hsize_t *)coord) < 0) + if(H5S_select_elements(tmp_space, H5S_SELECT_SET, num_elem, (const hsize_t *)coord) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") /* Update decoding pointer */ *p = pp; + /* Return space to the caller if allocated */ + if(!*space) + *space = tmp_space; + done: + /* Free temporary space if not passed to caller (only happens on error) */ + if(!*space && tmp_space) + if(H5S_close(tmp_space) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace") + /* Free the coordinate array if necessary */ if(coord != NULL) H5MM_xfree(coord); @@ -1165,7 +1447,7 @@ H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, /* Iterate through the node, copying each point's information */ while(node != NULL && numpoints > 0) { - HDmemcpy(buf, node->pnt, sizeof(hsize_t) * rank); + H5MM_memcpy(buf, node->pnt, sizeof(hsize_t) * rank); buf += rank; numpoints--; node = node->next; @@ -1649,7 +1931,7 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of /* Calculate offset of selection in projected buffer */ HDmemset(block, 0, sizeof(block)); - HDmemcpy(block, base_space->select.sel_info.pnt_lst->head->pnt, sizeof(hsize_t) * rank_diff); + H5MM_memcpy(block, base_space->select.sel_info.pnt_lst->head->pnt, sizeof(hsize_t) * rank_diff); *offset = H5VM_array_offset(base_space->extent.rank, base_space->extent.size, block); /* Iterate through base space's point nodes, copying the point information */ @@ -1666,7 +1948,7 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of } /* end if */ /* Copy over the point's coordinates */ - HDmemcpy(new_node->pnt, &base_node->pnt[rank_diff], (new_space->extent.rank * sizeof(hsize_t))); + H5MM_memcpy(new_node->pnt, &base_node->pnt[rank_diff], (new_space->extent.rank * sizeof(hsize_t))); /* Keep the order the same when copying */ if(NULL == prev_node) @@ -1704,7 +1986,7 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of /* Copy over the point's coordinates */ HDmemset(new_node->pnt, 0, sizeof(hsize_t) * rank_diff); - HDmemcpy(&new_node->pnt[rank_diff], base_node->pnt, (new_space->extent.rank * sizeof(hsize_t))); + H5MM_memcpy(&new_node->pnt[rank_diff], base_node->pnt, (new_space->extent.rank * sizeof(hsize_t))); /* Keep the order the same when copying */ if(NULL == prev_node) diff --git a/src/H5Spublic.h b/src/H5Spublic.h index 561875a..c01beca 100644 --- a/src/H5Spublic.h +++ b/src/H5Spublic.h @@ -97,7 +97,7 @@ H5_DLL herr_t H5Sset_extent_simple(hid_t space_id, int rank, const hsize_t dims[], const hsize_t max[]); H5_DLL hid_t H5Scopy(hid_t space_id); H5_DLL herr_t H5Sclose(hid_t space_id); -H5_DLL herr_t H5Sencode(hid_t obj_id, void *buf, size_t *nalloc); +H5_DLL herr_t H5Sencode2(hid_t obj_id, void *buf, size_t *nalloc, hid_t fapl); H5_DLL hid_t H5Sdecode(const void *buf); H5_DLL hssize_t H5Sget_simple_extent_npoints(hid_t space_id); H5_DLL int H5Sget_simple_extent_ndims(hid_t space_id); @@ -134,6 +134,16 @@ H5_DLL hssize_t H5Sget_select_hyper_nblocks(hid_t spaceid); H5_DLL herr_t H5Sget_select_hyper_blocklist(hid_t spaceid, hsize_t startblock, hsize_t numblocks, hsize_t buf[/*numblocks*/]); +/* Symbols defined for compatibility with previous versions of the HDF5 API. + * + * Use of these symbols is deprecated. + */ +#ifndef H5_NO_DEPRECATED_SYMBOLS +/* Function prototypes */ +H5_DLL herr_t H5Sencode1(hid_t obj_id, void *buf, size_t *nalloc); + +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + #ifdef __cplusplus } #endif diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 24586de..aaea203 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -114,7 +114,7 @@ H5S_select_offset(H5S_t *space, const hssize_t *offset) HDassert(offset); /* Copy the offset over */ - HDmemcpy(space->select.offset, offset, sizeof(hssize_t) * space->extent.rank); + H5MM_memcpy(space->select.offset, offset, sizeof(hssize_t) * space->extent.rank); /* Indicate that the offset was changed */ space->select.offset_changed = TRUE; @@ -544,101 +544,44 @@ H5S_select_valid(const H5S_t *space) herr_t H5S_select_deserialize(H5S_t **space, const uint8_t **p) { - H5S_t *tmp_space = NULL; /* Pointer to actual dataspace to use, either - *space or a newly allocated one */ uint32_t sel_type; /* Pointer to the selection type */ - uint32_t version; /* Version number */ - uint8_t flags = 0; /* Flags */ herr_t ret_value = FAIL; /* Return value */ FUNC_ENTER_NOAPI(FAIL) HDassert(space); - /* Allocate space if not provided */ - if(!*space) { - if(NULL == (tmp_space = H5S_create(H5S_SIMPLE))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace") - } /* end if */ - else - tmp_space = *space; + /* Selection-type specific coding is moved to the callbacks. */ /* Decode selection type */ UINT32DECODE(*p, sel_type); - /* Decode version */ - UINT32DECODE(*p, version); - - if(version >= (uint32_t)2) { - /* Decode flags */ - flags = *(*p)++; - - /* Check for unknown flags */ - if(flags & ~H5S_SELECT_FLAG_BITS) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTLOAD, FAIL, "unknown flag for selection") - - /* Skip over the remainder of the header */ - *p += 4; - } /* end if */ - else - /* Skip over the remainder of the header */ - *p += 8; - - /* Decode and check or patch rank for point and hyperslab selections */ - if((sel_type == H5S_SEL_POINTS) || (sel_type == H5S_SEL_HYPERSLABS)) { - uint32_t rank; /* Rank of dataspace */ - - /* Decode the rank of the point selection */ - UINT32DECODE(*p,rank); - - if(!*space) { - hsize_t dims[H5S_MAX_RANK]; - - /* Patch the rank of the allocated dataspace */ - (void)HDmemset(dims, 0, (size_t)rank * sizeof(dims[0])); - if(H5S_set_extent_simple(tmp_space, rank, dims, NULL) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't set dimensions") - } /* end if */ - else - /* Verify the rank of the provided dataspace */ - if(rank != tmp_space->extent.rank) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "rank of serialized selection does not match dataspace") - } /* end if */ - /* Make routine for selection type */ switch(sel_type) { case H5S_SEL_POINTS: /* Sequence of points selected */ - ret_value = (*H5S_sel_point->deserialize)(tmp_space, version, flags, p); + ret_value = (*H5S_sel_point->deserialize)(space, p); break; case H5S_SEL_HYPERSLABS: /* Hyperslab selection defined */ - ret_value = (*H5S_sel_hyper->deserialize)(tmp_space, version, flags, p); + ret_value = (*H5S_sel_hyper->deserialize)(space, p); break; case H5S_SEL_ALL: /* Entire extent selected */ - ret_value = (*H5S_sel_all->deserialize)(tmp_space, version, flags, p); + ret_value = (*H5S_sel_all->deserialize)(space, p); break; case H5S_SEL_NONE: /* Nothing selected */ - ret_value = (*H5S_sel_none->deserialize)(tmp_space, version, flags, p); + ret_value = (*H5S_sel_none->deserialize)(space, p); break; default: break; } /* end switch */ + if(ret_value < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTLOAD, FAIL, "can't deserialize selection") - /* Return space to the caller if allocated */ - if(!*space) - *space = tmp_space; - done: - /* Free temporary space if not passed to caller (only happens on error) */ - if(!*space && tmp_space) - if(H5S_close(tmp_space) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace") - FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_deserialize() */ @@ -1538,7 +1481,7 @@ H5S_select_iterate(void *buf, const H5T_t *type, const H5S_t *space, if(ndims > 0) { /* Copy the size of the space */ HDassert(space->extent.size); - HDmemcpy(space_size, space->extent.size, ndims * sizeof(hsize_t)); + H5MM_memcpy(space_size, space->extent.size, ndims * sizeof(hsize_t)); } /* end if */ space_size[ndims] = elmt_size; @@ -2192,16 +2135,16 @@ H5S_select_construct_projection(const H5S_t *base_space, H5S_t **new_space_ptr, rank_diff = new_space_rank - base_space_rank; H5VM_array_fill(new_space_dims, &tmp_dim_size, sizeof(tmp_dim_size), rank_diff); H5VM_array_fill(new_space_maxdims, &tmp_dim_size, sizeof(tmp_dim_size), rank_diff); - HDmemcpy(&new_space_dims[rank_diff], base_space_dims, sizeof(new_space_dims[0]) * base_space_rank); - HDmemcpy(&new_space_maxdims[rank_diff], base_space_maxdims, sizeof(new_space_maxdims[0]) * base_space_rank); + H5MM_memcpy(&new_space_dims[rank_diff], base_space_dims, sizeof(new_space_dims[0]) * base_space_rank); + H5MM_memcpy(&new_space_maxdims[rank_diff], base_space_maxdims, sizeof(new_space_maxdims[0]) * base_space_rank); } /* end if */ else { /* new_space_rank < base_space_rank */ /* we must copy the fastest changing dimension of the * base space into the dimensions of the new space. */ rank_diff = base_space_rank - new_space_rank; - HDmemcpy(new_space_dims, &base_space_dims[rank_diff], sizeof(new_space_dims[0]) * new_space_rank); - HDmemcpy(new_space_maxdims, &base_space_maxdims[rank_diff], sizeof(new_space_maxdims[0]) * new_space_rank); + H5MM_memcpy(new_space_dims, &base_space_dims[rank_diff], sizeof(new_space_dims[0]) * new_space_rank); + H5MM_memcpy(new_space_maxdims, &base_space_maxdims[rank_diff], sizeof(new_space_maxdims[0]) * new_space_rank); } /* end else */ /* now have the new space rank and dimensions set up -- @@ -2232,10 +2175,10 @@ H5S_select_construct_projection(const H5S_t *base_space, H5S_t **new_space_ptr, if(H5S_GET_EXTENT_TYPE(base_space) == H5S_SIMPLE && base_space->select.offset_changed) { if(new_space_rank > base_space_rank) { HDmemset(new_space->select.offset, 0, sizeof(new_space->select.offset[0]) * rank_diff); - HDmemcpy(&new_space->select.offset[rank_diff], base_space->select.offset, sizeof(new_space->select.offset[0]) * base_space_rank); + H5MM_memcpy(&new_space->select.offset[rank_diff], base_space->select.offset, sizeof(new_space->select.offset[0]) * base_space_rank); } /* end if */ else - HDmemcpy(new_space->select.offset, &base_space->select.offset[rank_diff], sizeof(new_space->select.offset[0]) * new_space_rank); + H5MM_memcpy(new_space->select.offset, &base_space->select.offset[rank_diff], sizeof(new_space->select.offset[0]) * new_space_rank); /* Propagate the offset changed flag into the new dataspace. */ new_space->select.offset_changed = TRUE; @@ -513,6 +513,7 @@ H5FL_DEFINE(H5T_shared_t); const unsigned H5O_dtype_ver_bounds[] = { H5O_DTYPE_VERSION_1, /* H5F_LIBVER_EARLIEST */ H5O_DTYPE_VERSION_3, /* H5F_LIBVER_V18 */ + H5O_DTYPE_VERSION_3, /* H5F_LIBVER_V110 */ H5O_DTYPE_VERSION_LATEST /* H5F_LIBVER_LATEST */ }; @@ -3338,7 +3339,7 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) if (NULL == new_dt->shared->u.compnd.memb) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(new_dt->shared->u.compnd.memb, old_dt->shared->u.compnd.memb, + H5MM_memcpy(new_dt->shared->u.compnd.memb, old_dt->shared->u.compnd.memb, new_dt->shared->u.compnd.nmembs * sizeof(H5T_cmemb_t)); } /* end if */ @@ -3404,7 +3405,7 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) (uint8_t *)H5MM_malloc(new_dt->shared->u.enumer.nalloc * new_dt->shared->size); if(NULL == new_dt->shared->u.enumer.value) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemcpy(new_dt->shared->u.enumer.value, old_dt->shared->u.enumer.value, + H5MM_memcpy(new_dt->shared->u.enumer.value, old_dt->shared->u.enumer.value, new_dt->shared->u.enumer.nmembs * new_dt->shared->size); for(i = 0; i < new_dt->shared->u.enumer.nmembs; i++) { s = old_dt->shared->u.enumer.name[i]; diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index 712b264..c6b85a5 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -1211,7 +1211,7 @@ H5T_save_refresh_state(hid_t tid, H5O_shared_t *cached_H5O_shared) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, FAIL, "can't increment object count") /* Cache the H5O_shared_t data */ - HDmemcpy(cached_H5O_shared, &(vol_dt->sh_loc), sizeof(H5O_shared_t)); + H5MM_memcpy(cached_H5O_shared, &(vol_dt->sh_loc), sizeof(H5O_shared_t)); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1245,7 +1245,7 @@ H5T_restore_refresh_state(hid_t tid, H5O_shared_t *cached_H5O_shared) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "tid is not not a named datatype ID") /* Restore the H5O_shared_t data */ - HDmemcpy(&(vol_dt->sh_loc), cached_H5O_shared, sizeof(H5O_shared_t)); + H5MM_memcpy(&(vol_dt->sh_loc), cached_H5O_shared, sizeof(H5O_shared_t)); /* Decrement the ref. count for this object in the top file */ if(H5FO_top_decr(vol_dt->sh_loc.file, vol_dt->sh_loc.u.loc.oh_addr) < 0) diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 9a1105b..7d47483 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -828,7 +828,7 @@ done: \ /* Macro defining action on source data which needs to be aligned (before main action) */ #define H5T_CONV_LOOP_PRE_SALIGN(ST) { \ - HDmemcpy(&src_aligned, src, sizeof(ST)); \ + H5MM_memcpy(&src_aligned, src, sizeof(ST)); \ } /* Macro defining action on source data which doesn't need to be aligned (before main action) */ @@ -854,7 +854,7 @@ done: \ /* Macro defining action on destination data which needs to be aligned (after main action) */ #define H5T_CONV_LOOP_POST_DALIGN(DT) { \ - HDmemcpy(dst, &dst_aligned, sizeof(DT)); \ + H5MM_memcpy(dst, &dst_aligned, sizeof(DT)); \ } /* Macro defining action on destination data which doesn't need to be aligned (after main action) */ @@ -1797,7 +1797,7 @@ H5T__conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * should copy the value to the true destination buffer. */ if(d == dbuf) - HDmemcpy(dp, d, dst->shared->size); + H5MM_memcpy(dp, d, dst->shared->size); if(buf_stride) { sp += direction * (ssize_t)buf_stride; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */ dp += direction * (ssize_t)buf_stride; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */ @@ -2852,7 +2852,7 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, else if(except_ret == H5T_CONV_ABORT) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") } else - HDmemcpy(d, + H5MM_memcpy(d, dst->shared->u.enumer.value + (unsigned)priv->src2dst[n] * dst->shared->size, dst->shared->size); } /* end if */ @@ -2888,7 +2888,7 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } /* end if */ else { HDassert(priv->src2dst[md] >= 0); - HDmemcpy(d, + H5MM_memcpy(d, dst->shared->u.enumer.value + (unsigned)priv->src2dst[md] * dst->shared->size, dst->shared->size); } /* end else */ @@ -3846,7 +3846,7 @@ H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * should copy the value to the true destination buffer. */ if(d==dbuf) - HDmemcpy(dp, d, dst->shared->size); + H5MM_memcpy(dp, d, dst->shared->size); /* Advance source & destination pointers by delta amounts */ sp += src_delta; @@ -4432,7 +4432,7 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, */ next: if(d == dbuf) - HDmemcpy(dp, d, dst_p->shared->size); + H5MM_memcpy(dp, d, dst_p->shared->size); /* Advance source & destination pointers by delta amounts */ sp += src_delta; @@ -4604,7 +4604,7 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, --nchars; nchars = MIN(dst->shared->size, nchars); if(d != s) - HDmemcpy(d, s, nchars); + H5MM_memcpy(d, s, nchars); break; case H5T_STR_RESERVED_3: @@ -4666,7 +4666,7 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * should copy the value to the true destination buffer. */ if(d == dbuf) - HDmemcpy(dp, d, dst->shared->size); + H5MM_memcpy(dp, d, dst->shared->size); /* Advance source & destination pointers by delta amounts */ sp += src_delta; @@ -8825,7 +8825,7 @@ H5T__conv_f_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * should copy the value to the true destination buffer. */ if (d==dbuf) - HDmemcpy (dp, d, dst_p->shared->size); + H5MM_memcpy (dp, d, dst_p->shared->size); if (buf_stride) { sp += direction * (ssize_t) buf_stride; dp += direction * (ssize_t) buf_stride; @@ -9235,7 +9235,7 @@ H5T__conv_i_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * should copy the value to the true destination buffer. */ if (d==dbuf) - HDmemcpy (dp, d, dst_p->shared->size); + H5MM_memcpy (dp, d, dst_p->shared->size); if (buf_stride) { sp += direction * (ssize_t) buf_stride; dp += direction * (ssize_t) buf_stride; diff --git a/src/H5Tenum.c b/src/H5Tenum.c index 0ed1775..ff88fab 100644 --- a/src/H5Tenum.c +++ b/src/H5Tenum.c @@ -223,7 +223,7 @@ H5T__enum_insert(const H5T_t *dt, const char *name, const void *value) dt->shared->u.enumer.sorted = H5T_SORT_NONE; i = dt->shared->u.enumer.nmembs++; dt->shared->u.enumer.name[i] = H5MM_xstrdup(name); - HDmemcpy(dt->shared->u.enumer.value+i*dt->shared->size, value, dt->shared->size); + H5MM_memcpy(dt->shared->u.enumer.value+i*dt->shared->size, value, dt->shared->size); done: FUNC_LEAVE_NOAPI(ret_value) @@ -298,7 +298,7 @@ H5T__get_member_value(const H5T_t *dt, unsigned membno, void *value/*out*/) HDassert(dt); HDassert(value); - HDmemcpy(value, dt->shared->u.enumer.value + membno*dt->shared->size, dt->shared->size); + H5MM_memcpy(value, dt->shared->u.enumer.value + membno*dt->shared->size, dt->shared->size); FUNC_LEAVE_NOAPI(SUCCEED) } @@ -569,7 +569,7 @@ H5T_enum_valueof(const H5T_t *dt, const char *name, void *value/*out*/) if (cmp!=0) HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "string doesn't exist in the enumeration type") - HDmemcpy(value, copied_dt->shared->u.enumer.value+md*copied_dt->shared->size, copied_dt->shared->size); + H5MM_memcpy(value, copied_dt->shared->u.enumer.value+md*copied_dt->shared->size, copied_dt->shared->size); done: if(copied_dt) diff --git a/src/H5Tfields.c b/src/H5Tfields.c index be62d85..8202c2c 100644 --- a/src/H5Tfields.c +++ b/src/H5Tfields.c @@ -351,10 +351,10 @@ H5T__sort_value(const H5T_t *dt, int *map) dt->shared->u.enumer.name[j + 1] = tmp; /* Swap values */ - HDmemcpy(tbuf, dt->shared->u.enumer.value + (j * size), size); - HDmemcpy(dt->shared->u.enumer.value + (j * size), + H5MM_memcpy(tbuf, dt->shared->u.enumer.value + (j * size), size); + H5MM_memcpy(dt->shared->u.enumer.value + (j * size), dt->shared->u.enumer.value + ((j + 1) * size), size); - HDmemcpy(dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size); + H5MM_memcpy(dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size); /* Swap map */ if(map) { @@ -457,10 +457,10 @@ H5T__sort_name(const H5T_t *dt, int *map) dt->shared->u.enumer.name[j+1] = tmp; /* Swap values */ - HDmemcpy(tbuf, dt->shared->u.enumer.value+j*size, size); - HDmemcpy(dt->shared->u.enumer.value+j*size, + H5MM_memcpy(tbuf, dt->shared->u.enumer.value+j*size, size); + H5MM_memcpy(dt->shared->u.enumer.value+j*size, dt->shared->u.enumer.value+(j+1)*size, size); - HDmemcpy(dt->shared->u.enumer.value+(j+1)*size, tbuf, size); + H5MM_memcpy(dt->shared->u.enumer.value+(j+1)*size, tbuf, size); /* Swap map */ if (map) { diff --git a/src/H5Tnative.c b/src/H5Tnative.c index c9ad01a..3554f75 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -369,7 +369,7 @@ H5T__get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_ali HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member name") if(H5T__get_member_value(dtype, u, tmp_memb_value) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member value") - HDmemcpy(memb_value, tmp_memb_value, H5T_get_size(super_type)); + H5MM_memcpy(memb_value, tmp_memb_value, H5T_get_size(super_type)); if(H5T_convert(tpath, super_type_id, nat_super_type_id, (size_t)1, (size_t)0, (size_t)0, memb_value, NULL) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member value") diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 841637d..bafb47f 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -302,7 +302,7 @@ H5T_vlen_seq_mem_getlen(const void *_vl) FUNC_LEAVE_NOAPI((ssize_t)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) #endif @@ -339,7 +339,7 @@ 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 @@ -376,7 +376,7 @@ H5T_vlen_seq_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) FUNC_LEAVE_NOAPI((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) #endif @@ -411,13 +411,13 @@ H5T_vlen_seq_mem_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) #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) @@ -463,7 +463,7 @@ H5T_vlen_seq_mem_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_ } /* end else */ /* Copy the data into the newly allocated buffer */ - HDmemcpy(vl.p,buf,len); + H5MM_memcpy(vl.p,buf,len); } /* end if */ else @@ -473,7 +473,7 @@ H5T_vlen_seq_mem_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_ 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) @@ -507,7 +507,7 @@ H5T_vlen_seq_mem_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED vl.p=NULL; /* 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)); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5T_vlen_seq_mem_setnull() */ @@ -541,7 +541,7 @@ H5T_vlen_str_mem_getlen(const void *_vl) HDassert(s); #else HDassert(_vl); - HDmemcpy(&s, _vl, sizeof(char *)); + H5MM_memcpy(&s, _vl, sizeof(char *)); #endif FUNC_LEAVE_NOAPI((ssize_t)HDstrlen(s)) @@ -576,7 +576,7 @@ H5T_vlen_str_mem_getptr(void *_vl) HDassert(s); #else HDassert(_vl); - HDmemcpy(&s, _vl, sizeof(char *)); + H5MM_memcpy(&s, _vl, sizeof(char *)); #endif FUNC_LEAVE_NOAPI(s) @@ -607,7 +607,7 @@ H5T_vlen_str_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) FUNC_ENTER_NOAPI_NOINIT_NOERR #ifndef H5_NO_ALIGNMENT_RESTRICTIONS - HDmemcpy(&s, _vl, sizeof(char *)); + H5MM_memcpy(&s, _vl, sizeof(char *)); #endif FUNC_LEAVE_NOAPI(s==NULL ? TRUE : FALSE) @@ -644,10 +644,10 @@ H5T_vlen_str_mem_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) 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) @@ -690,11 +690,11 @@ H5T_vlen_str_mem_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_ } /* end else */ len=(seq_len*base_size); - HDmemcpy(t,buf,len); + 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 */ @@ -721,7 +721,7 @@ H5T_vlen_str_mem_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED FUNC_ENTER_NOAPI_NOINIT_NOERR /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - HDmemcpy(_vl,&t,sizeof(char *)); + H5MM_memcpy(_vl,&t,sizeof(char *)); FUNC_LEAVE_NOAPI(SUCCEED) /*lint !e429 The pointer in 't' has been copied */ } /* end H5T_vlen_str_mem_setnull() */ @@ -29,11 +29,8 @@ /***********/ #include "H5private.h" /* Generic Functions */ -#include "H5Aprivate.h" /* Attributes */ #include "H5Eprivate.h" /* Error handling */ #include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5PLprivate.h" /* Plugins */ #include "H5VLpkg.h" /* Virtual Object Layer */ @@ -46,29 +43,10 @@ /* Local Typedefs */ /******************/ -/* Information needed for iterating over the registered VOL connector hid_t IDs. - * The name or value of the new VOL connector that is being registered is - * stored in the name (or value) field and the found_id field is initialized to - * H5I_INVALID_HID (-1). If we find a VOL connector with the same name / value, - * we set the found_id field to the existing ID for return to the function. - */ -typedef struct { - /* IN */ - H5VL_get_connector_kind_t kind; /* Which kind of connector search to make */ - union { - const char *name; /* The name of the VOL connector to check */ - H5VL_class_value_t value; /* The value of the VOL connector to check */ - } u; - - /* OUT */ - hid_t found_id; /* The connector ID, if we found a match */ -} H5VL_get_connector_ud_t; - /********************/ /* Local Prototypes */ /********************/ -static int H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data); /*********************/ @@ -88,45 +66,6 @@ static int H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data); /*------------------------------------------------------------------------- - * Function: H5VL__get_connector_cb - * - * Purpose: Callback routine to search through registered VOLs - * - * Return: Success: H5_ITER_STOP if the class and op_data name - * members match. H5_ITER_CONT otherwise. - * - * Failure: Can't fail - * - *------------------------------------------------------------------------- - */ -static int -H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data) -{ - H5VL_get_connector_ud_t *op_data = (H5VL_get_connector_ud_t *)_op_data; /* User data for callback */ - H5VL_class_t *cls = (H5VL_class_t *)obj; - int ret_value = H5_ITER_CONT; /* Callback return value */ - - FUNC_ENTER_STATIC_NOERR - - if(H5VL_GET_CONNECTOR_BY_NAME == op_data->kind) { - if(0 == HDstrcmp(cls->name, op_data->u.name)) { - op_data->found_id = id; - ret_value = H5_ITER_STOP; - } /* end if */ - } /* end if */ - else { - HDassert(H5VL_GET_CONNECTOR_BY_VALUE == op_data->kind); - if(cls->value == op_data->u.value) { - op_data->found_id = id; - ret_value = H5_ITER_STOP; - } /* end if */ - } /* end else */ - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL__get_connector_cb() */ - - -/*------------------------------------------------------------------------- * Function: H5VLregister_connector * * Purpose: Registers a new VOL connector as a member of the virtual object @@ -143,8 +82,7 @@ H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data) hid_t H5VLregister_connector(const H5VL_class_t *cls, hid_t vipl_id) { - H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ - hid_t ret_value = H5I_INVALID_HID; + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) H5TRACE2("i", "*xi", cls, vipl_id); @@ -161,25 +99,9 @@ H5VLregister_connector(const H5VL_class_t *cls, hid_t vipl_id) if (cls->wrap_cls.get_wrap_ctx && !cls->wrap_cls.free_wrap_ctx) HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "VOL connector must provide free callback for object wrapping contexts when a get callback is provided") - op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; - op_data.u.name = cls->name; - op_data.found_id = H5I_INVALID_HID; - - /* check if connector is already registered */ - if (H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL IDs") - - /* Increment the ref count on the existing VOL connector ID, if it's already registered */ - if(op_data.found_id != H5I_INVALID_HID) { - if (H5I_inc_ref(op_data.found_id, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") - ret_value = op_data.found_id; - } /* end if */ - else { - /* Create a new class ID */ - if ((ret_value = H5VL_register_connector(cls, TRUE, vipl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector") - } /* end else */ + /* Register connector */ + if((ret_value = H5VL__register_connector(cls, TRUE, vipl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector") done: FUNC_LEAVE_API(ret_value) @@ -203,8 +125,7 @@ done: hid_t H5VLregister_connector_by_name(const char *name, hid_t vipl_id) { - H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ - hid_t ret_value = H5I_INVALID_HID; + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) H5TRACE2("i", "*si", name, vipl_id); @@ -215,34 +136,9 @@ H5VLregister_connector_by_name(const char *name, hid_t vipl_id) if (0 == HDstrlen(name)) HGOTO_ERROR(H5E_ARGS, H5E_UNINITIALIZED, H5I_INVALID_HID, "zero-length VOL connector name is disallowed") - op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; - op_data.u.name = name; - op_data.found_id = H5I_INVALID_HID; - - /* Check if connector is already registered */ - if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL ids") - - /* If connector alread registered, increment ref count on ID and return ID */ - if(op_data.found_id != H5I_INVALID_HID) { - if(H5I_inc_ref(op_data.found_id, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") - ret_value = op_data.found_id; - } /* end if */ - else { - H5PL_key_t key; - const H5VL_class_t *cls; - - /* Try loading the connector */ - key.vol.kind = H5VL_GET_CONNECTOR_BY_NAME; - key.vol.u.name = name; - if(NULL == (cls = (const H5VL_class_t *)H5PL_load(H5PL_TYPE_VOL, &key))) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to load VOL connector") - - /* Register the connector we loaded */ - if((ret_value = H5VL_register_connector(cls, TRUE, vipl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID") - } /* end else */ + /* Register connector */ + if((ret_value = H5VL__register_connector_by_name(name, TRUE, vipl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector") done: FUNC_LEAVE_API(ret_value) @@ -266,8 +162,7 @@ done: hid_t H5VLregister_connector_by_value(H5VL_class_value_t value, hid_t vipl_id) { - H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ - hid_t ret_value = H5I_INVALID_HID; + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) H5TRACE2("i", "VCi", value, vipl_id); @@ -276,34 +171,9 @@ H5VLregister_connector_by_value(H5VL_class_value_t value, hid_t vipl_id) if(value < 0) HGOTO_ERROR(H5E_ARGS, H5E_UNINITIALIZED, H5I_INVALID_HID, "negative VOL connector value is disallowed") - op_data.kind = H5VL_GET_CONNECTOR_BY_VALUE; - op_data.u.value = value; - op_data.found_id = H5I_INVALID_HID; - - /* Check if connector is already registered */ - if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL ids") - - /* If connector alread registered, increment ref count on ID and return ID */ - if(op_data.found_id != H5I_INVALID_HID) { - if(H5I_inc_ref(op_data.found_id, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") - ret_value = op_data.found_id; - } /* end if */ - else { - H5PL_key_t key; - const H5VL_class_t *cls; - - /* Try loading the connector */ - key.vol.kind = H5VL_GET_CONNECTOR_BY_VALUE; - key.vol.u.value = value; - if(NULL == (cls = (const H5VL_class_t *)H5PL_load(H5PL_TYPE_VOL, &key))) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to load VOL connector") - - /* Register the connector we loaded */ - if((ret_value = H5VL_register_connector(cls, TRUE, vipl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID") - } /* end else */ + /* Register connector */ + if((ret_value = H5VL__register_connector_by_value(value, TRUE, vipl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector") done: FUNC_LEAVE_API(ret_value) @@ -315,33 +185,26 @@ done: * * Purpose: Tests whether a VOL class has been registered or not * - * Return: Positive if the VOL class has been registered - * - * Zero if it is unregistered + * Return: >0 if the VOL class has been registered + * 0 if it is unregistered + * <0 on error (if the class is not a valid class ID) * - * Negative on error (if the class is not a valid class ID) + * Programmer: Dana Robinson + * June 17, 2017 * *------------------------------------------------------------------------- */ htri_t H5VLis_connector_registered(const char *name) { - H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ htri_t ret_value = FALSE; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE1("t", "*s", name); - op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; - op_data.u.name = name; - op_data.found_id = H5I_INVALID_HID; - - /* Check arguments */ - if (H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_BADITER, FAIL, "can't iterate over VOL ids") - - if (op_data.found_id != H5I_INVALID_HID) - ret_value = TRUE; + /* Check if connector with this name is registered */ + if((ret_value = H5VL__is_connector_registered(name)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't check for VOL") done: FUNC_LEAVE_API(ret_value) @@ -356,30 +219,22 @@ done: * Return: Positive if the VOL class has been registered * Negative on error (if the class is not a valid class or not registered) * + * Programmer: Dana Robinson + * June 17, 2017 + * *------------------------------------------------------------------------- */ hid_t H5VLget_connector_id(const char *name) { - H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) H5TRACE1("i", "*s", name); - op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; - op_data.u.name = name; - op_data.found_id = H5I_INVALID_HID; - - /* Check arguments */ - if (H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) - HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL connector IDs") - - if (op_data.found_id != H5I_INVALID_HID) { - if (H5I_inc_ref(op_data.found_id, TRUE) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") - ret_value = op_data.found_id; - } /* end if */ + /* Get connector ID with this name */ + if((ret_value = H5VL__get_connector_id(name, TRUE)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, H5I_INVALID_HID, "can't get VOL id") done: FUNC_LEAVE_API(ret_value) @@ -406,7 +261,8 @@ H5VLget_connector_name(hid_t obj_id, char *name/*out*/, size_t size) FUNC_ENTER_API(FAIL) H5TRACE3("Zs", "ixz", obj_id, name, size); - if ((ret_value = H5VL_get_connector_name(obj_id, name, size)) < 0) + /* Call internal routine */ + if((ret_value = H5VL__get_connector_name(obj_id, name, size)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "Can't get connector name") done: @@ -488,6 +344,9 @@ done: * * Purpose: Compares two connector classes (based on their value field) * + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. + * * Return: Success: Non-negative, *cmp set to a value like strcmp * * Failure: Negative, *cmp unset @@ -587,3 +446,159 @@ done: FUNC_LEAVE_API(ret_value) } /* H5VLobject() */ + +/*--------------------------------------------------------------------------- + * Function: H5VLretrieve_lib_state + * + * Purpose: Retrieves a copy of the internal state of the HDF5 library, + * so that it can be restored later. + * + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. + * + * Return: Success: Non-negative, *state set + * Failure: Negative, *state unset + * + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 + * + *--------------------------------------------------------------------------- + */ +herr_t +H5VLretrieve_lib_state(void **state) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + /* Must use this, to avoid modifying the API context stack in FUNC_ENTER */ + FUNC_ENTER_API_NOINIT + H5TRACE1("e", "**x", state); + + /* Check args */ + if(NULL == state) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "invalid state pointer") + + /* Retrieve the library state */ + if(H5VL_retrieve_lib_state(state) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't retrieve library state") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* H5VLretrieve_lib_state() */ + + +/*--------------------------------------------------------------------------- + * Function: H5VLrestore_lib_state + * + * Purpose: Restores the internal state of the HDF5 library. + * + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 + * + *--------------------------------------------------------------------------- + */ +herr_t +H5VLrestore_lib_state(const void *state) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + /* Must use this, to avoid modifying the API context stack in FUNC_ENTER */ + FUNC_ENTER_API_NOINIT + H5TRACE1("e", "*x", state); + + /* Check args */ + if(NULL == state) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "invalid state pointer") + + /* Restore the library state */ + if(H5VL_restore_lib_state(state) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't restore library state") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* H5VLrestore_lib_state() */ + + +/*--------------------------------------------------------------------------- + * Function: H5VLreset_lib_state + * + * Purpose: Resets the internal state of the HDF5 library, undoing the + * affects of H5VLrestore_lib_state. + * + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. + * + * Note: This routine must be called as a "pair" with + * H5VLrestore_lib_state. It can be called before / after / + * independently of H5VLfree_lib_state. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Saturday, February 23, 2019 + * + *--------------------------------------------------------------------------- + */ +herr_t +H5VLreset_lib_state(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + /* Must use this, to avoid modifying the API context stack in FUNC_ENTER */ + FUNC_ENTER_API_NOINIT + H5TRACE0("e",""); + + /* Reset the library state */ + if(H5VL_reset_lib_state() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset library state") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* H5VLreset_lib_state() */ + + +/*--------------------------------------------------------------------------- + * Function: H5VLfree_lib_state + * + * Purpose: Free a retrieved library state. + * + * Note: This routine is _only_ for HDF5 VOL connector authors! It is + * _not_ part of the public API for HDF5 application developers. + * + * Note: This routine must be called as a "pair" with + * H5VLretrieve_lib_state. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 + * + *--------------------------------------------------------------------------- + */ +herr_t +H5VLfree_lib_state(void *state) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "*x", state); + + /* Check args */ + if(NULL == state) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "invalid state pointer") + + /* Free the library state */ + if(H5VL_free_lib_state(state) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "can't free library state") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5VLfree_lib_state() */ + diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 5a5d9ee..b785747 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -355,7 +355,7 @@ H5VL_copy_connector_info(const H5VL_class_t *connector, void **dst_info, else if(connector->info_cls.size > 0) { if(NULL == (new_connector_info = H5MM_malloc(connector->info_cls.size))) HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "connector info allocation failed") - HDmemcpy(new_connector_info, src_info, connector->info_cls.size); + H5MM_memcpy(new_connector_info, src_info, connector->info_cls.size); } /* end else-if */ else HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "no way to copy connector info") @@ -506,20 +506,25 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_free_connector_info(const H5VL_class_t *connector, void *info) +H5VL_free_connector_info(hid_t connector_id, void *info) { - herr_t ret_value = SUCCEED; /* Return value */ + H5VL_class_t *cls; /* VOL connector's class struct */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* Sanity checks */ - HDassert(connector); + /* Sanity check */ + HDassert(connector_id > 0); + + /* Check args and get class pointer */ + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a VOL connector ID") /* Only free info object, if it's non-NULL */ if(info) { /* Allow the connector to free info or do it ourselves */ - if(connector->info_cls.free) { - if((connector->info_cls.free)(info) < 0) + if(cls->info_cls.free) { + if((cls->info_cls.free)(info) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "connector info free request failed") } /* end if */ else @@ -544,18 +549,13 @@ done: herr_t H5VLfree_connector_info(hid_t connector_id, void *info) { - H5VL_class_t *cls; /* VOL connector's class struct */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API_NOINIT H5TRACE2("e", "i*x", connector_id, info); - /* Check args and get class pointer */ - if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") - /* Free the VOL connector info object */ - if(H5VL_free_connector_info(cls, info) < 0) + if(H5VL_free_connector_info(connector_id, info) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object") done: @@ -623,24 +623,9 @@ H5VLconnector_str_to_info(const char *str, hid_t connector_id, void **info) FUNC_ENTER_API_NOINIT H5TRACE3("e", "*si**x", str, connector_id, info); - /* Only deserialize string, if it's non-NULL */ - if(str) { - H5VL_class_t *cls; /* VOL connector's class struct */ - - /* Check args and get class pointer */ - if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") - - /* Allow the connector to deserialize info */ - if(cls->info_cls.from_str) { - if((cls->info_cls.from_str)(str, info) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTUNSERIALIZE, FAIL, "can't deserialize connector info") - } /* end if */ - else - *info = NULL; - } /* end if */ - else - *info = NULL; + /* Call internal routine */ + if(H5VL__connector_str_to_info(str, connector_id, info) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDECODE, FAIL, "can't deserialize connector info") done: FUNC_LEAVE_API_NOINIT(ret_value) @@ -755,84 +740,89 @@ done: /*------------------------------------------------------------------------- - * Function: H5VL_free_wrap_ctx + * Function: H5VL_wrap_object * - * Purpose: Free object wrapping context for a connector + * Purpose: Wrap an object with connector * - * Return: Success: Non-negative - * Failure: Negative + * Return: Success: Non-NULL + * Failure: NULL * *------------------------------------------------------------------------- */ -herr_t -H5VL_free_wrap_ctx(const H5VL_class_t *connector, void *wrap_ctx) +void * +H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, + H5I_type_t obj_type) { - herr_t ret_value = SUCCEED; /* Return value */ + void *ret_value; /* Return value */ - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_NOAPI(NULL) /* Sanity checks */ HDassert(connector); + HDassert(obj); - /* Only free wrap context, if it's non-NULL */ + /* Only wrap object if there's a wrap context */ if(wrap_ctx) { - /* Free the connector's object wrapping context */ - if((connector->wrap_cls.free_wrap_ctx)(wrap_ctx) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "connector wrap context free request failed") + /* Ask the connector to wrap the object */ + if(NULL == (ret_value = (connector->wrap_cls.wrap_object)(obj, obj_type, wrap_ctx))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't wrap object") } /* end if */ + else + ret_value = obj; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_free_wrap_ctx() */ +} /* end H5VL_wrap_object() */ /*--------------------------------------------------------------------------- - * Function: H5VLfree_wrap_ctx + * Function: H5VLwrap_object * - * Purpose: Release a VOL connector's object wrapping context + * Purpose: Asks a connector to wrap an underlying object. * - * Return: Success: Non-negative - * Failure: Negative + * Return: Success: Non-NULL + * Failure: NULL * *--------------------------------------------------------------------------- */ -herr_t -H5VLfree_wrap_ctx(void *wrap_ctx, hid_t connector_id) +void * +H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_ctx) { - H5VL_class_t *cls; /* VOL connector's class struct */ - herr_t ret_value = SUCCEED; /* Return value */ + H5VL_class_t *cls; /* VOL connector's class struct */ + void *ret_value = NULL; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE2("e", "*xi", wrap_ctx, connector_id); + H5TRACE4("*x", "*xIti*x", obj, obj_type, connector_id, wrap_ctx); /* Check args and get class pointer */ + if(NULL == obj) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid object") if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") - /* Release the VOL connector's object wrapper */ - if(H5VL_free_wrap_ctx(cls, wrap_ctx) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL connector object wrap context") + /* Wrap the object */ + if(NULL == (ret_value = H5VL_wrap_object(cls, wrap_ctx, obj, obj_type))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "unable to wrap object") done: FUNC_LEAVE_API_NOINIT(ret_value) -} /* H5VLfree_wrap_ctx() */ +} /* H5VLwrap_object */ /*------------------------------------------------------------------------- - * Function: H5VL_wrap_object + * Function: H5VL_unwrap_object * - * Purpose: Wrap an object with connector + * Purpose: Unwrap an object from connector * - * Return: Success: Non-negative - * Failure: Negative + * Return: Success: Non-NULL + * Failure: NULL * *------------------------------------------------------------------------- */ void * -H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, - H5I_type_t obj_type) +H5VL_unwrap_object(const H5VL_class_t *connector, void *obj) { - void *ret_value = SUCCEED; /* Return value */ + void *ret_value; /* Return value */ FUNC_ENTER_NOAPI(NULL) @@ -840,24 +830,24 @@ H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, HDassert(connector); HDassert(obj); - /* Only wrap object if there's a wrap context */ - if(wrap_ctx) { - /* Ask the connector to wrap the object */ - if(NULL == (ret_value = (connector->wrap_cls.wrap_object)(obj, obj_type, wrap_ctx))) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't wrap object") + /* Only unwrap object if there's an unwrap callback */ + if(connector->wrap_cls.wrap_object) { + /* Ask the connector to unwrap the object */ + if(NULL == (ret_value = (connector->wrap_cls.unwrap_object)(obj))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't unwrap object") } /* end if */ else ret_value = obj; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_wrap_object() */ +} /* end H5VL_unwrap_object() */ /*--------------------------------------------------------------------------- - * Function: H5VLwrap_object + * Function: H5VLunwrap_object * - * Purpose: Asks a connector to wrap an underlying object. + * Purpose: Unwrap an object from connector * * Return: Success: Non-NULL * Failure: NULL @@ -865,13 +855,13 @@ done: *--------------------------------------------------------------------------- */ void * -H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_ctx) +H5VLunwrap_object(void *obj, hid_t connector_id) { H5VL_class_t *cls; /* VOL connector's class struct */ void *ret_value = NULL; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE4("*x", "*xIti*x", obj, obj_type, connector_id, wrap_ctx); + H5TRACE2("*x", "*xi", obj, connector_id); /* Check args and get class pointer */ if(NULL == obj) @@ -879,13 +869,77 @@ H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_c if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") - /* Wrap the object */ - if(NULL == (ret_value = H5VL_wrap_object(cls, wrap_ctx, obj, obj_type))) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "unable to wrap object") + /* Unwrap the object */ + if(NULL == (ret_value = H5VL_unwrap_object(cls, obj))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "unable to unwrap object") done: FUNC_LEAVE_API_NOINIT(ret_value) -} /* H5VLwrap_object */ +} /* H5VLunwrap_object */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_free_wrap_ctx + * + * Purpose: Free object wrapping context for a connector + * + * Return: Success: Non-negative + * Failure: Negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_free_wrap_ctx(const H5VL_class_t *connector, void *wrap_ctx) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity checks */ + HDassert(connector); + + /* Only free wrap context, if it's non-NULL */ + if(wrap_ctx) { + /* Free the connector's object wrapping context */ + if((connector->wrap_cls.free_wrap_ctx)(wrap_ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "connector wrap context free request failed") + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_free_wrap_ctx() */ + + +/*--------------------------------------------------------------------------- + * Function: H5VLfree_wrap_ctx + * + * Purpose: Release a VOL connector's object wrapping context + * + * Return: Success: Non-negative + * Failure: Negative + * + *--------------------------------------------------------------------------- + */ +herr_t +H5VLfree_wrap_ctx(void *wrap_ctx, hid_t connector_id) +{ + H5VL_class_t *cls; /* VOL connector's class struct */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API_NOINIT + H5TRACE2("e", "*xi", wrap_ctx, connector_id); + + /* Check args and get class pointer */ + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* Release the VOL connector's object wrapper */ + if(H5VL_free_wrap_ctx(cls, wrap_ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL connector object wrap context") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* H5VLfree_wrap_ctx() */ /*------------------------------------------------------------------------- diff --git a/src/H5VLint.c b/src/H5VLint.c index 5aa25d2..1b735f5 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -29,14 +29,19 @@ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5CXprivate.h" /* API Contexts */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5FLprivate.h" /* Free lists */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Tprivate.h" /* Datatypes */ -#include "H5VLpkg.h" /* Virtual Object Layer */ +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5FLprivate.h" /* Free lists */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5PLprivate.h" /* Plugins */ +#include "H5Tprivate.h" /* Datatypes */ +#include "H5VLpkg.h" /* Virtual Object Layer */ + +/* VOL connectors */ +#include "H5VLnative.h" /* Native VOL connector */ +#include "H5VLpassthru.h" /* Pass-through VOL connector */ /****************/ @@ -51,10 +56,28 @@ /* Object wrapping context info */ typedef struct H5VL_wrap_ctx_t { unsigned rc; /* Ref. count for the # of times the context was set / reset */ - const H5VL_t *connector; /* VOL connector for "outermost" class to start wrap */ + H5VL_t *connector; /* VOL connector for "outermost" class to start wrap */ void *obj_wrap_ctx; /* "wrap context" for outermost connector */ } H5VL_wrap_ctx_t; +/* Information needed for iterating over the registered VOL connector hid_t IDs. + * The name or value of the new VOL connector that is being registered is + * stored in the name (or value) field and the found_id field is initialized to + * H5I_INVALID_HID (-1). If we find a VOL connector with the same name / value, + * we set the found_id field to the existing ID for return to the function. + */ +typedef struct { + /* IN */ + H5VL_get_connector_kind_t kind; /* Which kind of connector search to make */ + union { + const char *name; /* The name of the VOL connector to check */ + H5VL_class_value_t value; /* The value of the VOL connector to check */ + } u; + + /* OUT */ + hid_t found_id; /* The connector ID, if we found a match */ +} H5VL_get_connector_ud_t; + /********************/ /* Package Typedefs */ @@ -65,10 +88,15 @@ typedef struct H5VL_wrap_ctx_t { /* Local Prototypes */ /********************/ static herr_t H5VL__free_cls(H5VL_class_t *cls); +static int H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data); +static herr_t H5VL__set_def_conn(void); static void *H5VL__wrap_obj(void *obj, H5I_type_t obj_type); static H5VL_object_t *H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t wrap_obj); +static int64_t H5VL__conn_inc_rc(H5VL_t *connector); +static int64_t H5VL__conn_dec_rc(H5VL_t *connector); static void *H5VL__object(hid_t id, H5I_type_t obj_type); +static herr_t H5VL__free_vol_wrapper(H5VL_wrap_ctx_t *vol_wrap_ctx); /*********************/ @@ -83,6 +111,7 @@ hbool_t H5_PKG_INIT_VAR = FALSE; /* Library Private Variables */ /*****************************/ + /*******************/ /* Local Variables */ /*******************/ @@ -107,21 +136,27 @@ H5FL_DEFINE(H5VL_object_t); /* Declare a free list to manage the H5VL_wrap_ctx_t struct */ H5FL_DEFINE_STATIC(H5VL_wrap_ctx_t); +/* Default VOL connector */ +static H5VL_connector_prop_t H5VL_def_conn_s = {-1, NULL}; + /*------------------------------------------------------------------------- - * Function: H5VL_init + * Function: H5VL_init_phase1 * - * Purpose: Initialize the interface from some other package + * Purpose: Initialize the interface from some other package. This should + * be followed with a call to H5VL_init_phase2 after the H5P + * interface is completely set up, finish setting up the H5VL + * information. * - * Return: Success: Non-negative * + * Return: Success: Non-negative * Failure: Negative * *------------------------------------------------------------------------- */ herr_t -H5VL_init(void) +H5VL_init_phase1(void) { herr_t ret_value = SUCCEED; /* Return value */ @@ -131,7 +166,36 @@ H5VL_init(void) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_init() */ +} /* end H5VL_init_phase1() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_init_phase2 + * + * Purpose: Finish initializing the interface from some other package. + * + * Note: This is broken out as a separate routine to avoid a circular + * reference with the H5P package. + * + * Return: Success: Non-negative + * Failure: Negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_init_phase2(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Set up the default VOL connector in the default FAPL */ + if(H5VL__set_def_conn() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "unable to set default VOL connector") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_init_phase2() */ /*------------------------------------------------------------------------- @@ -148,12 +212,12 @@ done: herr_t H5VL__init_package(void) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE /* Initialize the atom group for the VL IDs */ - if (H5I_register_type(H5I_VOL_CLS) < 0) + if(H5I_register_type(H5I_VOL_CLS) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize H5VL interface") done: @@ -180,17 +244,27 @@ H5VL_term_package(void) FUNC_ENTER_NOAPI_NOINIT_NOERR if(H5_PKG_INIT_VAR) { - if (H5I_nmembers(H5I_VOL) > 0) { - (void)H5I_clear_type(H5I_VOL, FALSE, FALSE); + if(H5VL_def_conn_s.connector_id > 0) { + /* Release the default VOL connector */ + (void)H5VL_conn_free(&H5VL_def_conn_s); + H5VL_def_conn_s.connector_id = -1; + H5VL_def_conn_s.connector_info = NULL; n++; } /* end if */ else { - /* Destroy the VOL connector ID group */ - n += (H5I_dec_type_ref(H5I_VOL) > 0); - - /* Mark interface as closed */ - if (0 == n) - H5_PKG_INIT_VAR = FALSE; + if(H5I_nmembers(H5I_VOL) > 0) { + /* Unregister all VOL connectors */ + (void)H5I_clear_type(H5I_VOL, FALSE, FALSE); + n++; + } /* end if */ + else { + /* Destroy the VOL connector ID group */ + n += (H5I_dec_type_ref(H5I_VOL) > 0); + + /* Mark interface as closed */ + if(0 == n) + H5_PKG_INIT_VAR = FALSE; + } /* end else */ } /* end else */ } /* end if */ @@ -234,6 +308,182 @@ done: /*------------------------------------------------------------------------- + * Function: H5VL__get_connector_cb + * + * Purpose: Callback routine to search through registered VOLs + * + * Return: Success: H5_ITER_STOP if the class and op_data name + * members match. H5_ITER_CONT otherwise. + * Failure: Can't fail + * + * Programmer: Dana Robinson + * June 22, 2017 + * + *------------------------------------------------------------------------- + */ +static int +H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data) +{ + H5VL_get_connector_ud_t *op_data = (H5VL_get_connector_ud_t *)_op_data; /* User data for callback */ + H5VL_class_t *cls = (H5VL_class_t *)obj; + int ret_value = H5_ITER_CONT; /* Callback return value */ + + FUNC_ENTER_STATIC_NOERR + + if(H5VL_GET_CONNECTOR_BY_NAME == op_data->kind) { + if(0 == HDstrcmp(cls->name, op_data->u.name)) { + op_data->found_id = id; + ret_value = H5_ITER_STOP; + } /* end if */ + } /* end if */ + else { + HDassert(H5VL_GET_CONNECTOR_BY_VALUE == op_data->kind); + if(cls->value == op_data->u.value) { + op_data->found_id = id; + ret_value = H5_ITER_STOP; + } /* end if */ + } /* end else */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__get_connector_cb() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__set_def_conn + * + * Purpose: Parses a string that contains the default VOL connector for + * the library. + * + * Note: Usually from the environment variable "HDF5_VOL_CONNECTOR", + * but could be from elsewhere. + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Jordan Henderson + * November 2018 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL__set_def_conn(void) +{ + H5P_genplist_t *def_fapl; /* Default file access property list */ + H5P_genclass_t *def_fapclass; /* Default file access property class */ + const char *env_var; /* Environment variable for default VOL connector */ + char *buf = NULL; /* Buffer for tokenizing string */ + hid_t connector_id = -1; /* VOL conntector ID */ + void *vol_info = NULL; /* VOL connector info */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(H5VL_def_conn_s.connector_id == (-1)); + HDassert(H5VL_def_conn_s.connector_info == NULL); + + /* Check for environment variable set */ + env_var = HDgetenv("HDF5_VOL_CONNECTOR"); + + /* Only parse the string if it's set */ + if(env_var && *env_var) { + char *lasts = NULL; /* Context pointer for strtok_r() call */ + const char *tok = NULL; /* Token from strtok_r call */ + htri_t connector_is_registered; /* Whether connector is already registered */ + + /* Duplicate the string to parse, as it is modified as we go */ + if(NULL == (buf = H5MM_strdup(env_var))) + HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate memory for environment variable string") + + /* Get the first 'word' of the environment variable. + * If it's nothing (environment variable was whitespace) return error. + */ + if(NULL == (tok = HDstrtok_r(buf, " \t\n\r", &lasts))) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "VOL connector environment variable set empty?") + + /* First, check to see if the connector is already registered */ + if((connector_is_registered = H5VL__is_connector_registered(tok)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't check if VOL connector already registered") + else if(connector_is_registered) { + /* Retrieve the ID of the already-registered VOL connector */ + if((connector_id = H5VL__get_connector_id(tok, FALSE)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get VOL connector ID") + } /* end else-if */ + else { + /* Check for VOL connectors that ship with the library */ + if(!HDstrcmp(tok, "native")) { + connector_id = H5VL_NATIVE; + if(H5I_inc_ref(connector_id, FALSE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINC, FAIL, "can't increment VOL connector refcount") + } /* end if */ + else if(!HDstrcmp(tok, "pass_through")) { + connector_id = H5VL_PASSTHRU; + if(H5I_inc_ref(connector_id, FALSE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINC, FAIL, "can't increment VOL connector refcount") + } /* end else-if */ + else { + /* Register the VOL connector */ + /* (NOTE: No provisions for vipl_id currently) */ + if((connector_id = H5VL__register_connector_by_name(tok, FALSE, H5P_DEFAULT)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "can't register connector") + } /* end else */ + } /* end else */ + + /* Was there any connector info specified in the environment variable? */ + if(NULL != (tok = HDstrtok_r(NULL, " \t\n\r", &lasts))) + if(H5VL__connector_str_to_info(tok, connector_id, &vol_info) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDECODE, FAIL, "can't deserialize connector info") + + /* Set the default VOL connector */ + H5VL_def_conn_s.connector_id = connector_id; + H5VL_def_conn_s.connector_info = vol_info; + } /* end if */ + else { + /* Set the default VOL connector */ + H5VL_def_conn_s.connector_id = H5_DEFAULT_VOL; + H5VL_def_conn_s.connector_info = NULL; + + /* Increment the ref count on the default connector */ + if(H5I_inc_ref(H5VL_def_conn_s.connector_id, FALSE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINC, FAIL, "can't increment VOL connector refcount") + } /* end else */ + + /* Get default file access pclass */ + if(NULL == (def_fapclass = (H5P_genclass_t *)H5I_object(H5P_FILE_ACCESS))) + HGOTO_ERROR(H5E_VOL, H5E_BADATOM, FAIL, "can't find object for default file access property class ID") + + /* Change the default VOL for the default file access pclass */ + if(H5P_reset_vol_class(def_fapclass, &H5VL_def_conn_s) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set default VOL connector for default file access property class") + + /* Get default file access plist */ + if(NULL == (def_fapl = (H5P_genplist_t *)H5I_object(H5P_FILE_ACCESS_DEFAULT))) + HGOTO_ERROR(H5E_VOL, H5E_BADATOM, FAIL, "can't find object for default fapl ID") + + /* Change the default VOL for the default FAPL */ + if(H5P_set_vol(def_fapl, H5VL_def_conn_s.connector_id, H5VL_def_conn_s.connector_info) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set default VOL connector for default FAPL") + +done: + /* Clean up on error */ + if(ret_value < 0) { + if(vol_info) + if(H5VL_free_connector_info(connector_id, vol_info) < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "can't free VOL connector info") + if(connector_id >= 0) + /* The H5VL_class_t struct will be freed by this function */ + if(H5I_dec_ref(connector_id) < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to unregister VOL connector") + } /* end if */ + + /* Clean up */ + H5MM_xfree(buf); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__set_def_conn() */ + + +/*------------------------------------------------------------------------- * Function: H5VL__wrap_obj * * Purpose: Wraps a library object with possible VOL connector wrappers, to @@ -317,7 +567,7 @@ H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t new_vol_obj->data = object; /* Bump the reference count on the VOL connector */ - vol_connector->nrefs++; + H5VL__conn_inc_rc(vol_connector); /* If this is a datatype, we have to hide the VOL object under the H5T_t pointer */ if(H5I_DATATYPE == type) { @@ -393,29 +643,22 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_conn_free(const H5VL_connector_prop_t *info) +H5VL_conn_free(const H5VL_connector_prop_t *connector_prop) { herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - if(info) { + if(connector_prop) { /* Free the connector info (if it exists) and decrement the ID */ - if(info->connector_id > 0) { - if(info->connector_info) { - H5VL_class_t *connector; /* Pointer to connector */ - - /* Retrieve the connector for the ID */ - if(NULL == (connector = (H5VL_class_t *)H5I_object(info->connector_id))) - HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a VOL connector ID") - + if(connector_prop->connector_id > 0) { + if(connector_prop->connector_info) /* Free the connector info */ - if(H5VL_free_connector_info(connector, (void *)info->connector_info) < 0) /* Casting away const OK - QAK */ + if(H5VL_free_connector_info(connector_prop->connector_id, (void *)connector_prop->connector_info) < 0) /* Casting away const OK - QAK */ HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object") - } /* end if */ /* Decrement reference count for connector ID */ - if(H5I_dec_ref(info->connector_id) < 0) + if(H5I_dec_ref(connector_prop->connector_id) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "can't decrement reference count for connector ID") } /* end if */ } /* end if */ @@ -550,6 +793,76 @@ done: /*------------------------------------------------------------------------- + * Function: H5VL__conn_inc_rc + * + * Purpose: Wrapper to increment the ref. count on a connector. + * + * Return: Current ref. count (can't fail) + * + * Programmer: Quincey Koziol + * February 23, 2019 + * + *------------------------------------------------------------------------- + */ +static int64_t +H5VL__conn_inc_rc(H5VL_t *connector) +{ + FUNC_ENTER_STATIC_NOERR + + /* Check arguments */ + HDassert(connector); + + /* Increment refcount for connector */ + connector->nrefs++; + + FUNC_LEAVE_NOAPI(connector->nrefs) +} /* end H5VL__conn_inc_rc() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__conn_dec_rc + * + * Purpose: Wrapper to decrement the ref. count on a connector. + * + * Return: Current ref. count (>=0) on success, <0 on failure + * + * Programmer: Quincey Koziol + * February 23, 2019 + * + *------------------------------------------------------------------------- + */ +static int64_t +H5VL__conn_dec_rc(H5VL_t *connector) +{ + int64_t ret_value = -1; /* Return value */ + + FUNC_ENTER_STATIC + + /* Check arguments */ + HDassert(connector); + + /* Decrement refcount for connector */ + connector->nrefs--; + + /* Check for last reference */ + if(0 == connector->nrefs) { + if(H5I_dec_ref(connector->id) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on VOL connector") + H5FL_FREE(H5VL_t, connector); + + /* Set return value */ + ret_value = 0; + } /* end if */ + else + /* Set return value */ + ret_value = connector->nrefs; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__conn_dec_rc() */ + + +/*------------------------------------------------------------------------- * Function: H5VL_free_object * * Purpose: Wrapper to unregister an object ID with a VOL aux struct @@ -562,20 +875,16 @@ done: herr_t H5VL_free_object(H5VL_object_t *vol_obj) { - herr_t ret_value = SUCCEED; + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(SUCCEED) + FUNC_ENTER_NOAPI(FAIL) /* Check arguments */ HDassert(vol_obj); - vol_obj->connector->nrefs --; - - if(0 == vol_obj->connector->nrefs) { - if(H5I_dec_ref(vol_obj->connector->id) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on VOL connector") - vol_obj->connector = H5FL_FREE(H5VL_t, vol_obj->connector); - } /* end if */ + /* Decrement refcount on connector */ + if(H5VL__conn_dec_rc(vol_obj->connector) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on VOL connector") vol_obj = H5FL_FREE(H5VL_object_t, vol_obj); @@ -595,6 +904,9 @@ done: * * Failure: H5I_INVALID_HID * + * Programmer: Dana Robinson + * June 22, 2017 + * *------------------------------------------------------------------------- */ hid_t @@ -610,9 +922,9 @@ H5VL_register_connector(const void *_cls, hbool_t app_ref, hid_t vipl_id) HDassert(cls); /* Copy the class structure so the caller can reuse or free it */ - if (NULL == (saved = H5FL_CALLOC(H5VL_class_t))) + if(NULL == (saved = H5FL_MALLOC(H5VL_class_t))) HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, H5I_INVALID_HID, "memory allocation failed for VOL connector class struct") - HDmemcpy(saved, cls, sizeof(H5VL_class_t)); + H5MM_memcpy(saved, cls, sizeof(H5VL_class_t)); if(NULL == (saved->name = H5MM_strdup(cls->name))) HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, H5I_INVALID_HID, "memory allocation failed for VOL connector name") @@ -621,23 +933,319 @@ H5VL_register_connector(const void *_cls, hbool_t app_ref, hid_t vipl_id) HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to init VOL connector") /* Create the new class ID */ - if ((ret_value = H5I_register(H5I_VOL, saved, app_ref)) < 0) + if((ret_value = H5I_register(H5I_VOL, saved, app_ref)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID") done: - if (ret_value < 0 && saved) { - if (saved->name) + if(ret_value < 0 && saved) { + if(saved->name) H5MM_xfree((void *)(saved->name)); /* Casting away const OK -QAK */ H5FL_FREE(H5VL_class_t, saved); - } + } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_register_connector() */ /*------------------------------------------------------------------------- - * Function: H5VL_get_connector_name + * Function: H5VL__register_connector + * + * Purpose: Registers a new VOL connector as a member of the virtual object + * layer class. + * + * Return: Success: A VOL connector ID which is good until the + * library is closed or the connector is + * unregistered. + * + * Failure: H5I_INVALID_HID + * + * Programmer: Dana Robinson + * June 22, 2017 + * + *------------------------------------------------------------------------- + */ +hid_t +H5VL__register_connector(const H5VL_class_t *cls, hbool_t app_ref, hid_t vipl_id) +{ + H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Set up op data for iteration */ + op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; + op_data.u.name = cls->name; + op_data.found_id = H5I_INVALID_HID; + + /* Check if connector is already registered */ + if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL IDs") + + /* Increment the ref count on the existing VOL connector ID, if it's already registered */ + if(op_data.found_id != H5I_INVALID_HID) { + if(H5I_inc_ref(op_data.found_id, app_ref) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") + ret_value = op_data.found_id; + } /* end if */ + else { + /* Create a new class ID */ + if((ret_value = H5VL_register_connector(cls, app_ref, vipl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector") + } /* end else */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__register_connector() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__register_connector_by_name + * + * Purpose: Registers a new VOL connector as a member of the virtual object + * layer class. + * + * Return: Success: A VOL connector ID which is good until the + * library is closed or the connector is + * unregistered. + * + * Failure: H5I_INVALID_HID + * + * Programmer: Dana Robinson + * June 22, 2017 + * + *------------------------------------------------------------------------- + */ +hid_t +H5VL__register_connector_by_name(const char *name, hbool_t app_ref, hid_t vipl_id) +{ + H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Set up op data for iteration */ + op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; + op_data.u.name = name; + op_data.found_id = H5I_INVALID_HID; + + /* Check if connector is already registered */ + if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL ids") + + /* If connector alread registered, increment ref count on ID and return ID */ + if(op_data.found_id != H5I_INVALID_HID) { + if(H5I_inc_ref(op_data.found_id, app_ref) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") + ret_value = op_data.found_id; + } /* end if */ + else { + H5PL_key_t key; + const H5VL_class_t *cls; + + /* Try loading the connector */ + key.vol.kind = H5VL_GET_CONNECTOR_BY_NAME; + key.vol.u.name = name; + if(NULL == (cls = (const H5VL_class_t *)H5PL_load(H5PL_TYPE_VOL, &key))) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to load VOL connector") + + /* Register the connector we loaded */ + if((ret_value = H5VL_register_connector(cls, app_ref, vipl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID") + } /* end else */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__register_connector_by_name() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__register_connector_by_value + * + * Purpose: Registers a new VOL connector as a member of the virtual object + * layer class. + * + * Return: Success: A VOL connector ID which is good until the + * library is closed or the connector is + * unregistered. + * + * Failure: H5I_INVALID_HID + * + * Programmer: Dana Robinson + * June 22, 2017 + * + *------------------------------------------------------------------------- + */ +hid_t +H5VL__register_connector_by_value(H5VL_class_value_t value, hbool_t app_ref, hid_t vipl_id) +{ + H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Set up op data for iteration */ + op_data.kind = H5VL_GET_CONNECTOR_BY_VALUE; + op_data.u.value = value; + op_data.found_id = H5I_INVALID_HID; + + /* Check if connector is already registered */ + if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL ids") + + /* If connector alread registered, increment ref count on ID and return ID */ + if(op_data.found_id != H5I_INVALID_HID) { + if(H5I_inc_ref(op_data.found_id, app_ref) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") + ret_value = op_data.found_id; + } /* end if */ + else { + H5PL_key_t key; + const H5VL_class_t *cls; + + /* Try loading the connector */ + key.vol.kind = H5VL_GET_CONNECTOR_BY_VALUE; + key.vol.u.value = value; + if(NULL == (cls = (const H5VL_class_t *)H5PL_load(H5PL_TYPE_VOL, &key))) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to load VOL connector") + + /* Register the connector we loaded */ + if((ret_value = H5VL_register_connector(cls, app_ref, vipl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID") + } /* end else */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__register_connector_by_value() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__is_connector_registered + * + * Purpose: Checks if a connector with a particular name is registered. + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Dana Robinson + * June 17, 2017 + * + *------------------------------------------------------------------------- + */ +htri_t +H5VL__is_connector_registered(const char *name) +{ + H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ + htri_t ret_value = FALSE; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Set up op data for iteration */ + op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; + op_data.u.name = name; + op_data.found_id = H5I_INVALID_HID; + + /* Find connector with name */ + if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_BADITER, FAIL, "can't iterate over VOL connectors") + + /* Found a connector with that name */ + if(op_data.found_id != H5I_INVALID_HID) + ret_value = TRUE; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__is_connector_registered() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__get_connector_id + * + * Purpose: Retrieves the ID for a registered VOL connector. + * + * Return: Positive if the VOL class has been registered + * Negative on error (if the class is not a valid class or not registered) + * + * Programmer: Dana Robinson + * June 17, 2017 + * + *------------------------------------------------------------------------- + */ +hid_t +H5VL__get_connector_id(const char *name, hbool_t is_api) +{ + H5VL_get_connector_ud_t op_data; /* Callback info for connector search */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Set up op data for iteration */ + op_data.kind = H5VL_GET_CONNECTOR_BY_NAME; + op_data.u.name = name; + op_data.found_id = H5I_INVALID_HID; + + /* Find connector with name */ + if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0) + HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL connectors") + + /* Found a connector with that name */ + if(op_data.found_id != H5I_INVALID_HID) { + if(H5I_inc_ref(op_data.found_id, is_api) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") + ret_value = op_data.found_id; + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__get_connector_id() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__connector_str_to_info + * + * Purpose: Deserializes a string into a connector's info object + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * March 2, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL__connector_str_to_info(const char *str, hid_t connector_id, void **info) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Only deserialize string, if it's non-NULL */ + if(str) { + H5VL_class_t *cls; /* VOL connector's class struct */ + + /* Check args and get class pointer */ + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* Allow the connector to deserialize info */ + if(cls->info_cls.from_str) { + if((cls->info_cls.from_str)(str, info) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTUNSERIALIZE, FAIL, "can't deserialize connector info") + } /* end if */ + else + *info = NULL; + } /* end if */ + else + *info = NULL; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__connector_str_to_info() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__get_connector_name * * Purpose: Private version of H5VLget_connector_name * @@ -647,14 +1255,14 @@ done: *------------------------------------------------------------------------- */ ssize_t -H5VL_get_connector_name(hid_t id, char *name /*out*/, size_t size) +H5VL__get_connector_name(hid_t id, char *name /*out*/, size_t size) { H5VL_object_t *vol_obj; const H5VL_class_t *cls; size_t len; ssize_t ret_value = -1; - FUNC_ENTER_NOAPI(FAIL) + FUNC_ENTER_PACKAGE /* get the object pointer */ if (NULL == (vol_obj = H5VL_vol_object(id))) @@ -674,7 +1282,7 @@ H5VL_get_connector_name(hid_t id, char *name /*out*/, size_t size) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_get_connector_name() */ +} /* end H5VL__get_connector_name() */ /*------------------------------------------------------------------------- @@ -750,6 +1358,32 @@ H5VL_object_data(const H5VL_object_t *vol_obj) /*------------------------------------------------------------------------- + * Function: H5VL_object_unwrap + * + * Purpose: Correctly unwrap the 'data' field for a VOL object (H5VL_object), + * even for nested / stacked VOL connectors. + * + * Return: Success: Object pointer + * Failure: NULL + * + *------------------------------------------------------------------------- + */ +void * +H5VL_object_unwrap(const H5VL_object_t *vol_obj) +{ + void *ret_value = NULL; + + FUNC_ENTER_NOAPI(NULL) + + if(NULL == (ret_value = H5VL_unwrap_object(vol_obj->connector->cls, vol_obj->data))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't unwrap object") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_object_unwrap() */ + + +/*------------------------------------------------------------------------- * Function: H5VL__object * * Purpose: Internal function to return the VOL object pointer associated @@ -836,7 +1470,7 @@ H5VL_object(hid_t id) /* Get the underlying object */ if(NULL == (ret_value = H5VL__object(id, H5I_get_type(id)))) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, NULL, "can't retrieve object for ID") + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't retrieve object for ID") done: FUNC_LEAVE_NOAPI(ret_value) @@ -952,6 +1586,189 @@ done: /*------------------------------------------------------------------------- + * Function: H5VL_retrieve_lib_state + * + * Purpose: Retrieve the state of the library. + * + * Note: Currently just retrieves the API context state, but could be + * expanded in the future. + * + * Return: Success: Non-negative, *state set + * Failure: Negative, *state unset + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_retrieve_lib_state(void **state) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity checks */ + HDassert(state); + + /* Retrieve the API context state */ + if(H5CX_retrieve_state((H5CX_state_t **)state) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get API context state") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_retrieve_lib_state() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_restore_lib_state + * + * Purpose: Restore the state of the library. + * + * Note: Currently just restores the API context state, but could be + * expanded in the future. + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_restore_lib_state(const void *state) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity checks */ + HDassert(state); + + /* Push a new API context on the stack */ + if(H5CX_push() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't push API context") + + /* Restore the API context state */ + if(H5CX_restore_state((const H5CX_state_t *)state) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set API context state") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_restore_lib_state() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_reset_lib_state + * + * Purpose: Reset the state of the library, undoing affects of + * H5VL_restore_lib_state. + * + * Note: Currently just resets the API context state, but could be + * expanded in the future. + * + * Note: This routine must be called as a "pair" with + * H5VL_restore_lib_state. It can be called before / after / + * independently of H5VL_free_lib_state. + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Saturday, February 23, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_reset_lib_state(void) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Pop the API context off the stack */ + if(H5CX_pop() < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't pop API context") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_reset_lib_state() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_free_lib_state + * + * Purpose: Free a library state. + * + * Note: This routine must be called as a "pair" with + * H5VL_retrieve_lib_state. + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Thursday, January 10, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_free_lib_state(void *state) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity checks */ + HDassert(state); + + /* Free the API context state */ + if(H5CX_free_state((H5CX_state_t *)state) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "can't free API context state") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_free_lib_state() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__free_vol_wrapper + * + * Purpose: Free object wrapping context for VOL connector + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Wednesday, January 9, 2019 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL__free_vol_wrapper(H5VL_wrap_ctx_t *vol_wrap_ctx) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(vol_wrap_ctx); + HDassert(0 == vol_wrap_ctx->rc); + HDassert(vol_wrap_ctx->connector); + HDassert(vol_wrap_ctx->connector->cls); + + /* If there is a VOL connector object wrapping context, release it */ + if(vol_wrap_ctx->obj_wrap_ctx) + /* Release the VOL connector's object wrapping context */ + if((*vol_wrap_ctx->connector->cls->wrap_cls.free_wrap_ctx)(vol_wrap_ctx->obj_wrap_ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release connector's object wrapping context") + + /* Decrement refcount on connector */ + if(H5VL__conn_dec_rc(vol_wrap_ctx->connector) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on VOL connector") + + /* Release object wrapping context */ + H5FL_FREE(H5VL_wrap_ctx_t, vol_wrap_ctx); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__free_vol_wrapper() */ + + +/*------------------------------------------------------------------------- * Function: H5VL_set_vol_wrapper * * Purpose: Set up object wrapping context for current VOL connector @@ -961,7 +1778,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_set_vol_wrapper(void *obj, const H5VL_t *connector) +H5VL_set_vol_wrapper(void *obj, H5VL_t *connector) { H5VL_wrap_ctx_t *vol_wrap_ctx = NULL; /* Object wrapping context */ void *obj_wrap_ctx = NULL; /* VOL connector's wrapping context */ @@ -993,8 +1810,11 @@ H5VL_set_vol_wrapper(void *obj, const H5VL_t *connector) if(NULL == (vol_wrap_ctx = H5FL_MALLOC(H5VL_wrap_ctx_t))) HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate VOL wrap context") + /* Increment the outstanding objects that are using the connector */ + H5VL__conn_inc_rc(connector); + /* Set up VOL object wrapper context */ - vol_wrap_ctx->rc = 1;; + vol_wrap_ctx->rc = 1; vol_wrap_ctx->connector = connector; vol_wrap_ctx->obj_wrap_ctx = obj_wrap_ctx; } /* end if */ @@ -1016,6 +1836,80 @@ done: /*------------------------------------------------------------------------- + * Function: H5VL_inc_vol_wrapper + * + * Purpose: Increment refcount on object wrapping context + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Wednesday, January 9, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_inc_vol_wrapper(void *_vol_wrap_ctx) +{ + H5VL_wrap_ctx_t *vol_wrap_ctx = (H5VL_wrap_ctx_t *)_vol_wrap_ctx; /* VOL object wrapping context */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Check for valid, active VOL object wrap context */ + if(NULL == vol_wrap_ctx) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "no VOL object wrap context?") + if(0 == vol_wrap_ctx->rc) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "bad VOL object wrap context refcount?") + + /* Increment ref count on wrapping context */ + vol_wrap_ctx->rc++; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_inc_vol_wrapper() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_dec_vol_wrapper + * + * Purpose: Decrement refcount on object wrapping context, releasing it + * if the refcount drops to zero. + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Wednesday, January 9, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_dec_vol_wrapper(void *_vol_wrap_ctx) +{ + H5VL_wrap_ctx_t *vol_wrap_ctx = (H5VL_wrap_ctx_t *)_vol_wrap_ctx; /* VOL object wrapping context */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Check for valid, active VOL object wrap context */ + if(NULL == vol_wrap_ctx) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "no VOL object wrap context?") + if(0 == vol_wrap_ctx->rc) + HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "bad VOL object wrap context refcount?") + + /* Decrement ref count on wrapping context */ + vol_wrap_ctx->rc--; + + /* Release context if the ref count drops to zero */ + if(0 == vol_wrap_ctx->rc) + if(H5VL__free_vol_wrapper(vol_wrap_ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL object wrapping context") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_dec_vol_wrapper() */ + + +/*------------------------------------------------------------------------- * Function: H5VL_reset_vol_wrapper * * Purpose: Reset object wrapping context for current VOL connector @@ -1045,25 +1939,18 @@ H5VL_reset_vol_wrapper(void) /* Release context if the ref count drops to zero */ if(0 == vol_wrap_ctx->rc) { - /* If there is a VOL connector object wrapping context, release it */ - if(vol_wrap_ctx->obj_wrap_ctx) { - /* Release the VOL connector's object wrapping context */ - if((*vol_wrap_ctx->connector->cls->wrap_cls.free_wrap_ctx)(vol_wrap_ctx->obj_wrap_ctx) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release connector's object wrapping context") - } /* end if */ - /* Release object wrapping context */ - H5FL_FREE(H5VL_wrap_ctx_t, vol_wrap_ctx); + if(H5VL__free_vol_wrapper(vol_wrap_ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL object wrapping context") /* Reset the wrapper context */ if(H5CX_set_vol_wrap_ctx(NULL) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL object wrap context") } /* end if */ - else { + else /* Save the updated wrapper context */ if(H5CX_set_vol_wrap_ctx(vol_wrap_ctx) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL object wrap context") - } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5VLnative.c b/src/H5VLnative.c index f4f3b5f..7848c5d 100644 --- a/src/H5VLnative.c +++ b/src/H5VLnative.c @@ -50,6 +50,7 @@ static H5VL_class_t H5VL_native_cls_g = { NULL, /* get_object */ NULL, /* get_wrap_ctx */ NULL, /* wrap_object */ + NULL, /* unwrap_object */ NULL /* free_wrap_ctx */ }, { /* attribute_cls */ diff --git a/src/H5VLnative_file.c b/src/H5VLnative_file.c index 624cd30..8903911 100644 --- a/src/H5VLnative_file.c +++ b/src/H5VLnative_file.c @@ -228,6 +228,19 @@ H5VL__native_file_get(void *obj, H5VL_file_get_t get_type, break; } + /* H5Fget_fileno */ + case H5VL_FILE_GET_FILENO: + { + unsigned long *fileno = HDva_arg(arguments, unsigned long *); + unsigned long my_fileno = 0; + + f = (H5F_t *)obj; + H5F_GET_FILENO(f, my_fileno); + *fileno = my_fileno; /* sigh */ + + break; + } + /* H5Fget_name */ case H5VL_FILE_GET_NAME: { diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index fe72000..85a9346 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -20,6 +20,11 @@ * include _any_ private HDF5 header files. This connector should * therefore only make public HDF5 API calls and use standard C / * POSIX calls. + * + * Note that the HDF5 error stack must be preserved on code paths + * that could be invoked when the underlying VOL connector's + * callback can fail. + * */ @@ -93,9 +98,10 @@ static herr_t H5VL_pass_through_str_to_info(const char *str, void **info); /* VOL object wrap / retrieval callbacks */ static void *H5VL_pass_through_get_object(const void *obj); static herr_t H5VL_pass_through_get_wrap_ctx(const void *obj, void **wrap_ctx); -static herr_t H5VL_pass_through_free_wrap_ctx(void *obj); static void *H5VL_pass_through_wrap_object(void *obj, H5I_type_t obj_type, void *wrap_ctx); +static void *H5VL_pass_through_unwrap_object(void *obj); +static herr_t H5VL_pass_through_free_wrap_ctx(void *obj); /* Attribute callbacks */ static void *H5VL_pass_through_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); @@ -189,6 +195,7 @@ static const H5VL_class_t H5VL_pass_through_g = { H5VL_pass_through_get_object, /* get_object */ H5VL_pass_through_get_wrap_ctx, /* get_wrap_ctx */ H5VL_pass_through_wrap_object, /* wrap_object */ + H5VL_pass_through_unwrap_object, /* unwrap_object */ H5VL_pass_through_free_wrap_ctx, /* free_wrap_ctx */ }, { /* attribute_cls */ @@ -297,6 +304,9 @@ H5VL_pass_through_new_obj(void *under_obj, hid_t under_vol_id) * * Purpose: Release a pass through object * + * Note: Take care to preserve the current HDF5 error stack + * when calling HDF5 API calls. + * * Return: Success: 0 * Failure: -1 * @@ -308,7 +318,14 @@ H5VL_pass_through_new_obj(void *under_obj, hid_t under_vol_id) static herr_t H5VL_pass_through_free_obj(H5VL_pass_through_t *obj) { + hid_t err_id; + + err_id = H5Eget_current_stack(); + H5Idec_ref(obj->under_vol_id); + + H5Eset_current_stack(err_id); + free(obj); return 0; @@ -332,11 +349,8 @@ H5VL_pass_through_free_obj(H5VL_pass_through_t *obj) hid_t H5VL_pass_through_register(void) { - /* Clear the error stack */ - H5Eclear2(H5E_DEFAULT); - /* Singleton register the pass-through VOL connector ID */ - if(H5I_VOL != H5Iget_type(H5VL_PASSTHRU_g)) + if(H5VL_PASSTHRU_g < 0) H5VL_PASSTHRU_g = H5VLregister_connector(&H5VL_pass_through_g, H5P_DEFAULT); return H5VL_PASSTHRU_g; @@ -476,6 +490,9 @@ H5VL_pass_through_info_cmp(int *cmp_value, const void *_info1, const void *_info * * Purpose: Release an info object for the connector. * + * Note: Take care to preserve the current HDF5 error stack + * when calling HDF5 API calls. + * * Return: Success: 0 * Failure: -1 * @@ -485,16 +502,21 @@ static herr_t H5VL_pass_through_info_free(void *_info) { H5VL_pass_through_info_t *info = (H5VL_pass_through_info_t *)_info; + hid_t err_id; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL INFO Free\n"); #endif + err_id = H5Eget_current_stack(); + /* Release underlying VOL ID and info */ if(info->under_vol_info) H5VLfree_connector_info(info->under_vol_id, info->under_vol_info); H5Idec_ref(info->under_vol_id); + H5Eset_current_stack(err_id); + /* Free pass through info object itself */ free(info); @@ -663,8 +685,8 @@ H5VL_pass_through_get_wrap_ctx(const void *obj, void **wrap_ctx) * * Purpose: Use a "wrapper context" to wrap a data object * - * Return: Success: 0 - * Failure: -1 + * Return: Success: Pointer to wrapped object + * Failure: NULL * *--------------------------------------------------------------------------- */ @@ -691,10 +713,44 @@ H5VL_pass_through_wrap_object(void *obj, H5I_type_t obj_type, void *_wrap_ctx) /*--------------------------------------------------------------------------- + * Function: H5VL_pass_through_unwrap_object + * + * Purpose: Unwrap a wrapped object, discarding the wrapper, but returning + * underlying object. + * + * Return: Success: Pointer to unwrapped object + * Failure: NULL + * + *--------------------------------------------------------------------------- + */ +static void * +H5VL_pass_through_unwrap_object(void *obj) +{ + H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + void *under; + +#ifdef ENABLE_PASSTHRU_LOGGING + printf("------- PASS THROUGH VOL UNWRAP Object\n"); +#endif + + /* Unrap the object with the underlying VOL */ + under = H5VLunwrap_object(o->under_object, o->under_vol_id); + + if(under) + H5VL_pass_through_free_obj(o); + + return under; +} /* end H5VL_pass_through_unwrap_object() */ + + +/*--------------------------------------------------------------------------- * Function: H5VL_pass_through_free_wrap_ctx * * Purpose: Release a "wrapper context" for an object * + * Note: Take care to preserve the current HDF5 error stack + * when calling HDF5 API calls. + * * Return: Success: 0 * Failure: -1 * @@ -704,16 +760,21 @@ static herr_t H5VL_pass_through_free_wrap_ctx(void *_wrap_ctx) { H5VL_pass_through_wrap_ctx_t *wrap_ctx = (H5VL_pass_through_wrap_ctx_t *)_wrap_ctx; + hid_t err_id; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL WRAP CTX Free\n"); #endif + err_id = H5Eget_current_stack(); + /* Release underlying VOL ID and wrap context */ if(wrap_ctx->under_wrap_ctx) H5VLfree_wrap_ctx(wrap_ctx->under_wrap_ctx, wrap_ctx->under_vol_id); H5Idec_ref(wrap_ctx->under_vol_id); + H5Eset_current_stack(err_id); + /* Free pass through wrap context object itself */ free(wrap_ctx); @@ -1166,17 +1227,22 @@ H5VL_pass_through_dataset_specific(void *obj, H5VL_dataset_specific_t specific_t hid_t dxpl_id, void **req, va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL H5Dspecific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLdataset_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_dataset_specific() */ @@ -1368,17 +1434,22 @@ H5VL_pass_through_datatype_specific(void *obj, H5VL_datatype_specific_t specific hid_t dxpl_id, void **req, va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL DATATYPE Specific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLdatatype_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_datatype_specific() */ @@ -1908,17 +1979,22 @@ H5VL_pass_through_group_specific(void *obj, H5VL_group_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL GROUP Specific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLgroup_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_group_specific() */ @@ -2344,17 +2420,22 @@ H5VL_pass_through_object_specific(void *obj, const H5VL_loc_params_t *loc_params va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL OBJECT Specific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLobject_specific(o->under_object, loc_params, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_object_specific() */ diff --git a/src/H5VLpkg.h b/src/H5VLpkg.h index bbdb0cc..69e51c2 100644 --- a/src/H5VLpkg.h +++ b/src/H5VLpkg.h @@ -28,21 +28,36 @@ /* Other private headers needed by this file */ + /**************************/ /* Package Private Macros */ /**************************/ + /****************************/ /* Package Private Typedefs */ /****************************/ + /*****************************/ /* Package Private Variables */ /*****************************/ + /******************************/ /* Package Private Prototypes */ /******************************/ +H5_DLL hid_t H5VL__register_connector(const H5VL_class_t *cls, hbool_t app_ref, + hid_t vipl_id); +H5_DLL hid_t H5VL__register_connector_by_name(const char *name, hbool_t app_ref, + hid_t vipl_id); +H5_DLL hid_t H5VL__register_connector_by_value(H5VL_class_value_t value, + hbool_t app_ref, hid_t vipl_id); +H5_DLL htri_t H5VL__is_connector_registered(const char *name); +H5_DLL hid_t H5VL__get_connector_id(const char *name, hbool_t is_api); +H5_DLL herr_t H5VL__connector_str_to_info(const char *str, hid_t connector_id, + void **info); +H5_DLL ssize_t H5VL__get_connector_name(hid_t id, char *name/*out*/, size_t size); #endif /* _H5VLpkg_H */ diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index 283c77a..04cc982 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -18,10 +18,12 @@ /* Private headers needed by this file */ + /**************************/ /* Library Private Macros */ /**************************/ + /****************************/ /* Library Private Typedefs */ /****************************/ @@ -41,8 +43,8 @@ typedef struct H5VL_object_t { /* Internal structure to hold the connector ID & info for FAPLs */ typedef struct H5VL_connector_prop_t { - hid_t connector_id; /* VOL connector's ID */ - const void *connector_info; /* VOL connector info, for open callbacks */ + hid_t connector_id; /* VOL connector's ID */ + void *connector_info; /* VOL connector info, for open callbacks */ } H5VL_connector_prop_t; /* Which kind of VOL connector field to use for searching */ @@ -62,14 +64,14 @@ typedef enum H5VL_get_connector_kind_t { /******************************/ /* Utility functions */ -H5_DLL herr_t H5VL_init(void); +H5_DLL herr_t H5VL_init_phase1(void); +H5_DLL herr_t H5VL_init_phase2(void); H5_DLL herr_t H5VL_cmp_connector_cls(int *cmp_value, const H5VL_class_t *cls1, const H5VL_class_t *cls2); H5_DLL herr_t H5VL_conn_copy(H5VL_connector_prop_t *value); H5_DLL herr_t H5VL_conn_free(const H5VL_connector_prop_t *info); /* Functions that deal with VOL connectors */ H5_DLL hid_t H5VL_register_connector(const void *cls, hbool_t app_ref, hid_t vipl_id); -H5_DLL ssize_t H5VL_get_connector_name(hid_t id, char *name/*out*/, size_t size); /* NOTE: The object and ID functions below deal in VOL objects (i.e.; * H5VL_object_t). Similar non-VOL calls exist in H5Iprivate.h. Use @@ -84,6 +86,7 @@ H5_DLL ssize_t H5VL_get_connector_name(hid_t id, char *name/*out*/, size_t size) /* Functions that manipulate VOL objects */ H5_DLL void *H5VL_object(hid_t id); H5_DLL void *H5VL_object_data(const H5VL_object_t *vol_obj); +H5_DLL void *H5VL_object_unwrap(const H5VL_object_t *vol_obj); H5_DLL void *H5VL_object_verify(hid_t id, H5I_type_t obj_type); H5_DLL H5VL_object_t *H5VL_vol_object(hid_t id); H5_DLL herr_t H5VL_free_object(H5VL_object_t *obj); @@ -91,11 +94,20 @@ H5_DLL herr_t H5VL_free_object(H5VL_object_t *obj); /* Functions that wrap / unwrap VOL objects */ H5_DLL herr_t H5VL_get_wrap_ctx(const H5VL_class_t *connector, void *obj, void **wrap_ctx); -H5_DLL herr_t H5VL_free_wrap_ctx(const H5VL_class_t *connector, void *wrap_ctx); -H5_DLL herr_t H5VL_set_vol_wrapper(void *obj, const H5VL_t *vol_connector); -H5_DLL herr_t H5VL_reset_vol_wrapper(void); H5_DLL void * H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, H5I_type_t obj_type); +H5_DLL void * H5VL_unwrap_object(const H5VL_class_t *connector, void *obj); +H5_DLL herr_t H5VL_free_wrap_ctx(const H5VL_class_t *connector, void *wrap_ctx); +H5_DLL herr_t H5VL_set_vol_wrapper(void *obj, H5VL_t *vol_connector); +H5_DLL herr_t H5VL_inc_vol_wrapper(void *vol_wrap_ctx); +H5_DLL herr_t H5VL_dec_vol_wrapper(void *vol_wrap_ctx); +H5_DLL herr_t H5VL_reset_vol_wrapper(void); + +/* Library state functions */ +H5_DLL herr_t H5VL_retrieve_lib_state(void **state); +H5_DLL herr_t H5VL_restore_lib_state(const void *state); +H5_DLL herr_t H5VL_reset_lib_state(void); +H5_DLL herr_t H5VL_free_lib_state(void *state); /* ID registration functions */ H5_DLL hid_t H5VL_register(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t app_ref); @@ -112,7 +124,7 @@ H5_DLL int H5VL_copy_connector_info(const H5VL_class_t *connector, void **dst_in const void *src_info); H5_DLL herr_t H5VL_cmp_connector_info(const H5VL_class_t *connector, int *cmp_value, const void *info1, const void *info2); -H5_DLL herr_t H5VL_free_connector_info(const H5VL_class_t *connector, void *info); +H5_DLL herr_t H5VL_free_connector_info(hid_t connector_id, void *info); /* Attribute functions */ H5_DLL void *H5VL_attr_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index f8f5423..ca34f6b 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -114,6 +114,7 @@ typedef enum H5VL_file_get_t { H5VL_FILE_GET_FAPL, /* file access property list */ H5VL_FILE_GET_FCPL, /* file creation property list */ H5VL_FILE_GET_INTENT, /* file intent */ + H5VL_FILE_GET_FILENO, /* file number */ H5VL_FILE_GET_NAME, /* file name */ H5VL_FILE_GET_OBJ_COUNT, /* object count in file */ H5VL_FILE_GET_OBJ_IDS /* object ids in file */ @@ -252,6 +253,7 @@ typedef struct H5VL_wrap_class_t { void * (*get_object)(const void *obj); /* Callback to retrieve underlying object */ herr_t (*get_wrap_ctx)(const void *obj, void **wrap_ctx); /* Callback to retrieve the object wrapping context for the connector */ void * (*wrap_object)(void *obj, H5I_type_t obj_type, void *wrap_ctx); /* Callback to wrap a library object */ + void * (*unwrap_object)(void *obj); /* Callback to unwrap a library object */ herr_t (*free_wrap_ctx)(void *wrap_ctx); /* Callback to release the object wrapping context for the connector */ } H5VL_wrap_class_t; @@ -450,6 +452,10 @@ H5_DLL herr_t H5VLunregister_connector(hid_t connector_id); H5_DLL herr_t H5VLcmp_connector_cls(int *cmp, hid_t connector_id1, hid_t connector_id2); H5_DLL hid_t H5VLwrap_register(void *obj, H5I_type_t type); H5_DLL void *H5VLobject(hid_t obj_id); +H5_DLL herr_t H5VLretrieve_lib_state(void **state); +H5_DLL herr_t H5VLrestore_lib_state(const void *state); +H5_DLL herr_t H5VLreset_lib_state(void); +H5_DLL herr_t H5VLfree_lib_state(void *state); /* Public wrappers for generic callbacks */ @@ -467,6 +473,7 @@ H5_DLL void *H5VLget_object(void *obj, hid_t connector_id); H5_DLL herr_t H5VLget_wrap_ctx(void *obj, hid_t connector_id, void **wrap_ctx); H5_DLL void *H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_ctx); +H5_DLL void *H5VLunwrap_object(void *obj, hid_t connector_id); H5_DLL herr_t H5VLfree_wrap_ctx(void *wrap_ctx, hid_t connector_id); /* Public wrappers for attribute callbacks */ @@ -19,6 +19,7 @@ #include "H5private.h" #include "H5Eprivate.h" +#include "H5MMprivate.h" /* Memory management */ #include "H5Oprivate.h" #include "H5VMprivate.h" @@ -732,7 +733,7 @@ H5VM_stride_copy(unsigned n, hsize_t elmt_size, const hsize_t *size, /* Copy an element */ H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t); - HDmemcpy(dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ + H5MM_memcpy(dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ /* Decrement indices and advance pointers */ for (j=(int)(n-1), carry=TRUE; j>=0 && carry; --j) { @@ -749,7 +750,7 @@ H5VM_stride_copy(unsigned n, hsize_t elmt_size, const hsize_t *size, } } else { H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t); - HDmemcpy (dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ + H5MM_memcpy (dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ } FUNC_LEAVE_NOAPI(SUCCEED) @@ -801,7 +802,7 @@ H5VM_stride_copy_s(unsigned n, hsize_t elmt_size, const hsize_t *size, /* Copy an element */ H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t); - HDmemcpy(dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ + H5MM_memcpy(dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ /* Decrement indices and advance pointers */ for (j=(int)(n-1), carry=TRUE; j>=0 && carry; --j) { @@ -818,7 +819,7 @@ H5VM_stride_copy_s(unsigned n, hsize_t elmt_size, const hsize_t *size, } } else { H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t); - HDmemcpy (dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ + H5MM_memcpy (dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ } FUNC_LEAVE_NOAPI(SUCCEED) @@ -877,7 +878,7 @@ H5VM_stride_copy2(hsize_t nelmts, hsize_t elmt_size, /* Copy an element */ H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t); - HDmemcpy(dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ + H5MM_memcpy(dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */ /* Decrement indices and advance pointers */ for (j=(int)(dst_n-1), carry=TRUE; j>=0 && carry; --j) { @@ -936,7 +937,7 @@ H5VM_array_fill(void *_dst, const void *src, size_t size, size_t count) HDassert(size < SIZET_MAX && size > 0); HDassert(count < SIZET_MAX && count > 0); - HDmemcpy(dst, src, size); /* copy first item */ + H5MM_memcpy(dst, src, size); /* copy first item */ /* Initialize counters, etc. while compensating for first element copied */ copy_size = size; @@ -947,7 +948,7 @@ H5VM_array_fill(void *_dst, const void *src, size_t size, size_t count) /* copy until we've copied at least half of the items */ while (items_left >= copy_items) { - HDmemcpy(dst, _dst, copy_size); /* copy the current chunk */ + H5MM_memcpy(dst, _dst, copy_size); /* copy the current chunk */ dst += copy_size; /* move the offset for the next chunk */ items_left -= copy_items; /* decrement the number of items left */ @@ -955,7 +956,7 @@ H5VM_array_fill(void *_dst, const void *src, size_t size, size_t count) copy_items *= 2; /* increase the count of items we are copying */ } /* end while */ if (items_left > 0) /* if there are any items left to copy */ - HDmemcpy(dst, _dst, items_left * size); + H5MM_memcpy(dst, _dst, items_left * size); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5VM_array_fill() */ @@ -1623,7 +1624,7 @@ src_smaller: acc_len = 0; do { /* Copy data */ - HDmemcpy(dst, src, tmp_src_len); + H5MM_memcpy(dst, src, tmp_src_len); /* Accumulate number of bytes copied */ acc_len += tmp_src_len; @@ -1666,7 +1667,7 @@ dst_smaller: acc_len = 0; do { /* Copy data */ - HDmemcpy(dst, src, tmp_dst_len); + H5MM_memcpy(dst, src, tmp_dst_len); /* Accumulate number of bytes copied */ acc_len += tmp_dst_len; @@ -1709,7 +1710,7 @@ equal: acc_len = 0; do { /* Copy data */ - HDmemcpy(dst, src, tmp_dst_len); + H5MM_memcpy(dst, src, tmp_dst_len); /* Accumulate number of bytes copied */ acc_len += tmp_dst_len; diff --git a/src/H5VMprivate.h b/src/H5VMprivate.h index decac7e..26f59e2 100644 --- a/src/H5VMprivate.h +++ b/src/H5VMprivate.h @@ -21,6 +21,7 @@ /* Private headers needed by this file */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ /* Vector-Vector sequence operation callback */ typedef herr_t (*H5VM_opvv_func_t)(hsize_t dst_off, hsize_t src_off, @@ -41,7 +42,7 @@ typedef herr_t (*H5VM_opvv_func_t)(hsize_t dst_off, hsize_t src_off, /* Other functions */ #define H5VM_vector_cpy(N,DST,SRC) { \ HDassert(sizeof(*(DST))==sizeof(*(SRC))); \ - if (SRC) HDmemcpy (DST, SRC, (N)*sizeof(*(DST))); \ + if (SRC) H5MM_memcpy (DST, SRC, (N)*sizeof(*(DST))); \ else HDmemset (DST, 0, (N)*sizeof(*(DST))); \ } @@ -322,7 +322,7 @@ H5Z_register (const H5Z_class2_t *cls) /* Initialize */ i = H5Z_table_used_g++; - HDmemcpy(H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); + H5MM_memcpy(H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); #ifdef H5Z_DEBUG HDmemset(H5Z_stat_table_g+i, 0, sizeof(H5Z_stats_t)); #endif /* H5Z_DEBUG */ @@ -330,7 +330,7 @@ H5Z_register (const H5Z_class2_t *cls) /* Filter already registered */ else { /* Replace old contents */ - HDmemcpy(H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); + H5MM_memcpy(H5Z_table_g+i, cls, sizeof(H5Z_class2_t)); } /* end else */ done: diff --git a/src/H5Zfletcher32.c b/src/H5Zfletcher32.c index 4cd77ef..4d75d14 100644 --- a/src/H5Zfletcher32.c +++ b/src/H5Zfletcher32.c @@ -108,7 +108,7 @@ H5Z_filter_fletcher32 (unsigned flags, size_t H5_ATTR_UNUSED cd_nelmts, const un * system. We'll check both the correct checksum and the wrong * checksum to be consistent with Release 1.6.2 and before. */ - HDmemcpy(c, &fletcher, (size_t)4); + H5MM_memcpy(c, &fletcher, (size_t)4); tmp = c[1]; c[1] = c[0]; @@ -118,7 +118,7 @@ H5Z_filter_fletcher32 (unsigned flags, size_t H5_ATTR_UNUSED cd_nelmts, const un c[3] = c[2]; c[2] = tmp; - HDmemcpy(&reversed_fletcher, c, (size_t)4); + H5MM_memcpy(&reversed_fletcher, c, (size_t)4); /* Verify computed checksum matches stored checksum */ if(stored_fletcher != fletcher && stored_fletcher != reversed_fletcher) @@ -140,7 +140,7 @@ H5Z_filter_fletcher32 (unsigned flags, size_t H5_ATTR_UNUSED cd_nelmts, const un dst = (unsigned char *) outbuf; /* Copy raw data */ - HDmemcpy((void*)dst, (void*)(*buf), nbytes); + H5MM_memcpy((void*)dst, (void*)(*buf), nbytes); /* Append checksum to raw data for storage */ dst += nbytes; diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 0026749..d3e8fc0 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -141,7 +141,7 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ } /* end if */ \ \ /* Copy the value */ \ - HDmemcpy(&_cd_value, _fv_p, _copy_size); \ + H5MM_memcpy(&_cd_value, _fv_p, _copy_size); \ (cd_values)[_i] = (unsigned)_cd_value; \ \ /* Next field */ \ @@ -158,7 +158,7 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ _fv_p = ((char *)&(fill_val)) + sizeof(type) - MIN(4, _size_rem); \ while(_size_rem >= 4) { \ /* Copy the value */ \ - HDmemcpy(&_cd_value, _fv_p, _copy_size); \ + H5MM_memcpy(&_cd_value, _fv_p, _copy_size); \ (cd_values)[_i] = (unsigned)_cd_value; \ \ /* Next field */ \ @@ -176,7 +176,7 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ * _cd_value as it will not be fully overwritten and copy to the end \ * of _cd value as it is BE. */ \ _cd_value = (uint32_t)0; \ - HDmemcpy((char *)&_cd_value + 4 - _size_rem, _fv_p, _size_rem); \ + H5MM_memcpy((char *)&_cd_value + 4 - _size_rem, _fv_p, _size_rem); \ (cd_values)[_i] = (unsigned)_cd_value; \ } /* end if */ \ } /* end else */ \ @@ -269,7 +269,7 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ \ /* Copy the value */ \ _cd_value = (uint32_t)(cd_values)[_i]; \ - HDmemcpy(_fv_p, &_cd_value, _copy_size); \ + H5MM_memcpy(_fv_p, &_cd_value, _copy_size); \ \ /* Next field */ \ _i++; \ @@ -286,7 +286,7 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ while(_size_rem >= 4) { \ /* Copy the value */ \ _cd_value = (uint32_t)(cd_values)[_i]; \ - HDmemcpy(_fv_p, &_cd_value, _copy_size); \ + H5MM_memcpy(_fv_p, &_cd_value, _copy_size); \ \ /* Next field */ \ _i++; \ @@ -303,7 +303,7 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ * _cd_value as it will not be fully overwritten and copy to the end \ * of _cd value as it is BE. */ \ _cd_value = (uint32_t)(cd_values)[_i]; \ - HDmemcpy(_fv_p, (char *)&_cd_value + 4 - _size_rem, _size_rem); \ + H5MM_memcpy(_fv_p, (char *)&_cd_value + 4 - _size_rem, _size_rem); \ } /* end if */ \ } /* end else */ \ } @@ -529,10 +529,10 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ * account for offset in BE if sizes differ \ */ \ if(H5T_native_order_g == H5T_ORDER_LE) \ - HDmemcpy(minval, &min, sizeof(type)); \ + H5MM_memcpy(minval, &min, sizeof(type)); \ else { \ HDassert(H5T_native_order_g == H5T_ORDER_BE); \ - HDmemcpy(((char *)minval) + (sizeof(long long) - sizeof(type)), \ + H5MM_memcpy(((char *)minval) + (sizeof(long long) - sizeof(type)), \ &min, sizeof(type)); \ } /* end else */ \ else \ @@ -604,10 +604,10 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ * account for offset in BE if sizes differ \ */ \ if(H5T_native_order_g == H5T_ORDER_LE) \ - HDmemcpy(&min, &minval, sizeof(type)); \ + H5MM_memcpy(&min, &minval, sizeof(type)); \ else { \ HDassert(H5T_native_order_g == H5T_ORDER_BE); \ - HDmemcpy(&min, ((char *)&minval) + (sizeof(long long) \ + H5MM_memcpy(&min, ((char *)&minval) + (sizeof(long long) \ - sizeof(type)), sizeof(type)); \ } /* end else */ \ else \ @@ -1173,7 +1173,7 @@ H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_value /* special case: minbits equal to full precision */ if(minbits == p.size * 8) { - HDmemcpy(outbuf, (unsigned char*)(*buf)+buf_offset, size_out); + H5MM_memcpy(outbuf, (unsigned char*)(*buf)+buf_offset, size_out); /* free the original buffer */ H5MM_xfree(*buf); @@ -1273,7 +1273,7 @@ H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_value /* special case: minbits equal to full precision */ if(minbits == p.size * 8) { - HDmemcpy(outbuf + buf_offset, *buf, nbytes); + H5MM_memcpy(outbuf + buf_offset, *buf, nbytes); /* free the original buffer */ H5MM_xfree(*buf); diff --git a/src/H5Zshuffle.c b/src/H5Zshuffle.c index 1fef1c1..e70ef33 100644 --- a/src/H5Zshuffle.c +++ b/src/H5Zshuffle.c @@ -210,7 +210,7 @@ H5Z_filter_shuffle(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], if(leftover>0) { /* Adjust back to end of shuffled bytes */ _dest -= (bytesoftype - 1); /*lint !e794 _dest is initialized */ - HDmemcpy((void*)_dest, (void*)_src, leftover); + H5MM_memcpy((void*)_dest, (void*)_src, leftover); } } /* end if */ else { @@ -268,7 +268,7 @@ H5Z_filter_shuffle(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], if(leftover>0) { /* Adjust back to end of shuffled bytes */ _src -= (bytesoftype - 1); /*lint !e794 _src is initialized */ - HDmemcpy((void*)_dest, (void*)_src, leftover); + H5MM_memcpy((void*)_dest, (void*)_src, leftover); } } /* end else */ diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index f8fc325..6d07513 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -1078,7 +1078,7 @@ H5Z_xform_eval(H5Z_data_xform_t *data_xform_prop, void* array, size_t array_size if(NULL == (data_xform_prop->dat_val_pointers->ptr_dat_val[i] = (void*)H5MM_malloc(array_size * H5T_get_size((H5T_t *)H5I_object(array_type))))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "Ran out of memory trying to allocate space for data in data transform") - HDmemcpy(data_xform_prop->dat_val_pointers->ptr_dat_val[i], array, array_size * H5T_get_size((H5T_t *)H5I_object(array_type))); + H5MM_memcpy(data_xform_prop->dat_val_pointers->ptr_dat_val[i], array, array_size * H5T_get_size((H5T_t *)H5I_object(array_type))); } /* end for */ } /* end else */ @@ -1086,7 +1086,7 @@ H5Z_xform_eval(H5Z_data_xform_t *data_xform_prop, void* array, size_t array_size HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while performing data transform") if(data_xform_prop->dat_val_pointers->num_ptrs > 1) - HDmemcpy(array, res.value.dat_val, array_size * H5T_get_size((H5T_t *)H5I_object(array_type))); + H5MM_memcpy(array, res.value.dat_val, array_size * H5T_get_size((H5T_t *)H5I_object(array_type))); /* Free the temporary arrays we used */ if(data_xform_prop->dat_val_pointers->num_ptrs > 1) diff --git a/src/H5private.h b/src/H5private.h index ef52ac6..dad2d94 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1104,12 +1104,8 @@ typedef off_t h5_stat_size_t; #ifndef HDmemcmp #define HDmemcmp(X,Y,Z) memcmp(X,Y,Z) #endif /* HDmemcmp */ -/* - * The (char*) casts are required for the DEC when optimizations are turned - * on and the source and/or destination are not aligned. - */ #ifndef HDmemcpy - #define HDmemcpy(X,Y,Z) memcpy((char*)(X),(const char*)(Y),Z) + #define HDmemcpy(X,Y,Z) memcpy(X,Y,Z) #endif /* HDmemcpy */ #ifndef HDmemmove #define HDmemmove(X,Y,Z) memmove((char*)(X),(const char*)(Y),Z) diff --git a/src/H5public.h b/src/H5public.h index 353ff16..3b53e00 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -93,10 +93,10 @@ extern "C" { /* Version numbers */ #define H5_VERS_MAJOR 1 /* For major interface/format changes */ #define H5_VERS_MINOR 11 /* For minor interface/format changes */ -#define H5_VERS_RELEASE 4 /* For tweaks, bug-fixes, or development */ +#define H5_VERS_RELEASE 5 /* For tweaks, bug-fixes, or development */ #define H5_VERS_SUBRELEASE "" /* For pre-releases like snap0 */ /* Empty string for real releases. */ -#define H5_VERS_INFO "HDF5 library version: 1.11.4" /* Full version string */ +#define H5_VERS_INFO "HDF5 library version: 1.11.5" /* Full version string */ #define H5check() H5check_version(H5_VERS_MAJOR,H5_VERS_MINOR, \ H5_VERS_RELEASE) diff --git a/src/H5system.c b/src/H5system.c index f47d057..35123db 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -985,6 +985,132 @@ Wroundf(float arg) return (float)(arg < 0.0F ? HDceil(arg - 0.5F) : HDfloor(arg + 0.5F)); } +/*------------------------------------------------------------------------- +* Function: H5_get_utf16_str +* +* Purpose: Gets a UTF-16 string from an UTF-8 (or ASCII) string. +* +* Return: Success: A pointer to a UTF-16 string +* This must be freed by the caller using H5MM_xfree() +* Failure: NULL +* +* Programmer: Dana Robinson +* Spring 2019 +* +*------------------------------------------------------------------------- +*/ +const wchar_t * +H5_get_utf16_str(const char *s) +{ + int nwchars = -1; /* Length of the UTF-16 buffer */ + wchar_t *ret_s = NULL; /* UTF-16 version of the string */ + + /* Get the number of UTF-16 characters needed */ + if(0 == (nwchars = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0))) + goto error; + + /* Allocate a buffer for the UTF-16 string */ + if(NULL == (ret_s = (wchar_t *)H5MM_calloc(sizeof(wchar_t) * (size_t)nwchars))) + goto error; + + /* Convert the input UTF-8 string to UTF-16 */ + if(0 == MultiByteToWideChar(CP_UTF8, 0, s, -1, ret_s, nwchars)) + goto error; + + return ret_s; + +error: + if(ret_s) + H5MM_xfree((void *)ret_s); + return NULL; +} /* end H5_get_utf16_str() */ + +/*------------------------------------------------------------------------- + * Function: Wopen_utf8 + * + * Purpose: UTF-8 equivalent of open(2) for use on Windows. + * Converts a UTF-8 input path to UTF-16 and then opens the + * file via _wopen() under the hood + * + * Return: Success: A POSIX file descriptor + * Failure: -1 + * + * Programmer: Dana Robinson + * Spring 2019 + * + *------------------------------------------------------------------------- + */ +int +Wopen_utf8(const char *path, int oflag, ...) +{ + int fd = -1; /* POSIX file descriptor to be returned */ + wchar_t *wpath = NULL; /* UTF-16 version of the path */ + int pmode = 0; /* mode (optionally set via variable args) */ + + /* Convert the input UTF-8 path to UTF-16 */ + if(NULL == (wpath = H5_get_utf16_str(path))) + goto done; + + /* _O_BINARY must be set in Windows to avoid CR-LF <-> LF EOL + * transformations when performing I/O. Note that this will + * produce Unix-style text files, though. + */ + oflag |= _O_BINARY; + + /* Get the mode, if O_CREAT was specified */ + if(oflag & O_CREAT) { + va_list vl; + + HDva_start(vl, oflag); + pmode = HDva_arg(vl, int); + HDva_end(vl); + } + + /* Open the file */ + fd = _wopen(wpath, oflag, pmode); + +done: + if(wpath) + H5MM_xfree((void *)wpath); + + return fd; +} /* end Wopen_utf8() */ + +/*------------------------------------------------------------------------- + * Function: Wremove_utf8 + * + * Purpose: UTF-8 equivalent of remove(3) for use on Windows. + * Converts a UTF-8 input path to UTF-16 and then opens the + * file via _wremove() under the hood + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Dana Robinson + * Spring 2019 + * + *------------------------------------------------------------------------- + */ +int +Wremove_utf8(const char *path) +{ + wchar_t *wpath = NULL; /* UTF-16 version of the path */ + int ret; + + /* Convert the input UTF-8 path to UTF-16 */ + if(NULL == (wpath = H5_get_utf16_str(path))) + goto done; + + /* Open the file */ + ret = _wremove(wpath); + +done: + if(wpath) + H5MM_xfree((void *)wpath); + + return ret; +} /* end Wremove_utf8() */ + #endif /* H5_HAVE_WIN32_API */ @@ -1130,13 +1256,13 @@ H5_combine_path(const char* path1, const char* path2, char **full_name /*out*/) FUNC_ENTER_NOAPI_NOINIT - HDassert(path1); HDassert(path2); - path1_len = HDstrlen(path1); + if(path1) + path1_len = HDstrlen(path1); path2_len = HDstrlen(path2); - if(*path1 == '\0' || H5_CHECK_ABSOLUTE(path2)) { + if(path1 == NULL || *path1 == '\0' || H5_CHECK_ABSOLUTE(path2)) { /* If path1 is empty or path2 is absolute, simply use path2 */ if(NULL == (*full_name = (char *)H5MM_strdup(path2))) diff --git a/src/H5trace.c b/src/H5trace.c index 9a13193..23f2f1d 100644 --- a/src/H5trace.c +++ b/src/H5trace.c @@ -1054,7 +1054,11 @@ H5_trace(const double *returning, const char *func, const char *type, ...) break; case H5F_LIBVER_V110: - HDcompile_assert(H5F_LIBVER_LATEST == H5F_LIBVER_V110); + HDfprintf(out, "H5F_LIBVER_V110"); + break; + + case H5F_LIBVER_V112: + HDcompile_assert(H5F_LIBVER_LATEST == H5F_LIBVER_V112); HDfprintf(out, "H5F_LIBVER_LATEST"); break; diff --git a/src/H5vers.txt b/src/H5vers.txt index 914c30e..22117c3 100644 --- a/src/H5vers.txt +++ b/src/H5vers.txt @@ -61,12 +61,14 @@ FUNCTION: H5Oget_info_by_name; ; v18, v112 FUNCTION: H5Oget_info_by_idx; ; v18, v112 FUNCTION: H5Ovisit; ; v18, v112 FUNCTION: H5Ovisit_by_name; ; v18, v112 +FUNCTION: H5Pencode; ; v110, v112 FUNCTION: H5Pget_filter; ; v10, v18 FUNCTION: H5Pget_filter_by_id; ; v16, v18 FUNCTION: H5Pinsert; ; v14, v18 FUNCTION: H5Pregister; ; v14, v18 FUNCTION: H5Rdereference; ; v10, v110 FUNCTION: H5Rget_obj_type; ; v16, v18 +FUNCTION: H5Sencode; ; v18, v112 FUNCTION: H5Tarray_create; ; v14, v18 FUNCTION: H5Tcommit; ; v10, v18 FUNCTION: H5Tget_array_dims; ; v14, v18 diff --git a/src/H5win32defs.h b/src/H5win32defs.h index 140afc3..2ae2575 100644 --- a/src/H5win32defs.h +++ b/src/H5win32defs.h @@ -34,6 +34,7 @@ typedef __int64 h5_stat_size_t; #define HDaccess(F,M) _access(F,M) #define HDchdir(S) _chdir(S) #define HDclose(F) _close(F) +#define HDcreat(S,M) Wopen_utf8(S,O_CREAT|O_TRUNC|O_RDWR,M) #define HDdup(F) _dup(F) #define HDfdopen(N,S) _fdopen(N,S) #define HDfileno(F) _fileno(F) @@ -47,15 +48,13 @@ typedef __int64 h5_stat_size_t; #define HDmkdir(S,M) _mkdir(S) #define HDnanosleep(N, O) Wnanosleep(N, O) #define HDoff_t __int64 -/* _O_BINARY must be set in Windows to avoid CR-LF <-> LF EOL - * transformations when performing I/O. Note that this will - * produce Unix-style text files, though. - * - * Also note that the variadic macro is using a VC++ extension + +/* Note that the variadic HDopen macro is using a VC++ extension * where the comma is dropped if nothing is passed to the ellipsis. */ -#define HDopen(S,F,...) _open(S, F | _O_BINARY, __VA_ARGS__) +#define HDopen(S,F,...) Wopen_utf8(S,F,__VA_ARGS__) #define HDread(F,M,Z) _read(F,M,Z) +#define HDremove(S) Wremove_utf8(S) #define HDrmdir(S) _rmdir(S) #define HDsetvbuf(F,S,M,Z) setvbuf(F,S,M,(Z>1?Z:2)) #define HDsleep(S) Sleep(S*1000) @@ -128,6 +127,9 @@ extern "C" { H5_DLL int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap); H5_DLL int Wnanosleep(const struct timespec *req, struct timespec *rem); H5_DLL herr_t H5_expand_windows_env_vars(char **env_var); + H5_DLL const wchar_t *H5_get_utf16_str(const char *s); + H5_DLL int Wopen_utf8(const char *path, int oflag, ...); + H5_DLL int Wremove_utf8(const char *path); /* Round functions only needed for VS2012 and earlier. * They are always built to ensure they don't go stale and diff --git a/src/Makefile.am b/src/Makefile.am index 5532655..378e390 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -102,7 +102,7 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5R.c H5Rint.c H5Rdeprec.c \ H5UC.c \ H5RS.c \ - H5S.c H5Sall.c H5Sdbg.c H5Shyper.c H5Snone.c H5Spoint.c \ + H5S.c H5Sall.c H5Sdbg.c H5Sdeprec.c H5Shyper.c H5Snone.c H5Spoint.c \ H5Sselect.c H5Stest.c \ H5SL.c \ H5SM.c H5SMbtree2.c H5SMcache.c H5SMmessage.c H5SMtest.c \ |