From 12740af4a6da858e05672017877ef21cb89e2574 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 30 May 2024 22:12:30 -0500 Subject: [PATCH] Refactor to reduce code duplication (#4531) * Update error output w/new routine name --- src/H5D.c | 8 +- src/H5Dint.c | 10 +-- src/H5VLcallback.c | 141 ++---------------------------------- src/H5VLprivate.h | 10 +-- test/testfiles/error_test_1 | 2 +- 5 files changed, 18 insertions(+), 153 deletions(-) diff --git a/src/H5D.c b/src/H5D.c index d014d27cac..e7c3f4df0b 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -987,8 +987,8 @@ H5D__read_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t m HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms"); /* Read the data */ - if (H5VL_dataset_read_direct(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, - buf, token_ptr) < 0) + if (H5VL_dataset_read(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, + token_ptr) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data"); done: @@ -1289,8 +1289,8 @@ H5D__write_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms"); /* Write the data */ - if (H5VL_dataset_write_direct(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, - buf, token_ptr) < 0) + if (H5VL_dataset_write(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, + token_ptr) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data"); done: diff --git a/src/H5Dint.c b/src/H5Dint.c index 66340c8fa5..8f28afb48e 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -62,7 +62,7 @@ typedef struct { /* Internal data structure for computing variable-length dataset's total size */ /* (Used for generic 'get vlen buf size' operation) */ typedef struct { - const H5VL_object_t *dset_vol_obj; /* VOL object for the dataset */ + H5VL_object_t *dset_vol_obj; /* VOL object for the dataset */ hid_t fspace_id; /* Dataset dataspace ID of the dataset we are working on */ H5S_t *fspace; /* Dataset's dataspace for operation */ hid_t mspace_id; /* Memory dataspace ID of the dataset we are working on */ @@ -2816,9 +2816,9 @@ H5D__vlen_get_buf_size_gen_cb(void H5_ATTR_UNUSED *elem, hid_t type_id, unsigned HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, FAIL, "can't select point"); /* Read in the point (with the custom VL memory allocator) */ - if (H5VL_dataset_read(1, &vlen_bufsize->dset_vol_obj, &type_id, &vlen_bufsize->mspace_id, - &vlen_bufsize->fspace_id, vlen_bufsize->dxpl_id, &vlen_bufsize->common.fl_tbuf, - H5_REQUEST_NULL) < 0) + if (H5VL_dataset_read(1, &vlen_bufsize->dset_vol_obj->data, vlen_bufsize->dset_vol_obj->connector, + &type_id, &vlen_bufsize->mspace_id, &vlen_bufsize->fspace_id, vlen_bufsize->dxpl_id, + &vlen_bufsize->common.fl_tbuf, H5_REQUEST_NULL) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read point"); done: @@ -2860,7 +2860,7 @@ H5D__vlen_get_buf_size_gen(H5VL_object_t *vol_obj, hid_t type_id, hid_t space_id HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "dataspace does not have extent set"); /* Save the dataset */ - vlen_bufsize.dset_vol_obj = (const H5VL_object_t *)vol_obj; + vlen_bufsize.dset_vol_obj = vol_obj; /* Set up VOL callback arguments */ vol_cb_args.op_type = H5VL_DATASET_GET_SPACE; diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 02622dab93..2d89d50e7a 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -2025,7 +2025,7 @@ done: } /* end H5VL__dataset_read() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_read_direct + * Function: H5VL_dataset_read * * Purpose: Reads data from dataset through the VOL. This is like * H5VL_dataset_read, but takes an array of void * for the @@ -2039,8 +2039,8 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_dataset_read_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], - hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **req) +H5VL_dataset_read(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], hid_t mem_space_id[], + hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **req) { bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */ H5VL_object_t tmp_vol_obj; /* Temporary VOL object for setting VOL wrapper */ @@ -2069,70 +2069,6 @@ done: if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info"); - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_read_direct() */ - -/*------------------------------------------------------------------------- - * Function: H5VL_dataset_read - * - * Purpose: Reads data from dataset through the VOL - * - * Return: Success: Non-negative - * Failure: Negative - * - *------------------------------------------------------------------------- - */ -herr_t -H5VL_dataset_read(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[], hid_t mem_space_id[], - hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **req) -{ - bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */ - void *obj_local; /* Local buffer for obj */ - void **obj = &obj_local; /* Array of object pointers */ - size_t i; /* Local index variable */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - assert(vol_obj); - assert(vol_obj[0]); - - /* Set wrapper info in API context */ - if (H5VL_set_vol_wrapper(vol_obj[0]) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL wrapper info"); - vol_wrapper_set = true; - - /* Allocate obj array if necessary */ - if (count > 1) - if (NULL == (obj = (void **)H5MM_malloc(count * sizeof(void *)))) - HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate space for object array"); - - /* Build obj array */ - for (i = 0; i < count; i++) { - /* Get the object */ - obj[i] = vol_obj[i]->data; - - /* Make sure the class matches */ - if (vol_obj[i]->connector->cls->value != vol_obj[0]->connector->cls->value) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, - "datasets are accessed through different VOL connectors and can't be used in the " - "same I/O call"); - } - - /* Call the corresponding internal VOL routine */ - if (H5VL__dataset_read(count, obj, vol_obj[0]->connector->cls, mem_type_id, mem_space_id, file_space_id, - dxpl_id, buf, req) < 0) - HGOTO_ERROR(H5E_VOL, H5E_READERROR, FAIL, "dataset read failed"); - -done: - /* Reset object wrapping info in API context */ - if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) - HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info"); - - /* Free memory */ - if (obj != &obj_local) - H5MM_free(obj); - FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_dataset_read() */ @@ -2212,7 +2148,7 @@ done: } /* end H5VL__dataset_write() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_write_direct + * Function: H5VL_dataset_write * * Purpose: Writes data from dataset through the VOL. This is like * H5VL_dataset_write, but takes an array of void * for the @@ -2226,9 +2162,8 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_dataset_write_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], - hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, const void *buf[], - void **req) +H5VL_dataset_write(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], hid_t mem_space_id[], + hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void **req) { bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */ H5VL_object_t tmp_vol_obj; /* Temporary VOL object for setting VOL wrapper */ @@ -2257,70 +2192,6 @@ done: if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info"); - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_write_direct() */ - -/*------------------------------------------------------------------------- - * Function: H5VL_dataset_write - * - * Purpose: Writes data from dataset through the VOL - * - * Return: Success: Non-negative - * Failure: Negative - * - *------------------------------------------------------------------------- - */ -herr_t -H5VL_dataset_write(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[], hid_t mem_space_id[], - hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void **req) -{ - bool vol_wrapper_set = false; /* Whether the VOL object wrapping context was set up */ - void *obj_local; /* Local buffer for obj */ - void **obj = &obj_local; /* Array of object pointers */ - size_t i; /* Local index variable */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - assert(vol_obj); - assert(vol_obj[0]); - - /* Set wrapper info in API context */ - if (H5VL_set_vol_wrapper(vol_obj[0]) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL wrapper info"); - vol_wrapper_set = true; - - /* Allocate obj array if necessary */ - if (count > 1) - if (NULL == (obj = (void **)H5MM_malloc(count * sizeof(void *)))) - HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate space for object array"); - - /* Build obj array */ - for (i = 0; i < count; i++) { - /* Get the object */ - obj[i] = vol_obj[i]->data; - - /* Make sure the class matches */ - if (vol_obj[i]->connector->cls->value != vol_obj[0]->connector->cls->value) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, - "datasets are accessed through different VOL connectors and can't be used in the " - "same I/O call"); - } - - /* Call the corresponding internal VOL routine */ - if (H5VL__dataset_write(count, obj, vol_obj[0]->connector->cls, mem_type_id, mem_space_id, file_space_id, - dxpl_id, buf, req) < 0) - HGOTO_ERROR(H5E_VOL, H5E_WRITEERROR, FAIL, "dataset write failed"); - -done: - /* Reset object wrapping info in API context */ - if (vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) - HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info"); - - /* Free memory */ - if (obj != &obj_local) - H5MM_free(obj); - FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_dataset_write() */ diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index d0c856b904..79ed93c03b 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -177,18 +177,12 @@ H5_DLL void *H5VL_dataset_create(const H5VL_object_t *vol_obj, const H5VL_loc_p hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VL_dataset_open(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req); -H5_DLL herr_t H5VL_dataset_read(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[], +H5_DLL herr_t H5VL_dataset_read(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **req); -H5_DLL herr_t H5VL_dataset_read_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], - hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, - void *buf[], void **req); -H5_DLL herr_t H5VL_dataset_write(size_t count, const H5VL_object_t *vol_obj[], hid_t mem_type_id[], +H5_DLL herr_t H5VL_dataset_write(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void **req); -H5_DLL herr_t H5VL_dataset_write_direct(size_t count, void *obj[], H5VL_t *connector, hid_t mem_type_id[], - hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, - const void *buf[], void **req); H5_DLL herr_t H5VL_dataset_get(const H5VL_object_t *vol_obj, H5VL_dataset_get_args_t *args, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL_dataset_specific(const H5VL_object_t *cls, H5VL_dataset_specific_args_t *args, diff --git a/test/testfiles/error_test_1 b/test/testfiles/error_test_1 index 6d94d434e4..8ddf3e4da6 100644 --- a/test/testfiles/error_test_1 +++ b/test/testfiles/error_test_1 @@ -50,7 +50,7 @@ HDF5-DIAG: Error detected in HDF5 (version (number)): #001: (file name) line (number) in H5D__read_api_common(): can't read data major: Dataset minor: Read failed - #002: (file name) line (number) in H5VL_dataset_read_direct(): dataset read failed + #002: (file name) line (number) in H5VL_dataset_read(): dataset read failed major: Virtual Object Layer minor: Read failed #003: (file name) line (number) in H5VL__dataset_read(): dataset read failed