Skip to content

Commit

Permalink
Fixed a typo in H5O_get_info and added one more test to catch the
Browse files Browse the repository at this point in the history
scenario introduced by that typo.
  • Loading branch information
bmribler committed Nov 2, 2024
1 parent fb46c34 commit b3fbc54
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/H5Oint.c
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,7 @@ H5O__visit(H5G_loc_t *loc, const char *obj_name, H5_index_t idx_type, H5_iter_or
HGOTO_ERROR(H5E_ID, H5E_CANTREGISTER, FAIL, "unable to register visited object");

/* Make callback for starting object */
if ((ret_value = op(obj_id, ".", oinfop, op_data)) < 0)
if ((ret_value = op(obj_id, ".", &oinfo, op_data)) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_BADITER, FAIL, "can't visit objects");

/* Check return value of first callback */
Expand Down
50 changes: 39 additions & 11 deletions test/th5o.c
Original file line number Diff line number Diff line change
Expand Up @@ -1882,11 +1882,13 @@ test_h5o_getinfo_visit(void)

#define G1 "g1" /* Group /g1 */
#define G1G2 "g1/g2" /* Group /g1/g2 */
#define ATTR1 "Attr1" /* Attribute Attr1 */
#define D1G1G2 "/g1/g2/dset1" /* Dataset /g1/g2/dset1 */
#define NUM_OBJS 4 /* Number of objects including root group */

typedef struct {
unsigned idx; /* Index in object visit structure */
unsigned idx; /* Index in object visit structure */
unsigned fields; /* Fields to verify number of attributes in callback */
} ovisit2_ud_t;

/* Names of objects being visited, in this order */
Expand All @@ -1902,15 +1904,24 @@ static const char *visited_objs[] = {".", "g1", "g1/g2", "g1/g2/dset1"};
**
****************************************************************/
static int
visit2_obj_cb(hid_t H5_ATTR_UNUSED obj_id, const char *name, const H5O_info1_t H5_ATTR_UNUSED *info,
void *_op_data)
visit2_obj_cb(hid_t obj_id, const char *name, const H5O_info1_t H5_ATTR_UNUSED *info, void *_op_data)
{
H5O_info1_t oinfo;

memset(&oinfo, 0, sizeof(oinfo));
ovisit2_ud_t *op_data = (ovisit2_ud_t *)_op_data;

if (strcmp(visited_objs[op_data->idx], name) != 0)
return H5_ITER_ERROR;

if (H5Oget_info2(obj_id, &oinfo, op_data->fields) < 0)
return H5_ITER_ERROR;

if (op_data->fields == H5O_INFO_NUM_ATTRS)
fprintf(stderr, "it is H5O_INFO_NUM_ATTRS, info->num_attrs = %ld\n", oinfo.num_attrs);
else
fprintf(stderr, "it is not oinfo.num_attrs\n");

/* Advance to next location in expected output */
op_data->idx++;

Expand All @@ -1927,14 +1938,16 @@ visit2_obj_cb(hid_t H5_ATTR_UNUSED obj_id, const char *name, const H5O_info1_t H
static void
test_h5o_visit2(void)
{
hid_t fid = H5I_INVALID_HID; /* HDF5 File ID */
hid_t gid1 = H5I_INVALID_HID, gid2 = H5I_INVALID_HID; /* Group IDs */
hid_t sid = H5I_INVALID_HID; /* Dataspace ID */
hid_t did = H5I_INVALID_HID; /* Dataset ID */
hid_t obj_id; /* Object ID for root group */
char filename[1024]; /* File used in this test */
ovisit2_ud_t udata; /* User-data for visiting */
unsigned fields; /* Fields to return */
hid_t fid = H5I_INVALID_HID; /* HDF5 File ID */
hid_t gid1 = H5I_INVALID_HID,
gid2 = H5I_INVALID_HID; /* Group IDs */
hid_t sid = H5I_INVALID_HID; /* Dataspace ID */
hid_t did = H5I_INVALID_HID; /* Dataset ID */
hid_t attid = H5I_INVALID_HID; /* Attribute ID */
hid_t obj_id; /* Object ID for root group */
char filename[1024]; /* File used in this test */
ovisit2_ud_t udata; /* User-data for visiting */
unsigned fields; /* Fields to return */
H5_index_t idx_type = H5_INDEX_NAME;
H5_iter_order_t order = H5_ITER_DEC;
bool vol_is_native;
Expand Down Expand Up @@ -1972,6 +1985,11 @@ test_h5o_visit2(void)
did = H5Dcreate2(gid2, D1G1G2, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(did, FAIL, "H5Dcreate2");

/* Add an attribute to verify H5O_get_info with H5O_INFO_NUM_ATTRS works */
attid = H5Acreate2(fid, ATTR1, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT);
CHECK(attid, FAIL, "H5Acreate2");

H5Aclose(attid);
H5Dclose(did);
H5Gclose(gid2);
H5Gclose(gid1);
Expand All @@ -1983,6 +2001,7 @@ test_h5o_visit2(void)
/* Visit root with H5O_INFO_META_SIZE */
udata.idx = 0; /* first object, i.e., root group */
fields = H5O_INFO_META_SIZE;
udata.fields = fields;
ret = H5Ovisit2(obj_id, idx_type, order, visit2_obj_cb, &udata, fields);
CHECK(ret, FAIL, "H5Ovisit2");

Expand All @@ -1992,6 +2011,7 @@ test_h5o_visit2(void)
/* Visit root with H5O_INFO_BASIC */
udata.idx = 0; /* first object, i.e., root group */
fields = H5O_INFO_BASIC;
udata.fields = fields;
ret = H5Ovisit2(obj_id, idx_type, order, visit2_obj_cb, &udata, fields);
CHECK(ret, FAIL, "H5Ovisit2");

Expand All @@ -2001,6 +2021,14 @@ test_h5o_visit2(void)
/* Visit root with H5O_INFO_ALL */
udata.idx = 0; /* first object, i.e., root group */
fields = H5O_INFO_ALL;
udata.fields = fields;
ret = H5Ovisit2(obj_id, idx_type, order, visit2_obj_cb, &udata, fields);
CHECK(ret, FAIL, "H5Ovisit2");

/* Visit root with H5O_INFO_NUM_ATTRS */
udata.idx = 0; /* first object, i.e., root group */
fields = H5O_INFO_NUM_ATTRS;
udata.fields = fields;
ret = H5Ovisit2(obj_id, idx_type, order, visit2_obj_cb, &udata, fields);
CHECK(ret, FAIL, "H5Ovisit2");

Expand Down

0 comments on commit b3fbc54

Please sign in to comment.