summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2016-03-08 02:49:13 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2016-03-08 02:49:13 (GMT)
commitc3ad0376099f3ab9c688eb56f243d48ec90a39c3 (patch)
tree37ffd00acd74beee9df2447d8095ed5e8366124f
parent6a59ea16edca6a7998aa6833d566786cec34730d (diff)
downloadhdf5-c3ad0376099f3ab9c688eb56f243d48ec90a39c3.zip
hdf5-c3ad0376099f3ab9c688eb56f243d48ec90a39c3.tar.gz
hdf5-c3ad0376099f3ab9c688eb56f243d48ec90a39c3.tar.bz2
[svn-r29331] Merge of r29150 from trunk
segfault on corrupted file fix Tested on: 64-bit Ubuntu 15.10 w/ gcc 5.2.1 autotools serial
-rw-r--r--src/H5Abtree2.c33
-rw-r--r--src/H5B2.c58
-rw-r--r--src/H5B2int.c70
-rw-r--r--src/H5B2pkg.h4
-rw-r--r--src/H5B2private.h2
-rw-r--r--src/H5B2test.c25
-rw-r--r--src/H5C.c10
-rw-r--r--src/H5Dbtree2.c8
-rw-r--r--src/H5Gbtree2.c45
-rw-r--r--src/H5HFbtree2.c52
-rw-r--r--src/H5SM.c54
-rw-r--r--src/H5SMmessage.c39
-rw-r--r--src/H5SMpkg.h2
-rw-r--r--test/dsets.c90
14 files changed, 288 insertions, 204 deletions
diff --git a/src/H5Abtree2.c b/src/H5Abtree2.c
index 716ad4a..a9c77d2 100644
--- a/src/H5Abtree2.c
+++ b/src/H5Abtree2.c
@@ -80,7 +80,7 @@ typedef struct H5A_fh_ud_cmp_t {
/* v2 B-tree driver callbacks for 'creation order' index */
static herr_t H5A__dense_btree2_corder_store(void *native, const void *udata);
-static herr_t H5A__dense_btree2_corder_compare(const void *rec1, const void *rec2);
+static herr_t H5A__dense_btree2_corder_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5A__dense_btree2_corder_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5A__dense_btree2_corder_decode(const uint8_t *raw, void *native,
@@ -90,7 +90,7 @@ static herr_t H5A__dense_btree2_corder_debug(FILE *stream, int indent, int fwidt
/* v2 B-tree driver callbacks for 'name' index */
static herr_t H5A__dense_btree2_name_store(void *native, const void *udata);
-static herr_t H5A__dense_btree2_name_compare(const void *rec1, const void *rec2);
+static herr_t H5A__dense_btree2_name_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5A__dense_btree2_name_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5A__dense_btree2_name_decode(const uint8_t *raw, void *native,
@@ -245,13 +245,13 @@ H5A__dense_btree2_name_store(void *_nrecord, const void *_udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5A__dense_btree2_name_compare(const void *_bt2_udata, const void *_bt2_rec)
+H5A__dense_btree2_name_compare(const void *_bt2_udata, const void *_bt2_rec, int *result)
{
const H5A_bt2_ud_common_t *bt2_udata = (const H5A_bt2_ud_common_t *)_bt2_udata;
const H5A_dense_bt2_name_rec_t *bt2_rec = (const H5A_dense_bt2_name_rec_t *)_bt2_rec;
- herr_t ret_value = FAIL; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_STATIC_NOERR
+ FUNC_ENTER_STATIC
/* Sanity check */
HDassert(bt2_udata);
@@ -259,13 +259,12 @@ H5A__dense_btree2_name_compare(const void *_bt2_udata, const void *_bt2_rec)
/* Check hash value */
if(bt2_udata->name_hash < bt2_rec->hash)
- ret_value = (-1);
+ *result = (-1);
else if(bt2_udata->name_hash > bt2_rec->hash)
- ret_value = 1;
+ *result = 1;
else {
H5A_fh_ud_cmp_t fh_udata; /* User data for fractal heap 'op' callback */
H5HF_t *fheap; /* Fractal heap handle to use for finding object */
- herr_t status; /* Status from fractal heap 'op' routine */
/* Sanity check */
HDassert(bt2_udata->name_hash == bt2_rec->hash);
@@ -290,13 +289,14 @@ H5A__dense_btree2_name_compare(const void *_bt2_udata, const void *_bt2_rec)
HDassert(fheap);
/* Check if the user's attribute and the B-tree's attribute have the same name */
- status = H5HF_op(fheap, bt2_udata->dxpl_id, &bt2_rec->id, H5A__dense_fh_name_cmp, &fh_udata);
- HDassert(status >= 0);
+ if(H5HF_op(fheap, bt2_udata->dxpl_id, &bt2_rec->id, H5A__dense_fh_name_cmp, &fh_udata) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
/* Callback will set comparison value */
- ret_value = fh_udata.cmp;
+ *result = fh_udata.cmp;
} /* end else */
+done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5A__dense_btree2_name_compare() */
@@ -437,11 +437,10 @@ H5A__dense_btree2_corder_store(void *_nrecord, const void *_udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5A__dense_btree2_corder_compare(const void *_bt2_udata, const void *_bt2_rec)
+H5A__dense_btree2_corder_compare(const void *_bt2_udata, const void *_bt2_rec, int *result)
{
const H5A_bt2_ud_common_t *bt2_udata = (const H5A_bt2_ud_common_t *)_bt2_udata;
const H5A_dense_bt2_corder_rec_t *bt2_rec = (const H5A_dense_bt2_corder_rec_t *)_bt2_rec;
- herr_t ret_value = FAIL; /* Return value */
FUNC_ENTER_STATIC_NOERR
@@ -451,13 +450,13 @@ H5A__dense_btree2_corder_compare(const void *_bt2_udata, const void *_bt2_rec)
/* Check creation order value */
if(bt2_udata->corder < bt2_rec->corder)
- ret_value = -1;
+ *result = -1;
else if(bt2_udata->corder > bt2_rec->corder)
- ret_value = 1;
+ *result = 1;
else
- ret_value = 0;
+ *result = 0;
- FUNC_LEAVE_NOAPI(ret_value)
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5A__dense_btree2_corder_compare() */
diff --git a/src/H5B2.c b/src/H5B2.c
index 463a50a..ff27d87 100644
--- a/src/H5B2.c
+++ b/src/H5B2.c
@@ -508,22 +508,26 @@ H5B2_find(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_found_t op,
* find candidates or avoid further searching.
*/
if(hdr->min_native_rec != NULL) {
- if((cmp = (hdr->cls->compare)(udata, hdr->min_native_rec)) < 0)
- HGOTO_DONE(FALSE) /* Less than the least record--not found */
- else if(cmp == 0) { /* Record is found */
- if(op && (op)(hdr->min_native_rec, op_data) < 0)
+ if((hdr->cls->compare)(udata, hdr->min_native_rec, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ if(cmp < 0)
+ HGOTO_DONE(FALSE) /* Less than the least record--not found */
+ else if(cmp == 0) { /* Record is found */
+ if(op && (op)(hdr->min_native_rec, op_data) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "'found' callback failed for B-tree find operation")
- HGOTO_DONE(TRUE)
- } /* end if */
+ HGOTO_DONE(TRUE)
+ } /* end if */
} /* end if */
if(hdr->max_native_rec != NULL) {
- if((cmp = (hdr->cls->compare)(udata, hdr->max_native_rec)) > 0)
- HGOTO_DONE(FALSE) /* Greater than the greatest record--not found */
- else if(cmp == 0) { /* Record is found */
- if(op && (op)(hdr->max_native_rec, op_data) < 0)
+ if((hdr->cls->compare)(udata, hdr->max_native_rec, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ if(cmp > 0)
+ HGOTO_DONE(FALSE) /* Less than the least record--not found */
+ else if(cmp == 0) { /* Record is found */
+ if(op && (op)(hdr->max_native_rec, op_data) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "'found' callback failed for B-tree find operation")
- HGOTO_DONE(TRUE)
- } /* end if */
+ HGOTO_DONE(TRUE)
+ } /* end if */
} /* end if */
/* Current depth of the tree */
@@ -552,10 +556,15 @@ H5B2_find(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_found_t op,
} /* end if */
/* Locate node pointer for child */
- cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native,
+ udata, &idx, &cmp) < 0) {
+ /* Unlock current node before failing */
+ H5AC_unprotect(hdr->f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET);
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ } /* end if */
+
if(cmp > 0)
idx++;
-
if(cmp != 0) {
/* Get node pointer for next node to search */
next_node_ptr=internal->node_ptrs[idx];
@@ -626,7 +635,12 @@ H5B2_find(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_found_t op,
} /* end if */
/* Locate record */
- cmp = H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native,
+ udata, &idx, &cmp) < 0) {
+ /* unlock current node before failing */
+ H5AC_unprotect(hdr->f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET);
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ }
if(cmp != 0) {
/* Unlock leaf node */
@@ -1207,7 +1221,13 @@ H5B2_modify(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_modify_t op,
} /* end if */
/* Locate node pointer for child */
- cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native,
+ udata, &idx, &cmp) < 0) {
+ /* Unlock current node */
+ H5AC_unprotect(hdr->f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET);
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ }
+
if(cmp > 0)
idx++;
@@ -1290,7 +1310,11 @@ H5B2_modify(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_modify_t op,
} /* end if */
/* Locate record */
- cmp = H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native,
+ udata, &idx, &cmp) < 0) {
+ H5AC_unprotect(hdr->f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET);
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ }
if(cmp != 0) {
/* Unlock leaf node */
diff --git a/src/H5B2int.c b/src/H5B2int.c
index f8b5223..3e3c487 100644
--- a/src/H5B2int.c
+++ b/src/H5B2int.c
@@ -139,28 +139,33 @@ H5FL_SEQ_EXTERN(H5B2_node_info_t);
*
*-------------------------------------------------------------------------
*/
-int
+herr_t
H5B2__locate_record(const H5B2_class_t *type, unsigned nrec, size_t *rec_off,
- const uint8_t *native, const void *udata, unsigned *idx)
+ const uint8_t *native, const void *udata, unsigned *idx, int *cmp)
{
unsigned lo = 0, hi; /* Low & high index values */
unsigned my_idx = 0; /* Final index value */
- int cmp = -1; /* Key comparison value */
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_PACKAGE
- FUNC_ENTER_PACKAGE_NOERR
+ *cmp = -1;
hi = nrec;
- while(lo < hi && cmp) {
- my_idx = (lo + hi) / 2;
- if((cmp = (type->compare)(udata, native + rec_off[my_idx])) < 0)
- hi = my_idx;
- else
- lo = my_idx + 1;
- }
+ while(lo < hi && *cmp) {
+ my_idx = (lo + hi) / 2;
+ if((type->compare)(udata, native + rec_off[my_idx], cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ if(*cmp < 0)
+ hi = my_idx;
+ else
+ lo = my_idx + 1;
+ } /* end while */
*idx = my_idx;
- FUNC_LEAVE_NOAPI(cmp)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__locate_record */
@@ -2359,7 +2364,9 @@ H5B2__insert_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
idx = 0;
else {
/* Find correct location to insert this record */
- if((cmp = H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx)) == 0)
+ if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ if(cmp == 0)
HGOTO_ERROR(H5E_BTREE, H5E_EXISTS, FAIL, "record is already in B-tree")
if(cmp > 0)
idx++;
@@ -2465,7 +2472,10 @@ H5B2__insert_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, uint16_t depth,
size_t split_nrec; /* Number of records to split node at */
/* Locate node pointer for child */
- if((cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx)) == 0)
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native,
+ udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ if(cmp == 0)
HGOTO_ERROR(H5E_BTREE, H5E_EXISTS, FAIL, "record is already in B-tree")
if(cmp > 0)
idx++;
@@ -2520,8 +2530,11 @@ H5B2__insert_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, uint16_t depth,
} /* end else */
/* Locate node pointer for child (after split/redistribute) */
-/* Actually, this can be easily updated (for 2-node redistrib.) and shouldn't require re-searching */
- if((cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx)) == 0)
+ /* Actually, this can be easily updated (for 2-node redistrib.) and shouldn't require re-searching */
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native,
+ udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ if(cmp == 0)
HGOTO_ERROR(H5E_BTREE, H5E_EXISTS, FAIL, "record is already in B-tree")
if(cmp > 0)
idx++;
@@ -2621,7 +2634,8 @@ H5B2__update_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
idx = 0;
else {
/* Find correct location to insert this record */
- cmp = H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
/* Check for inserting a record */
if(0 != cmp) {
@@ -2774,7 +2788,8 @@ H5B2__update_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, uint16_t depth,
HDassert(internal->nrec == curr_node_ptr->node_nrec);
/* Locate node pointer for child */
- cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
/* Check for modifying existing record */
if(0 == cmp) {
@@ -3344,6 +3359,7 @@ H5B2__remove_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
haddr_t leaf_addr = HADDR_UNDEF; /* Leaf address on disk */
unsigned leaf_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting leaf node */
unsigned idx; /* Location of record which matches key */
+ int cmp; /* Comparison value of records */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@@ -3363,7 +3379,9 @@ H5B2__remove_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
HDassert(leaf->nrec == curr_node_ptr->node_nrec);
/* Find correct location to remove this record */
- if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx) != 0)
+ if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+ if(cmp != 0)
HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "record is not in B-tree")
/* Check for invalidating the min/max record for the tree */
@@ -3579,7 +3597,9 @@ H5B2__remove_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, hbool_t *depth_decreased,
if(swap_loc)
idx = 0;
else {
- cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native,
+ udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
if(cmp >= 0)
idx++;
} /* end else */
@@ -3641,7 +3661,8 @@ H5B2__remove_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, hbool_t *depth_decreased,
idx = 0;
else {
/* Actually, this can be easily updated (for 2-node redistrib.) and shouldn't require re-searching */
- cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
if(cmp >= 0)
idx++;
} /* end else */
@@ -4217,7 +4238,8 @@ H5B2__neighbor_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_p
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect B-tree leaf node")
/* Locate node pointer for child */
- cmp = H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
if(cmp > 0)
idx++;
else
@@ -4304,7 +4326,9 @@ H5B2__neighbor_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, uint16_t depth,
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect B-tree internal node")
/* Locate node pointer for child */
- cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native,
+ udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
if(cmp > 0)
idx++;
diff --git a/src/H5B2pkg.h b/src/H5B2pkg.h
index 38b4bad..ca5a55e 100644
--- a/src/H5B2pkg.h
+++ b/src/H5B2pkg.h
@@ -387,8 +387,8 @@ H5_DLL herr_t H5B2__node_size(H5B2_hdr_t *hdr, hid_t dxpl_id,
hsize_t *op_data);
/* Routines for locating records */
-H5_DLL int H5B2__locate_record(const H5B2_class_t *type, unsigned nrec,
- size_t *rec_off, const uint8_t *native, const void *udata, unsigned *idx);
+H5_DLL herr_t H5B2__locate_record(const H5B2_class_t *type, unsigned nrec,
+ size_t *rec_off, const uint8_t *native, const void *udata, unsigned *idx, int *result);
H5_DLL herr_t H5B2__neighbor_internal(H5B2_hdr_t *hdr, hid_t dxpl_id,
uint16_t depth, H5B2_node_ptr_t *curr_node_ptr, void *neighbor_loc,
H5B2_compare_t comp, void *parent, void *udata, H5B2_found_t op,
diff --git a/src/H5B2private.h b/src/H5B2private.h
index 1620561..eef8aa3 100644
--- a/src/H5B2private.h
+++ b/src/H5B2private.h
@@ -93,7 +93,7 @@ struct H5B2_class_t {
void *(*crt_context)(void *udata); /* Create context for other client callbacks */
herr_t (*dst_context)(void *ctx); /* Destroy client callback context */
herr_t (*store)(void *nrecord, const void *udata); /* Store application record in native record table */
- herr_t (*compare)(const void *rec1, const void *rec2); /* Compare two native records */
+ herr_t (*compare)(const void *rec1, const void *rec2, int *result); /* Compare two native records */
herr_t (*encode)(uint8_t *raw, const void *record, void *ctx); /* Encode record from native form to disk storage form */
herr_t (*decode)(const uint8_t *raw, void *record, void *ctx); /* Decode record from disk storage form to native form */
herr_t (*debug)(FILE *stream, int indent, int fwidth, /* Print a record for debugging */
diff --git a/src/H5B2test.c b/src/H5B2test.c
index 141acee..be4265f 100644
--- a/src/H5B2test.c
+++ b/src/H5B2test.c
@@ -65,7 +65,7 @@ typedef struct H5B2_test_ctx_t {
static void *H5B2__test_crt_context(void *udata);
static herr_t H5B2__test_dst_context(void *ctx);
static herr_t H5B2__test_store(void *nrecord, const void *udata);
-static herr_t H5B2__test_compare(const void *rec1, const void *rec2);
+static herr_t H5B2__test_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5B2__test_encode(uint8_t *raw, const void *nrecord, void *ctx);
static herr_t H5B2__test_decode(const uint8_t *raw, void *nrecord, void *ctx);
static herr_t H5B2__test_debug(FILE *stream, int indent, int fwidth,
@@ -73,7 +73,7 @@ static herr_t H5B2__test_debug(FILE *stream, int indent, int fwidth,
/* v2 B-tree driver callbacks for 'test2' B-trees */
static herr_t H5B2__test2_store(void *nrecord, const void *udata);
-static herr_t H5B2__test2_compare(const void *rec1, const void *rec2);
+static herr_t H5B2__test2_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5B2__test2_encode(uint8_t *raw, const void *nrecord, void *ctx);
static herr_t H5B2__test2_decode(const uint8_t *raw, void *nrecord, void *ctx);
static herr_t H5B2__test2_debug(FILE *stream, int indent, int fwidth,
@@ -236,11 +236,13 @@ H5B2__test_store(void *nrecord, const void *udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2__test_compare(const void *rec1, const void *rec2)
+H5B2__test_compare(const void *rec1, const void *rec2, int *result)
{
FUNC_ENTER_STATIC_NOERR
- FUNC_LEAVE_NOAPI((herr_t)(*(const hssize_t *)rec1 - *(const hssize_t *)rec2))
+ *result = (int)(*(const hssize_t *)rec1 - *(const hssize_t *)rec2);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5B2__test_compare() */
@@ -369,11 +371,13 @@ H5B2__test2_store(void *nrecord, const void *udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2__test2_compare(const void *rec1, const void *rec2)
+H5B2__test2_compare(const void *rec1, const void *rec2, int *result)
{
FUNC_ENTER_STATIC_NOERR
- FUNC_LEAVE_NOAPI((herr_t)(((const H5B2_test_rec_t *)rec1)->key - ((const H5B2_test_rec_t *)rec2)->key))
+ *result = (int)(((const H5B2_test_rec_t *)rec1)->key - ((const H5B2_test_rec_t *)rec2)->key);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5B2__test2_compare() */
@@ -563,7 +567,10 @@ H5B2_get_node_info_test(H5B2_t *bt2, hid_t dxpl_id, void *udata,
} /* end if */
/* Locate node pointer for child */
- cmp = H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native,
+ udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
+
if(cmp > 0)
idx++;
@@ -614,7 +621,9 @@ H5B2_get_node_info_test(H5B2_t *bt2, hid_t dxpl_id, void *udata,
} /* end if */
/* Locate record */
- cmp = H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx);
+ if(H5B2__locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native,
+ udata, &idx, &cmp) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
/* Unlock current node */
if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
diff --git a/src/H5C.c b/src/H5C.c
index ae73259..211cf2d 100644
--- a/src/H5C.c
+++ b/src/H5C.c
@@ -3282,16 +3282,12 @@ H5C_protect(H5F_t * f,
hit = FALSE;
- thing = H5C_load_entry(f, dxpl_id,
+ if(NULL == (thing = H5C_load_entry(f, dxpl_id,
#ifdef H5_HAVE_PARALLEL
- coll_access,
+ coll_access,
#endif /* H5_HAVE_PARALLEL */
- type, addr, udata);
-
- if ( thing == NULL ) {
-
+ type, addr, udata)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTLOAD, NULL, "can't load entry")
- }
entry_ptr = (H5C_cache_entry_t *)thing;
entry_ptr->ring = ring;
diff --git a/src/H5Dbtree2.c b/src/H5Dbtree2.c
index 2435fac..363d57a 100644
--- a/src/H5Dbtree2.c
+++ b/src/H5Dbtree2.c
@@ -89,7 +89,7 @@ typedef struct H5D_bt2_ud_t {
static void *H5D__bt2_crt_context(void *udata);
static herr_t H5D__bt2_dst_context(void *ctx);
static herr_t H5D__bt2_store(void *native, const void *udata);
-static herr_t H5D__bt2_compare(const void *rec1, const void *rec2);
+static herr_t H5D__bt2_compare(const void *rec1, const void *rec2, int *result);
/* v2 B-tree class for indexing non-filtered chunked datasets */
static herr_t H5D__bt2_unfilt_encode(uint8_t *raw, const void *native, void *ctx);
@@ -350,12 +350,12 @@ H5D__bt2_store(void *record, const void *_udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5D__bt2_compare(const void *_udata, const void *_rec2)
+H5D__bt2_compare(const void *_udata, const void *_rec2, int *result)
{
const H5D_bt2_ud_t *udata = (const H5D_bt2_ud_t *)_udata; /* User data */
const H5D_chunk_rec_t *rec1 = &(udata->rec); /* The search record */
const H5D_chunk_rec_t *rec2 = (const H5D_chunk_rec_t *)_rec2; /* The native record */
- herr_t ret_value = FAIL; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_STATIC_NOERR
@@ -364,7 +364,7 @@ H5D__bt2_compare(const void *_udata, const void *_rec2)
HDassert(rec2);
/* Compare the offsets but ignore the other fields */
- ret_value = H5VM_vector_cmp_u(udata->ndims, rec1->scaled, rec2->scaled);
+ *result = H5VM_vector_cmp_u(udata->ndims, rec1->scaled, rec2->scaled);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5D__bt2_compare() */
diff --git a/src/H5Gbtree2.c b/src/H5Gbtree2.c
index 1a99b12..ff7e200 100644
--- a/src/H5Gbtree2.c
+++ b/src/H5Gbtree2.c
@@ -78,7 +78,7 @@ typedef struct H5G_fh_ud_cmp_t {
/* v2 B-tree driver callbacks for 'creation order' index */
static herr_t H5G_dense_btree2_corder_store(void *native, const void *udata);
-static herr_t H5G_dense_btree2_corder_compare(const void *rec1, const void *rec2);
+static herr_t H5G_dense_btree2_corder_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5G_dense_btree2_corder_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5G_dense_btree2_corder_decode(const uint8_t *raw, void *native,
@@ -88,7 +88,7 @@ static herr_t H5G_dense_btree2_corder_debug(FILE *stream, int indent, int fwidth
/* v2 B-tree driver callbacks for 'name' index */
static herr_t H5G_dense_btree2_name_store(void *native, const void *udata);
-static herr_t H5G_dense_btree2_name_compare(const void *rec1, const void *rec2);
+static herr_t H5G__dense_btree2_name_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5G_dense_btree2_name_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5G_dense_btree2_name_decode(const uint8_t *raw, void *native,
@@ -111,7 +111,7 @@ const H5B2_class_t H5G_BT2_NAME[1]={{ /* B-tree class information */
NULL, /* Create client callback context */
NULL, /* Destroy client callback context */
H5G_dense_btree2_name_store, /* Record storage callback */
- H5G_dense_btree2_name_compare, /* Record comparison callback */
+ H5G__dense_btree2_name_compare, /* Record comparison callback */
H5G_dense_btree2_name_encode, /* Record encoding callback */
H5G_dense_btree2_name_decode, /* Record decoding callback */
H5G_dense_btree2_name_debug /* Record debugging callback */
@@ -216,7 +216,7 @@ H5G_dense_btree2_name_store(void *_nrecord, const void *_udata)
/*-------------------------------------------------------------------------
- * Function: H5G_dense_btree2_name_compare
+ * Function: H5G__dense_btree2_name_compare
*
* Purpose: Compare two native information records, according to some key
*
@@ -230,13 +230,13 @@ H5G_dense_btree2_name_store(void *_nrecord, const void *_udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5G_dense_btree2_name_compare(const void *_bt2_udata, const void *_bt2_rec)
+H5G__dense_btree2_name_compare(const void *_bt2_udata, const void *_bt2_rec, int *result)
{
const H5G_bt2_ud_common_t *bt2_udata = (const H5G_bt2_ud_common_t *)_bt2_udata;
const H5G_dense_bt2_name_rec_t *bt2_rec = (const H5G_dense_bt2_name_rec_t *)_bt2_rec;
- herr_t ret_value = FAIL; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC
/* Sanity check */
HDassert(bt2_udata);
@@ -246,20 +246,19 @@ H5G_dense_btree2_name_compare(const void *_bt2_udata, const void *_bt2_rec)
{
unsigned u;
-HDfprintf(stderr, "%s: bt2_udata = {'%s', %x}\n", "H5G_dense_btree2_name_compare", bt2_udata->name, (unsigned)bt2_udata->name_hash);
-HDfprintf(stderr, "%s: bt2_rec = {%x, ", "H5G_dense_btree2_name_compare", (unsigned)bt2_rec->hash);
+HDfprintf(stderr, "%s: bt2_udata = {'%s', %x}\n", "H5G__dense_btree2_name_compare", bt2_udata->name, (unsigned)bt2_udata->name_hash);
+HDfprintf(stderr, "%s: bt2_rec = {%x, ", "H5G__dense_btree2_name_compare", (unsigned)bt2_rec->hash);
for(u = 0; u < H5G_DENSE_FHEAP_ID_LEN; u++)
HDfprintf(stderr, "%02x%s", bt2_rec->id[u], (u < (H5G_DENSE_FHEAP_ID_LEN - 1) ? " " : "}\n"));
}
#endif /* QAK */
/* Check hash value */
if(bt2_udata->name_hash < bt2_rec->hash)
- ret_value = (-1);
+ *result = (-1);
else if(bt2_udata->name_hash > bt2_rec->hash)
- ret_value = 1;
+ *result = 1;
else {
H5G_fh_ud_cmp_t fh_udata; /* User data for fractal heap 'op' callback */
- herr_t status; /* Status from fractal heap 'op' routine */
/* Sanity check */
HDassert(bt2_udata->name_hash == bt2_rec->hash);
@@ -276,16 +275,17 @@ for(u = 0; u < H5G_DENSE_FHEAP_ID_LEN; u++)
fh_udata.cmp = 0;
/* Check if the user's link and the B-tree's link have the same name */
- status = H5HF_op(bt2_udata->fheap, bt2_udata->dxpl_id, bt2_rec->id,
- H5G_dense_fh_name_cmp, &fh_udata);
- HDassert(status >= 0);
+ if(H5HF_op(bt2_udata->fheap, bt2_udata->dxpl_id, bt2_rec->id,
+ H5G_dense_fh_name_cmp, &fh_udata) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
/* Callback will set comparison value */
- ret_value = fh_udata.cmp;
+ *result = fh_udata.cmp;
} /* end else */
+done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* H5G_dense_btree2_name_compare() */
+} /* H5G__dense_btree2_name_compare() */
/*-------------------------------------------------------------------------
@@ -419,11 +419,10 @@ H5G_dense_btree2_corder_store(void *_nrecord, const void *_udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5G_dense_btree2_corder_compare(const void *_bt2_udata, const void *_bt2_rec)
+H5G_dense_btree2_corder_compare(const void *_bt2_udata, const void *_bt2_rec, int *result)
{
const H5G_bt2_ud_common_t *bt2_udata = (const H5G_bt2_ud_common_t *)_bt2_udata;
const H5G_dense_bt2_corder_rec_t *bt2_rec = (const H5G_dense_bt2_corder_rec_t *)_bt2_rec;
- herr_t ret_value = FAIL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT_NOERR
@@ -443,13 +442,13 @@ for(u = 0; u < H5G_DENSE_FHEAP_ID_LEN; u++)
#endif /* QAK */
/* Check creation order value */
if(bt2_udata->corder < bt2_rec->corder)
- ret_value = -1;
+ *result = -1;
else if(bt2_udata->corder > bt2_rec->corder)
- ret_value = 1;
+ *result = 1;
else
- ret_value = 0;
+ *result = 0;
- FUNC_LEAVE_NOAPI(ret_value)
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5G_dense_btree2_corder_compare() */
diff --git a/src/H5HFbtree2.c b/src/H5HFbtree2.c
index a79bf58..d4a30b8 100644
--- a/src/H5HFbtree2.c
+++ b/src/H5HFbtree2.c
@@ -74,7 +74,7 @@ static herr_t H5HF__huge_bt2_dst_context(void *ctx);
/* Callbacks for indirect objects */
static herr_t H5HF__huge_bt2_indir_store(void *native, const void *udata);
-static herr_t H5HF__huge_bt2_indir_compare(const void *rec1, const void *rec2);
+static herr_t H5HF__huge_bt2_indir_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5HF__huge_bt2_indir_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5HF__huge_bt2_indir_decode(const uint8_t *raw, void *native,
@@ -84,7 +84,7 @@ static herr_t H5HF__huge_bt2_indir_debug(FILE *stream, int indent, int fwidth,
/* Callbacks for filtered indirect objects */
static herr_t H5HF__huge_bt2_filt_indir_store(void *native, const void *udata);
-static herr_t H5HF__huge_bt2_filt_indir_compare(const void *rec1, const void *rec2);
+static herr_t H5HF__huge_bt2_filt_indir_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5HF__huge_bt2_filt_indir_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5HF__huge_bt2_filt_indir_decode(const uint8_t *raw, void *native,
@@ -94,7 +94,7 @@ static herr_t H5HF__huge_bt2_filt_indir_debug(FILE *stream, int indent, int fwid
/* Callbacks for direct objects */
static herr_t H5HF__huge_bt2_dir_store(void *native, const void *udata);
-static herr_t H5HF__huge_bt2_dir_compare(const void *rec1, const void *rec2);
+static herr_t H5HF__huge_bt2_dir_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5HF__huge_bt2_dir_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5HF__huge_bt2_dir_decode(const uint8_t *raw, void *native,
@@ -104,7 +104,7 @@ static herr_t H5HF__huge_bt2_dir_debug(FILE *stream, int indent, int fwidth,
/* Callbacks for filtered direct objects */
static herr_t H5HF__huge_bt2_filt_dir_store(void *native, const void *udata);
-static herr_t H5HF__huge_bt2_filt_dir_compare(const void *rec1, const void *rec2);
+static herr_t H5HF__huge_bt2_filt_dir_compare(const void *rec1, const void *rec2, int *result);
static herr_t H5HF__huge_bt2_filt_dir_encode(uint8_t *raw, const void *native,
void *ctx);
static herr_t H5HF__huge_bt2_filt_dir_decode(const uint8_t *raw, void *native,
@@ -358,11 +358,14 @@ H5HF__huge_bt2_indir_store(void *nrecord, const void *udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5HF__huge_bt2_indir_compare(const void *_rec1, const void *_rec2)
+H5HF__huge_bt2_indir_compare(const void *_rec1, const void *_rec2, int *result)
{
FUNC_ENTER_STATIC_NOERR
- FUNC_LEAVE_NOAPI((herr_t)(((const H5HF_huge_bt2_indir_rec_t *)_rec1)->id - ((const H5HF_huge_bt2_indir_rec_t *)_rec2)->id))
+ *result = (int)(((const H5HF_huge_bt2_indir_rec_t *)_rec1)->id -
+ ((const H5HF_huge_bt2_indir_rec_t *)_rec2)->id);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5HF__huge_bt2_indir_compare() */
@@ -558,11 +561,14 @@ H5HF__huge_bt2_filt_indir_store(void *nrecord, const void *udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5HF__huge_bt2_filt_indir_compare(const void *_rec1, const void *_rec2)
+H5HF__huge_bt2_filt_indir_compare(const void *_rec1, const void *_rec2, int *result)
{
FUNC_ENTER_STATIC_NOERR
- FUNC_LEAVE_NOAPI((herr_t)(((const H5HF_huge_bt2_filt_indir_rec_t *)_rec1)->id - ((const H5HF_huge_bt2_filt_indir_rec_t *)_rec2)->id))
+ *result = (int)(((const H5HF_huge_bt2_filt_indir_rec_t *)_rec1)->id -
+ ((const H5HF_huge_bt2_filt_indir_rec_t *)_rec2)->id);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5HF__huge_bt2_filt_indir_compare() */
@@ -737,26 +743,25 @@ H5HF__huge_bt2_dir_store(void *nrecord, const void *udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5HF__huge_bt2_dir_compare(const void *_rec1, const void *_rec2)
+H5HF__huge_bt2_dir_compare(const void *_rec1, const void *_rec2, int *result)
{
const H5HF_huge_bt2_dir_rec_t *rec1 = (const H5HF_huge_bt2_dir_rec_t *)_rec1;
const H5HF_huge_bt2_dir_rec_t *rec2 = (const H5HF_huge_bt2_dir_rec_t *)_rec2;
- herr_t ret_value = FAIL; /* Return value */
FUNC_ENTER_STATIC_NOERR
if(rec1->addr < rec2->addr)
- ret_value = -1;
+ *result = -1;
else if(rec1->addr > rec2->addr)
- ret_value = 1;
+ *result = 1;
else if(rec1->len < rec2->len)
- ret_value = -1;
+ *result = -1;
else if(rec1->len > rec2->len)
- ret_value = 1;
+ *result = 1;
else
- ret_value = 0;
+ *result = 0;
- FUNC_LEAVE_NOAPI(ret_value)
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5HF__huge_bt2_dir_compare() */
@@ -950,26 +955,25 @@ H5HF__huge_bt2_filt_dir_store(void *nrecord, const void *udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5HF__huge_bt2_filt_dir_compare(const void *_rec1, const void *_rec2)
+H5HF__huge_bt2_filt_dir_compare(const void *_rec1, const void *_rec2, int *result)
{
const H5HF_huge_bt2_filt_dir_rec_t *rec1 = (const H5HF_huge_bt2_filt_dir_rec_t *)_rec1;
const H5HF_huge_bt2_filt_dir_rec_t *rec2 = (const H5HF_huge_bt2_filt_dir_rec_t *)_rec2;
- herr_t ret_value = FAIL; /* Return value */
FUNC_ENTER_STATIC_NOERR
if(rec1->addr < rec2->addr)
- ret_value = -1;
+ *result = -1;
else if(rec1->addr > rec2->addr)
- ret_value = 1;
+ *result = 1;
else if(rec1->len < rec2->len)
- ret_value = -1;
+ *result = -1;
else if(rec1->len > rec2->len)
- ret_value = 1;
+ *result = 1;
else
- ret_value = 0;
+ *result = 0;
- FUNC_LEAVE_NOAPI(ret_value)
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5HF__huge_bt2_filt_dir_compare() */
diff --git a/src/H5SM.c b/src/H5SM.c
index 413ad1f..0b72e40 100644
--- a/src/H5SM.c
+++ b/src/H5SM.c
@@ -60,7 +60,8 @@ static herr_t H5SM_create_index(H5F_t *f, H5SM_index_header_t *header,
static herr_t H5SM_delete_index(H5F_t *f, H5SM_index_header_t *header,
hid_t dxpl_id, hbool_t delete_heap);
static haddr_t H5SM_create_list(H5F_t *f, H5SM_index_header_t *header, hid_t dxpl_id);
-static size_t H5SM_find_in_list(const H5SM_list_t *list, const H5SM_mesg_key_t *key, size_t *empty_pos);
+static herr_t H5SM__find_in_list(const H5SM_list_t *list, const H5SM_mesg_key_t *key,
+ size_t *empty_pos, size_t *list_pos);
static herr_t H5SM_convert_list_to_btree(H5F_t * f, H5SM_index_header_t * header,
H5SM_list_t **_list, H5HF_t *fheap, H5O_t *open_oh, hid_t dxpl_id);
static herr_t H5SM_convert_btree_to_list(H5F_t * f, H5SM_index_header_t * header, hid_t dxpl_id);
@@ -1303,7 +1304,9 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
* Also record the first empty list position we find in case we need it
* later.
*/
- list_pos = H5SM_find_in_list(list, &key, &empty_pos);
+ if(H5SM__find_in_list(list, &key, &empty_pos, &list_pos) < 0)
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTINSERT, FAIL, "unable to search for message in list")
+
if(defer) {
if(list_pos != UFAIL)
found = TRUE;
@@ -1464,10 +1467,15 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
/* Insert the new message into the SOHM index */
if(header->index_type == H5SM_LIST) {
/* Index is a list. Find an empty spot if we haven't already */
- if(empty_pos == UFAIL)
- if((H5SM_find_in_list(list, NULL, &empty_pos) == UFAIL) || empty_pos == UFAIL)
- HGOTO_ERROR(H5E_SOHM, H5E_CANTINSERT, FAIL, "unable to find empty entry in list")
+ if(empty_pos == UFAIL) {
+ size_t pos;
+
+ if(H5SM__find_in_list(list, NULL, &empty_pos, &pos) < 0)
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTINSERT, FAIL, "unable to search for message in list")
+ if(pos == UFAIL || empty_pos == UFAIL)
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTINSERT, FAIL, "unable to find empty entry in list")
+ }
/* Insert message into list */
HDassert(list->messages[empty_pos].location == H5SM_NO_LOC);
HDassert(key.message.location != H5SM_NO_LOC);
@@ -1610,7 +1618,7 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5SM_find_in_list
+ * Function: H5SM__find_in_list
*
* Purpose: Find a message's location in a list. Also find the first
* empty location in the list (since if we don't find the
@@ -1630,13 +1638,13 @@ done:
*
*-------------------------------------------------------------------------
*/
-static size_t
-H5SM_find_in_list(const H5SM_list_t *list, const H5SM_mesg_key_t *key, size_t *empty_pos)
+static herr_t
+H5SM__find_in_list(const H5SM_list_t *list, const H5SM_mesg_key_t *key, size_t *empty_pos, size_t *pos)
{
size_t x;
- size_t ret_value = 0; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC
HDassert(list);
/* Both key and empty_pos can be NULL, but not both! */
@@ -1650,9 +1658,17 @@ H5SM_find_in_list(const H5SM_list_t *list, const H5SM_mesg_key_t *key, size_t *e
* Also record the first empty position we find.
*/
for(x = 0; x < list->header->list_max; x++) {
- if((list->messages[x].location != H5SM_NO_LOC) &&
- (0 == H5SM__message_compare(key, &(list->messages[x]))))
- HGOTO_DONE(x)
+ if(list->messages[x].location != H5SM_NO_LOC) {
+ int cmp;
+
+ if(H5SM__message_compare(key, &(list->messages[x]), &cmp) < 0)
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTCOMPARE, FAIL, "can't compare message records")
+
+ if(0 == cmp) {
+ *pos = x;
+ HGOTO_DONE(SUCCEED)
+ }
+ }
else if(empty_pos && list->messages[x].location == H5SM_NO_LOC) {
/* Note position */
*empty_pos = x;
@@ -1663,11 +1679,11 @@ H5SM_find_in_list(const H5SM_list_t *list, const H5SM_mesg_key_t *key, size_t *e
} /* end for */
/* If we reached this point, we didn't find the message */
- ret_value = UFAIL;
+ *pos = UFAIL;
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5SM_find_in_list */
+} /* end H5SM__find_in_list */
/*-------------------------------------------------------------------------
@@ -1834,7 +1850,9 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index")
/* Find the message in the list */
- if((list_pos = H5SM_find_in_list(list, &key, NULL)) == UFAIL)
+ if(H5SM__find_in_list(list, &key, NULL, &list_pos) < 0)
+ HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "unable to search for message in list")
+ if(list_pos == UFAIL)
HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index")
if(list->messages[list_pos].location == H5SM_IN_HEAP)
@@ -2217,7 +2235,9 @@ H5SM_get_refcount(H5F_t *f, hid_t dxpl_id, unsigned type_id,
HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index")
/* Find the message in the list */
- if((list_pos = H5SM_find_in_list(list, &key, NULL)) == UFAIL)
+ if(H5SM__find_in_list(list, &key, NULL, &list_pos) < 0)
+ HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "unable to search for message in list")
+ if(list_pos == UFAIL)
HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index")
/* Copy the message */
diff --git a/src/H5SMmessage.c b/src/H5SMmessage.c
index 426ea20..92b6a75 100644
--- a/src/H5SMmessage.c
+++ b/src/H5SMmessage.c
@@ -186,13 +186,13 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5SM__message_compare(const void *rec1, const void *rec2)
+H5SM__message_compare(const void *rec1, const void *rec2, int *result)
{
const H5SM_mesg_key_t *key = (const H5SM_mesg_key_t *) rec1;
const H5SM_sohm_t *mesg = (const H5SM_sohm_t *) rec2;
- herr_t ret_value = 0;
+ herr_t ret_value = SUCCEED;
- FUNC_ENTER_PACKAGE_NOERR
+ FUNC_ENTER_PACKAGE
/* If the key has an fheap ID, we're looking for a message that's
* already in the index; if the fheap ID matches, we've found the message
@@ -201,28 +201,31 @@ H5SM__message_compare(const void *rec1, const void *rec2)
* message in the index, we've found the message.
*/
if(mesg->location == H5SM_IN_HEAP && key->message.location == H5SM_IN_HEAP) {
- if(key->message.u.heap_loc.fheap_id.val == mesg->u.heap_loc.fheap_id.val)
- HGOTO_DONE(0);
+ if(key->message.u.heap_loc.fheap_id.val == mesg->u.heap_loc.fheap_id.val) {
+ *result = 0;
+ HGOTO_DONE(SUCCEED);
+ }
} /* end if */
else if(mesg->location == H5SM_IN_OH && key->message.location == H5SM_IN_OH) {
if(key->message.u.mesg_loc.oh_addr == mesg->u.mesg_loc.oh_addr &&
- key->message.u.mesg_loc.index == mesg->u.mesg_loc.index &&
- key->message.msg_type_id == mesg->msg_type_id)
- HGOTO_DONE(0);
+ key->message.u.mesg_loc.index == mesg->u.mesg_loc.index &&
+ key->message.msg_type_id == mesg->msg_type_id) {
+ *result = 0;
+ HGOTO_DONE(SUCCEED);
+ }
} /* end if */
/* Compare hash values */
if(key->message.hash > mesg->hash)
- ret_value = 1;
+ *result = 1;
else if(key->message.hash < mesg->hash)
- ret_value = -1;
+ *result = -1;
/* If the hash values match, make sure the messages are really the same */
else {
/* Hash values match; compare the encoded message with the one in
* the index.
*/
H5SM_compare_udata_t udata;
- herr_t status;
HDassert(key->message.hash == mesg->hash);
HDassert(key->encoding_size > 0 && key->encoding);
@@ -235,8 +238,8 @@ H5SM__message_compare(const void *rec1, const void *rec2)
*/
if(mesg->location == H5SM_IN_HEAP) {
/* Call heap op routine with comparison callback */
- status = H5HF_op(key->fheap, key->dxpl_id, &(mesg->u.heap_loc.fheap_id), H5SM_compare_cb, &udata);
- HDassert(status >= 0);
+ if(H5HF_op(key->fheap, key->dxpl_id, &(mesg->u.heap_loc.fheap_id), H5SM_compare_cb, &udata) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPARE, FAIL, "can't compare btree2 records")
} /* end if */
else {
H5O_loc_t oloc; /* Object owning the message */
@@ -247,8 +250,8 @@ H5SM__message_compare(const void *rec1, const void *rec2)
HDassert(mesg->location == H5SM_IN_OH);
/* Reset the object location */
- status = H5O_loc_reset(&oloc);
- HDassert(status >= 0);
+ if(H5O_loc_reset(&oloc) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTRESET, FAIL, "unable to initialize target location")
/* Set up object location */
oloc.file = key->file;
@@ -260,11 +263,11 @@ H5SM__message_compare(const void *rec1, const void *rec2)
/* Locate the right message and compare with it */
op.op_type = H5O_MESG_OP_LIB;
op.u.lib_op = H5SM_compare_iter_op;
- status = H5O_msg_iterate(&oloc, mesg->msg_type_id, &op, &udata, key->dxpl_id);
- HDassert(status >= 0);
+ if(H5O_msg_iterate(&oloc, mesg->msg_type_id, &op, &udata, key->dxpl_id) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "error iterating over links")
} /* end else */
- ret_value = udata.ret;
+ *result = udata.ret;
} /* end if */
done:
diff --git a/src/H5SMpkg.h b/src/H5SMpkg.h
index f072741..3b13e23 100644
--- a/src/H5SMpkg.h
+++ b/src/H5SMpkg.h
@@ -268,7 +268,7 @@ H5_DLLVAR const H5B2_class_t H5SM_INDEX[1];
H5_DLL ssize_t H5SM_get_index(const H5SM_master_table_t *table, unsigned type_id);
/* Encode and decode routines, used for B-tree and cache encoding/decoding */
-H5_DLL herr_t H5SM__message_compare(const void *rec1, const void *rec2);
+H5_DLL herr_t H5SM__message_compare(const void *rec1, const void *rec2, int *result);
H5_DLL herr_t H5SM__message_encode(uint8_t *raw, const void *native, void *ctx);
H5_DLL herr_t H5SM__message_decode(const uint8_t *raw, void *native, void *ctx);
diff --git a/test/dsets.c b/test/dsets.c
index e06d81d..b2b6c6f 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -10181,48 +10181,48 @@ test_swmr_non_latest(const char *env_h5_driver, hid_t fapl)
SKIPPED();
HDputs(" Test skipped due to VFD not supporting SWMR I/O.");
return 0;
- }
+ } /* end if */
/* Check if we are using the latest version of the format */
if(H5Pget_libver_bounds(fapl, &low, NULL) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
h5_fixname(FILENAME[18], fapl, filename, sizeof filename);
if(low == H5F_LIBVER_LATEST) {
- /* Create file with write+latest-format */
- if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
- FAIL_STACK_ERROR
+ /* Create file with write+latest-format */
+ if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ FAIL_STACK_ERROR
} else {
- /* Create file with SWMR-write+non-latest-format */
- if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
- FAIL_STACK_ERROR
- }
+ /* Create file with SWMR-write+non-latest-format */
+ if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
+ FAIL_STACK_ERROR
+ } /* end else */
/* Create a chunked dataset: this will use extensible array chunk indexing */
if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
chunk_dim[0] = 6;
if(H5Pset_chunk(dcpl, 1, chunk_dim) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
dim[0] = 1;
max_dim[0] = H5S_UNLIMITED;
if((sid = H5Screate_simple(1, dim, max_dim)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if((did = H5Dcreate2(fid, DSET_CHUNKED_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Write to the dataset */
data = 100;
if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Verify the dataset's indexing type */
if(H5D__layout_idx_type_test(did, &idx_type) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(idx_type != H5D_CHUNK_IDX_EARRAY)
FAIL_PUTS_ERROR("created dataset not indexed by extensible array")
@@ -10234,50 +10234,50 @@ test_swmr_non_latest(const char *env_h5_driver, hid_t fapl)
/* Open the file again */
if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Open the dataset in the file */
if((did = H5Dopen2(fid, DSET_CHUNKED_NAME, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Verify the dataset's indexing type */
if(H5D__layout_idx_type_test(did, &idx_type) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(idx_type != H5D_CHUNK_IDX_EARRAY)
FAIL_PUTS_ERROR("created dataset not indexed by extensible array")
/* Read from the dataset and verify data read is correct */
if(H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(data != 100)
- FAIL_STACK_ERROR
+ TEST_ERROR
/* Close the dataset */
if(H5Dclose(did) < 0) FAIL_STACK_ERROR
/* Create a group in the file */
if((gid = H5Gcreate2(fid, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Create a chunked dataset in the group: this will use v2 B-tree chunk indexing */
if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
chunk_dims2[0] = chunk_dims2[1] = 10;
if(H5Pset_chunk(dcpl, 2, chunk_dims2) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
dims2[0] = dims2[1] = 1;
max_dims2[0] = max_dims2[1] = H5S_UNLIMITED;
if((sid = H5Screate_simple(2, dims2, max_dims2)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if((did = H5Dcreate2(gid, DSET_CHUNKED_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Verify the dataset's indexing type */
if(H5D__layout_idx_type_test(did, &idx_type) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(idx_type != H5D_CHUNK_IDX_BT2)
FAIL_PUTS_ERROR("created dataset not indexed by v2 B-tree")
@@ -10289,18 +10289,20 @@ test_swmr_non_latest(const char *env_h5_driver, hid_t fapl)
if(H5Fclose(fid) < 0) FAIL_STACK_ERROR
/* Open the file again */
- if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) FAIL_STACK_ERROR
+ if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
+ FAIL_STACK_ERROR
/* Open the group */
- if((gid = H5Gopen2(fid, "group", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
+ if((gid = H5Gopen2(fid, "group", H5P_DEFAULT)) < 0)
+ FAIL_STACK_ERROR
/* Open the dataset in the group */
if((did = H5Dopen2(gid, DSET_CHUNKED_NAME, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Verify the dataset's indexing type */
if(H5D__layout_idx_type_test(did, &idx_type) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(idx_type != H5D_CHUNK_IDX_BT2)
FAIL_PUTS_ERROR("created dataset not indexed by v2 B-tree")
@@ -10311,15 +10313,16 @@ test_swmr_non_latest(const char *env_h5_driver, hid_t fapl)
/* Reopen the file with SWMR-write */
- if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) FAIL_STACK_ERROR
+ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
+ FAIL_STACK_ERROR
/* Open the dataset in the file */
if((did = H5Dopen2(fid, DSET_CHUNKED_NAME, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Verify the dataset's indexing type */
if(H5D__layout_idx_type_test(did, &idx_type) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(idx_type != H5D_CHUNK_IDX_EARRAY)
FAIL_PUTS_ERROR("created dataset not indexed by extensible array")
@@ -10327,22 +10330,23 @@ test_swmr_non_latest(const char *env_h5_driver, hid_t fapl)
if(H5Dclose(did) < 0) FAIL_STACK_ERROR
/* Open the group */
- if((gid = H5Gopen2(fid, "group", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
+ if((gid = H5Gopen2(fid, "group", H5P_DEFAULT)) < 0)
+ FAIL_STACK_ERROR
/* Open the dataset in the group */
if((did = H5Dopen2(gid, DSET_CHUNKED_NAME, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Verify the dataset's indexing type */
if(H5D__layout_idx_type_test(did, &idx_type) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(idx_type != H5D_CHUNK_IDX_BT2)
FAIL_PUTS_ERROR("created dataset not indexed by v2 B-tree")
/* Write to the dataset in the group */
data = 99;
if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Closing */
if(H5Dclose(did) < 0) FAIL_STACK_ERROR
@@ -10351,19 +10355,21 @@ test_swmr_non_latest(const char *env_h5_driver, hid_t fapl)
/* Open the file again with SWMR read access */
if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
- if((gid = H5Gopen2(fid, "group", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
+ if((gid = H5Gopen2(fid, "group", H5P_DEFAULT)) < 0)
+ FAIL_STACK_ERROR
/* Open the dataset */
if((did = H5Dopen2(gid, DSET_CHUNKED_NAME, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Read from the dataset and verify data read is correct */
data = 0;
if(H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data) < 0)
- FAIL_STACK_ERROR
- if(data != 99) FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
+ if(data != 99)
+ TEST_ERROR
/* Closing */
if(H5Dclose(did) < 0) FAIL_STACK_ERROR