From a512a3891640f4825487373b33d9c4f61e87666f Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Thu, 31 Aug 2023 16:28:49 -0500 Subject: [PATCH 1/4] Implement H5Fget_obj_ids --- src/rest_vol_file.c | 69 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/src/rest_vol_file.c b/src/rest_vol_file.c index 0eacbf2e..9ac913d9 100644 --- a/src/rest_vol_file.c +++ b/src/rest_vol_file.c @@ -17,6 +17,13 @@ #include "rest_vol_file.h" +herr_t RV_iterate_copy_hid_cb(hid_t obj_id, void *udata); + +struct object_id_list { + hid_t *obj_id_list; + size_t obj_count; +} typedef object_id_list; + /*------------------------------------------------------------------------- * Function: RV_file_create * @@ -544,9 +551,44 @@ RV_file_get(void *obj, H5VL_file_get_args_t *args, hid_t dxpl_id, void **req) /* H5Fget_obj_ids */ case H5VL_FILE_GET_OBJ_IDS: - FUNC_GOTO_ERROR(H5E_FILE, H5E_UNSUPPORTED, FAIL, "H5Fget_obj_ids is unsupported"); - break; + if (args->args.get_obj_ids.max_objs <= 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "invalid max object parameter"); + + if (args->args.get_obj_ids.oid_list == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "given object id list buffer is NULL"); + + if (args->args.get_obj_ids.count == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "given object id count buffer is NULL"); + + *args->args.get_obj_ids.count = 0; + unsigned int requested_types = args->args.get_obj_ids.types; + + object_id_list id_list; + id_list.obj_id_list = args->args.get_obj_ids.oid_list; + id_list.obj_count = 0; + + if (args->args.get_obj_ids.types & H5F_OBJ_FILE) + if (H5Iiterate(H5I_FILE, RV_iterate_copy_hid_cb, &id_list) < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over file ids"); + + if (args->args.get_obj_ids.types & H5F_OBJ_GROUP) + if (H5Iiterate(H5I_GROUP, RV_iterate_copy_hid_cb, &id_list) < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over group ids"); + + if (args->args.get_obj_ids.types & H5F_OBJ_DATATYPE) + if (H5Iiterate(H5I_DATATYPE, RV_iterate_copy_hid_cb, &id_list) < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over datatype ids"); + + if (args->args.get_obj_ids.types & H5F_OBJ_DATASET) + if (H5Iiterate(H5I_DATASET, RV_iterate_copy_hid_cb, &id_list) < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over dataset ids"); + + if (args->args.get_obj_ids.types & H5F_OBJ_ATTR) + if (H5Iiterate(H5I_ATTR, RV_iterate_copy_hid_cb, &id_list) < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over attribute ids"); + + break; default: FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get this type of information from file"); } /* end switch */ @@ -755,3 +797,26 @@ RV_file_close(void *file, hid_t dxpl_id, void **req) return ret_value; } /* end RV_file_close() */ + +/*------------------------------------------------------------------------- + * Function: RV_iterate_copy_hid_cb + * + * Purpose: Callback for H5Iiterate() that copies the hid_t + * of each library object into a list. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Matthew Larson + * August, 2023 + */ +herr_t RV_iterate_copy_hid_cb(hid_t obj_id, void *udata) { + herr_t ret_value = SUCCEED; + object_id_list *id_list = (object_id_list *) udata; + + id_list->obj_id_list[id_list->obj_count] = obj_id; + + id_list->obj_count++; + +done: + return ret_value; +} \ No newline at end of file From 1dad84f138e97039096d19437b0c417243ebb133 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 31 Aug 2023 21:41:54 +0000 Subject: [PATCH 2/4] Committing clang-format changes --- src/rest_vol_file.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rest_vol_file.c b/src/rest_vol_file.c index 9ac913d9..e9b9aa03 100644 --- a/src/rest_vol_file.c +++ b/src/rest_vol_file.c @@ -566,7 +566,7 @@ RV_file_get(void *obj, H5VL_file_get_args_t *args, hid_t dxpl_id, void **req) object_id_list id_list; id_list.obj_id_list = args->args.get_obj_ids.oid_list; - id_list.obj_count = 0; + id_list.obj_count = 0; if (args->args.get_obj_ids.types & H5F_OBJ_FILE) if (H5Iiterate(H5I_FILE, RV_iterate_copy_hid_cb, &id_list) < 0) @@ -809,9 +809,11 @@ RV_file_close(void *file, hid_t dxpl_id, void **req) * Programmer: Matthew Larson * August, 2023 */ -herr_t RV_iterate_copy_hid_cb(hid_t obj_id, void *udata) { - herr_t ret_value = SUCCEED; - object_id_list *id_list = (object_id_list *) udata; +herr_t +RV_iterate_copy_hid_cb(hid_t obj_id, void *udata) +{ + herr_t ret_value = SUCCEED; + object_id_list *id_list = (object_id_list *)udata; id_list->obj_id_list[id_list->obj_count] = obj_id; From 94d83426291f61dcaffe9dc16157b631424e2da1 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Tue, 12 Sep 2023 09:39:56 -0500 Subject: [PATCH 3/4] Fix returned H5Fget_obj_ids count --- src/rest_vol_file.c | 37 +++++++++++++++++++++++-------------- test/test_rest_vol.c | 2 -- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/rest_vol_file.c b/src/rest_vol_file.c index e9b9aa03..6ed1a98f 100644 --- a/src/rest_vol_file.c +++ b/src/rest_vol_file.c @@ -19,10 +19,11 @@ herr_t RV_iterate_copy_hid_cb(hid_t obj_id, void *udata); -struct object_id_list { +struct get_obj_ids_udata_t { hid_t *obj_id_list; size_t obj_count; -} typedef object_id_list; + size_t max_obj_count; +} typedef get_obj_ids_udata_t; /*------------------------------------------------------------------------- * Function: RV_file_create @@ -552,42 +553,48 @@ RV_file_get(void *obj, H5VL_file_get_args_t *args, hid_t dxpl_id, void **req) /* H5Fget_obj_ids */ case H5VL_FILE_GET_OBJ_IDS: - if (args->args.get_obj_ids.max_objs <= 0) - FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "invalid max object parameter"); - if (args->args.get_obj_ids.oid_list == NULL) FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "given object id list buffer is NULL"); if (args->args.get_obj_ids.count == NULL) FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "given object id count buffer is NULL"); + if (args->args.get_obj_ids.max_objs < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "invalid max object parameter"); + + if (args->args.get_obj_ids.max_objs == 0) + FUNC_GOTO_DONE(SUCCEED); + *args->args.get_obj_ids.count = 0; unsigned int requested_types = args->args.get_obj_ids.types; - object_id_list id_list; + get_obj_ids_udata_t id_list; id_list.obj_id_list = args->args.get_obj_ids.oid_list; id_list.obj_count = 0; + id_list.max_obj_count = args->args.get_obj_ids.max_objs; - if (args->args.get_obj_ids.types & H5F_OBJ_FILE) + if (requested_types & H5F_OBJ_FILE) if (H5Iiterate(H5I_FILE, RV_iterate_copy_hid_cb, &id_list) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over file ids"); - if (args->args.get_obj_ids.types & H5F_OBJ_GROUP) + if (requested_types & H5F_OBJ_GROUP) if (H5Iiterate(H5I_GROUP, RV_iterate_copy_hid_cb, &id_list) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over group ids"); - if (args->args.get_obj_ids.types & H5F_OBJ_DATATYPE) + if (requested_types & H5F_OBJ_DATATYPE) if (H5Iiterate(H5I_DATATYPE, RV_iterate_copy_hid_cb, &id_list) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over datatype ids"); - if (args->args.get_obj_ids.types & H5F_OBJ_DATASET) + if (requested_types & H5F_OBJ_DATASET) if (H5Iiterate(H5I_DATASET, RV_iterate_copy_hid_cb, &id_list) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over dataset ids"); - if (args->args.get_obj_ids.types & H5F_OBJ_ATTR) + if (requested_types & H5F_OBJ_ATTR) if (H5Iiterate(H5I_ATTR, RV_iterate_copy_hid_cb, &id_list) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over attribute ids"); + *args->args.get_obj_ids.count = id_list.obj_count; + break; default: FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get this type of information from file"); @@ -812,11 +819,13 @@ RV_file_close(void *file, hid_t dxpl_id, void **req) herr_t RV_iterate_copy_hid_cb(hid_t obj_id, void *udata) { - herr_t ret_value = SUCCEED; - object_id_list *id_list = (object_id_list *)udata; + herr_t ret_value = H5_ITER_CONT; + get_obj_ids_udata_t *id_list = (get_obj_ids_udata_t *)udata; - id_list->obj_id_list[id_list->obj_count] = obj_id; + if (id_list->obj_count >= id_list->max_obj_count) + FUNC_GOTO_DONE(H5_ITER_STOP); + id_list->obj_id_list[id_list->obj_count] = obj_id; id_list->obj_count++; done: diff --git a/test/test_rest_vol.c b/test/test_rest_vol.c index 818974a9..b9a1967e 100644 --- a/test/test_rest_vol.c +++ b/test/test_rest_vol.c @@ -1475,8 +1475,6 @@ test_unused_file_API_calls(void) TEST_ERROR if (H5Fget_obj_count(file_id, H5F_OBJ_DATASET) >= 0) TEST_ERROR - if (H5Fget_obj_ids(file_id, H5F_OBJ_DATASET, 0, &obj_id) >= 0) - TEST_ERROR if (H5Fmount(file_id, "/", file_id, H5P_DEFAULT) >= 0) TEST_ERROR if (H5Funmount(file_id, "/") >= 0) From fde0fa00a8ede3495139abebab110616f14484b9 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:09:48 +0000 Subject: [PATCH 4/4] Committing clang-format changes --- src/rest_vol_file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rest_vol_file.c b/src/rest_vol_file.c index 6ed1a98f..932c5438 100644 --- a/src/rest_vol_file.c +++ b/src/rest_vol_file.c @@ -569,8 +569,8 @@ RV_file_get(void *obj, H5VL_file_get_args_t *args, hid_t dxpl_id, void **req) unsigned int requested_types = args->args.get_obj_ids.types; get_obj_ids_udata_t id_list; - id_list.obj_id_list = args->args.get_obj_ids.oid_list; - id_list.obj_count = 0; + id_list.obj_id_list = args->args.get_obj_ids.oid_list; + id_list.obj_count = 0; id_list.max_obj_count = args->args.get_obj_ids.max_objs; if (requested_types & H5F_OBJ_FILE)