diff options
Diffstat (limited to 'src')
84 files changed, 1798 insertions, 1380 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1e05424..3f40dda 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -465,6 +465,10 @@ SET (H5Z_SRCS ${HDF5_SRC_DIR}/H5Zszip.c ${HDF5_SRC_DIR}/H5Ztrans.c ) +IF (H5_ZLIB_HEADER) + SET_PROPERTY(SOURCE ${HDF5_SRC_DIR}/H5Zdeflate.c PROPERTY + COMPILE_DEFINITIONS H5_ZLIB_HEADER="${H5_ZLIB_HEADER}") +ENDIF (H5_ZLIB_HEADER) SET (H5Z_HDRS ${HDF5_SRC_DIR}/H5Zpkg.h @@ -501,6 +505,7 @@ SET (common_SRCS ${HDF5_SRC_DIR}/H5FO.c ${HDF5_SRC_DIR}/H5HP.c ${HDF5_SRC_DIR}/H5I.c + ${HDF5_SRC_DIR}/H5Itest.c ${HDF5_SRC_DIR}/H5L.c ${HDF5_SRC_DIR}/H5Lexternal.c ${HDF5_SRC_DIR}/H5MM.c @@ -694,15 +699,17 @@ H5_SET_LIB_OPTIONS (${HDF5_LIB_TARGET} ${HDF5_LIB_NAME} ${LIB_TYPE}) #----------------------------------------------------------------------------- # Add file(s) to CMake Install #----------------------------------------------------------------------------- -INSTALL (
- FILES
- ${H5_PUBLIC_HEADERS}
- ${H5_PRIVATE_HEADERS}
- DESTINATION
- include
- COMPONENT - headers -)
+IF (NOT HDF5_INSTALL_NO_DEVELOPMENT) + INSTALL ( + FILES + ${H5_PUBLIC_HEADERS} + ${H5_PRIVATE_HEADERS} + DESTINATION + ${HDF5_INSTALL_INCLUDE_DIR} + COMPONENT + headers + ) +ENDIF (NOT HDF5_INSTALL_NO_DEVELOPMENT) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install for import into other projects @@ -713,8 +720,8 @@ IF (HDF5_EXPORTED_TARGETS) ${HDF5_LIB_TARGET} EXPORT ${HDF5_EXPORTED_TARGETS} - LIBRARY DESTINATION lib COMPONENT libraries - ARCHIVE DESTINATION lib COMPONENT libraries - RUNTIME DESTINATION bin COMPONENT libraries + LIBRARY DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT libraries + ARCHIVE DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT libraries + RUNTIME DESTINATION ${HDF5_INSTALL_BIN_DIR} COMPONENT libraries ) ENDIF (HDF5_EXPORTED_TARGETS) @@ -2424,18 +2424,19 @@ H5A_close(H5A_t *attr) HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release object header info") /* Reference count can be 0. It only happens when H5A_create fails. */ - if(1 >= attr->shared->nrefs) { + if(attr->shared->nrefs <= 1) { /* Free dynamicly allocated items */ if(H5A_free(attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release attribute info") /* Destroy shared attribute struct */ attr->shared = H5FL_FREE(H5A_shared_t, attr->shared); - } else if(attr->shared->nrefs > 1) { + } /* end if */ + else { /* There are other references to the shared part of the attribute. * Only decrement the reference count. */ --attr->shared->nrefs; - } + } /* end else */ /* Free group hierarchy path */ if(H5G_name_free(&(attr->path)) < 0) @@ -929,7 +929,7 @@ done: /*------------------------------------------------------------------------- - * Function: H5AC_set + * Function: H5AC_insert_entry * * Purpose: Adds the specified thing to the cache. The thing need not * exist on disk yet, but it must have an address and disk @@ -944,7 +944,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5AC_set(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type, haddr_t addr, +H5AC_insert_entry(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type, haddr_t addr, void *thing, unsigned int flags) { #if H5AC__TRACE_FILE_ENABLED @@ -954,7 +954,7 @@ H5AC_set(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type, haddr_t addr, #endif /* H5AC__TRACE_FILE_ENABLED */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5AC_set, FAIL) + FUNC_ENTER_NOAPI(H5AC_insert_entry, FAIL) HDassert(f); HDassert(f->shared); @@ -983,7 +983,7 @@ H5AC_set(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type, haddr_t addr, ( H5C_get_trace_file_ptr(f->shared->cache, &trace_file_ptr) >= 0) && ( trace_file_ptr != NULL ) ) { - sprintf(trace, "H5AC_set 0x%lx %d 0x%x", + sprintf(trace, "H5AC_insert_entry 0x%lx %d 0x%x", (unsigned long)addr, type->id, flags); @@ -1028,7 +1028,7 @@ done: #endif /* H5AC__TRACE_FILE_ENABLED */ FUNC_LEAVE_NOAPI(ret_value) -} /* H5AC_set() */ +} /* H5AC_insert_entry() */ /*------------------------------------------------------------------------- diff --git a/src/H5ACprivate.h b/src/H5ACprivate.h index b55572d..6780b72 100644 --- a/src/H5ACprivate.h +++ b/src/H5ACprivate.h @@ -342,7 +342,7 @@ H5_DLL herr_t H5AC_init(void); H5_DLL herr_t H5AC_create(const H5F_t *f, H5AC_cache_config_t *config_ptr); H5_DLL herr_t H5AC_get_entry_status(const H5F_t *f, haddr_t addr, unsigned * status_ptr); -H5_DLL herr_t H5AC_set(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type, +H5_DLL herr_t H5AC_insert_entry(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type, haddr_t addr, void *thing, unsigned int flags); H5_DLL herr_t H5AC_pin_protected_entry(void *thing); H5_DLL herr_t H5AC_create_flush_dependency(void *parent_thing, void *child_thing); diff --git a/src/H5Aint.c b/src/H5Aint.c index ba30506..101d604 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -1149,8 +1149,8 @@ H5A_dense_copy_file_cb(const H5A_t *attr_src, void *_udata) HDassert(udata->file); HDassert(udata->cpy_info); - if ( NULL == (attr_dst=H5A_attr_copy_file(attr_src, udata->file, - udata->recompute_size, udata->cpy_info, udata->dxpl_id))) + if(NULL == (attr_dst = H5A_attr_copy_file(attr_src, udata->file, + udata->recompute_size, udata->cpy_info, udata->dxpl_id))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") /* Reset shared location information */ @@ -1168,10 +1168,8 @@ H5A_dense_copy_file_cb(const H5A_t *attr_src, void *_udata) H5_END_TAG(H5_ITER_ERROR); done: - if(attr_dst) { - (void)H5A_free(attr_dst); - attr_dst = H5FL_FREE(H5A_t, attr_dst); - } /* end if */ + if(attr_dst && H5A_close(attr_dst) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close destination attribute") FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_dense_copy_file_cb() */ @@ -245,7 +245,7 @@ H5B_create(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, void *udata, /* * Cache the new B-tree node. */ - if(H5AC_set(f, dxpl_id, H5AC_BT, *addr_p, bt, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_BT, *addr_p, bt, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "can't add B-tree root node to cache") #ifdef H5B_DEBUG H5B_assert(f, dxpl_id, *addr_p, shared->type, udata); @@ -687,7 +687,7 @@ H5B_insert(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, HDmemcpy(H5B_NKEY(new_bt, shared, 2), rt_key, shared->type->sizeof_nkey); /* Insert the modified copy of the old root into the file again */ - if(H5AC_set(f, dxpl_id, H5AC_BT, addr, new_bt, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_BT, addr, new_bt, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to flush old B-tree root node") #ifdef H5B_DEBUG diff --git a/src/H5B2hdr.c b/src/H5B2hdr.c index 94e2c54..e8d8b96 100644 --- a/src/H5B2hdr.c +++ b/src/H5B2hdr.c @@ -309,7 +309,7 @@ H5B2_hdr_create(H5F_t *f, hid_t dxpl_id, const H5B2_create_t *cparam, HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, HADDR_UNDEF, "file allocation failed for B-tree header") /* Cache the new B-tree node */ - if(H5AC_set(f, dxpl_id, H5AC_BT2_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_BT2_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, HADDR_UNDEF, "can't add B-tree header to cache") /* Set address of v2 B-tree header to return */ diff --git a/src/H5B2int.c b/src/H5B2int.c index db137f8..f6602737f 100644 --- a/src/H5B2int.c +++ b/src/H5B2int.c @@ -80,10 +80,10 @@ static herr_t H5B2_swap_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, H5B2_internal_t *internal, unsigned *internal_flags_ptr, unsigned idx, void *swap_loc); #ifdef H5B2_DEBUG -static herr_t H5B2_assert_leaf(H5B2_hdr_t *hdr, H5B2_leaf_t *leaf); -static herr_t H5B2_assert_leaf2(H5B2_hdr_t *hdr, H5B2_leaf_t *leaf, H5B2_leaf_t *leaf2); -static herr_t H5B2_assert_internal(hsize_t parent_all_nrec, H5B2_hdr_t *hdr, H5B2_internal_t *internal); -static herr_t H5B2_assert_internal2(hsize_t parent_all_nrec, H5B2_hdr_t *hdr, H5B2_internal_t *internal, H5B2_internal_t *internal2); +static herr_t H5B2_assert_leaf(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf); +static herr_t H5B2_assert_leaf2(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf, const H5B2_leaf_t *leaf2); +static herr_t H5B2_assert_internal(hsize_t parent_all_nrec, const H5B2_hdr_t *hdr, const H5B2_internal_t *internal); +static herr_t H5B2_assert_internal2(hsize_t parent_all_nrec, const H5B2_hdr_t *hdr, const H5B2_internal_t *internal, const H5B2_internal_t *internal2); #endif /* H5B2_DEBUG */ /*********************/ @@ -178,7 +178,7 @@ H5B2_split1(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *cur { const H5AC_class_t *child_class; /* Pointer to child node's class info */ haddr_t left_addr, right_addr; /* Addresses of left & right child nodes */ - void *left_child, *right_child; /* Pointers to child nodes */ + void *left_child = NULL, *right_child = NULL; /* Pointers to child nodes */ uint16_t *left_nrec, *right_nrec; /* Pointers to child # of records */ uint8_t *left_native, *right_native;/* Pointers to childs' native records */ H5B2_node_ptr_t *left_node_ptrs = NULL, *right_node_ptrs = NULL;/* Pointers to childs' node pointer info */ @@ -324,12 +324,12 @@ H5B2_split1(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, H5B2_node_ptr_t *cur #ifdef H5B2_DEBUG H5B2_assert_internal((hsize_t)0, hdr, internal); if(depth > 1) { - H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, left_child, right_child); - H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, right_child, left_child); + H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)left_child, (H5B2_internal_t *)right_child); + H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, (H5B2_internal_t *)right_child, (H5B2_internal_t *)left_child); } /* end if */ else { - H5B2_assert_leaf2(hdr, left_child, right_child); - H5B2_assert_leaf(hdr, right_child); + H5B2_assert_leaf2(hdr, (H5B2_leaf_t *)left_child, (H5B2_leaf_t *)right_child); + H5B2_assert_leaf(hdr, (H5B2_leaf_t *)right_child); } /* end else */ #endif /* H5B2_DEBUG */ @@ -509,12 +509,12 @@ H5B2_redistribute2(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, #ifdef H5B2_DEBUG H5B2_assert_internal((hsize_t)0, hdr, internal); if(depth > 1) { - H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, left_child, right_child); - H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, right_child, left_child); + H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)left_child, (H5B2_internal_t *)right_child); + H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, (H5B2_internal_t *)right_child, (H5B2_internal_t *)left_child); } /* end if */ else { - H5B2_assert_leaf2(hdr, left_child, right_child); - H5B2_assert_leaf(hdr, right_child); + H5B2_assert_leaf2(hdr, (H5B2_leaf_t *)left_child, (H5B2_leaf_t *)right_child); + H5B2_assert_leaf(hdr, (H5B2_leaf_t *)right_child); } /* end else */ #endif /* H5B2_DEBUG */ @@ -629,12 +629,12 @@ H5B2_redistribute2(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, #ifdef H5B2_DEBUG H5B2_assert_internal((hsize_t)0, hdr, internal); if(depth > 1) { - H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, left_child, right_child); - H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, right_child, left_child); + H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)left_child, (H5B2_internal_t *)right_child); + H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, (H5B2_internal_t *)right_child, (H5B2_internal_t *)left_child); } /* end if */ else { - H5B2_assert_leaf2(hdr, left_child, right_child); - H5B2_assert_leaf(hdr, right_child); + H5B2_assert_leaf2(hdr, (H5B2_leaf_t *)left_child, (H5B2_leaf_t *)right_child); + H5B2_assert_leaf(hdr, (H5B2_leaf_t *)right_child); } /* end else */ #endif /* H5B2_DEBUG */ @@ -672,8 +672,8 @@ H5B2_redistribute3(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, const H5AC_class_t *child_class; /* Pointer to child node's class info */ haddr_t left_addr, right_addr; /* Addresses of left & right child nodes */ haddr_t middle_addr; /* Address of middle child node */ - void *left_child, *right_child; /* Pointers to child nodes */ - void *middle_child; /* Pointers to middle child node */ + void *left_child = NULL, *right_child = NULL; /* Pointers to child nodes */ + void *middle_child = NULL; /* Pointers to middle child node */ uint16_t *left_nrec, *right_nrec; /* Pointers to child # of records */ uint16_t *middle_nrec; /* Pointers to middle child # of records */ uint8_t *left_native, *right_native; /* Pointers to childs' native records */ @@ -1011,15 +1011,15 @@ H5B2_redistribute3(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, #ifdef H5B2_DEBUG H5B2_assert_internal((hsize_t)0, hdr, internal); if(depth > 1) { - H5B2_assert_internal2(internal->node_ptrs[idx - 1].all_nrec, hdr, left_child, middle_child); - H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, middle_child, left_child); - H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, middle_child, right_child); - H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, right_child, middle_child); + H5B2_assert_internal2(internal->node_ptrs[idx - 1].all_nrec, hdr, (H5B2_internal_t *)left_child, (H5B2_internal_t *)middle_child); + H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)middle_child, (H5B2_internal_t *)left_child); + H5B2_assert_internal2(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)middle_child, (H5B2_internal_t *)right_child); + H5B2_assert_internal2(internal->node_ptrs[idx + 1].all_nrec, hdr, (H5B2_internal_t *)right_child, (H5B2_internal_t *)middle_child); } /* end if */ else { - H5B2_assert_leaf2(hdr, left_child, middle_child); - H5B2_assert_leaf2(hdr, middle_child, right_child); - H5B2_assert_leaf(hdr, right_child); + H5B2_assert_leaf2(hdr, (H5B2_leaf_t *)left_child, (H5B2_leaf_t *)middle_child); + H5B2_assert_leaf2(hdr, (H5B2_leaf_t *)middle_child, (H5B2_leaf_t *)right_child); + H5B2_assert_leaf(hdr, (H5B2_leaf_t *)right_child); } /* end else */ #endif /* H5B2_DEBUG */ @@ -1058,7 +1058,7 @@ H5B2_merge2(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, { const H5AC_class_t *child_class; /* Pointer to child node's class info */ haddr_t left_addr, right_addr; /* Addresses of left & right child nodes */ - void *left_child, *right_child; /* Pointers to left & right child nodes */ + void *left_child = NULL, *right_child = NULL; /* Pointers to left & right child nodes */ uint16_t *left_nrec, *right_nrec; /* Pointers to left & right child # of records */ uint8_t *left_native, *right_native; /* Pointers to left & right children's native records */ H5B2_node_ptr_t *left_node_ptrs = NULL, *right_node_ptrs = NULL;/* Pointers to childs' node pointer info */ @@ -1171,9 +1171,9 @@ H5B2_merge2(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, #ifdef H5B2_DEBUG H5B2_assert_internal((hsize_t)0, hdr, internal); if(depth > 1) - H5B2_assert_internal(internal->node_ptrs[idx].all_nrec, hdr, left_child); + H5B2_assert_internal(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)left_child); else - H5B2_assert_leaf(hdr, left_child); + H5B2_assert_leaf(hdr, (H5B2_leaf_t *)left_child); #endif /* H5B2_DEBUG */ done: @@ -1212,8 +1212,8 @@ H5B2_merge3(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, const H5AC_class_t *child_class; /* Pointer to child node's class info */ haddr_t left_addr, right_addr; /* Addresses of left & right child nodes */ haddr_t middle_addr; /* Address of middle child node */ - void *left_child, *right_child; /* Pointers to left & right child nodes */ - void *middle_child; /* Pointer to middle child node */ + void *left_child = NULL, *right_child = NULL; /* Pointers to left & right child nodes */ + void *middle_child = NULL; /* Pointer to middle child node */ uint16_t *left_nrec, *right_nrec; /* Pointers to left & right child # of records */ uint16_t *middle_nrec; /* Pointer to middle child # of records */ uint8_t *left_native, *right_native; /* Pointers to left & right children's native records */ @@ -1393,12 +1393,12 @@ H5B2_merge3(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, #ifdef H5B2_DEBUG H5B2_assert_internal((hsize_t)0, hdr, internal); if(depth > 1) { - H5B2_assert_internal2(internal->node_ptrs[idx - 1].all_nrec, hdr, left_child, middle_child); - H5B2_assert_internal(internal->node_ptrs[idx].all_nrec, hdr, middle_child); + H5B2_assert_internal2(internal->node_ptrs[idx - 1].all_nrec, hdr, (H5B2_internal_t *)left_child, (H5B2_internal_t *)middle_child); + H5B2_assert_internal(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)middle_child); } /* end if */ else { - H5B2_assert_leaf2(hdr, left_child, middle_child); - H5B2_assert_leaf(hdr, middle_child); + H5B2_assert_leaf2(hdr, (H5B2_leaf_t *)left_child, (H5B2_leaf_t *)middle_child); + H5B2_assert_leaf(hdr, (H5B2_leaf_t *)middle_child); } /* end else */ #endif /* H5B2_DEBUG */ @@ -1439,7 +1439,7 @@ H5B2_swap_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, { const H5AC_class_t *child_class; /* Pointer to child node's class info */ haddr_t child_addr; /* Address of child node */ - void *child; /* Pointer to child node */ + void *child = NULL; /* Pointer to child node */ uint8_t *child_native; /* Pointer to child's native records */ herr_t ret_value = SUCCEED; /* Return value */ @@ -1494,9 +1494,9 @@ H5B2_swap_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, #ifdef H5B2_DEBUG H5B2_assert_internal((hsize_t)0, hdr, internal); if(depth > 1) - H5B2_assert_internal(internal->node_ptrs[idx].all_nrec, hdr, child); + H5B2_assert_internal(internal->node_ptrs[idx].all_nrec, hdr, (H5B2_internal_t *)child); else - H5B2_assert_leaf(hdr, child); + H5B2_assert_leaf(hdr, (H5B2_leaf_t *)child); #endif /* H5B2_DEBUG */ done: @@ -1771,7 +1771,7 @@ HDmemset(leaf->leaf_native, 0, hdr->cls->nrec_size * hdr->node_info[0].max_nrec) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for B-tree leaf node") /* Cache the new B-tree node */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_BT2_LEAF, node_ptr->addr, leaf, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_BT2_LEAF, node_ptr->addr, leaf, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "can't add B-tree leaf to cache") done: @@ -1890,7 +1890,7 @@ HDmemset(internal->node_ptrs, 0, sizeof(H5B2_node_ptr_t) * (hdr->node_info[depth HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for B-tree internal node") /* Cache the new B-tree node */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_BT2_INT, node_ptr->addr, internal, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_BT2_INT, node_ptr->addr, internal, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "can't add B-tree internal node to cache") done: @@ -3082,7 +3082,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5B2_assert_leaf(H5B2_hdr_t *hdr, H5B2_leaf_t *leaf) +H5B2_assert_leaf(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf) { /* General sanity checking on node */ HDassert(leaf->nrec <= hdr->node_info->split_nrec); @@ -3105,13 +3105,13 @@ H5B2_assert_leaf(H5B2_hdr_t *hdr, H5B2_leaf_t *leaf) *------------------------------------------------------------------------- */ static herr_t -H5B2_assert_leaf2(H5B2_hdr_t *hdr, H5B2_leaf_t *leaf, H5B2_leaf_t *leaf2) +H5B2_assert_leaf2(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf, const H5B2_leaf_t UNUSED *leaf2) { /* General sanity checking on node */ HDassert(leaf->nrec <= hdr->node_info->split_nrec); return(0); -} /* end H5B2_assert_leaf() */ +} /* end H5B2_assert_leaf2() */ /*------------------------------------------------------------------------- @@ -3128,10 +3128,10 @@ H5B2_assert_leaf2(H5B2_hdr_t *hdr, H5B2_leaf_t *leaf, H5B2_leaf_t *leaf2) *------------------------------------------------------------------------- */ static herr_t -H5B2_assert_internal(hsize_t parent_all_nrec, H5B2_hdr_t *hdr, H5B2_internal_t *internal) +H5B2_assert_internal(hsize_t parent_all_nrec, const H5B2_hdr_t *hdr, const H5B2_internal_t *internal) { hsize_t tot_all_nrec; /* Total number of records at or below this node */ - unsigned u, v; /* Local index variables */ + uint16_t u, v; /* Local index variables */ /* General sanity checking on node */ HDassert(internal->nrec <= hdr->node_info->split_nrec); @@ -3169,10 +3169,10 @@ H5B2_assert_internal(hsize_t parent_all_nrec, H5B2_hdr_t *hdr, H5B2_internal_t * *------------------------------------------------------------------------- */ static herr_t -H5B2_assert_internal2(hsize_t parent_all_nrec, H5B2_hdr_t *hdr, H5B2_internal_t *internal, H5B2_internal_t *internal2) +H5B2_assert_internal2(hsize_t parent_all_nrec, const H5B2_hdr_t *hdr, const H5B2_internal_t *internal, const H5B2_internal_t *internal2) { hsize_t tot_all_nrec; /* Total number of records at or below this node */ - unsigned u, v; /* Local index variables */ + uint16_t u, v; /* Local index variables */ /* General sanity checking on node */ HDassert(internal->nrec <= hdr->node_info->split_nrec); @@ -150,8 +150,7 @@ static void * H5C_load_entry(H5F_t * f, hid_t dxpl_id, const H5C_class_t * type, haddr_t addr, - void * udata, - hbool_t skip_file_checks); + void * udata); static herr_t H5C_make_space_in_cache(H5F_t * f, hid_t primary_dxpl_id, @@ -1158,8 +1157,6 @@ H5C_create(size_t max_cache_size, H5C_stats__reset(cache_ptr); - cache_ptr->skip_file_checks = FALSE; - cache_ptr->skip_dxpl_id_checks = FALSE; cache_ptr->prefix[0] = '\0'; /* empty string */ /* Set return value */ @@ -1409,7 +1406,6 @@ H5C_dest(H5F_t * f, /* Sanity check */ HDassert(cache_ptr); HDassert(cache_ptr->magic == H5C__H5C_T_MAGIC); - HDassert(cache_ptr->skip_file_checks || f); /* Flush and invalidate all cache entries */ if(H5C_flush_invalidate_cache(f, primary_dxpl_id, secondary_dxpl_id, @@ -1595,7 +1591,6 @@ H5C_flush_cache(H5F_t *f, hid_t primary_dxpl_id, hid_t secondary_dxpl_id, unsign HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f); HDassert( cache_ptr->slist_ptr ); ignore_protected = ( (flags & H5C__FLUSH_IGNORE_PROTECTED_FLAG) != 0 ); @@ -1977,7 +1972,6 @@ H5C_flush_to_min_clean(H5F_t * f, HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f ); if ( cache_ptr->check_write_permitted != NULL ) { @@ -2547,7 +2541,6 @@ H5C_insert_entry(H5F_t * f, HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f ); HDassert( type ); HDassert( type->flush ); HDassert( type->size ); @@ -2870,7 +2863,6 @@ H5C_mark_entries_as_clean(H5F_t * f, cache_ptr = f->shared->cache; HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f ); HDassert( ce_array_len > 0 ); HDassert( ce_array_ptr != NULL ); @@ -3635,7 +3627,6 @@ H5C_protect(H5F_t * f, HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f ); HDassert( type ); HDassert( type->flush ); HDassert( type->load ); @@ -3698,7 +3689,7 @@ H5C_protect(H5F_t * f, hit = FALSE; - thing = H5C_load_entry(f, primary_dxpl_id, type, addr, udata, cache_ptr->skip_file_checks); + thing = H5C_load_entry(f, primary_dxpl_id, type, addr, udata); if ( thing == NULL ) { @@ -4414,48 +4405,6 @@ H5C_set_prefix(H5C_t * cache_ptr, char * prefix) /*------------------------------------------------------------------------- - * Function: H5C_set_skip_flags - * - * Purpose: Set the values of the skip sanity check flags. - * - * This function and the skip sanity check flags were created - * for the convenience of the test bed. However it is - * possible that there may be other uses for the flags. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: John Mainzer - * 6/11/04 - * - *------------------------------------------------------------------------- - */ -herr_t -H5C_set_skip_flags(H5C_t * cache_ptr, - hbool_t skip_file_checks, - hbool_t skip_dxpl_id_checks) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(H5C_set_skip_flags, FAIL) - - /* This would normally be an assert, but we need to use an HGOTO_ERROR - * call to shut up the compiler. - */ - if ( ( ! cache_ptr ) || ( cache_ptr->magic != H5C__H5C_T_MAGIC ) ) { - - HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr") - } - - cache_ptr->skip_file_checks = skip_file_checks; - cache_ptr->skip_dxpl_id_checks = skip_dxpl_id_checks; - -done: - FUNC_LEAVE_NOAPI(ret_value) - -} /* H5C_set_skip_flags() */ - - -/*------------------------------------------------------------------------- * Function: H5C_set_trace_file_ptr * * Purpose: Set the trace_file_ptr field for the cache. @@ -5236,7 +5185,6 @@ H5C_unprotect(H5F_t * f, HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f ); HDassert( type ); HDassert( type->clear ); HDassert( type->flush ); @@ -7421,7 +7369,6 @@ H5C_flush_invalidate_cache(H5F_t * f, HDassert( f ); HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f ); HDassert( cache_ptr->slist_ptr ); /* Filter out the flags that are not relevant to the flush/invalidate. @@ -7972,7 +7919,6 @@ H5C_flush_single_entry(H5F_t * f, HDassert( f ); HDassert( cache_ptr ); HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); - HDassert( cache_ptr->skip_file_checks || f ); HDassert( H5F_addr_defined(addr) ); HDassert( first_flush_ptr ); @@ -8042,14 +7988,8 @@ H5C_flush_single_entry(H5F_t * f, * Note that we only do these sanity checks when the clear_only flag * is not set, and the entry to be flushed is dirty. Don't bother * otherwise as no file I/O can result. - * - * There are also cases (testing for instance) where it is convenient - * to pass in dummy dxpl_ids. Since we don't use the dxpl_ids directly, - * this isn't a problem -- but we do have to turn off sanity checks - * involving them. We use cache_ptr->skip_dxpl_id_checks to do this. */ - if ( ( ! cache_ptr->skip_dxpl_id_checks ) && - ( ! clear_only ) && + if ( ( ! clear_only ) && ( entry_ptr->is_dirty ) && ( IS_H5FD_MPI(f) ) ) { @@ -8390,12 +8330,7 @@ H5C_load_entry(H5F_t * f, hid_t dxpl_id, const H5C_class_t * type, haddr_t addr, - void * udata, -#ifndef NDEBUG - hbool_t skip_file_checks) -#else /* NDEBUG */ - hbool_t UNUSED skip_file_checks) -#endif /* NDEBUG */ + void * udata) { void * thing = NULL; /* Pointer to thing loaded */ H5C_cache_entry_t * entry; /* Alias for thing loaded, as cache entry */ @@ -8407,7 +8342,6 @@ H5C_load_entry(H5F_t * f, HDassert(f); HDassert(f->shared); HDassert(f->shared->cache); - HDassert(skip_file_checks || f); HDassert(type); HDassert(type->load); HDassert(type->size); @@ -9048,31 +8982,21 @@ done: * Programmer: Mike McGreevy * December 1, 2009 * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t H5C_ignore_tags(H5C_t * cache_ptr) { - /* Variable Declarations */ - herr_t ret_value = SUCCEED; /* Return value */ - - /* Function Enter Macro */ - FUNC_ENTER_NOAPI(H5C_ignore_tags, FAIL) + FUNC_ENTER_NOAPI_NOFUNC(H5C_ignore_tags) /* Assertions */ - HDassert( cache_ptr != NULL ); - HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); + HDassert(cache_ptr != NULL); + HDassert(cache_ptr->magic == H5C__H5C_T_MAGIC); /* Set variable to ignore tag values upon assignment */ cache_ptr->ignore_tags = TRUE; -done: - - /* Function Leave Macro */ - FUNC_LEAVE_NOAPI(ret_value) - + FUNC_LEAVE_NOAPI(SUCCEED) } /* H5C_ignore_tags */ @@ -9097,38 +9021,32 @@ done: static herr_t H5C_tag_entry(H5C_t * cache_ptr, H5C_cache_entry_t * entry_ptr, hid_t dxpl_id) { - /* Variable Declarations */ - hid_t ret_value = SUCCEED; - haddr_t tag; - H5P_genplist_t *dxpl; /* dataset transfer property list */ + H5P_genplist_t *dxpl; /* dataset transfer property list */ + haddr_t tag; /* Tag address */ + hid_t ret_value = SUCCEED; /* Return value */ - /* Function Enter Macro */ FUNC_ENTER_NOAPI(H5C_tag_entry, FAIL) /* Assertions */ - HDassert( cache_ptr != NULL ); - HDassert( entry_ptr != NULL ); - HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); + HDassert(cache_ptr != NULL); + HDassert(entry_ptr != NULL); + HDassert(cache_ptr->magic == H5C__H5C_T_MAGIC); /* Get the dataset transfer property list */ if(NULL == (dxpl = (H5P_genplist_t *)H5I_object_verify(dxpl_id, H5I_GENPROP_LST))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list"); + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") /* Get the tag from the DXPL */ - if( (H5P_get(dxpl, "H5AC_metadata_tag", &tag)) < 0 ) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to query property value"); - - if (cache_ptr->ignore_tags != TRUE) { - - /* Perform some sanity checks to ensure that - a correct tag is being applied */ - #if H5C_DO_TAGGING_SANITY_CHECKS - if ( (H5C_verify_tag(entry_ptr->type->id, tag)) < 0 ) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "tag verification failed"); - #endif + if((H5P_get(dxpl, "H5AC_metadata_tag", &tag)) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to query property value") + if(cache_ptr->ignore_tags != TRUE) { +#if H5C_DO_TAGGING_SANITY_CHECKS + /* Perform some sanity checks to ensure that a correct tag is being applied */ + if(H5C_verify_tag(entry_ptr->type->id, tag) < 0) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "tag verification failed") +#endif } else { - /* if we're ignoring tags, it's because we're running tests on internal functions and may not have inserted a tag value into a given dxpl_id before creating some metadata. Thus, @@ -9136,19 +9054,15 @@ H5C_tag_entry(H5C_t * cache_ptr, H5C_cache_entry_t * entry_ptr, hid_t dxpl_id) arbitrarily set it to something for the sake of passing the tests. If the tag value is set, then we'll just let it get assigned without additional checking for correctness. */ - - if (!tag) tag = H5AC__IGNORE_TAG; - + if(!tag) + tag = H5AC__IGNORE_TAG; } /* end if */ /* Apply the tag to the entry */ entry_ptr->tag = tag; done: - - /* Function Leave Macro */ FUNC_LEAVE_NOAPI(ret_value) - } /* H5C_tag_entry */ @@ -9172,34 +9086,25 @@ done: static herr_t H5C_flush_tagged_entries(H5F_t * f, hid_t primary_dxpl_id, hid_t secondary_dxpl_id, H5C_t * cache_ptr, haddr_t tag) { - /* Variable Declarations */ - herr_t result; herr_t ret_value = SUCCEED; - /* Function Enter Macro */ FUNC_ENTER_NOAPI(H5C_flush_tagged_entries, FAIL) /* Assertions */ HDassert(0); /* This function is not yet used. We shouldn't be in here yet. */ - HDassert( cache_ptr != NULL ); - HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); + HDassert(cache_ptr != NULL); + HDassert(cache_ptr->magic == H5C__H5C_T_MAGIC); /* Mark all entries with specified tag */ - if ( (result = H5C_mark_tagged_entries(cache_ptr, tag)) < 0 ) + if(H5C_mark_tagged_entries(cache_ptr, tag) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't mark tagged entries") /* Flush all marked entries */ - if ( (result = H5C_flush_marked_entries(f, - primary_dxpl_id, - secondary_dxpl_id, - cache_ptr)) < 0 ) + if(H5C_flush_marked_entries(f, primary_dxpl_id, secondary_dxpl_id, cache_ptr) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush marked entries") done: - - /* Function Leave Macro */ FUNC_LEAVE_NOAPI(ret_value) - } /* H5C_flush_tagged_entries */ @@ -9224,44 +9129,29 @@ done: static herr_t H5C_mark_tagged_entries(H5C_t * cache_ptr, haddr_t tag) { - /* Variable Declarations */ - int i; /* Iterator */ - herr_t result; /* Result */ - H5C_cache_entry_t *next_entry_ptr = NULL; /* entry pointer */ - herr_t ret_value = SUCCEED; /* Return Value */ + H5C_cache_entry_t *next_entry_ptr; /* entry pointer */ + unsigned u; /* Local index variable */ - /* Function Enter Macro */ - FUNC_ENTER_NOAPI(H5C_mark_tagged_entries, FAIL) + FUNC_ENTER_NOAPI_NOINIT(H5C_mark_tagged_entries) /* Assertions */ HDassert(0); /* This function is not yet used. We shouldn't be in here yet. */ - HDassert( cache_ptr != NULL ); - HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); + HDassert(cache_ptr != NULL); + HDassert(cache_ptr->magic == H5C__H5C_T_MAGIC); /* Iterate through entries, marking those with specified tag. */ - for (i = 0; i < H5C__HASH_TABLE_LEN; i++) { - - next_entry_ptr = cache_ptr->index[i]; - - while ( next_entry_ptr != NULL ) { - - if ( next_entry_ptr->tag == tag ) { + for(u = 0; u < H5C__HASH_TABLE_LEN; u++) { + next_entry_ptr = cache_ptr->index[u]; + while(next_entry_ptr != NULL) { + if(next_entry_ptr->tag == tag) next_entry_ptr->flush_marker = TRUE; - } /* end if */ - next_entry_ptr = next_entry_ptr->ht_next; - } /* end while */ - } /* for */ -done: - - /* Function Leave Macro */ - FUNC_LEAVE_NOAPI(ret_value); - + FUNC_LEAVE_NOAPI(SUCCEED) } /* H5C_mark_tagged_entries */ @@ -9285,26 +9175,19 @@ done: static herr_t H5C_flush_marked_entries(H5F_t * f, hid_t primary_dxpl_id, hid_t secondary_dxpl_id, H5C_t * cache_ptr) { - /* Variable Declarations */ herr_t ret_value = SUCCEED; - /* Function Enter Macro */ FUNC_ENTER_NOAPI(H5C_flush_marked_entries, FAIL) /* Assertions */ HDassert(0); /* This function is not yet used. We shouldn't be in here yet. */ - HDassert( cache_ptr != NULL ); - HDassert( cache_ptr->magic == H5C__H5C_T_MAGIC ); + HDassert(cache_ptr != NULL); + HDassert(cache_ptr->magic == H5C__H5C_T_MAGIC); /* Flush all marked entries */ - if(H5C_flush_cache(f, - primary_dxpl_id, - secondary_dxpl_id, - H5C__FLUSH_MARKED_ENTRIES_FLAG | - H5C__FLUSH_IGNORE_PROTECTED_FLAG) < 0) { - + if(H5C_flush_cache(f, primary_dxpl_id, secondary_dxpl_id, + H5C__FLUSH_MARKED_ENTRIES_FLAG | H5C__FLUSH_IGNORE_PROTECTED_FLAG) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush cache") - } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -9328,65 +9211,59 @@ done: static herr_t H5C_verify_tag(int id, haddr_t tag) { - /* Variable Declarations */ herr_t ret_value = SUCCEED; - /* Function Enter Macro */ FUNC_ENTER_NOAPI(H5C_verify_tag, FAIL) /* Perform some sanity checks on tag value. Certain entry * types require certain tag values, so check that these * constraints are met. */ - if (tag == H5AC__IGNORE_TAG) { - - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "cannot ignore a tag while doing verification."); - - } else if (tag == H5AC__INVALID_TAG) { - - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "no metadata tag provided"); - - } else { + if(tag == H5AC__IGNORE_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "cannot ignore a tag while doing verification.") + else if(tag == H5AC__INVALID_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "no metadata tag provided") + else { /* Perform some sanity checks on tag value. Certain entry * types require certain tag values, so check that these * constraints are met. */ /* Superblock */ - if (id == H5AC_SUPERBLOCK_ID) { - if (tag != H5AC__SUPERBLOCK_TAG) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "superblock not tagged with H5AC__SUPERBLOCK_TAG"); + if(id == H5AC_SUPERBLOCK_ID) { + if(tag != H5AC__SUPERBLOCK_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "superblock not tagged with H5AC__SUPERBLOCK_TAG") } else { - if (tag == H5AC__SUPERBLOCK_TAG) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "H5AC__SUPERBLOCK_TAG applied to non-superblock entry"); + if(tag == H5AC__SUPERBLOCK_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "H5AC__SUPERBLOCK_TAG applied to non-superblock entry") } /* Free Space Manager */ - if ((id == H5AC_FSPACE_HDR_ID) || (id == H5AC_FSPACE_SINFO_ID)) { - if (tag != H5AC__FREESPACE_TAG) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "freespace entry not tagged with H5AC__FREESPACE_TAG"); + if((id == H5AC_FSPACE_HDR_ID) || (id == H5AC_FSPACE_SINFO_ID)) { + if(tag != H5AC__FREESPACE_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "freespace entry not tagged with H5AC__FREESPACE_TAG") } else { - if (tag == H5AC__FREESPACE_TAG) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "H5AC__FREESPACE_TAG applied to non-freespace entry"); + if(tag == H5AC__FREESPACE_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "H5AC__FREESPACE_TAG applied to non-freespace entry") } /* SOHM */ - if ((id == H5AC_SOHM_TABLE_ID) || (id == H5AC_SOHM_LIST_ID)) { - if (tag != H5AC__SOHM_TAG) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "sohm entry not tagged with H5AC__SOHM_TAG"); + if((id == H5AC_SOHM_TABLE_ID) || (id == H5AC_SOHM_LIST_ID)) { + if(tag != H5AC__SOHM_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "sohm entry not tagged with H5AC__SOHM_TAG") } /* Global Heap */ - if (id == H5AC_GHEAP_ID) { - if (tag != H5AC__GLOBALHEAP_TAG) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "global heap not tagged with H5AC__GLOBALHEAP_TAG"); + if(id == H5AC_GHEAP_ID) { + if(tag != H5AC__GLOBALHEAP_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "global heap not tagged with H5AC__GLOBALHEAP_TAG") } else { - if (tag == H5AC__GLOBALHEAP_TAG) - HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "H5AC__GLOBALHEAP_TAG applied to non-globalheap entry"); + if(tag == H5AC__GLOBALHEAP_TAG) + HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "H5AC__GLOBALHEAP_TAG applied to non-globalheap entry") } - } + } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -9412,24 +9289,21 @@ done: void H5C_retag_copied_metadata(H5C_t * cache_ptr, haddr_t metadata_tag) { - /* Variable Declarations */ - int i = 0; /* Iterator */ - - /* Assertions */ - HDassert(cache_ptr); + unsigned u; /* Local index variable */ - /* Function Enter Macro */ FUNC_ENTER_NOAPI_NOFUNC(H5C_retag_copied_metadata) + HDassert(cache_ptr); + /* Iterate through entries, retagging those with the H5AC__COPIED_TAG tag */ - for(i = 0; i < H5C__HASH_TABLE_LEN; i++) { + for(u = 0; u < H5C__HASH_TABLE_LEN; u++) { H5C_cache_entry_t *next_entry_ptr; /* entry pointer */ - next_entry_ptr = cache_ptr->index[i]; + next_entry_ptr = cache_ptr->index[u]; while(next_entry_ptr != NULL) { - if(cache_ptr->index[i] != NULL) { - if((cache_ptr->index[i])->tag == H5AC__COPIED_TAG) - (cache_ptr->index[i])->tag = metadata_tag; + if(cache_ptr->index[u] != NULL) { + if((cache_ptr->index[u])->tag == H5AC__COPIED_TAG) + (cache_ptr->index[u])->tag = metadata_tag; } /* end if */ next_entry_ptr = next_entry_ptr->ht_next; diff --git a/src/H5Cpkg.h b/src/H5Cpkg.h index b4a8944..06eeb48 100644 --- a/src/H5Cpkg.h +++ b/src/H5Cpkg.h @@ -832,25 +832,6 @@ * * Fields supporting testing: * - * For test purposes, it is useful to turn off some asserts and sanity - * checks. The following flags support this. - * - * skip_file_checks: Boolean flag used to skip sanity checks on file - * parameters passed to the cache. In the test bed, there - * is no reason to have a file open, as the cache proper - * just passes these parameters through without using them. - * - * When this flag is set, all sanity checks on the file - * parameters are skipped. The field defaults to FALSE. - * - * skip_dxpl_id_checks: Boolean flag used to skip sanity checks on the - * dxpl_id parameters passed to the cache. These are not - * used directly by the cache, so skipping the checks - * simplifies the test bed. - * - * When this flag is set, all sanity checks on the dxpl_id - * parameters are skipped. The field defaults to FALSE. - * * prefix Array of char used to prefix debugging output. The * field is intended to allow marking of output of with * the processes mpi rank. @@ -1014,8 +995,6 @@ struct H5C_t #endif /* H5C_COLLECT_CACHE_STATS */ - hbool_t skip_file_checks; - hbool_t skip_dxpl_id_checks; char prefix[H5C__PREFIX_LEN]; }; diff --git a/src/H5Cprivate.h b/src/H5Cprivate.h index 7e14872..9f10409 100644 --- a/src/H5Cprivate.h +++ b/src/H5Cprivate.h @@ -1171,10 +1171,6 @@ H5_DLL herr_t H5C_set_evictions_enabled(H5C_t *cache_ptr, H5_DLL herr_t H5C_set_prefix(H5C_t * cache_ptr, char * prefix); -H5_DLL herr_t H5C_set_skip_flags(H5C_t * cache_ptr, - hbool_t skip_file_checks, - hbool_t skip_dxpl_id_checks); - H5_DLL herr_t H5C_set_trace_file_ptr(H5C_t * cache_ptr, FILE * trace_file_ptr); diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index fa4b62c..cde291f 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -402,6 +402,10 @@ H5D_chunk_construct(H5F_t UNUSED *f, H5D_t *dset) HDassert(f); HDassert(dset); + /* Check for invalid chunk dimension rank */ + if(0 == dset->shared->layout.u.chunk.ndims) + HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "no chunk information set?") + /* Set up layout information */ if((ndims = H5S_GET_EXTENT_NDIMS(dset->shared->space)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to get rank") @@ -424,13 +428,18 @@ H5D_chunk_construct(H5F_t UNUSED *f, H5D_t *dset) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to query maximum dimensions") /* Sanity check dimensions */ - for(u = 0; u < dset->shared->layout.u.chunk.ndims - 1; u++) + for(u = 0; u < dset->shared->layout.u.chunk.ndims - 1; u++) { + /* Don't allow zero-sized chunk dimensions */ + if(0 == dset->shared->layout.u.chunk.dim[u]) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "chunk size must be > 0, dim = %u ", u) + /* * The chunk size of a dimension with a fixed size cannot exceed * the maximum dimension size */ if(max_dim[u] != H5S_UNLIMITED && max_dim[u] < dset->shared->layout.u.chunk.dim[u]) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "chunk size must be <= maximum dimension size for fixed-sized dimensions") + } /* end for */ /* Compute the total size of a chunk */ /* (Use 64-bit value to ensure that we can detect >4GB chunks) */ diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index f0929d9..a9c0dd5 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -168,13 +168,16 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t H5D_compact_construct(H5F_t *f, H5D_t *dset) { hssize_t stmp_size; /* Temporary holder for raw data size */ hsize_t tmp_size; /* Temporary holder for raw data size */ hsize_t max_comp_data_size; /* Max. allowed size of compact data */ + hsize_t dim[H5O_LAYOUT_NDIMS]; /* Current size of data in elements */ + hsize_t max_dim[H5O_LAYOUT_NDIMS]; /* Maximum size of data in elements */ + int ndims; /* Rank of dataspace */ + int i; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5D_compact_construct) @@ -183,6 +186,13 @@ H5D_compact_construct(H5F_t *f, H5D_t *dset) HDassert(f); HDassert(dset); + /* Check for invalid dataset dimensions */ + if((ndims = H5S_get_simple_extent_dims(dset->shared->space, dim, max_dim)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get dataspace dimensions") + for(i = 0; i < ndims; i++) + if(max_dim[i] > dim[i]) + HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "extendible compact dataset") + /* * Compact dataset is stored in dataset object header message of * layout. diff --git a/src/H5Dfill.c b/src/H5Dfill.c index 1929a5a..1999dda 100644 --- a/src/H5Dfill.c +++ b/src/H5Dfill.c @@ -585,7 +585,8 @@ H5D_fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts, hid_t dxpl_id) HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed") /* Replicate the fill value into the cached buffer */ - H5V_array_fill(fb_info->fill_buf, fb_info->fill_buf, fb_info->mem_elmt_size, nelmts); + if(nelmts > 1) + H5V_array_fill((void *)((unsigned char *)fb_info->fill_buf + fb_info->mem_elmt_size), fb_info->fill_buf, fb_info->mem_elmt_size, (nelmts - 1)); /* Reset the entire background buffer, if necessary */ if(H5T_path_bkg(fb_info->mem_to_dset_tpath)) @@ -596,6 +597,9 @@ H5D_fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts, hid_t dxpl_id) buf = fb_info->fill_alloc_func(fb_info->fill_buf_size, fb_info->fill_alloc_info); else buf = H5FL_BLK_MALLOC(non_zero_fill, fb_info->fill_buf_size); + 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); /* Type convert the dataset buffer, to copy any VL components */ @@ -603,12 +607,16 @@ H5D_fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts, hid_t dxpl_id) HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed") done: - if (buf) { + if(buf) { /* Free dynamically allocated VL elements in fill buffer */ - if (fb_info->fill->type) - H5T_vlen_reclaim_elmt(buf, fb_info->fill->type, dxpl_id); - else - H5T_vlen_reclaim_elmt(buf, fb_info->mem_type, dxpl_id); + if(fb_info->fill->type) { + if(H5T_vlen_reclaim_elmt(buf, fb_info->fill->type, dxpl_id) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't reclaim vlen element") + } /* end if */ + else { + if(H5T_vlen_reclaim_elmt(buf, fb_info->mem_type, dxpl_id) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't reclaim vlen element") + } /* end else */ /* Free temporary fill buffer */ if(fb_info->fill_free_func) diff --git a/src/H5Dlayout.c b/src/H5Dlayout.c index bbcdcdd..1505f0e 100644 --- a/src/H5Dlayout.c +++ b/src/H5Dlayout.c @@ -274,7 +274,7 @@ H5D_layout_set_latest_version(H5O_layout_t *layout, const H5S_t *space) /* Query the dimensionality of the dataspace */ if((sndims = H5S_GET_EXTENT_NDIMS(space)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "invalid dataspace rank") + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "invalid dataspace rank") ndims = (unsigned)sndims; /* Avoid scalar/null dataspace */ @@ -285,7 +285,7 @@ H5D_layout_set_latest_version(H5O_layout_t *layout, const H5S_t *space) /* Query the dataspace's dimensions */ if(H5S_get_simple_extent_dims(space, NULL, max_dims) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "can't get dataspace max. dimensions") + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get dataspace max. dimensions") /* Spin through the max. dimensions, looking for unlimited dimensions */ for(u = 0; u < ndims; u++) @@ -294,7 +294,10 @@ H5D_layout_set_latest_version(H5O_layout_t *layout, const H5S_t *space) /* Chunked datasets with unlimited dimension(s) */ if(unlim_count) { /* dataset with unlimited dimension(s) must be chunked */ - HDassert(layout->type == H5D_CHUNKED); + /* Check for invalid layout type */ + if(layout->type != H5D_CHUNKED) + HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "dataset with unlimited dimensions is not chunked") + if(1 == unlim_count) { /* Chunked dataset with only 1 unlimited dimension */ layout->u.chunk.idx_type = H5D_CHUNK_IDX_EARRAY; layout->storage.u.chunk.idx_type = H5D_CHUNK_IDX_EARRAY; diff --git a/src/H5Dproxy.c b/src/H5Dproxy.c index 8a94402..fb52517 100644 --- a/src/H5Dproxy.c +++ b/src/H5Dproxy.c @@ -350,7 +350,7 @@ HDfprintf(stderr, "%s: ent->proxy_addr = %a\n", FUNC, ent->proxy_addr); proxy->ent = ent; /* Insert chunk proxy into metadata cache, pinned */ - if(H5AC_set(dset->oloc.file, dxpl_id, H5AC_CHUNK_PROXY, ent->proxy_addr, proxy, H5AC__PIN_ENTRY_FLAG) < 0) + if(H5AC_insert_entry(dset->oloc.file, dxpl_id, H5AC_CHUNK_PROXY, ent->proxy_addr, proxy, H5AC__PIN_ENTRY_FLAG) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't add chunk proxy to cache") /* Compose chunked index info struct */ diff --git a/src/H5Dtest.c b/src/H5Dtest.c index 49b0986..68208b3 100644 --- a/src/H5Dtest.c +++ b/src/H5Dtest.c @@ -14,7 +14,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Programmer: Quincey Koziol <koziol@ncsa.uiuc.edu> - * Thusdayr, May 27, 2004 + * Thursday, May 27, 2004 * * Purpose: Dataset testing functions. */ diff --git a/src/H5EAdblkpage.c b/src/H5EAdblkpage.c index 1876262..eba7470 100644 --- a/src/H5EAdblkpage.c +++ b/src/H5EAdblkpage.c @@ -179,7 +179,7 @@ HDfprintf(stderr, "%s: dblk_page->size = %Zu\n", FUNC, dblk_page->size); H5E_THROW(H5E_CANTSET, "can't set extensible array data block page elements to class's fill value") /* Cache the new extensible array data block page */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add extensible array data block page to cache") CATCH diff --git a/src/H5EAdblock.c b/src/H5EAdblock.c index 1378c6b..640f353 100644 --- a/src/H5EAdblock.c +++ b/src/H5EAdblock.c @@ -206,7 +206,7 @@ HDfprintf(stderr, "%s: dblock->block_off = %Hu\n", FUNC, dblock->block_off); H5E_THROW(H5E_CANTSET, "can't set extensible array data block elements to class's fill value") /* Cache the new extensible array data block */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_EARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_EARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add extensible array data block to cache") /* Update extensible array data block statistics */ diff --git a/src/H5EAhdr.c b/src/H5EAhdr.c index a7f12a5..0d283ea 100644 --- a/src/H5EAhdr.c +++ b/src/H5EAhdr.c @@ -436,7 +436,7 @@ HDfprintf(stderr, "%s: Called\n", FUNC); H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array header") /* Cache the new extensible array header */ - if(H5AC_set(f, dxpl_id, H5AC_EARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_EARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add extensible array header to cache") /* Set address of array header to return */ diff --git a/src/H5EAiblock.c b/src/H5EAiblock.c index 2fde249..e18947a 100644 --- a/src/H5EAiblock.c +++ b/src/H5EAiblock.c @@ -231,7 +231,7 @@ HDfprintf(stderr, "%s: iblock->size = %Zu\n", FUNC, iblock->size); } /* end if */ /* Cache the new extensible array index block */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_EARRAY_IBLOCK, iblock_addr, iblock, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_EARRAY_IBLOCK, iblock_addr, iblock, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add extensible array index block to cache") /* Update extensible array index block statistics */ diff --git a/src/H5EAsblock.c b/src/H5EAsblock.c index 938cd03..ba1c40f 100644 --- a/src/H5EAsblock.c +++ b/src/H5EAsblock.c @@ -232,7 +232,7 @@ HDfprintf(stderr, "%s: sblock->block_off = %Hu\n", FUNC, sblock->block_off); H5V_array_fill(sblock->dblk_addrs, &tmp_addr, sizeof(haddr_t), sblock->ndblks); /* Cache the new extensible array super block */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_EARRAY_SBLOCK, sblock_addr, sblock, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_EARRAY_SBLOCK, sblock_addr, sblock, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add extensible array super block to cache") /* Update extensible array super block statistics */ @@ -1197,12 +1197,26 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, tent_flags = flags; if(NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) { - if(tent_flags == flags) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") + if(tent_flags == flags) { +#ifndef H5_USING_MEMCHECKER + time_t mytime = HDtime(NULL); + + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: time = %s, name = '%s', tent_flags = %x", HDctime(&mytime), name, tent_flags) +#else /* H5_USING_MEMCHECKER */ + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', tent_flags = %x", name, tent_flags) +#endif /* H5_USING_MEMCHECKER */ + } /* end if */ H5E_clear_stack(NULL); tent_flags = flags; - if(NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") + if(NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) { +#ifndef H5_USING_MEMCHECKER + time_t mytime = HDtime(NULL); + + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: time = %s, name = '%s', tent_flags = %x", HDctime(&mytime), name, tent_flags) +#else /* H5_USING_MEMCHECKER */ + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', tent_flags = %x", name, tent_flags) +#endif /* H5_USING_MEMCHECKER */ + } /* end if */ } /* end if */ /* Is the file already open? */ diff --git a/src/H5FAdblkpage.c b/src/H5FAdblkpage.c index 2df31f2..b5ef82c 100644 --- a/src/H5FAdblkpage.c +++ b/src/H5FAdblkpage.c @@ -177,7 +177,7 @@ HDfprintf(stderr, "%s: dblk_page->size = %Zu\n", FUNC, dblk_page->size); H5E_THROW(H5E_CANTSET, "can't set fixed array data block page elements to class's fill value") /* Cache the new fixed array data block page */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add fixed array data block page to cache") CATCH diff --git a/src/H5FAdblock.c b/src/H5FAdblock.c index fd1dd89..80e2159 100644 --- a/src/H5FAdblock.c +++ b/src/H5FAdblock.c @@ -225,7 +225,7 @@ HDfprintf(stderr, "%s: dblock->size = %Zu\n", FUNC, dblock->size); H5E_THROW(H5E_CANTSET, "can't set fixed array data block elements to class's fill value") /* Cache the new fixed array data block */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_FARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_FARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add fixed array data block to cache") /* Mark the header dirty (for updating statistics) */ diff --git a/src/H5FAhdr.c b/src/H5FAhdr.c index 5cfba0d..23a554a 100644 --- a/src/H5FAhdr.c +++ b/src/H5FAhdr.c @@ -222,7 +222,7 @@ HDfprintf(stderr, "%s: Called\n", FUNC); H5E_THROW(H5E_CANTALLOC, "file allocation failed for Fixed Array header") /* Cache the new Fixed Array header */ - if(H5AC_set(f, dxpl_id, H5AC_FARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_FARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add fixed array header to cache") /* Set address of array header to return */ diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c index 4d87dde..c6868e0 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -574,7 +574,7 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd if (HDposix_memalign(&buf2, file->fa.mboundary, file->fa.fbsize) != 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "HDposix_memalign failed") - if(o_flags &= O_CREAT) { + if(o_flags & O_CREAT) { if(write(file->fd, (void*)buf1, sizeof(int))<0) { if(write(file->fd, (void*)buf2, file->fa.fbsize)<0) HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, NULL, "file system may not support Direct I/O") @@ -590,8 +590,17 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd HGOTO_ERROR(H5E_FILE, H5E_READERROR, NULL, "file system may not support Direct I/O") else file->fa.must_align = TRUE; - } else - file->fa.must_align = FALSE; + } else { + if(o_flags & O_RDWR) { + if(file_seek(file->fd, (file_offset_t)0, SEEK_SET) < 0) + HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, NULL, "unable to seek to proper position") + if(write(file->fd, (void *)buf1, sizeof(int))<0) + file->fa.must_align = TRUE; + else + file->fa.must_align = FALSE; + } else + file->fa.must_align = FALSE; + } } if(buf1) @@ -918,12 +927,13 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha hbool_t _must_align = TRUE; herr_t ret_value=SUCCEED; /* Return value */ size_t alloc_size; - void *copy_buf, *p2, *p3; + void *copy_buf = NULL, *p2; size_t _boundary; size_t _fbsize; size_t _cbsize; - haddr_t copy_addr = addr; - size_t copy_size = size; + haddr_t read_size; /* Size to read into copy buffer */ + size_t copy_size = size; /* Size remaining to read when using copy buffer */ + size_t copy_offset; /* Offset into copy buffer of the requested data */ FUNC_ENTER_NOAPI(H5FD_direct_read, FAIL) @@ -987,19 +997,24 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha buf = (char*)buf + nbytes; } } else { + /* Calculate where we will begin copying from the copy buffer */ + copy_offset = (size_t)(addr % _fbsize); + /* allocate memory needed for the Direct IO option up to the maximal * copy buffer size. Make a bigger buffer for aligned I/O if size is * smaller than maximal copy buffer. */ - if(size < _cbsize) - alloc_size = ((size / _fbsize) * _fbsize) + _fbsize; - else + alloc_size = ((copy_offset + size - 1) / _fbsize + 1) * _fbsize; + if(alloc_size > _cbsize) alloc_size = _cbsize; + HDassert(!(alloc_size % _fbsize)); if (HDposix_memalign(©_buf, _boundary, alloc_size) != 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "HDposix_memalign failed") - /* look for the aligned position for reading the data */ - if(file_seek(file->fd, (file_offset_t)(copy_addr - copy_addr % _fbsize), SEEK_SET) < 0) - HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") + /* look for the aligned position for reading the data */ + HDassert(!(((addr / _fbsize) * _fbsize) % _fbsize)); + if(file_seek(file->fd, (file_offset_t)((addr / _fbsize) * _fbsize), + SEEK_SET) < 0) + HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") /* * Read the aligned data in file into aligned buffer first, then copy the data @@ -1007,7 +1022,6 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha * size, do the reading by segment (the outer while loop). If not, do one step * reading. */ - p3 = buf; do { /* Read the aligned data in file first. Not able to handle interrupted * system calls and partial results like sec2 driver does because the @@ -1015,41 +1029,48 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha * file is smaller than ALLOC_SIZE. */ HDmemset(copy_buf, 0, alloc_size); + /* Calculate how much data we have to read in this iteration + * (including unused parts of blocks) */ + if((copy_size + copy_offset) < alloc_size) + read_size = ((copy_size + copy_offset - 1) / _fbsize + 1) + * _fbsize; + else + read_size = alloc_size; + + HDassert(!(read_size % _fbsize)); do { - nbytes = HDread(file->fd, copy_buf, alloc_size); + nbytes = HDread(file->fd, copy_buf, read_size); } while(-1==nbytes && EINTR==errno); if (-1==nbytes) /* error */ HSYS_GOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed") - /* look for the right position and copy the data to the original buffer. - * Consider all possible situations here: file address is not aligned on - * file block size; the end of data address is not aligned; the end of data - * address is aligned; data size is smaller or bigger than maximal copy size.*/ - p2 = (unsigned char*)copy_buf + (size_t)(copy_addr % _fbsize); - if(size < _cbsize) - HDmemcpy(p3, p2, size); - else if(size >= _cbsize && copy_size <= (alloc_size-(size_t)(copy_addr%_fbsize))) - HDmemcpy(p3, p2, copy_size); - else if(size >= _cbsize && copy_size > (alloc_size-(size_t)(copy_addr%_fbsize))) { - HDmemcpy(p3, p2, (alloc_size - (size_t)(copy_addr % _fbsize))); - p3 = (unsigned char*)p3 + (alloc_size - (size_t)(copy_addr % _fbsize)); - } - - /* update the size and address of data being read. */ - if(copy_size > (alloc_size - (size_t)(copy_addr % _fbsize))) - copy_size -= (alloc_size - (size_t)(copy_addr % _fbsize)); - else - copy_size = 0; - copy_addr += (alloc_size - (size_t)(copy_addr % _fbsize)); + /* Copy the needed data from the copy buffer to the output + * buffer, and update copy_size. If the copy buffer does not + * contain the rest of the data, just copy what's in the copy + * buffer and also update read_addr and copy_offset to read the + * next section of data. */ + p2 = (unsigned char*)copy_buf + copy_offset; + if((copy_size + copy_offset) <= alloc_size) { + HDmemcpy(buf, p2, copy_size); + buf = (unsigned char *)buf + copy_size; + copy_size = 0; + } /* end if */ + else { + HDmemcpy(buf, p2, alloc_size - copy_offset); + buf = (unsigned char*)buf + alloc_size - copy_offset; + copy_size -= alloc_size - copy_offset; + copy_offset = 0; + } /* end else */ } while (copy_size > 0); - /*Final step: update address and buffer*/ - addr += (haddr_t)size; - buf = (unsigned char*)buf + size; + /*Final step: update address*/ + addr = (haddr_t)(((addr + size - 1) / _fbsize + 1) * _fbsize); - if(copy_buf) - HDfree(copy_buf); + if(copy_buf) { + HDfree(copy_buf); + copy_buf = NULL; + } /* end if */ } /* Update current position */ @@ -1058,6 +1079,9 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha done: if(ret_value<0) { + if(copy_buf) + HDfree(copy_buf); + /* Reset last file I/O information */ file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; @@ -1094,13 +1118,16 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h hbool_t _must_align = TRUE; herr_t ret_value=SUCCEED; /* Return value */ size_t alloc_size; - void *copy_buf, *p1; + void *copy_buf = NULL, *p1; const void *p3; size_t _boundary; size_t _fbsize; size_t _cbsize; - haddr_t copy_addr = addr; - size_t copy_size = size; + haddr_t write_addr; /* Address to write copy buffer */ + haddr_t write_size; /* Size to write from copy buffer */ + haddr_t read_size; /* Size to read into copy buffer */ + size_t copy_size = size; /* Size remaining to write when using copy buffer */ + size_t copy_offset; /* Offset into copy buffer of the data to write */ FUNC_ENTER_NOAPI(H5FD_direct_write, FAIL) @@ -1152,41 +1179,83 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h buf = (const char*)buf + nbytes; } } else { + /* Calculate where we will begin reading from (on disk) and where we + * will begin copying from the copy buffer */ + write_addr = (addr / _fbsize) * _fbsize; + copy_offset = (size_t)(addr % _fbsize); + /* allocate memory needed for the Direct IO option up to the maximal * copy buffer size. Make a bigger buffer for aligned I/O if size is * smaller than maximal copy buffer. */ - if(size < _cbsize) - alloc_size = ((size / _fbsize) * _fbsize) + _fbsize; - else - alloc_size = _cbsize; + alloc_size = ((copy_offset + size - 1) / _fbsize + 1) * _fbsize; + if(alloc_size > _cbsize) + alloc_size = _cbsize; + HDassert(!(alloc_size % _fbsize)); if (HDposix_memalign(©_buf, _boundary, alloc_size) != 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "HDposix_memalign failed") - /* look for the right position for reading the data */ - if(file_seek(file->fd, (file_offset_t)(copy_addr - copy_addr % _fbsize), SEEK_SET) < 0) - HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") + /* look for the right position for reading or writing the data */ + if(file_seek(file->fd, (file_offset_t)write_addr, SEEK_SET) < 0) + HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") p3 = buf; do { + /* Calculate how much data we have to write in this iteration + * (including unused parts of blocks) */ + if((copy_size + copy_offset) < alloc_size) + write_size = ((copy_size + copy_offset - 1) / _fbsize + 1) + * _fbsize; + else + write_size = alloc_size; + /* * Read the aligned data first if the aligned region doesn't fall * entirely in the range to be writen. Not able to handle interrupted * system calls and partial results like sec2 driver does because the * data may no longer be aligned. It's expecially true when the data in - * file is smaller than ALLOC_SIZE. + * file is smaller than ALLOC_SIZE. Only read the entire section if + * both ends are misaligned, otherwise only read the block on the + * misaligned end. */ - HDmemset(copy_buf, 0, alloc_size); - - if(copy_addr <= addr || (copy_addr + alloc_size) >= (addr + size)) { - do { - nbytes = read(file->fd, copy_buf, alloc_size); - } while (-1==nbytes && EINTR==errno); - - if (-1==nbytes) /* error */ - HSYS_GOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed") - } + HDmemset(copy_buf, 0, _fbsize); + + if(copy_offset > 0) { + if((write_addr + write_size) > (addr + size)) { + HDassert((write_addr + write_size) - (addr + size) < _fbsize); + read_size = write_size; + p1 = copy_buf; + } /* end if */ + else { + read_size = _fbsize; + p1 = copy_buf; + } /* end else */ + } /* end if */ + else if((write_addr + write_size) > (addr + size)) { + HDassert((write_addr + write_size) - (addr + size) < _fbsize); + read_size = _fbsize; + p1 = (unsigned char *)copy_buf + write_size - _fbsize; + + /* Seek to the last block, for reading */ + HDassert(!((write_addr + write_size - _fbsize) % _fbsize)); + if(file_seek(file->fd, + (file_offset_t)(write_addr + write_size - _fbsize), + SEEK_SET) < 0) + HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") + } /* end if */ + else + p1 = NULL; + + if(p1) { + HDassert(!(read_size % _fbsize)); + do { + nbytes = read(file->fd, p1, read_size); + } while (-1==nbytes && EINTR==errno); + + if (-1==nbytes) /* error */ + HSYS_GOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed") + } /* end if */ /* look for the right position and append or copy the data to be written to * the aligned buffer. @@ -1194,46 +1263,47 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h * file block size; the end of data address is not aligned; the end of data * address is aligned; data size is smaller or bigger than maximal copy size. */ - p1 = (unsigned char*)copy_buf + (size_t)(copy_addr % _fbsize); - if(size < _cbsize) - HDmemcpy(p1, p3, size); - else if(size >= _cbsize && copy_size <= (alloc_size-(size_t)(copy_addr%_fbsize))) { - HDmemcpy(p1, p3, copy_size); - }else if(size >= _cbsize && copy_size > (alloc_size-(size_t)(copy_addr%_fbsize))) { - HDmemcpy(p1, p3, (alloc_size - (size_t)(copy_addr % _fbsize))); - p3 = (const unsigned char *)p3 + (alloc_size - (size_t)(copy_addr % _fbsize)); - } + p1 = (unsigned char *)copy_buf + copy_offset; + if((copy_size + copy_offset) <= alloc_size) { + HDmemcpy(p1, p3, copy_size); + copy_size = 0; + } /* end if */ + else { + HDmemcpy(p1, p3, alloc_size - copy_offset); + p3 = (const unsigned char *)p3 + (alloc_size - copy_offset); + copy_size -= alloc_size - copy_offset; + copy_offset = 0; + } /* end else */ /*look for the aligned position for writing the data*/ - if(file_seek(file->fd, (file_offset_t)(copy_addr - copy_addr % _fbsize), SEEK_SET) < 0) + HDassert(!(write_addr % _fbsize)); + if(file_seek(file->fd, (file_offset_t)write_addr, SEEK_SET) < 0) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") /* * Write the data. It doesn't truncate the extra data introduced by * alignment because that step is done in H5FD_direct_flush. */ + HDassert(!(write_size % _fbsize)); do { - nbytes = HDwrite(file->fd, copy_buf, alloc_size); + nbytes = HDwrite(file->fd, copy_buf, write_size); } while (-1==nbytes && EINTR==errno); if (-1==nbytes) /* error */ HSYS_GOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") - /* update the size and address of data being read. */ - if(copy_size > (alloc_size - (size_t)(copy_addr % _fbsize))) - copy_size -= (alloc_size - (size_t)(copy_addr % _fbsize)); - else - copy_size = 0; - - copy_addr += (alloc_size - (size_t)(copy_addr % _fbsize)); + /* update the write address */ + write_addr += write_size; } while (copy_size > 0); /*Update the address and size*/ - addr += (haddr_t)size; + addr = write_addr; buf = (const char*)buf + size; - if(copy_buf) + if(copy_buf) { HDfree(copy_buf); + copy_buf = NULL; + } /* end if */ } /* Update current position and eof */ @@ -1244,6 +1314,9 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h done: if(ret_value<0) { + if(copy_buf) + HDfree(copy_buf); + /* Reset last file I/O information */ file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index ab2bc72..4c7b4ba 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -110,24 +110,14 @@ typedef struct H5FD_sec2_t { * some macros here so we don't have to have conditional compilations later * throughout the code. * - * file_offset_t: The datatype for file offsets, the second argument of - * the lseek() or lseek64() call. + * HDoff_t: The datatype for file offsets, the second argument of + * the lseek() or lseek64() call. * */ -/* adding for windows NT file system support. */ - -#ifdef H5_HAVE_LSEEK64 -# define file_offset_t off64_t -#elif defined (_WIN32) && !defined(__MWERKS__) -# /*MSVC*/ -# define file_offset_t __int64 -#else -# define file_offset_t off_t -#endif /* * These macros check for overflow of various quantities. These macros - * assume that file_offset_t is signed and haddr_t and size_t are unsigned. + * assume that HDoff_t is signed and haddr_t and size_t are unsigned. * * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' * is too large to be represented by the second argument @@ -140,13 +130,13 @@ typedef struct H5FD_sec2_t { * which can be addressed entirely by the second * argument of the file seek function. */ -#define MAXADDR (((haddr_t)1<<(8*sizeof(file_offset_t)-1))-1) +#define MAXADDR (((haddr_t)1<<(8*sizeof(HDoff_t)-1))-1) #define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || \ ((A) & ~(haddr_t)MAXADDR)) #define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) #define REGION_OVERFLOW(A,Z) (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || \ HADDR_UNDEF==(A)+(Z) || \ - (file_offset_t)((A)+(Z))<(file_offset_t)(A)) + (HDoff_t)((A)+(Z))<(HDoff_t)(A)) /* Prototypes */ static H5FD_t *H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, @@ -347,7 +337,7 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) FUNC_ENTER_NOAPI(H5FD_sec2_open, NULL) /* Sanity check on file offsets */ - HDassert(sizeof(file_offset_t) >= sizeof(size_t)); + HDassert(sizeof(HDoff_t) >= sizeof(size_t)); /* Check arguments */ if(!name || !*name) @@ -369,9 +359,8 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) /* Open the file */ if((fd = HDopen(name, o_flags, 0666)) < 0) { int myerrno = errno; - time_t mytime = HDtime(NULL); - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: time = %s, name = '%s', errno = %d, error message = '%s', flags = %x, o_flags = %x", HDctime(&mytime), name, myerrno, HDstrerror(myerrno), flags, (unsigned)o_flags); + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', errno = %d, error message = '%s', flags = %x, o_flags = %x", name, myerrno, HDstrerror(myerrno), flags, (unsigned)o_flags); } /* end if */ if(HDfstat(fd, &sb) < 0) HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file") @@ -759,7 +748,7 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, /* Seek to the correct location */ if((addr != file->pos || OP_READ != file->op) && - HDlseek(file->fd, (file_offset_t)addr, SEEK_SET) < 0) + HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") /* @@ -773,7 +762,7 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, if(-1 == nbytes) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - file_offset_t myoffset = HDlseek(file->fd, (file_offset_t)0, SEEK_CUR); + HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, size = %lu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long)size, (unsigned long long)myoffset); } /* end if */ @@ -839,7 +828,7 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, had if(!H5F_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr) if(REGION_OVERFLOW(addr, size)) - HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr) + HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu", (unsigned long long)addr, (unsigned long long)size) /* If the file is open for SWMR read access, allow access to data past * the end of the allocated space (the 'eoa'). This is done because the * eoa stored in the file's superblock might be out of sync with the @@ -847,11 +836,11 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, had * SWMR write operations. */ if(!file->swmr_read && (addr + size) > file->eoa) - HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr) + HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu, eoa = %llu", (unsigned long long)addr, (unsigned long long)size, (unsigned long long)file->eoa) /* Seek to the correct location */ if((addr != file->pos || OP_WRITE != file->op) && - HDlseek(file->fd, (file_offset_t)addr, SEEK_SET) < 0) + HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") /* @@ -865,7 +854,7 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, had if(-1 == nbytes) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - file_offset_t myoffset = HDlseek(file->fd, (file_offset_t)0, SEEK_CUR); + HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, size = %lu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long)size, (unsigned long long)myoffset); } /* end if */ @@ -940,11 +929,11 @@ H5FD_sec2_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t UNUSED closing) #ifdef H5_VMS /* Reset seek offset to the beginning of the file, so that the file isn't * re-extended later. This may happen on Open VMS. */ - if(-1 == HDlseek(file->fd, (file_offset_t)0, SEEK_SET)) + if(-1 == HDlseek(file->fd, (HDoff_t)0, SEEK_SET)) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") #endif - if(-1 == HDftruncate(file->fd, (file_offset_t)file->eoa)) + if(-1 == HDftruncate(file->fd, (HDoff_t)file->eoa)) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to extend file properly") #endif /* _WIN32 */ @@ -959,3 +948,4 @@ H5FD_sec2_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t UNUSED closing) done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_sec2_truncate() */ + diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c index 40befaf..3cba6a1 100644 --- a/src/H5FDstdio.c +++ b/src/H5FDstdio.c @@ -116,16 +116,44 @@ typedef struct H5FD_stdio_t { hbool_t swmr_read; /* Whether the file is open for SWMR read access */ } H5FD_stdio_t; -#ifdef H5_HAVE_LSEEK64 -# define file_offset_t off64_t -# define file_truncate ftruncate64 -#elif defined (_WIN32) && !defined(__MWERKS__) -# /*MSVC*/ -# define file_offset_t __int64 -# define file_truncate _chsize -#else -# define file_offset_t off_t -# define file_truncate ftruncate +/* Use similar structure as in H5private.h by defining Windows stuff first. */ +#ifdef _WIN32 + #if _MSC_VER > 1310 /* Newer than VS.NET 2003 */ + # define file_fseek _fseeki64 + # define file_offset_t __int64 + # define file_ftruncate _chsize_s /* Supported in VS 2005 or newer */ + # define file_ftell _ftelli64 + #else + # define file_fseek fseek + # define file_offset_t long + # define file_ftruncate _chsize + # define file_ftell ftell + #endif +#endif + +/* Use file_xxx to indicate these are local macros, avoiding confusing + * with the global HD_xxx macros. + * Need fseeko, off_t, ftell and ftruncate are all of the same 32 or 64 + * versions. + * Assume fseeko, which is POSIX standard, is always supported; + * but prefer to use fseeko64 if supported. + * [Note: the ifndef H5_HAVE_FSEEKO condition to determine BIG FILE not + * supported was old code. This condition is not supposed to be true in Unix + * like systems but may happen in non-Unix systems like Windows. They are left + * in for now and will be cleaned later. -AKC-] + */ +#ifndef file_fseek + #ifdef H5_HAVE_FSEEKO64 + # define file_fseek fseeko64 + # define file_offset_t off64_t + # define file_ftruncate ftruncate64 + # define file_ftell ftello64 + #else + # define file_fseek fseeko + # define file_offset_t off_t + # define file_ftruncate ftruncate + # define file_ftell ftello + #endif #endif /* @@ -386,18 +414,10 @@ H5FD_stdio_open( const char *name, unsigned flags, hid_t fapl_id, file->op = H5FD_STDIO_OP_SEEK; file->pos = HADDR_UNDEF; file->write_access=write_access; /* Note the write_access for later */ -#ifdef H5_HAVE_FSEEKO - if(fseeko(file->fp, (off_t)0, SEEK_END) < 0) { -#else - if(fseek(file->fp, (long)0L, SEEK_END) < 0) { -#endif + if(file_fseek(file->fp, (file_offset_t)0, SEEK_END) < 0) { file->op = H5FD_STDIO_OP_UNKNOWN; } else { -#ifdef H5_HAVE_FTELLO - off_t x = ftello (file->fp); -#else - long x = ftell (file->fp); -#endif + file_offset_t x = file_ftell (file->fp); assert (x>=0); file->eof = (haddr_t)x; } @@ -821,11 +841,7 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, siz */ if (!(file->op == H5FD_STDIO_OP_READ || file->op==H5FD_STDIO_OP_SEEK) || file->pos != addr) { -#ifdef H5_HAVE_FSEEKO - if (fseeko(file->fp, (off_t)addr, SEEK_SET) < 0) { -#else - if (fseek(file->fp, (long)addr, SEEK_SET) < 0) { -#endif + if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) { file->op = H5FD_STDIO_OP_UNKNOWN; file->pos = HADDR_UNDEF; H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1) @@ -915,11 +931,7 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, */ if ((file->op != H5FD_STDIO_OP_WRITE && file->op != H5FD_STDIO_OP_SEEK) || file->pos != addr) { -#ifdef H5_HAVE_FSEEKO - if (fseeko(file->fp, (off_t)addr, SEEK_SET) < 0) { -#else - if (fseek(file->fp, (long)addr, SEEK_SET) < 0) { -#endif + if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) { file->op = H5FD_STDIO_OP_UNKNOWN; file->pos = HADDR_UNDEF; H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1) @@ -1012,6 +1024,9 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing) * Programmer: Quincey Koziol * Thursday, January 31, 2008 * + * Modifications: + * Vailin Choi; June 2010 + * Fix for window failures manifested from tests in mf.c. *------------------------------------------------------------------------- */ static herr_t @@ -1037,7 +1052,7 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing) HFILE filehandle; /* Windows file handle */ LARGE_INTEGER li; /* 64-bit integer for SetFilePointer() call */ - /* Reset seek offset to beginning of file, so that file isn't re-extended later */ + /* Reset seek offset to beginning of file, so that file isn't re-extended later */ rewind(file->fp); /* Map the posix file handle to a Windows file handle */ @@ -1054,7 +1069,7 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing) rewind(file->fp); /* Truncate file to proper length */ - if(-1 == file_truncate(fd, (file_offset_t)file->eoa)) + if(-1 == file_ftruncate(fd, (file_offset_t)file->eoa)) H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1) #endif /* _WIN32 */ @@ -143,7 +143,7 @@ HDfprintf(stderr, "%s: Creating free space manager, nclasses = %Zu\n", FUNC, ncl HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "file allocation failed for free space header") /* Cache the new free space header (pinned) */ - if(H5AC_set(f, dxpl_id, H5AC_FSPACE_HDR, fspace->addr, fspace, H5AC__PIN_ENTRY_FLAG) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_FSPACE_HDR, fspace->addr, fspace, H5AC__PIN_ENTRY_FLAG) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTINIT, NULL, "can't add free space header to cache") /* Return free space header address to caller, if desired */ @@ -401,7 +401,7 @@ HDfprintf(stderr, "%s: Real sections to store in file\n", FUNC); HDassert(H5F_addr_defined(fspace->sect_addr)); /* Cache the free space section info */ - if(H5AC_set(f, dxpl_id, H5AC_FSPACE_SINFO, fspace->sect_addr, fspace->sinfo, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_FSPACE_SINFO, fspace->sect_addr, fspace->sinfo, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTINIT, FAIL, "can't add free space sections to cache") } /* end if */ else { @@ -767,7 +767,7 @@ H5FS_alloc_hdr(H5F_t *f, H5FS_t *fspace, haddr_t *fs_addr, hid_t dxpl_id) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for free space header") /* Cache the new free space header (pinned) */ - if(H5AC_set(f, dxpl_id, H5AC_FSPACE_HDR, fspace->addr, fspace, H5AC__PIN_ENTRY_FLAG) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_FSPACE_HDR, fspace->addr, fspace, H5AC__PIN_ENTRY_FLAG) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTINIT, FAIL, "can't add free space header to cache") } /* end if */ @@ -814,7 +814,7 @@ H5FS_alloc_sect(H5F_t *f, H5FS_t *fspace, hid_t dxpl_id) HGOTO_ERROR(H5E_FSPACE, H5E_CANTMARKDIRTY, FAIL, "unable to mark free space header as dirty") /* Cache the free-space section info */ - if(H5AC_set(f, dxpl_id, H5AC_FSPACE_SINFO, fspace->sect_addr, fspace->sinfo, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_FSPACE_SINFO, fspace->sect_addr, fspace->sinfo, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTINIT, FAIL, "can't add free space sections to cache") fspace->sinfo = NULL; diff --git a/src/H5Faccum.c b/src/H5Faccum.c index 426a639..2fc53ea 100644 --- a/src/H5Faccum.c +++ b/src/H5Faccum.c @@ -143,13 +143,18 @@ H5F_accum_read(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, - new_addr); /* Check if we need more buffer space */ - if(new_size > f->shared->accum.size) { - /* Adjust the buffer size, by doubling it */ - f->shared->accum.alloc_size = MAX(f->shared->accum.alloc_size * 2, new_size); + if(new_size > f->shared->accum.alloc_size) { + size_t new_alloc_size; /* New size of accumulator */ + + /* Adjust the buffer size to be a power of 2 that is large enough to hold data */ + new_alloc_size = (size_t)1 << (1 + H5V_log2_gen((uint64_t)(new_size - 1))); /* Reallocate the metadata accumulator buffer */ - if(NULL == (f->shared->accum.buf = H5FL_BLK_REALLOC(meta_accum, f->shared->accum.buf, f->shared->accum.alloc_size))) - HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate metadata accumulator buffer") + if(NULL == (f->shared->accum.buf = H5FL_BLK_REALLOC(meta_accum, f->shared->accum.buf, new_alloc_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") + + /* Note the new buffer size */ + f->shared->accum.alloc_size = new_alloc_size; #ifdef H5_CLEAR_MEMORY HDmemset(f->shared->accum.buf + f->shared->accum.size, 0, (f->shared->accum.alloc_size - f->shared->accum.size)); #endif /* H5_CLEAR_MEMORY */ @@ -163,6 +168,10 @@ HDmemset(f->shared->accum.buf + f->shared->accum.size, 0, (f->shared->accum.allo /* Make room for the metadata to read in */ HDmemmove(f->shared->accum.buf + amount_before, f->shared->accum.buf, f->shared->accum.size); + /* Adjust dirty region tracking info, if present */ + if(f->shared->accum.dirty) + f->shared->accum.dirty_off += amount_before; + /* Dispatch to driver */ if(H5FD_read(f->shared->lf, dxpl_id, type, addr, amount_before, f->shared->accum.buf) < 0) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "driver read request failed") @@ -228,6 +237,7 @@ H5F_accum_adjust(H5F_meta_accum_t *accum, H5FD_t *lf, hid_t dxpl_id, HDassert(accum); HDassert(lf); + HDassert(H5F_ACCUM_APPEND == adjust || H5F_ACCUM_PREPEND == adjust); HDassert(size > 0); HDassert(size <= H5F_ACCUM_MAX_SIZE); @@ -252,36 +262,65 @@ H5F_accum_adjust(H5F_meta_accum_t *accum, H5FD_t *lf, hid_t dxpl_id, remnant_size = 0; } /* end if */ else { - new_size = (H5F_ACCUM_MAX_SIZE / 2); - shrink_size = (H5F_ACCUM_MAX_SIZE / 2); - remnant_size = accum->size - shrink_size; + if(H5F_ACCUM_PREPEND == adjust) { + new_size = (H5F_ACCUM_MAX_SIZE / 2); + shrink_size = (H5F_ACCUM_MAX_SIZE / 2); + remnant_size = accum->size - shrink_size; + } /* end if */ + else { + size_t adjust_size = size + accum->dirty_len; + + /* Check if we can slide the dirty region down, to accommodate the request */ + if(accum->dirty && (adjust_size <= H5F_ACCUM_MAX_SIZE)) { + if((ssize_t)(H5F_ACCUM_MAX_SIZE - (accum->dirty_off + adjust_size)) >= (ssize_t)(2 * size)) + shrink_size = accum->dirty_off / 2; + else + shrink_size = accum->dirty_off; + remnant_size = accum->size - shrink_size; + new_size = remnant_size + size; + } /* end if */ + else { + new_size = (H5F_ACCUM_MAX_SIZE / 2); + shrink_size = (H5F_ACCUM_MAX_SIZE / 2); + remnant_size = accum->size - shrink_size; + } /* end else */ + } /* end else */ } /* end else */ /* Check if we need to flush accumulator data to file */ if(accum->dirty) { /* Check whether to accumulator will be prepended or appended */ if(H5F_ACCUM_PREPEND == adjust) { - /* Write out upper part of the existing metadata accumulator, with dispatch to driver */ - if(H5FD_write(lf, dxpl_id, H5FD_MEM_DEFAULT, (accum->loc + remnant_size), shrink_size, (accum->buf + remnant_size)) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") + /* Check if the dirty region overlaps the region to eliminate from the accumulator */ + if((accum->size - shrink_size) < (accum->dirty_off + accum->dirty_len)) { + /* Write out the dirty region from the metadata accumulator, with dispatch to driver */ + if(H5FD_write(lf, dxpl_id, H5FD_MEM_DEFAULT, (accum->loc + accum->dirty_off), accum->dirty_len, (accum->buf + accum->dirty_off)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, FAIL, "file write failed") + + /* Reset accumulator dirty flag */ + accum->dirty = FALSE; + } /* end if */ } /* end if */ else { - /* Sanity check */ - HDassert(H5F_ACCUM_APPEND == adjust); - - /* Write out lower part of the existing metadata accumulator, with dispatch to driver */ - if(H5FD_write(lf, dxpl_id, H5FD_MEM_DEFAULT, accum->loc, shrink_size, accum->buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") + /* Check if the dirty region overlaps the region to eliminate from the accumulator */ + if(shrink_size > accum->dirty_off) { + /* Write out the dirty region from the metadata accumulator, with dispatch to driver */ + if(H5FD_write(lf, dxpl_id, H5FD_MEM_DEFAULT, (accum->loc + accum->dirty_off), accum->dirty_len, (accum->buf + accum->dirty_off)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, FAIL, "file write failed") + + /* Reset accumulator dirty flag */ + accum->dirty = FALSE; + } /* end if */ /* Move remnant of accumulator down */ HDmemmove(accum->buf, (accum->buf + shrink_size), remnant_size); /* Adjust accumulator's location */ accum->loc += shrink_size; - } /* end else */ - /* Reset accumulator dirty flag (in case of error) */ - accum->dirty = FALSE; + /* Adjust dirty region tracking info */ + accum->dirty_off -= shrink_size; + } /* end else */ } /* end if */ /* Trim the accumulator's use of its buffer */ @@ -294,7 +333,7 @@ H5F_accum_adjust(H5F_meta_accum_t *accum, H5FD_t *lf, hid_t dxpl_id, /* Reallocate the metadata accumulator buffer */ if(NULL == (new_buf = H5FL_BLK_REALLOC(meta_accum, accum->buf, new_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") + HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "unable to allocate metadata accumulator buffer") /* Update accumulator info */ accum->buf = new_buf; @@ -361,8 +400,15 @@ H5F_accum_write(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, f->shared->accum.loc = addr; f->shared->accum.size += size; - /* Mark it as written to */ - f->shared->accum.dirty = TRUE; + /* Adjust the dirty region and mark accumulator dirty */ + if(f->shared->accum.dirty) + f->shared->accum.dirty_len = size + f->shared->accum.dirty_off + + f->shared->accum.dirty_len; + else { + f->shared->accum.dirty_len = size; + f->shared->accum.dirty = TRUE; + } /* end else */ + f->shared->accum.dirty_off = 0; } /* end if */ /* Check if the new metadata adjoins the end of the current accumulator */ else if(addr == (f->shared->accum.loc + f->shared->accum.size)) { @@ -373,11 +419,18 @@ H5F_accum_write(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, /* Copy the new metadata to the end */ HDmemcpy(f->shared->accum.buf + f->shared->accum.size, buf, size); + /* Adjust the dirty region and mark accumulator dirty */ + if(f->shared->accum.dirty) + f->shared->accum.dirty_len = size + (f->shared->accum.size - + f->shared->accum.dirty_off); + else { + f->shared->accum.dirty_off = f->shared->accum.size; + f->shared->accum.dirty_len = size; + f->shared->accum.dirty = TRUE; + } /* end else */ + /* Set the new size of the metadata accumulator */ f->shared->accum.size += size; - - /* Mark it as written to */ - f->shared->accum.dirty = TRUE; } /* end if */ /* Check if the piece of metadata being written overlaps the metadata accumulator */ else if(H5F_addr_overlap(addr, size, f->shared->accum.loc, f->shared->accum.size)) { @@ -385,11 +438,33 @@ H5F_accum_write(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, /* Check if the new metadata is entirely within the current accumulator */ if(addr >= f->shared->accum.loc && (addr + size) <= (f->shared->accum.loc + f->shared->accum.size)) { - /* Copy the new metadata to the proper location within the accumulator */ - HDmemcpy(f->shared->accum.buf + (addr - f->shared->accum.loc), buf, size); + size_t dirty_off = (size_t)(addr - f->shared->accum.loc); - /* Mark it as written to */ - f->shared->accum.dirty = TRUE; + /* Copy the new metadata to the proper location within the accumulator */ + HDmemcpy(f->shared->accum.buf + dirty_off, buf, size); + + /* Adjust the dirty region and mark accumulator dirty */ + if(f->shared->accum.dirty) { + /* Check for new metadata starting before current dirty region */ + if(dirty_off <= f->shared->accum.dirty_off) { + if((dirty_off + size) <= (f->shared->accum.dirty_off + f->shared->accum.dirty_len)) + f->shared->accum.dirty_len = (f->shared->accum.dirty_off + f->shared->accum.dirty_len) - dirty_off; + else + f->shared->accum.dirty_len = size; + f->shared->accum.dirty_off = dirty_off; + } /* end if */ + else { + if((dirty_off + size) <= (f->shared->accum.dirty_off + f->shared->accum.dirty_len)) + ; /* f->shared->accum.dirty_len doesn't change */ + else + f->shared->accum.dirty_len = (dirty_off + size) - f->shared->accum.dirty_off; + } /* end else */ + } /* end if */ + else { + f->shared->accum.dirty_off = dirty_off; + f->shared->accum.dirty_len = size; + f->shared->accum.dirty = TRUE; + } /* end else */ } /* end if */ /* Check if the new metadata overlaps the beginning of the current accumulator */ else if(addr < f->shared->accum.loc && (addr + size) <= (f->shared->accum.loc + f->shared->accum.size)) { @@ -415,11 +490,26 @@ H5F_accum_write(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, f->shared->accum.loc = addr; f->shared->accum.size += add_size; - /* Mark it as written to */ - f->shared->accum.dirty = TRUE; + /* Adjust the dirty region and mark accumulator dirty */ + if(f->shared->accum.dirty) { + size_t curr_dirty_end = add_size + f->shared->accum.dirty_off + f->shared->accum.dirty_len; + + f->shared->accum.dirty_off = 0; + if(size <= curr_dirty_end) + f->shared->accum.dirty_len = curr_dirty_end; + else + f->shared->accum.dirty_len = size; + } /* end if */ + else { + f->shared->accum.dirty_off = 0; + f->shared->accum.dirty_len = size; + f->shared->accum.dirty = TRUE; + } /* end else */ } /* end if */ /* Check if the new metadata overlaps the end of the current accumulator */ else if(addr >= f->shared->accum.loc && (addr + size) > (f->shared->accum.loc + f->shared->accum.size)) { + size_t dirty_off = (size_t)(addr - f->shared->accum.loc); + /* Calculate the amount we will need to add to the accumulator size, based on the amount of overlap */ H5_ASSIGN_OVERFLOW(add_size, (addr + size) - (f->shared->accum.loc + f->shared->accum.size), hsize_t, size_t); @@ -428,24 +518,43 @@ H5F_accum_write(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, HGOTO_ERROR(H5E_IO, H5E_CANTRESIZE, FAIL, "can't adjust metadata accumulator") /* Copy the new metadata to the end */ - HDmemcpy(f->shared->accum.buf + (addr - f->shared->accum.loc), buf, size); + HDmemcpy(f->shared->accum.buf + dirty_off, buf, size); /* Set the new size of the metadata accumulator */ f->shared->accum.size += add_size; - /* Mark it as written to */ - f->shared->accum.dirty = TRUE; + /* Adjust the dirty region and mark accumulator dirty */ + if(f->shared->accum.dirty) { + /* Check for new metadata starting before current dirty region */ + if(dirty_off <= f->shared->accum.dirty_off) { + f->shared->accum.dirty_off = dirty_off; + f->shared->accum.dirty_len = size; + } /* end if */ + else { + f->shared->accum.dirty_len = (dirty_off + size) - f->shared->accum.dirty_off; + } /* end else */ + } /* end if */ + else { + f->shared->accum.dirty_off = dirty_off; + f->shared->accum.dirty_len = size; + f->shared->accum.dirty = TRUE; + } /* end else */ } /* end if */ /* New metadata overlaps both ends of the current accumulator */ else { /* Check if we need more buffer space */ - if(size > f->shared->accum.size) { - /* Adjust the buffer size, by doubling it */ - f->shared->accum.alloc_size = MAX(f->shared->accum.alloc_size * 2, size); + if(size > f->shared->accum.alloc_size) { + size_t new_alloc_size; /* New size of accumulator */ + + /* Adjust the buffer size to be a power of 2 that is large enough to hold data */ + new_alloc_size = (size_t)1 << (1 + H5V_log2_gen((uint64_t)(size - 1))); /* Reallocate the metadata accumulator buffer */ - if(NULL == (f->shared->accum.buf = H5FL_BLK_REALLOC(meta_accum, f->shared->accum.buf, f->shared->accum.alloc_size))) + if(NULL == (f->shared->accum.buf = H5FL_BLK_REALLOC(meta_accum, f->shared->accum.buf, new_alloc_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") + + /* Note the new buffer size */ + f->shared->accum.alloc_size = new_alloc_size; #ifdef H5_CLEAR_MEMORY HDmemset(f->shared->accum.buf + size, 0, (f->shared->accum.alloc_size - size)); #endif /* H5_CLEAR_MEMORY */ @@ -458,7 +567,9 @@ HDmemset(f->shared->accum.buf + size, 0, (f->shared->accum.alloc_size - size)); f->shared->accum.loc = addr; f->shared->accum.size = size; - /* Mark it as written to */ + /* Adjust the dirty region and mark accumulator dirty */ + f->shared->accum.dirty_off = 0; + f->shared->accum.dirty_len = size; f->shared->accum.dirty = TRUE; } /* end else */ } /* end if */ @@ -466,7 +577,7 @@ HDmemset(f->shared->accum.buf + size, 0, (f->shared->accum.alloc_size - size)); else { /* Write out the existing metadata accumulator, with dispatch to driver */ if(f->shared->accum.dirty) { - if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, f->shared->accum.loc, f->shared->accum.size, f->shared->accum.buf) < 0) + if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, f->shared->accum.loc + f->shared->accum.dirty_off, f->shared->accum.dirty_len, f->shared->accum.buf + f->shared->accum.dirty_off) < 0) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") /* Reset accumulator dirty flag */ @@ -512,10 +623,14 @@ HDmemset(f->shared->accum.buf + clear_size, 0, (f->shared->accum.alloc_size - cl /* Update the metadata accumulator information */ f->shared->accum.loc = addr; f->shared->accum.size = size; - f->shared->accum.dirty = TRUE; /* Store the piece of metadata in the accumulator */ HDmemcpy(f->shared->accum.buf, buf, size); + + /* Adjust the dirty region and mark accumulator dirty */ + f->shared->accum.dirty_off = 0; + f->shared->accum.dirty_len = size; + f->shared->accum.dirty = TRUE; } /* end else */ } /* end if */ /* No metadata in the accumulator, grab this piece and keep it */ @@ -533,15 +648,22 @@ HDmemset(f->shared->accum.buf + clear_size, 0, (f->shared->accum.alloc_size - cl /* Note the new buffer size */ f->shared->accum.alloc_size = new_size; +#ifdef H5_CLEAR_MEMORY +HDmemset(f->shared->accum.buf + size, 0, (f->shared->accum.alloc_size - size)); +#endif /* H5_CLEAR_MEMORY */ } /* end if */ /* Update the metadata accumulator information */ f->shared->accum.loc = addr; f->shared->accum.size = size; - f->shared->accum.dirty = TRUE; /* Store the piece of metadata in the accumulator */ HDmemcpy(f->shared->accum.buf, buf, size); + + /* Adjust the dirty region and mark accumulator dirty */ + f->shared->accum.dirty_off = 0; + f->shared->accum.dirty_len = size; + f->shared->accum.dirty = TRUE; } /* end else */ /* Indicate success */ @@ -610,25 +732,100 @@ H5F_accum_free(H5F_t *f, hid_t dxpl_id, H5FD_mem_t UNUSED type, haddr_t addr, /* Adjust the accumulator information */ f->shared->accum.loc += overlap_size; f->shared->accum.size = new_accum_size; + + /* Adjust the dirty region and possibly mark accumulator clean */ + if(f->shared->accum.dirty) { + /* Check if block freed is entirely before dirty region */ + if(overlap_size < f->shared->accum.dirty_off) + f->shared->accum.dirty_off -= overlap_size; + else { + /* Check if block freed ends within dirty region */ + if(overlap_size < (f->shared->accum.dirty_off + f->shared->accum.dirty_len)) { + f->shared->accum.dirty_len = (f->shared->accum.dirty_off + f->shared->accum.dirty_len) - overlap_size; + f->shared->accum.dirty_off = 0; + } /* end if */ + /* Block freed encompasses dirty region */ + else + f->shared->accum.dirty = FALSE; + } /* end else */ + } /* end if */ } /* end else */ } /* end if */ /* Block to free must start within the accumulator */ else { + haddr_t dirty_end = f->shared->accum.loc + f->shared->accum.dirty_off + f->shared->accum.dirty_len; + haddr_t dirty_start = f->shared->accum.loc + f->shared->accum.dirty_off; + /* Calculate the size of the overlap with the accumulator */ H5_ASSIGN_OVERFLOW(overlap_size, (f->shared->accum.loc + f->shared->accum.size) - addr, haddr_t, size_t); - /* Block to free is in the middle of the accumulator */ - if(H5F_addr_lt((addr + size), f->shared->accum.loc + f->shared->accum.size)) { + /* Check if block to free begins before end of dirty region */ + if(f->shared->accum.dirty && H5F_addr_lt(addr, dirty_end)) { haddr_t tail_addr; - size_t tail_size; - /* Calculate the address & size of the tail to write */ + /* Calculate the address of the tail to write */ tail_addr = addr + size; - H5_ASSIGN_OVERFLOW(tail_size, (f->shared->accum.loc + f->shared->accum.size) - tail_addr, haddr_t, size_t); - /* Write out the part of the accumulator after the block to free */ - if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, tail_addr, tail_size, f->shared->accum.buf + (tail_addr - f->shared->accum.loc)) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") + /* Check if the block to free begins before dirty region */ + if(H5F_addr_lt(addr, dirty_start)) { + /* Check if block to free is entirely before dirty region */ + if(H5F_addr_le(tail_addr, dirty_start)) { + /* Write out the entire dirty region of the accumulator */ + if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, dirty_start, f->shared->accum.dirty_len, f->shared->accum.buf + f->shared->accum.dirty_off) < 0) + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") + } /* end if */ + /* Block to free overlaps with some/all of dirty region */ + else { + size_t write_size; + + write_size = (size_t)(dirty_end - tail_addr); + + /* Check for unfreed dirty region to write */ + if(write_size > 0) { + size_t dirty_delta; + + dirty_delta = f->shared->accum.dirty_len - write_size; + + /* Write out the unfreed dirty region of the accumulator */ + if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, dirty_start + dirty_delta, write_size, f->shared->accum.buf + f->shared->accum.dirty_off + dirty_delta) < 0) + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") + } /* end if */ + } /* end else */ + + /* Reset dirty flag */ + f->shared->accum.dirty = FALSE; + } /* end if */ + /* Block to free begins at beginning of or in middle of dirty region */ + else { + /* Check if block to free ends before end of dirty region */ + if(H5F_addr_lt(tail_addr, dirty_end)) { + size_t write_size; + + write_size = (size_t)(dirty_end - tail_addr); + + /* Check for unfreed dirty region to write */ + if(write_size > 0) { + size_t dirty_delta; + + dirty_delta = f->shared->accum.dirty_len - write_size; + + /* Write out the unfreed end of the dirty region of the accumulator */ + if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, dirty_start + dirty_delta, write_size, f->shared->accum.buf + f->shared->accum.dirty_off + dirty_delta) < 0) + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") + } /* end if */ + } /* end if */ + + /* Check for block to free beginning at same location as dirty region */ + if(H5F_addr_eq(addr, dirty_start)) { + /* Reset dirty flag */ + f->shared->accum.dirty = FALSE; + } /* end if */ + /* Block to free eliminates end of dirty region */ + else { + f->shared->accum.dirty_len = (addr - dirty_start); + } /* end else */ + } /* end else */ + } /* end if */ /* Adjust the accumulator information */ @@ -665,9 +862,9 @@ H5F_accum_flush(H5F_t *f, hid_t dxpl_id) HDassert(f->shared); /* Check if we need to flush out the metadata accumulator */ - if((f->shared->feature_flags & H5FD_FEAT_ACCUMULATE_METADATA) && f->shared->accum.dirty && f->shared->accum.size > 0) { + if((f->shared->feature_flags & H5FD_FEAT_ACCUMULATE_METADATA) && f->shared->accum.dirty) { /* Flush the metadata contents */ - if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, f->shared->accum.loc, f->shared->accum.size, f->shared->accum.buf) < 0) + if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_DEFAULT, f->shared->accum.loc + f->shared->accum.dirty_off, f->shared->accum.dirty_len, f->shared->accum.buf + f->shared->accum.dirty_off) < 0) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") /* Reset the dirty flag */ @@ -719,6 +916,7 @@ H5F_accum_reset(H5F_t *f, hid_t dxpl_id) f->shared->accum.alloc_size = f->shared->accum.size = 0; f->shared->accum.loc = HADDR_UNDEF; f->shared->accum.dirty = FALSE; + f->shared->accum.dirty_len = 0; } /* end if */ done: diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h index 3fff3de..0d30e53 100644 --- a/src/H5Fpkg.h +++ b/src/H5Fpkg.h @@ -142,6 +142,8 @@ typedef struct H5F_meta_accum_t { haddr_t loc; /* File location (offset) of the accumulated metadata */ size_t size; /* Size of the accumulated metadata buffer used (in bytes) */ size_t alloc_size; /* Size of the accumulated metadata buffer allocated (in bytes) */ + size_t dirty_off; /* Offset of the dirty region in the accumulator buffer */ + size_t dirty_len; /* Length of the dirty region in the accumulator buffer */ hbool_t dirty; /* Flag to indicate that the accumulated metadata is dirty */ } H5F_meta_accum_t; diff --git a/src/H5Fsuper.c b/src/H5Fsuper.c index fd8c692..a259dde 100644 --- a/src/H5Fsuper.c +++ b/src/H5Fsuper.c @@ -189,12 +189,27 @@ H5F_super_ext_create(H5F_t *f, hid_t dxpl_id, H5O_loc_t *ext_ptr) HDassert(!H5F_addr_defined(f->shared->sblock->ext_addr)); HDassert(ext_ptr); - H5O_loc_reset(ext_ptr); - if(H5O_create(f, dxpl_id, 0, H5P_GROUP_CREATE_DEFAULT, ext_ptr) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, FAIL, "unable to create superblock extension") + /* Check for older version of superblock format that can't support superblock extensions */ + if(f->shared->sblock->super_vers < HDF5_SUPERBLOCK_VERSION_2) + HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, FAIL, "superblock extension not permitted with version %u of superblock", f->shared->sblock->super_vers) + else if(H5F_addr_defined(f->shared->sblock->ext_addr)) + HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, FAIL, "superblock extension already exists?!?!") + else { + /* The superblock extension isn't actually a group, but the + * default group creation list should work fine. + * If we don't supply a size for the object header, HDF5 will + * allocate H5O_MIN_SIZE by default. This is currently + * big enough to hold the biggest possible extension, but should + * be tuned if more information is added to the superblock + * extension. + */ + H5O_loc_reset(ext_ptr); + if(H5O_create(f, dxpl_id, 0, H5P_GROUP_CREATE_DEFAULT, ext_ptr) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, FAIL, "unable to create superblock extension") - /* Record the address of the superblock extension */ - f->shared->sblock->ext_addr = ext_ptr->addr; + /* Record the address of the superblock extension */ + f->shared->sblock->ext_addr = ext_ptr->addr; + } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -487,7 +502,7 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to set EOA value for superblock") /* Insert superblock into cache, pinned */ - if(H5AC_set(f, dxpl_id, H5AC_SUPERBLOCK, (haddr_t)0, sblock, H5AC__PIN_ENTRY_FLAG) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_SUPERBLOCK, (haddr_t)0, sblock, H5AC__PIN_ENTRY_FLAG) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, FAIL, "can't add superblock to cache") sblock_in_cache = TRUE; diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c index e9e124f..6629934 100644 --- a/src/H5Gdeprec.c +++ b/src/H5Gdeprec.c @@ -1142,7 +1142,7 @@ H5G_obj_get_type_by_idx(H5O_loc_t *oloc, hsize_t idx, hid_t dxpl_id) htri_t linfo_exists; /* Whether the link info message exists */ H5G_obj_t ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5G_obj_get_type_by_idx, H5G_UNKNOWN) + FUNC_ENTER_NOAPI_TAG(H5G_obj_get_type_by_idx, dxpl_id, oloc->addr, H5G_UNKNOWN) /* Sanity check */ HDassert(oloc); @@ -1169,7 +1169,7 @@ H5G_obj_get_type_by_idx(H5O_loc_t *oloc, hsize_t idx, hid_t dxpl_id) } /* end else */ done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI_TAG(ret_value, H5G_UNKNOWN) } /* end H5G_obj_get_type_by_idx() */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ diff --git a/src/H5Gent.c b/src/H5Gent.c index 69037d4..a2e6159 100644 --- a/src/H5Gent.c +++ b/src/H5Gent.c @@ -248,8 +248,8 @@ H5G_ent_encode(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent) } /* end else */ /* fill with zero */ - while(*pp < p_ret) - *(*pp)++ = 0; + if(*pp < p_ret) + HDmemset(*pp, 0, (p_ret - *pp)); *pp = p_ret; done: diff --git a/src/H5Gname.c b/src/H5Gname.c index b298ccf..96b2e3a 100644 --- a/src/H5Gname.c +++ b/src/H5Gname.c @@ -426,49 +426,57 @@ H5G_name_copy(H5G_name_t *dst, const H5G_name_t *src, H5_copy_depth_t depth) *------------------------------------------------------------------------- */ ssize_t -H5G_get_name(hid_t id, char *name/*out*/, size_t size, hid_t lapl_id, - hid_t dxpl_id) +H5G_get_name(const H5G_loc_t *loc, char *name/*out*/, size_t size, + hbool_t *cached, hid_t lapl_id, hid_t dxpl_id) { - H5G_loc_t loc; /* Object location */ - ssize_t ret_value = FAIL; + ssize_t len = 0; /* Length of object's name */ + ssize_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5G_get_name, FAIL) - /* get object location */ - if(H5G_loc(id, &loc) >= 0) { - ssize_t len = 0; + /* Sanity check */ + HDassert(loc); - /* If the user path is available and it's not "hidden", use it */ - if(loc.path->user_path_r != NULL && loc.path->obj_hidden == 0) { - len = H5RS_len(loc.path->user_path_r); + /* If the user path is available and it's not "hidden", use it */ + if(loc->path->user_path_r != NULL && loc->path->obj_hidden == 0) { + len = H5RS_len(loc->path->user_path_r); - if(name) { - HDstrncpy(name, H5RS_get_str(loc.path->user_path_r), MIN((size_t)(len + 1), size)); - if((size_t)len >= size) - name[size - 1] = '\0'; - } /* end if */ + if(name) { + HDstrncpy(name, H5RS_get_str(loc->path->user_path_r), MIN((size_t)(len + 1), size)); + if((size_t)len >= size) + name[size - 1] = '\0'; } /* end if */ - else if(!loc.path->obj_hidden) { - hid_t file; - /* Retrieve file ID for name search */ - if((file = H5I_get_file_id(id, FALSE)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve file ID") + /* Indicate that the name is cached, if requested */ + /* (Currently only used for testing - QAK, 2010/07/26) */ + if(cached) + *cached = TRUE; + } /* end if */ + else if(!loc->path->obj_hidden) { + hid_t file; - /* Search for name of object */ - if((len = H5G_get_name_by_addr(file, lapl_id, dxpl_id, loc.oloc, name, size)) < 0) { - H5I_dec_ref(file, FALSE); - HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't determine name") - } /* end if */ + /* Retrieve file ID for name search */ + if((file = H5F_get_id(loc->oloc->file, FALSE)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't get file ID") - /* Close file ID used for search */ - if(H5I_dec_ref(file, FALSE) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTCLOSEFILE, FAIL, "can't determine name") - } /* end else */ + /* Search for name of object */ + if((len = H5G_get_name_by_addr(file, lapl_id, dxpl_id, loc->oloc, name, size)) < 0) { + H5I_dec_ref(file, FALSE); + HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't determine name") + } /* end if */ - /* Set return value */ - ret_value = len; - } /* end if */ + /* Close file ID used for search */ + if(H5I_dec_ref(file, FALSE) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTCLOSEFILE, FAIL, "can't determine name") + + /* Indicate that the name is _not_ cached, if requested */ + /* (Currently only used for testing - QAK, 2010/07/26) */ + if(cached) + *cached = FALSE; + } /* end else */ + + /* Set return value */ + ret_value = len; done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Gnode.c b/src/H5Gnode.c index ef38380..2b793a9 100644 --- a/src/H5Gnode.c +++ b/src/H5Gnode.c @@ -313,7 +313,7 @@ H5G_node_create(H5F_t *f, hid_t dxpl_id, H5B_ins_t UNUSED op, void *_lt_key, if(NULL == (sym->entry = H5FL_SEQ_CALLOC(H5G_entry_t, (size_t)(2 * H5F_SYM_LEAF_K(f))))) HGOTO_ERROR(H5E_SYM, H5E_CANTALLOC, FAIL, "memory allocation failed") - if(H5AC_set(f, dxpl_id, H5AC_SNODE, *addr_p, sym, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_SNODE, *addr_p, sym, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to cache symbol table leaf node") /* * The left and right symbols in an empty tree are both the @@ -778,7 +778,7 @@ H5G_node_remove(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_lt_key/*in,out*/, /* "Normal" removal of a single entry from the symbol table node */ if(udata->common.name != NULL) { H5O_link_t lnk; /* Constructed link for replacement */ - size_t len; /* Length of string in local heap */ + size_t link_name_len; /* Length of string in local heap */ const char *base; /* Base of heap */ /* Get base address of heap */ @@ -804,6 +804,7 @@ H5G_node_remove(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_lt_key/*in,out*/, /* Get a pointer to the name of the link */ if(NULL == (lnk.name = (char *)H5HL_offset_into(udata->common.heap, sn->entry[idx].name_off))) HGOTO_ERROR(H5E_SYM, H5E_CANTGET, H5B_INS_ERROR, "unable to get link name") + link_name_len = HDstrlen(lnk.name) + 1; /* Set up rest of link structure */ lnk.corder_valid = FALSE; @@ -837,15 +838,16 @@ H5G_node_remove(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_lt_key/*in,out*/, else { /* Remove the soft link's value from the local heap */ if(lnk.u.soft.name) { - len = HDstrlen(lnk.u.soft.name) + 1; - if(H5HL_remove(f, dxpl_id, udata->common.heap, sn->entry[idx].cache.slink.lval_offset, len) < 0) + size_t soft_link_len; /* Length of string in local heap */ + + soft_link_len = HDstrlen(lnk.u.soft.name) + 1; + if(H5HL_remove(f, dxpl_id, udata->common.heap, sn->entry[idx].cache.slink.lval_offset, soft_link_len) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, H5B_INS_ERROR, "unable to remove soft link from local heap") } /* end if */ } /* end else */ /* Remove the link's name from the local heap */ - len = HDstrlen(lnk.name) + 1; - if(H5HL_remove(f, dxpl_id, udata->common.heap, sn->entry[idx].name_off, len) < 0) + if(H5HL_remove(f, dxpl_id, udata->common.heap, sn->entry[idx].name_off, link_name_len) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, H5B_INS_ERROR, "unable to remove link name from local heap") /* Remove the entry from the symbol table node */ diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h index 3e66777..7b09423 100644 --- a/src/H5Gprivate.h +++ b/src/H5Gprivate.h @@ -196,8 +196,8 @@ H5_DLL herr_t H5G_name_replace(const struct H5O_link_t *lnk, H5G_names_op_t op, H5_DLL herr_t H5G_name_reset(H5G_name_t *name); H5_DLL herr_t H5G_name_copy(H5G_name_t *dst, const H5G_name_t *src, H5_copy_depth_t depth); H5_DLL herr_t H5G_name_free(H5G_name_t *name); -H5_DLL ssize_t H5G_get_name(hid_t id, char *name/*out*/, size_t size, - hid_t lapl_id, hid_t dxpl_id); +H5_DLL ssize_t H5G_get_name(const H5G_loc_t *loc, char *name/*out*/, size_t size, + hbool_t *cached, hid_t lapl_id, hid_t dxpl_id); H5_DLL ssize_t H5G_get_name_by_addr(hid_t fid, hid_t lapl_id, hid_t dxpl_id, const struct H5O_loc_t *loc, char* name, size_t size); diff --git a/src/H5Gtraverse.c b/src/H5Gtraverse.c index 5b1f71c..742e2bc 100644 --- a/src/H5Gtraverse.c +++ b/src/H5Gtraverse.c @@ -171,8 +171,7 @@ H5G_traverse_ud(const H5G_loc_t *grp_loc/*in,out*/, const H5O_link_t *lnk, H5G_loc_t grp_loc_copy; H5G_name_t grp_path_copy; H5O_loc_t grp_oloc_copy; - H5O_loc_t *new_oloc = NULL; - H5F_t *temp_file = NULL; + H5G_loc_t new_loc; /* Group location for newly opened external object */ H5G_t *grp; hid_t lapl_id = (-1); /* LAPL local to this routine */ H5P_genplist_t *lapl; /* LAPL with nlinks set */ @@ -189,13 +188,9 @@ H5G_traverse_ud(const H5G_loc_t *grp_loc/*in,out*/, const H5O_link_t *lnk, HDassert(nlinks); HDassert(_lapl_id >= 0); - /* Reset the object's path information, because we can't detect any changes - * in the "path" the user-defined callback takes */ - H5G_name_free(obj_loc->path); - /* Get the link class for this type of link. */ if(NULL == (link_class = H5L_find_class(lnk->type))) - HGOTO_ERROR(H5E_LINK, H5E_NOTREGISTERED, FAIL, "unable to get UD link class") + HGOTO_ERROR(H5E_SYM, H5E_NOTREGISTERED, FAIL, "unable to get UD link class") /* Set up location for user-defined callback. Use a copy of our current * grp_loc. */ @@ -203,37 +198,37 @@ H5G_traverse_ud(const H5G_loc_t *grp_loc/*in,out*/, const H5O_link_t *lnk, grp_loc_copy.oloc = &grp_oloc_copy; H5G_loc_reset(&grp_loc_copy); if(H5G_loc_copy(&grp_loc_copy, grp_loc, H5_COPY_DEEP) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "unable to copy object location") + HGOTO_ERROR(H5E_SYM, H5E_CANTCOPY, FAIL, "unable to copy object location") - /* Create a group to pass to the user-defined callback */ - if((grp = H5G_open(&grp_loc_copy, dxpl_id)) == NULL) + /* Create a group ID to pass to the user-defined callback */ + if(NULL == (grp = H5G_open(&grp_loc_copy, dxpl_id))) HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") if((cur_grp = H5I_register(H5I_GROUP, grp, FALSE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") + HGOTO_ERROR(H5E_SYM, H5E_CANTREGISTER, FAIL, "unable to register group") /* Check for generic default property list and use link access default if so */ if(_lapl_id == H5P_DEFAULT) { HDassert(H5P_LINK_ACCESS_DEFAULT != -1); if(NULL == (lapl = (H5P_genplist_t *)H5I_object(H5P_LINK_ACCESS_DEFAULT))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "unable to get default property list") + HGOTO_ERROR(H5E_SYM, H5E_BADATOM, FAIL, "unable to get default property list") } /* end if */ else { /* Get the underlying property list passed in */ if(NULL == (lapl = (H5P_genplist_t *)H5I_object(_lapl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "unable to get property list from ID") + HGOTO_ERROR(H5E_SYM, H5E_BADATOM, FAIL, "unable to get property list from ID") } /* end else */ /* Copy the property list passed in */ if((lapl_id = H5P_copy_plist(lapl, FALSE)) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "unable to copy property list") + HGOTO_ERROR(H5E_SYM, H5E_CANTCOPY, FAIL, "unable to copy property list") /* Get the underlying property list copy */ if(NULL == (lapl = (H5P_genplist_t *)H5I_object(lapl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "unable to get property list from ID") + HGOTO_ERROR(H5E_SYM, H5E_BADATOM, FAIL, "unable to get property list from ID") /* Record number of soft links left to traverse in the property list. */ if(H5P_set(lapl, H5L_ACS_NLINKS_NAME, nlinks) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set nlink info") + HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set nlink info") /* User-defined callback function */ cb_return = (link_class->trav_func)(lnk->name, cur_grp, lnk->u.ud.udata, lnk->u.ud.size, lapl_id); @@ -253,79 +248,45 @@ H5G_traverse_ud(const H5G_loc_t *grp_loc/*in,out*/, const H5O_link_t *lnk, } /* end if */ /* else, we really needed to open the object */ else - HGOTO_ERROR(H5E_ARGS, H5E_BADATOM, FAIL, "traversal callback returned invalid ID") + HGOTO_ERROR(H5E_SYM, H5E_BADATOM, FAIL, "traversal callback returned invalid ID") } /* end if */ - /* Get the oloc from the ID the user callback returned */ - switch(H5I_get_type(cb_return)) { - case H5I_GROUP: - if((new_oloc = H5G_oloc((H5G_t *)H5I_object(cb_return))) == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get object location from group ID") - break; - - case H5I_DATASET: - if((new_oloc = H5D_oloc((H5D_t *)H5I_object(cb_return))) ==NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get object location from dataset ID") - break; - - case H5I_DATATYPE: - if((new_oloc = H5T_oloc((H5T_t *)H5I_object(cb_return))) ==NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get object location from datatype ID") - break; - - case H5I_FILE: - if((temp_file = (H5F_t *)H5I_object(cb_return)) == NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "couldn't get file from ID") - if((new_oloc = H5G_oloc(temp_file->shared->root_grp)) ==NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get root group location from file ID") - break; - - case H5I_UNINIT: - case H5I_BADID: - case H5I_DATASPACE: - case H5I_ATTR: - case H5I_REFERENCE: - case H5I_VFL: - case H5I_GENPROP_CLS: - case H5I_GENPROP_LST: - case H5I_ERROR_CLASS: - case H5I_ERROR_MSG: - case H5I_ERROR_STACK: - case H5I_NTYPES: - default: - HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL, "not a valid location or object ID") - } /* end switch */ - - /* Copy the location the user returned to us */ - if(H5O_loc_copy(obj_loc->oloc, new_oloc, H5_COPY_DEEP) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "unable to copy object location") + /* Get the object location information from the ID the user callback returned */ + if(H5G_loc(cb_return, &new_loc) < 0) + HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unable to get object location from ID") + + /* Release any previous location information for the object */ + H5G_loc_free(obj_loc); + + /* Copy new object's location information */ + H5G_loc_copy(obj_loc, &new_loc, H5_COPY_DEEP); /* Hold the file open until we free this object header (otherwise the * object location will be invalidated when the file closes). */ if(H5O_loc_hold_file(obj_loc->oloc) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, FAIL, "unable to hold file open") + HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to hold file open") /* We have a copy of the location and we're holding the file open. * Close the open ID the user passed back. */ if(H5I_dec_ref(cb_return, FALSE) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom from UD callback") + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close atom from UD callback") cb_return = (-1); done: /* Close location given to callback. */ if(cur_grp > 0) if(H5I_dec_ref(cur_grp, FALSE) < 0) - HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom for current location") + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close atom for current location") if(ret_value < 0 && cb_return > 0) if(H5I_dec_ref(cb_return, FALSE) < 0) - HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom from UD callback") + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close atom from UD callback") /* Close the LAPL, if we copied one */ if(lapl_id > 0 && H5I_dec_ref(lapl_id, FALSE) < 0) - HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close copied link access property list") + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close copied link access property list") FUNC_LEAVE_NOAPI(ret_value) } /* end H5G_traverse_ud() */ @@ -573,7 +534,7 @@ H5G_traverse_special(const H5G_loc_t *grp_loc, const H5O_link_t *lnk, */ if(grp_loc->oloc->holding_file && grp_loc->oloc->file == obj_loc->oloc->file) if(H5O_loc_hold_file(obj_loc->oloc) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, FAIL, "unable to hold file open") + HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to hold file open") done: FUNC_LEAVE_NOAPI(ret_value) @@ -845,7 +806,18 @@ H5G_traverse_real(const H5G_loc_t *_loc, const char *name, unsigned target, */ if(grp_loc.oloc->holding_file) if(H5O_loc_hold_file(obj_loc.oloc) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, FAIL, "unable to hold file open") + HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to hold file open") + + /* Reset any non-default object header messages */ + if(ginfo != &def_ginfo) + if(H5O_msg_reset(H5O_GINFO_ID, ginfo) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to reset group info message") + if(linfo != &def_linfo) + if(H5O_msg_reset(H5O_LINFO_ID, linfo) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to reset link info message") + if(pline != &def_pline) + if(H5O_msg_reset(H5O_PLINE_ID, pline) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to reset I/O pipeline message") } /* end if */ else HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "component not found") @@ -896,7 +868,8 @@ done: /* If there's valid information in the link, reset it */ if(link_valid) - H5O_msg_reset(H5O_LINK_ID, &lnk); + if(H5O_msg_reset(H5O_LINK_ID, &lnk) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to reset link message") FUNC_LEAVE_NOAPI(ret_value) } /* end H5G_traverse_real() */ diff --git a/src/H5HFdblock.c b/src/H5HFdblock.c index b2b3077..5cd035a 100644 --- a/src/H5HFdblock.c +++ b/src/H5HFdblock.c @@ -182,7 +182,7 @@ HDmemset(dblock->blk, 0, dblock->size); } /* end else */ /* Cache the new fractal heap direct block */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add fractal heap direct block to cache") /* Increase the allocated heap size */ diff --git a/src/H5HFhdr.c b/src/H5HFhdr.c index 67bb7b0..e678d74 100644 --- a/src/H5HFhdr.c +++ b/src/H5HFhdr.c @@ -500,7 +500,7 @@ H5HF_hdr_create(H5F_t *f, hid_t dxpl_id, const H5HF_create_t *cparam) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed for fractal heap header") /* Cache the new fractal heap header */ - if(H5AC_set(f, dxpl_id, H5AC_FHEAP_HDR, hdr->heap_addr, hdr, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_FHEAP_HDR, hdr->heap_addr, hdr, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINSERT, HADDR_UNDEF, "can't add fractal heap header to cache") /* Set address of heap header to return */ diff --git a/src/H5HFiblock.c b/src/H5HFiblock.c index 7958075..6fbb0c2 100644 --- a/src/H5HFiblock.c +++ b/src/H5HFiblock.c @@ -1056,7 +1056,7 @@ H5HF_man_iblock_create(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_indirect_t *par_iblo iblock->max_child = 0; /* Cache the new indirect block */ - if(H5AC_set(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, *addr_p, iblock, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, *addr_p, iblock, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add fractal heap indirect block to cache") done: diff --git a/src/H5HFman.c b/src/H5HFman.c index 0ec6f5f..b1fb322 100644 --- a/src/H5HFman.c +++ b/src/H5HFman.c @@ -107,7 +107,7 @@ herr_t H5HF_man_insert(H5HF_hdr_t *hdr, hid_t dxpl_id, size_t obj_size, const void *obj, void *_id) { - H5HF_free_section_t *sec_node; /* Pointer to free space section */ + H5HF_free_section_t *sec_node = NULL; /* Pointer to free space section */ H5HF_direct_t *dblock = NULL; /* Pointer to direct block to modify */ haddr_t dblock_addr = HADDR_UNDEF; /* Direct block address */ size_t dblock_size; /* Direct block size */ @@ -176,6 +176,7 @@ H5HF_man_insert(H5HF_hdr_t *hdr, hid_t dxpl_id, size_t obj_size, const void *obj /* Reduce (& possibly re-add) single section */ if(H5HF_sect_single_reduce(hdr, dxpl_id, sec_node, obj_size) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't reduce single section node") + sec_node = NULL; /* Encode the object in the block */ { @@ -203,6 +204,11 @@ H5HF_man_insert(H5HF_hdr_t *hdr, hid_t dxpl_id, size_t obj_size, const void *obj HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't adjust free space for heap") done: + /* Release section node on error */ + if(ret_value < 0) + if(sec_node && H5HF_sect_single_free((H5FS_section_info_t *)sec_node) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to release section node") + /* Release the direct block (marked as dirty) */ if(dblock && H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, dblock_addr, dblock, H5AC__DIRTIED_FLAG) < 0) HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap direct block") @@ -332,7 +338,7 @@ H5HF_man_op_real(H5HF_hdr_t *hdr, hid_t dxpl_id, const uint8_t *id, blk_off = (size_t)(obj_off - dblock->block_off); /* Check for object's offset in the direct block prefix information */ - if(blk_off < H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr)) + if(blk_off < (size_t)H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr)) HGOTO_ERROR(H5E_HEAP, H5E_BADRANGE, FAIL, "object located in prefix of direct block") /* Check for object's length overrunning the end of the direct block */ @@ -553,7 +559,7 @@ H5HF_man_remove(H5HF_hdr_t *hdr, hid_t dxpl_id, const uint8_t *id) blk_off = (size_t)(obj_off - dblock_block_off); /* Check for object's offset in the direct block prefix information */ - if(blk_off < H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr)) + if(blk_off < (size_t)H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr)) HGOTO_ERROR(H5E_HEAP, H5E_BADRANGE, FAIL, "object located in prefix of direct block") /* Check for object's length overrunning the end of the direct block */ diff --git a/src/H5HFsection.c b/src/H5HFsection.c index d763897..e41f46d 100644 --- a/src/H5HFsection.c +++ b/src/H5HFsection.c @@ -2335,7 +2335,7 @@ done: /*------------------------------------------------------------------------- - * Function: H5HF_sect_indirect_row + * Function: H5HF_sect_indirect_for_row * * Purpose: Create the underlying indirect section for a new row section * @@ -2924,6 +2924,7 @@ H5HF_sect_indirect_reduce_row(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_ unsigned start_col; /* Start column in indirect block */ unsigned end_entry; /* Entry for last block covered */ unsigned end_row; /* End row in indirect block */ + H5HF_free_section_t *peer_sect = NULL; /* Peer indirect section */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5HF_sect_indirect_reduce_row) @@ -3053,7 +3054,6 @@ H5HF_sect_indirect_reduce_row(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_ } /* end if */ } /* end if */ else { - H5HF_free_section_t *peer_sect; /* Peer indirect section */ H5HF_indirect_t *iblock; /* Pointer to indirect block for this section */ hsize_t iblock_off; /* Section's indirect block's offset in "heap space" */ unsigned peer_nentries; /* Number of entries in new peer indirect section */ @@ -3090,11 +3090,11 @@ H5HF_sect_indirect_reduce_row(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_ HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't create indirect section") /* Set up direct row & indirect entry information for peer section */ - peer_sect->u.indirect.dir_nrows = peer_dir_nrows; - if(NULL == (peer_sect->u.indirect.dir_rows = (H5HF_free_section_t **)H5MM_malloc(sizeof(H5HF_free_section_t *) * peer_dir_nrows))) - HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "allocation failed for row section pointer array") peer_sect->u.indirect.indir_nents = 0; peer_sect->u.indirect.indir_ents = NULL; + peer_sect->u.indirect.dir_nrows = peer_dir_nrows; + if(NULL == (peer_sect->u.indirect.dir_rows = (H5HF_free_section_t **)H5MM_malloc(sizeof(H5HF_free_section_t *) * peer_dir_nrows))) + 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], @@ -3137,6 +3137,9 @@ H5HF_sect_indirect_reduce_row(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_ (sect->u.indirect.indir_nents + sect->u.indirect.dir_nrows)); HDassert(peer_sect->u.indirect.rc == (peer_sect->u.indirect.indir_nents + peer_sect->u.indirect.dir_nrows)); + + /* Reset the peer_sect variable, to indicate that it has been hooked into the data structures correctly and shouldn't be freed */ + peer_sect = NULL; } /* end else */ } /* end if */ else { @@ -3150,6 +3153,16 @@ H5HF_sect_indirect_reduce_row(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_ } /* end else */ done: + /* Free allocated peer_sect. Note that this is necessary for all failures until peer_sect is linked + * into the main free space structures (via the direct blocks), and the reference count is updated. */ + if(peer_sect) { + /* Sanity check - we should only be here if an error occurred */ + HDassert(ret_value < 0); + + if(H5HF_sect_indirect_free(peer_sect) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node") + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5HF_sect_indirect_reduce_row() */ @@ -3178,6 +3191,7 @@ H5HF_sect_indirect_reduce(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_t *s unsigned start_col; /* Start column in indirect block */ unsigned end_entry; /* Entry for last block covered */ unsigned end_row; /* End row in indirect block */ + H5HF_free_section_t *peer_sect = NULL; /* Peer indirect section */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5HF_sect_indirect_reduce) @@ -3264,7 +3278,6 @@ H5HF_sect_indirect_reduce(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_t *s sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.indir_ents); } /* end if */ else { - H5HF_free_section_t *peer_sect; /* Peer indirect section */ H5HF_indirect_t *iblock; /* Pointer to indirect block for this section */ hsize_t iblock_off; /* Section's indirect block's offset in "heap space" */ haddr_t peer_sect_addr; /* Address of new peer section in "heap space" */ @@ -3320,7 +3333,7 @@ H5HF_sect_indirect_reduce(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_t *s peer_sect->u.indirect.dir_rows = NULL; peer_sect->u.indirect.indir_nents = peer_nentries; if(NULL == (peer_sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_malloc(sizeof(H5HF_free_section_t *) * peer_nentries))) - HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "allocation failed for indirect section pointer array") + 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], @@ -3336,10 +3349,6 @@ H5HF_sect_indirect_reduce(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_t *s for(u = 0; u < peer_nentries; u++) peer_sect->u.indirect.indir_ents[u]->u.indirect.parent = peer_sect; - /* Make new "first row" in peer section */ - if(H5HF_sect_indirect_first(hdr, dxpl_id, peer_sect->u.indirect.indir_ents[0]) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't make new 'first row' for peer indirect section") - /* Adjust reference counts for current & peer sections */ peer_sect->u.indirect.rc = peer_nentries; sect->u.indirect.rc -= peer_nentries; @@ -3355,6 +3364,13 @@ H5HF_sect_indirect_reduce(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_t *s (sect->u.indirect.indir_nents + sect->u.indirect.dir_nrows)); HDassert(peer_sect->u.indirect.rc == (peer_sect->u.indirect.indir_nents + peer_sect->u.indirect.dir_nrows)); + + /* Make new "first row" in peer section */ + if(H5HF_sect_indirect_first(hdr, dxpl_id, peer_sect->u.indirect.indir_ents[0]) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't make new 'first row' for peer indirect section") + + /* Reset the peer_sect variable, to indicate that it has been hooked into the data structures correctly and shouldn't be freed */ + peer_sect = NULL; } /* end else */ } /* end if */ else { @@ -3373,6 +3389,16 @@ H5HF_sect_indirect_reduce(H5HF_hdr_t *hdr, hid_t dxpl_id, H5HF_free_section_t *s HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't decrement section's ref. count ") done: + /* Free allocated peer_sect. Note that this is necessary for all failures until peer_sect is linked + * into the main free space structures (via the direct blocks), and the reference count is updated. */ + if(peer_sect) { + /* Sanity check - we should only be here if an error occurred */ + HDassert(ret_value < 0); + + if(H5HF_sect_indirect_free(peer_sect) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node") + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5HF_sect_indirect_reduce() */ diff --git a/src/H5HFtiny.c b/src/H5HFtiny.c index ce91bd1..f11b6c0 100644 --- a/src/H5HFtiny.c +++ b/src/H5HFtiny.c @@ -178,6 +178,9 @@ 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); +#ifdef H5_CLEAR_MEMORY +HDmemset(id + obj_size, 0, (hdr->id_len - (1 + hdr->tiny_len_extended + obj_size))); +#endif /* H5_CLEAR_MEMORY */ /* Update statistics about heap */ hdr->tiny_size += obj_size; @@ -227,7 +227,7 @@ HDmemset(heap->chunk, 0, size); } /* end else */ /* Add the heap to the cache */ - if(H5AC_set(f, dxpl_id, H5AC_GHEAP, addr, heap, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_GHEAP, addr, heap, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, HADDR_UNDEF, "unable to cache global heap collection") ret_value = addr; @@ -163,7 +163,7 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/) HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed") /* Add to cache */ - if(H5AC_set(f, dxpl_id, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "unable to cache local heap prefix") /* Set address to return */ @@ -270,7 +270,7 @@ H5HL_dblk_realloc(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t new_heap_size) HGOTO_ERROR(H5E_HEAP, H5E_CANTRESIZE, FAIL, "unable to resize heap prefix in cache") /* Insert data block into cache (pinned) */ - if(H5AC_set(f, dxpl_id, H5AC_LHEAP_DBLK, new_addr, dblk, H5AC__PIN_ENTRY_FLAG) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_LHEAP_DBLK, new_addr, dblk, H5AC__PIN_ENTRY_FLAG) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "unable to cache local heap data block") dblk = NULL; diff --git a/src/H5HLcache.c b/src/H5HLcache.c index 51d60f9..56d9919 100644 --- a/src/H5HLcache.c +++ b/src/H5HLcache.c @@ -440,10 +440,16 @@ H5HL_prefix_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, /* Check if the local heap is a single object in cache */ if(heap->single_cache_obj) { - /* Set p to the start of the data block. This is necessary because - * there may be a gap between the used portion of the prefix and the - * data block due to alignment constraints. */ - p = buf + heap->prfx_size; + if((p - buf) < heap->prfx_size) { + size_t gap; /* Size of gap between prefix and data block */ + + /* Set p to the start of the data block. This is necessary because + * there may be a gap between the used portion of the prefix and the + * data block due to alignment constraints. */ + gap = heap->prfx_size - (p - buf); + HDmemset(p, 0, gap); + p += gap; + } /* end if */ /* Serialize the free list into the heap data's image */ H5HL_fl_serialize(heap); @@ -896,7 +896,7 @@ H5I_register(H5I_type_t type, const void *object, hbool_t app_ref) /* new ID to check for */ next_id = H5I_MAKE(type, type_ptr->nextid); - hash_loc = H5I_LOC(type_ptr->nextid, type_ptr->hash_size); + hash_loc = (unsigned)H5I_LOC(type_ptr->nextid, type_ptr->hash_size); curr_id = type_ptr->id_list[hash_loc]; if(curr_id == NULL) break; /* Ha! this is not likely... */ @@ -1421,15 +1421,16 @@ H5I_dec_ref(hid_t id, hbool_t app_ref) if(!type_ptr->free_func || (type_ptr->free_func)((void *)id_ptr->obj_ptr) >= 0) { H5I_remove(id); ret_value = 0; - } else { + } /* end if */ + else ret_value = FAIL; - } - } else { + } /* end if */ + else { --(id_ptr->count); - if (app_ref) + if(app_ref) --(id_ptr->app_count); HDassert(id_ptr->count >= id_ptr->app_count); - ret_value = app_ref ? id_ptr->app_count : id_ptr->count; + ret_value = (int)(app_ref ? id_ptr->app_count : id_ptr->count); } done: @@ -1525,7 +1526,7 @@ H5I_inc_ref(hid_t id, hbool_t app_ref) ++(id_ptr->app_count); /* Set return value */ - ret_value = app_ref ? id_ptr->app_count : id_ptr->count; + ret_value = (int)(app_ref ? id_ptr->app_count : id_ptr->count); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1615,7 +1616,7 @@ H5I_get_ref(hid_t id, hbool_t app_ref) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't locate ID") /* Set return value */ - ret_value = app_ref ? id_ptr->app_count : id_ptr->count; + ret_value = (int)(app_ref ? id_ptr->app_count : id_ptr->count); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1696,7 +1697,7 @@ H5I_inc_type_ref(H5I_type_t type) HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "invalid type") /* Set return value */ - ret_value = ++(type_ptr->count); + ret_value = (int)(++(type_ptr->count)); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1797,7 +1798,7 @@ H5I_dec_type_ref(H5I_type_t type) } /* end if */ else { --(type_ptr->count); - ret_value = type_ptr->count; + ret_value = (herr_t)type_ptr->count; } /* end else */ done: @@ -1879,7 +1880,7 @@ H5I_get_type_ref(H5I_type_t type) HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "invalid type") /* Set return value */ - ret_value = type_ptr->count; + ret_value = (int)type_ptr->count; done: FUNC_LEAVE_NOAPI(ret_value) @@ -2133,13 +2134,18 @@ done: ssize_t H5Iget_name(hid_t id, char *name/*out*/, size_t size) { + H5G_loc_t loc; /* Object location */ ssize_t ret_value; /* Return value */ FUNC_ENTER_API(H5Iget_name, FAIL) H5TRACE3("Zs", "ixz", id, name, size); + /* Get object location */ + if(H5G_loc(id, &loc) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't retrieve object location") + /* Call internal group routine to retrieve object's name */ - if((ret_value = H5G_get_name(id, name, size, H5P_DEFAULT, H5AC_ind_dxpl_id)) < 0) + if((ret_value = H5G_get_name(&loc, name, size, NULL, H5P_DEFAULT, H5AC_ind_dxpl_id)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't retrieve object name") done: @@ -2187,7 +2193,6 @@ done: * ID given an object ID. * * Return: Success: file ID - * * Failure: a negative value * * Programmer: Raymond Lu @@ -2198,7 +2203,6 @@ done: hid_t H5I_get_file_id(hid_t obj_id, hbool_t app_ref) { - H5G_loc_t loc; /* Location of object */ H5I_type_t type; /* ID type */ hid_t ret_value; /* Return value */ @@ -2207,18 +2211,24 @@ H5I_get_file_id(hid_t obj_id, hbool_t app_ref) /* Get object type */ type = H5I_TYPE(obj_id); if(type == H5I_FILE) { - ret_value = obj_id; - - /* Increment reference count on atom. */ - if(H5I_inc_ref(ret_value, app_ref) < 0) + /* Increment reference count on file ID */ + if(H5I_inc_ref(obj_id, app_ref) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed") - } + + /* Set return value */ + ret_value = obj_id; + } /* end if */ else if(type == H5I_DATATYPE || type == H5I_GROUP || type == H5I_DATASET || type == H5I_ATTR) { + H5G_loc_t loc; /* Location of object */ + + /* Get the object location information */ if(H5G_loc(obj_id, &loc) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't get object location") + + /* Get the file ID for the object */ if((ret_value = H5F_get_id(loc.oloc->file, app_ref)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't get file ID") - } + } /* end if */ else HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid object ID") diff --git a/src/H5Ipkg.h b/src/H5Ipkg.h index e86f134..f17a4b0 100644 --- a/src/H5Ipkg.h +++ b/src/H5Ipkg.h @@ -67,4 +67,10 @@ /* Package Private Prototypes */ /******************************/ +/* Testing functions */ +#ifdef H5I_TESTING +H5_DLL ssize_t H5I_get_name_test(hid_t id, char *name/*out*/, size_t size, + hbool_t *cached); +#endif /* H5I_TESTING */ + #endif /*_H5Ipkg_H*/ diff --git a/src/H5Itest.c b/src/H5Itest.c new file mode 100644 index 0000000..1c6892d --- /dev/null +++ b/src/H5Itest.c @@ -0,0 +1,98 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* Programmer: Quincey Koziol <koziol@hdfgoup.org> + * Tuesday, July 27, 2010 + * + * Purpose: ID testing functions. + */ + +/****************/ +/* Module Setup */ +/****************/ + +#define H5I_PACKAGE /*suppress error about including H5Ipkg */ +#define H5I_TESTING /*suppress warning about H5I testing funcs*/ + + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5ACprivate.h" /* Metadata cache */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Gprivate.h" /* Groups */ +#include "H5Ipkg.h" /* IDs */ + + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + + +/*------------------------------------------------------------------------- + * Function: H5I_get_name_test + * + * Purpose: Testing version of H5Iget_name() + * + * Return: Success: The length of name. + * Failure: -1 + * + * Programmer: Quincey Koziol + * Tuesday, July 27, 2010 + * + *------------------------------------------------------------------------- + */ +ssize_t +H5I_get_name_test(hid_t id, char *name/*out*/, size_t size, hbool_t *cached) +{ + H5G_loc_t loc; /* Object location */ + ssize_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5I_get_name_test, FAIL) + + /* Get object location */ + if(H5G_loc(id, &loc) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't retrieve object location") + + /* Call internal group routine to retrieve object's name */ + if((ret_value = H5G_get_name(&loc, name, size, cached, H5P_DEFAULT, H5AC_ind_dxpl_id)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't retrieve object name") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I_get_name_test() */ + diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index c5ae92f..d98a843 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -53,6 +53,9 @@ const H5L_class_t H5L_EXTERN_LINK_CLASS[1] = {{ /* Valid flags for external links */ #define H5L_EXT_FLAGS_ALL 0 +/* Size of local link name buffer for traversing external links */ +#define H5L_EXT_TRAVERSE_BUF_SIZE 256 + /*-------------------------------------------------------------------------- NAME @@ -205,7 +208,8 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, H5L_elink_cb_t cb_info; /* Callback info struct */ hid_t fapl_id = -1; /* File access property list for external link's file */ hid_t ext_obj = -1; /* ID for external link's object */ - char *temp_group_name = NULL;/* Temporary pointer to group name */ + char *parent_group_name = NULL;/* Temporary pointer to group name */ + char local_group_name[H5L_EXT_TRAVERSE_BUF_SIZE]; /* Local buffer to hold group name */ char *temp_file_name = NULL; /* Temporary pointer to file name */ char *actual_file_name = NULL; /* Parent file's actual name */ H5P_genplist_t *fa_plist; /* File access property list pointer */ @@ -264,41 +268,34 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, /* Make callback if it exists */ if(cb_info.func) { const char *parent_file_name; /* Parent file name */ - const char *parent_group_name; /* Parent group name */ + ssize_t group_name_len; /* Length of parent group name */ /* Get parent file name */ parent_file_name = H5F_OPEN_NAME(loc.oloc->file); + /* Query length of parent group name */ + if((group_name_len = H5G_get_name(&loc, NULL, (size_t) 0, NULL, lapl_id, H5AC_ind_dxpl_id)) < 0) + HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve length of group name") + + /* Account for null terminator */ + group_name_len++; + + /* Check if we need to allocate larger buffer */ + if((size_t)group_name_len > sizeof(local_group_name)) { + if(NULL == (parent_group_name = (char *)H5MM_malloc((size_t)group_name_len))) + HGOTO_ERROR(H5E_LINK, H5E_CANTALLOC, FAIL, "can't allocate buffer to hold group name, group_name_len = %Zu", group_name_len) + } /* end if */ + else + parent_group_name = local_group_name; + /* Get parent group name */ - if(loc.path->user_path_r != NULL && loc.path->obj_hidden == 0) - /* Use user_path_r if possible */ - parent_group_name = H5RS_get_str(loc.path->user_path_r); - else { - /* Otherwise use H5G_get_name */ - ssize_t group_name_len; /* Length of parent group name */ - - /* Get length of parent group name */ - if((group_name_len = H5G_get_name(cur_group, NULL, (size_t) 0, lapl_id, H5AC_ind_dxpl_id)) < 0) - HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve length of group name") - - /* account for null terminator */ - group_name_len++; - - /* Copy parent group name */ - if(NULL == (temp_group_name = (char *)H5MM_malloc((size_t)group_name_len))) - HGOTO_ERROR(H5E_LINK, H5E_NOSPACE, FAIL, "memory allocation failed") - if(H5G_get_name(cur_group, temp_group_name, (size_t) group_name_len, lapl_id, H5AC_ind_dxpl_id) < 0) - HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve group name") - parent_group_name = temp_group_name; - } /* end else */ + if(H5G_get_name(&loc, parent_group_name, (size_t) group_name_len, NULL, lapl_id, H5AC_ind_dxpl_id) < 0) + HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to retrieve group name") /* Make callback */ if((cb_info.func)(parent_file_name, parent_group_name, file_name, obj_name, &intent, fapl_id, cb_info.user_data) < 0) HGOTO_ERROR(H5E_LINK, H5E_CALLBACK, FAIL, "traversal operator failed") - /* Free temp_group_name */ - temp_group_name = (char *)H5MM_xfree(temp_group_name); - /* Check access flags */ if((intent & H5F_ACC_TRUNC) || (intent & H5F_ACC_EXCL)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file open flags") @@ -460,8 +457,9 @@ done: HDONE_ERROR(H5E_ATOM, H5E_CANTRELEASE, FAIL, "unable to close atom for file access property list") if(ext_file && H5F_try_close(ext_file) < 0) HDONE_ERROR(H5E_LINK, H5E_CANTCLOSEFILE, FAIL, "problem closing external file") + if(parent_group_name && parent_group_name != local_group_name) + parent_group_name = (char *)H5MM_xfree(parent_group_name); full_name = (char *)H5MM_xfree(full_name); - temp_group_name = (char *)H5MM_xfree(temp_group_name); temp_file_name = (char *)H5MM_xfree(temp_file_name); actual_file_name = (char *)H5MM_xfree(actual_file_name); @@ -1053,17 +1053,29 @@ H5Oclose(hid_t object_id) H5TRACE1("e", "i", object_id); /* Get the type of the object and close it in the correct way */ - switch(H5I_get_type(object_id)) - { - case(H5I_GROUP): - case(H5I_DATATYPE): - case(H5I_DATASET): + switch(H5I_get_type(object_id)) { + case H5I_GROUP: + case H5I_DATATYPE: + case H5I_DATASET: if(H5I_object(object_id) == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object") if(H5I_dec_ref(object_id, TRUE) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close object") break; + case H5I_UNINIT: + case H5I_BADID: + case H5I_FILE: + case H5I_DATASPACE: + case H5I_ATTR: + case H5I_REFERENCE: + case H5I_VFL: + case H5I_GENPROP_CLS: + case H5I_GENPROP_LST: + case H5I_ERROR_CLASS: + case H5I_ERROR_MSG: + case H5I_ERROR_STACK: + case H5I_NTYPES: default: HGOTO_ERROR(H5E_ARGS, H5E_CANTRELEASE, FAIL, "not a valid file object ID (dataset, group, or datatype)") break; @@ -1229,14 +1241,14 @@ H5O_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, hid_t ocpl_id, oh->mesg[0].dirty = TRUE; oh->mesg[0].native = NULL; oh->mesg[0].raw = oh->chunk[0].image + (H5O_SIZEOF_HDR(oh) - H5O_SIZEOF_CHKSUM_OH(oh)) + H5O_SIZEOF_MSGHDR_OH(oh); - oh->mesg[0].raw_size = size_hint - H5O_SIZEOF_MSGHDR_OH(oh); + oh->mesg[0].raw_size = size_hint - (size_t)H5O_SIZEOF_MSGHDR_OH(oh); oh->mesg[0].chunkno = 0; /* Set metadata tag in dxpl_id */ H5_BEGIN_TAG(dxpl_id, oh_addr, FAIL); /* Cache object header */ - if(H5AC_set(f, dxpl_id, H5AC_OHDR, oh_addr, oh, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_OHDR, oh_addr, oh, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTINSERT, FAIL, "unable to cache object header") oh = NULL; @@ -1486,7 +1498,7 @@ H5O_link_oh(H5F_t *f, int adjust, hid_t dxpl_id, H5O_t *oh, hbool_t *deleted) HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, FAIL, "link count would be negative") /* Adjust the link count for the object header */ - oh->nlink += adjust; + oh->nlink = (unsigned)((int)oh->nlink + adjust); /* Mark object header as dirty in cache */ if(H5AC_mark_entry_dirty(oh) < 0) @@ -1518,7 +1530,7 @@ H5O_link_oh(H5F_t *f, int adjust, hid_t dxpl_id, H5O_t *oh, hbool_t *deleted) } /* end if */ /* Adjust the link count for the object header */ - oh->nlink += adjust; + oh->nlink = (unsigned)((int)oh->nlink + adjust); /* Mark object header as dirty in cache */ if(H5AC_mark_entry_dirty(oh) < 0) @@ -1675,6 +1687,7 @@ H5O_protect(const H5O_loc_t *loc, hid_t dxpl_id, H5AC_protect_t prot) * when the object header is actually loaded from the file. */ HDassert(udata.made_attempt == TRUE); + HDassert(cont_msg_info.msgs); /* Construct the user data for protecting chunks */ chk_udata.decoding = TRUE; @@ -1716,8 +1729,7 @@ H5O_protect(const H5O_loc_t *loc, hid_t dxpl_id, H5AC_protect_t prot) } /* end while */ /* Release any continuation messages built up */ - if(cont_msg_info.msgs) - cont_msg_info.msgs = (H5O_cont_t *)H5FL_SEQ_FREE(H5O_cont_t, cont_msg_info.msgs); + cont_msg_info.msgs = (H5O_cont_t *)H5FL_SEQ_FREE(H5O_cont_t, cont_msg_info.msgs); /* Pass back out some of the chunk's user data */ udata.common.merged_null_msgs = chk_udata.common.merged_null_msgs; @@ -1991,7 +2003,7 @@ H5O_touch_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh, hbool_t force) break; /* Create a new message, if necessary */ - if(idx == oh->nmesgs) { + if(idx == (int)oh->nmesgs) { unsigned mesg_flags = 0; /* Flags for message in object header */ /* If we would have to create a new message, but we aren't 'forcing' it, get out now */ @@ -2427,23 +2439,35 @@ H5O_get_loc(hid_t object_id) FUNC_ENTER_NOAPI_NOINIT(H5O_get_loc) - switch(H5I_get_type(object_id)) - { - case(H5I_GROUP): + switch(H5I_get_type(object_id)) { + case H5I_GROUP: if(NULL == (ret_value = H5O_OBJ_GROUP->get_oloc(object_id))) HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from group ID") break; - case(H5I_DATASET): + case H5I_DATASET: if(NULL == (ret_value = H5O_OBJ_DATASET->get_oloc(object_id))) HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from dataset ID") break; - case(H5I_DATATYPE): + case H5I_DATATYPE: if(NULL == (ret_value = H5O_OBJ_DATATYPE->get_oloc(object_id))) HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from datatype ID") break; + case H5I_UNINIT: + case H5I_BADID: + case H5I_FILE: + case H5I_DATASPACE: + case H5I_ATTR: + case H5I_REFERENCE: + case H5I_VFL: + case H5I_GENPROP_CLS: + case H5I_GENPROP_LST: + case H5I_ERROR_CLASS: + case H5I_ERROR_MSG: + case H5I_ERROR_STACK: + case H5I_NTYPES: default: HGOTO_ERROR(H5E_OHDR, H5E_BADTYPE, NULL, "invalid object type") } /* end switch */ @@ -2505,7 +2529,7 @@ H5O_loc_reset(H5O_loc_t *loc) *------------------------------------------------------------------------- */ herr_t -H5O_loc_copy(H5O_loc_t *dst, const H5O_loc_t *src, H5_copy_depth_t depth) +H5O_loc_copy(H5O_loc_t *dst, H5O_loc_t *src, H5_copy_depth_t depth) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_loc_copy) @@ -2525,8 +2549,7 @@ H5O_loc_copy(H5O_loc_t *dst, const H5O_loc_t *src, H5_copy_depth_t depth) if(src->holding_file) dst->file->nopen_objs++; } else if(depth == H5_COPY_SHALLOW) { - /* Discarding 'const' qualifier OK - QAK */ - H5O_loc_reset((H5O_loc_t *)src); + H5O_loc_reset(src); } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -2687,7 +2710,7 @@ H5O_get_hdr_info_real(const H5O_t *oh, H5O_hdr_info_t *hdr) hdr->flags = oh->flags; /* Iterate over all the messages, accumulating message size & type information */ - hdr->space.meta = H5O_SIZEOF_HDR(oh) + (H5O_SIZEOF_CHKHDR_OH(oh) * (oh->nchunks - 1)); + hdr->space.meta = (hsize_t)H5O_SIZEOF_HDR(oh) + (hsize_t)(H5O_SIZEOF_CHKHDR_OH(oh) * (oh->nchunks - 1)); hdr->space.mesg = 0; hdr->space.free = 0; hdr->mesg.present = 0; @@ -2697,11 +2720,11 @@ H5O_get_hdr_info_real(const H5O_t *oh, H5O_hdr_info_t *hdr) /* Accumulate space usage information, based on the type of message */ if(H5O_NULL_ID == curr_msg->type->id) - hdr->space.free += H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; + hdr->space.free += (hsize_t)((size_t)H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size); else if(H5O_CONT_ID == curr_msg->type->id) - hdr->space.meta += H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; + hdr->space.meta += (hsize_t)((size_t)H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size); else { - hdr->space.meta += H5O_SIZEOF_MSGHDR_OH(oh); + hdr->space.meta += (hsize_t)H5O_SIZEOF_MSGHDR_OH(oh); hdr->space.mesg += curr_msg->raw_size; } /* end else */ diff --git a/src/H5Oalloc.c b/src/H5Oalloc.c index a06740c..aba88b4 100644 --- a/src/H5Oalloc.c +++ b/src/H5Oalloc.c @@ -186,7 +186,7 @@ if(chunkno > 0) { null_msg = &(oh->mesg[oh->nmesgs++]); null_msg->type = H5O_MSG_NULL; null_msg->native = NULL; - null_msg->raw_size = new_gap_size - H5O_SIZEOF_MSGHDR_OH(oh); + null_msg->raw_size = new_gap_size - (size_t)H5O_SIZEOF_MSGHDR_OH(oh); null_msg->raw = (oh->chunk[chunkno].image + oh->chunk[chunkno].size) - (H5O_SIZEOF_CHKSUM_OH(oh) + null_msg->raw_size); null_msg->chunkno = chunkno; @@ -297,7 +297,7 @@ H5O_eliminate_gap(H5O_t *oh, hbool_t *chk_dirtied, H5O_mesg_t *mesg, } else if(move_end == move_start && !null_before_gap) { /* Slide null message up */ - HDmemmove(move_start - gap_size, move_start, mesg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh)); + HDmemmove(move_start - gap_size, move_start, mesg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); /* Adjust start of null message */ mesg->raw -= gap_size; @@ -371,7 +371,7 @@ H5O_alloc_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned null_idx, HGOTO_ERROR(H5E_OHDR, H5E_CANTINSERT, FAIL, "can't insert gap in chunk") } /* end if */ else { - size_t new_mesg_size = new_size + H5O_SIZEOF_MSGHDR_OH(oh); /* Total size of newly allocated message */ + size_t new_mesg_size = new_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh); /* Total size of newly allocated message */ H5O_mesg_t *null_msg; /* Pointer to new null message */ /* Check if we need to extend message table to hold the new null message */ @@ -553,7 +553,7 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno, delta = aligned_size - oh->mesg[extend_msg].raw_size; } /* end if */ else - delta = (aligned_size + H5O_SIZEOF_MSGHDR_OH(oh)) - oh->chunk[chunkno].gap; + delta = (aligned_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)) - oh->chunk[chunkno].gap; delta = H5O_ALIGN_OH(oh, delta); /* Check for changing the chunk #0 data size enough to need adjusting the flags */ @@ -626,7 +626,7 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno, oh->mesg[extend_msg].raw = ((oh->chunk[chunkno].image + oh->chunk[chunkno].size) - (H5O_SIZEOF_CHKSUM_OH(oh) + oh->chunk[chunkno].gap)) + H5O_SIZEOF_MSGHDR_OH(oh); - oh->mesg[extend_msg].raw_size = (delta + oh->chunk[chunkno].gap) - H5O_SIZEOF_MSGHDR_OH(oh); + oh->mesg[extend_msg].raw_size = (delta + oh->chunk[chunkno].gap) - (size_t)H5O_SIZEOF_MSGHDR_OH(oh); oh->mesg[extend_msg].chunkno = chunkno; } /* end else */ @@ -817,7 +817,7 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size) for(v = 0, tmp_msg = &oh->mesg[0]; v < oh->nmesgs; v++, tmp_msg++) { if(tmp_msg->type->id == H5O_NULL_ID && (tmp_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh)) == end_msg) { null_msgno = v; - null_size = H5O_SIZEOF_MSGHDR_OH(oh) + tmp_msg->raw_size; + null_size = (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + tmp_msg->raw_size; break; } /* end if */ @@ -854,7 +854,7 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size) /* Keep track of the total size of smaller messages in the last * chunk, in case we need to move more than 1 message. */ - multi_size += curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh); + multi_size += curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh); } /* end else */ } /* end for */ if(found_null >= 0 || found_attr.msgno >= 0 || found_other.msgno >= 0) @@ -876,7 +876,7 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size) found_other = found_attr; HDassert(found_other.msgno >= 0); - size += H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other.msgno].raw_size; + size += (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other.msgno].raw_size; } /* end if */ } /* end if */ else @@ -887,7 +887,7 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size) * for the message header. This must be at least some minimum and * aligned propertly. */ - size = MAX(H5O_MIN_SIZE, size + H5O_SIZEOF_MSGHDR_OH(oh)); + size = MAX(H5O_MIN_SIZE, size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); HDassert(size == H5O_ALIGN_OH(oh, size)); /* @@ -961,16 +961,16 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size) } /* end if */ else { /* Copy the raw data */ - HDmemcpy(p, curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), - curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh)); + HDmemcpy(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 */ curr_msg->chunkno = chunkno; curr_msg->raw = p + H5O_SIZEOF_MSGHDR_OH(oh); /* Account for copied message in new chunk */ - p += H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; - size -= H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; + p += (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; + size -= (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; } /* end else */ } /* end if */ @@ -984,8 +984,8 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size) + ((chunkno == 1) ? H5O_SIZEOF_HDR(oh) : H5O_SIZEOF_CHKHDR_OH(oh)) - H5O_SIZEOF_CHKSUM_OH(oh) + H5O_SIZEOF_MSGHDR_OH(oh); null_msg->raw_size = oh->chunk[chunkno - 1].size - - ((chunkno == 1) ? (size_t)H5O_SIZEOF_HDR(oh) : H5O_SIZEOF_CHKHDR_OH(oh)) - - H5O_SIZEOF_MSGHDR_OH(oh); + - ((chunkno == 1) ? (size_t)H5O_SIZEOF_HDR(oh) : (size_t)H5O_SIZEOF_CHKHDR_OH(oh)) + - (size_t)H5O_SIZEOF_MSGHDR_OH(oh); null_msg->chunkno = chunkno - 1; HDassert(null_msg->raw_size >= cont_size); @@ -1017,15 +1017,15 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size) /* Copy the message to move (& its prefix) to its new location */ HDmemcpy(p, oh->mesg[found_other.msgno].raw - H5O_SIZEOF_MSGHDR_OH(oh), - oh->mesg[found_other.msgno].raw_size + H5O_SIZEOF_MSGHDR_OH(oh)); + oh->mesg[found_other.msgno].raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); /* Switch moved message to point to new location */ oh->mesg[found_other.msgno].raw = p + H5O_SIZEOF_MSGHDR_OH(oh); oh->mesg[found_other.msgno].chunkno = chunkno; /* Account for copied message in new chunk */ - p += H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other.msgno].raw_size; - size -= H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other.msgno].raw_size; + p += (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other.msgno].raw_size; + size -= (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other.msgno].raw_size; /* Add any available space after the message to move to the new null message */ if(found_other.gap_size > 0) { @@ -1309,7 +1309,7 @@ H5O_move_cont(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned cont_u) /* Find size of all non-null messages in the chunk pointed to by the continuation message */ if(curr_msg->type->id != H5O_NULL_ID) { HDassert(curr_msg->type->id != H5O_CONT_ID); - nonnull_size += curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh); + nonnull_size += curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh); } /* end if */ } /* end if */ } /* end for */ @@ -1321,7 +1321,7 @@ H5O_move_cont(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned cont_u) /* (Could count any null messages in the chunk w/the continuation * message also, but that is pretty complex. -QAK) */ - if(nonnull_size && nonnull_size <= (gap_size + cont_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh))) { + if(nonnull_size && nonnull_size <= (gap_size + cont_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh))) { uint8_t *move_start, *move_end; /* Pointers to area of messages to move */ unsigned cont_chunkno; /* Chunk number for continuation message */ @@ -1347,7 +1347,7 @@ H5O_move_cont(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned cont_u) size_t move_size; /* Size of the message to be moved */ /* Compute size of message to move */ - move_size = curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh); + 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); @@ -1368,7 +1368,7 @@ H5O_move_cont(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned cont_u) gap_size += (size_t)(move_end - move_start); if(gap_size >= (size_t)H5O_SIZEOF_MSGHDR_OH(oh)) { /* Adjust size of null (was continuation) message */ - cont_msg->raw_size = gap_size - H5O_SIZEOF_MSGHDR_OH(oh); + cont_msg->raw_size = gap_size - (size_t)H5O_SIZEOF_MSGHDR_OH(oh); cont_msg->raw = move_start + H5O_SIZEOF_MSGHDR_OH(oh); cont_msg->dirty = TRUE; chk_dirtied = TRUE; @@ -1442,6 +1442,10 @@ done: static htri_t H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) { + H5O_chunk_proxy_t *null_chk_proxy = NULL; /* Chunk that null message is in */ + H5O_chunk_proxy_t *curr_chk_proxy = NULL; /* Chunk that message is in */ + hbool_t null_chk_dirtied = FALSE; /* Flags for unprotecting null chunk */ + hbool_t curr_chk_dirtied = FALSE; /* Flags for unprotecting curr chunk */ hbool_t packed_msg; /* Flag to indicate that messages were packed */ hbool_t did_packing = FALSE; /* Whether any messages were packed */ htri_t ret_value; /* Return value */ @@ -1482,15 +1486,13 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /* Don't swap messages if the second message is also a null message */ /* (We'll merge them together later, in another routine) */ if(H5O_NULL_ID != nonnull_msg->type->id) { - H5O_chunk_proxy_t *null_chk_proxy; /* Chunk that message is in */ - /* Protect chunk */ if(NULL == (null_chk_proxy = H5O_chunk_protect(f, dxpl_id, oh, curr_msg->chunkno))) HGOTO_ERROR(H5E_OHDR, H5E_CANTPROTECT, FAIL, "unable to load object header chunk") /* Copy raw data for non-null message to new location */ HDmemmove(curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), - nonnull_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), nonnull_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh)); + nonnull_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), nonnull_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh)); /* Adjust non-null message's offset in chunk */ nonnull_msg->raw = curr_msg->raw; @@ -1506,6 +1508,7 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /* Release chunk, marking it dirty */ if(H5O_chunk_unprotect(f, dxpl_id, null_chk_proxy, TRUE) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to unprotect object header chunk") + null_chk_proxy = NULL; /* Set the flag to indicate that the null message * was packed - if its not at the end its chunk, @@ -1544,10 +1547,6 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) for(v = 0, null_msg = &oh->mesg[0]; v < oh->nmesgs; v++, null_msg++) { if(H5O_NULL_ID == null_msg->type->id && curr_msg->chunkno > null_msg->chunkno && curr_msg->raw_size <= null_msg->raw_size) { - H5O_chunk_proxy_t *null_chk_proxy; /* Chunk that null message is in */ - H5O_chunk_proxy_t *curr_chk_proxy; /* Chunk that message is in */ - unsigned null_chk_dirtied = FALSE; /* Flags for unprotecting null chunk */ - unsigned curr_chk_dirtied = FALSE; /* Flags for unprotecting curr chunk */ unsigned old_chunkno; /* Old message information */ uint8_t *old_raw; @@ -1562,7 +1561,7 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) HGOTO_ERROR(H5E_OHDR, H5E_CANTPROTECT, FAIL, "unable to load object header chunk") /* 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 + H5O_SIZEOF_MSGHDR_OH(oh)); + 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)); /* Point non-null message at null message's space */ curr_msg->chunkno = null_msg->chunkno; @@ -1583,6 +1582,8 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /* Release current chunk, marking it dirty */ if(H5O_chunk_unprotect(f, dxpl_id, curr_chk_proxy, curr_chk_dirtied) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to unprotect object header chunk") + curr_chk_proxy = NULL; + curr_chk_dirtied = FALSE; /* Check for gap in null message's chunk */ if(oh->chunk[old_chunkno].gap > 0) { @@ -1596,6 +1597,8 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /* Release null chunk, marking it dirty */ if(H5O_chunk_unprotect(f, dxpl_id, null_chk_proxy, null_chk_dirtied) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to unprotect object header chunk") + null_chk_proxy = NULL; + null_chk_dirtied = FALSE; } /* end if */ else { unsigned new_null_msg; /* Message index for new null message */ @@ -1620,8 +1623,8 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) } /* end if */ else { /* Adjust null message's size & offset */ - null_msg->raw += curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh); - null_msg->raw_size -= curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh); + null_msg->raw += curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh); + null_msg->raw_size -= curr_msg->raw_size + (size_t)H5O_SIZEOF_MSGHDR_OH(oh); /* Mark null message dirty */ null_msg->dirty = TRUE; @@ -1643,6 +1646,8 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /* Release null message's chunk, marking it dirty */ if(H5O_chunk_unprotect(f, dxpl_id, null_chk_proxy, null_chk_dirtied) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to unprotect object header chunk") + null_chk_proxy = NULL; + null_chk_dirtied = FALSE; /* Initialize new null message to take over non-null message's location */ oh->mesg[new_null_msg].type = H5O_MSG_NULL; @@ -1667,6 +1672,8 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /* Release new null message's chunk, marking it dirty */ if(H5O_chunk_unprotect(f, dxpl_id, curr_chk_proxy, curr_chk_dirtied) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to unprotect object header chunk") + curr_chk_proxy = NULL; + curr_chk_dirtied = FALSE; } /* end else */ /* Indicate that we packed messages */ @@ -1697,6 +1704,11 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh) ret_value = (htri_t)did_packing; done: + if(null_chk_proxy && H5O_chunk_unprotect(f, dxpl_id, null_chk_proxy, null_chk_dirtied) < 0) + HDONE_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to unprotect null object header chunk") + if(curr_chk_proxy && H5O_chunk_unprotect(f, dxpl_id, curr_chk_proxy, curr_chk_dirtied) < 0) + HDONE_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to unprotect current object header chunk") + FUNC_LEAVE_NOAPI(ret_value) } /* H5O_move_msgs_forward() */ @@ -1757,7 +1769,7 @@ H5O_merge_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh) if((curr_msg->raw + curr_msg->raw_size) == (curr_msg2->raw - H5O_SIZEOF_MSGHDR_OH(oh))) { /* Extend first null message length to cover second null message */ adj_raw = 0; - adj_raw_size = H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size; + adj_raw_size = (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size; /* Message has been merged */ merged_msg = TRUE; @@ -1765,8 +1777,8 @@ H5O_merge_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /* Check for second message before first message */ else if((curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh)) == (curr_msg2->raw + curr_msg2->raw_size)) { /* Adjust first message address and extend length to cover second message */ - adj_raw = -((ssize_t)(H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size)); - adj_raw_size = H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size; + adj_raw = -((ssize_t)((size_t)H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size)); + adj_raw_size = (size_t)H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size; /* Message has been merged */ merged_msg = TRUE; @@ -1877,7 +1889,7 @@ H5O_remove_empty_chunks(H5F_t *f, hid_t dxpl_id, H5O_t *oh) * its not the "base" chunk), delete that chunk from object header */ if(H5O_NULL_ID == null_msg->type->id && null_msg->chunkno > 0 && - (H5O_SIZEOF_MSGHDR_OH(oh) + null_msg->raw_size) + ((size_t)H5O_SIZEOF_MSGHDR_OH(oh) + null_msg->raw_size) == (oh->chunk[null_msg->chunkno].size - H5O_SIZEOF_CHKHDR_OH(oh))) { H5O_mesg_t *curr_msg; /* Pointer to current message to operate on */ unsigned null_msg_no; /* Message # for null message */ diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index 9f0f189..f155c94 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -849,16 +849,19 @@ H5O_attr_write_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, if(NULL == (chk_proxy = H5O_chunk_protect(udata->f, udata->dxpl_id, oh, mesg->chunkno))) HGOTO_ERROR(H5E_ATTR, H5E_CANTPROTECT, H5_ITER_ERROR, "unable to load object header chunk") - /* Allocate storage for the message's data, if necessary */ - if(NULL == ((H5A_t *)mesg->native)->shared->data) - if(NULL == (((H5A_t *)mesg->native)->shared->data = H5FL_BLK_MALLOC(attr_buf, udata->attr->shared->data_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "memory allocation failed") - - /* Copy the data into the header message */ - /* (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); + /* Because the attribute structure is shared now. The only situation that requires + * copying the data is when the metadata cache evicts and reloads this attribute. + * The shared attribute structure will be different in that situation. SLU-2010/7/29 */ + if(((H5A_t *)mesg->native)->shared != udata->attr->shared) { + /* Sanity check */ + HDassert(((H5A_t *)mesg->native)->shared->data); + HDassert(udata->attr->shared->data); + HDassert(((H5A_t *)mesg->native)->shared->data != udata->attr->shared->data); + + /* (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); + } /* end if */ /* Mark the message as modified */ mesg->dirty = TRUE; diff --git a/src/H5Ochunk.c b/src/H5Ochunk.c index 79c4442..42b391d 100644 --- a/src/H5Ochunk.c +++ b/src/H5Ochunk.c @@ -118,7 +118,7 @@ H5O_chunk_add(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx) HGOTO_ERROR(H5E_OHDR, H5E_CANTINC, FAIL, "can't increment reference count on object header") /* Insert the chunk proxy into the cache */ - if(H5AC_set(f, dxpl_id, H5AC_OHDR_CHK, oh->chunk[idx].addr, chk_proxy, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_OHDR_CHK, oh->chunk[idx].addr, chk_proxy, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTINSERT, FAIL, "unable to cache object header chunk") chk_proxy = NULL; @@ -148,8 +148,8 @@ done: H5O_chunk_proxy_t * H5O_chunk_protect(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx) { - H5O_chunk_proxy_t *chk_proxy; /* Proxy for protected chunk */ - H5O_chunk_proxy_t *ret_value; /* Return value */ + H5O_chunk_proxy_t *chk_proxy = NULL; /* Proxy for protected chunk */ + H5O_chunk_proxy_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_TAG(H5O_chunk_protect, dxpl_id, oh->cache_info.addr, NULL) @@ -196,6 +196,11 @@ H5O_chunk_protect(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx) ret_value = chk_proxy; done: + /* Cleanup on error */ + if(!ret_value) + if(0 == idx && chk_proxy) + chk_proxy = H5FL_FREE(H5O_chunk_proxy_t, chk_proxy); + FUNC_LEAVE_NOAPI_TAG(ret_value, NULL) } /* end H5O_chunk_protect() */ diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c index 94f7d9a..7a10765 100644 --- a/src/H5Ocopy.c +++ b/src/H5Ocopy.c @@ -575,7 +575,15 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, addr_new = oh_dst->chunk[0].addr; /* Create memory image for the new chunk */ - if(NULL == (oh_dst->chunk[0].image = H5FL_BLK_MALLOC(chunk_image, (size_t)dst_oh_size))) + /* Note: we use calloc() instead of malloc() here because older versions of + * some messages don't initialize "unused" bytes and because we want to + * write out the same version of the object header and older versions of + * object headers aligned messages. In both those situations, it's + * complex and error-prone to determine all the proper ways/places to + * clear to zero bytes, so we just set the buffer to zero's here. + * (QAK - 2010/08/17) + */ + if(NULL == (oh_dst->chunk[0].image = H5FL_BLK_CALLOC(chunk_image, (size_t)dst_oh_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Set dest. chunk information */ @@ -731,7 +739,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, H5_BEGIN_TAG(dxpl_id, oloc_dst->addr, FAIL); /* Insert destination object header in cache */ - if(H5AC_set(oloc_dst->file, dxpl_id, H5AC_OHDR, oloc_dst->addr, oh_dst, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(oloc_dst->file, dxpl_id, H5AC_OHDR, oloc_dst->addr, oh_dst, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTINSERT, FAIL, "unable to cache object header") oh_dst = NULL; diff --git a/src/H5Odtype.c b/src/H5Odtype.c index fec695e..51694a3 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1272,7 +1272,7 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) /* (starting with version 3 of the datatype message, use the minimum # of bytes required) */ if(dt->shared->version >= H5O_DTYPE_VERSION_3) ret_value += offset_nbytes; /*member offset*/ - if(dt->shared->version >= H5O_DTYPE_VERSION_2) + else if(dt->shared->version == H5O_DTYPE_VERSION_2) ret_value += 4; /*member offset*/ else ret_value += 4 + /*member offset*/ diff --git a/src/H5Olayout.c b/src/H5Olayout.c index 82227e6..debc169 100644 --- a/src/H5Olayout.c +++ b/src/H5Olayout.c @@ -797,6 +797,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, H5D_copy_file_ud_t *udata = (H5D_copy_file_ud_t *)_udata; /* Dataset copying user data */ H5O_layout_t *layout_src = (H5O_layout_t *) mesg_src; H5O_layout_t *layout_dst = NULL; + hbool_t copied = FALSE; /* Whether the data was copied */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_layout_copy_file) @@ -819,6 +820,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, /* copy compact raw data */ if(H5D_compact_copy(file_src, &layout_src->storage.u.compact, file_dst, &layout_dst->storage.u.compact, udata->src_dtype, cpy_info, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage") + copied = TRUE; } /* end if */ break; @@ -827,7 +829,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, * layout message less than version 3 because versions 1 & 2 would * truncate the dimension sizes to 32-bits of information. - QAK 5/26/04 */ - if(layout_src->version < 3) + if(layout_src->version < H5O_LAYOUT_VERSION_3) layout_dst->storage.u.contig.size = H5S_extent_nelem(udata->src_space_extent) * H5T_get_size(udata->src_dtype); @@ -835,6 +837,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, /* 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, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy contiguous storage") + copied = TRUE; } /* end if */ break; @@ -843,15 +846,13 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, /* 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, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage") + copied = TRUE; } /* end if */ break; default: HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "Invalid layout class") } /* end switch */ - - /* Freed by copy routine */ - udata->src_dtype = NULL; } /* end if */ else { /* Dataset's raw data will be copied using the 'storage' message, reset storage her */ @@ -859,6 +860,10 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, NULL, "unable to free message resources") } /* end else */ + /* Check if copy routine was invoked (which frees the source datatype) */ + if(copied) + udata->src_dtype = NULL; + /* Set return value */ ret_value = layout_dst; diff --git a/src/H5Omtime.c b/src/H5Omtime.c index e71fb50..731d833 100644 --- a/src/H5Omtime.c +++ b/src/H5Omtime.c @@ -96,7 +96,7 @@ const H5O_msg_class_t H5O_MSG_MTIME_NEW[1] = {{ #define H5O_MTIME_VERSION 1 /* Track whether tzset routine was called */ -static int ntzset=0; +static hbool_t ntzset = FALSE; /* Declare a free list to manage the time_t struct */ H5FL_DEFINE(time_t); @@ -180,23 +180,22 @@ H5O_mtime_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, H5O_t UNUSED *open_oh, struct tm tm; void *ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_mtime_decode); + FUNC_ENTER_NOAPI_NOINIT(H5O_mtime_decode) /* check args */ - assert(f); - assert(p); + HDassert(f); + HDassert(p); /* Initialize time zone information */ - if (!ntzset) { + if(!ntzset) { HDtzset(); - ntzset=1; + ntzset = TRUE; } /* end if */ /* decode */ - for (i=0; i<14; i++) { - if (!HDisdigit(p[i])) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "badly formatted modification time message"); - } + for(i = 0; i < 14; i++) + if(!HDisdigit(p[i])) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "badly formatted modification time message") /* * Convert YYYYMMDDhhmmss UTC to a time_t. This is a little problematic @@ -213,8 +212,8 @@ H5O_mtime_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, H5O_t UNUSED *open_oh, tm.tm_min = (p[10]-'0')*10 + (p[11]-'0'); tm.tm_sec = (p[12]-'0')*10 + (p[13]-'0'); tm.tm_isdst = -1; /*figure it out*/ - if ((time_t)-1==(the_time=HDmktime(&tm))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "badly formatted modification time message"); + if((time_t)-1 == (the_time = HDmktime(&tm))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "badly formatted modification time message") #if defined(H5_HAVE_TM_GMTOFF) /* FreeBSD, OSF 4.0 */ @@ -230,8 +229,8 @@ H5O_mtime_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, H5O_t UNUSED *open_oh, { struct timezone tz; - if (HDBSDgettimeofday(NULL, &tz)<0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to obtain local timezone information"); + if(HDBSDgettimeofday(NULL, &tz) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to obtain local timezone information") the_time -= tz.tz_minuteswest * 60 - (tm.tm_isdst ? 3600 : 0); } #elif defined(H5_HAVE_GETTIMEOFDAY) && defined(H5_HAVE_STRUCT_TIMEZONE) && defined(H5_GETTIMEOFDAY_GIVES_TZ) @@ -239,8 +238,8 @@ H5O_mtime_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, H5O_t UNUSED *open_oh, struct timezone tz; struct timeval tv; /* Used as a placebo; some systems don't like NULL */ - if (HDgettimeofday(&tv, &tz) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to obtain local timezone information"); + if(HDgettimeofday(&tv, &tz) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to obtain local timezone information") the_time -= tz.tz_minuteswest * 60 - (tm.tm_isdst ? 3600 : 0); } @@ -254,20 +253,20 @@ H5O_mtime_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, H5O_t UNUSED *open_oh, */ /* Irix64 */ - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to obtain local timezone information"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to obtain local timezone information") #endif /* The return value */ - if (NULL==(mesg = H5FL_MALLOC(time_t))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); + if(NULL == (mesg = H5FL_MALLOC(time_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") *mesg = the_time; /* Set return value */ - ret_value=mesg; + ret_value = mesg; done: - FUNC_LEAVE_NOAPI(ret_value); -} + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_mtime_decode() */ /*------------------------------------------------------------------------- diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 4bef827..b062b95 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -787,7 +787,7 @@ H5_DLL herr_t H5O_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, in /* These functions operate on object locations */ H5_DLL herr_t H5O_loc_reset(H5O_loc_t *loc); -H5_DLL herr_t H5O_loc_copy(H5O_loc_t *dst, const H5O_loc_t *src, H5_copy_depth_t depth); +H5_DLL herr_t H5O_loc_copy(H5O_loc_t *dst, H5O_loc_t *src, H5_copy_depth_t depth); H5_DLL herr_t H5O_loc_hold_file(H5O_loc_t *loc); H5_DLL herr_t H5O_loc_free(H5O_loc_t *loc); diff --git a/src/H5Osdspace.c b/src/H5Osdspace.c index f4cac40..323bec9 100644 --- a/src/H5Osdspace.c +++ b/src/H5Osdspace.c @@ -246,15 +246,15 @@ H5O_sdspace_encode(H5F_t *f, uint8_t *p, const void *_mesg) /* Version */ HDassert(sdim->version > 0); HDassert(sdim->type != H5S_NULL || sdim->version >= H5O_SDSPACE_VERSION_2); - *p++ = sdim->version; + *p++ = (uint8_t)sdim->version; /* Rank */ - *p++ = sdim->rank; + *p++ = (uint8_t)sdim->rank; /* Flags */ if(sdim->max) flags |= H5S_VALID_MAX; - *p++ = flags; + *p++ = (uint8_t)flags; /* Dataspace type */ if(sdim->version > H5O_SDSPACE_VERSION_1) @@ -319,7 +319,7 @@ H5O_sdspace_copy(const void *_mesg, void *_dest) done: if(NULL == ret_value) - if(dest && NULL != _dest) + if(dest && NULL == _dest) dest = H5FL_FREE(H5S_extent_t, dest); FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index 5bc2783..4055664 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -54,7 +54,7 @@ #define H5D_DEF_STORAGE_COMPACT_INIT {(hbool_t)FALSE, (size_t)0, NULL} #define H5D_DEF_STORAGE_CONTIG_INIT {HADDR_UNDEF, (hsize_t)0} #define H5D_DEF_STORAGE_CHUNK_INIT {H5D_CHUNK_IDX_BTREE, HADDR_UNDEF, H5D_COPS_BTREE, {{NULL}}} -#define H5D_DEF_LAYOUT_CHUNK_INIT {H5D_CHUNK_IDX_BTREE, (uint8_t)0, (unsigned)1, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, (unsigned)0, (uint32_t)0, (hsize_t)0, (hsize_t)0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {{{(uint8_t)0}}}} +#define H5D_DEF_LAYOUT_CHUNK_INIT {H5D_CHUNK_IDX_BTREE, (uint8_t)0, (unsigned)0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, (unsigned)0, (uint32_t)0, (hsize_t)0, (hsize_t)0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {{{(uint8_t)0}}}} #ifdef H5_HAVE_C99_DESIGNATED_INITIALIZER #define H5D_DEF_STORAGE_COMPACT {H5D_COMPACT, { .compact = H5D_DEF_STORAGE_COMPACT_INIT }} #define H5D_DEF_STORAGE_CONTIG {H5D_CONTIGUOUS, { .contig = H5D_DEF_STORAGE_CONTIG_INIT }} @@ -976,6 +976,7 @@ H5Pset_chunk_opts(hid_t plist_id, unsigned options) herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Pset_chunk_opts, FAIL) + H5TRACE2("e", "iIu", plist_id, options); /* Check arguments */ if(options & ~(H5D_CHUNK_DONT_FILTER_PARTIAL_CHUNKS)) @@ -1042,6 +1043,7 @@ H5Pget_chunk_opts(hid_t plist_id, unsigned *options) herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Pget_chunk_opts, FAIL) + H5TRACE2("e", "i*Iu", plist_id, options); #ifndef H5_HAVE_C99_DESIGNATED_INITIALIZER /* If the compiler doesn't support C99 designated initializers, check if @@ -209,7 +209,7 @@ H5SM_init(H5F_t *f, H5P_genplist_t * fc_plist, const H5O_loc_t *ext_loc, hid_t d HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, FAIL, "file allocation failed for SOHM table") /* Cache the new table */ - if(H5AC_set(f, dxpl_id, H5AC_SOHM_TABLE, table_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_SOHM_TABLE, table_addr, table, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTINS, FAIL, "can't add SOHM table to cache") /* Record the address of the master table in the file */ @@ -655,7 +655,7 @@ H5SM_create_list(H5F_t *f, H5SM_index_header_t *header, hid_t dxpl_id) HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed for SOHM list") /* Put the list into the cache */ - if(H5AC_set(f, dxpl_id, H5AC_SOHM_LIST, addr, list, H5AC__NO_FLAGS_SET) < 0) + if(H5AC_insert_entry(f, dxpl_id, H5AC_SOHM_LIST, addr, list, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTINS, HADDR_UNDEF, "can't add SOHM list to cache") /* Set return value */ @@ -1742,7 +1742,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, /* If this returns failure, it means that the message wasn't found. * If it succeeds, a copy of the modified message will be returned. */ - if(H5B2_modify(bt2, dxpl_id, &key, H5SM_decr_ref, &message) <0) + if(H5B2_modify(bt2, dxpl_id, &key, H5SM_decr_ref, &message) < 0) HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index") /* Point to the message */ diff --git a/src/H5SMcache.c b/src/H5SMcache.c index 4a9338b..1511fd0 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -605,7 +605,7 @@ H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis if(H5SM_message_encode(p, &(list->messages[x]), &ctx) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTFLUSH, FAIL, "unable to write shared message to disk") - p+=H5SM_SOHM_ENTRY_SIZE(f); + p += H5SM_SOHM_ENTRY_SIZE(f); ++mesgs_written; } /* end if */ } /* end for */ @@ -614,6 +614,9 @@ H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis /* Compute checksum on buffer */ computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); UINT32ENCODE(p, computed_chksum); +#ifdef H5_CLEAR_MEMORY +HDmemset(p, 0, (list->header->list_size - (p - buf))); +#endif /* H5_CLEAR_MEMORY */ /* Write the list to disk */ HDassert((size_t)(p - buf) <= list->header->list_size); diff --git a/src/H5SMmessage.c b/src/H5SMmessage.c index 32ded03..0d41a09 100644 --- a/src/H5SMmessage.c +++ b/src/H5SMmessage.c @@ -309,7 +309,7 @@ H5SM_message_encode(uint8_t *raw, const void *_nrecord, void *_ctx) *raw++ = 0; /* reserved (possible flags byte) */ *raw++ = (uint8_t)message->msg_type_id; UINT16ENCODE(raw, message->u.mesg_loc.index); - H5F_addr_encode_len(ctx->sizeof_addr, &raw, message->u.mesg_loc.oh_addr); + H5F_addr_encode_len((size_t)ctx->sizeof_addr, &raw, message->u.mesg_loc.oh_addr); } /* end else */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -350,7 +350,7 @@ H5SM_message_decode(const uint8_t *raw, void *_nrecord, void *_ctx) raw++; /* reserved */ message->msg_type_id = *raw++; UINT16DECODE(raw, message->u.mesg_loc.index); - H5F_addr_decode_len(ctx->sizeof_addr, &raw, &message->u.mesg_loc.oh_addr); + H5F_addr_decode_len((size_t)ctx->sizeof_addr, &raw, &message->u.mesg_loc.oh_addr); } /* end else */ FUNC_LEAVE_NOAPI(SUCCEED) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index df81275..628512f 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -327,7 +327,7 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) iter->u.hyp.diminfo[curr_dim].count = tdiminfo[i].count; iter->u.hyp.diminfo[curr_dim].block = tdiminfo[i].block * acc; iter->u.hyp.size[curr_dim] = mem_size[i] * acc; - iter->u.hyp.sel_off[curr_dim] = space->select.offset[i] * acc; + iter->u.hyp.sel_off[curr_dim] = space->select.offset[i] * (hssize_t)acc; /* Reset the "last dim flattened" flag to avoid flattened any further dimensions */ last_dim_flattened = 0; @@ -1385,7 +1385,7 @@ H5S_hyper_copy_span(H5S_hyper_span_info_t *spans) /* Copy the hyperslab span tree */ if(NULL == (ret_value = H5S_hyper_copy_span_helper(spans))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy hyperslab span tree") + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy hyperslab span tree") /* Reset the scratch pointers for the next routine which needs them */ H5S_hyper_span_scratch(spans, NULL); @@ -2662,10 +2662,10 @@ H5S_hyper_bounds_helper(const H5S_hyper_span_info_t *spans, const hssize_t *offs HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") /* Check if the current span extends the bounding box */ - if((curr->low + offset[rank]) < start[rank]) - start[rank] = curr->low + offset[rank]; - if((curr->high + offset[rank]) > end[rank]) - end[rank] = curr->high + offset[rank]; + if((curr->low + (hsize_t)offset[rank]) < start[rank]) + start[rank] = curr->low + (hsize_t)offset[rank]; + if((curr->high + (hsize_t)offset[rank]) > end[rank]) + end[rank] = curr->high + (hsize_t)offset[rank]; /* Recurse if this node has down spans */ if(curr->down != NULL) { @@ -2711,43 +2711,43 @@ done: herr_t H5S_hyper_bounds(const H5S_t *space, hsize_t *start, hsize_t *end) { - int rank; /* Dataspace rank */ - int i; /* index variable */ - herr_t ret_value=SUCCEED; /* Return value */ + unsigned rank; /* Dataspace rank */ + unsigned i; /* index variable */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5S_hyper_bounds,FAIL) + FUNC_ENTER_NOAPI(H5S_hyper_bounds, FAIL) - assert(space); - assert(start); - assert(end); + HDassert(space); + HDassert(start); + HDassert(end); /* Set the start and end arrays up */ - rank=space->extent.rank; - for(i=0; i<rank; i++) { - start[i]=HSIZET_MAX; - end[i]=0; + rank = space->extent.rank; + for(i = 0; i < rank; i++) { + start[i] = HSIZET_MAX; + end[i] = 0; } /* end for */ /* Check for a "regular" hyperslab selection */ if(space->select.sel_info.hslab->diminfo_valid) { - const H5S_hyper_dim_t *diminfo=space->select.sel_info.hslab->opt_diminfo; /* local alias for diminfo */ + const H5S_hyper_dim_t *diminfo = space->select.sel_info.hslab->opt_diminfo; /* local alias for diminfo */ /* Check each dimension */ - for(i=0; i<rank; i++) { + for(i = 0; i < rank; i++) { /* Check for offset moving selection negative */ - if((space->select.offset[i]+(hssize_t)diminfo[i].start)<0) + if((space->select.offset[i] + (hssize_t)diminfo[i].start) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") /* Compute the smallest location in this dimension */ - start[i]=diminfo[i].start+space->select.offset[i]; + start[i] = diminfo[i].start + (hsize_t)space->select.offset[i]; /* Compute the largest location in this dimension */ - end[i]=diminfo[i].start+diminfo[i].stride*(diminfo[i].count-1)+(diminfo[i].block-1)+space->select.offset[i]; + end[i] = diminfo[i].start + diminfo[i].stride * (diminfo[i].count - 1) + (diminfo[i].block - 1) + (hsize_t)space->select.offset[i]; } /* end for */ } /* end if */ else { /* Call the recursive routine to get the bounds for the span tree */ - ret_value=H5S_hyper_bounds_helper(space->select.sel_info.hslab->span_lst,space->select.offset,(hsize_t)0,start,end); + ret_value = H5S_hyper_bounds_helper(space->select.sel_info.hslab->span_lst, space->select.offset, (hsize_t)0, start, end); } /* end if */ done: @@ -2781,7 +2781,7 @@ H5S_hyper_offset(const H5S_t *space, hsize_t *offset) const hssize_t *sel_offset; /* Pointer to the selection's offset */ const hsize_t *dim_size; /* Pointer to a dataspace's extent */ hsize_t accum; /* Accumulator for dimension sizes */ - int rank; /* Dataspace rank */ + unsigned rank; /* Dataspace rank */ int i; /* index variable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -2804,7 +2804,7 @@ H5S_hyper_offset(const H5S_t *space, hsize_t *offset) /* Loop through starting coordinates, calculating the linear offset */ accum = 1; - for(i = (rank - 1); i >= 0; i--) { + for(i = (int)(rank - 1); i >= 0; i--) { hssize_t hyp_offset = (hssize_t)diminfo[i].start + sel_offset[i]; /* Hyperslab's offset in this dimension */ /* Check for offset moving selection out of the dataspace */ @@ -2812,7 +2812,7 @@ H5S_hyper_offset(const H5S_t *space, hsize_t *offset) HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") /* Add the hyperslab's offset in this dimension to the total linear offset */ - *offset += hyp_offset * accum; + *offset += (hsize_t)(hyp_offset * (hssize_t)accum); /* Increase the accumulator */ accum *= dim_size[i]; @@ -2824,7 +2824,7 @@ H5S_hyper_offset(const H5S_t *space, hsize_t *offset) /* Calculate the accumulator for each dimension */ accum = 1; - for(i = (rank - 1); i >= 0; i--) { + for(i = (int)(rank - 1); i >= 0; i--) { /* Set the accumulator for this dimension */ dim_accum[i] = accum; @@ -2845,7 +2845,7 @@ H5S_hyper_offset(const H5S_t *space, hsize_t *offset) HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") /* Add the hyperslab's offset in this dimension to the total linear offset */ - *offset += hyp_offset * dim_accum[i]; + *offset += (hsize_t)(hyp_offset * (hssize_t)dim_accum[i]); /* Advance to first span in "down" dimension */ if(span->down) { @@ -4436,8 +4436,8 @@ H5S_hyper_adjust_helper_s(H5S_hyper_span_info_t *spans, const hssize_t *offset) while(span != NULL) { /* Adjust span offset */ HDassert((hssize_t)span->low >= *offset); - span->low -= *offset; - span->high -= *offset; + span->low = (hsize_t)((hssize_t)span->low - *offset); + span->high = (hsize_t)((hssize_t)span->high - *offset); /* Recursively adjust spans in next dimension down */ if(span->down != NULL) @@ -4474,146 +4474,37 @@ herr_t H5S_hyper_adjust_s(H5S_t *space, const hssize_t *offset) { unsigned u; /* Local index variable */ - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_adjust_s); + FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_adjust_s) - assert(space); - assert(offset); + HDassert(space); + HDassert(offset); /* Subtract the offset from the "regular" coordinates, if they exist */ if(space->select.sel_info.hslab->diminfo_valid) { - for(u=0; u<space->extent.rank; u++) { - assert((hssize_t)space->select.sel_info.hslab->opt_diminfo[u].start>=offset[u]); - space->select.sel_info.hslab->opt_diminfo[u].start-=offset[u]; + for(u = 0; u < space->extent.rank; u++) { + HDassert((hssize_t)space->select.sel_info.hslab->opt_diminfo[u].start >= offset[u]); + space->select.sel_info.hslab->opt_diminfo[u].start = (hsize_t)((hssize_t)space->select.sel_info.hslab->opt_diminfo[u].start - offset[u]); } /* end for */ } /* end if */ /* Subtract the offset from the span tree coordinates, if they exist */ if(space->select.sel_info.hslab->span_lst) { - if(H5S_hyper_adjust_helper_s(space->select.sel_info.hslab->span_lst,offset)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab offset adjustment"); + if(H5S_hyper_adjust_helper_s(space->select.sel_info.hslab->span_lst, offset) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab offset adjustment") /* Reset the scratch pointers for the next routine which needs them */ H5S_hyper_span_scratch(space->select.sel_info.hslab->span_lst, NULL); } /* end if */ done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* H5S_hyper_adjust_s() */ /*-------------------------------------------------------------------------- NAME - H5S_hyper_move_helper - PURPOSE - Helper routine to move offset in span trees - USAGE - herr_t H5S_hyper_move_helper(spans, offset) - H5S_hyper_span_info_t *spans; IN: Span tree to operate with - const hssize_t *offset; IN: Offset to move to - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Adjust the location of the spans in a span tree by moving selection to an - offset. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static herr_t -H5S_hyper_move_helper (H5S_hyper_span_info_t *spans, const hssize_t *offset) -{ - H5S_hyper_span_t *span; /* Pointer to current span in span tree */ - - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_move_helper); - - /* Sanity check */ - assert(spans); - assert(offset); - - /* Check if we've already set this down span tree */ - if(spans->scratch!=(H5S_hyper_span_info_t *)~((size_t)NULL)) { - /* Set the tree's scratch pointer */ - spans->scratch=(H5S_hyper_span_info_t *)~((size_t)NULL); - - /* Get the span lists for each span in this tree */ - span=spans->head; - - /* Iterate over the spans in tree */ - while(span!=NULL) { - /* Adjust span location */ - assert(*offset>=0); - span->high=*offset+(span->high-span->low); - span->low=*offset; - - /* Recursively move spans in next dimension down */ - if(span->down!=NULL) - H5S_hyper_move_helper(span->down,offset+1); - - /* Advance to next span in this dimension */ - span=span->next; - } /* end while */ - } /* end if */ - - FUNC_LEAVE_NOAPI(SUCCEED); -} /* H5S_hyper_move_helper() */ - - -/*-------------------------------------------------------------------------- - NAME - H5S_hyper_move - PURPOSE - Move a hyperslab selection by to an offset - USAGE - herr_t H5S_hyper_move(space,offset) - H5S_t *space; IN/OUT: Pointer to dataspace to move - const hssize_t *offset; IN: Offset to move to - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Moves a hyperslab selection to a new offset. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -herr_t -H5S_hyper_move(H5S_t *space, const hssize_t *offset) -{ - unsigned u; /* Local index variable */ - herr_t ret_value=SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_move); - - assert(space); - assert(offset); - - /* Move to the offset with the "regular" coordinates, if they exist */ - if(space->select.sel_info.hslab->diminfo_valid) { - for(u=0; u<space->extent.rank; u++) { - assert(offset[u]>=0); - space->select.sel_info.hslab->opt_diminfo[u].start=offset[u]; - } /* end for */ - } /* end if */ - - /* Subtract the offset from the span tree coordinates, if they exist */ - if(space->select.sel_info.hslab->span_lst) { - if(H5S_hyper_move_helper(space->select.sel_info.hslab->span_lst,offset)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab offset movement"); - - /* Reset the scratch pointers for the next routine which needs them */ - H5S_hyper_span_scratch(space->select.sel_info.hslab->span_lst, NULL); - } /* end if */ - -done: - FUNC_LEAVE_NOAPI(ret_value); -} /* H5S_hyper_move() */ - - -/*-------------------------------------------------------------------------- - NAME H5S_hyper_normalize_offset PURPOSE "Normalize" a hyperslab selection by adjusting it's coordinates by the @@ -5774,10 +5665,9 @@ static H5S_hyper_span_info_t * H5S_hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride, const hsize_t *count, const hsize_t *block) { - H5S_hyper_span_info_t *down; /* Pointer to spans in next dimension down */ - H5S_hyper_span_t *span; /* New hyperslab span */ + H5S_hyper_span_info_t *down = NULL; /* Pointer to spans in next dimension down */ H5S_hyper_span_t *last_span; /* Current position in hyperslab span list */ - H5S_hyper_span_t *head; /* Head of new hyperslab span list */ + H5S_hyper_span_t *head = NULL; /* Head of new hyperslab span list */ hsize_t stride_iter; /* Iterator over the stride values */ int i; /* Counters */ unsigned u; /* Counters */ @@ -5793,8 +5683,7 @@ H5S_hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride, HDassert(block); /* Start creating spans in fastest changing dimension */ - down = NULL; - for(i = (rank - 1); i >= 0; i--) { + for(i = (int)(rank - 1); i >= 0; i--) { /* Sanity check */ if(0 == count[i]) @@ -5806,6 +5695,8 @@ H5S_hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride, /* Generate all the span segments for this dimension */ for(u = 0, stride_iter = 0; u < count[i]; u++, stride_iter += stride[i]) { + H5S_hyper_span_t *span; /* New hyperslab span */ + /* Allocate a span node */ if(NULL == (span = H5FL_MALLOC(H5S_hyper_span_t))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") @@ -5918,7 +5809,7 @@ H5S_hyper_rebuild_helper(const H5S_hyper_span_t *span, H5S_hyper_dim_t span_slab hsize_t curr_block, next_block; hsize_t curr_start; hsize_t curr_low; - int outcount; + size_t outcount; unsigned u; H5S_hyper_dim_t canon_down_span_slab_info[H5S_MAX_RANK]; hbool_t ret_value = TRUE; @@ -6318,6 +6209,11 @@ H5S_generate_hyperslab (H5S_t *space, H5S_seloper_t op, } /* end if */ break; + case H5S_SELECT_NOOP: + case H5S_SELECT_SET: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: default: HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation"); } /* end switch */ @@ -6444,6 +6340,10 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, case H5S_SELECT_NOTB: /* Binary "A not B" operation for hyperslabs */ HGOTO_DONE(SUCCEED); /* Selection stays same */ + case H5S_SELECT_NOOP: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: default: HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation"); } /* end switch */ @@ -6503,6 +6403,10 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, case H5S_SELECT_NOTB: /* Binary "A not B" operation for hyperslabs */ HGOTO_DONE(SUCCEED); /* Selection stays "none" */ + case H5S_SELECT_NOOP: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: default: HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation"); } /* end switch */ @@ -6551,6 +6455,10 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't convert selection"); HGOTO_DONE(SUCCEED); + case H5S_SELECT_NOOP: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: default: HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation"); } /* end switch */ @@ -6565,6 +6473,8 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, break; /* Else fall through to error */ + case H5S_SEL_ERROR: + case H5S_SEL_N: default: HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation"); } /* end switch */ @@ -7642,63 +7552,64 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, H5S_hyper_span_t *curr_span; /* Current hyperslab span node */ H5S_hyper_span_t **ispan; /* Iterator's hyperslab span nodes */ hsize_t slab[H5O_LAYOUT_NDIMS]; /* Cumulative size of each dimension in bytes */ - hsize_t acc; /* Accumulator for computing cumulative sizes */ - hsize_t loc_off; /* Element offset in the dataspace */ - hsize_t last_span_end=0; /* The offset of the end of the last span */ + hsize_t acc; /* Accumulator for computing cumulative sizes */ + hsize_t loc_off; /* Element offset in the dataspace */ + hsize_t last_span_end = 0; /* The offset of the end of the last span */ hsize_t *abs_arr; /* Absolute hyperslab span position */ const hssize_t *off_arr; /* Offset within the dataspace extent */ - size_t span_size=0; /* Number of bytes in current span to actually process */ - size_t io_left; /* Number of elements left to process */ + size_t span_size = 0; /* Number of bytes in current span to actually process */ + size_t io_left; /* Number of elements left to process */ size_t io_bytes_left; /* Number of bytes left to process */ - size_t io_used; /* Number of elements processed */ - size_t curr_seq=0; /* Number of sequence/offsets stored in the arrays */ - size_t elem_size; /* Size of each element iterating over */ - int ndims; /* Number of dimensions of dataset */ - int fast_dim; /* Rank of the fastest changing dimension for the dataspace */ + size_t io_used; /* Number of elements processed */ + size_t curr_seq = 0; /* Number of sequence/offsets stored in the arrays */ + size_t elem_size; /* Size of each element iterating over */ + unsigned ndims; /* Number of dimensions of dataset */ + unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ int curr_dim; /* Current dimension being operated on */ + unsigned u; /* Index variable */ int i; /* Index variable */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_get_seq_list_gen); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_get_seq_list_gen) /* Check args */ - assert(space); - assert(iter); - assert(maxseq>0); - assert(maxelem>0); - assert(nseq); - assert(nelem); - assert(off); - assert(len); + HDassert(space); + HDassert(iter); + HDassert(maxseq > 0); + HDassert(maxelem > 0); + HDassert(nseq); + HDassert(nelem); + HDassert(off); + HDassert(len); /* Set the rank of the fastest changing dimension */ - ndims=space->extent.rank; - fast_dim=(ndims-1); + ndims = space->extent.rank; + fast_dim = (ndims - 1); /* Get the pointers to the current span info and span nodes */ - curr_span=iter->u.hyp.span[fast_dim]; - abs_arr=iter->u.hyp.off; - off_arr=space->select.offset; - ispan=iter->u.hyp.span; - elem_size=iter->elmt_size; + curr_span = iter->u.hyp.span[fast_dim]; + abs_arr = iter->u.hyp.off; + off_arr = space->select.offset; + ispan = iter->u.hyp.span; + elem_size = iter->elmt_size; /* Set the amount of elements to perform I/O on, etc. */ - H5_CHECK_OVERFLOW(iter->elmt_left,hsize_t,size_t); - io_left=MIN(maxelem,(size_t)iter->elmt_left); - io_bytes_left=io_left*elem_size; + H5_CHECK_OVERFLOW(iter->elmt_left, hsize_t, size_t); + io_left = MIN(maxelem, (size_t)iter->elmt_left); + io_bytes_left = io_left * elem_size; /* Compute the cumulative size of dataspace dimensions */ - for(i=fast_dim, acc=elem_size; i>=0; i--) { - slab[i]=acc; - acc*=space->extent.size[i]; + for(i = (int)fast_dim, acc = elem_size; i >= 0; i--) { + slab[i] = acc; + acc *= space->extent.size[i]; } /* end for */ /* Set the offset of the first element iterated on */ - for(i=0, loc_off=0; i<ndims; i++) + for(u = 0, loc_off = 0; u < ndims; u++) /* Compute the sequential element offset */ - loc_off+=(abs_arr[i]+off_arr[i])*slab[i]; + loc_off += ((hsize_t)((hssize_t)abs_arr[u] + off_arr[u])) * slab[u]; /* Range check against number of elements left in selection */ - assert(io_bytes_left<=(iter->elmt_left*elem_size)); + HDassert(io_bytes_left <= (iter->elmt_left * elem_size)); /* Take care of any partial spans leftover from previous I/Os */ if(abs_arr[fast_dim]!=curr_span->low) { @@ -7765,7 +7676,7 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, if(NULL == curr_span) { /* Same as code in main loop */ /* Start at the next fastest dim */ - curr_dim = fast_dim - 1; + curr_dim = (int)(fast_dim - 1); /* Work back up through the dimensions */ while(curr_dim >= 0) { @@ -7804,7 +7715,7 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, /* Check if we have more spans in the tree */ if(curr_dim >= 0) { /* Walk back down the iterator positions, reseting them */ - while(curr_dim < fast_dim) { + while((unsigned)curr_dim < fast_dim) { HDassert(curr_span); HDassert(curr_span->down); HDassert(curr_span->down->head); @@ -7826,8 +7737,8 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, HDassert(curr_span == iter->u.hyp.span[fast_dim]); /* Reset the buffer offset */ - for(i = 0, loc_off = 0; i < ndims; i++) - loc_off += (abs_arr[i] + off_arr[i]) * slab[i]; + for(u = 0, loc_off = 0; u < ndims; u++) + loc_off += ((hsize_t)((hssize_t)abs_arr[u] + off_arr[u])) * slab[u]; } /* end else */ else /* We had better be done with I/O or bad things are going to happen... */ @@ -7861,25 +7772,18 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, /* Store the I/O information for the span */ /* Check if this is appending onto previous sequence */ - if(curr_seq>0 && last_span_end==loc_off) - len[curr_seq-1]+=span_size; + if(curr_seq > 0 && last_span_end == loc_off) + len[curr_seq - 1] += span_size; else { - off[curr_seq]=loc_off; - len[curr_seq]=span_size; + off[curr_seq] = loc_off; + len[curr_seq] = span_size; /* Increment the number of sequences in arrays */ curr_seq++; } /* end else */ /* Set the location of the last span's end */ - last_span_end=loc_off+span_size; - - /* If the sequence & offset arrays are full, do what? */ - if(curr_seq>=maxseq) { - /* Break out now, we are finished with sequences */ - break; - - } /* end else */ + last_span_end = loc_off + span_size; /* end COMMON */ /* Break out now, we are finished with I/O */ @@ -7887,31 +7791,31 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, } /* end if */ else { /* Decrement I/O left to perform */ - io_bytes_left-=span_size; + io_bytes_left -= span_size; /* COMMON */ /* Store the I/O information for the span */ /* Check if this is appending onto previous sequence */ - if(curr_seq>0 && last_span_end==loc_off) + if(curr_seq > 0 && last_span_end == loc_off) len[curr_seq-1]+=span_size; else { - off[curr_seq]=loc_off; - len[curr_seq]=span_size; + off[curr_seq] = loc_off; + len[curr_seq] = span_size; /* Increment the number of sequences in arrays */ curr_seq++; } /* end else */ /* Set the location of the last span's end */ - last_span_end=loc_off+span_size; + last_span_end = loc_off + span_size; +/* end COMMON */ /* If the sequence & offset arrays are full, do what? */ - if(curr_seq>=maxseq) { + if(curr_seq >= maxseq) { /* Break out now, we are finished with sequences */ break; } /* end else */ -/* end COMMON */ } /* end else */ /* Move to next span in fastest changing dimension */ @@ -7946,10 +7850,10 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, /* Adjust iterator pointers */ /* Start at the next fastest dim */ - curr_dim=fast_dim-1; + curr_dim = (int)(fast_dim - 1); /* Work back up through the dimensions */ - while(curr_dim>=0) { + while(curr_dim >= 0) { /* Reset the current span */ curr_span=iter->u.hyp.span[curr_dim]; @@ -7983,51 +7887,51 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, } /* end while */ /* Check if we are finished with the spans in the tree */ - if(curr_dim<0) { + if(curr_dim < 0) { /* We had better be done with I/O or bad things are going to happen... */ - assert(io_bytes_left==0); + HDassert(io_bytes_left == 0); break; } /* end if */ else { /* Walk back down the iterator positions, reseting them */ - while(curr_dim<fast_dim) { - assert(curr_span); - assert(curr_span->down); - assert(curr_span->down->head); + while((unsigned)curr_dim < fast_dim) { + HDassert(curr_span); + HDassert(curr_span->down); + HDassert(curr_span->down->head); /* Increment current dimension to the next dimension down */ curr_dim++; /* Set the new span for the next dimension down */ - iter->u.hyp.span[curr_dim]=curr_span->down->head; + iter->u.hyp.span[curr_dim] = curr_span->down->head; /* Advance span down the tree */ - curr_span=curr_span->down->head; + curr_span = curr_span->down->head; /* Reset the absolute offset for the dim */ - abs_arr[curr_dim]=curr_span->low; + abs_arr[curr_dim] = curr_span->low; } /* end while */ /* Verify that the curr_span points to the fastest dim */ - assert(curr_span==iter->u.hyp.span[fast_dim]); + HDassert(curr_span == iter->u.hyp.span[fast_dim]); } /* end else */ /* Reset the buffer offset */ - for(i=0, loc_off=0; i<ndims; i++) - loc_off+=(abs_arr[i]+off_arr[i])*slab[i]; + for(u = 0, loc_off = 0; u < ndims; u++) + loc_off += ((hsize_t)((hssize_t)abs_arr[u] + off_arr[u])) * slab[u]; } /* end while */ /* Decrement number of elements left in iterator */ - io_used=(io_left-(io_bytes_left/elem_size)); - iter->elmt_left-=io_used; + io_used = (io_left - (io_bytes_left / elem_size)); + iter->elmt_left -= io_used; /* Set the number of sequences generated */ - *nseq=curr_seq; + *nseq = curr_seq; /* Set the number of elements used */ - *nelem=io_used; + *nelem = io_used; - FUNC_LEAVE_NOAPI(SUCCEED); + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S_hyper_get_seq_list_gen() */ @@ -8062,7 +7966,7 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, +H5S_hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, size_t maxseq, size_t maxelem, size_t *nseq, size_t *nelem, hsize_t *off, size_t *len) { @@ -8085,11 +7989,12 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, size_t act_blk_count; /* Actual number of blocks to output */ size_t total_rows; /* Total number of entire rows to output */ size_t curr_rows; /* Current number of entire rows to output */ - int fast_dim; /* Rank of the fastest changing dimension for the dataspace */ + unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ + unsigned ndims; /* Number of dimensions of dataset */ int temp_dim; /* Temporary rank holder */ - int ndims; /* Number of dimensions of dataset */ hsize_t acc; /* Accumulator */ hsize_t loc; /* Coordinate offset */ + unsigned u; /* Local index variable */ int i; /* Local index variable */ size_t curr_seq=0; /* Current sequence being operated on */ size_t actual_elem; /* The actual number of elements to count */ @@ -8099,50 +8004,50 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, size_t start_io_left; /* The initial number of elements left in I/O operation */ size_t elem_size; /* Size of each element iterating over */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_get_seq_list_opt); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_get_seq_list_opt) /* Check args */ - assert(space); - assert(iter); - assert(maxseq>0); - assert(maxelem>0); - assert(nseq); - assert(nelem); - assert(off); - assert(len); + HDassert(space); + HDassert(iter); + HDassert(maxseq > 0); + HDassert(maxelem > 0); + HDassert(nseq); + HDassert(nelem); + HDassert(off); + HDassert(len); /* Set the local copy of the diminfo pointer */ - tdiminfo=iter->u.hyp.diminfo; + tdiminfo = iter->u.hyp.diminfo; /* Check if this is a "flattened" regular hyperslab selection */ - if(iter->u.hyp.iter_rank!=0 && iter->u.hyp.iter_rank<space->extent.rank) { + if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < space->extent.rank) { /* Set the aliases for a few important dimension ranks */ - ndims=iter->u.hyp.iter_rank; - fast_dim=ndims-1; + ndims = iter->u.hyp.iter_rank; + fast_dim = ndims - 1; /* Set the local copy of the selection offset */ - sel_off=iter->u.hyp.sel_off; + sel_off = iter->u.hyp.sel_off; /* Set up the pointer to the size of the memory space */ - mem_size=iter->u.hyp.size; + mem_size = iter->u.hyp.size; } /* end if */ else { /* Set the aliases for a few important dimension ranks */ - ndims=space->extent.rank; - fast_dim=ndims-1; + ndims = space->extent.rank; + fast_dim = ndims - 1; /* Set the local copy of the selection offset */ - sel_off=space->select.offset; + sel_off = space->select.offset; /* Set up the pointer to the size of the memory space */ - mem_size=space->extent.size; + mem_size = space->extent.size; } /* end else */ /* initialize row sizes for each dimension */ - elem_size=iter->elmt_size; - for(i=(ndims-1),acc=elem_size; i>=0; i--) { - slab[i]=acc; - acc*=mem_size[i]; + elem_size = iter->elmt_size; + for(i = (int)fast_dim, acc = elem_size; i >= 0; i--) { + slab[i] = acc; + acc *= mem_size[i]; } /* end for */ /* Calculate the number of elements to sequence through */ @@ -8166,12 +8071,12 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, actual_elem=MIN(leftover,io_left); /* Compute the initial buffer offset */ - for(i=0,loc=0; i<ndims; i++) - loc+=(iter->u.hyp.off[i]+sel_off[i])*slab[i]; + for(u = 0, loc = 0; u < ndims; u++) + loc += ((hsize_t)((hssize_t)iter->u.hyp.off[u] + sel_off[u])) * slab[u]; /* Add a new sequence */ - off[curr_seq]=loc; - H5_ASSIGN_OVERFLOW(len[curr_seq],actual_elem*elem_size,hsize_t,size_t); + off[curr_seq] = loc; + H5_ASSIGN_OVERFLOW(len[curr_seq], actual_elem * elem_size, hsize_t, size_t); /* Increment sequence count */ curr_seq++; @@ -8180,10 +8085,10 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, io_left -= actual_elem; /* Advance the hyperslab iterator */ - H5S_hyper_iter_next(iter,actual_elem); + H5S_hyper_iter_next(iter, actual_elem); /* Decrement the number of elements left in selection */ - iter->elmt_left-=actual_elem; + iter->elmt_left -= actual_elem; } /* end if */ /* Now that we've cleared the "remainder" of the previous fastest dimension @@ -8191,32 +8096,32 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, * algorithm to compute the offsets and run through as many as possible, * until the buffer fills up. */ - if(io_left>0 && curr_seq<maxseq) { /* Just in case the "remainder" above filled the buffer */ + if(io_left > 0 && curr_seq < maxseq) { /* Just in case the "remainder" above filled the buffer */ /* Keep the number of elements we started with */ - nelmts=io_left; + nelmts = io_left; /* Compute the arrays to perform I/O on */ /* Copy the location of the point to get */ /* (Add in the selection offset) */ - for(i=0; i<ndims; i++) - offset[i] = iter->u.hyp.off[i] + sel_off[i]; + for(u = 0; u < ndims; u++) + offset[u] = (hsize_t)((hssize_t)iter->u.hyp.off[u] + sel_off[u]); /* Compute the current "counts" for this location */ - for(i=0; i<ndims; i++) { - if(tdiminfo[i].count==1) { - tmp_count[i] = 0; - tmp_block[i] = iter->u.hyp.off[i]-tdiminfo[i].start; + for(u = 0; u < ndims; u++) { + if(tdiminfo[u].count == 1) { + tmp_count[u] = 0; + tmp_block[u] = iter->u.hyp.off[u] - tdiminfo[u].start; } /* end if */ else { - tmp_count[i] = (iter->u.hyp.off[i]-tdiminfo[i].start)/tdiminfo[i].stride; - tmp_block[i] = (iter->u.hyp.off[i]-tdiminfo[i].start)%tdiminfo[i].stride; + tmp_count[u] = (iter->u.hyp.off[u] - tdiminfo[u].start) / tdiminfo[u].stride; + tmp_block[u] = (iter->u.hyp.off[u] - tdiminfo[u].start) % tdiminfo[u].stride; } /* end else */ } /* end for */ /* Compute the initial buffer offset */ - for(i=0,loc=0; i<ndims; i++) - loc+=offset[i]*slab[i]; + for(u = 0, loc = 0; u < ndims; u++) + loc += offset[u] * slab[u]; /* Set the number of elements to write each time */ H5_ASSIGN_OVERFLOW(actual_elem,tdiminfo[fast_dim].block,hsize_t,size_t); @@ -8225,31 +8130,31 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, actual_bytes=actual_elem*elem_size; /* Set local copies of information for the fastest changing dimension */ - fast_dim_start=tdiminfo[fast_dim].start; - fast_dim_stride=tdiminfo[fast_dim].stride; - fast_dim_block=tdiminfo[fast_dim].block; - H5_ASSIGN_OVERFLOW(fast_dim_buf_off,slab[fast_dim]*fast_dim_stride,hsize_t,size_t); - fast_dim_offset=fast_dim_start+sel_off[fast_dim]; + fast_dim_start = tdiminfo[fast_dim].start; + fast_dim_stride = tdiminfo[fast_dim].stride; + fast_dim_block = tdiminfo[fast_dim].block; + H5_ASSIGN_OVERFLOW(fast_dim_buf_off, slab[fast_dim] * fast_dim_stride, hsize_t, size_t); + fast_dim_offset = (hsize_t)((hssize_t)fast_dim_start + sel_off[fast_dim]); /* Compute the number of blocks which would fit into the buffer */ - H5_CHECK_OVERFLOW(io_left/fast_dim_block,hsize_t,size_t); - tot_blk_count=(size_t)(io_left/fast_dim_block); + H5_CHECK_OVERFLOW(io_left / fast_dim_block, hsize_t, size_t); + tot_blk_count = (size_t)(io_left / fast_dim_block); /* Don't go over the maximum number of sequences allowed */ - tot_blk_count=MIN(tot_blk_count,(maxseq-curr_seq)); + tot_blk_count = MIN(tot_blk_count, (maxseq - curr_seq)); /* Compute the amount to wrap at the end of each row */ - for(i=0; i<ndims; i++) - wrap[i]=(mem_size[i]-(tdiminfo[i].stride*tdiminfo[i].count))*slab[i]; + for(u = 0; u < ndims; u++) + wrap[u] = (mem_size[u] - (tdiminfo[u].stride * tdiminfo[u].count)) * slab[u]; /* Compute the amount to skip between blocks */ - for(i=0; i<ndims; i++) - skip[i]=(tdiminfo[i].stride-tdiminfo[i].block)*slab[i]; + for(u = 0; u < ndims; u++) + skip[u] = (tdiminfo[u].stride - tdiminfo[u].block) * slab[u]; /* Check if there is a partial row left (with full blocks) */ - if(tmp_count[fast_dim]>0) { + if(tmp_count[fast_dim] > 0) { /* Get number of blocks in fastest dimension */ - H5_ASSIGN_OVERFLOW(fast_dim_count,tdiminfo[fast_dim].count-tmp_count[fast_dim],hsize_t,size_t); + H5_ASSIGN_OVERFLOW(fast_dim_count, tdiminfo[fast_dim].count - tmp_count[fast_dim], hsize_t, size_t); /* Make certain this entire row will fit into buffer */ fast_dim_count=MIN(fast_dim_count,tot_blk_count); @@ -8292,30 +8197,30 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, tmp_count[fast_dim]=0; /* Increment the offset and count for the other dimensions */ - temp_dim=fast_dim-1; - while(temp_dim>=0) { + temp_dim = (int)fast_dim - 1; + while(temp_dim >= 0) { /* Move to the next row in the curent dimension */ offset[temp_dim]++; tmp_block[temp_dim]++; /* If this block is still in the range of blocks to output for the dimension, break out of loop */ - if(tmp_block[temp_dim]<tdiminfo[temp_dim].block) + if(tmp_block[temp_dim] < tdiminfo[temp_dim].block) break; else { /* Move to the next block in the current dimension */ - offset[temp_dim]+=(tdiminfo[temp_dim].stride-tdiminfo[temp_dim].block); + offset[temp_dim] += (tdiminfo[temp_dim].stride - tdiminfo[temp_dim].block); loc += skip[temp_dim]; - tmp_block[temp_dim]=0; + tmp_block[temp_dim] = 0; tmp_count[temp_dim]++; /* If this block is still in the range of blocks to output for the dimension, break out of loop */ if(tmp_count[temp_dim]<tdiminfo[temp_dim].count) break; else { - offset[temp_dim]=tdiminfo[temp_dim].start+sel_off[temp_dim]; + offset[temp_dim] = (hsize_t)((hssize_t)tdiminfo[temp_dim].start + sel_off[temp_dim]); loc += wrap[temp_dim]; - tmp_count[temp_dim]=0; /* reset back to the beginning of the line */ - tmp_block[temp_dim]=0; + tmp_count[temp_dim] = 0; /* reset back to the beginning of the line */ + tmp_block[temp_dim] = 0; } /* end else */ } /* end else */ @@ -8325,13 +8230,13 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, } /* end if */ else { /* Update the offset in the fastest dimension */ - offset[fast_dim]+=(fast_dim_stride*act_blk_count); + offset[fast_dim] += (fast_dim_stride * act_blk_count); } /* end else */ } /* end if */ /* Compute the number of entire rows to read in */ - H5_CHECK_OVERFLOW( tot_blk_count/tdiminfo[fast_dim].count ,hsize_t,size_t); - curr_rows=total_rows=(size_t)(tot_blk_count/tdiminfo[fast_dim].count); + H5_CHECK_OVERFLOW(tot_blk_count / tdiminfo[fast_dim].count, hsize_t, size_t); + curr_rows = total_rows = (size_t)(tot_blk_count / tdiminfo[fast_dim].count); /* Reset copy of number of blocks in fastest dimension */ H5_ASSIGN_OVERFLOW(fast_dim_count,tdiminfo[fast_dim].count,hsize_t,size_t); @@ -8341,14 +8246,14 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, #define DUFF_GUTS \ /* Store the sequence information */ \ - off[curr_seq]=loc; \ - len[curr_seq]=actual_bytes; \ + off[curr_seq] = loc; \ + len[curr_seq] = actual_bytes; \ \ /* Increment sequence count */ \ curr_seq++; \ \ /* Increment information to reflect block just processed */ \ - loc+=fast_dim_buf_off; + loc += fast_dim_buf_off; #ifdef NO_DUFFS_DEVICE /* Loop over all the blocks in the fastest changing dimension */ @@ -8392,30 +8297,30 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, loc += wrap[fast_dim]; /* Increment the offset and count for the other dimensions */ - temp_dim=fast_dim-1; - while(temp_dim>=0) { + temp_dim = (int)fast_dim - 1; + while(temp_dim >= 0) { /* Move to the next row in the curent dimension */ offset[temp_dim]++; tmp_block[temp_dim]++; /* If this block is still in the range of blocks to output for the dimension, break out of loop */ - if(tmp_block[temp_dim]<tdiminfo[temp_dim].block) + if(tmp_block[temp_dim] < tdiminfo[temp_dim].block) break; else { /* Move to the next block in the current dimension */ - offset[temp_dim]+=(tdiminfo[temp_dim].stride-tdiminfo[temp_dim].block); + offset[temp_dim] += (tdiminfo[temp_dim].stride - tdiminfo[temp_dim].block); loc += skip[temp_dim]; - tmp_block[temp_dim]=0; + tmp_block[temp_dim] = 0; tmp_count[temp_dim]++; /* If this block is still in the range of blocks to output for the dimension, break out of loop */ if(tmp_count[temp_dim]<tdiminfo[temp_dim].count) break; else { - offset[temp_dim]=tdiminfo[temp_dim].start+sel_off[temp_dim]; + offset[temp_dim] = (hsize_t)((hssize_t)tdiminfo[temp_dim].start + sel_off[temp_dim]); loc += wrap[temp_dim]; - tmp_count[temp_dim]=0; /* reset back to the beginning of the line */ - tmp_block[temp_dim]=0; + tmp_count[temp_dim] = 0; /* reset back to the beginning of the line */ + tmp_block[temp_dim] = 0; } /* end else */ } /* end else */ @@ -8430,8 +8335,8 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, /* Adjust the number of blocks & elements left to transfer */ /* Decrement number of elements left */ - H5_CHECK_OVERFLOW( actual_elem*(total_rows*tdiminfo[fast_dim].count) ,hsize_t,size_t); - io_left -= (size_t)(actual_elem*(total_rows*tdiminfo[fast_dim].count)); + H5_CHECK_OVERFLOW(actual_elem * (total_rows * tdiminfo[fast_dim].count), hsize_t, size_t); + io_left -= (size_t)(actual_elem * (total_rows * tdiminfo[fast_dim].count)); /* Decrement number of blocks left */ H5_CHECK_OVERFLOW( (total_rows*tdiminfo[fast_dim].count) ,hsize_t,size_t); @@ -8491,20 +8396,20 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, /* Update the iterator with the location we stopped */ /* (Subtract out the selection offset) */ - for(i=0; i<ndims; i++) - iter->u.hyp.off[i] = offset[i] - sel_off[i]; + for(u = 0; u < ndims; u++) + iter->u.hyp.off[u] = (hsize_t)((hssize_t)offset[u] - sel_off[u]); /* Decrement the number of elements left in selection */ - iter->elmt_left-=(nelmts-io_left); + iter->elmt_left -= (nelmts - io_left); } /* end if */ /* Set the number of sequences generated */ - *nseq=curr_seq; + *nseq = curr_seq; /* Set the number of bytes used */ - *nelem=start_io_left-io_left; + *nelem = start_io_left - io_left; - FUNC_LEAVE_NOAPI(SUCCEED); + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S_hyper_get_seq_list_opt() */ diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index d7faa89..0e67af1 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -257,7 +257,6 @@ H5_DLL htri_t H5S_hyper_intersect (H5S_t *space1, H5S_t *space2); #endif /* LATER */ H5_DLL htri_t H5S_hyper_intersect_block (H5S_t *space, hsize_t *start, hsize_t *end); H5_DLL herr_t H5S_hyper_adjust_s(H5S_t *space, const hssize_t *offset); -H5_DLL herr_t H5S_hyper_move(H5S_t *space, const hssize_t *offset); H5_DLL htri_t H5S_hyper_normalize_offset(H5S_t *space, hssize_t *old_offset); H5_DLL herr_t H5S_hyper_denormalize_offset(H5S_t *space, const hssize_t *old_offset); diff --git a/src/H5Torder.c b/src/H5Torder.c index 6c0667b..590a6c7 100644 --- a/src/H5Torder.c +++ b/src/H5Torder.c @@ -18,24 +18,72 @@ * the datatype byte order for the H5T interface. */ +/****************/ +/* Module Setup */ +/****************/ + #define H5T_PACKAGE /*suppress error about including H5Tpkg */ /* Interface initialization */ #define H5_INTERFACE_INIT_FUNC H5T_init_order_interface +/***********/ +/* Headers */ +/***********/ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Iprivate.h" /* IDs */ #include "H5Tpkg.h" /* Datatypes */ + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ +static herr_t H5T_set_order(H5T_t *dtype, H5T_order_t order); + + +/*********************/ +/* Public Variables */ +/*********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + /*-------------------------------------------------------------------------- NAME H5T_init_order_interface -- Initialize interface-specific information USAGE herr_t H5T_init_order_interface() - RETURNS Non-negative on success/Negative on failure DESCRIPTION @@ -57,30 +105,31 @@ H5T_init_order_interface(void) * * Purpose: Returns the byte order of a datatype. * - * Return: Success: A byte order constant - * + * Return: Success: A byte order constant. If the type is compound + * and its members have mixed orders, this function + * returns H5T_ORDER_MIXED. * Failure: H5T_ORDER_ERROR (Negative) * * Programmer: Robb Matzke * Wednesday, January 7, 1998 - * + * *------------------------------------------------------------------------- */ H5T_order_t H5Tget_order(hid_t type_id) { - H5T_t *dt; - H5T_order_t ret_value; + H5T_t *dt; /* Datatype to query */ + H5T_order_t ret_value; /* Return value */ FUNC_ENTER_API(H5Tget_order, H5T_ORDER_ERROR) H5TRACE1("To", "i", type_id); /* Check args */ - if(NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_ORDER_ERROR, "not a datatype") + if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, H5T_ORDER_ERROR, "not a datatype") /* Get order */ - if((ret_value = H5T_get_order(dt)) == H5T_ORDER_ERROR) + if(H5T_ORDER_ERROR == (ret_value = H5T_get_order(dt))) HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, H5T_ORDER_ERROR, "cant't get order for specified datatype") done: @@ -102,20 +151,51 @@ done: *------------------------------------------------------------------------- */ H5T_order_t -H5T_get_order(const H5T_t *dt) +H5T_get_order(const H5T_t *dtype) { - H5T_order_t ret_value; /* Return value */ + H5T_order_t ret_value = H5T_ORDER_NONE; /* Return value */ FUNC_ENTER_NOAPI(H5T_get_order, H5T_ORDER_ERROR) - /*defer to parent*/ - while(dt->shared->parent) - dt = dt->shared->parent; - if(!H5T_IS_ATOMIC(dt->shared)) - HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, H5T_ORDER_ERROR, "operation not defined for specified datatype") + /* Defer to parent */ + while(dtype->shared->parent) + dtype = dtype->shared->parent; + + /* Set order for atomic type. */ + if(H5T_IS_ATOMIC(dtype->shared)) + ret_value = dtype->shared->u.atomic.order; + else { + /* Check for compound datatype */ + if(H5T_COMPOUND == dtype->shared->type) { + H5T_order_t memb_order = H5T_ORDER_NONE; + int nmemb; /* Number of members in compound & enum types */ + int i; /* Local index variable */ + + /* Retrieve the number of members */ + if((nmemb = H5T_get_nmembers(dtype)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_ORDER_ERROR, "can't get number of members from compound data type") + + /* Get order for each compound member type. */ + for(i = 0; i < nmemb; i++) { + /* Get order for member */ + if((memb_order = H5T_get_order(dtype->shared->u.compnd.memb[i].type)) == H5T_ORDER_ERROR) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, H5T_ORDER_ERROR, "can't get order for compound member") - /* Order */ - ret_value = dt->shared->u.atomic.order; + /* Ignore the H5T_ORDER_NONE, write down the first non H5T_ORDER_NONE order. */ + if(memb_order != H5T_ORDER_NONE && ret_value == H5T_ORDER_NONE) + ret_value = memb_order; + + /* If the orders are mixed, stop the loop and report it. + * (H5T_ORDER_NONE is ignored) + */ + if(memb_order != H5T_ORDER_NONE && ret_value != H5T_ORDER_NONE + && memb_order != ret_value) { + ret_value = H5T_ORDER_MIXED; + break; + } /* end if */ + } /* end for */ + } /* end if */ + } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -127,46 +207,103 @@ done: * * Purpose: Sets the byte order for a datatype. * + * Notes: There are some restrictions on this operation: + * 1. For enum type, members shouldn't be defined yet. + * 2. H5T_ORDER_NONE only works for reference and fixed-length + * string. + * 3. For opaque type, the order will be ignored. + * 4. For compound type, all restrictions above apply to the + * members. + * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Wednesday, January 7, 1998 * - * Modifications: - * Robb Matzke, 22 Dec 1998 - * Also works for derived datatypes. - * *------------------------------------------------------------------------- */ herr_t H5Tset_order(hid_t type_id, H5T_order_t order) { - H5T_t *dt = NULL; - herr_t ret_value=SUCCEED; /* Return value */ + H5T_t *dt; /* Datatype to modify */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Tset_order, FAIL) H5TRACE2("e", "iTo", type_id, order); /* Check args */ - if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - if (H5T_STATE_TRANSIENT!=dt->shared->state) - HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only") - if (order < H5T_ORDER_LE || order > H5T_ORDER_NONE) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order") - if (H5T_ENUM==dt->shared->type && dt->shared->u.enumer.nmembs>0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined") - while (dt->shared->parent) - dt = dt->shared->parent; /*defer to parent*/ - if (order == H5T_ORDER_NONE && !(H5T_REFERENCE == dt->shared->type || H5T_IS_FIXED_STRING(dt->shared))) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order") - if (!H5T_IS_ATOMIC(dt->shared)) - HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified datatype") - - /* Commit */ - dt->shared->u.atomic.order = order; + if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype") + if(order < H5T_ORDER_LE || order > H5T_ORDER_NONE || order == H5T_ORDER_MIXED) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "illegal byte order") + if(H5T_STATE_TRANSIENT != dt->shared->state) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype is read-only") + + /* Call internal routine to set the order */ + if(H5T_set_order(dt, order) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "can't set order") done: FUNC_LEAVE_API(ret_value) -} +} /* end H5Tset_order() */ + + +/*------------------------------------------------------------------------- + * Function: H5T_set_order + * + * Purpose: Private function to set the byte order for a datatype. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Raymond Lu + * 13 August 2010 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T_set_order(H5T_t *dtype, H5T_order_t order) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5T_set_order, FAIL) + + if(H5T_ENUM == dtype->shared->type && dtype->shared->u.enumer.nmembs > 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "operation not allowed after enum members are defined") + + /* For derived data type, defer to parent */ + while(dtype->shared->parent) + dtype = dtype->shared->parent; + + /* Check for setting order on inappropriate datatype */ + if(order == H5T_ORDER_NONE && !(H5T_REFERENCE == dtype->shared->type || + H5T_OPAQUE == dtype->shared->type || H5T_IS_FIXED_STRING(dtype->shared))) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "illegal byte order for type") + + /* For atomic data type */ + if(H5T_IS_ATOMIC(dtype->shared)) + dtype->shared->u.atomic.order = order; + else { + /* Check for compound datatype */ + if(H5T_COMPOUND == dtype->shared->type) { + int nmemb; /* Number of members in type */ + int i; /* Local index variable */ + + /* Retrieve the number of fields in the compound datatype */ + if((nmemb = H5T_get_nmembers(dtype)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get number of members from compound data type") + + /* Check for uninitialized compound datatype */ + if(nmemb == 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_UNINITIALIZED, FAIL, "no member is in the compound data type") + + /* Loop through all fields of compound type, setting the order */ + for(i = 0; i < nmemb; i++) + if(H5T_set_order(dtype->shared->u.compnd.memb[i].type, order) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't set order for compound member") + } /* end if */ + } /* end else */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_set_order() */ diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 330a731..d646ef1 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -50,7 +50,8 @@ typedef enum H5T_order_t { H5T_ORDER_LE = 0, /*little endian */ H5T_ORDER_BE = 1, /*bit endian */ H5T_ORDER_VAX = 2, /*VAX mixed endian */ - H5T_ORDER_NONE = 3 /*no particular order (strings, bits,..) */ + H5T_ORDER_MIXED = 3, /*Compound type with mixed member orders */ + H5T_ORDER_NONE = 4 /*no particular order (strings, bits,..) */ /*H5T_ORDER_NONE must be last */ } H5T_order_t; diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 95f4086..f1b1f00 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -100,8 +100,6 @@ H5T_init_vlen_interface(void) * Programmer: Quincey Koziol * Thursday, May 20, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ hid_t @@ -144,8 +142,6 @@ done: * Programmer: Quincey Koziol * Tuesday, November 20, 2001 * - * Modifications: - * *------------------------------------------------------------------------- */ H5T_t * @@ -315,11 +311,6 @@ done: * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ static ssize_t @@ -357,11 +348,6 @@ H5T_vlen_seq_mem_getlen(const void *_vl) * Programmer: Quincey Koziol * Saturday, June 12, 2004 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ static void * @@ -399,11 +385,6 @@ H5T_vlen_seq_mem_getptr(void *_vl) * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -442,11 +423,6 @@ H5T_vlen_seq_mem_isnull(const H5F_t UNUSED *f, void *_vl) * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -489,8 +465,6 @@ H5T_vlen_seq_mem_read(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void *bu * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -548,8 +522,6 @@ done: * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -584,11 +556,6 @@ H5T_vlen_seq_mem_setnull(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ static ssize_t @@ -624,12 +591,6 @@ H5T_vlen_str_mem_getlen(const void *_vl) * Programmer: Quincey Koziol * Saturday, June 12, 2004 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * Added assertion on _vl. - * *------------------------------------------------------------------------- */ static void * @@ -665,11 +626,6 @@ H5T_vlen_str_mem_getptr(void *_vl) * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -702,11 +658,6 @@ H5T_vlen_str_mem_isnull(const H5F_t UNUSED *f, void *_vl) * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -748,8 +699,6 @@ H5T_vlen_str_mem_read(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void *bu * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -797,8 +746,6 @@ done: * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -826,8 +773,6 @@ H5T_vlen_str_mem_setnull(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ static ssize_t @@ -857,8 +802,6 @@ H5T_vlen_disk_getlen(const void *_vl) * Programmer: Quincey Koziol * Saturday, June 12, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -884,8 +827,6 @@ H5T_vlen_disk_getptr(void UNUSED *vl) * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ static htri_t @@ -919,8 +860,6 @@ H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -967,29 +906,24 @@ done: * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * - * Raymond Lu - * Thursday, June 26, 2002 - * Free heap objects storing old data. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ static herr_t -H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED *vl_alloc_info, void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size) +H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED *vl_alloc_info, + void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size) { - uint8_t *vl=(uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg=(uint8_t *)_bg; /*Pointer to the old data hvl_t */ + uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ + uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ H5HG_t hobjid; /* New VL sequence's heap ID */ size_t len; /* Size of new sequence on disk (in bytes) */ - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5T_vlen_disk_write) /* check parameters */ HDassert(vl); - HDassert(seq_len==0 || buf); + HDassert(seq_len == 0 || buf); HDassert(f); /* Free heap object for old data. */ @@ -1004,9 +938,9 @@ H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED INT32DECODE(bg, bg_hobjid.idx); /* Free heap object for old data */ - if(bg_hobjid.addr>0) { + if(bg_hobjid.addr > 0) { /* Free heap object */ - if(H5HG_remove(f, dxpl_id, &bg_hobjid)<0) + if(H5HG_remove(f, dxpl_id, &bg_hobjid) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") } /* end if */ } /* end if */ @@ -1015,13 +949,13 @@ H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED UINT32ENCODE(vl, seq_len); /* Write the VL information to disk (allocates space also) */ - len=(seq_len*base_size); - if(H5HG_insert(f,dxpl_id,len,buf,&hobjid)<0) + len = (seq_len*base_size); + if(H5HG_insert(f, dxpl_id, len, buf, &hobjid) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to write VL information") /* Encode the heap information */ - H5F_addr_encode(f,&vl,hobjid.addr); - INT32ENCODE(vl,hobjid.idx); + H5F_addr_encode(f, &vl, hobjid.addr); + INT32ENCODE(vl, hobjid.idx); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1038,17 +972,15 @@ done: * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) { - uint8_t *vl=(uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg=(uint8_t *)_bg; /*Pointer to the old data hvl_t */ - uint32_t seq_len=0; /* Sequence length */ - herr_t ret_value=SUCCEED; /* Return value */ + uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ + uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ + uint32_t seq_len = 0; /* Sequence length */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5T_vlen_disk_setnull) @@ -1057,7 +989,7 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) HDassert(vl); /* Free heap object for old data. */ - if(bg!=NULL) { + if(bg != NULL) { H5HG_t bg_hobjid; /* "Background" VL info sequence's ID info */ /* Skip the length of the sequence and heap object ID from background data. */ @@ -1068,9 +1000,9 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) INT32DECODE(bg, bg_hobjid.idx); /* Free heap object for old data */ - if(bg_hobjid.addr>0) { + if(bg_hobjid.addr > 0) { /* Free heap object */ - if(H5HG_remove(f, dxpl_id, &bg_hobjid)<0) + if(H5HG_remove(f, dxpl_id, &bg_hobjid) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") } /* end if */ } /* end if */ @@ -1079,8 +1011,8 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) UINT32ENCODE(vl, seq_len); /* Encode the "nil" heap pointer information */ - H5F_addr_encode(f,&vl,(haddr_t)0); - INT32ENCODE(vl,0); + H5F_addr_encode(f, &vl, (haddr_t)0); + INT32ENCODE(vl, 0); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1111,8 +1043,8 @@ done: static herr_t H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, void *free_info) { - unsigned i; /* local index variable */ - herr_t ret_value = SUCCEED; + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5T_vlen_reclaim_recurse) @@ -1127,9 +1059,9 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi void *off; /* offset of field */ /* Calculate the offset member and recurse on it */ - for(i=0; i<dt->shared->u.array.nelem; i++) { - off=((uint8_t *)elem)+i*(dt->shared->parent->shared->size); - if(H5T_vlen_reclaim_recurse(off,dt->shared->parent,free_func,free_info)<0) + for(u = 0; u < dt->shared->u.array.nelem; u++) { + off = ((uint8_t *)elem) + u * (dt->shared->parent->shared->size); + if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free array element") } /* end for */ } /* end if */ @@ -1137,14 +1069,14 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_COMPOUND: /* Check each field and recurse on VL, compound, enum or array ones */ - for (i=0; i<dt->shared->u.compnd.nmembs; i++) { + for(u = 0; u < dt->shared->u.compnd.nmembs; u++) { /* Recurse if it's VL, compound, enum or array */ - if(H5T_IS_COMPLEX(dt->shared->u.compnd.memb[i].type->shared->type)) { + if(H5T_IS_COMPLEX(dt->shared->u.compnd.memb[u].type->shared->type)) { void *off; /* offset of field */ /* Calculate the offset member and recurse on it */ - off=((uint8_t *)elem)+dt->shared->u.compnd.memb[i].offset; - if(H5T_vlen_reclaim_recurse(off,dt->shared->u.compnd.memb[i].type,free_func,free_info)<0) + off = ((uint8_t *)elem) + dt->shared->u.compnd.memb[u].offset; + if(H5T_vlen_reclaim_recurse(off, dt->shared->u.compnd.memb[u].type, free_func, free_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free compound field") } /* end if */ } /* end for */ @@ -1152,8 +1084,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_VLEN: /* Recurse on the VL information if it's VL, compound, enum or array, then free VL sequence */ - if(dt->shared->u.vlen.type==H5T_VLEN_SEQUENCE) { - hvl_t *vl=(hvl_t *)elem; /* Temp. ptr to the vl info */ + if(dt->shared->u.vlen.type == H5T_VLEN_SEQUENCE) { + hvl_t *vl = (hvl_t *)elem; /* Temp. ptr to the vl info */ /* Check if there is anything actually in this sequence */ if(vl->len!=0) { @@ -1162,24 +1094,24 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi void *off; /* offset of field */ /* Calculate the offset of each array element and recurse on it */ - while(vl->len>0) { - off=((uint8_t *)vl->p)+(vl->len-1)*dt->shared->parent->shared->size; - if(H5T_vlen_reclaim_recurse(off,dt->shared->parent,free_func,free_info)<0) + while(vl->len > 0) { + off = ((uint8_t *)vl->p) + (vl->len - 1) * dt->shared->parent->shared->size; + if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free VL element") vl->len--; } /* end while */ } /* end if */ /* Free the VL sequence */ - if(free_func!=NULL) - (*free_func)(vl->p,free_info); + if(free_func != NULL) + (*free_func)(vl->p, free_info); else H5MM_xfree(vl->p); } /* end if */ - } else if(dt->shared->u.vlen.type==H5T_VLEN_STRING) { + } else if(dt->shared->u.vlen.type == H5T_VLEN_STRING) { /* Free the VL string */ - if(free_func!=NULL) - (*free_func)(*(char **)elem,free_info); + if(free_func != NULL) + (*free_func)(*(char **)elem, free_info); else H5MM_xfree(*(char **)elem); } else { @@ -1226,7 +1158,7 @@ H5T_vlen_reclaim(void *elem, hid_t type_id, unsigned UNUSED ndim, const hsize_t { H5T_vlen_alloc_info_t *vl_alloc_info = (H5T_vlen_alloc_info_t *)op_data; /* VL allocation info from iterator */ H5T_t *dt; - herr_t ret_value; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5T_vlen_reclaim, FAIL) @@ -1235,11 +1167,12 @@ H5T_vlen_reclaim(void *elem, hid_t type_id, unsigned UNUSED ndim, const hsize_t HDassert(H5I_DATATYPE == H5I_get_type(type_id)); /* Check args */ - if (NULL==(dt=H5I_object_verify(type_id,H5I_DATATYPE))) + if(NULL == (dt = H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Pull the free function and free info pointer out of the op_data and call the recurse datatype free function */ - ret_value=H5T_vlen_reclaim_recurse(elem,dt,vl_alloc_info->free_func,vl_alloc_info->free_info); + if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info->free_func, vl_alloc_info->free_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") done: FUNC_LEAVE_NOAPI(ret_value) @@ -1289,13 +1222,13 @@ H5T_vlen_get_alloc_info(hid_t dxpl_id, H5T_vlen_alloc_info_t **vl_alloc_info) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset transfer property list") /* Get the allocation functions & information */ - if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_NAME,&(*vl_alloc_info)->alloc_func)<0) + if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_NAME,&(*vl_alloc_info)->alloc_func) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_INFO_NAME,&(*vl_alloc_info)->alloc_info)<0) + if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_INFO_NAME,&(*vl_alloc_info)->alloc_info) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_FREE_NAME,&(*vl_alloc_info)->free_func)<0) + if (H5P_get(plist,H5D_XFER_VLEN_FREE_NAME,&(*vl_alloc_info)->free_func) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_FREE_INFO_NAME,&(*vl_alloc_info)->free_info)<0) + if (H5P_get(plist,H5D_XFER_VLEN_FREE_INFO_NAME,&(*vl_alloc_info)->free_info) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") } /* end else */ @@ -1318,8 +1251,6 @@ done: * Programmer: Mike McGreevy * May 11, 2010 * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t @@ -1335,12 +1266,14 @@ H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt, hid_t dxpl_id) FUNC_ENTER_NOAPI(H5T_vlen_reclaim_elmt, FAIL) /* Get VL allocation info */ - if (H5T_vlen_get_alloc_info(dxpl_id, &vl_alloc_info) < 0) + if(H5T_vlen_get_alloc_info(dxpl_id, &vl_alloc_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info") /* Recurse on buffer to free dynamic fields */ - ret_value = H5T_vlen_reclaim_recurse(elem,dt,vl_alloc_info->free_func,vl_alloc_info->free_info); + if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info->free_func, vl_alloc_info->free_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") done: FUNC_LEAVE_NOAPI(ret_value) } /* H5T_vlen_reclaim_elmt */ + @@ -498,7 +498,7 @@ H5Z_prelude_callback(const H5O_pline_t *pline, hid_t dcpl_id, hid_t type_id, { H5Z_class2_t *fclass; /* Individual filter information */ size_t u; /* Local index variable */ - herr_t ret_value = SUCCEED; /* Return value */ + htri_t ret_value = TRUE; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5Z_prelude_callback) @@ -526,17 +526,16 @@ H5Z_prelude_callback(const H5O_pline_t *pline, hid_t dcpl_id, hid_t type_id, /* Check if there is a "can apply" callback */ if(fclass->can_apply) { /* Make callback to filter's "can apply" function */ - herr_t status = (fclass->can_apply)(dcpl_id, type_id, space_id); + htri_t status = (fclass->can_apply)(dcpl_id, type_id, space_id); - /* Check return value */ - if(status <= 0) { - /* Indicate filter can't apply to this combination of parameters */ - if(status == 0) - HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "filter parameters not appropriate") - /* Indicate error during filter callback */ - else - HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "error during user callback") - } /* end if */ + /* Indicate error during filter callback */ + if(status < 0) + HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "error during user callback") + + /* Indicate filter can't apply to this combination of parameters. + * If the filter is NOT optional, returns failure. */ + if(status == FALSE && !(pline->filter[u].flags & H5Z_FLAG_OPTIONAL)) + HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "filter parameters not appropriate") } /* end if */ break; diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c index c490720..598aa97 100644 --- a/src/H5Zdeflate.c +++ b/src/H5Zdeflate.c @@ -28,8 +28,11 @@ #ifdef H5_HAVE_FILTER_DEFLATE -#ifdef H5_HAVE_ZLIB_H -# include "zlib.h" +#if defined(H5_HAVE_ZLIB_H) && !defined(H5_ZLIB_HEADER) +# define H5_ZLIB_HEADER "zlib.h" +#endif +#if defined(H5_ZLIB_HEADER) +# include H5_ZLIB_HEADER /* "zlib.h" */ #endif /* Local function prototypes */ @@ -98,9 +101,9 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, /* Set the uncompression parameters */ HDmemset(&z_strm, 0, sizeof(z_strm)); - z_strm.next_in = *buf; + z_strm.next_in = (Bytef *)*buf; H5_ASSIGN_OVERFLOW(z_strm.avail_in,nbytes,size_t,unsigned); - z_strm.next_out = outbuf; + z_strm.next_out = (Bytef *)outbuf; H5_ASSIGN_OVERFLOW(z_strm.avail_out,nalloc,size_t,unsigned); /* Initialize the uncompression routines */ @@ -152,7 +155,7 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, /* Finish uncompressing the stream */ (void)inflateEnd(&z_strm); - } + } /* end if */ else { /* * Output; compress but fail if the result would be larger than the @@ -169,19 +172,20 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, H5_ASSIGN_OVERFLOW(aggression,cd_values[0],unsigned,int); /* Allocate output (compressed) buffer */ - if (NULL==(z_dst=outbuf=H5MM_malloc(z_dst_nbytes))) + if(NULL == (outbuf = H5MM_malloc(z_dst_nbytes))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate deflate destination buffer") + z_dst = (Bytef *)outbuf; /* Perform compression from the source to the destination buffer */ - status = compress2 (z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression); + status = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression); /* Check for various zlib errors */ - if (Z_BUF_ERROR==status) + if(Z_BUF_ERROR == status) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "overflow") - else if (Z_MEM_ERROR==status) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, 0, "deflate memory error") - else if (Z_OK!=status) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, 0, "other deflate error") + else if(Z_MEM_ERROR == status) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "deflate memory error") + else if(Z_OK != status) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "other deflate error") /* Successfully uncompressed the buffer */ else { /* Free the input buffer */ @@ -192,8 +196,8 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, outbuf = NULL; *buf_size = nbytes; ret_value = z_dst_nbytes; - } - } + } /* end else */ + } /* end else */ done: if(outbuf) diff --git a/src/H5Znbit.c b/src/H5Znbit.c index 8f785a2..bcdd549 100644 --- a/src/H5Znbit.c +++ b/src/H5Znbit.c @@ -38,7 +38,7 @@ typedef struct { } parms_atomic; /* Local function prototypes */ -static herr_t H5Z_can_apply_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id); +static htri_t H5Z_can_apply_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id); static herr_t H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id); static size_t H5Z_filter_nbit(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf); @@ -129,11 +129,11 @@ static unsigned parms_index = 0; * *------------------------------------------------------------------------- */ -static herr_t +static htri_t H5Z_can_apply_nbit(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED space_id) { const H5T_t *type; /* Datatype */ - herr_t ret_value = TRUE; /* Return value */ + htri_t ret_value = TRUE; /* Return value */ FUNC_ENTER_NOAPI(H5Z_can_apply_nbit, FAIL) diff --git a/src/H5Zpublic.h b/src/H5Zpublic.h index 44d2bbb..5d9b5ed 100644 --- a/src/H5Zpublic.h +++ b/src/H5Zpublic.h @@ -158,7 +158,7 @@ extern "C" { * The "can_apply" callback returns positive a valid combination, zero for an * invalid combination and negative for an error. */ -typedef herr_t (*H5Z_can_apply_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id); +typedef htri_t (*H5Z_can_apply_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id); /* * After the "can_apply" callbacks are checked for new datasets, the "set_local" diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 5737702..eb3c6e6 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -41,7 +41,7 @@ enum H5Z_scaleoffset_t {t_bad=0, t_uchar=1, t_ushort, t_uint, t_ulong, t_ulong_l /* Local function prototypes */ static double H5Z_scaleoffset_rnd(double val); -static herr_t H5Z_can_apply_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id); +static htri_t H5Z_can_apply_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id); static enum H5Z_scaleoffset_t H5Z_scaleoffset_get_type(unsigned dtype_class, unsigned dtype_size, unsigned dtype_sign); static herr_t H5Z_scaleoffset_set_parms_fillval(H5P_genplist_t *dcpl_plist, @@ -611,13 +611,13 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ * *------------------------------------------------------------------------- */ -static herr_t +static htri_t H5Z_can_apply_scaleoffset(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED space_id) { const H5T_t *type; /* Datatype */ H5T_class_t dtype_class; /* Datatype's class */ H5T_order_t dtype_order; /* Datatype's endianness order */ - herr_t ret_value = TRUE; /* Return value */ + htri_t ret_value = TRUE; /* Return value */ FUNC_ENTER_NOAPI(H5Z_can_apply_scaleoffset, FAIL) @@ -640,9 +640,9 @@ H5Z_can_apply_scaleoffset(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED spac /* Range check datatype's endianness order */ if(dtype_order != H5T_ORDER_LE && dtype_order != H5T_ORDER_BE) - HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype endianness order") + HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FALSE, "bad datatype endianness order") } else - HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "datatype class not supported by scaleoffset") + HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FALSE, "datatype class not supported by scaleoffset") done: FUNC_LEAVE_NOAPI(ret_value) @@ -806,6 +806,11 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id) if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") +#ifdef H5_CLEAR_MEMORY + /* Initialize the parameters to a known state */ + HDmemset(cd_values, 0, sizeof(cd_values)); +#endif /* H5_CLEAR_MEMORY */ + /* Get the filter's current parameters */ if(H5P_get_filter_by_id(dcpl_plist, H5Z_FILTER_SCALEOFFSET, &flags, &cd_nelmts, cd_values, (size_t)0, NULL, NULL) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get scaleoffset parameters") @@ -1182,6 +1187,14 @@ H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_value for(i = 0; i < sizeof(unsigned long long); i++) ((unsigned char *)outbuf)[5+i] = (unsigned char)((minval & ((unsigned long long)0xff << i*8)) >> i*8); +#ifdef H5_CLEAR_MEMORY + /* Zero out remaining, unused bytes */ + /* (Looks like an error in the original determination of how many + * bytes would be needed for parameters. - QAK, 2010/08/19) + */ + HDmemset(outbuf + 13, 0, (size_t)8); +#endif /* H5_CLEAR_MEMORY */ + /* special case: minbits equal to full precision */ if(minbits == p.size * 8) { HDmemcpy(outbuf + buf_offset, *buf, nbytes); diff --git a/src/H5Zszip.c b/src/H5Zszip.c index 5da92ac..52f5e11 100644 --- a/src/H5Zszip.c +++ b/src/H5Zszip.c @@ -34,7 +34,7 @@ #endif /* Local function prototypes */ -static herr_t H5Z_can_apply_szip(hid_t dcpl_id, hid_t type_id, hid_t space_id); +static htri_t H5Z_can_apply_szip(hid_t dcpl_id, hid_t type_id, hid_t space_id); static herr_t H5Z_set_local_szip(hid_t dcpl_id, hid_t type_id, hid_t space_id); static size_t H5Z_filter_szip (unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf); @@ -76,13 +76,13 @@ H5Z_class2_t H5Z_SZIP[1] = {{ * *------------------------------------------------------------------------- */ -static herr_t +static htri_t H5Z_can_apply_szip(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED space_id) { const H5T_t *type; /* Datatype */ unsigned dtype_size; /* Datatype's size (in bits) */ H5T_order_t dtype_order; /* Datatype's endianness order */ - herr_t ret_value = TRUE; /* Return value */ + htri_t ret_value = TRUE; /* Return value */ FUNC_ENTER_NOAPI(H5Z_can_apply_szip, FAIL) diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index 762b316..8028123 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -555,7 +555,7 @@ static H5Z_node * H5Z_parse_expression(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) { H5Z_node *expr; - void* ret_value; + H5Z_node *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5Z_parse_expression) @@ -566,7 +566,7 @@ H5Z_parse_expression(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) current = H5Z_get_token(current); - switch (current->tok_type) { + switch(current->tok_type) { case H5Z_XFORM_PLUS: new_node = H5Z_new_node(H5Z_XFORM_PLUS); @@ -612,6 +612,13 @@ H5Z_parse_expression(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers) case H5Z_XFORM_END: HGOTO_DONE(expr) + case H5Z_XFORM_ERROR: + case H5Z_XFORM_INTEGER: + case H5Z_XFORM_FLOAT: + case H5Z_XFORM_SYMBOL: + case H5Z_XFORM_MULT: + case H5Z_XFORM_DIVIDE: + case H5Z_XFORM_LPAREN: default: H5Z_xform_destroy_parse_tree(expr); HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "Error parsing data transform expression") @@ -1101,54 +1108,69 @@ done: static hid_t H5Z_xform_find_type(const H5T_t* type) { - hid_t ret_value = SUCCEED; + H5T_t *tmp; /* Temporary datatype */ + hid_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5Z_xform_find_type) HDassert(type); /* Check for SHORT type */ - if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_SHORT, H5I_DATATYPE), FALSE)) == 0) + if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_SHORT, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_SHORT) /* Check for INT type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_INT, H5I_DATATYPE), FALSE)) == 0) - HGOTO_DONE(H5T_NATIVE_INT) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_INT, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) + HGOTO_DONE(H5T_NATIVE_INT) /* Check for LONG type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_LONG, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_LONG, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_LONG) /* Check for LONGLONG type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_LLONG, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_LLONG, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_LLONG) /* Check for UCHAR type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_UCHAR, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_UCHAR, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_UCHAR) /* Check for CHAR type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_CHAR, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_CHAR, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_CHAR) /* Check for SCHAR type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_SCHAR, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_SCHAR, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_SCHAR) /* Check for USHORT type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_USHORT, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_USHORT, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_USHORT) /* Check for UINT type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_UINT, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_UINT, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_UINT) /* Check for ULONG type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_ULONG, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_ULONG, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_ULONG) /* Check for ULONGLONG type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_ULLONG, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_ULLONG, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_ULLONG) /* Check for FLOAT type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_FLOAT, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_FLOAT, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_FLOAT) /* Check for DOUBLE type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_DOUBLE, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_DOUBLE, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_DOUBLE) #if H5_SIZEOF_LONG_DOUBLE !=0 /* Check for LONGDOUBLE type */ - else if((H5T_cmp(type, (const H5T_t *)H5I_object_verify(H5T_NATIVE_LDOUBLE, H5I_DATATYPE), FALSE)) == 0) + else if((tmp = (H5T_t *)H5I_object_verify(H5T_NATIVE_LDOUBLE, H5I_DATATYPE)) + && 0 == H5T_cmp(type, tmp, FALSE)) HGOTO_DONE(H5T_NATIVE_LDOUBLE) #endif else diff --git a/src/H5config.h.in b/src/H5config.h.in index 5c9e1f2..3283893 100644 --- a/src/H5config.h.in +++ b/src/H5config.h.in @@ -120,18 +120,21 @@ /* Define to 1 if you have the `frexpl' function. */ #undef HAVE_FREXPL -/* Define to 1 if you have the `fseek64' function. */ -#undef HAVE_FSEEK64 - /* Define to 1 if you have the `fseeko' function. */ #undef HAVE_FSEEKO +/* Define to 1 if you have the `fseeko64' function. */ +#undef HAVE_FSEEKO64 + /* Define to 1 if you have the `fstat64' function. */ #undef HAVE_FSTAT64 /* Define to 1 if you have the `ftello' function. */ #undef HAVE_FTELLO +/* Define to 1 if you have the `ftello64' function. */ +#undef HAVE_FTELLO64 + /* Define to 1 if you have the `ftruncate64' function. */ #undef HAVE_FTRUNCATE64 diff --git a/src/H5dbg.c b/src/H5dbg.c index 196ed5b..632ac08 100644 --- a/src/H5dbg.c +++ b/src/H5dbg.c @@ -78,8 +78,8 @@ *------------------------------------------------------------------------- */ herr_t -H5_buffer_dump(FILE *stream, int indent, uint8_t *buf, - uint8_t *marker, size_t buf_offset, size_t buf_size) +H5_buffer_dump(FILE *stream, int indent, const uint8_t *buf, + const uint8_t *marker, size_t buf_offset, size_t buf_size) { size_t u, v; /* Local index variable */ @@ -102,7 +102,7 @@ H5_buffer_dump(FILE *stream, int indent, uint8_t *buf, for(u = 0; u < buf_size; u += 16) { uint8_t c; - HDfprintf(stream, "%*s %8d: ", indent, "", u); + HDfprintf(stream, "%*s %8d: ", indent, "", u + buf_offset); /* Print the hex values */ for(v = 0; v < 16; v++) { @@ -119,6 +119,7 @@ H5_buffer_dump(FILE *stream, int indent, uint8_t *buf, if(7 == v) HDfputc(' ', stream); } /* end for */ + HDfputc(' ', stream); /* Print the character values */ for(v = 0; v < 16; v++) { @@ -133,6 +134,8 @@ H5_buffer_dump(FILE *stream, int indent, uint8_t *buf, HDfputc('.', stream); } /* end else */ } /* end if */ + if(7 == v) + HDfputc(' ', stream); } /* end for */ HDfputc('\n', stream); diff --git a/src/H5private.h b/src/H5private.h index 5b8d123..3875fb3 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -480,8 +480,9 @@ typedef struct { * function (or any other non-HDF5 function) in the source! */ - /* Use platform-specific versions if necessary */ -#include "H5win32defs.h" +/* Put all platform-specific definitions in the following file */ +/* so that the following definitions are platform free. */ +#include "H5win32defs.h" /* For Windows-specific definitions */ #ifndef HDabort #define HDabort() abort() @@ -912,11 +913,14 @@ H5_DLL int HDfprintf (FILE *stream, const char *fmt, ...); #ifndef HDlongjmp #define HDlongjmp(J,N) longjmp(J,N) #endif /* HDlongjmp */ +/* HDlseek and HDoff_t must be defined together for consistency. */ #ifndef HDlseek #ifdef H5_HAVE_LSEEK64 - #define HDlseek(F,O,W) lseek64(F,O,W) + #define HDlseek(F,O,W) lseek64(F,O,W) + #define HDoff_t off64_t #else - #define HDlseek(F,O,W) lseek(F,O,W) + #define HDlseek(F,O,W) lseek(F,O,W) + #define HDoff_t off_t #endif #endif /* HDlseek */ #ifndef HDmalloc @@ -2338,8 +2342,8 @@ H5_DLL uint32_t H5_hash_string(const char *str); H5_DLL herr_t H5_build_extpath(const char *, char ** /*out*/ ); /* Functions for debugging */ -H5_DLL herr_t H5_buffer_dump(FILE *stream, int indent, uint8_t *buf, - uint8_t *marker, size_t buf_offset, size_t buf_size); +H5_DLL herr_t H5_buffer_dump(FILE *stream, int indent, const uint8_t *buf, + const uint8_t *marker, size_t buf_offset, size_t buf_size); #endif /* _H5private_H */ diff --git a/src/H5win32defs.h b/src/H5win32defs.h index 141ec82..d478e4c 100644 --- a/src/H5win32defs.h +++ b/src/H5win32defs.h @@ -56,6 +56,12 @@ typedef __int64 h5_stat_size_t; #endif /* H5_HAVE_GETTIMEOFDAY */ #define HDgetdrive() _getdrive() #define HDlseek(F,O,W) _lseeki64(F,O,W) +#if !defined(__MWERKS__) +# /*MSVC*/ +# define HDoff_t __int64 +#else +# define HDoff_t off_t +#endif #define HDmemset(X,C,Z) memset((void*)(X),C,Z) #define HDmkdir(S,M) _mkdir(S) #define HDopen(S,F,M) _open(S,F|_O_BINARY,M) diff --git a/src/Makefile.am b/src/Makefile.am index e3f3cdc..5dd6b36 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -72,7 +72,7 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5HFspace.c H5HFstat.c H5HFtest.c H5HFtiny.c \ H5HG.c H5HGcache.c H5HGdbg.c \ H5HL.c H5HLcache.c H5HLdbg.c H5HLint.c \ - H5HP.c H5I.c H5L.c H5Lexternal.c H5lib_settings.c \ + H5HP.c H5I.c H5Itest.c H5L.c H5Lexternal.c H5lib_settings.c \ H5MF.c H5MFaggr.c H5MFdbg.c H5MFsection.c \ H5MM.c H5MP.c H5MPtest.c \ H5O.c H5Oainfo.c H5Oalloc.c H5Oattr.c \ diff --git a/src/Makefile.in b/src/Makefile.in index 14a17bf..1fa47ad 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -123,8 +123,8 @@ am_libhdf5_la_OBJECTS = H5.lo H5checksum.lo H5dbg.lo H5system.lo \ H5HFdtable.lo H5HFhdr.lo H5HFhuge.lo H5HFiblock.lo H5HFiter.lo \ H5HFman.lo H5HFsection.lo H5HFspace.lo H5HFstat.lo H5HFtest.lo \ H5HFtiny.lo H5HG.lo H5HGcache.lo H5HGdbg.lo H5HL.lo \ - H5HLcache.lo H5HLdbg.lo H5HLint.lo H5HP.lo H5I.lo H5L.lo \ - H5Lexternal.lo H5lib_settings.lo H5MF.lo H5MFaggr.lo \ + H5HLcache.lo H5HLdbg.lo H5HLint.lo H5HP.lo H5I.lo H5Itest.lo \ + H5L.lo H5Lexternal.lo H5lib_settings.lo H5MF.lo H5MFaggr.lo \ H5MFdbg.lo H5MFsection.lo H5MM.lo H5MP.lo H5MPtest.lo H5O.lo \ H5Oainfo.lo H5Oalloc.lo H5Oattr.lo H5Oattribute.lo H5Obogus.lo \ H5Obtreek.lo H5Ocache.lo H5Ochunk.lo H5Ocont.lo H5Ocopy.lo \ @@ -494,7 +494,7 @@ libhdf5_la_SOURCES = H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5HFspace.c H5HFstat.c H5HFtest.c H5HFtiny.c \ H5HG.c H5HGcache.c H5HGdbg.c \ H5HL.c H5HLcache.c H5HLdbg.c H5HLint.c \ - H5HP.c H5I.c H5L.c H5Lexternal.c H5lib_settings.c \ + H5HP.c H5I.c H5Itest.c H5L.c H5Lexternal.c H5lib_settings.c \ H5MF.c H5MFaggr.c H5MFdbg.c H5MFsection.c \ H5MM.c H5MP.c H5MPtest.c \ H5O.c H5Oainfo.c H5Oalloc.c H5Oattr.c \ @@ -811,6 +811,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5HLint.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5HP.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5I.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Itest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5L.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Lexternal.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5MF.Plo@am__quote@ |